echarts.simple.js 1.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521
  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. /*
  7. * Licensed to the Apache Software Foundation (ASF) under one
  8. * or more contributor license agreements. See the NOTICE file
  9. * distributed with this work for additional information
  10. * regarding copyright ownership. The ASF licenses this file
  11. * to you under the Apache License, Version 2.0 (the
  12. * "License"); you may not use this file except in compliance
  13. * with the License. You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing,
  18. * software distributed under the License is distributed on an
  19. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20. * KIND, either express or implied. See the License for the
  21. * specific language governing permissions and limitations
  22. * under the License.
  23. */
  24. // (1) The code `if (__DEV__) ...` can be removed by build tool.
  25. // (2) If intend to use `__DEV__`, this module should be imported. Use a global
  26. // variable `__DEV__` may cause that miss the declaration (see #6535), or the
  27. // declaration is behind of the using position (for example in `Model.extent`,
  28. // And tools like rollup can not analysis the dependency if not import).
  29. var dev;
  30. // In browser
  31. if (typeof window !== 'undefined') {
  32. dev = window.__DEV__;
  33. }
  34. // In node
  35. else if (typeof global !== 'undefined') {
  36. dev = global.__DEV__;
  37. }
  38. if (typeof dev === 'undefined') {
  39. dev = true;
  40. }
  41. var __DEV__ = dev;
  42. /**
  43. * zrender: 生成唯一id
  44. *
  45. * @author errorrik (errorrik@gmail.com)
  46. */
  47. var idStart = 0x0907;
  48. var guid = function () {
  49. return idStart++;
  50. };
  51. /**
  52. * echarts设备环境识别
  53. *
  54. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  55. * @author firede[firede@firede.us]
  56. * @desc thanks zepto.
  57. */
  58. /* global wx */
  59. var env = {};
  60. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  61. // In Weixin Application
  62. env = {
  63. browser: {},
  64. os: {},
  65. node: false,
  66. wxa: true, // Weixin Application
  67. canvasSupported: true,
  68. svgSupported: false,
  69. touchEventsSupported: true,
  70. domSupported: false
  71. };
  72. }
  73. else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  74. // In worker
  75. env = {
  76. browser: {},
  77. os: {},
  78. node: false,
  79. worker: true,
  80. canvasSupported: true,
  81. domSupported: false
  82. };
  83. }
  84. else if (typeof navigator === 'undefined') {
  85. // In node
  86. env = {
  87. browser: {},
  88. os: {},
  89. node: true,
  90. worker: false,
  91. // Assume canvas is supported
  92. canvasSupported: true,
  93. svgSupported: true,
  94. domSupported: false
  95. };
  96. }
  97. else {
  98. env = detect(navigator.userAgent);
  99. }
  100. var env$1 = env;
  101. // Zepto.js
  102. // (c) 2010-2013 Thomas Fuchs
  103. // Zepto.js may be freely distributed under the MIT license.
  104. function detect(ua) {
  105. var os = {};
  106. var browser = {};
  107. // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  108. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  109. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  110. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  111. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  112. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  113. // var touchpad = webos && ua.match(/TouchPad/);
  114. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  115. // var silk = ua.match(/Silk\/([\d._]+)/);
  116. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  117. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  118. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  119. // var playbook = ua.match(/PlayBook/);
  120. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  121. var firefox = ua.match(/Firefox\/([\d.]+)/);
  122. // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  123. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  124. var ie = ua.match(/MSIE\s([\d.]+)/)
  125. // IE 11 Trident/7.0; rv:11.0
  126. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  127. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  128. var weChat = (/micromessenger/i).test(ua);
  129. // Todo: clean this up with a better OS/browser seperation:
  130. // - discern (more) between multiple browsers on android
  131. // - decide if kindle fire in silk mode is android or not
  132. // - Firefox on Android doesn't specify the Android version
  133. // - possibly devide in os, device and browser hashes
  134. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  135. // if (android) os.android = true, os.version = android[2];
  136. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  137. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  138. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  139. // if (webos) os.webos = true, os.version = webos[2];
  140. // if (touchpad) os.touchpad = true;
  141. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  142. // if (bb10) os.bb10 = true, os.version = bb10[2];
  143. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  144. // if (playbook) browser.playbook = true;
  145. // if (kindle) os.kindle = true, os.version = kindle[1];
  146. // if (silk) browser.silk = true, browser.version = silk[1];
  147. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  148. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  149. if (firefox) {
  150. browser.firefox = true;
  151. browser.version = firefox[1];
  152. }
  153. // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  154. // if (webview) browser.webview = true;
  155. if (ie) {
  156. browser.ie = true;
  157. browser.version = ie[1];
  158. }
  159. if (edge) {
  160. browser.edge = true;
  161. browser.version = edge[1];
  162. }
  163. // It is difficult to detect WeChat in Win Phone precisely, because ua can
  164. // not be set on win phone. So we do not consider Win Phone.
  165. if (weChat) {
  166. browser.weChat = true;
  167. }
  168. // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  169. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  170. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  171. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  172. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  173. return {
  174. browser: browser,
  175. os: os,
  176. node: false,
  177. // 原生canvas支持,改极端点了
  178. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  179. canvasSupported: !!document.createElement('canvas').getContext,
  180. svgSupported: typeof SVGRect !== 'undefined',
  181. // works on most browsers
  182. // IE10/11 does not support touch event, and MS Edge supports them but not by
  183. // default, so we dont check navigator.maxTouchPoints for them here.
  184. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  185. // <http://caniuse.com/#search=pointer%20event>.
  186. pointerEventsSupported:
  187. // (1) Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  188. // events currently. So we dont use that on other browsers unless tested sufficiently.
  189. // For example, in iOS 13 Mobile Chromium 78, if the touching behavior starts page
  190. // scroll, the `pointermove` event can not be fired any more. That will break some
  191. // features like "pan horizontally to move something and pan vertically to page scroll".
  192. // The horizontal pan probably be interrupted by the casually triggered page scroll.
  193. // (2) Although IE 10 supports pointer event, it use old style and is different from the
  194. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  195. 'onpointerdown' in window
  196. && (browser.edge || (browser.ie && browser.version >= 11)),
  197. // passiveSupported: detectPassiveSupport()
  198. domSupported: typeof document !== 'undefined'
  199. };
  200. }
  201. // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
  202. // function detectPassiveSupport() {
  203. // // Test via a getter in the options object to see if the passive property is accessed
  204. // var supportsPassive = false;
  205. // try {
  206. // var opts = Object.defineProperty({}, 'passive', {
  207. // get: function() {
  208. // supportsPassive = true;
  209. // }
  210. // });
  211. // window.addEventListener('testPassive', function() {}, opts);
  212. // } catch (e) {
  213. // }
  214. // return supportsPassive;
  215. // }
  216. /**
  217. * @module zrender/core/util
  218. */
  219. // 用于处理merge时无法遍历Date等对象的问题
  220. var BUILTIN_OBJECT = {
  221. '[object Function]': 1,
  222. '[object RegExp]': 1,
  223. '[object Date]': 1,
  224. '[object Error]': 1,
  225. '[object CanvasGradient]': 1,
  226. '[object CanvasPattern]': 1,
  227. // For node-canvas
  228. '[object Image]': 1,
  229. '[object Canvas]': 1
  230. };
  231. var TYPED_ARRAY = {
  232. '[object Int8Array]': 1,
  233. '[object Uint8Array]': 1,
  234. '[object Uint8ClampedArray]': 1,
  235. '[object Int16Array]': 1,
  236. '[object Uint16Array]': 1,
  237. '[object Int32Array]': 1,
  238. '[object Uint32Array]': 1,
  239. '[object Float32Array]': 1,
  240. '[object Float64Array]': 1
  241. };
  242. var objToString = Object.prototype.toString;
  243. var arrayProto = Array.prototype;
  244. var nativeForEach = arrayProto.forEach;
  245. var nativeFilter = arrayProto.filter;
  246. var nativeSlice = arrayProto.slice;
  247. var nativeMap = arrayProto.map;
  248. var nativeReduce = arrayProto.reduce;
  249. // Avoid assign to an exported variable, for transforming to cjs.
  250. var methods = {};
  251. function $override(name, fn) {
  252. // Clear ctx instance for different environment
  253. if (name === 'createCanvas') {
  254. _ctx = null;
  255. }
  256. methods[name] = fn;
  257. }
  258. /**
  259. * Those data types can be cloned:
  260. * Plain object, Array, TypedArray, number, string, null, undefined.
  261. * Those data types will be assgined using the orginal data:
  262. * BUILTIN_OBJECT
  263. * Instance of user defined class will be cloned to a plain object, without
  264. * properties in prototype.
  265. * Other data types is not supported (not sure what will happen).
  266. *
  267. * Caution: do not support clone Date, for performance consideration.
  268. * (There might be a large number of date in `series.data`).
  269. * So date should not be modified in and out of echarts.
  270. *
  271. * @param {*} source
  272. * @return {*} new
  273. */
  274. function clone(source) {
  275. if (source == null || typeof source !== 'object') {
  276. return source;
  277. }
  278. var result = source;
  279. var typeStr = objToString.call(source);
  280. if (typeStr === '[object Array]') {
  281. if (!isPrimitive(source)) {
  282. result = [];
  283. for (var i = 0, len = source.length; i < len; i++) {
  284. result[i] = clone(source[i]);
  285. }
  286. }
  287. }
  288. else if (TYPED_ARRAY[typeStr]) {
  289. if (!isPrimitive(source)) {
  290. var Ctor = source.constructor;
  291. if (source.constructor.from) {
  292. result = Ctor.from(source);
  293. }
  294. else {
  295. result = new Ctor(source.length);
  296. for (var i = 0, len = source.length; i < len; i++) {
  297. result[i] = clone(source[i]);
  298. }
  299. }
  300. }
  301. }
  302. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  303. result = {};
  304. for (var key in source) {
  305. if (source.hasOwnProperty(key)) {
  306. result[key] = clone(source[key]);
  307. }
  308. }
  309. }
  310. return result;
  311. }
  312. /**
  313. * @memberOf module:zrender/core/util
  314. * @param {*} target
  315. * @param {*} source
  316. * @param {boolean} [overwrite=false]
  317. */
  318. function merge(target, source, overwrite) {
  319. // We should escapse that source is string
  320. // and enter for ... in ...
  321. if (!isObject$1(source) || !isObject$1(target)) {
  322. return overwrite ? clone(source) : target;
  323. }
  324. for (var key in source) {
  325. if (source.hasOwnProperty(key)) {
  326. var targetProp = target[key];
  327. var sourceProp = source[key];
  328. if (isObject$1(sourceProp)
  329. && isObject$1(targetProp)
  330. && !isArray(sourceProp)
  331. && !isArray(targetProp)
  332. && !isDom(sourceProp)
  333. && !isDom(targetProp)
  334. && !isBuiltInObject(sourceProp)
  335. && !isBuiltInObject(targetProp)
  336. && !isPrimitive(sourceProp)
  337. && !isPrimitive(targetProp)
  338. ) {
  339. // 如果需要递归覆盖,就递归调用merge
  340. merge(targetProp, sourceProp, overwrite);
  341. }
  342. else if (overwrite || !(key in target)) {
  343. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  344. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  345. target[key] = clone(source[key], true);
  346. }
  347. }
  348. }
  349. return target;
  350. }
  351. /**
  352. * @param {Array} targetAndSources The first item is target, and the rests are source.
  353. * @param {boolean} [overwrite=false]
  354. * @return {*} target
  355. */
  356. function mergeAll(targetAndSources, overwrite) {
  357. var result = targetAndSources[0];
  358. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  359. result = merge(result, targetAndSources[i], overwrite);
  360. }
  361. return result;
  362. }
  363. /**
  364. * @param {*} target
  365. * @param {*} source
  366. * @memberOf module:zrender/core/util
  367. */
  368. function extend(target, source) {
  369. for (var key in source) {
  370. if (source.hasOwnProperty(key)) {
  371. target[key] = source[key];
  372. }
  373. }
  374. return target;
  375. }
  376. /**
  377. * @param {*} target
  378. * @param {*} source
  379. * @param {boolean} [overlay=false]
  380. * @memberOf module:zrender/core/util
  381. */
  382. function defaults(target, source, overlay) {
  383. for (var key in source) {
  384. if (source.hasOwnProperty(key)
  385. && (overlay ? source[key] != null : target[key] == null)
  386. ) {
  387. target[key] = source[key];
  388. }
  389. }
  390. return target;
  391. }
  392. var createCanvas = function () {
  393. return methods.createCanvas();
  394. };
  395. methods.createCanvas = function () {
  396. return document.createElement('canvas');
  397. };
  398. // FIXME
  399. var _ctx;
  400. function getContext() {
  401. if (!_ctx) {
  402. // Use util.createCanvas instead of createCanvas
  403. // because createCanvas may be overwritten in different environment
  404. _ctx = createCanvas().getContext('2d');
  405. }
  406. return _ctx;
  407. }
  408. /**
  409. * 查询数组中元素的index
  410. * @memberOf module:zrender/core/util
  411. */
  412. function indexOf(array, value) {
  413. if (array) {
  414. if (array.indexOf) {
  415. return array.indexOf(value);
  416. }
  417. for (var i = 0, len = array.length; i < len; i++) {
  418. if (array[i] === value) {
  419. return i;
  420. }
  421. }
  422. }
  423. return -1;
  424. }
  425. /**
  426. * 构造类继承关系
  427. *
  428. * @memberOf module:zrender/core/util
  429. * @param {Function} clazz 源类
  430. * @param {Function} baseClazz 基类
  431. */
  432. function inherits(clazz, baseClazz) {
  433. var clazzPrototype = clazz.prototype;
  434. function F() {}
  435. F.prototype = baseClazz.prototype;
  436. clazz.prototype = new F();
  437. for (var prop in clazzPrototype) {
  438. if (clazzPrototype.hasOwnProperty(prop)) {
  439. clazz.prototype[prop] = clazzPrototype[prop];
  440. }
  441. }
  442. clazz.prototype.constructor = clazz;
  443. clazz.superClass = baseClazz;
  444. }
  445. /**
  446. * @memberOf module:zrender/core/util
  447. * @param {Object|Function} target
  448. * @param {Object|Function} sorce
  449. * @param {boolean} overlay
  450. */
  451. function mixin(target, source, overlay) {
  452. target = 'prototype' in target ? target.prototype : target;
  453. source = 'prototype' in source ? source.prototype : source;
  454. defaults(target, source, overlay);
  455. }
  456. /**
  457. * Consider typed array.
  458. * @param {Array|TypedArray} data
  459. */
  460. function isArrayLike(data) {
  461. if (!data) {
  462. return;
  463. }
  464. if (typeof data === 'string') {
  465. return false;
  466. }
  467. return typeof data.length === 'number';
  468. }
  469. /**
  470. * 数组或对象遍历
  471. * @memberOf module:zrender/core/util
  472. * @param {Object|Array} obj
  473. * @param {Function} cb
  474. * @param {*} [context]
  475. */
  476. function each$1(obj, cb, context) {
  477. if (!(obj && cb)) {
  478. return;
  479. }
  480. if (obj.forEach && obj.forEach === nativeForEach) {
  481. obj.forEach(cb, context);
  482. }
  483. else if (obj.length === +obj.length) {
  484. for (var i = 0, len = obj.length; i < len; i++) {
  485. cb.call(context, obj[i], i, obj);
  486. }
  487. }
  488. else {
  489. for (var key in obj) {
  490. if (obj.hasOwnProperty(key)) {
  491. cb.call(context, obj[key], key, obj);
  492. }
  493. }
  494. }
  495. }
  496. /**
  497. * 数组映射
  498. * @memberOf module:zrender/core/util
  499. * @param {Array} obj
  500. * @param {Function} cb
  501. * @param {*} [context]
  502. * @return {Array}
  503. */
  504. function map(obj, cb, context) {
  505. if (!(obj && cb)) {
  506. return;
  507. }
  508. if (obj.map && obj.map === nativeMap) {
  509. return obj.map(cb, context);
  510. }
  511. else {
  512. var result = [];
  513. for (var i = 0, len = obj.length; i < len; i++) {
  514. result.push(cb.call(context, obj[i], i, obj));
  515. }
  516. return result;
  517. }
  518. }
  519. /**
  520. * @memberOf module:zrender/core/util
  521. * @param {Array} obj
  522. * @param {Function} cb
  523. * @param {Object} [memo]
  524. * @param {*} [context]
  525. * @return {Array}
  526. */
  527. function reduce(obj, cb, memo, context) {
  528. if (!(obj && cb)) {
  529. return;
  530. }
  531. if (obj.reduce && obj.reduce === nativeReduce) {
  532. return obj.reduce(cb, memo, context);
  533. }
  534. else {
  535. for (var i = 0, len = obj.length; i < len; i++) {
  536. memo = cb.call(context, memo, obj[i], i, obj);
  537. }
  538. return memo;
  539. }
  540. }
  541. /**
  542. * 数组过滤
  543. * @memberOf module:zrender/core/util
  544. * @param {Array} obj
  545. * @param {Function} cb
  546. * @param {*} [context]
  547. * @return {Array}
  548. */
  549. function filter(obj, cb, context) {
  550. if (!(obj && cb)) {
  551. return;
  552. }
  553. if (obj.filter && obj.filter === nativeFilter) {
  554. return obj.filter(cb, context);
  555. }
  556. else {
  557. var result = [];
  558. for (var i = 0, len = obj.length; i < len; i++) {
  559. if (cb.call(context, obj[i], i, obj)) {
  560. result.push(obj[i]);
  561. }
  562. }
  563. return result;
  564. }
  565. }
  566. /**
  567. * 数组项查找
  568. * @memberOf module:zrender/core/util
  569. * @param {Array} obj
  570. * @param {Function} cb
  571. * @param {*} [context]
  572. * @return {*}
  573. */
  574. /**
  575. * @memberOf module:zrender/core/util
  576. * @param {Function} func
  577. * @param {*} context
  578. * @return {Function}
  579. */
  580. function bind(func, context) {
  581. var args = nativeSlice.call(arguments, 2);
  582. return function () {
  583. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  584. };
  585. }
  586. /**
  587. * @memberOf module:zrender/core/util
  588. * @param {Function} func
  589. * @return {Function}
  590. */
  591. function curry(func) {
  592. var args = nativeSlice.call(arguments, 1);
  593. return function () {
  594. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  595. };
  596. }
  597. /**
  598. * @memberOf module:zrender/core/util
  599. * @param {*} value
  600. * @return {boolean}
  601. */
  602. function isArray(value) {
  603. return objToString.call(value) === '[object Array]';
  604. }
  605. /**
  606. * @memberOf module:zrender/core/util
  607. * @param {*} value
  608. * @return {boolean}
  609. */
  610. function isFunction$1(value) {
  611. return typeof value === 'function';
  612. }
  613. /**
  614. * @memberOf module:zrender/core/util
  615. * @param {*} value
  616. * @return {boolean}
  617. */
  618. function isString(value) {
  619. return objToString.call(value) === '[object String]';
  620. }
  621. /**
  622. * @memberOf module:zrender/core/util
  623. * @param {*} value
  624. * @return {boolean}
  625. */
  626. function isObject$1(value) {
  627. // Avoid a V8 JIT bug in Chrome 19-20.
  628. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  629. var type = typeof value;
  630. return type === 'function' || (!!value && type === 'object');
  631. }
  632. /**
  633. * @memberOf module:zrender/core/util
  634. * @param {*} value
  635. * @return {boolean}
  636. */
  637. function isBuiltInObject(value) {
  638. return !!BUILTIN_OBJECT[objToString.call(value)];
  639. }
  640. /**
  641. * @memberOf module:zrender/core/util
  642. * @param {*} value
  643. * @return {boolean}
  644. */
  645. function isTypedArray(value) {
  646. return !!TYPED_ARRAY[objToString.call(value)];
  647. }
  648. /**
  649. * @memberOf module:zrender/core/util
  650. * @param {*} value
  651. * @return {boolean}
  652. */
  653. function isDom(value) {
  654. return typeof value === 'object'
  655. && typeof value.nodeType === 'number'
  656. && typeof value.ownerDocument === 'object';
  657. }
  658. /**
  659. * Whether is exactly NaN. Notice isNaN('a') returns true.
  660. * @param {*} value
  661. * @return {boolean}
  662. */
  663. function eqNaN(value) {
  664. /* eslint-disable-next-line no-self-compare */
  665. return value !== value;
  666. }
  667. /**
  668. * If value1 is not null, then return value1, otherwise judget rest of values.
  669. * Low performance.
  670. * @memberOf module:zrender/core/util
  671. * @return {*} Final value
  672. */
  673. function retrieve(values) {
  674. for (var i = 0, len = arguments.length; i < len; i++) {
  675. if (arguments[i] != null) {
  676. return arguments[i];
  677. }
  678. }
  679. }
  680. function retrieve2(value0, value1) {
  681. return value0 != null
  682. ? value0
  683. : value1;
  684. }
  685. function retrieve3(value0, value1, value2) {
  686. return value0 != null
  687. ? value0
  688. : value1 != null
  689. ? value1
  690. : value2;
  691. }
  692. /**
  693. * @memberOf module:zrender/core/util
  694. * @param {Array} arr
  695. * @param {number} startIndex
  696. * @param {number} endIndex
  697. * @return {Array}
  698. */
  699. function slice() {
  700. return Function.call.apply(nativeSlice, arguments);
  701. }
  702. /**
  703. * Normalize css liked array configuration
  704. * e.g.
  705. * 3 => [3, 3, 3, 3]
  706. * [4, 2] => [4, 2, 4, 2]
  707. * [4, 3, 2] => [4, 3, 2, 3]
  708. * @param {number|Array.<number>} val
  709. * @return {Array.<number>}
  710. */
  711. function normalizeCssArray(val) {
  712. if (typeof (val) === 'number') {
  713. return [val, val, val, val];
  714. }
  715. var len = val.length;
  716. if (len === 2) {
  717. // vertical | horizontal
  718. return [val[0], val[1], val[0], val[1]];
  719. }
  720. else if (len === 3) {
  721. // top | horizontal | bottom
  722. return [val[0], val[1], val[2], val[1]];
  723. }
  724. return val;
  725. }
  726. /**
  727. * @memberOf module:zrender/core/util
  728. * @param {boolean} condition
  729. * @param {string} message
  730. */
  731. function assert$1(condition, message) {
  732. if (!condition) {
  733. throw new Error(message);
  734. }
  735. }
  736. /**
  737. * @memberOf module:zrender/core/util
  738. * @param {string} str string to be trimed
  739. * @return {string} trimed string
  740. */
  741. function trim(str) {
  742. if (str == null) {
  743. return null;
  744. }
  745. else if (typeof str.trim === 'function') {
  746. return str.trim();
  747. }
  748. else {
  749. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  750. }
  751. }
  752. var primitiveKey = '__ec_primitive__';
  753. /**
  754. * Set an object as primitive to be ignored traversing children in clone or merge
  755. */
  756. function setAsPrimitive(obj) {
  757. obj[primitiveKey] = true;
  758. }
  759. function isPrimitive(obj) {
  760. return obj[primitiveKey];
  761. }
  762. /**
  763. * @constructor
  764. * @param {Object} obj Only apply `ownProperty`.
  765. */
  766. function HashMap(obj) {
  767. var isArr = isArray(obj);
  768. // Key should not be set on this, otherwise
  769. // methods get/set/... may be overrided.
  770. this.data = {};
  771. var thisMap = this;
  772. (obj instanceof HashMap)
  773. ? obj.each(visit)
  774. : (obj && each$1(obj, visit));
  775. function visit(value, key) {
  776. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  777. }
  778. }
  779. HashMap.prototype = {
  780. constructor: HashMap,
  781. // Do not provide `has` method to avoid defining what is `has`.
  782. // (We usually treat `null` and `undefined` as the same, different
  783. // from ES6 Map).
  784. get: function (key) {
  785. return this.data.hasOwnProperty(key) ? this.data[key] : null;
  786. },
  787. set: function (key, value) {
  788. // Comparing with invocation chaining, `return value` is more commonly
  789. // used in this case: `var someVal = map.set('a', genVal());`
  790. return (this.data[key] = value);
  791. },
  792. // Although util.each can be performed on this hashMap directly, user
  793. // should not use the exposed keys, who are prefixed.
  794. each: function (cb, context) {
  795. context !== void 0 && (cb = bind(cb, context));
  796. /* eslint-disable guard-for-in */
  797. for (var key in this.data) {
  798. this.data.hasOwnProperty(key) && cb(this.data[key], key);
  799. }
  800. /* eslint-enable guard-for-in */
  801. },
  802. // Do not use this method if performance sensitive.
  803. removeKey: function (key) {
  804. delete this.data[key];
  805. }
  806. };
  807. function createHashMap(obj) {
  808. return new HashMap(obj);
  809. }
  810. function noop() {}
  811. /* global Float32Array */
  812. var ArrayCtor = typeof Float32Array === 'undefined'
  813. ? Array
  814. : Float32Array;
  815. /**
  816. * 创建一个向量
  817. * @param {number} [x=0]
  818. * @param {number} [y=0]
  819. * @return {Vector2}
  820. */
  821. function create(x, y) {
  822. var out = new ArrayCtor(2);
  823. if (x == null) {
  824. x = 0;
  825. }
  826. if (y == null) {
  827. y = 0;
  828. }
  829. out[0] = x;
  830. out[1] = y;
  831. return out;
  832. }
  833. /**
  834. * 复制向量数据
  835. * @param {Vector2} out
  836. * @param {Vector2} v
  837. * @return {Vector2}
  838. */
  839. function copy(out, v) {
  840. out[0] = v[0];
  841. out[1] = v[1];
  842. return out;
  843. }
  844. /**
  845. * 克隆一个向量
  846. * @param {Vector2} v
  847. * @return {Vector2}
  848. */
  849. function clone$1(v) {
  850. var out = new ArrayCtor(2);
  851. out[0] = v[0];
  852. out[1] = v[1];
  853. return out;
  854. }
  855. /**
  856. * 设置向量的两个项
  857. * @param {Vector2} out
  858. * @param {number} a
  859. * @param {number} b
  860. * @return {Vector2} 结果
  861. */
  862. /**
  863. * 向量相加
  864. * @param {Vector2} out
  865. * @param {Vector2} v1
  866. * @param {Vector2} v2
  867. */
  868. function add(out, v1, v2) {
  869. out[0] = v1[0] + v2[0];
  870. out[1] = v1[1] + v2[1];
  871. return out;
  872. }
  873. /**
  874. * 向量缩放后相加
  875. * @param {Vector2} out
  876. * @param {Vector2} v1
  877. * @param {Vector2} v2
  878. * @param {number} a
  879. */
  880. function scaleAndAdd(out, v1, v2, a) {
  881. out[0] = v1[0] + v2[0] * a;
  882. out[1] = v1[1] + v2[1] * a;
  883. return out;
  884. }
  885. /**
  886. * 向量相减
  887. * @param {Vector2} out
  888. * @param {Vector2} v1
  889. * @param {Vector2} v2
  890. */
  891. function sub(out, v1, v2) {
  892. out[0] = v1[0] - v2[0];
  893. out[1] = v1[1] - v2[1];
  894. return out;
  895. }
  896. /**
  897. * 向量长度
  898. * @param {Vector2} v
  899. * @return {number}
  900. */
  901. function len(v) {
  902. return Math.sqrt(lenSquare(v));
  903. }
  904. // jshint ignore:line
  905. /**
  906. * 向量长度平方
  907. * @param {Vector2} v
  908. * @return {number}
  909. */
  910. function lenSquare(v) {
  911. return v[0] * v[0] + v[1] * v[1];
  912. }
  913. /**
  914. * 向量乘法
  915. * @param {Vector2} out
  916. * @param {Vector2} v1
  917. * @param {Vector2} v2
  918. */
  919. /**
  920. * 向量除法
  921. * @param {Vector2} out
  922. * @param {Vector2} v1
  923. * @param {Vector2} v2
  924. */
  925. /**
  926. * 向量点乘
  927. * @param {Vector2} v1
  928. * @param {Vector2} v2
  929. * @return {number}
  930. */
  931. /**
  932. * 向量缩放
  933. * @param {Vector2} out
  934. * @param {Vector2} v
  935. * @param {number} s
  936. */
  937. function scale(out, v, s) {
  938. out[0] = v[0] * s;
  939. out[1] = v[1] * s;
  940. return out;
  941. }
  942. /**
  943. * 向量归一化
  944. * @param {Vector2} out
  945. * @param {Vector2} v
  946. */
  947. function normalize(out, v) {
  948. var d = len(v);
  949. if (d === 0) {
  950. out[0] = 0;
  951. out[1] = 0;
  952. }
  953. else {
  954. out[0] = v[0] / d;
  955. out[1] = v[1] / d;
  956. }
  957. return out;
  958. }
  959. /**
  960. * 计算向量间距离
  961. * @param {Vector2} v1
  962. * @param {Vector2} v2
  963. * @return {number}
  964. */
  965. function distance(v1, v2) {
  966. return Math.sqrt(
  967. (v1[0] - v2[0]) * (v1[0] - v2[0])
  968. + (v1[1] - v2[1]) * (v1[1] - v2[1])
  969. );
  970. }
  971. var dist = distance;
  972. /**
  973. * 向量距离平方
  974. * @param {Vector2} v1
  975. * @param {Vector2} v2
  976. * @return {number}
  977. */
  978. function distanceSquare(v1, v2) {
  979. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  980. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  981. }
  982. var distSquare = distanceSquare;
  983. /**
  984. * 求负向量
  985. * @param {Vector2} out
  986. * @param {Vector2} v
  987. */
  988. /**
  989. * 插值两个点
  990. * @param {Vector2} out
  991. * @param {Vector2} v1
  992. * @param {Vector2} v2
  993. * @param {number} t
  994. */
  995. /**
  996. * 矩阵左乘向量
  997. * @param {Vector2} out
  998. * @param {Vector2} v
  999. * @param {Vector2} m
  1000. */
  1001. function applyTransform(out, v, m) {
  1002. var x = v[0];
  1003. var y = v[1];
  1004. out[0] = m[0] * x + m[2] * y + m[4];
  1005. out[1] = m[1] * x + m[3] * y + m[5];
  1006. return out;
  1007. }
  1008. /**
  1009. * 求两个向量最小值
  1010. * @param {Vector2} out
  1011. * @param {Vector2} v1
  1012. * @param {Vector2} v2
  1013. */
  1014. function min(out, v1, v2) {
  1015. out[0] = Math.min(v1[0], v2[0]);
  1016. out[1] = Math.min(v1[1], v2[1]);
  1017. return out;
  1018. }
  1019. /**
  1020. * 求两个向量最大值
  1021. * @param {Vector2} out
  1022. * @param {Vector2} v1
  1023. * @param {Vector2} v2
  1024. */
  1025. function max(out, v1, v2) {
  1026. out[0] = Math.max(v1[0], v2[0]);
  1027. out[1] = Math.max(v1[1], v2[1]);
  1028. return out;
  1029. }
  1030. // TODO Draggable for group
  1031. // FIXME Draggable on element which has parent rotation or scale
  1032. function Draggable() {
  1033. this.on('mousedown', this._dragStart, this);
  1034. this.on('mousemove', this._drag, this);
  1035. this.on('mouseup', this._dragEnd, this);
  1036. // `mosuemove` and `mouseup` can be continue to fire when dragging.
  1037. // See [Drag outside] in `Handler.js`. So we do not need to trigger
  1038. // `_dragEnd` when globalout. That would brings better user experience.
  1039. // this.on('globalout', this._dragEnd, this);
  1040. // this._dropTarget = null;
  1041. // this._draggingTarget = null;
  1042. // this._x = 0;
  1043. // this._y = 0;
  1044. }
  1045. Draggable.prototype = {
  1046. constructor: Draggable,
  1047. _dragStart: function (e) {
  1048. var draggingTarget = e.target;
  1049. // Find if there is draggable in the ancestor
  1050. while (draggingTarget && !draggingTarget.draggable) {
  1051. draggingTarget = draggingTarget.parent;
  1052. }
  1053. if (draggingTarget) {
  1054. this._draggingTarget = draggingTarget;
  1055. draggingTarget.dragging = true;
  1056. this._x = e.offsetX;
  1057. this._y = e.offsetY;
  1058. this.dispatchToElement(param(draggingTarget, e), 'dragstart', e.event);
  1059. }
  1060. },
  1061. _drag: function (e) {
  1062. var draggingTarget = this._draggingTarget;
  1063. if (draggingTarget) {
  1064. var x = e.offsetX;
  1065. var y = e.offsetY;
  1066. var dx = x - this._x;
  1067. var dy = y - this._y;
  1068. this._x = x;
  1069. this._y = y;
  1070. draggingTarget.drift(dx, dy, e);
  1071. this.dispatchToElement(param(draggingTarget, e), 'drag', e.event);
  1072. var dropTarget = this.findHover(x, y, draggingTarget).target;
  1073. var lastDropTarget = this._dropTarget;
  1074. this._dropTarget = dropTarget;
  1075. if (draggingTarget !== dropTarget) {
  1076. if (lastDropTarget && dropTarget !== lastDropTarget) {
  1077. this.dispatchToElement(param(lastDropTarget, e), 'dragleave', e.event);
  1078. }
  1079. if (dropTarget && dropTarget !== lastDropTarget) {
  1080. this.dispatchToElement(param(dropTarget, e), 'dragenter', e.event);
  1081. }
  1082. }
  1083. }
  1084. },
  1085. _dragEnd: function (e) {
  1086. var draggingTarget = this._draggingTarget;
  1087. if (draggingTarget) {
  1088. draggingTarget.dragging = false;
  1089. }
  1090. this.dispatchToElement(param(draggingTarget, e), 'dragend', e.event);
  1091. if (this._dropTarget) {
  1092. this.dispatchToElement(param(this._dropTarget, e), 'drop', e.event);
  1093. }
  1094. this._draggingTarget = null;
  1095. this._dropTarget = null;
  1096. }
  1097. };
  1098. function param(target, e) {
  1099. return {target: target, topTarget: e && e.topTarget};
  1100. }
  1101. /**
  1102. * Event Mixin
  1103. * @module zrender/mixin/Eventful
  1104. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  1105. * pissang (https://www.github.com/pissang)
  1106. */
  1107. var arrySlice = Array.prototype.slice;
  1108. /**
  1109. * Event dispatcher.
  1110. *
  1111. * @alias module:zrender/mixin/Eventful
  1112. * @constructor
  1113. * @param {Object} [eventProcessor] The object eventProcessor is the scope when
  1114. * `eventProcessor.xxx` called.
  1115. * @param {Function} [eventProcessor.normalizeQuery]
  1116. * param: {string|Object} Raw query.
  1117. * return: {string|Object} Normalized query.
  1118. * @param {Function} [eventProcessor.filter] Event will be dispatched only
  1119. * if it returns `true`.
  1120. * param: {string} eventType
  1121. * param: {string|Object} query
  1122. * return: {boolean}
  1123. * @param {Function} [eventProcessor.afterTrigger] Called after all handlers called.
  1124. * param: {string} eventType
  1125. */
  1126. var Eventful = function (eventProcessor) {
  1127. this._$handlers = {};
  1128. this._$eventProcessor = eventProcessor;
  1129. };
  1130. Eventful.prototype = {
  1131. constructor: Eventful,
  1132. /**
  1133. * The handler can only be triggered once, then removed.
  1134. *
  1135. * @param {string} event The event name.
  1136. * @param {string|Object} [query] Condition used on event filter.
  1137. * @param {Function} handler The event handler.
  1138. * @param {Object} context
  1139. */
  1140. one: function (event, query, handler, context) {
  1141. return on(this, event, query, handler, context, true);
  1142. },
  1143. /**
  1144. * Bind a handler.
  1145. *
  1146. * @param {string} event The event name.
  1147. * @param {string|Object} [query] Condition used on event filter.
  1148. * @param {Function} handler The event handler.
  1149. * @param {Object} [context]
  1150. */
  1151. on: function (event, query, handler, context) {
  1152. return on(this, event, query, handler, context, false);
  1153. },
  1154. /**
  1155. * Whether any handler has bound.
  1156. *
  1157. * @param {string} event
  1158. * @return {boolean}
  1159. */
  1160. isSilent: function (event) {
  1161. var _h = this._$handlers;
  1162. return !_h[event] || !_h[event].length;
  1163. },
  1164. /**
  1165. * Unbind a event.
  1166. *
  1167. * @param {string} [event] The event name.
  1168. * If no `event` input, "off" all listeners.
  1169. * @param {Function} [handler] The event handler.
  1170. * If no `handler` input, "off" all listeners of the `event`.
  1171. */
  1172. off: function (event, handler) {
  1173. var _h = this._$handlers;
  1174. if (!event) {
  1175. this._$handlers = {};
  1176. return this;
  1177. }
  1178. if (handler) {
  1179. if (_h[event]) {
  1180. var newList = [];
  1181. for (var i = 0, l = _h[event].length; i < l; i++) {
  1182. if (_h[event][i].h !== handler) {
  1183. newList.push(_h[event][i]);
  1184. }
  1185. }
  1186. _h[event] = newList;
  1187. }
  1188. if (_h[event] && _h[event].length === 0) {
  1189. delete _h[event];
  1190. }
  1191. }
  1192. else {
  1193. delete _h[event];
  1194. }
  1195. return this;
  1196. },
  1197. /**
  1198. * Dispatch a event.
  1199. *
  1200. * @param {string} type The event name.
  1201. */
  1202. trigger: function (type) {
  1203. var _h = this._$handlers[type];
  1204. var eventProcessor = this._$eventProcessor;
  1205. if (_h) {
  1206. var args = arguments;
  1207. var argLen = args.length;
  1208. if (argLen > 3) {
  1209. args = arrySlice.call(args, 1);
  1210. }
  1211. var len = _h.length;
  1212. for (var i = 0; i < len;) {
  1213. var hItem = _h[i];
  1214. if (eventProcessor
  1215. && eventProcessor.filter
  1216. && hItem.query != null
  1217. && !eventProcessor.filter(type, hItem.query)
  1218. ) {
  1219. i++;
  1220. continue;
  1221. }
  1222. // Optimize advise from backbone
  1223. switch (argLen) {
  1224. case 1:
  1225. hItem.h.call(hItem.ctx);
  1226. break;
  1227. case 2:
  1228. hItem.h.call(hItem.ctx, args[1]);
  1229. break;
  1230. case 3:
  1231. hItem.h.call(hItem.ctx, args[1], args[2]);
  1232. break;
  1233. default:
  1234. // have more than 2 given arguments
  1235. hItem.h.apply(hItem.ctx, args);
  1236. break;
  1237. }
  1238. if (hItem.one) {
  1239. _h.splice(i, 1);
  1240. len--;
  1241. }
  1242. else {
  1243. i++;
  1244. }
  1245. }
  1246. }
  1247. eventProcessor && eventProcessor.afterTrigger
  1248. && eventProcessor.afterTrigger(type);
  1249. return this;
  1250. },
  1251. /**
  1252. * Dispatch a event with context, which is specified at the last parameter.
  1253. *
  1254. * @param {string} type The event name.
  1255. */
  1256. triggerWithContext: function (type) {
  1257. var _h = this._$handlers[type];
  1258. var eventProcessor = this._$eventProcessor;
  1259. if (_h) {
  1260. var args = arguments;
  1261. var argLen = args.length;
  1262. if (argLen > 4) {
  1263. args = arrySlice.call(args, 1, args.length - 1);
  1264. }
  1265. var ctx = args[args.length - 1];
  1266. var len = _h.length;
  1267. for (var i = 0; i < len;) {
  1268. var hItem = _h[i];
  1269. if (eventProcessor
  1270. && eventProcessor.filter
  1271. && hItem.query != null
  1272. && !eventProcessor.filter(type, hItem.query)
  1273. ) {
  1274. i++;
  1275. continue;
  1276. }
  1277. // Optimize advise from backbone
  1278. switch (argLen) {
  1279. case 1:
  1280. hItem.h.call(ctx);
  1281. break;
  1282. case 2:
  1283. hItem.h.call(ctx, args[1]);
  1284. break;
  1285. case 3:
  1286. hItem.h.call(ctx, args[1], args[2]);
  1287. break;
  1288. default:
  1289. // have more than 2 given arguments
  1290. hItem.h.apply(ctx, args);
  1291. break;
  1292. }
  1293. if (hItem.one) {
  1294. _h.splice(i, 1);
  1295. len--;
  1296. }
  1297. else {
  1298. i++;
  1299. }
  1300. }
  1301. }
  1302. eventProcessor && eventProcessor.afterTrigger
  1303. && eventProcessor.afterTrigger(type);
  1304. return this;
  1305. }
  1306. };
  1307. function normalizeQuery(host, query) {
  1308. var eventProcessor = host._$eventProcessor;
  1309. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  1310. query = eventProcessor.normalizeQuery(query);
  1311. }
  1312. return query;
  1313. }
  1314. function on(eventful, event, query, handler, context, isOnce) {
  1315. var _h = eventful._$handlers;
  1316. if (typeof query === 'function') {
  1317. context = handler;
  1318. handler = query;
  1319. query = null;
  1320. }
  1321. if (!handler || !event) {
  1322. return eventful;
  1323. }
  1324. query = normalizeQuery(eventful, query);
  1325. if (!_h[event]) {
  1326. _h[event] = [];
  1327. }
  1328. for (var i = 0; i < _h[event].length; i++) {
  1329. if (_h[event][i].h === handler) {
  1330. return eventful;
  1331. }
  1332. }
  1333. var wrap = {
  1334. h: handler,
  1335. one: isOnce,
  1336. query: query,
  1337. ctx: context || eventful,
  1338. // FIXME
  1339. // Do not publish this feature util it is proved that it makes sense.
  1340. callAtLast: handler.zrEventfulCallAtLast
  1341. };
  1342. var lastIndex = _h[event].length - 1;
  1343. var lastWrap = _h[event][lastIndex];
  1344. (lastWrap && lastWrap.callAtLast)
  1345. ? _h[event].splice(lastIndex, 0, wrap)
  1346. : _h[event].push(wrap);
  1347. return eventful;
  1348. }
  1349. /**
  1350. * The algoritm is learnt from
  1351. * https://franklinta.com/2014/09/08/computing-css-matrix3d-transforms/
  1352. * And we made some optimization for matrix inversion.
  1353. * Other similar approaches:
  1354. * "cv::getPerspectiveTransform", "Direct Linear Transformation".
  1355. */
  1356. var LN2 = Math.log(2);
  1357. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1358. var cacheKey = rowMask + '-' + colMask;
  1359. var fullRank = rows.length;
  1360. if (detCache.hasOwnProperty(cacheKey)) {
  1361. return detCache[cacheKey];
  1362. }
  1363. if (rank === 1) {
  1364. // In this case the colMask must be like: `11101111`. We can find the place of `0`.
  1365. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1366. return rows[rowStart][colStart];
  1367. }
  1368. var subRowMask = rowMask | (1 << rowStart);
  1369. var subRowStart = rowStart + 1;
  1370. while (rowMask & (1 << subRowStart)) {
  1371. subRowStart++;
  1372. }
  1373. var sum = 0;
  1374. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1375. var colTag = 1 << j;
  1376. if (!(colTag & colMask)) {
  1377. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1378. // det(subMatrix(0, j))
  1379. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1380. colLocalIdx++;
  1381. }
  1382. }
  1383. detCache[cacheKey] = sum;
  1384. return sum;
  1385. }
  1386. /**
  1387. * Usage:
  1388. * ```js
  1389. * var transformer = buildTransformer(
  1390. * [10, 44, 100, 44, 100, 300, 10, 300],
  1391. * [50, 54, 130, 14, 140, 330, 14, 220]
  1392. * );
  1393. * var out = [];
  1394. * transformer && transformer([11, 33], out);
  1395. * ```
  1396. *
  1397. * Notice: `buildTransformer` may take more than 10ms in some Android device.
  1398. *
  1399. * @param {Array.<number>} src source four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1400. * @param {Array.<number>} dest destination four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1401. * @return {Function} transformer If fail, return null/undefined.
  1402. */
  1403. function buildTransformer(src, dest) {
  1404. var mA = [
  1405. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1406. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1407. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1408. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1409. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1410. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1411. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1412. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1413. ];
  1414. var detCache = {};
  1415. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1416. if (det === 0) {
  1417. // can not make transformer when and only when
  1418. // any three of the markers are collinear.
  1419. return;
  1420. }
  1421. // `invert(mA) * dest`, that is, `adj(mA) / det * dest`.
  1422. var vh = [];
  1423. for (var i = 0; i < 8; i++) {
  1424. for (var j = 0; j < 8; j++) {
  1425. vh[j] == null && (vh[j] = 0);
  1426. vh[j] += ((i + j) % 2 ? -1 : 1)
  1427. // det(subMatrix(i, j))
  1428. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1429. / det * dest[i];
  1430. }
  1431. }
  1432. return function (out, srcPointX, srcPointY) {
  1433. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1434. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1435. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1436. };
  1437. }
  1438. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1439. /**
  1440. * Transform "local coord" from `elFrom` to `elTarget`.
  1441. * "local coord": the coord based on the input `el`. The origin point is at
  1442. * the position of "left: 0; top: 0;" in the `el`.
  1443. *
  1444. * Support when CSS transform is used.
  1445. *
  1446. * Having the `out` (that is, `[outX, outY]`), we can create an DOM element
  1447. * and set the CSS style as "left: outX; top: outY;" and append it to `elTarge`
  1448. * to locate the element.
  1449. *
  1450. * For example, this code below positions a child of `document.body` on the event
  1451. * point, no matter whether `body` has `margin`/`paddin`/`transfrom`/... :
  1452. * ```js
  1453. * transformLocalCoord(out, container, document.body, event.offsetX, event.offsetY);
  1454. * if (!eqNaN(out[0])) {
  1455. * // Then locate the tip element on the event point.
  1456. * var tipEl = document.createElement('div');
  1457. * tipEl.style.cssText = 'position: absolute; left:' + out[0] + ';top:' + out[1] + ';';
  1458. * document.body.appendChild(tipEl);
  1459. * }
  1460. * ```
  1461. *
  1462. * Notice: In some env this method is not supported. If called, `out` will be `[NaN, NaN]`.
  1463. *
  1464. * @param {Array.<number>} out [inX: number, inY: number] The output..
  1465. * If can not transform, `out` will not be modified but return `false`.
  1466. * @param {HTMLElement} elFrom The `[inX, inY]` is based on elFrom.
  1467. * @param {HTMLElement} elTarget The `out` is based on elTarget.
  1468. * @param {number} inX
  1469. * @param {number} inY
  1470. * @return {boolean} Whether transform successfully.
  1471. */
  1472. /**
  1473. * Transform between a "viewport coord" and a "local coord".
  1474. * "viewport coord": the coord based on the left-top corner of the viewport
  1475. * of the browser.
  1476. * "local coord": the coord based on the input `el`. The origin point is at
  1477. * the position of "left: 0; top: 0;" in the `el`.
  1478. *
  1479. * Support the case when CSS transform is used on el.
  1480. *
  1481. * @param {Array.<number>} out [inX: number, inY: number] The output. If `inverse: false`,
  1482. * it represents "local coord", otherwise "vireport coord".
  1483. * If can not transform, `out` will not be modified but return `false`.
  1484. * @param {HTMLElement} el The "local coord" is based on the `el`, see comment above.
  1485. * @param {number} inX If `inverse: false`,
  1486. * it represents "vireport coord", otherwise "local coord".
  1487. * @param {number} inY If `inverse: false`,
  1488. * it represents "vireport coord", otherwise "local coord".
  1489. * @param {boolean} [inverse=false]
  1490. * `true`: from "viewport coord" to "local coord".
  1491. * `false`: from "local coord" to "viewport coord".
  1492. * @return {boolean} Whether transform successfully.
  1493. */
  1494. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1495. if (el.getBoundingClientRect && env$1.domSupported && !isCanvasEl(el)) {
  1496. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1497. var markers = prepareCoordMarkers(el, saved);
  1498. var transformer = preparePointerTransformer(markers, saved, inverse);
  1499. if (transformer) {
  1500. transformer(out, inX, inY);
  1501. return true;
  1502. }
  1503. }
  1504. return false;
  1505. }
  1506. function prepareCoordMarkers(el, saved) {
  1507. var markers = saved.markers;
  1508. if (markers) {
  1509. return markers;
  1510. }
  1511. markers = saved.markers = [];
  1512. var propLR = ['left', 'right'];
  1513. var propTB = ['top', 'bottom'];
  1514. for (var i = 0; i < 4; i++) {
  1515. var marker = document.createElement('div');
  1516. var stl = marker.style;
  1517. var idxLR = i % 2;
  1518. var idxTB = (i >> 1) % 2;
  1519. stl.cssText = [
  1520. 'position: absolute',
  1521. 'visibility: hidden',
  1522. 'padding: 0',
  1523. 'margin: 0',
  1524. 'border-width: 0',
  1525. 'user-select: none',
  1526. 'width:0',
  1527. 'height:0',
  1528. // 'width: 5px',
  1529. // 'height: 5px',
  1530. propLR[idxLR] + ':0',
  1531. propTB[idxTB] + ':0',
  1532. propLR[1 - idxLR] + ':auto',
  1533. propTB[1 - idxTB] + ':auto',
  1534. ''
  1535. ].join('!important;');
  1536. el.appendChild(marker);
  1537. markers.push(marker);
  1538. }
  1539. return markers;
  1540. }
  1541. function preparePointerTransformer(markers, saved, inverse) {
  1542. var transformerName = inverse ? 'invTrans' : 'trans';
  1543. var transformer = saved[transformerName];
  1544. var oldSrcCoords = saved.srcCoords;
  1545. var oldCoordTheSame = true;
  1546. var srcCoords = [];
  1547. var destCoords = [];
  1548. for (var i = 0; i < 4; i++) {
  1549. var rect = markers[i].getBoundingClientRect();
  1550. var ii = 2 * i;
  1551. var x = rect.left;
  1552. var y = rect.top;
  1553. srcCoords.push(x, y);
  1554. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1555. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1556. }
  1557. // Cache to avoid time consuming of `buildTransformer`.
  1558. return (oldCoordTheSame && transformer)
  1559. ? transformer
  1560. : (
  1561. saved.srcCoords = srcCoords,
  1562. saved[transformerName] = inverse
  1563. ? buildTransformer(destCoords, srcCoords)
  1564. : buildTransformer(srcCoords, destCoords)
  1565. );
  1566. }
  1567. function isCanvasEl(el) {
  1568. return el.nodeName.toUpperCase() === 'CANVAS';
  1569. }
  1570. /**
  1571. * Utilities for mouse or touch events.
  1572. */
  1573. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  1574. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1575. var _calcOut = [];
  1576. /**
  1577. * Get the `zrX` and `zrY`, which are relative to the top-left of
  1578. * the input `el`.
  1579. * CSS transform (2D & 3D) is supported.
  1580. *
  1581. * The strategy to fetch the coords:
  1582. * + If `calculate` is not set as `true`, users of this method should
  1583. * ensure that `el` is the same or the same size & location as `e.target`.
  1584. * Otherwise the result coords are probably not expected. Because we
  1585. * firstly try to get coords from e.offsetX/e.offsetY.
  1586. * + If `calculate` is set as `true`, the input `el` can be any element
  1587. * and we force to calculate the coords based on `el`.
  1588. * + The input `el` should be positionable (not position:static).
  1589. *
  1590. * The force `calculate` can be used in case like:
  1591. * When mousemove event triggered on ec tooltip, `e.target` is not `el`(zr painter.dom).
  1592. *
  1593. * @param {HTMLElement} el DOM element.
  1594. * @param {Event} e Mouse event or touch event.
  1595. * @param {Object} out Get `out.zrX` and `out.zrY` as the result.
  1596. * @param {boolean} [calculate=false] Whether to force calculate
  1597. * the coordinates but not use ones provided by browser.
  1598. */
  1599. function clientToLocal(el, e, out, calculate) {
  1600. out = out || {};
  1601. // According to the W3C Working Draft, offsetX and offsetY should be relative
  1602. // to the padding edge of the target element. The only browser using this convention
  1603. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  1604. // not support the properties.
  1605. // (see http://www.jacklmoore.com/notes/mouse-position/)
  1606. // In zr painter.dom, padding edge equals to border edge.
  1607. if (calculate || !env$1.canvasSupported) {
  1608. calculateZrXY(el, e, out);
  1609. }
  1610. // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  1611. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  1612. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  1613. // zoom-factor, overflow / opacity layers, transforms ...)
  1614. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  1615. // <https://bugs.jquery.com/ticket/8523#comment:14>
  1616. // BTW3, In ff, offsetX/offsetY is always 0.
  1617. else if (env$1.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  1618. out.zrX = e.layerX;
  1619. out.zrY = e.layerY;
  1620. }
  1621. // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  1622. else if (e.offsetX != null) {
  1623. out.zrX = e.offsetX;
  1624. out.zrY = e.offsetY;
  1625. }
  1626. // For some other device, e.g., IOS safari.
  1627. else {
  1628. calculateZrXY(el, e, out);
  1629. }
  1630. return out;
  1631. }
  1632. function calculateZrXY(el, e, out) {
  1633. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect.
  1634. if (env$1.domSupported && el.getBoundingClientRect) {
  1635. var ex = e.clientX;
  1636. var ey = e.clientY;
  1637. if (isCanvasEl(el)) {
  1638. // Original approach, which do not support CSS transform.
  1639. // marker can not be locationed in a canvas container
  1640. // (getBoundingClientRect is always 0). We do not support
  1641. // that input a pre-created canvas to zr while using css
  1642. // transform in iOS.
  1643. var box = el.getBoundingClientRect();
  1644. out.zrX = ex - box.left;
  1645. out.zrY = ey - box.top;
  1646. return;
  1647. }
  1648. else {
  1649. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1650. out.zrX = _calcOut[0];
  1651. out.zrY = _calcOut[1];
  1652. return;
  1653. }
  1654. }
  1655. }
  1656. out.zrX = out.zrY = 0;
  1657. }
  1658. /**
  1659. * Find native event compat for legency IE.
  1660. * Should be called at the begining of a native event listener.
  1661. *
  1662. * @param {Event} [e] Mouse event or touch event or pointer event.
  1663. * For lagency IE, we use `window.event` is used.
  1664. * @return {Event} The native event.
  1665. */
  1666. function getNativeEvent(e) {
  1667. return e || window.event;
  1668. }
  1669. /**
  1670. * Normalize the coordinates of the input event.
  1671. *
  1672. * Get the `e.zrX` and `e.zrY`, which are relative to the top-left of
  1673. * the input `el`.
  1674. * Get `e.zrDelta` if using mouse wheel.
  1675. * Get `e.which`, see the comment inside this function.
  1676. *
  1677. * Do not calculate repeatly if `zrX` and `zrY` already exist.
  1678. *
  1679. * Notice: see comments in `clientToLocal`. check the relationship
  1680. * between the result coords and the parameters `el` and `calculate`.
  1681. *
  1682. * @param {HTMLElement} el DOM element.
  1683. * @param {Event} [e] See `getNativeEvent`.
  1684. * @param {boolean} [calculate=false] Whether to force calculate
  1685. * the coordinates but not use ones provided by browser.
  1686. * @return {UIEvent} The normalized native UIEvent.
  1687. */
  1688. function normalizeEvent(el, e, calculate) {
  1689. e = getNativeEvent(e);
  1690. if (e.zrX != null) {
  1691. return e;
  1692. }
  1693. var eventType = e.type;
  1694. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1695. if (!isTouch) {
  1696. clientToLocal(el, e, e, calculate);
  1697. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  1698. }
  1699. else {
  1700. var touch = eventType !== 'touchend'
  1701. ? e.targetTouches[0]
  1702. : e.changedTouches[0];
  1703. touch && clientToLocal(el, touch, e, calculate);
  1704. }
  1705. // Add which for click: 1 === left; 2 === middle; 3 === right; otherwise: 0;
  1706. // See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
  1707. // If e.which has been defined, it may be readonly,
  1708. // see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
  1709. var button = e.button;
  1710. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1711. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1712. }
  1713. // [Caution]: `e.which` from browser is not always reliable. For example,
  1714. // when press left button and `mousemove (pointermove)` in Edge, the `e.which`
  1715. // is 65536 and the `e.button` is -1. But the `mouseup (pointerup)` and
  1716. // `mousedown (pointerdown)` is the same as Chrome does.
  1717. return e;
  1718. }
  1719. /**
  1720. * @param {HTMLElement} el
  1721. * @param {string} name
  1722. * @param {Function} handler
  1723. * @param {Object|boolean} opt If boolean, means `opt.capture`
  1724. * @param {boolean} [opt.capture=false]
  1725. * @param {boolean} [opt.passive=false]
  1726. */
  1727. function addEventListener(el, name, handler, opt) {
  1728. if (isDomLevel2) {
  1729. // Reproduct the console warning:
  1730. // [Violation] Added non-passive event listener to a scroll-blocking <some> event.
  1731. // Consider marking event handler as 'passive' to make the page more responsive.
  1732. // Just set console log level: verbose in chrome dev tool.
  1733. // then the warning log will be printed when addEventListener called.
  1734. // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  1735. // We have not yet found a neat way to using passive. Because in zrender the dom event
  1736. // listener delegate all of the upper events of element. Some of those events need
  1737. // to prevent default. For example, the feature `preventDefaultMouseMove` of echarts.
  1738. // Before passive can be adopted, these issues should be considered:
  1739. // (1) Whether and how a zrender user specifies an event listener passive. And by default,
  1740. // passive or not.
  1741. // (2) How to tread that some zrender event listener is passive, and some is not. If
  1742. // we use other way but not preventDefault of mousewheel and touchmove, browser
  1743. // compatibility should be handled.
  1744. // var opts = (env.passiveSupported && name === 'mousewheel')
  1745. // ? {passive: true}
  1746. // // By default, the third param of el.addEventListener is `capture: false`.
  1747. // : void 0;
  1748. // el.addEventListener(name, handler /* , opts */);
  1749. el.addEventListener(name, handler, opt);
  1750. }
  1751. else {
  1752. // For simplicity, do not implement `setCapture` for IE9-.
  1753. el.attachEvent('on' + name, handler);
  1754. }
  1755. }
  1756. /**
  1757. * Parameter are the same as `addEventListener`.
  1758. *
  1759. * Notice that if a listener is registered twice, one with capture and one without,
  1760. * remove each one separately. Removal of a capturing listener does not affect a
  1761. * non-capturing version of the same listener, and vice versa.
  1762. */
  1763. function removeEventListener(el, name, handler, opt) {
  1764. if (isDomLevel2) {
  1765. el.removeEventListener(name, handler, opt);
  1766. }
  1767. else {
  1768. el.detachEvent('on' + name, handler);
  1769. }
  1770. }
  1771. /**
  1772. * preventDefault and stopPropagation.
  1773. * Notice: do not use this method in zrender. It can only be
  1774. * used by upper applications if necessary.
  1775. *
  1776. * @param {Event} e A mouse or touch event.
  1777. */
  1778. var stop = isDomLevel2
  1779. ? function (e) {
  1780. e.preventDefault();
  1781. e.stopPropagation();
  1782. e.cancelBubble = true;
  1783. }
  1784. : function (e) {
  1785. e.returnValue = false;
  1786. e.cancelBubble = true;
  1787. };
  1788. /**
  1789. * This method only works for mouseup and mousedown. The functionality is restricted
  1790. * for fault tolerance, See the `e.which` compatibility above.
  1791. *
  1792. * @param {MouseEvent} e
  1793. * @return {boolean}
  1794. */
  1795. /**
  1796. * To be removed.
  1797. * @deprecated
  1798. */
  1799. /**
  1800. * Only implements needed gestures for mobile.
  1801. */
  1802. var GestureMgr = function () {
  1803. /**
  1804. * @private
  1805. * @type {Array.<Object>}
  1806. */
  1807. this._track = [];
  1808. };
  1809. GestureMgr.prototype = {
  1810. constructor: GestureMgr,
  1811. recognize: function (event, target, root) {
  1812. this._doTrack(event, target, root);
  1813. return this._recognize(event);
  1814. },
  1815. clear: function () {
  1816. this._track.length = 0;
  1817. return this;
  1818. },
  1819. _doTrack: function (event, target, root) {
  1820. var touches = event.touches;
  1821. if (!touches) {
  1822. return;
  1823. }
  1824. var trackItem = {
  1825. points: [],
  1826. touches: [],
  1827. target: target,
  1828. event: event
  1829. };
  1830. for (var i = 0, len = touches.length; i < len; i++) {
  1831. var touch = touches[i];
  1832. var pos = clientToLocal(root, touch, {});
  1833. trackItem.points.push([pos.zrX, pos.zrY]);
  1834. trackItem.touches.push(touch);
  1835. }
  1836. this._track.push(trackItem);
  1837. },
  1838. _recognize: function (event) {
  1839. for (var eventName in recognizers) {
  1840. if (recognizers.hasOwnProperty(eventName)) {
  1841. var gestureInfo = recognizers[eventName](this._track, event);
  1842. if (gestureInfo) {
  1843. return gestureInfo;
  1844. }
  1845. }
  1846. }
  1847. }
  1848. };
  1849. function dist$1(pointPair) {
  1850. var dx = pointPair[1][0] - pointPair[0][0];
  1851. var dy = pointPair[1][1] - pointPair[0][1];
  1852. return Math.sqrt(dx * dx + dy * dy);
  1853. }
  1854. function center(pointPair) {
  1855. return [
  1856. (pointPair[0][0] + pointPair[1][0]) / 2,
  1857. (pointPair[0][1] + pointPair[1][1]) / 2
  1858. ];
  1859. }
  1860. var recognizers = {
  1861. pinch: function (track, event) {
  1862. var trackLen = track.length;
  1863. if (!trackLen) {
  1864. return;
  1865. }
  1866. var pinchEnd = (track[trackLen - 1] || {}).points;
  1867. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  1868. if (pinchPre
  1869. && pinchPre.length > 1
  1870. && pinchEnd
  1871. && pinchEnd.length > 1
  1872. ) {
  1873. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1874. !isFinite(pinchScale) && (pinchScale = 1);
  1875. event.pinchScale = pinchScale;
  1876. var pinchCenter = center(pinchEnd);
  1877. event.pinchX = pinchCenter[0];
  1878. event.pinchY = pinchCenter[1];
  1879. return {
  1880. type: 'pinch',
  1881. target: track[0].target,
  1882. event: event
  1883. };
  1884. }
  1885. }
  1886. // Only pinch currently.
  1887. };
  1888. /**
  1889. * [The interface between `Handler` and `HandlerProxy`]:
  1890. *
  1891. * The default `HandlerProxy` only support the common standard web environment
  1892. * (e.g., standalone browser, headless browser, embed browser in mobild APP, ...).
  1893. * But `HandlerProxy` can be replaced to support more non-standard environment
  1894. * (e.g., mini app), or to support more feature that the default `HandlerProxy`
  1895. * not provided (like echarts-gl did).
  1896. * So the interface between `Handler` and `HandlerProxy` should be stable. Do not
  1897. * make break changes util inevitable. The interface include the public methods
  1898. * of `Handler` and the events listed in `handlerNames` below, by which `HandlerProxy`
  1899. * drives `Handler`.
  1900. */
  1901. /**
  1902. * [Drag outside]:
  1903. *
  1904. * That is, triggering `mousemove` and `mouseup` event when the pointer is out of the
  1905. * zrender area when dragging. That is important for the improvement of the user experience
  1906. * when dragging something near the boundary without being terminated unexpectedly.
  1907. *
  1908. * We originally consider to introduce new events like `pagemovemove` and `pagemouseup`
  1909. * to resolve this issue. But some drawbacks of it is described in
  1910. * https://github.com/ecomfe/zrender/pull/536#issuecomment-560286899
  1911. *
  1912. * Instead, we referenced the specifications:
  1913. * https://www.w3.org/TR/touch-events/#the-touchmove-event
  1914. * https://www.w3.org/TR/2014/WD-DOM-Level-3-Events-20140925/#event-type-mousemove
  1915. * where the the mousemove/touchmove can be continue to fire if the user began a drag
  1916. * operation and the pointer has left the boundary. (for the mouse event, browsers
  1917. * only do it on `document` and when the pointer has left the boundary of the browser.)
  1918. *
  1919. * So the default `HandlerProxy` supports this feature similarly: if it is in the dragging
  1920. * state (see `pointerCapture` in `HandlerProxy`), the `mousemove` and `mouseup` continue
  1921. * to fire until release the pointer. That is implemented by listen to those event on
  1922. * `document`.
  1923. * If we implement some other `HandlerProxy` only for touch device, that would be easier.
  1924. * The touch event support this feature by default.
  1925. *
  1926. * Note:
  1927. * There might be some cases that the mouse event can not be
  1928. * received on `document`. For example,
  1929. * (A) `useCapture` is not supported and some user defined event listeners on the ancestor
  1930. * of zr dom throw Error .
  1931. * (B) `useCapture` is not supported Some user defined event listeners on the ancestor of
  1932. * zr dom call `stopPropagation`.
  1933. * In these cases, the `mousemove` event might be keep triggered event
  1934. * if the mouse is released. We try to reduce the side-effect in those cases.
  1935. * That is, do nothing (especially, `findHover`) in those cases. See `isOutsideBoundary`.
  1936. *
  1937. * Note:
  1938. * If `HandlerProxy` listens to `document` with `useCapture`, `HandlerProxy` needs to
  1939. * make sure `stopPropagation` and `preventDefault` doing nothing if and only if the event
  1940. * target is not zrender dom. Becuase it is dangerous to enable users to call them in
  1941. * `document` capture phase to prevent the propagation to any listener of the webpage.
  1942. * But they are needed to work when the pointer inside the zrender dom.
  1943. */
  1944. var SILENT = 'silent';
  1945. function makeEventPacket(eveType, targetInfo, event) {
  1946. return {
  1947. type: eveType,
  1948. event: event,
  1949. // target can only be an element that is not silent.
  1950. target: targetInfo.target,
  1951. // topTarget can be a silent element.
  1952. topTarget: targetInfo.topTarget,
  1953. cancelBubble: false,
  1954. offsetX: event.zrX,
  1955. offsetY: event.zrY,
  1956. gestureEvent: event.gestureEvent,
  1957. pinchX: event.pinchX,
  1958. pinchY: event.pinchY,
  1959. pinchScale: event.pinchScale,
  1960. wheelDelta: event.zrDelta,
  1961. zrByTouch: event.zrByTouch,
  1962. which: event.which,
  1963. stop: stopEvent
  1964. };
  1965. }
  1966. function stopEvent() {
  1967. stop(this.event);
  1968. }
  1969. function EmptyProxy() {}
  1970. EmptyProxy.prototype.dispose = function () {};
  1971. var handlerNames = [
  1972. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1973. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1974. ];
  1975. /**
  1976. * @alias module:zrender/Handler
  1977. * @constructor
  1978. * @extends module:zrender/mixin/Eventful
  1979. * @param {module:zrender/Storage} storage Storage instance.
  1980. * @param {module:zrender/Painter} painter Painter instance.
  1981. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  1982. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  1983. */
  1984. var Handler = function (storage, painter, proxy, painterRoot) {
  1985. Eventful.call(this);
  1986. this.storage = storage;
  1987. this.painter = painter;
  1988. this.painterRoot = painterRoot;
  1989. proxy = proxy || new EmptyProxy();
  1990. /**
  1991. * Proxy of event. can be Dom, WebGLSurface, etc.
  1992. */
  1993. this.proxy = null;
  1994. /**
  1995. * {target, topTarget, x, y}
  1996. * @private
  1997. * @type {Object}
  1998. */
  1999. this._hovered = {};
  2000. /**
  2001. * @private
  2002. * @type {Date}
  2003. */
  2004. this._lastTouchMoment;
  2005. /**
  2006. * @private
  2007. * @type {number}
  2008. */
  2009. this._lastX;
  2010. /**
  2011. * @private
  2012. * @type {number}
  2013. */
  2014. this._lastY;
  2015. /**
  2016. * @private
  2017. * @type {module:zrender/core/GestureMgr}
  2018. */
  2019. this._gestureMgr;
  2020. Draggable.call(this);
  2021. this.setHandlerProxy(proxy);
  2022. };
  2023. Handler.prototype = {
  2024. constructor: Handler,
  2025. setHandlerProxy: function (proxy) {
  2026. if (this.proxy) {
  2027. this.proxy.dispose();
  2028. }
  2029. if (proxy) {
  2030. each$1(handlerNames, function (name) {
  2031. proxy.on && proxy.on(name, this[name], this);
  2032. }, this);
  2033. // Attach handler
  2034. proxy.handler = this;
  2035. }
  2036. this.proxy = proxy;
  2037. },
  2038. mousemove: function (event) {
  2039. var x = event.zrX;
  2040. var y = event.zrY;
  2041. var isOutside = isOutsideBoundary(this, x, y);
  2042. var lastHovered = this._hovered;
  2043. var lastHoveredTarget = lastHovered.target;
  2044. // If lastHoveredTarget is removed from zr (detected by '__zr') by some API call
  2045. // (like 'setOption' or 'dispatchAction') in event handlers, we should find
  2046. // lastHovered again here. Otherwise 'mouseout' can not be triggered normally.
  2047. // See #6198.
  2048. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  2049. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  2050. lastHoveredTarget = lastHovered.target;
  2051. }
  2052. var hovered = this._hovered = isOutside ? {x: x, y: y} : this.findHover(x, y);
  2053. var hoveredTarget = hovered.target;
  2054. var proxy = this.proxy;
  2055. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2056. // Mouse out on previous hovered element
  2057. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2058. this.dispatchToElement(lastHovered, 'mouseout', event);
  2059. }
  2060. // Mouse moving on one element
  2061. this.dispatchToElement(hovered, 'mousemove', event);
  2062. // Mouse over on a new element
  2063. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2064. this.dispatchToElement(hovered, 'mouseover', event);
  2065. }
  2066. },
  2067. mouseout: function (event) {
  2068. var eventControl = event.zrEventControl;
  2069. var zrIsToLocalDOM = event.zrIsToLocalDOM;
  2070. if (eventControl !== 'only_globalout') {
  2071. this.dispatchToElement(this._hovered, 'mouseout', event);
  2072. }
  2073. if (eventControl !== 'no_globalout') {
  2074. // FIXME: if the pointer moving from the extra doms to realy "outside",
  2075. // the `globalout` should have been triggered. But currently not.
  2076. !zrIsToLocalDOM && this.trigger('globalout', {type: 'globalout', event: event});
  2077. }
  2078. },
  2079. /**
  2080. * Resize
  2081. */
  2082. resize: function (event) {
  2083. this._hovered = {};
  2084. },
  2085. /**
  2086. * Dispatch event
  2087. * @param {string} eventName
  2088. * @param {event=} eventArgs
  2089. */
  2090. dispatch: function (eventName, eventArgs) {
  2091. var handler = this[eventName];
  2092. handler && handler.call(this, eventArgs);
  2093. },
  2094. /**
  2095. * Dispose
  2096. */
  2097. dispose: function () {
  2098. this.proxy.dispose();
  2099. this.storage =
  2100. this.proxy =
  2101. this.painter = null;
  2102. },
  2103. /**
  2104. * 设置默认的cursor style
  2105. * @param {string} [cursorStyle='default'] 例如 crosshair
  2106. */
  2107. setCursorStyle: function (cursorStyle) {
  2108. var proxy = this.proxy;
  2109. proxy.setCursor && proxy.setCursor(cursorStyle);
  2110. },
  2111. /**
  2112. * 事件分发代理
  2113. *
  2114. * @private
  2115. * @param {Object} targetInfo {target, topTarget} 目标图形元素
  2116. * @param {string} eventName 事件名称
  2117. * @param {Object} event 事件对象
  2118. */
  2119. dispatchToElement: function (targetInfo, eventName, event) {
  2120. targetInfo = targetInfo || {};
  2121. var el = targetInfo.target;
  2122. if (el && el.silent) {
  2123. return;
  2124. }
  2125. var eventHandler = 'on' + eventName;
  2126. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2127. while (el) {
  2128. el[eventHandler]
  2129. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  2130. el.trigger(eventName, eventPacket);
  2131. el = el.parent;
  2132. if (eventPacket.cancelBubble) {
  2133. break;
  2134. }
  2135. }
  2136. if (!eventPacket.cancelBubble) {
  2137. // 冒泡到顶级 zrender 对象
  2138. this.trigger(eventName, eventPacket);
  2139. // 分发事件到用户自定义层
  2140. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  2141. this.painter && this.painter.eachOtherLayer(function (layer) {
  2142. if (typeof (layer[eventHandler]) === 'function') {
  2143. layer[eventHandler].call(layer, eventPacket);
  2144. }
  2145. if (layer.trigger) {
  2146. layer.trigger(eventName, eventPacket);
  2147. }
  2148. });
  2149. }
  2150. },
  2151. /**
  2152. * @private
  2153. * @param {number} x
  2154. * @param {number} y
  2155. * @param {module:zrender/graphic/Displayable} exclude
  2156. * @return {model:zrender/Element}
  2157. * @method
  2158. */
  2159. findHover: function (x, y, exclude) {
  2160. var list = this.storage.getDisplayList();
  2161. var out = {x: x, y: y};
  2162. for (var i = list.length - 1; i >= 0; i--) {
  2163. var hoverCheckResult;
  2164. if (list[i] !== exclude
  2165. // getDisplayList may include ignored item in VML mode
  2166. && !list[i].ignore
  2167. && (hoverCheckResult = isHover(list[i], x, y))
  2168. ) {
  2169. !out.topTarget && (out.topTarget = list[i]);
  2170. if (hoverCheckResult !== SILENT) {
  2171. out.target = list[i];
  2172. break;
  2173. }
  2174. }
  2175. }
  2176. return out;
  2177. },
  2178. processGesture: function (event, stage) {
  2179. if (!this._gestureMgr) {
  2180. this._gestureMgr = new GestureMgr();
  2181. }
  2182. var gestureMgr = this._gestureMgr;
  2183. stage === 'start' && gestureMgr.clear();
  2184. var gestureInfo = gestureMgr.recognize(
  2185. event,
  2186. this.findHover(event.zrX, event.zrY, null).target,
  2187. this.proxy.dom
  2188. );
  2189. stage === 'end' && gestureMgr.clear();
  2190. // Do not do any preventDefault here. Upper application do that if necessary.
  2191. if (gestureInfo) {
  2192. var type = gestureInfo.type;
  2193. event.gestureEvent = type;
  2194. this.dispatchToElement({target: gestureInfo.target}, type, gestureInfo.event);
  2195. }
  2196. }
  2197. };
  2198. // Common handlers
  2199. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2200. Handler.prototype[name] = function (event) {
  2201. var x = event.zrX;
  2202. var y = event.zrY;
  2203. var isOutside = isOutsideBoundary(this, x, y);
  2204. var hovered;
  2205. var hoveredTarget;
  2206. if (name !== 'mouseup' || !isOutside) {
  2207. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  2208. hovered = this.findHover(x, y);
  2209. hoveredTarget = hovered.target;
  2210. }
  2211. if (name === 'mousedown') {
  2212. this._downEl = hoveredTarget;
  2213. this._downPoint = [event.zrX, event.zrY];
  2214. // In case click triggered before mouseup
  2215. this._upEl = hoveredTarget;
  2216. }
  2217. else if (name === 'mouseup') {
  2218. this._upEl = hoveredTarget;
  2219. }
  2220. else if (name === 'click') {
  2221. if (this._downEl !== this._upEl
  2222. // Original click event is triggered on the whole canvas element,
  2223. // including the case that `mousedown` - `mousemove` - `mouseup`,
  2224. // which should be filtered, otherwise it will bring trouble to
  2225. // pan and zoom.
  2226. || !this._downPoint
  2227. // Arbitrary value
  2228. || dist(this._downPoint, [event.zrX, event.zrY]) > 4
  2229. ) {
  2230. return;
  2231. }
  2232. this._downPoint = null;
  2233. }
  2234. this.dispatchToElement(hovered, name, event);
  2235. };
  2236. });
  2237. function isHover(displayable, x, y) {
  2238. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2239. var el = displayable;
  2240. var isSilent;
  2241. while (el) {
  2242. // If clipped by ancestor.
  2243. // FIXME: If clipPath has neither stroke nor fill,
  2244. // el.clipPath.contain(x, y) will always return false.
  2245. if (el.clipPath && !el.clipPath.contain(x, y)) {
  2246. return false;
  2247. }
  2248. if (el.silent) {
  2249. isSilent = true;
  2250. }
  2251. el = el.parent;
  2252. }
  2253. return isSilent ? SILENT : true;
  2254. }
  2255. return false;
  2256. }
  2257. /**
  2258. * See [Drag outside].
  2259. */
  2260. function isOutsideBoundary(handlerInstance, x, y) {
  2261. var painter = handlerInstance.painter;
  2262. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2263. }
  2264. mixin(Handler, Eventful);
  2265. mixin(Handler, Draggable);
  2266. /**
  2267. * 3x2矩阵操作类
  2268. * @exports zrender/tool/matrix
  2269. */
  2270. /* global Float32Array */
  2271. var ArrayCtor$1 = typeof Float32Array === 'undefined'
  2272. ? Array
  2273. : Float32Array;
  2274. /**
  2275. * Create a identity matrix.
  2276. * @return {Float32Array|Array.<number>}
  2277. */
  2278. function create$1() {
  2279. var out = new ArrayCtor$1(6);
  2280. identity(out);
  2281. return out;
  2282. }
  2283. /**
  2284. * 设置矩阵为单位矩阵
  2285. * @param {Float32Array|Array.<number>} out
  2286. */
  2287. function identity(out) {
  2288. out[0] = 1;
  2289. out[1] = 0;
  2290. out[2] = 0;
  2291. out[3] = 1;
  2292. out[4] = 0;
  2293. out[5] = 0;
  2294. return out;
  2295. }
  2296. /**
  2297. * 复制矩阵
  2298. * @param {Float32Array|Array.<number>} out
  2299. * @param {Float32Array|Array.<number>} m
  2300. */
  2301. function copy$1(out, m) {
  2302. out[0] = m[0];
  2303. out[1] = m[1];
  2304. out[2] = m[2];
  2305. out[3] = m[3];
  2306. out[4] = m[4];
  2307. out[5] = m[5];
  2308. return out;
  2309. }
  2310. /**
  2311. * 矩阵相乘
  2312. * @param {Float32Array|Array.<number>} out
  2313. * @param {Float32Array|Array.<number>} m1
  2314. * @param {Float32Array|Array.<number>} m2
  2315. */
  2316. function mul$1(out, m1, m2) {
  2317. // Consider matrix.mul(m, m2, m);
  2318. // where out is the same as m2.
  2319. // So use temp variable to escape error.
  2320. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  2321. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  2322. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  2323. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  2324. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  2325. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  2326. out[0] = out0;
  2327. out[1] = out1;
  2328. out[2] = out2;
  2329. out[3] = out3;
  2330. out[4] = out4;
  2331. out[5] = out5;
  2332. return out;
  2333. }
  2334. /**
  2335. * 平移变换
  2336. * @param {Float32Array|Array.<number>} out
  2337. * @param {Float32Array|Array.<number>} a
  2338. * @param {Float32Array|Array.<number>} v
  2339. */
  2340. function translate(out, a, v) {
  2341. out[0] = a[0];
  2342. out[1] = a[1];
  2343. out[2] = a[2];
  2344. out[3] = a[3];
  2345. out[4] = a[4] + v[0];
  2346. out[5] = a[5] + v[1];
  2347. return out;
  2348. }
  2349. /**
  2350. * 旋转变换
  2351. * @param {Float32Array|Array.<number>} out
  2352. * @param {Float32Array|Array.<number>} a
  2353. * @param {number} rad
  2354. */
  2355. function rotate(out, a, rad) {
  2356. var aa = a[0];
  2357. var ac = a[2];
  2358. var atx = a[4];
  2359. var ab = a[1];
  2360. var ad = a[3];
  2361. var aty = a[5];
  2362. var st = Math.sin(rad);
  2363. var ct = Math.cos(rad);
  2364. out[0] = aa * ct + ab * st;
  2365. out[1] = -aa * st + ab * ct;
  2366. out[2] = ac * ct + ad * st;
  2367. out[3] = -ac * st + ct * ad;
  2368. out[4] = ct * atx + st * aty;
  2369. out[5] = ct * aty - st * atx;
  2370. return out;
  2371. }
  2372. /**
  2373. * 缩放变换
  2374. * @param {Float32Array|Array.<number>} out
  2375. * @param {Float32Array|Array.<number>} a
  2376. * @param {Float32Array|Array.<number>} v
  2377. */
  2378. function scale$1(out, a, v) {
  2379. var vx = v[0];
  2380. var vy = v[1];
  2381. out[0] = a[0] * vx;
  2382. out[1] = a[1] * vy;
  2383. out[2] = a[2] * vx;
  2384. out[3] = a[3] * vy;
  2385. out[4] = a[4] * vx;
  2386. out[5] = a[5] * vy;
  2387. return out;
  2388. }
  2389. /**
  2390. * 求逆矩阵
  2391. * @param {Float32Array|Array.<number>} out
  2392. * @param {Float32Array|Array.<number>} a
  2393. */
  2394. function invert(out, a) {
  2395. var aa = a[0];
  2396. var ac = a[2];
  2397. var atx = a[4];
  2398. var ab = a[1];
  2399. var ad = a[3];
  2400. var aty = a[5];
  2401. var det = aa * ad - ab * ac;
  2402. if (!det) {
  2403. return null;
  2404. }
  2405. det = 1.0 / det;
  2406. out[0] = ad * det;
  2407. out[1] = -ab * det;
  2408. out[2] = -ac * det;
  2409. out[3] = aa * det;
  2410. out[4] = (ac * aty - ad * atx) * det;
  2411. out[5] = (ab * atx - aa * aty) * det;
  2412. return out;
  2413. }
  2414. /**
  2415. * Clone a new matrix.
  2416. * @param {Float32Array|Array.<number>} a
  2417. */
  2418. /**
  2419. * 提供变换扩展
  2420. * @module zrender/mixin/Transformable
  2421. * @author pissang (https://www.github.com/pissang)
  2422. */
  2423. var mIdentity = identity;
  2424. var EPSILON = 5e-5;
  2425. function isNotAroundZero(val) {
  2426. return val > EPSILON || val < -EPSILON;
  2427. }
  2428. /**
  2429. * @alias module:zrender/mixin/Transformable
  2430. * @constructor
  2431. */
  2432. var Transformable = function (opts) {
  2433. opts = opts || {};
  2434. // If there are no given position, rotation, scale
  2435. if (!opts.position) {
  2436. /**
  2437. * 平移
  2438. * @type {Array.<number>}
  2439. * @default [0, 0]
  2440. */
  2441. this.position = [0, 0];
  2442. }
  2443. if (opts.rotation == null) {
  2444. /**
  2445. * 旋转
  2446. * @type {Array.<number>}
  2447. * @default 0
  2448. */
  2449. this.rotation = 0;
  2450. }
  2451. if (!opts.scale) {
  2452. /**
  2453. * 缩放
  2454. * @type {Array.<number>}
  2455. * @default [1, 1]
  2456. */
  2457. this.scale = [1, 1];
  2458. }
  2459. /**
  2460. * 旋转和缩放的原点
  2461. * @type {Array.<number>}
  2462. * @default null
  2463. */
  2464. this.origin = this.origin || null;
  2465. };
  2466. var transformableProto = Transformable.prototype;
  2467. transformableProto.transform = null;
  2468. /**
  2469. * 判断是否需要有坐标变换
  2470. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  2471. */
  2472. transformableProto.needLocalTransform = function () {
  2473. return isNotAroundZero(this.rotation)
  2474. || isNotAroundZero(this.position[0])
  2475. || isNotAroundZero(this.position[1])
  2476. || isNotAroundZero(this.scale[0] - 1)
  2477. || isNotAroundZero(this.scale[1] - 1);
  2478. };
  2479. var scaleTmp = [];
  2480. transformableProto.updateTransform = function () {
  2481. var parent = this.parent;
  2482. var parentHasTransform = parent && parent.transform;
  2483. var needLocalTransform = this.needLocalTransform();
  2484. var m = this.transform;
  2485. if (!(needLocalTransform || parentHasTransform)) {
  2486. m && mIdentity(m);
  2487. return;
  2488. }
  2489. m = m || create$1();
  2490. if (needLocalTransform) {
  2491. this.getLocalTransform(m);
  2492. }
  2493. else {
  2494. mIdentity(m);
  2495. }
  2496. // 应用父节点变换
  2497. if (parentHasTransform) {
  2498. if (needLocalTransform) {
  2499. mul$1(m, parent.transform, m);
  2500. }
  2501. else {
  2502. copy$1(m, parent.transform);
  2503. }
  2504. }
  2505. // 保存这个变换矩阵
  2506. this.transform = m;
  2507. var globalScaleRatio = this.globalScaleRatio;
  2508. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  2509. this.getGlobalScale(scaleTmp);
  2510. var relX = scaleTmp[0] < 0 ? -1 : 1;
  2511. var relY = scaleTmp[1] < 0 ? -1 : 1;
  2512. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  2513. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  2514. m[0] *= sx;
  2515. m[1] *= sx;
  2516. m[2] *= sy;
  2517. m[3] *= sy;
  2518. }
  2519. this.invTransform = this.invTransform || create$1();
  2520. invert(this.invTransform, m);
  2521. };
  2522. transformableProto.getLocalTransform = function (m) {
  2523. return Transformable.getLocalTransform(this, m);
  2524. };
  2525. /**
  2526. * 将自己的transform应用到context上
  2527. * @param {CanvasRenderingContext2D} ctx
  2528. */
  2529. transformableProto.setTransform = function (ctx) {
  2530. var m = this.transform;
  2531. var dpr = ctx.dpr || 1;
  2532. if (m) {
  2533. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  2534. }
  2535. else {
  2536. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2537. }
  2538. };
  2539. transformableProto.restoreTransform = function (ctx) {
  2540. var dpr = ctx.dpr || 1;
  2541. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2542. };
  2543. var tmpTransform = [];
  2544. var originTransform = create$1();
  2545. transformableProto.setLocalTransform = function (m) {
  2546. if (!m) {
  2547. // TODO return or set identity?
  2548. return;
  2549. }
  2550. var sx = m[0] * m[0] + m[1] * m[1];
  2551. var sy = m[2] * m[2] + m[3] * m[3];
  2552. var position = this.position;
  2553. var scale$$1 = this.scale;
  2554. if (isNotAroundZero(sx - 1)) {
  2555. sx = Math.sqrt(sx);
  2556. }
  2557. if (isNotAroundZero(sy - 1)) {
  2558. sy = Math.sqrt(sy);
  2559. }
  2560. if (m[0] < 0) {
  2561. sx = -sx;
  2562. }
  2563. if (m[3] < 0) {
  2564. sy = -sy;
  2565. }
  2566. position[0] = m[4];
  2567. position[1] = m[5];
  2568. scale$$1[0] = sx;
  2569. scale$$1[1] = sy;
  2570. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  2571. };
  2572. /**
  2573. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  2574. */
  2575. transformableProto.decomposeTransform = function () {
  2576. if (!this.transform) {
  2577. return;
  2578. }
  2579. var parent = this.parent;
  2580. var m = this.transform;
  2581. if (parent && parent.transform) {
  2582. // Get local transform and decompose them to position, scale, rotation
  2583. mul$1(tmpTransform, parent.invTransform, m);
  2584. m = tmpTransform;
  2585. }
  2586. var origin = this.origin;
  2587. if (origin && (origin[0] || origin[1])) {
  2588. originTransform[4] = origin[0];
  2589. originTransform[5] = origin[1];
  2590. mul$1(tmpTransform, m, originTransform);
  2591. tmpTransform[4] -= origin[0];
  2592. tmpTransform[5] -= origin[1];
  2593. m = tmpTransform;
  2594. }
  2595. this.setLocalTransform(m);
  2596. };
  2597. /**
  2598. * Get global scale
  2599. * @return {Array.<number>}
  2600. */
  2601. transformableProto.getGlobalScale = function (out) {
  2602. var m = this.transform;
  2603. out = out || [];
  2604. if (!m) {
  2605. out[0] = 1;
  2606. out[1] = 1;
  2607. return out;
  2608. }
  2609. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  2610. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  2611. if (m[0] < 0) {
  2612. out[0] = -out[0];
  2613. }
  2614. if (m[3] < 0) {
  2615. out[1] = -out[1];
  2616. }
  2617. return out;
  2618. };
  2619. /**
  2620. * 变换坐标位置到 shape 的局部坐标空间
  2621. * @method
  2622. * @param {number} x
  2623. * @param {number} y
  2624. * @return {Array.<number>}
  2625. */
  2626. transformableProto.transformCoordToLocal = function (x, y) {
  2627. var v2 = [x, y];
  2628. var invTransform = this.invTransform;
  2629. if (invTransform) {
  2630. applyTransform(v2, v2, invTransform);
  2631. }
  2632. return v2;
  2633. };
  2634. /**
  2635. * 变换局部坐标位置到全局坐标空间
  2636. * @method
  2637. * @param {number} x
  2638. * @param {number} y
  2639. * @return {Array.<number>}
  2640. */
  2641. transformableProto.transformCoordToGlobal = function (x, y) {
  2642. var v2 = [x, y];
  2643. var transform = this.transform;
  2644. if (transform) {
  2645. applyTransform(v2, v2, transform);
  2646. }
  2647. return v2;
  2648. };
  2649. /**
  2650. * @static
  2651. * @param {Object} target
  2652. * @param {Array.<number>} target.origin
  2653. * @param {number} target.rotation
  2654. * @param {Array.<number>} target.position
  2655. * @param {Array.<number>} [m]
  2656. */
  2657. Transformable.getLocalTransform = function (target, m) {
  2658. m = m || [];
  2659. mIdentity(m);
  2660. var origin = target.origin;
  2661. var scale$$1 = target.scale || [1, 1];
  2662. var rotation = target.rotation || 0;
  2663. var position = target.position || [0, 0];
  2664. if (origin) {
  2665. // Translate to origin
  2666. m[4] -= origin[0];
  2667. m[5] -= origin[1];
  2668. }
  2669. scale$1(m, m, scale$$1);
  2670. if (rotation) {
  2671. rotate(m, m, rotation);
  2672. }
  2673. if (origin) {
  2674. // Translate back from origin
  2675. m[4] += origin[0];
  2676. m[5] += origin[1];
  2677. }
  2678. m[4] += position[0];
  2679. m[5] += position[1];
  2680. return m;
  2681. };
  2682. /**
  2683. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  2684. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  2685. * @exports zrender/animation/easing
  2686. */
  2687. var easing = {
  2688. /**
  2689. * @param {number} k
  2690. * @return {number}
  2691. */
  2692. linear: function (k) {
  2693. return k;
  2694. },
  2695. /**
  2696. * @param {number} k
  2697. * @return {number}
  2698. */
  2699. quadraticIn: function (k) {
  2700. return k * k;
  2701. },
  2702. /**
  2703. * @param {number} k
  2704. * @return {number}
  2705. */
  2706. quadraticOut: function (k) {
  2707. return k * (2 - k);
  2708. },
  2709. /**
  2710. * @param {number} k
  2711. * @return {number}
  2712. */
  2713. quadraticInOut: function (k) {
  2714. if ((k *= 2) < 1) {
  2715. return 0.5 * k * k;
  2716. }
  2717. return -0.5 * (--k * (k - 2) - 1);
  2718. },
  2719. // 三次方的缓动(t^3)
  2720. /**
  2721. * @param {number} k
  2722. * @return {number}
  2723. */
  2724. cubicIn: function (k) {
  2725. return k * k * k;
  2726. },
  2727. /**
  2728. * @param {number} k
  2729. * @return {number}
  2730. */
  2731. cubicOut: function (k) {
  2732. return --k * k * k + 1;
  2733. },
  2734. /**
  2735. * @param {number} k
  2736. * @return {number}
  2737. */
  2738. cubicInOut: function (k) {
  2739. if ((k *= 2) < 1) {
  2740. return 0.5 * k * k * k;
  2741. }
  2742. return 0.5 * ((k -= 2) * k * k + 2);
  2743. },
  2744. // 四次方的缓动(t^4)
  2745. /**
  2746. * @param {number} k
  2747. * @return {number}
  2748. */
  2749. quarticIn: function (k) {
  2750. return k * k * k * k;
  2751. },
  2752. /**
  2753. * @param {number} k
  2754. * @return {number}
  2755. */
  2756. quarticOut: function (k) {
  2757. return 1 - (--k * k * k * k);
  2758. },
  2759. /**
  2760. * @param {number} k
  2761. * @return {number}
  2762. */
  2763. quarticInOut: function (k) {
  2764. if ((k *= 2) < 1) {
  2765. return 0.5 * k * k * k * k;
  2766. }
  2767. return -0.5 * ((k -= 2) * k * k * k - 2);
  2768. },
  2769. // 五次方的缓动(t^5)
  2770. /**
  2771. * @param {number} k
  2772. * @return {number}
  2773. */
  2774. quinticIn: function (k) {
  2775. return k * k * k * k * k;
  2776. },
  2777. /**
  2778. * @param {number} k
  2779. * @return {number}
  2780. */
  2781. quinticOut: function (k) {
  2782. return --k * k * k * k * k + 1;
  2783. },
  2784. /**
  2785. * @param {number} k
  2786. * @return {number}
  2787. */
  2788. quinticInOut: function (k) {
  2789. if ((k *= 2) < 1) {
  2790. return 0.5 * k * k * k * k * k;
  2791. }
  2792. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2793. },
  2794. // 正弦曲线的缓动(sin(t))
  2795. /**
  2796. * @param {number} k
  2797. * @return {number}
  2798. */
  2799. sinusoidalIn: function (k) {
  2800. return 1 - Math.cos(k * Math.PI / 2);
  2801. },
  2802. /**
  2803. * @param {number} k
  2804. * @return {number}
  2805. */
  2806. sinusoidalOut: function (k) {
  2807. return Math.sin(k * Math.PI / 2);
  2808. },
  2809. /**
  2810. * @param {number} k
  2811. * @return {number}
  2812. */
  2813. sinusoidalInOut: function (k) {
  2814. return 0.5 * (1 - Math.cos(Math.PI * k));
  2815. },
  2816. // 指数曲线的缓动(2^t)
  2817. /**
  2818. * @param {number} k
  2819. * @return {number}
  2820. */
  2821. exponentialIn: function (k) {
  2822. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2823. },
  2824. /**
  2825. * @param {number} k
  2826. * @return {number}
  2827. */
  2828. exponentialOut: function (k) {
  2829. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2830. },
  2831. /**
  2832. * @param {number} k
  2833. * @return {number}
  2834. */
  2835. exponentialInOut: function (k) {
  2836. if (k === 0) {
  2837. return 0;
  2838. }
  2839. if (k === 1) {
  2840. return 1;
  2841. }
  2842. if ((k *= 2) < 1) {
  2843. return 0.5 * Math.pow(1024, k - 1);
  2844. }
  2845. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2846. },
  2847. // 圆形曲线的缓动(sqrt(1-t^2))
  2848. /**
  2849. * @param {number} k
  2850. * @return {number}
  2851. */
  2852. circularIn: function (k) {
  2853. return 1 - Math.sqrt(1 - k * k);
  2854. },
  2855. /**
  2856. * @param {number} k
  2857. * @return {number}
  2858. */
  2859. circularOut: function (k) {
  2860. return Math.sqrt(1 - (--k * k));
  2861. },
  2862. /**
  2863. * @param {number} k
  2864. * @return {number}
  2865. */
  2866. circularInOut: function (k) {
  2867. if ((k *= 2) < 1) {
  2868. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2869. }
  2870. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2871. },
  2872. // 创建类似于弹簧在停止前来回振荡的动画
  2873. /**
  2874. * @param {number} k
  2875. * @return {number}
  2876. */
  2877. elasticIn: function (k) {
  2878. var s;
  2879. var a = 0.1;
  2880. var p = 0.4;
  2881. if (k === 0) {
  2882. return 0;
  2883. }
  2884. if (k === 1) {
  2885. return 1;
  2886. }
  2887. if (!a || a < 1) {
  2888. a = 1;
  2889. s = p / 4;
  2890. }
  2891. else {
  2892. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2893. }
  2894. return -(a * Math.pow(2, 10 * (k -= 1))
  2895. * Math.sin((k - s) * (2 * Math.PI) / p));
  2896. },
  2897. /**
  2898. * @param {number} k
  2899. * @return {number}
  2900. */
  2901. elasticOut: function (k) {
  2902. var s;
  2903. var a = 0.1;
  2904. var p = 0.4;
  2905. if (k === 0) {
  2906. return 0;
  2907. }
  2908. if (k === 1) {
  2909. return 1;
  2910. }
  2911. if (!a || a < 1) {
  2912. a = 1;
  2913. s = p / 4;
  2914. }
  2915. else {
  2916. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2917. }
  2918. return (a * Math.pow(2, -10 * k)
  2919. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  2920. },
  2921. /**
  2922. * @param {number} k
  2923. * @return {number}
  2924. */
  2925. elasticInOut: function (k) {
  2926. var s;
  2927. var a = 0.1;
  2928. var p = 0.4;
  2929. if (k === 0) {
  2930. return 0;
  2931. }
  2932. if (k === 1) {
  2933. return 1;
  2934. }
  2935. if (!a || a < 1) {
  2936. a = 1;
  2937. s = p / 4;
  2938. }
  2939. else {
  2940. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2941. }
  2942. if ((k *= 2) < 1) {
  2943. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  2944. * Math.sin((k - s) * (2 * Math.PI) / p));
  2945. }
  2946. return a * Math.pow(2, -10 * (k -= 1))
  2947. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  2948. },
  2949. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  2950. /**
  2951. * @param {number} k
  2952. * @return {number}
  2953. */
  2954. backIn: function (k) {
  2955. var s = 1.70158;
  2956. return k * k * ((s + 1) * k - s);
  2957. },
  2958. /**
  2959. * @param {number} k
  2960. * @return {number}
  2961. */
  2962. backOut: function (k) {
  2963. var s = 1.70158;
  2964. return --k * k * ((s + 1) * k + s) + 1;
  2965. },
  2966. /**
  2967. * @param {number} k
  2968. * @return {number}
  2969. */
  2970. backInOut: function (k) {
  2971. var s = 1.70158 * 1.525;
  2972. if ((k *= 2) < 1) {
  2973. return 0.5 * (k * k * ((s + 1) * k - s));
  2974. }
  2975. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2976. },
  2977. // 创建弹跳效果
  2978. /**
  2979. * @param {number} k
  2980. * @return {number}
  2981. */
  2982. bounceIn: function (k) {
  2983. return 1 - easing.bounceOut(1 - k);
  2984. },
  2985. /**
  2986. * @param {number} k
  2987. * @return {number}
  2988. */
  2989. bounceOut: function (k) {
  2990. if (k < (1 / 2.75)) {
  2991. return 7.5625 * k * k;
  2992. }
  2993. else if (k < (2 / 2.75)) {
  2994. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  2995. }
  2996. else if (k < (2.5 / 2.75)) {
  2997. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  2998. }
  2999. else {
  3000. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  3001. }
  3002. },
  3003. /**
  3004. * @param {number} k
  3005. * @return {number}
  3006. */
  3007. bounceInOut: function (k) {
  3008. if (k < 0.5) {
  3009. return easing.bounceIn(k * 2) * 0.5;
  3010. }
  3011. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  3012. }
  3013. };
  3014. /**
  3015. * 动画主控制器
  3016. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  3017. * @config life(1000) 动画时长
  3018. * @config delay(0) 动画延迟时间
  3019. * @config loop(true)
  3020. * @config gap(0) 循环的间隔时间
  3021. * @config onframe
  3022. * @config easing(optional)
  3023. * @config ondestroy(optional)
  3024. * @config onrestart(optional)
  3025. *
  3026. * TODO pause
  3027. */
  3028. function Clip(options) {
  3029. this._target = options.target;
  3030. // 生命周期
  3031. this._life = options.life || 1000;
  3032. // 延时
  3033. this._delay = options.delay || 0;
  3034. // 开始时间
  3035. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  3036. this._initialized = false;
  3037. // 是否循环
  3038. this.loop = options.loop == null ? false : options.loop;
  3039. this.gap = options.gap || 0;
  3040. this.easing = options.easing || 'Linear';
  3041. this.onframe = options.onframe;
  3042. this.ondestroy = options.ondestroy;
  3043. this.onrestart = options.onrestart;
  3044. this._pausedTime = 0;
  3045. this._paused = false;
  3046. }
  3047. Clip.prototype = {
  3048. constructor: Clip,
  3049. step: function (globalTime, deltaTime) {
  3050. // Set startTime on first step, or _startTime may has milleseconds different between clips
  3051. // PENDING
  3052. if (!this._initialized) {
  3053. this._startTime = globalTime + this._delay;
  3054. this._initialized = true;
  3055. }
  3056. if (this._paused) {
  3057. this._pausedTime += deltaTime;
  3058. return;
  3059. }
  3060. var percent = (globalTime - this._startTime - this._pausedTime) / this._life;
  3061. // 还没开始
  3062. if (percent < 0) {
  3063. return;
  3064. }
  3065. percent = Math.min(percent, 1);
  3066. var easing$$1 = this.easing;
  3067. var easingFunc = typeof easing$$1 === 'string' ? easing[easing$$1] : easing$$1;
  3068. var schedule = typeof easingFunc === 'function'
  3069. ? easingFunc(percent)
  3070. : percent;
  3071. this.fire('frame', schedule);
  3072. // 结束
  3073. if (percent === 1) {
  3074. if (this.loop) {
  3075. this.restart(globalTime);
  3076. // 重新开始周期
  3077. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  3078. return 'restart';
  3079. }
  3080. // 动画完成将这个控制器标识为待删除
  3081. // 在Animation.update中进行批量删除
  3082. this._needsRemove = true;
  3083. return 'destroy';
  3084. }
  3085. return null;
  3086. },
  3087. restart: function (globalTime) {
  3088. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  3089. this._startTime = globalTime - remainder + this.gap;
  3090. this._pausedTime = 0;
  3091. this._needsRemove = false;
  3092. },
  3093. fire: function (eventType, arg) {
  3094. eventType = 'on' + eventType;
  3095. if (this[eventType]) {
  3096. this[eventType](this._target, arg);
  3097. }
  3098. },
  3099. pause: function () {
  3100. this._paused = true;
  3101. },
  3102. resume: function () {
  3103. this._paused = false;
  3104. }
  3105. };
  3106. // Simple LRU cache use doubly linked list
  3107. // @module zrender/core/LRU
  3108. /**
  3109. * Simple double linked list. Compared with array, it has O(1) remove operation.
  3110. * @constructor
  3111. */
  3112. var LinkedList = function () {
  3113. /**
  3114. * @type {module:zrender/core/LRU~Entry}
  3115. */
  3116. this.head = null;
  3117. /**
  3118. * @type {module:zrender/core/LRU~Entry}
  3119. */
  3120. this.tail = null;
  3121. this._len = 0;
  3122. };
  3123. var linkedListProto = LinkedList.prototype;
  3124. /**
  3125. * Insert a new value at the tail
  3126. * @param {} val
  3127. * @return {module:zrender/core/LRU~Entry}
  3128. */
  3129. linkedListProto.insert = function (val) {
  3130. var entry = new Entry(val);
  3131. this.insertEntry(entry);
  3132. return entry;
  3133. };
  3134. /**
  3135. * Insert an entry at the tail
  3136. * @param {module:zrender/core/LRU~Entry} entry
  3137. */
  3138. linkedListProto.insertEntry = function (entry) {
  3139. if (!this.head) {
  3140. this.head = this.tail = entry;
  3141. }
  3142. else {
  3143. this.tail.next = entry;
  3144. entry.prev = this.tail;
  3145. entry.next = null;
  3146. this.tail = entry;
  3147. }
  3148. this._len++;
  3149. };
  3150. /**
  3151. * Remove entry.
  3152. * @param {module:zrender/core/LRU~Entry} entry
  3153. */
  3154. linkedListProto.remove = function (entry) {
  3155. var prev = entry.prev;
  3156. var next = entry.next;
  3157. if (prev) {
  3158. prev.next = next;
  3159. }
  3160. else {
  3161. // Is head
  3162. this.head = next;
  3163. }
  3164. if (next) {
  3165. next.prev = prev;
  3166. }
  3167. else {
  3168. // Is tail
  3169. this.tail = prev;
  3170. }
  3171. entry.next = entry.prev = null;
  3172. this._len--;
  3173. };
  3174. /**
  3175. * @return {number}
  3176. */
  3177. linkedListProto.len = function () {
  3178. return this._len;
  3179. };
  3180. /**
  3181. * Clear list
  3182. */
  3183. linkedListProto.clear = function () {
  3184. this.head = this.tail = null;
  3185. this._len = 0;
  3186. };
  3187. /**
  3188. * @constructor
  3189. * @param {} val
  3190. */
  3191. var Entry = function (val) {
  3192. /**
  3193. * @type {}
  3194. */
  3195. this.value = val;
  3196. /**
  3197. * @type {module:zrender/core/LRU~Entry}
  3198. */
  3199. this.next;
  3200. /**
  3201. * @type {module:zrender/core/LRU~Entry}
  3202. */
  3203. this.prev;
  3204. };
  3205. /**
  3206. * LRU Cache
  3207. * @constructor
  3208. * @alias module:zrender/core/LRU
  3209. */
  3210. var LRU = function (maxSize) {
  3211. this._list = new LinkedList();
  3212. this._map = {};
  3213. this._maxSize = maxSize || 10;
  3214. this._lastRemovedEntry = null;
  3215. };
  3216. var LRUProto = LRU.prototype;
  3217. /**
  3218. * @param {string} key
  3219. * @param {} value
  3220. * @return {} Removed value
  3221. */
  3222. LRUProto.put = function (key, value) {
  3223. var list = this._list;
  3224. var map = this._map;
  3225. var removed = null;
  3226. if (map[key] == null) {
  3227. var len = list.len();
  3228. // Reuse last removed entry
  3229. var entry = this._lastRemovedEntry;
  3230. if (len >= this._maxSize && len > 0) {
  3231. // Remove the least recently used
  3232. var leastUsedEntry = list.head;
  3233. list.remove(leastUsedEntry);
  3234. delete map[leastUsedEntry.key];
  3235. removed = leastUsedEntry.value;
  3236. this._lastRemovedEntry = leastUsedEntry;
  3237. }
  3238. if (entry) {
  3239. entry.value = value;
  3240. }
  3241. else {
  3242. entry = new Entry(value);
  3243. }
  3244. entry.key = key;
  3245. list.insertEntry(entry);
  3246. map[key] = entry;
  3247. }
  3248. return removed;
  3249. };
  3250. /**
  3251. * @param {string} key
  3252. * @return {}
  3253. */
  3254. LRUProto.get = function (key) {
  3255. var entry = this._map[key];
  3256. var list = this._list;
  3257. if (entry != null) {
  3258. // Put the latest used entry in the tail
  3259. if (entry !== list.tail) {
  3260. list.remove(entry);
  3261. list.insertEntry(entry);
  3262. }
  3263. return entry.value;
  3264. }
  3265. };
  3266. /**
  3267. * Clear the cache
  3268. */
  3269. LRUProto.clear = function () {
  3270. this._list.clear();
  3271. this._map = {};
  3272. };
  3273. var kCSSColorTable = {
  3274. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3275. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3276. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3277. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3278. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3279. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3280. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3281. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3282. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3283. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3284. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3285. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3286. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3287. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3288. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3289. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3290. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3291. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3292. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3293. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3294. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3295. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3296. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3297. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3298. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3299. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3300. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3301. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3302. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3303. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3304. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3305. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3306. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3307. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3308. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3309. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3310. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3311. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3312. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3313. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3314. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3315. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3316. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3317. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3318. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3319. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3320. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3321. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3322. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3323. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3324. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3325. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3326. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3327. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3328. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3329. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3330. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3331. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3332. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3333. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3334. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3335. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3336. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3337. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3338. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3339. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3340. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3341. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3342. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3343. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3344. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3345. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3346. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3347. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3348. };
  3349. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  3350. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3351. return i < 0 ? 0 : i > 255 ? 255 : i;
  3352. }
  3353. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  3354. return f < 0 ? 0 : f > 1 ? 1 : f;
  3355. }
  3356. function parseCssInt(str) { // int or percentage.
  3357. if (str.length && str.charAt(str.length - 1) === '%') {
  3358. return clampCssByte(parseFloat(str) / 100 * 255);
  3359. }
  3360. return clampCssByte(parseInt(str, 10));
  3361. }
  3362. function parseCssFloat(str) { // float or percentage.
  3363. if (str.length && str.charAt(str.length - 1) === '%') {
  3364. return clampCssFloat(parseFloat(str) / 100);
  3365. }
  3366. return clampCssFloat(parseFloat(str));
  3367. }
  3368. function cssHueToRgb(m1, m2, h) {
  3369. if (h < 0) {
  3370. h += 1;
  3371. }
  3372. else if (h > 1) {
  3373. h -= 1;
  3374. }
  3375. if (h * 6 < 1) {
  3376. return m1 + (m2 - m1) * h * 6;
  3377. }
  3378. if (h * 2 < 1) {
  3379. return m2;
  3380. }
  3381. if (h * 3 < 2) {
  3382. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3383. }
  3384. return m1;
  3385. }
  3386. function setRgba(out, r, g, b, a) {
  3387. out[0] = r;
  3388. out[1] = g;
  3389. out[2] = b;
  3390. out[3] = a;
  3391. return out;
  3392. }
  3393. function copyRgba(out, a) {
  3394. out[0] = a[0];
  3395. out[1] = a[1];
  3396. out[2] = a[2];
  3397. out[3] = a[3];
  3398. return out;
  3399. }
  3400. var colorCache = new LRU(20);
  3401. var lastRemovedArr = null;
  3402. function putToCache(colorStr, rgbaArr) {
  3403. // Reuse removed array
  3404. if (lastRemovedArr) {
  3405. copyRgba(lastRemovedArr, rgbaArr);
  3406. }
  3407. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3408. }
  3409. /**
  3410. * @param {string} colorStr
  3411. * @param {Array.<number>} out
  3412. * @return {Array.<number>}
  3413. * @memberOf module:zrender/util/color
  3414. */
  3415. function parse(colorStr, rgbaArr) {
  3416. if (!colorStr) {
  3417. return;
  3418. }
  3419. rgbaArr = rgbaArr || [];
  3420. var cached = colorCache.get(colorStr);
  3421. if (cached) {
  3422. return copyRgba(rgbaArr, cached);
  3423. }
  3424. // colorStr may be not string
  3425. colorStr = colorStr + '';
  3426. // Remove all whitespace, not compliant, but should just be more accepting.
  3427. var str = colorStr.replace(/ /g, '').toLowerCase();
  3428. // Color keywords (and transparent) lookup.
  3429. if (str in kCSSColorTable) {
  3430. copyRgba(rgbaArr, kCSSColorTable[str]);
  3431. putToCache(colorStr, rgbaArr);
  3432. return rgbaArr;
  3433. }
  3434. // #abc and #abc123 syntax.
  3435. if (str.charAt(0) === '#') {
  3436. if (str.length === 4) {
  3437. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3438. if (!(iv >= 0 && iv <= 0xfff)) {
  3439. setRgba(rgbaArr, 0, 0, 0, 1);
  3440. return; // Covers NaN.
  3441. }
  3442. setRgba(rgbaArr,
  3443. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  3444. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  3445. (iv & 0xf) | ((iv & 0xf) << 4),
  3446. 1
  3447. );
  3448. putToCache(colorStr, rgbaArr);
  3449. return rgbaArr;
  3450. }
  3451. else if (str.length === 7) {
  3452. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3453. if (!(iv >= 0 && iv <= 0xffffff)) {
  3454. setRgba(rgbaArr, 0, 0, 0, 1);
  3455. return; // Covers NaN.
  3456. }
  3457. setRgba(rgbaArr,
  3458. (iv & 0xff0000) >> 16,
  3459. (iv & 0xff00) >> 8,
  3460. iv & 0xff,
  3461. 1
  3462. );
  3463. putToCache(colorStr, rgbaArr);
  3464. return rgbaArr;
  3465. }
  3466. return;
  3467. }
  3468. var op = str.indexOf('(');
  3469. var ep = str.indexOf(')');
  3470. if (op !== -1 && ep + 1 === str.length) {
  3471. var fname = str.substr(0, op);
  3472. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3473. var alpha = 1; // To allow case fallthrough.
  3474. switch (fname) {
  3475. case 'rgba':
  3476. if (params.length !== 4) {
  3477. setRgba(rgbaArr, 0, 0, 0, 1);
  3478. return;
  3479. }
  3480. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  3481. // Fall through.
  3482. case 'rgb':
  3483. if (params.length !== 3) {
  3484. setRgba(rgbaArr, 0, 0, 0, 1);
  3485. return;
  3486. }
  3487. setRgba(rgbaArr,
  3488. parseCssInt(params[0]),
  3489. parseCssInt(params[1]),
  3490. parseCssInt(params[2]),
  3491. alpha
  3492. );
  3493. putToCache(colorStr, rgbaArr);
  3494. return rgbaArr;
  3495. case 'hsla':
  3496. if (params.length !== 4) {
  3497. setRgba(rgbaArr, 0, 0, 0, 1);
  3498. return;
  3499. }
  3500. params[3] = parseCssFloat(params[3]);
  3501. hsla2rgba(params, rgbaArr);
  3502. putToCache(colorStr, rgbaArr);
  3503. return rgbaArr;
  3504. case 'hsl':
  3505. if (params.length !== 3) {
  3506. setRgba(rgbaArr, 0, 0, 0, 1);
  3507. return;
  3508. }
  3509. hsla2rgba(params, rgbaArr);
  3510. putToCache(colorStr, rgbaArr);
  3511. return rgbaArr;
  3512. default:
  3513. return;
  3514. }
  3515. }
  3516. setRgba(rgbaArr, 0, 0, 0, 1);
  3517. return;
  3518. }
  3519. /**
  3520. * @param {Array.<number>} hsla
  3521. * @param {Array.<number>} rgba
  3522. * @return {Array.<number>} rgba
  3523. */
  3524. function hsla2rgba(hsla, rgba) {
  3525. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  3526. // NOTE(deanm): According to the CSS spec s/l should only be
  3527. // percentages, but we don't bother and let float or percentage.
  3528. var s = parseCssFloat(hsla[1]);
  3529. var l = parseCssFloat(hsla[2]);
  3530. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3531. var m1 = l * 2 - m2;
  3532. rgba = rgba || [];
  3533. setRgba(rgba,
  3534. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  3535. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  3536. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255),
  3537. 1
  3538. );
  3539. if (hsla.length === 4) {
  3540. rgba[3] = hsla[3];
  3541. }
  3542. return rgba;
  3543. }
  3544. /**
  3545. * @param {string} color
  3546. * @param {number} level
  3547. * @return {string}
  3548. * @memberOf module:zrender/util/color
  3549. */
  3550. function lift(color, level) {
  3551. var colorArr = parse(color);
  3552. if (colorArr) {
  3553. for (var i = 0; i < 3; i++) {
  3554. if (level < 0) {
  3555. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3556. }
  3557. else {
  3558. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  3559. }
  3560. if (colorArr[i] > 255) {
  3561. colorArr[i] = 255;
  3562. }
  3563. else if (color[i] < 0) {
  3564. colorArr[i] = 0;
  3565. }
  3566. }
  3567. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3568. }
  3569. }
  3570. /**
  3571. * @param {string} color
  3572. * @return {string}
  3573. * @memberOf module:zrender/util/color
  3574. */
  3575. /**
  3576. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  3577. * @param {number} normalizedValue A float between 0 and 1.
  3578. * @param {Array.<Array.<number>>} colors List of rgba color array
  3579. * @param {Array.<number>} [out] Mapped gba color array
  3580. * @return {Array.<number>} will be null/undefined if input illegal.
  3581. */
  3582. /**
  3583. * @deprecated
  3584. */
  3585. /**
  3586. * @param {number} normalizedValue A float between 0 and 1.
  3587. * @param {Array.<string>} colors Color list.
  3588. * @param {boolean=} fullOutput Default false.
  3589. * @return {(string|Object)} Result color. If fullOutput,
  3590. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  3591. * @memberOf module:zrender/util/color
  3592. */
  3593. /**
  3594. * @deprecated
  3595. */
  3596. /**
  3597. * @param {string} color
  3598. * @param {number=} h 0 ~ 360, ignore when null.
  3599. * @param {number=} s 0 ~ 1, ignore when null.
  3600. * @param {number=} l 0 ~ 1, ignore when null.
  3601. * @return {string} Color string in rgba format.
  3602. * @memberOf module:zrender/util/color
  3603. */
  3604. /**
  3605. * @param {string} color
  3606. * @param {number=} alpha 0 ~ 1
  3607. * @return {string} Color string in rgba format.
  3608. * @memberOf module:zrender/util/color
  3609. */
  3610. /**
  3611. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  3612. * @param {string} type 'rgba', 'hsva', ...
  3613. * @return {string} Result color. (If input illegal, return undefined).
  3614. */
  3615. function stringify(arrColor, type) {
  3616. if (!arrColor || !arrColor.length) {
  3617. return;
  3618. }
  3619. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3620. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3621. colorStr += ',' + arrColor[3];
  3622. }
  3623. return type + '(' + colorStr + ')';
  3624. }
  3625. /**
  3626. * @module echarts/animation/Animator
  3627. */
  3628. var arraySlice = Array.prototype.slice;
  3629. function defaultGetter(target, key) {
  3630. return target[key];
  3631. }
  3632. function defaultSetter(target, key, value) {
  3633. target[key] = value;
  3634. }
  3635. /**
  3636. * @param {number} p0
  3637. * @param {number} p1
  3638. * @param {number} percent
  3639. * @return {number}
  3640. */
  3641. function interpolateNumber(p0, p1, percent) {
  3642. return (p1 - p0) * percent + p0;
  3643. }
  3644. /**
  3645. * @param {string} p0
  3646. * @param {string} p1
  3647. * @param {number} percent
  3648. * @return {string}
  3649. */
  3650. function interpolateString(p0, p1, percent) {
  3651. return percent > 0.5 ? p1 : p0;
  3652. }
  3653. /**
  3654. * @param {Array} p0
  3655. * @param {Array} p1
  3656. * @param {number} percent
  3657. * @param {Array} out
  3658. * @param {number} arrDim
  3659. */
  3660. function interpolateArray(p0, p1, percent, out, arrDim) {
  3661. var len = p0.length;
  3662. if (arrDim === 1) {
  3663. for (var i = 0; i < len; i++) {
  3664. out[i] = interpolateNumber(p0[i], p1[i], percent);
  3665. }
  3666. }
  3667. else {
  3668. var len2 = len && p0[0].length;
  3669. for (var i = 0; i < len; i++) {
  3670. for (var j = 0; j < len2; j++) {
  3671. out[i][j] = interpolateNumber(
  3672. p0[i][j], p1[i][j], percent
  3673. );
  3674. }
  3675. }
  3676. }
  3677. }
  3678. // arr0 is source array, arr1 is target array.
  3679. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  3680. function fillArr(arr0, arr1, arrDim) {
  3681. var arr0Len = arr0.length;
  3682. var arr1Len = arr1.length;
  3683. if (arr0Len !== arr1Len) {
  3684. // FIXME Not work for TypedArray
  3685. var isPreviousLarger = arr0Len > arr1Len;
  3686. if (isPreviousLarger) {
  3687. // Cut the previous
  3688. arr0.length = arr1Len;
  3689. }
  3690. else {
  3691. // Fill the previous
  3692. for (var i = arr0Len; i < arr1Len; i++) {
  3693. arr0.push(
  3694. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  3695. );
  3696. }
  3697. }
  3698. }
  3699. // Handling NaN value
  3700. var len2 = arr0[0] && arr0[0].length;
  3701. for (var i = 0; i < arr0.length; i++) {
  3702. if (arrDim === 1) {
  3703. if (isNaN(arr0[i])) {
  3704. arr0[i] = arr1[i];
  3705. }
  3706. }
  3707. else {
  3708. for (var j = 0; j < len2; j++) {
  3709. if (isNaN(arr0[i][j])) {
  3710. arr0[i][j] = arr1[i][j];
  3711. }
  3712. }
  3713. }
  3714. }
  3715. }
  3716. /**
  3717. * @param {Array} arr0
  3718. * @param {Array} arr1
  3719. * @param {number} arrDim
  3720. * @return {boolean}
  3721. */
  3722. function isArraySame(arr0, arr1, arrDim) {
  3723. if (arr0 === arr1) {
  3724. return true;
  3725. }
  3726. var len = arr0.length;
  3727. if (len !== arr1.length) {
  3728. return false;
  3729. }
  3730. if (arrDim === 1) {
  3731. for (var i = 0; i < len; i++) {
  3732. if (arr0[i] !== arr1[i]) {
  3733. return false;
  3734. }
  3735. }
  3736. }
  3737. else {
  3738. var len2 = arr0[0].length;
  3739. for (var i = 0; i < len; i++) {
  3740. for (var j = 0; j < len2; j++) {
  3741. if (arr0[i][j] !== arr1[i][j]) {
  3742. return false;
  3743. }
  3744. }
  3745. }
  3746. }
  3747. return true;
  3748. }
  3749. /**
  3750. * Catmull Rom interpolate array
  3751. * @param {Array} p0
  3752. * @param {Array} p1
  3753. * @param {Array} p2
  3754. * @param {Array} p3
  3755. * @param {number} t
  3756. * @param {number} t2
  3757. * @param {number} t3
  3758. * @param {Array} out
  3759. * @param {number} arrDim
  3760. */
  3761. function catmullRomInterpolateArray(
  3762. p0, p1, p2, p3, t, t2, t3, out, arrDim
  3763. ) {
  3764. var len = p0.length;
  3765. if (arrDim === 1) {
  3766. for (var i = 0; i < len; i++) {
  3767. out[i] = catmullRomInterpolate(
  3768. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  3769. );
  3770. }
  3771. }
  3772. else {
  3773. var len2 = p0[0].length;
  3774. for (var i = 0; i < len; i++) {
  3775. for (var j = 0; j < len2; j++) {
  3776. out[i][j] = catmullRomInterpolate(
  3777. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  3778. t, t2, t3
  3779. );
  3780. }
  3781. }
  3782. }
  3783. }
  3784. /**
  3785. * Catmull Rom interpolate number
  3786. * @param {number} p0
  3787. * @param {number} p1
  3788. * @param {number} p2
  3789. * @param {number} p3
  3790. * @param {number} t
  3791. * @param {number} t2
  3792. * @param {number} t3
  3793. * @return {number}
  3794. */
  3795. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  3796. var v0 = (p2 - p0) * 0.5;
  3797. var v1 = (p3 - p1) * 0.5;
  3798. return (2 * (p1 - p2) + v0 + v1) * t3
  3799. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  3800. + v0 * t + p1;
  3801. }
  3802. function cloneValue(value) {
  3803. if (isArrayLike(value)) {
  3804. var len = value.length;
  3805. if (isArrayLike(value[0])) {
  3806. var ret = [];
  3807. for (var i = 0; i < len; i++) {
  3808. ret.push(arraySlice.call(value[i]));
  3809. }
  3810. return ret;
  3811. }
  3812. return arraySlice.call(value);
  3813. }
  3814. return value;
  3815. }
  3816. function rgba2String(rgba) {
  3817. rgba[0] = Math.floor(rgba[0]);
  3818. rgba[1] = Math.floor(rgba[1]);
  3819. rgba[2] = Math.floor(rgba[2]);
  3820. return 'rgba(' + rgba.join(',') + ')';
  3821. }
  3822. function getArrayDim(keyframes) {
  3823. var lastValue = keyframes[keyframes.length - 1].value;
  3824. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  3825. }
  3826. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  3827. var getter = animator._getter;
  3828. var setter = animator._setter;
  3829. var useSpline = easing === 'spline';
  3830. var trackLen = keyframes.length;
  3831. if (!trackLen) {
  3832. return;
  3833. }
  3834. // Guess data type
  3835. var firstVal = keyframes[0].value;
  3836. var isValueArray = isArrayLike(firstVal);
  3837. var isValueColor = false;
  3838. var isValueString = false;
  3839. // For vertices morphing
  3840. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  3841. var trackMaxTime;
  3842. // Sort keyframe as ascending
  3843. keyframes.sort(function (a, b) {
  3844. return a.time - b.time;
  3845. });
  3846. trackMaxTime = keyframes[trackLen - 1].time;
  3847. // Percents of each keyframe
  3848. var kfPercents = [];
  3849. // Value of each keyframe
  3850. var kfValues = [];
  3851. var prevValue = keyframes[0].value;
  3852. var isAllValueEqual = true;
  3853. for (var i = 0; i < trackLen; i++) {
  3854. kfPercents.push(keyframes[i].time / trackMaxTime);
  3855. // Assume value is a color when it is a string
  3856. var value = keyframes[i].value;
  3857. // Check if value is equal, deep check if value is array
  3858. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  3859. || (!isValueArray && value === prevValue))) {
  3860. isAllValueEqual = false;
  3861. }
  3862. prevValue = value;
  3863. // Try converting a string to a color array
  3864. if (typeof value === 'string') {
  3865. var colorArray = parse(value);
  3866. if (colorArray) {
  3867. value = colorArray;
  3868. isValueColor = true;
  3869. }
  3870. else {
  3871. isValueString = true;
  3872. }
  3873. }
  3874. kfValues.push(value);
  3875. }
  3876. if (!forceAnimate && isAllValueEqual) {
  3877. return;
  3878. }
  3879. var lastValue = kfValues[trackLen - 1];
  3880. // Polyfill array and NaN value
  3881. for (var i = 0; i < trackLen - 1; i++) {
  3882. if (isValueArray) {
  3883. fillArr(kfValues[i], lastValue, arrDim);
  3884. }
  3885. else {
  3886. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  3887. kfValues[i] = lastValue;
  3888. }
  3889. }
  3890. }
  3891. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  3892. // Cache the key of last frame to speed up when
  3893. // animation playback is sequency
  3894. var lastFrame = 0;
  3895. var lastFramePercent = 0;
  3896. var start;
  3897. var w;
  3898. var p0;
  3899. var p1;
  3900. var p2;
  3901. var p3;
  3902. if (isValueColor) {
  3903. var rgba = [0, 0, 0, 0];
  3904. }
  3905. var onframe = function (target, percent) {
  3906. // Find the range keyframes
  3907. // kf1-----kf2---------current--------kf3
  3908. // find kf2 and kf3 and do interpolation
  3909. var frame;
  3910. // In the easing function like elasticOut, percent may less than 0
  3911. if (percent < 0) {
  3912. frame = 0;
  3913. }
  3914. else if (percent < lastFramePercent) {
  3915. // Start from next key
  3916. // PENDING start from lastFrame ?
  3917. start = Math.min(lastFrame + 1, trackLen - 1);
  3918. for (frame = start; frame >= 0; frame--) {
  3919. if (kfPercents[frame] <= percent) {
  3920. break;
  3921. }
  3922. }
  3923. // PENDING really need to do this ?
  3924. frame = Math.min(frame, trackLen - 2);
  3925. }
  3926. else {
  3927. for (frame = lastFrame; frame < trackLen; frame++) {
  3928. if (kfPercents[frame] > percent) {
  3929. break;
  3930. }
  3931. }
  3932. frame = Math.min(frame - 1, trackLen - 2);
  3933. }
  3934. lastFrame = frame;
  3935. lastFramePercent = percent;
  3936. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  3937. if (range === 0) {
  3938. return;
  3939. }
  3940. else {
  3941. w = (percent - kfPercents[frame]) / range;
  3942. }
  3943. if (useSpline) {
  3944. p1 = kfValues[frame];
  3945. p0 = kfValues[frame === 0 ? frame : frame - 1];
  3946. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  3947. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  3948. if (isValueArray) {
  3949. catmullRomInterpolateArray(
  3950. p0, p1, p2, p3, w, w * w, w * w * w,
  3951. getter(target, propName),
  3952. arrDim
  3953. );
  3954. }
  3955. else {
  3956. var value;
  3957. if (isValueColor) {
  3958. value = catmullRomInterpolateArray(
  3959. p0, p1, p2, p3, w, w * w, w * w * w,
  3960. rgba, 1
  3961. );
  3962. value = rgba2String(rgba);
  3963. }
  3964. else if (isValueString) {
  3965. // String is step(0.5)
  3966. return interpolateString(p1, p2, w);
  3967. }
  3968. else {
  3969. value = catmullRomInterpolate(
  3970. p0, p1, p2, p3, w, w * w, w * w * w
  3971. );
  3972. }
  3973. setter(
  3974. target,
  3975. propName,
  3976. value
  3977. );
  3978. }
  3979. }
  3980. else {
  3981. if (isValueArray) {
  3982. interpolateArray(
  3983. kfValues[frame], kfValues[frame + 1], w,
  3984. getter(target, propName),
  3985. arrDim
  3986. );
  3987. }
  3988. else {
  3989. var value;
  3990. if (isValueColor) {
  3991. interpolateArray(
  3992. kfValues[frame], kfValues[frame + 1], w,
  3993. rgba, 1
  3994. );
  3995. value = rgba2String(rgba);
  3996. }
  3997. else if (isValueString) {
  3998. // String is step(0.5)
  3999. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  4000. }
  4001. else {
  4002. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  4003. }
  4004. setter(
  4005. target,
  4006. propName,
  4007. value
  4008. );
  4009. }
  4010. }
  4011. };
  4012. var clip = new Clip({
  4013. target: animator._target,
  4014. life: trackMaxTime,
  4015. loop: animator._loop,
  4016. delay: animator._delay,
  4017. onframe: onframe,
  4018. ondestroy: oneTrackDone
  4019. });
  4020. if (easing && easing !== 'spline') {
  4021. clip.easing = easing;
  4022. }
  4023. return clip;
  4024. }
  4025. /**
  4026. * @alias module:zrender/animation/Animator
  4027. * @constructor
  4028. * @param {Object} target
  4029. * @param {boolean} loop
  4030. * @param {Function} getter
  4031. * @param {Function} setter
  4032. */
  4033. var Animator = function (target, loop, getter, setter) {
  4034. this._tracks = {};
  4035. this._target = target;
  4036. this._loop = loop || false;
  4037. this._getter = getter || defaultGetter;
  4038. this._setter = setter || defaultSetter;
  4039. this._clipCount = 0;
  4040. this._delay = 0;
  4041. this._doneList = [];
  4042. this._onframeList = [];
  4043. this._clipList = [];
  4044. };
  4045. Animator.prototype = {
  4046. /**
  4047. * Set Animation keyframe
  4048. * @param {number} time 关键帧时间,单位是ms
  4049. * @param {Object} props 关键帧的属性值,key-value表示
  4050. * @return {module:zrender/animation/Animator}
  4051. */
  4052. when: function (time /* ms */, props) {
  4053. var tracks = this._tracks;
  4054. for (var propName in props) {
  4055. if (!props.hasOwnProperty(propName)) {
  4056. continue;
  4057. }
  4058. if (!tracks[propName]) {
  4059. tracks[propName] = [];
  4060. // Invalid value
  4061. var value = this._getter(this._target, propName);
  4062. if (value == null) {
  4063. // zrLog('Invalid property ' + propName);
  4064. continue;
  4065. }
  4066. // If time is 0
  4067. // Then props is given initialize value
  4068. // Else
  4069. // Initialize value from current prop value
  4070. if (time !== 0) {
  4071. tracks[propName].push({
  4072. time: 0,
  4073. value: cloneValue(value)
  4074. });
  4075. }
  4076. }
  4077. tracks[propName].push({
  4078. time: time,
  4079. value: props[propName]
  4080. });
  4081. }
  4082. return this;
  4083. },
  4084. /**
  4085. * 添加动画每一帧的回调函数
  4086. * @param {Function} callback
  4087. * @return {module:zrender/animation/Animator}
  4088. */
  4089. during: function (callback) {
  4090. this._onframeList.push(callback);
  4091. return this;
  4092. },
  4093. pause: function () {
  4094. for (var i = 0; i < this._clipList.length; i++) {
  4095. this._clipList[i].pause();
  4096. }
  4097. this._paused = true;
  4098. },
  4099. resume: function () {
  4100. for (var i = 0; i < this._clipList.length; i++) {
  4101. this._clipList[i].resume();
  4102. }
  4103. this._paused = false;
  4104. },
  4105. isPaused: function () {
  4106. return !!this._paused;
  4107. },
  4108. _doneCallback: function () {
  4109. // Clear all tracks
  4110. this._tracks = {};
  4111. // Clear all clips
  4112. this._clipList.length = 0;
  4113. var doneList = this._doneList;
  4114. var len = doneList.length;
  4115. for (var i = 0; i < len; i++) {
  4116. doneList[i].call(this);
  4117. }
  4118. },
  4119. /**
  4120. * Start the animation
  4121. * @param {string|Function} [easing]
  4122. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  4123. * @param {boolean} forceAnimate
  4124. * @return {module:zrender/animation/Animator}
  4125. */
  4126. start: function (easing, forceAnimate) {
  4127. var self = this;
  4128. var clipCount = 0;
  4129. var oneTrackDone = function () {
  4130. clipCount--;
  4131. if (!clipCount) {
  4132. self._doneCallback();
  4133. }
  4134. };
  4135. var lastClip;
  4136. for (var propName in this._tracks) {
  4137. if (!this._tracks.hasOwnProperty(propName)) {
  4138. continue;
  4139. }
  4140. var clip = createTrackClip(
  4141. this, easing, oneTrackDone,
  4142. this._tracks[propName], propName, forceAnimate
  4143. );
  4144. if (clip) {
  4145. this._clipList.push(clip);
  4146. clipCount++;
  4147. // If start after added to animation
  4148. if (this.animation) {
  4149. this.animation.addClip(clip);
  4150. }
  4151. lastClip = clip;
  4152. }
  4153. }
  4154. // Add during callback on the last clip
  4155. if (lastClip) {
  4156. var oldOnFrame = lastClip.onframe;
  4157. lastClip.onframe = function (target, percent) {
  4158. oldOnFrame(target, percent);
  4159. for (var i = 0; i < self._onframeList.length; i++) {
  4160. self._onframeList[i](target, percent);
  4161. }
  4162. };
  4163. }
  4164. // This optimization will help the case that in the upper application
  4165. // the view may be refreshed frequently, where animation will be
  4166. // called repeatly but nothing changed.
  4167. if (!clipCount) {
  4168. this._doneCallback();
  4169. }
  4170. return this;
  4171. },
  4172. /**
  4173. * Stop animation
  4174. * @param {boolean} forwardToLast If move to last frame before stop
  4175. */
  4176. stop: function (forwardToLast) {
  4177. var clipList = this._clipList;
  4178. var animation = this.animation;
  4179. for (var i = 0; i < clipList.length; i++) {
  4180. var clip = clipList[i];
  4181. if (forwardToLast) {
  4182. // Move to last frame before stop
  4183. clip.onframe(this._target, 1);
  4184. }
  4185. animation && animation.removeClip(clip);
  4186. }
  4187. clipList.length = 0;
  4188. },
  4189. /**
  4190. * Set when animation delay starts
  4191. * @param {number} time 单位ms
  4192. * @return {module:zrender/animation/Animator}
  4193. */
  4194. delay: function (time) {
  4195. this._delay = time;
  4196. return this;
  4197. },
  4198. /**
  4199. * Add callback for animation end
  4200. * @param {Function} cb
  4201. * @return {module:zrender/animation/Animator}
  4202. */
  4203. done: function (cb) {
  4204. if (cb) {
  4205. this._doneList.push(cb);
  4206. }
  4207. return this;
  4208. },
  4209. /**
  4210. * @return {Array.<module:zrender/animation/Clip>}
  4211. */
  4212. getClips: function () {
  4213. return this._clipList;
  4214. }
  4215. };
  4216. var dpr = 1;
  4217. // If in browser environment
  4218. if (typeof window !== 'undefined') {
  4219. dpr = Math.max(window.devicePixelRatio || 1, 1);
  4220. }
  4221. /**
  4222. * config默认配置项
  4223. * @exports zrender/config
  4224. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  4225. */
  4226. /**
  4227. * Debug log mode:
  4228. * 0: Do nothing, for release.
  4229. * 1: console.error, for debug.
  4230. */
  4231. var debugMode = 0;
  4232. // retina 屏幕优化
  4233. var devicePixelRatio = dpr;
  4234. var logError = function () {
  4235. };
  4236. if (debugMode === 1) {
  4237. logError = console.error;
  4238. }
  4239. var logError$1 = logError;
  4240. /**
  4241. * @alias module:zrender/mixin/Animatable
  4242. * @constructor
  4243. */
  4244. var Animatable = function () {
  4245. /**
  4246. * @type {Array.<module:zrender/animation/Animator>}
  4247. * @readOnly
  4248. */
  4249. this.animators = [];
  4250. };
  4251. Animatable.prototype = {
  4252. constructor: Animatable,
  4253. /**
  4254. * 动画
  4255. *
  4256. * @param {string} path The path to fetch value from object, like 'a.b.c'.
  4257. * @param {boolean} [loop] Whether to loop animation.
  4258. * @return {module:zrender/animation/Animator}
  4259. * @example:
  4260. * el.animate('style', false)
  4261. * .when(1000, {x: 10} )
  4262. * .done(function(){ // Animation done })
  4263. * .start()
  4264. */
  4265. animate: function (path, loop) {
  4266. var target;
  4267. var animatingShape = false;
  4268. var el = this;
  4269. var zr = this.__zr;
  4270. if (path) {
  4271. var pathSplitted = path.split('.');
  4272. var prop = el;
  4273. // If animating shape
  4274. animatingShape = pathSplitted[0] === 'shape';
  4275. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  4276. if (!prop) {
  4277. continue;
  4278. }
  4279. prop = prop[pathSplitted[i]];
  4280. }
  4281. if (prop) {
  4282. target = prop;
  4283. }
  4284. }
  4285. else {
  4286. target = el;
  4287. }
  4288. if (!target) {
  4289. logError$1(
  4290. 'Property "'
  4291. + path
  4292. + '" is not existed in element '
  4293. + el.id
  4294. );
  4295. return;
  4296. }
  4297. var animators = el.animators;
  4298. var animator = new Animator(target, loop);
  4299. animator.during(function (target) {
  4300. el.dirty(animatingShape);
  4301. })
  4302. .done(function () {
  4303. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  4304. animators.splice(indexOf(animators, animator), 1);
  4305. });
  4306. animators.push(animator);
  4307. // If animate after added to the zrender
  4308. if (zr) {
  4309. zr.animation.addAnimator(animator);
  4310. }
  4311. return animator;
  4312. },
  4313. /**
  4314. * 停止动画
  4315. * @param {boolean} forwardToLast If move to last frame before stop
  4316. */
  4317. stopAnimation: function (forwardToLast) {
  4318. var animators = this.animators;
  4319. var len = animators.length;
  4320. for (var i = 0; i < len; i++) {
  4321. animators[i].stop(forwardToLast);
  4322. }
  4323. animators.length = 0;
  4324. return this;
  4325. },
  4326. /**
  4327. * Caution: this method will stop previous animation.
  4328. * So do not use this method to one element twice before
  4329. * animation starts, unless you know what you are doing.
  4330. * @param {Object} target
  4331. * @param {number} [time=500] Time in ms
  4332. * @param {string} [easing='linear']
  4333. * @param {number} [delay=0]
  4334. * @param {Function} [callback]
  4335. * @param {Function} [forceAnimate] Prevent stop animation and callback
  4336. * immediently when target values are the same as current values.
  4337. *
  4338. * @example
  4339. * // Animate position
  4340. * el.animateTo({
  4341. * position: [10, 10]
  4342. * }, function () { // done })
  4343. *
  4344. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  4345. * el.animateTo({
  4346. * shape: {
  4347. * width: 500
  4348. * },
  4349. * style: {
  4350. * fill: 'red'
  4351. * }
  4352. * position: [10, 10]
  4353. * }, 100, 100, 'cubicOut', function () { // done })
  4354. */
  4355. // TODO Return animation key
  4356. animateTo: function (target, time, delay, easing, callback, forceAnimate) {
  4357. animateTo(this, target, time, delay, easing, callback, forceAnimate);
  4358. },
  4359. /**
  4360. * Animate from the target state to current state.
  4361. * The params and the return value are the same as `this.animateTo`.
  4362. */
  4363. animateFrom: function (target, time, delay, easing, callback, forceAnimate) {
  4364. animateTo(this, target, time, delay, easing, callback, forceAnimate, true);
  4365. }
  4366. };
  4367. function animateTo(animatable, target, time, delay, easing, callback, forceAnimate, reverse) {
  4368. // animateTo(target, time, easing, callback);
  4369. if (isString(delay)) {
  4370. callback = easing;
  4371. easing = delay;
  4372. delay = 0;
  4373. }
  4374. // animateTo(target, time, delay, callback);
  4375. else if (isFunction$1(easing)) {
  4376. callback = easing;
  4377. easing = 'linear';
  4378. delay = 0;
  4379. }
  4380. // animateTo(target, time, callback);
  4381. else if (isFunction$1(delay)) {
  4382. callback = delay;
  4383. delay = 0;
  4384. }
  4385. // animateTo(target, callback)
  4386. else if (isFunction$1(time)) {
  4387. callback = time;
  4388. time = 500;
  4389. }
  4390. // animateTo(target)
  4391. else if (!time) {
  4392. time = 500;
  4393. }
  4394. // Stop all previous animations
  4395. animatable.stopAnimation();
  4396. animateToShallow(animatable, '', animatable, target, time, delay, reverse);
  4397. // Animators may be removed immediately after start
  4398. // if there is nothing to animate
  4399. var animators = animatable.animators.slice();
  4400. var count = animators.length;
  4401. function done() {
  4402. count--;
  4403. if (!count) {
  4404. callback && callback();
  4405. }
  4406. }
  4407. // No animators. This should be checked before animators[i].start(),
  4408. // because 'done' may be executed immediately if no need to animate.
  4409. if (!count) {
  4410. callback && callback();
  4411. }
  4412. // Start after all animators created
  4413. // Incase any animator is done immediately when all animation properties are not changed
  4414. for (var i = 0; i < animators.length; i++) {
  4415. animators[i]
  4416. .done(done)
  4417. .start(easing, forceAnimate);
  4418. }
  4419. }
  4420. /**
  4421. * @param {string} path=''
  4422. * @param {Object} source=animatable
  4423. * @param {Object} target
  4424. * @param {number} [time=500]
  4425. * @param {number} [delay=0]
  4426. * @param {boolean} [reverse] If `true`, animate
  4427. * from the `target` to current state.
  4428. *
  4429. * @example
  4430. * // Animate position
  4431. * el._animateToShallow({
  4432. * position: [10, 10]
  4433. * })
  4434. *
  4435. * // Animate shape, style and position in 100ms, delayed 100ms
  4436. * el._animateToShallow({
  4437. * shape: {
  4438. * width: 500
  4439. * },
  4440. * style: {
  4441. * fill: 'red'
  4442. * }
  4443. * position: [10, 10]
  4444. * }, 100, 100)
  4445. */
  4446. function animateToShallow(animatable, path, source, target, time, delay, reverse) {
  4447. var objShallow = {};
  4448. var propertyCount = 0;
  4449. for (var name in target) {
  4450. if (!target.hasOwnProperty(name)) {
  4451. continue;
  4452. }
  4453. if (source[name] != null) {
  4454. if (isObject$1(target[name]) && !isArrayLike(target[name])) {
  4455. animateToShallow(
  4456. animatable,
  4457. path ? path + '.' + name : name,
  4458. source[name],
  4459. target[name],
  4460. time,
  4461. delay,
  4462. reverse
  4463. );
  4464. }
  4465. else {
  4466. if (reverse) {
  4467. objShallow[name] = source[name];
  4468. setAttrByPath(animatable, path, name, target[name]);
  4469. }
  4470. else {
  4471. objShallow[name] = target[name];
  4472. }
  4473. propertyCount++;
  4474. }
  4475. }
  4476. else if (target[name] != null && !reverse) {
  4477. setAttrByPath(animatable, path, name, target[name]);
  4478. }
  4479. }
  4480. if (propertyCount > 0) {
  4481. animatable.animate(path, false)
  4482. .when(time == null ? 500 : time, objShallow)
  4483. .delay(delay || 0);
  4484. }
  4485. }
  4486. function setAttrByPath(el, path, name, value) {
  4487. // Attr directly if not has property
  4488. // FIXME, if some property not needed for element ?
  4489. if (!path) {
  4490. el.attr(name, value);
  4491. }
  4492. else {
  4493. // Only support set shape or style
  4494. var props = {};
  4495. props[path] = {};
  4496. props[path][name] = value;
  4497. el.attr(props);
  4498. }
  4499. }
  4500. /**
  4501. * @alias module:zrender/Element
  4502. * @constructor
  4503. * @extends {module:zrender/mixin/Animatable}
  4504. * @extends {module:zrender/mixin/Transformable}
  4505. * @extends {module:zrender/mixin/Eventful}
  4506. */
  4507. var Element = function (opts) { // jshint ignore:line
  4508. Transformable.call(this, opts);
  4509. Eventful.call(this, opts);
  4510. Animatable.call(this, opts);
  4511. /**
  4512. * 画布元素ID
  4513. * @type {string}
  4514. */
  4515. this.id = opts.id || guid();
  4516. };
  4517. Element.prototype = {
  4518. /**
  4519. * 元素类型
  4520. * Element type
  4521. * @type {string}
  4522. */
  4523. type: 'element',
  4524. /**
  4525. * 元素名字
  4526. * Element name
  4527. * @type {string}
  4528. */
  4529. name: '',
  4530. /**
  4531. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  4532. * ZRender instance will be assigned when element is associated with zrender
  4533. * @name module:/zrender/Element#__zr
  4534. * @type {module:zrender/ZRender}
  4535. */
  4536. __zr: null,
  4537. /**
  4538. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  4539. * If ignore drawing and events of the element object
  4540. * @name module:/zrender/Element#ignore
  4541. * @type {boolean}
  4542. * @default false
  4543. */
  4544. ignore: false,
  4545. /**
  4546. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  4547. * 该路径会继承被裁减对象的变换
  4548. * @type {module:zrender/graphic/Path}
  4549. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  4550. * @readOnly
  4551. */
  4552. clipPath: null,
  4553. /**
  4554. * 是否是 Group
  4555. * @type {boolean}
  4556. */
  4557. isGroup: false,
  4558. /**
  4559. * Drift element
  4560. * @param {number} dx dx on the global space
  4561. * @param {number} dy dy on the global space
  4562. */
  4563. drift: function (dx, dy) {
  4564. switch (this.draggable) {
  4565. case 'horizontal':
  4566. dy = 0;
  4567. break;
  4568. case 'vertical':
  4569. dx = 0;
  4570. break;
  4571. }
  4572. var m = this.transform;
  4573. if (!m) {
  4574. m = this.transform = [1, 0, 0, 1, 0, 0];
  4575. }
  4576. m[4] += dx;
  4577. m[5] += dy;
  4578. this.decomposeTransform();
  4579. this.dirty(false);
  4580. },
  4581. /**
  4582. * Hook before update
  4583. */
  4584. beforeUpdate: function () {},
  4585. /**
  4586. * Hook after update
  4587. */
  4588. afterUpdate: function () {},
  4589. /**
  4590. * Update each frame
  4591. */
  4592. update: function () {
  4593. this.updateTransform();
  4594. },
  4595. /**
  4596. * @param {Function} cb
  4597. * @param {} context
  4598. */
  4599. traverse: function (cb, context) {},
  4600. /**
  4601. * @protected
  4602. */
  4603. attrKV: function (key, value) {
  4604. if (key === 'position' || key === 'scale' || key === 'origin') {
  4605. // Copy the array
  4606. if (value) {
  4607. var target = this[key];
  4608. if (!target) {
  4609. target = this[key] = [];
  4610. }
  4611. target[0] = value[0];
  4612. target[1] = value[1];
  4613. }
  4614. }
  4615. else {
  4616. this[key] = value;
  4617. }
  4618. },
  4619. /**
  4620. * Hide the element
  4621. */
  4622. hide: function () {
  4623. this.ignore = true;
  4624. this.__zr && this.__zr.refresh();
  4625. },
  4626. /**
  4627. * Show the element
  4628. */
  4629. show: function () {
  4630. this.ignore = false;
  4631. this.__zr && this.__zr.refresh();
  4632. },
  4633. /**
  4634. * @param {string|Object} key
  4635. * @param {*} value
  4636. */
  4637. attr: function (key, value) {
  4638. if (typeof key === 'string') {
  4639. this.attrKV(key, value);
  4640. }
  4641. else if (isObject$1(key)) {
  4642. for (var name in key) {
  4643. if (key.hasOwnProperty(name)) {
  4644. this.attrKV(name, key[name]);
  4645. }
  4646. }
  4647. }
  4648. this.dirty(false);
  4649. return this;
  4650. },
  4651. /**
  4652. * @param {module:zrender/graphic/Path} clipPath
  4653. */
  4654. setClipPath: function (clipPath) {
  4655. var zr = this.__zr;
  4656. if (zr) {
  4657. clipPath.addSelfToZr(zr);
  4658. }
  4659. // Remove previous clip path
  4660. if (this.clipPath && this.clipPath !== clipPath) {
  4661. this.removeClipPath();
  4662. }
  4663. this.clipPath = clipPath;
  4664. clipPath.__zr = zr;
  4665. clipPath.__clipTarget = this;
  4666. this.dirty(false);
  4667. },
  4668. /**
  4669. */
  4670. removeClipPath: function () {
  4671. var clipPath = this.clipPath;
  4672. if (clipPath) {
  4673. if (clipPath.__zr) {
  4674. clipPath.removeSelfFromZr(clipPath.__zr);
  4675. }
  4676. clipPath.__zr = null;
  4677. clipPath.__clipTarget = null;
  4678. this.clipPath = null;
  4679. this.dirty(false);
  4680. }
  4681. },
  4682. /**
  4683. * Add self from zrender instance.
  4684. * Not recursively because it will be invoked when element added to storage.
  4685. * @param {module:zrender/ZRender} zr
  4686. */
  4687. addSelfToZr: function (zr) {
  4688. this.__zr = zr;
  4689. // 添加动画
  4690. var animators = this.animators;
  4691. if (animators) {
  4692. for (var i = 0; i < animators.length; i++) {
  4693. zr.animation.addAnimator(animators[i]);
  4694. }
  4695. }
  4696. if (this.clipPath) {
  4697. this.clipPath.addSelfToZr(zr);
  4698. }
  4699. },
  4700. /**
  4701. * Remove self from zrender instance.
  4702. * Not recursively because it will be invoked when element added to storage.
  4703. * @param {module:zrender/ZRender} zr
  4704. */
  4705. removeSelfFromZr: function (zr) {
  4706. this.__zr = null;
  4707. // 移除动画
  4708. var animators = this.animators;
  4709. if (animators) {
  4710. for (var i = 0; i < animators.length; i++) {
  4711. zr.animation.removeAnimator(animators[i]);
  4712. }
  4713. }
  4714. if (this.clipPath) {
  4715. this.clipPath.removeSelfFromZr(zr);
  4716. }
  4717. }
  4718. };
  4719. mixin(Element, Animatable);
  4720. mixin(Element, Transformable);
  4721. mixin(Element, Eventful);
  4722. /**
  4723. * @module echarts/core/BoundingRect
  4724. */
  4725. var v2ApplyTransform = applyTransform;
  4726. var mathMin = Math.min;
  4727. var mathMax = Math.max;
  4728. /**
  4729. * @alias module:echarts/core/BoundingRect
  4730. */
  4731. function BoundingRect(x, y, width, height) {
  4732. if (width < 0) {
  4733. x = x + width;
  4734. width = -width;
  4735. }
  4736. if (height < 0) {
  4737. y = y + height;
  4738. height = -height;
  4739. }
  4740. /**
  4741. * @type {number}
  4742. */
  4743. this.x = x;
  4744. /**
  4745. * @type {number}
  4746. */
  4747. this.y = y;
  4748. /**
  4749. * @type {number}
  4750. */
  4751. this.width = width;
  4752. /**
  4753. * @type {number}
  4754. */
  4755. this.height = height;
  4756. }
  4757. BoundingRect.prototype = {
  4758. constructor: BoundingRect,
  4759. /**
  4760. * @param {module:echarts/core/BoundingRect} other
  4761. */
  4762. union: function (other) {
  4763. var x = mathMin(other.x, this.x);
  4764. var y = mathMin(other.y, this.y);
  4765. this.width = mathMax(
  4766. other.x + other.width,
  4767. this.x + this.width
  4768. ) - x;
  4769. this.height = mathMax(
  4770. other.y + other.height,
  4771. this.y + this.height
  4772. ) - y;
  4773. this.x = x;
  4774. this.y = y;
  4775. },
  4776. /**
  4777. * @param {Array.<number>} m
  4778. * @methods
  4779. */
  4780. applyTransform: (function () {
  4781. var lt = [];
  4782. var rb = [];
  4783. var lb = [];
  4784. var rt = [];
  4785. return function (m) {
  4786. // In case usage like this
  4787. // el.getBoundingRect().applyTransform(el.transform)
  4788. // And element has no transform
  4789. if (!m) {
  4790. return;
  4791. }
  4792. lt[0] = lb[0] = this.x;
  4793. lt[1] = rt[1] = this.y;
  4794. rb[0] = rt[0] = this.x + this.width;
  4795. rb[1] = lb[1] = this.y + this.height;
  4796. v2ApplyTransform(lt, lt, m);
  4797. v2ApplyTransform(rb, rb, m);
  4798. v2ApplyTransform(lb, lb, m);
  4799. v2ApplyTransform(rt, rt, m);
  4800. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4801. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4802. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4803. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4804. this.width = maxX - this.x;
  4805. this.height = maxY - this.y;
  4806. };
  4807. })(),
  4808. /**
  4809. * Calculate matrix of transforming from self to target rect
  4810. * @param {module:zrender/core/BoundingRect} b
  4811. * @return {Array.<number>}
  4812. */
  4813. calculateTransform: function (b) {
  4814. var a = this;
  4815. var sx = b.width / a.width;
  4816. var sy = b.height / a.height;
  4817. var m = create$1();
  4818. // 矩阵右乘
  4819. translate(m, m, [-a.x, -a.y]);
  4820. scale$1(m, m, [sx, sy]);
  4821. translate(m, m, [b.x, b.y]);
  4822. return m;
  4823. },
  4824. /**
  4825. * @param {(module:echarts/core/BoundingRect|Object)} b
  4826. * @return {boolean}
  4827. */
  4828. intersect: function (b) {
  4829. if (!b) {
  4830. return false;
  4831. }
  4832. if (!(b instanceof BoundingRect)) {
  4833. // Normalize negative width/height.
  4834. b = BoundingRect.create(b);
  4835. }
  4836. var a = this;
  4837. var ax0 = a.x;
  4838. var ax1 = a.x + a.width;
  4839. var ay0 = a.y;
  4840. var ay1 = a.y + a.height;
  4841. var bx0 = b.x;
  4842. var bx1 = b.x + b.width;
  4843. var by0 = b.y;
  4844. var by1 = b.y + b.height;
  4845. return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4846. },
  4847. contain: function (x, y) {
  4848. var rect = this;
  4849. return x >= rect.x
  4850. && x <= (rect.x + rect.width)
  4851. && y >= rect.y
  4852. && y <= (rect.y + rect.height);
  4853. },
  4854. /**
  4855. * @return {module:echarts/core/BoundingRect}
  4856. */
  4857. clone: function () {
  4858. return new BoundingRect(this.x, this.y, this.width, this.height);
  4859. },
  4860. /**
  4861. * Copy from another rect
  4862. */
  4863. copy: function (other) {
  4864. this.x = other.x;
  4865. this.y = other.y;
  4866. this.width = other.width;
  4867. this.height = other.height;
  4868. },
  4869. plain: function () {
  4870. return {
  4871. x: this.x,
  4872. y: this.y,
  4873. width: this.width,
  4874. height: this.height
  4875. };
  4876. }
  4877. };
  4878. /**
  4879. * @param {Object|module:zrender/core/BoundingRect} rect
  4880. * @param {number} rect.x
  4881. * @param {number} rect.y
  4882. * @param {number} rect.width
  4883. * @param {number} rect.height
  4884. * @return {module:zrender/core/BoundingRect}
  4885. */
  4886. BoundingRect.create = function (rect) {
  4887. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4888. };
  4889. /**
  4890. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  4891. * @module zrender/graphic/Group
  4892. * @example
  4893. * var Group = require('zrender/container/Group');
  4894. * var Circle = require('zrender/graphic/shape/Circle');
  4895. * var g = new Group();
  4896. * g.position[0] = 100;
  4897. * g.position[1] = 100;
  4898. * g.add(new Circle({
  4899. * style: {
  4900. * x: 100,
  4901. * y: 100,
  4902. * r: 20,
  4903. * }
  4904. * }));
  4905. * zr.add(g);
  4906. */
  4907. /**
  4908. * @alias module:zrender/graphic/Group
  4909. * @constructor
  4910. * @extends module:zrender/mixin/Transformable
  4911. * @extends module:zrender/mixin/Eventful
  4912. */
  4913. var Group = function (opts) {
  4914. opts = opts || {};
  4915. Element.call(this, opts);
  4916. for (var key in opts) {
  4917. if (opts.hasOwnProperty(key)) {
  4918. this[key] = opts[key];
  4919. }
  4920. }
  4921. this._children = [];
  4922. this.__storage = null;
  4923. this.__dirty = true;
  4924. };
  4925. Group.prototype = {
  4926. constructor: Group,
  4927. isGroup: true,
  4928. /**
  4929. * @type {string}
  4930. */
  4931. type: 'group',
  4932. /**
  4933. * 所有子孙元素是否响应鼠标事件
  4934. * @name module:/zrender/container/Group#silent
  4935. * @type {boolean}
  4936. * @default false
  4937. */
  4938. silent: false,
  4939. /**
  4940. * @return {Array.<module:zrender/Element>}
  4941. */
  4942. children: function () {
  4943. return this._children.slice();
  4944. },
  4945. /**
  4946. * 获取指定 index 的儿子节点
  4947. * @param {number} idx
  4948. * @return {module:zrender/Element}
  4949. */
  4950. childAt: function (idx) {
  4951. return this._children[idx];
  4952. },
  4953. /**
  4954. * 获取指定名字的儿子节点
  4955. * @param {string} name
  4956. * @return {module:zrender/Element}
  4957. */
  4958. childOfName: function (name) {
  4959. var children = this._children;
  4960. for (var i = 0; i < children.length; i++) {
  4961. if (children[i].name === name) {
  4962. return children[i];
  4963. }
  4964. }
  4965. },
  4966. /**
  4967. * @return {number}
  4968. */
  4969. childCount: function () {
  4970. return this._children.length;
  4971. },
  4972. /**
  4973. * 添加子节点到最后
  4974. * @param {module:zrender/Element} child
  4975. */
  4976. add: function (child) {
  4977. if (child && child !== this && child.parent !== this) {
  4978. this._children.push(child);
  4979. this._doAdd(child);
  4980. }
  4981. return this;
  4982. },
  4983. /**
  4984. * 添加子节点在 nextSibling 之前
  4985. * @param {module:zrender/Element} child
  4986. * @param {module:zrender/Element} nextSibling
  4987. */
  4988. addBefore: function (child, nextSibling) {
  4989. if (child && child !== this && child.parent !== this
  4990. && nextSibling && nextSibling.parent === this) {
  4991. var children = this._children;
  4992. var idx = children.indexOf(nextSibling);
  4993. if (idx >= 0) {
  4994. children.splice(idx, 0, child);
  4995. this._doAdd(child);
  4996. }
  4997. }
  4998. return this;
  4999. },
  5000. _doAdd: function (child) {
  5001. if (child.parent) {
  5002. child.parent.remove(child);
  5003. }
  5004. child.parent = this;
  5005. var storage = this.__storage;
  5006. var zr = this.__zr;
  5007. if (storage && storage !== child.__storage) {
  5008. storage.addToStorage(child);
  5009. if (child instanceof Group) {
  5010. child.addChildrenToStorage(storage);
  5011. }
  5012. }
  5013. zr && zr.refresh();
  5014. },
  5015. /**
  5016. * 移除子节点
  5017. * @param {module:zrender/Element} child
  5018. */
  5019. remove: function (child) {
  5020. var zr = this.__zr;
  5021. var storage = this.__storage;
  5022. var children = this._children;
  5023. var idx = indexOf(children, child);
  5024. if (idx < 0) {
  5025. return this;
  5026. }
  5027. children.splice(idx, 1);
  5028. child.parent = null;
  5029. if (storage) {
  5030. storage.delFromStorage(child);
  5031. if (child instanceof Group) {
  5032. child.delChildrenFromStorage(storage);
  5033. }
  5034. }
  5035. zr && zr.refresh();
  5036. return this;
  5037. },
  5038. /**
  5039. * 移除所有子节点
  5040. */
  5041. removeAll: function () {
  5042. var children = this._children;
  5043. var storage = this.__storage;
  5044. var child;
  5045. var i;
  5046. for (i = 0; i < children.length; i++) {
  5047. child = children[i];
  5048. if (storage) {
  5049. storage.delFromStorage(child);
  5050. if (child instanceof Group) {
  5051. child.delChildrenFromStorage(storage);
  5052. }
  5053. }
  5054. child.parent = null;
  5055. }
  5056. children.length = 0;
  5057. return this;
  5058. },
  5059. /**
  5060. * 遍历所有子节点
  5061. * @param {Function} cb
  5062. * @param {} context
  5063. */
  5064. eachChild: function (cb, context) {
  5065. var children = this._children;
  5066. for (var i = 0; i < children.length; i++) {
  5067. var child = children[i];
  5068. cb.call(context, child, i);
  5069. }
  5070. return this;
  5071. },
  5072. /**
  5073. * 深度优先遍历所有子孙节点
  5074. * @param {Function} cb
  5075. * @param {} context
  5076. */
  5077. traverse: function (cb, context) {
  5078. for (var i = 0; i < this._children.length; i++) {
  5079. var child = this._children[i];
  5080. cb.call(context, child);
  5081. if (child.type === 'group') {
  5082. child.traverse(cb, context);
  5083. }
  5084. }
  5085. return this;
  5086. },
  5087. addChildrenToStorage: function (storage) {
  5088. for (var i = 0; i < this._children.length; i++) {
  5089. var child = this._children[i];
  5090. storage.addToStorage(child);
  5091. if (child instanceof Group) {
  5092. child.addChildrenToStorage(storage);
  5093. }
  5094. }
  5095. },
  5096. delChildrenFromStorage: function (storage) {
  5097. for (var i = 0; i < this._children.length; i++) {
  5098. var child = this._children[i];
  5099. storage.delFromStorage(child);
  5100. if (child instanceof Group) {
  5101. child.delChildrenFromStorage(storage);
  5102. }
  5103. }
  5104. },
  5105. dirty: function () {
  5106. this.__dirty = true;
  5107. this.__zr && this.__zr.refresh();
  5108. return this;
  5109. },
  5110. /**
  5111. * @return {module:zrender/core/BoundingRect}
  5112. */
  5113. getBoundingRect: function (includeChildren) {
  5114. // TODO Caching
  5115. var rect = null;
  5116. var tmpRect = new BoundingRect(0, 0, 0, 0);
  5117. var children = includeChildren || this._children;
  5118. var tmpMat = [];
  5119. for (var i = 0; i < children.length; i++) {
  5120. var child = children[i];
  5121. if (child.ignore || child.invisible) {
  5122. continue;
  5123. }
  5124. var childRect = child.getBoundingRect();
  5125. var transform = child.getLocalTransform(tmpMat);
  5126. // TODO
  5127. // The boundingRect cacluated by transforming original
  5128. // rect may be bigger than the actual bundingRect when rotation
  5129. // is used. (Consider a circle rotated aginst its center, where
  5130. // the actual boundingRect should be the same as that not be
  5131. // rotated.) But we can not find better approach to calculate
  5132. // actual boundingRect yet, considering performance.
  5133. if (transform) {
  5134. tmpRect.copy(childRect);
  5135. tmpRect.applyTransform(transform);
  5136. rect = rect || tmpRect.clone();
  5137. rect.union(tmpRect);
  5138. }
  5139. else {
  5140. rect = rect || childRect.clone();
  5141. rect.union(childRect);
  5142. }
  5143. }
  5144. return rect || tmpRect;
  5145. }
  5146. };
  5147. inherits(Group, Element);
  5148. // https://github.com/mziccard/node-timsort
  5149. var DEFAULT_MIN_MERGE = 32;
  5150. var DEFAULT_MIN_GALLOPING = 7;
  5151. function minRunLength(n) {
  5152. var r = 0;
  5153. while (n >= DEFAULT_MIN_MERGE) {
  5154. r |= n & 1;
  5155. n >>= 1;
  5156. }
  5157. return n + r;
  5158. }
  5159. function makeAscendingRun(array, lo, hi, compare) {
  5160. var runHi = lo + 1;
  5161. if (runHi === hi) {
  5162. return 1;
  5163. }
  5164. if (compare(array[runHi++], array[lo]) < 0) {
  5165. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  5166. runHi++;
  5167. }
  5168. reverseRun(array, lo, runHi);
  5169. }
  5170. else {
  5171. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  5172. runHi++;
  5173. }
  5174. }
  5175. return runHi - lo;
  5176. }
  5177. function reverseRun(array, lo, hi) {
  5178. hi--;
  5179. while (lo < hi) {
  5180. var t = array[lo];
  5181. array[lo++] = array[hi];
  5182. array[hi--] = t;
  5183. }
  5184. }
  5185. function binaryInsertionSort(array, lo, hi, start, compare) {
  5186. if (start === lo) {
  5187. start++;
  5188. }
  5189. for (; start < hi; start++) {
  5190. var pivot = array[start];
  5191. var left = lo;
  5192. var right = start;
  5193. var mid;
  5194. while (left < right) {
  5195. mid = left + right >>> 1;
  5196. if (compare(pivot, array[mid]) < 0) {
  5197. right = mid;
  5198. }
  5199. else {
  5200. left = mid + 1;
  5201. }
  5202. }
  5203. var n = start - left;
  5204. switch (n) {
  5205. case 3:
  5206. array[left + 3] = array[left + 2];
  5207. case 2:
  5208. array[left + 2] = array[left + 1];
  5209. case 1:
  5210. array[left + 1] = array[left];
  5211. break;
  5212. default:
  5213. while (n > 0) {
  5214. array[left + n] = array[left + n - 1];
  5215. n--;
  5216. }
  5217. }
  5218. array[left] = pivot;
  5219. }
  5220. }
  5221. function gallopLeft(value, array, start, length, hint, compare) {
  5222. var lastOffset = 0;
  5223. var maxOffset = 0;
  5224. var offset = 1;
  5225. if (compare(value, array[start + hint]) > 0) {
  5226. maxOffset = length - hint;
  5227. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  5228. lastOffset = offset;
  5229. offset = (offset << 1) + 1;
  5230. if (offset <= 0) {
  5231. offset = maxOffset;
  5232. }
  5233. }
  5234. if (offset > maxOffset) {
  5235. offset = maxOffset;
  5236. }
  5237. lastOffset += hint;
  5238. offset += hint;
  5239. }
  5240. else {
  5241. maxOffset = hint + 1;
  5242. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  5243. lastOffset = offset;
  5244. offset = (offset << 1) + 1;
  5245. if (offset <= 0) {
  5246. offset = maxOffset;
  5247. }
  5248. }
  5249. if (offset > maxOffset) {
  5250. offset = maxOffset;
  5251. }
  5252. var tmp = lastOffset;
  5253. lastOffset = hint - offset;
  5254. offset = hint - tmp;
  5255. }
  5256. lastOffset++;
  5257. while (lastOffset < offset) {
  5258. var m = lastOffset + (offset - lastOffset >>> 1);
  5259. if (compare(value, array[start + m]) > 0) {
  5260. lastOffset = m + 1;
  5261. }
  5262. else {
  5263. offset = m;
  5264. }
  5265. }
  5266. return offset;
  5267. }
  5268. function gallopRight(value, array, start, length, hint, compare) {
  5269. var lastOffset = 0;
  5270. var maxOffset = 0;
  5271. var offset = 1;
  5272. if (compare(value, array[start + hint]) < 0) {
  5273. maxOffset = hint + 1;
  5274. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  5275. lastOffset = offset;
  5276. offset = (offset << 1) + 1;
  5277. if (offset <= 0) {
  5278. offset = maxOffset;
  5279. }
  5280. }
  5281. if (offset > maxOffset) {
  5282. offset = maxOffset;
  5283. }
  5284. var tmp = lastOffset;
  5285. lastOffset = hint - offset;
  5286. offset = hint - tmp;
  5287. }
  5288. else {
  5289. maxOffset = length - hint;
  5290. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  5291. lastOffset = offset;
  5292. offset = (offset << 1) + 1;
  5293. if (offset <= 0) {
  5294. offset = maxOffset;
  5295. }
  5296. }
  5297. if (offset > maxOffset) {
  5298. offset = maxOffset;
  5299. }
  5300. lastOffset += hint;
  5301. offset += hint;
  5302. }
  5303. lastOffset++;
  5304. while (lastOffset < offset) {
  5305. var m = lastOffset + (offset - lastOffset >>> 1);
  5306. if (compare(value, array[start + m]) < 0) {
  5307. offset = m;
  5308. }
  5309. else {
  5310. lastOffset = m + 1;
  5311. }
  5312. }
  5313. return offset;
  5314. }
  5315. function TimSort(array, compare) {
  5316. var minGallop = DEFAULT_MIN_GALLOPING;
  5317. var runStart;
  5318. var runLength;
  5319. var stackSize = 0;
  5320. var tmp = [];
  5321. runStart = [];
  5322. runLength = [];
  5323. function pushRun(_runStart, _runLength) {
  5324. runStart[stackSize] = _runStart;
  5325. runLength[stackSize] = _runLength;
  5326. stackSize += 1;
  5327. }
  5328. function mergeRuns() {
  5329. while (stackSize > 1) {
  5330. var n = stackSize - 2;
  5331. if (
  5332. (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1])
  5333. || (n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1])
  5334. ) {
  5335. if (runLength[n - 1] < runLength[n + 1]) {
  5336. n--;
  5337. }
  5338. }
  5339. else if (runLength[n] > runLength[n + 1]) {
  5340. break;
  5341. }
  5342. mergeAt(n);
  5343. }
  5344. }
  5345. function forceMergeRuns() {
  5346. while (stackSize > 1) {
  5347. var n = stackSize - 2;
  5348. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  5349. n--;
  5350. }
  5351. mergeAt(n);
  5352. }
  5353. }
  5354. function mergeAt(i) {
  5355. var start1 = runStart[i];
  5356. var length1 = runLength[i];
  5357. var start2 = runStart[i + 1];
  5358. var length2 = runLength[i + 1];
  5359. runLength[i] = length1 + length2;
  5360. if (i === stackSize - 3) {
  5361. runStart[i + 1] = runStart[i + 2];
  5362. runLength[i + 1] = runLength[i + 2];
  5363. }
  5364. stackSize--;
  5365. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  5366. start1 += k;
  5367. length1 -= k;
  5368. if (length1 === 0) {
  5369. return;
  5370. }
  5371. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  5372. if (length2 === 0) {
  5373. return;
  5374. }
  5375. if (length1 <= length2) {
  5376. mergeLow(start1, length1, start2, length2);
  5377. }
  5378. else {
  5379. mergeHigh(start1, length1, start2, length2);
  5380. }
  5381. }
  5382. function mergeLow(start1, length1, start2, length2) {
  5383. var i = 0;
  5384. for (i = 0; i < length1; i++) {
  5385. tmp[i] = array[start1 + i];
  5386. }
  5387. var cursor1 = 0;
  5388. var cursor2 = start2;
  5389. var dest = start1;
  5390. array[dest++] = array[cursor2++];
  5391. if (--length2 === 0) {
  5392. for (i = 0; i < length1; i++) {
  5393. array[dest + i] = tmp[cursor1 + i];
  5394. }
  5395. return;
  5396. }
  5397. if (length1 === 1) {
  5398. for (i = 0; i < length2; i++) {
  5399. array[dest + i] = array[cursor2 + i];
  5400. }
  5401. array[dest + length2] = tmp[cursor1];
  5402. return;
  5403. }
  5404. var _minGallop = minGallop;
  5405. var count1;
  5406. var count2;
  5407. var exit;
  5408. while (1) {
  5409. count1 = 0;
  5410. count2 = 0;
  5411. exit = false;
  5412. do {
  5413. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  5414. array[dest++] = array[cursor2++];
  5415. count2++;
  5416. count1 = 0;
  5417. if (--length2 === 0) {
  5418. exit = true;
  5419. break;
  5420. }
  5421. }
  5422. else {
  5423. array[dest++] = tmp[cursor1++];
  5424. count1++;
  5425. count2 = 0;
  5426. if (--length1 === 1) {
  5427. exit = true;
  5428. break;
  5429. }
  5430. }
  5431. } while ((count1 | count2) < _minGallop);
  5432. if (exit) {
  5433. break;
  5434. }
  5435. do {
  5436. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  5437. if (count1 !== 0) {
  5438. for (i = 0; i < count1; i++) {
  5439. array[dest + i] = tmp[cursor1 + i];
  5440. }
  5441. dest += count1;
  5442. cursor1 += count1;
  5443. length1 -= count1;
  5444. if (length1 <= 1) {
  5445. exit = true;
  5446. break;
  5447. }
  5448. }
  5449. array[dest++] = array[cursor2++];
  5450. if (--length2 === 0) {
  5451. exit = true;
  5452. break;
  5453. }
  5454. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  5455. if (count2 !== 0) {
  5456. for (i = 0; i < count2; i++) {
  5457. array[dest + i] = array[cursor2 + i];
  5458. }
  5459. dest += count2;
  5460. cursor2 += count2;
  5461. length2 -= count2;
  5462. if (length2 === 0) {
  5463. exit = true;
  5464. break;
  5465. }
  5466. }
  5467. array[dest++] = tmp[cursor1++];
  5468. if (--length1 === 1) {
  5469. exit = true;
  5470. break;
  5471. }
  5472. _minGallop--;
  5473. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5474. if (exit) {
  5475. break;
  5476. }
  5477. if (_minGallop < 0) {
  5478. _minGallop = 0;
  5479. }
  5480. _minGallop += 2;
  5481. }
  5482. minGallop = _minGallop;
  5483. minGallop < 1 && (minGallop = 1);
  5484. if (length1 === 1) {
  5485. for (i = 0; i < length2; i++) {
  5486. array[dest + i] = array[cursor2 + i];
  5487. }
  5488. array[dest + length2] = tmp[cursor1];
  5489. }
  5490. else if (length1 === 0) {
  5491. throw new Error();
  5492. // throw new Error('mergeLow preconditions were not respected');
  5493. }
  5494. else {
  5495. for (i = 0; i < length1; i++) {
  5496. array[dest + i] = tmp[cursor1 + i];
  5497. }
  5498. }
  5499. }
  5500. function mergeHigh(start1, length1, start2, length2) {
  5501. var i = 0;
  5502. for (i = 0; i < length2; i++) {
  5503. tmp[i] = array[start2 + i];
  5504. }
  5505. var cursor1 = start1 + length1 - 1;
  5506. var cursor2 = length2 - 1;
  5507. var dest = start2 + length2 - 1;
  5508. var customCursor = 0;
  5509. var customDest = 0;
  5510. array[dest--] = array[cursor1--];
  5511. if (--length1 === 0) {
  5512. customCursor = dest - (length2 - 1);
  5513. for (i = 0; i < length2; i++) {
  5514. array[customCursor + i] = tmp[i];
  5515. }
  5516. return;
  5517. }
  5518. if (length2 === 1) {
  5519. dest -= length1;
  5520. cursor1 -= length1;
  5521. customDest = dest + 1;
  5522. customCursor = cursor1 + 1;
  5523. for (i = length1 - 1; i >= 0; i--) {
  5524. array[customDest + i] = array[customCursor + i];
  5525. }
  5526. array[dest] = tmp[cursor2];
  5527. return;
  5528. }
  5529. var _minGallop = minGallop;
  5530. while (true) {
  5531. var count1 = 0;
  5532. var count2 = 0;
  5533. var exit = false;
  5534. do {
  5535. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  5536. array[dest--] = array[cursor1--];
  5537. count1++;
  5538. count2 = 0;
  5539. if (--length1 === 0) {
  5540. exit = true;
  5541. break;
  5542. }
  5543. }
  5544. else {
  5545. array[dest--] = tmp[cursor2--];
  5546. count2++;
  5547. count1 = 0;
  5548. if (--length2 === 1) {
  5549. exit = true;
  5550. break;
  5551. }
  5552. }
  5553. } while ((count1 | count2) < _minGallop);
  5554. if (exit) {
  5555. break;
  5556. }
  5557. do {
  5558. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  5559. if (count1 !== 0) {
  5560. dest -= count1;
  5561. cursor1 -= count1;
  5562. length1 -= count1;
  5563. customDest = dest + 1;
  5564. customCursor = cursor1 + 1;
  5565. for (i = count1 - 1; i >= 0; i--) {
  5566. array[customDest + i] = array[customCursor + i];
  5567. }
  5568. if (length1 === 0) {
  5569. exit = true;
  5570. break;
  5571. }
  5572. }
  5573. array[dest--] = tmp[cursor2--];
  5574. if (--length2 === 1) {
  5575. exit = true;
  5576. break;
  5577. }
  5578. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  5579. if (count2 !== 0) {
  5580. dest -= count2;
  5581. cursor2 -= count2;
  5582. length2 -= count2;
  5583. customDest = dest + 1;
  5584. customCursor = cursor2 + 1;
  5585. for (i = 0; i < count2; i++) {
  5586. array[customDest + i] = tmp[customCursor + i];
  5587. }
  5588. if (length2 <= 1) {
  5589. exit = true;
  5590. break;
  5591. }
  5592. }
  5593. array[dest--] = array[cursor1--];
  5594. if (--length1 === 0) {
  5595. exit = true;
  5596. break;
  5597. }
  5598. _minGallop--;
  5599. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5600. if (exit) {
  5601. break;
  5602. }
  5603. if (_minGallop < 0) {
  5604. _minGallop = 0;
  5605. }
  5606. _minGallop += 2;
  5607. }
  5608. minGallop = _minGallop;
  5609. if (minGallop < 1) {
  5610. minGallop = 1;
  5611. }
  5612. if (length2 === 1) {
  5613. dest -= length1;
  5614. cursor1 -= length1;
  5615. customDest = dest + 1;
  5616. customCursor = cursor1 + 1;
  5617. for (i = length1 - 1; i >= 0; i--) {
  5618. array[customDest + i] = array[customCursor + i];
  5619. }
  5620. array[dest] = tmp[cursor2];
  5621. }
  5622. else if (length2 === 0) {
  5623. throw new Error();
  5624. // throw new Error('mergeHigh preconditions were not respected');
  5625. }
  5626. else {
  5627. customCursor = dest - (length2 - 1);
  5628. for (i = 0; i < length2; i++) {
  5629. array[customCursor + i] = tmp[i];
  5630. }
  5631. }
  5632. }
  5633. this.mergeRuns = mergeRuns;
  5634. this.forceMergeRuns = forceMergeRuns;
  5635. this.pushRun = pushRun;
  5636. }
  5637. function sort(array, compare, lo, hi) {
  5638. if (!lo) {
  5639. lo = 0;
  5640. }
  5641. if (!hi) {
  5642. hi = array.length;
  5643. }
  5644. var remaining = hi - lo;
  5645. if (remaining < 2) {
  5646. return;
  5647. }
  5648. var runLength = 0;
  5649. if (remaining < DEFAULT_MIN_MERGE) {
  5650. runLength = makeAscendingRun(array, lo, hi, compare);
  5651. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  5652. return;
  5653. }
  5654. var ts = new TimSort(array, compare);
  5655. var minRun = minRunLength(remaining);
  5656. do {
  5657. runLength = makeAscendingRun(array, lo, hi, compare);
  5658. if (runLength < minRun) {
  5659. var force = remaining;
  5660. if (force > minRun) {
  5661. force = minRun;
  5662. }
  5663. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  5664. runLength = force;
  5665. }
  5666. ts.pushRun(lo, runLength);
  5667. ts.mergeRuns();
  5668. remaining -= runLength;
  5669. lo += runLength;
  5670. } while (remaining !== 0);
  5671. ts.forceMergeRuns();
  5672. }
  5673. // Use timsort because in most case elements are partially sorted
  5674. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  5675. function shapeCompareFunc(a, b) {
  5676. if (a.zlevel === b.zlevel) {
  5677. if (a.z === b.z) {
  5678. // if (a.z2 === b.z2) {
  5679. // // FIXME Slow has renderidx compare
  5680. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  5681. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  5682. // return a.__renderidx - b.__renderidx;
  5683. // }
  5684. return a.z2 - b.z2;
  5685. }
  5686. return a.z - b.z;
  5687. }
  5688. return a.zlevel - b.zlevel;
  5689. }
  5690. /**
  5691. * 内容仓库 (M)
  5692. * @alias module:zrender/Storage
  5693. * @constructor
  5694. */
  5695. var Storage = function () { // jshint ignore:line
  5696. this._roots = [];
  5697. this._displayList = [];
  5698. this._displayListLen = 0;
  5699. };
  5700. Storage.prototype = {
  5701. constructor: Storage,
  5702. /**
  5703. * @param {Function} cb
  5704. *
  5705. */
  5706. traverse: function (cb, context) {
  5707. for (var i = 0; i < this._roots.length; i++) {
  5708. this._roots[i].traverse(cb, context);
  5709. }
  5710. },
  5711. /**
  5712. * 返回所有图形的绘制队列
  5713. * @param {boolean} [update=false] 是否在返回前更新该数组
  5714. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  5715. *
  5716. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  5717. * @return {Array.<module:zrender/graphic/Displayable>}
  5718. */
  5719. getDisplayList: function (update, includeIgnore) {
  5720. includeIgnore = includeIgnore || false;
  5721. if (update) {
  5722. this.updateDisplayList(includeIgnore);
  5723. }
  5724. return this._displayList;
  5725. },
  5726. /**
  5727. * 更新图形的绘制队列。
  5728. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  5729. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  5730. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  5731. */
  5732. updateDisplayList: function (includeIgnore) {
  5733. this._displayListLen = 0;
  5734. var roots = this._roots;
  5735. var displayList = this._displayList;
  5736. for (var i = 0, len = roots.length; i < len; i++) {
  5737. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  5738. }
  5739. displayList.length = this._displayListLen;
  5740. env$1.canvasSupported && sort(displayList, shapeCompareFunc);
  5741. },
  5742. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  5743. if (el.ignore && !includeIgnore) {
  5744. return;
  5745. }
  5746. el.beforeUpdate();
  5747. if (el.__dirty) {
  5748. el.update();
  5749. }
  5750. el.afterUpdate();
  5751. var userSetClipPath = el.clipPath;
  5752. if (userSetClipPath) {
  5753. // FIXME 效率影响
  5754. if (clipPaths) {
  5755. clipPaths = clipPaths.slice();
  5756. }
  5757. else {
  5758. clipPaths = [];
  5759. }
  5760. var currentClipPath = userSetClipPath;
  5761. var parentClipPath = el;
  5762. // Recursively add clip path
  5763. while (currentClipPath) {
  5764. // clipPath 的变换是基于使用这个 clipPath 的元素
  5765. currentClipPath.parent = parentClipPath;
  5766. currentClipPath.updateTransform();
  5767. clipPaths.push(currentClipPath);
  5768. parentClipPath = currentClipPath;
  5769. currentClipPath = currentClipPath.clipPath;
  5770. }
  5771. }
  5772. if (el.isGroup) {
  5773. var children = el._children;
  5774. for (var i = 0; i < children.length; i++) {
  5775. var child = children[i];
  5776. // Force to mark as dirty if group is dirty
  5777. // FIXME __dirtyPath ?
  5778. if (el.__dirty) {
  5779. child.__dirty = true;
  5780. }
  5781. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  5782. }
  5783. // Mark group clean here
  5784. el.__dirty = false;
  5785. }
  5786. else {
  5787. el.__clipPaths = clipPaths;
  5788. this._displayList[this._displayListLen++] = el;
  5789. }
  5790. },
  5791. /**
  5792. * 添加图形(Shape)或者组(Group)到根节点
  5793. * @param {module:zrender/Element} el
  5794. */
  5795. addRoot: function (el) {
  5796. if (el.__storage === this) {
  5797. return;
  5798. }
  5799. if (el instanceof Group) {
  5800. el.addChildrenToStorage(this);
  5801. }
  5802. this.addToStorage(el);
  5803. this._roots.push(el);
  5804. },
  5805. /**
  5806. * 删除指定的图形(Shape)或者组(Group)
  5807. * @param {string|Array.<string>} [el] 如果为空清空整个Storage
  5808. */
  5809. delRoot: function (el) {
  5810. if (el == null) {
  5811. // 不指定el清空
  5812. for (var i = 0; i < this._roots.length; i++) {
  5813. var root = this._roots[i];
  5814. if (root instanceof Group) {
  5815. root.delChildrenFromStorage(this);
  5816. }
  5817. }
  5818. this._roots = [];
  5819. this._displayList = [];
  5820. this._displayListLen = 0;
  5821. return;
  5822. }
  5823. if (el instanceof Array) {
  5824. for (var i = 0, l = el.length; i < l; i++) {
  5825. this.delRoot(el[i]);
  5826. }
  5827. return;
  5828. }
  5829. var idx = indexOf(this._roots, el);
  5830. if (idx >= 0) {
  5831. this.delFromStorage(el);
  5832. this._roots.splice(idx, 1);
  5833. if (el instanceof Group) {
  5834. el.delChildrenFromStorage(this);
  5835. }
  5836. }
  5837. },
  5838. addToStorage: function (el) {
  5839. if (el) {
  5840. el.__storage = this;
  5841. el.dirty(false);
  5842. }
  5843. return this;
  5844. },
  5845. delFromStorage: function (el) {
  5846. if (el) {
  5847. el.__storage = null;
  5848. }
  5849. return this;
  5850. },
  5851. /**
  5852. * 清空并且释放Storage
  5853. */
  5854. dispose: function () {
  5855. this._renderList =
  5856. this._roots = null;
  5857. },
  5858. displayableSortFunc: shapeCompareFunc
  5859. };
  5860. var SHADOW_PROPS = {
  5861. 'shadowBlur': 1,
  5862. 'shadowOffsetX': 1,
  5863. 'shadowOffsetY': 1,
  5864. 'textShadowBlur': 1,
  5865. 'textShadowOffsetX': 1,
  5866. 'textShadowOffsetY': 1,
  5867. 'textBoxShadowBlur': 1,
  5868. 'textBoxShadowOffsetX': 1,
  5869. 'textBoxShadowOffsetY': 1
  5870. };
  5871. var fixShadow = function (ctx, propName, value) {
  5872. if (SHADOW_PROPS.hasOwnProperty(propName)) {
  5873. return value *= ctx.dpr;
  5874. }
  5875. return value;
  5876. };
  5877. var ContextCachedBy = {
  5878. NONE: 0,
  5879. STYLE_BIND: 1,
  5880. PLAIN_TEXT: 2
  5881. };
  5882. // Avoid confused with 0/false.
  5883. var WILL_BE_RESTORED = 9;
  5884. var STYLE_COMMON_PROPS = [
  5885. ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
  5886. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  5887. ];
  5888. // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  5889. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  5890. var Style = function (opts) {
  5891. this.extendFrom(opts, false);
  5892. };
  5893. function createLinearGradient(ctx, obj, rect) {
  5894. var x = obj.x == null ? 0 : obj.x;
  5895. var x2 = obj.x2 == null ? 1 : obj.x2;
  5896. var y = obj.y == null ? 0 : obj.y;
  5897. var y2 = obj.y2 == null ? 0 : obj.y2;
  5898. if (!obj.global) {
  5899. x = x * rect.width + rect.x;
  5900. x2 = x2 * rect.width + rect.x;
  5901. y = y * rect.height + rect.y;
  5902. y2 = y2 * rect.height + rect.y;
  5903. }
  5904. // Fix NaN when rect is Infinity
  5905. x = isNaN(x) ? 0 : x;
  5906. x2 = isNaN(x2) ? 1 : x2;
  5907. y = isNaN(y) ? 0 : y;
  5908. y2 = isNaN(y2) ? 0 : y2;
  5909. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  5910. return canvasGradient;
  5911. }
  5912. function createRadialGradient(ctx, obj, rect) {
  5913. var width = rect.width;
  5914. var height = rect.height;
  5915. var min = Math.min(width, height);
  5916. var x = obj.x == null ? 0.5 : obj.x;
  5917. var y = obj.y == null ? 0.5 : obj.y;
  5918. var r = obj.r == null ? 0.5 : obj.r;
  5919. if (!obj.global) {
  5920. x = x * width + rect.x;
  5921. y = y * height + rect.y;
  5922. r = r * min;
  5923. }
  5924. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  5925. return canvasGradient;
  5926. }
  5927. Style.prototype = {
  5928. constructor: Style,
  5929. /**
  5930. * @type {string}
  5931. */
  5932. fill: '#000',
  5933. /**
  5934. * @type {string}
  5935. */
  5936. stroke: null,
  5937. /**
  5938. * @type {number}
  5939. */
  5940. opacity: 1,
  5941. /**
  5942. * @type {number}
  5943. */
  5944. fillOpacity: null,
  5945. /**
  5946. * @type {number}
  5947. */
  5948. strokeOpacity: null,
  5949. /**
  5950. * `true` is not supported.
  5951. * `false`/`null`/`undefined` are the same.
  5952. * `false` is used to remove lineDash in some
  5953. * case that `null`/`undefined` can not be set.
  5954. * (e.g., emphasis.lineStyle in echarts)
  5955. * @type {Array.<number>|boolean}
  5956. */
  5957. lineDash: null,
  5958. /**
  5959. * @type {number}
  5960. */
  5961. lineDashOffset: 0,
  5962. /**
  5963. * @type {number}
  5964. */
  5965. shadowBlur: 0,
  5966. /**
  5967. * @type {number}
  5968. */
  5969. shadowOffsetX: 0,
  5970. /**
  5971. * @type {number}
  5972. */
  5973. shadowOffsetY: 0,
  5974. /**
  5975. * @type {number}
  5976. */
  5977. lineWidth: 1,
  5978. /**
  5979. * If stroke ignore scale
  5980. * @type {Boolean}
  5981. */
  5982. strokeNoScale: false,
  5983. // Bounding rect text configuration
  5984. // Not affected by element transform
  5985. /**
  5986. * @type {string}
  5987. */
  5988. text: null,
  5989. /**
  5990. * If `fontSize` or `fontFamily` exists, `font` will be reset by
  5991. * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.
  5992. * So do not visit it directly in upper application (like echarts),
  5993. * but use `contain/text#makeFont` instead.
  5994. * @type {string}
  5995. */
  5996. font: null,
  5997. /**
  5998. * The same as font. Use font please.
  5999. * @deprecated
  6000. * @type {string}
  6001. */
  6002. textFont: null,
  6003. /**
  6004. * It helps merging respectively, rather than parsing an entire font string.
  6005. * @type {string}
  6006. */
  6007. fontStyle: null,
  6008. /**
  6009. * It helps merging respectively, rather than parsing an entire font string.
  6010. * @type {string}
  6011. */
  6012. fontWeight: null,
  6013. /**
  6014. * It helps merging respectively, rather than parsing an entire font string.
  6015. * Should be 12 but not '12px'.
  6016. * @type {number}
  6017. */
  6018. fontSize: null,
  6019. /**
  6020. * It helps merging respectively, rather than parsing an entire font string.
  6021. * @type {string}
  6022. */
  6023. fontFamily: null,
  6024. /**
  6025. * Reserved for special functinality, like 'hr'.
  6026. * @type {string}
  6027. */
  6028. textTag: null,
  6029. /**
  6030. * @type {string}
  6031. */
  6032. textFill: '#000',
  6033. /**
  6034. * @type {string}
  6035. */
  6036. textStroke: null,
  6037. /**
  6038. * @type {number}
  6039. */
  6040. textWidth: null,
  6041. /**
  6042. * Only for textBackground.
  6043. * @type {number}
  6044. */
  6045. textHeight: null,
  6046. /**
  6047. * textStroke may be set as some color as a default
  6048. * value in upper applicaion, where the default value
  6049. * of textStrokeWidth should be 0 to make sure that
  6050. * user can choose to do not use text stroke.
  6051. * @type {number}
  6052. */
  6053. textStrokeWidth: 0,
  6054. /**
  6055. * @type {number}
  6056. */
  6057. textLineHeight: null,
  6058. /**
  6059. * 'inside', 'left', 'right', 'top', 'bottom'
  6060. * [x, y]
  6061. * Based on x, y of rect.
  6062. * @type {string|Array.<number>}
  6063. * @default 'inside'
  6064. */
  6065. textPosition: 'inside',
  6066. /**
  6067. * If not specified, use the boundingRect of a `displayable`.
  6068. * @type {Object}
  6069. */
  6070. textRect: null,
  6071. /**
  6072. * [x, y]
  6073. * @type {Array.<number>}
  6074. */
  6075. textOffset: null,
  6076. /**
  6077. * @type {string}
  6078. */
  6079. textAlign: null,
  6080. /**
  6081. * @type {string}
  6082. */
  6083. textVerticalAlign: null,
  6084. /**
  6085. * @type {number}
  6086. */
  6087. textDistance: 5,
  6088. /**
  6089. * @type {string}
  6090. */
  6091. textShadowColor: 'transparent',
  6092. /**
  6093. * @type {number}
  6094. */
  6095. textShadowBlur: 0,
  6096. /**
  6097. * @type {number}
  6098. */
  6099. textShadowOffsetX: 0,
  6100. /**
  6101. * @type {number}
  6102. */
  6103. textShadowOffsetY: 0,
  6104. /**
  6105. * @type {string}
  6106. */
  6107. textBoxShadowColor: 'transparent',
  6108. /**
  6109. * @type {number}
  6110. */
  6111. textBoxShadowBlur: 0,
  6112. /**
  6113. * @type {number}
  6114. */
  6115. textBoxShadowOffsetX: 0,
  6116. /**
  6117. * @type {number}
  6118. */
  6119. textBoxShadowOffsetY: 0,
  6120. /**
  6121. * Whether transform text.
  6122. * Only available in Path and Image element,
  6123. * where the text is called as `RectText`.
  6124. * @type {boolean}
  6125. */
  6126. transformText: false,
  6127. /**
  6128. * Text rotate around position of Path or Image.
  6129. * The origin of the rotation can be specified by `textOrigin`.
  6130. * Only available in Path and Image element,
  6131. * where the text is called as `RectText`.
  6132. */
  6133. textRotation: 0,
  6134. /**
  6135. * Text origin of text rotation.
  6136. * Useful in the case like label rotation of circular symbol.
  6137. * Only available in Path and Image element, where the text is called
  6138. * as `RectText` and the element is called as "host element".
  6139. * The value can be:
  6140. * + If specified as a coordinate like `[10, 40]`, it is the `[x, y]`
  6141. * base on the left-top corner of the rect of its host element.
  6142. * + If specified as a string `center`, it is the center of the rect of
  6143. * its host element.
  6144. * + By default, this origin is the `textPosition`.
  6145. * @type {string|Array.<number>}
  6146. */
  6147. textOrigin: null,
  6148. /**
  6149. * @type {string}
  6150. */
  6151. textBackgroundColor: null,
  6152. /**
  6153. * @type {string}
  6154. */
  6155. textBorderColor: null,
  6156. /**
  6157. * @type {number}
  6158. */
  6159. textBorderWidth: 0,
  6160. /**
  6161. * @type {number}
  6162. */
  6163. textBorderRadius: 0,
  6164. /**
  6165. * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`
  6166. * @type {number|Array.<number>}
  6167. */
  6168. textPadding: null,
  6169. /**
  6170. * Text styles for rich text.
  6171. * @type {Object}
  6172. */
  6173. rich: null,
  6174. /**
  6175. * {outerWidth, outerHeight, ellipsis, placeholder}
  6176. * @type {Object}
  6177. */
  6178. truncate: null,
  6179. /**
  6180. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  6181. * @type {string}
  6182. */
  6183. blend: null,
  6184. /**
  6185. * @param {CanvasRenderingContext2D} ctx
  6186. */
  6187. bind: function (ctx, el, prevEl) {
  6188. var style = this;
  6189. var prevStyle = prevEl && prevEl.style;
  6190. // If no prevStyle, it means first draw.
  6191. // Only apply cache if the last time cachced by this function.
  6192. var notCheckCache = !prevStyle || ctx.__attrCachedBy !== ContextCachedBy.STYLE_BIND;
  6193. ctx.__attrCachedBy = ContextCachedBy.STYLE_BIND;
  6194. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6195. var prop = STYLE_COMMON_PROPS[i];
  6196. var styleName = prop[0];
  6197. if (notCheckCache || style[styleName] !== prevStyle[styleName]) {
  6198. // FIXME Invalid property value will cause style leak from previous element.
  6199. ctx[styleName] =
  6200. fixShadow(ctx, styleName, style[styleName] || prop[1]);
  6201. }
  6202. }
  6203. if ((notCheckCache || style.fill !== prevStyle.fill)) {
  6204. ctx.fillStyle = style.fill;
  6205. }
  6206. if ((notCheckCache || style.stroke !== prevStyle.stroke)) {
  6207. ctx.strokeStyle = style.stroke;
  6208. }
  6209. if ((notCheckCache || style.opacity !== prevStyle.opacity)) {
  6210. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  6211. }
  6212. if ((notCheckCache || style.blend !== prevStyle.blend)) {
  6213. ctx.globalCompositeOperation = style.blend || 'source-over';
  6214. }
  6215. if (this.hasStroke()) {
  6216. var lineWidth = style.lineWidth;
  6217. ctx.lineWidth = lineWidth / (
  6218. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  6219. );
  6220. }
  6221. },
  6222. hasFill: function () {
  6223. var fill = this.fill;
  6224. return fill != null && fill !== 'none';
  6225. },
  6226. hasStroke: function () {
  6227. var stroke = this.stroke;
  6228. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  6229. },
  6230. /**
  6231. * Extend from other style
  6232. * @param {zrender/graphic/Style} otherStyle
  6233. * @param {boolean} overwrite true: overwrirte any way.
  6234. * false: overwrite only when !target.hasOwnProperty
  6235. * others: overwrite when property is not null/undefined.
  6236. */
  6237. extendFrom: function (otherStyle, overwrite) {
  6238. if (otherStyle) {
  6239. for (var name in otherStyle) {
  6240. if (otherStyle.hasOwnProperty(name)
  6241. && (overwrite === true
  6242. || (
  6243. overwrite === false
  6244. ? !this.hasOwnProperty(name)
  6245. : otherStyle[name] != null
  6246. )
  6247. )
  6248. ) {
  6249. this[name] = otherStyle[name];
  6250. }
  6251. }
  6252. }
  6253. },
  6254. /**
  6255. * Batch setting style with a given object
  6256. * @param {Object|string} obj
  6257. * @param {*} [obj]
  6258. */
  6259. set: function (obj, value) {
  6260. if (typeof obj === 'string') {
  6261. this[obj] = value;
  6262. }
  6263. else {
  6264. this.extendFrom(obj, true);
  6265. }
  6266. },
  6267. /**
  6268. * Clone
  6269. * @return {zrender/graphic/Style} [description]
  6270. */
  6271. clone: function () {
  6272. var newStyle = new this.constructor();
  6273. newStyle.extendFrom(this, true);
  6274. return newStyle;
  6275. },
  6276. getGradient: function (ctx, obj, rect) {
  6277. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  6278. var canvasGradient = method(ctx, obj, rect);
  6279. var colorStops = obj.colorStops;
  6280. for (var i = 0; i < colorStops.length; i++) {
  6281. canvasGradient.addColorStop(
  6282. colorStops[i].offset, colorStops[i].color
  6283. );
  6284. }
  6285. return canvasGradient;
  6286. }
  6287. };
  6288. var styleProto = Style.prototype;
  6289. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6290. var prop = STYLE_COMMON_PROPS[i];
  6291. if (!(prop[0] in styleProto)) {
  6292. styleProto[prop[0]] = prop[1];
  6293. }
  6294. }
  6295. // Provide for others
  6296. Style.getGradient = styleProto.getGradient;
  6297. var Pattern = function (image, repeat) {
  6298. // Should do nothing more in this constructor. Because gradient can be
  6299. // declard by `color: {image: ...}`, where this constructor will not be called.
  6300. this.image = image;
  6301. this.repeat = repeat;
  6302. // Can be cloned
  6303. this.type = 'pattern';
  6304. };
  6305. Pattern.prototype.getCanvasPattern = function (ctx) {
  6306. return ctx.createPattern(this.image, this.repeat || 'repeat');
  6307. };
  6308. /**
  6309. * @module zrender/Layer
  6310. * @author pissang(https://www.github.com/pissang)
  6311. */
  6312. function returnFalse() {
  6313. return false;
  6314. }
  6315. /**
  6316. * 创建dom
  6317. *
  6318. * @inner
  6319. * @param {string} id dom id 待用
  6320. * @param {Painter} painter painter instance
  6321. * @param {number} number
  6322. */
  6323. function createDom(id, painter, dpr) {
  6324. var newDom = createCanvas();
  6325. var width = painter.getWidth();
  6326. var height = painter.getHeight();
  6327. var newDomStyle = newDom.style;
  6328. if (newDomStyle) { // In node or some other non-browser environment
  6329. newDomStyle.position = 'absolute';
  6330. newDomStyle.left = 0;
  6331. newDomStyle.top = 0;
  6332. newDomStyle.width = width + 'px';
  6333. newDomStyle.height = height + 'px';
  6334. newDom.setAttribute('data-zr-dom-id', id);
  6335. }
  6336. newDom.width = width * dpr;
  6337. newDom.height = height * dpr;
  6338. return newDom;
  6339. }
  6340. /**
  6341. * @alias module:zrender/Layer
  6342. * @constructor
  6343. * @extends module:zrender/mixin/Transformable
  6344. * @param {string} id
  6345. * @param {module:zrender/Painter} painter
  6346. * @param {number} [dpr]
  6347. */
  6348. var Layer = function (id, painter, dpr) {
  6349. var dom;
  6350. dpr = dpr || devicePixelRatio;
  6351. if (typeof id === 'string') {
  6352. dom = createDom(id, painter, dpr);
  6353. }
  6354. // Not using isDom because in node it will return false
  6355. else if (isObject$1(id)) {
  6356. dom = id;
  6357. id = dom.id;
  6358. }
  6359. this.id = id;
  6360. this.dom = dom;
  6361. var domStyle = dom.style;
  6362. if (domStyle) { // Not in node
  6363. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  6364. domStyle['-webkit-user-select'] = 'none';
  6365. domStyle['user-select'] = 'none';
  6366. domStyle['-webkit-touch-callout'] = 'none';
  6367. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  6368. domStyle['padding'] = 0; // eslint-disable-line dot-notation
  6369. domStyle['margin'] = 0; // eslint-disable-line dot-notation
  6370. domStyle['border-width'] = 0;
  6371. }
  6372. this.domBack = null;
  6373. this.ctxBack = null;
  6374. this.painter = painter;
  6375. this.config = null;
  6376. // Configs
  6377. /**
  6378. * 每次清空画布的颜色
  6379. * @type {string}
  6380. * @default 0
  6381. */
  6382. this.clearColor = 0;
  6383. /**
  6384. * 是否开启动态模糊
  6385. * @type {boolean}
  6386. * @default false
  6387. */
  6388. this.motionBlur = false;
  6389. /**
  6390. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  6391. * @type {number}
  6392. * @default 0.7
  6393. */
  6394. this.lastFrameAlpha = 0.7;
  6395. /**
  6396. * Layer dpr
  6397. * @type {number}
  6398. */
  6399. this.dpr = dpr;
  6400. };
  6401. Layer.prototype = {
  6402. constructor: Layer,
  6403. __dirty: true,
  6404. __used: false,
  6405. __drawIndex: 0,
  6406. __startIndex: 0,
  6407. __endIndex: 0,
  6408. incremental: false,
  6409. getElementCount: function () {
  6410. return this.__endIndex - this.__startIndex;
  6411. },
  6412. initContext: function () {
  6413. this.ctx = this.dom.getContext('2d');
  6414. this.ctx.dpr = this.dpr;
  6415. },
  6416. createBackBuffer: function () {
  6417. var dpr = this.dpr;
  6418. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  6419. this.ctxBack = this.domBack.getContext('2d');
  6420. if (dpr !== 1) {
  6421. this.ctxBack.scale(dpr, dpr);
  6422. }
  6423. },
  6424. /**
  6425. * @param {number} width
  6426. * @param {number} height
  6427. */
  6428. resize: function (width, height) {
  6429. var dpr = this.dpr;
  6430. var dom = this.dom;
  6431. var domStyle = dom.style;
  6432. var domBack = this.domBack;
  6433. if (domStyle) {
  6434. domStyle.width = width + 'px';
  6435. domStyle.height = height + 'px';
  6436. }
  6437. dom.width = width * dpr;
  6438. dom.height = height * dpr;
  6439. if (domBack) {
  6440. domBack.width = width * dpr;
  6441. domBack.height = height * dpr;
  6442. if (dpr !== 1) {
  6443. this.ctxBack.scale(dpr, dpr);
  6444. }
  6445. }
  6446. },
  6447. /**
  6448. * 清空该层画布
  6449. * @param {boolean} [clearAll]=false Clear all with out motion blur
  6450. * @param {Color} [clearColor]
  6451. */
  6452. clear: function (clearAll, clearColor) {
  6453. var dom = this.dom;
  6454. var ctx = this.ctx;
  6455. var width = dom.width;
  6456. var height = dom.height;
  6457. var clearColor = clearColor || this.clearColor;
  6458. var haveMotionBLur = this.motionBlur && !clearAll;
  6459. var lastFrameAlpha = this.lastFrameAlpha;
  6460. var dpr = this.dpr;
  6461. if (haveMotionBLur) {
  6462. if (!this.domBack) {
  6463. this.createBackBuffer();
  6464. }
  6465. this.ctxBack.globalCompositeOperation = 'copy';
  6466. this.ctxBack.drawImage(
  6467. dom, 0, 0,
  6468. width / dpr,
  6469. height / dpr
  6470. );
  6471. }
  6472. ctx.clearRect(0, 0, width, height);
  6473. if (clearColor && clearColor !== 'transparent') {
  6474. var clearColorGradientOrPattern;
  6475. // Gradient
  6476. if (clearColor.colorStops) {
  6477. // Cache canvas gradient
  6478. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  6479. x: 0,
  6480. y: 0,
  6481. width: width,
  6482. height: height
  6483. });
  6484. clearColor.__canvasGradient = clearColorGradientOrPattern;
  6485. }
  6486. // Pattern
  6487. else if (clearColor.image) {
  6488. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  6489. }
  6490. ctx.save();
  6491. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  6492. ctx.fillRect(0, 0, width, height);
  6493. ctx.restore();
  6494. }
  6495. if (haveMotionBLur) {
  6496. var domBack = this.domBack;
  6497. ctx.save();
  6498. ctx.globalAlpha = lastFrameAlpha;
  6499. ctx.drawImage(domBack, 0, 0, width, height);
  6500. ctx.restore();
  6501. }
  6502. }
  6503. };
  6504. var requestAnimationFrame = (
  6505. typeof window !== 'undefined'
  6506. && (
  6507. (window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  6508. // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  6509. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  6510. || window.mozRequestAnimationFrame
  6511. || window.webkitRequestAnimationFrame
  6512. )
  6513. ) || function (func) {
  6514. setTimeout(func, 16);
  6515. };
  6516. var globalImageCache = new LRU(50);
  6517. /**
  6518. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6519. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6520. */
  6521. function findExistImage(newImageOrSrc) {
  6522. if (typeof newImageOrSrc === 'string') {
  6523. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6524. return cachedImgObj && cachedImgObj.image;
  6525. }
  6526. else {
  6527. return newImageOrSrc;
  6528. }
  6529. }
  6530. /**
  6531. * Caution: User should cache loaded images, but not just count on LRU.
  6532. * Consider if required images more than LRU size, will dead loop occur?
  6533. *
  6534. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6535. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  6536. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  6537. * @param {Function} [cb] params: (image, cbPayload)
  6538. * @param {Object} [cbPayload] Payload on cb calling.
  6539. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6540. */
  6541. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  6542. if (!newImageOrSrc) {
  6543. return image;
  6544. }
  6545. else if (typeof newImageOrSrc === 'string') {
  6546. // Image should not be loaded repeatly.
  6547. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  6548. return image;
  6549. }
  6550. // Only when there is no existent image or existent image src
  6551. // is different, this method is responsible for load.
  6552. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6553. var pendingWrap = {hostEl: hostEl, cb: cb, cbPayload: cbPayload};
  6554. if (cachedImgObj) {
  6555. image = cachedImgObj.image;
  6556. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  6557. }
  6558. else {
  6559. image = new Image();
  6560. image.onload = image.onerror = imageOnLoad;
  6561. globalImageCache.put(
  6562. newImageOrSrc,
  6563. image.__cachedImgObj = {
  6564. image: image,
  6565. pending: [pendingWrap]
  6566. }
  6567. );
  6568. image.src = image.__zrImageSrc = newImageOrSrc;
  6569. }
  6570. return image;
  6571. }
  6572. // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  6573. else {
  6574. return newImageOrSrc;
  6575. }
  6576. }
  6577. function imageOnLoad() {
  6578. var cachedImgObj = this.__cachedImgObj;
  6579. this.onload = this.onerror = this.__cachedImgObj = null;
  6580. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  6581. var pendingWrap = cachedImgObj.pending[i];
  6582. var cb = pendingWrap.cb;
  6583. cb && cb(this, pendingWrap.cbPayload);
  6584. pendingWrap.hostEl.dirty();
  6585. }
  6586. cachedImgObj.pending.length = 0;
  6587. }
  6588. function isImageReady(image) {
  6589. return image && image.width && image.height;
  6590. }
  6591. var textWidthCache = {};
  6592. var textWidthCacheCounter = 0;
  6593. var TEXT_CACHE_MAX = 5000;
  6594. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  6595. var DEFAULT_FONT$1 = '12px sans-serif';
  6596. // Avoid assign to an exported variable, for transforming to cjs.
  6597. var methods$1 = {};
  6598. /**
  6599. * @public
  6600. * @param {string} text
  6601. * @param {string} font
  6602. * @return {number} width
  6603. */
  6604. function getWidth(text, font) {
  6605. font = font || DEFAULT_FONT$1;
  6606. var key = text + ':' + font;
  6607. if (textWidthCache[key]) {
  6608. return textWidthCache[key];
  6609. }
  6610. var textLines = (text + '').split('\n');
  6611. var width = 0;
  6612. for (var i = 0, l = textLines.length; i < l; i++) {
  6613. // textContain.measureText may be overrided in SVG or VML
  6614. width = Math.max(measureText(textLines[i], font).width, width);
  6615. }
  6616. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  6617. textWidthCacheCounter = 0;
  6618. textWidthCache = {};
  6619. }
  6620. textWidthCacheCounter++;
  6621. textWidthCache[key] = width;
  6622. return width;
  6623. }
  6624. /**
  6625. * @public
  6626. * @param {string} text
  6627. * @param {string} font
  6628. * @param {string} [textAlign='left']
  6629. * @param {string} [textVerticalAlign='top']
  6630. * @param {Array.<number>} [textPadding]
  6631. * @param {Object} [rich]
  6632. * @param {Object} [truncate]
  6633. * @return {Object} {x, y, width, height, lineHeight}
  6634. */
  6635. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6636. return rich
  6637. ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate)
  6638. : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate);
  6639. }
  6640. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate) {
  6641. var contentBlock = parsePlainText(text, font, textPadding, textLineHeight, truncate);
  6642. var outerWidth = getWidth(text, font);
  6643. if (textPadding) {
  6644. outerWidth += textPadding[1] + textPadding[3];
  6645. }
  6646. var outerHeight = contentBlock.outerHeight;
  6647. var x = adjustTextX(0, outerWidth, textAlign);
  6648. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6649. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  6650. rect.lineHeight = contentBlock.lineHeight;
  6651. return rect;
  6652. }
  6653. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6654. var contentBlock = parseRichText(text, {
  6655. rich: rich,
  6656. truncate: truncate,
  6657. font: font,
  6658. textAlign: textAlign,
  6659. textPadding: textPadding,
  6660. textLineHeight: textLineHeight
  6661. });
  6662. var outerWidth = contentBlock.outerWidth;
  6663. var outerHeight = contentBlock.outerHeight;
  6664. var x = adjustTextX(0, outerWidth, textAlign);
  6665. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6666. return new BoundingRect(x, y, outerWidth, outerHeight);
  6667. }
  6668. /**
  6669. * @public
  6670. * @param {number} x
  6671. * @param {number} width
  6672. * @param {string} [textAlign='left']
  6673. * @return {number} Adjusted x.
  6674. */
  6675. function adjustTextX(x, width, textAlign) {
  6676. // FIXME Right to left language
  6677. if (textAlign === 'right') {
  6678. x -= width;
  6679. }
  6680. else if (textAlign === 'center') {
  6681. x -= width / 2;
  6682. }
  6683. return x;
  6684. }
  6685. /**
  6686. * @public
  6687. * @param {number} y
  6688. * @param {number} height
  6689. * @param {string} [textVerticalAlign='top']
  6690. * @return {number} Adjusted y.
  6691. */
  6692. function adjustTextY(y, height, textVerticalAlign) {
  6693. if (textVerticalAlign === 'middle') {
  6694. y -= height / 2;
  6695. }
  6696. else if (textVerticalAlign === 'bottom') {
  6697. y -= height;
  6698. }
  6699. return y;
  6700. }
  6701. /**
  6702. * Follow same interface to `Displayable.prototype.calculateTextPosition`.
  6703. * @public
  6704. * @param {Obejct} [out] Prepared out object. If not input, auto created in the method.
  6705. * @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited.
  6706. * @param {Object} rect {x, y, width, height} Rect of the host elment, according to which the text positioned.
  6707. * @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign}
  6708. */
  6709. function calculateTextPosition(out, style, rect) {
  6710. var textPosition = style.textPosition;
  6711. var distance = style.textDistance;
  6712. var x = rect.x;
  6713. var y = rect.y;
  6714. distance = distance || 0;
  6715. var height = rect.height;
  6716. var width = rect.width;
  6717. var halfHeight = height / 2;
  6718. var textAlign = 'left';
  6719. var textVerticalAlign = 'top';
  6720. switch (textPosition) {
  6721. case 'left':
  6722. x -= distance;
  6723. y += halfHeight;
  6724. textAlign = 'right';
  6725. textVerticalAlign = 'middle';
  6726. break;
  6727. case 'right':
  6728. x += distance + width;
  6729. y += halfHeight;
  6730. textVerticalAlign = 'middle';
  6731. break;
  6732. case 'top':
  6733. x += width / 2;
  6734. y -= distance;
  6735. textAlign = 'center';
  6736. textVerticalAlign = 'bottom';
  6737. break;
  6738. case 'bottom':
  6739. x += width / 2;
  6740. y += height + distance;
  6741. textAlign = 'center';
  6742. break;
  6743. case 'inside':
  6744. x += width / 2;
  6745. y += halfHeight;
  6746. textAlign = 'center';
  6747. textVerticalAlign = 'middle';
  6748. break;
  6749. case 'insideLeft':
  6750. x += distance;
  6751. y += halfHeight;
  6752. textVerticalAlign = 'middle';
  6753. break;
  6754. case 'insideRight':
  6755. x += width - distance;
  6756. y += halfHeight;
  6757. textAlign = 'right';
  6758. textVerticalAlign = 'middle';
  6759. break;
  6760. case 'insideTop':
  6761. x += width / 2;
  6762. y += distance;
  6763. textAlign = 'center';
  6764. break;
  6765. case 'insideBottom':
  6766. x += width / 2;
  6767. y += height - distance;
  6768. textAlign = 'center';
  6769. textVerticalAlign = 'bottom';
  6770. break;
  6771. case 'insideTopLeft':
  6772. x += distance;
  6773. y += distance;
  6774. break;
  6775. case 'insideTopRight':
  6776. x += width - distance;
  6777. y += distance;
  6778. textAlign = 'right';
  6779. break;
  6780. case 'insideBottomLeft':
  6781. x += distance;
  6782. y += height - distance;
  6783. textVerticalAlign = 'bottom';
  6784. break;
  6785. case 'insideBottomRight':
  6786. x += width - distance;
  6787. y += height - distance;
  6788. textAlign = 'right';
  6789. textVerticalAlign = 'bottom';
  6790. break;
  6791. }
  6792. out = out || {};
  6793. out.x = x;
  6794. out.y = y;
  6795. out.textAlign = textAlign;
  6796. out.textVerticalAlign = textVerticalAlign;
  6797. return out;
  6798. }
  6799. /**
  6800. * To be removed. But still do not remove in case that some one has imported it.
  6801. * @deprecated
  6802. * @public
  6803. * @param {stirng} textPosition
  6804. * @param {Object} rect {x, y, width, height}
  6805. * @param {number} distance
  6806. * @return {Object} {x, y, textAlign, textVerticalAlign}
  6807. */
  6808. /**
  6809. * Show ellipsis if overflow.
  6810. *
  6811. * @public
  6812. * @param {string} text
  6813. * @param {string} containerWidth
  6814. * @param {string} font
  6815. * @param {number} [ellipsis='...']
  6816. * @param {Object} [options]
  6817. * @param {number} [options.maxIterations=3]
  6818. * @param {number} [options.minChar=0] If truncate result are less
  6819. * then minChar, ellipsis will not show, which is
  6820. * better for user hint in some cases.
  6821. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  6822. * @return {string}
  6823. */
  6824. function truncateText(text, containerWidth, font, ellipsis, options) {
  6825. if (!containerWidth) {
  6826. return '';
  6827. }
  6828. var textLines = (text + '').split('\n');
  6829. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  6830. // FIXME
  6831. // It is not appropriate that every line has '...' when truncate multiple lines.
  6832. for (var i = 0, len = textLines.length; i < len; i++) {
  6833. textLines[i] = truncateSingleLine(textLines[i], options);
  6834. }
  6835. return textLines.join('\n');
  6836. }
  6837. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  6838. options = extend({}, options);
  6839. options.font = font;
  6840. var ellipsis = retrieve2(ellipsis, '...');
  6841. options.maxIterations = retrieve2(options.maxIterations, 2);
  6842. var minChar = options.minChar = retrieve2(options.minChar, 0);
  6843. // FIXME
  6844. // Other languages?
  6845. options.cnCharWidth = getWidth('国', font);
  6846. // FIXME
  6847. // Consider proportional font?
  6848. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  6849. options.placeholder = retrieve2(options.placeholder, '');
  6850. // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  6851. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  6852. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  6853. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  6854. contentWidth -= ascCharWidth;
  6855. }
  6856. var ellipsisWidth = getWidth(ellipsis, font);
  6857. if (ellipsisWidth > contentWidth) {
  6858. ellipsis = '';
  6859. ellipsisWidth = 0;
  6860. }
  6861. contentWidth = containerWidth - ellipsisWidth;
  6862. options.ellipsis = ellipsis;
  6863. options.ellipsisWidth = ellipsisWidth;
  6864. options.contentWidth = contentWidth;
  6865. options.containerWidth = containerWidth;
  6866. return options;
  6867. }
  6868. function truncateSingleLine(textLine, options) {
  6869. var containerWidth = options.containerWidth;
  6870. var font = options.font;
  6871. var contentWidth = options.contentWidth;
  6872. if (!containerWidth) {
  6873. return '';
  6874. }
  6875. var lineWidth = getWidth(textLine, font);
  6876. if (lineWidth <= containerWidth) {
  6877. return textLine;
  6878. }
  6879. for (var j = 0; ; j++) {
  6880. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  6881. textLine += options.ellipsis;
  6882. break;
  6883. }
  6884. var subLength = j === 0
  6885. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  6886. : lineWidth > 0
  6887. ? Math.floor(textLine.length * contentWidth / lineWidth)
  6888. : 0;
  6889. textLine = textLine.substr(0, subLength);
  6890. lineWidth = getWidth(textLine, font);
  6891. }
  6892. if (textLine === '') {
  6893. textLine = options.placeholder;
  6894. }
  6895. return textLine;
  6896. }
  6897. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  6898. var width = 0;
  6899. var i = 0;
  6900. for (var len = text.length; i < len && width < contentWidth; i++) {
  6901. var charCode = text.charCodeAt(i);
  6902. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  6903. }
  6904. return i;
  6905. }
  6906. /**
  6907. * @public
  6908. * @param {string} font
  6909. * @return {number} line height
  6910. */
  6911. function getLineHeight(font) {
  6912. // FIXME A rough approach.
  6913. return getWidth('国', font);
  6914. }
  6915. /**
  6916. * @public
  6917. * @param {string} text
  6918. * @param {string} font
  6919. * @return {Object} width
  6920. */
  6921. function measureText(text, font) {
  6922. return methods$1.measureText(text, font);
  6923. }
  6924. // Avoid assign to an exported variable, for transforming to cjs.
  6925. methods$1.measureText = function (text, font) {
  6926. var ctx = getContext();
  6927. ctx.font = font || DEFAULT_FONT$1;
  6928. return ctx.measureText(text);
  6929. };
  6930. /**
  6931. * @public
  6932. * @param {string} text
  6933. * @param {string} font
  6934. * @param {Object} [truncate]
  6935. * @return {Object} block: {lineHeight, lines, height, outerHeight, canCacheByTextString}
  6936. * Notice: for performance, do not calculate outerWidth util needed.
  6937. * `canCacheByTextString` means the result `lines` is only determined by the input `text`.
  6938. * Thus we can simply comparing the `input` text to determin whether the result changed,
  6939. * without travel the result `lines`.
  6940. */
  6941. function parsePlainText(text, font, padding, textLineHeight, truncate) {
  6942. text != null && (text += '');
  6943. var lineHeight = retrieve2(textLineHeight, getLineHeight(font));
  6944. var lines = text ? text.split('\n') : [];
  6945. var height = lines.length * lineHeight;
  6946. var outerHeight = height;
  6947. var canCacheByTextString = true;
  6948. if (padding) {
  6949. outerHeight += padding[0] + padding[2];
  6950. }
  6951. if (text && truncate) {
  6952. canCacheByTextString = false;
  6953. var truncOuterHeight = truncate.outerHeight;
  6954. var truncOuterWidth = truncate.outerWidth;
  6955. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  6956. text = '';
  6957. lines = [];
  6958. }
  6959. else if (truncOuterWidth != null) {
  6960. var options = prepareTruncateOptions(
  6961. truncOuterWidth - (padding ? padding[1] + padding[3] : 0),
  6962. font,
  6963. truncate.ellipsis,
  6964. {minChar: truncate.minChar, placeholder: truncate.placeholder}
  6965. );
  6966. // FIXME
  6967. // It is not appropriate that every line has '...' when truncate multiple lines.
  6968. for (var i = 0, len = lines.length; i < len; i++) {
  6969. lines[i] = truncateSingleLine(lines[i], options);
  6970. }
  6971. }
  6972. }
  6973. return {
  6974. lines: lines,
  6975. height: height,
  6976. outerHeight: outerHeight,
  6977. lineHeight: lineHeight,
  6978. canCacheByTextString: canCacheByTextString
  6979. };
  6980. }
  6981. /**
  6982. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  6983. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  6984. *
  6985. * @public
  6986. * @param {string} text
  6987. * @param {Object} style
  6988. * @return {Object} block
  6989. * {
  6990. * width,
  6991. * height,
  6992. * lines: [{
  6993. * lineHeight,
  6994. * width,
  6995. * tokens: [[{
  6996. * styleName,
  6997. * text,
  6998. * width, // include textPadding
  6999. * height, // include textPadding
  7000. * textWidth, // pure text width
  7001. * textHeight, // pure text height
  7002. * lineHeihgt,
  7003. * font,
  7004. * textAlign,
  7005. * textVerticalAlign
  7006. * }], [...], ...]
  7007. * }, ...]
  7008. * }
  7009. * If styleName is undefined, it is plain text.
  7010. */
  7011. function parseRichText(text, style) {
  7012. var contentBlock = {lines: [], width: 0, height: 0};
  7013. text != null && (text += '');
  7014. if (!text) {
  7015. return contentBlock;
  7016. }
  7017. var lastIndex = STYLE_REG.lastIndex = 0;
  7018. var result;
  7019. while ((result = STYLE_REG.exec(text)) != null) {
  7020. var matchedIndex = result.index;
  7021. if (matchedIndex > lastIndex) {
  7022. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  7023. }
  7024. pushTokens(contentBlock, result[2], result[1]);
  7025. lastIndex = STYLE_REG.lastIndex;
  7026. }
  7027. if (lastIndex < text.length) {
  7028. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  7029. }
  7030. var lines = contentBlock.lines;
  7031. var contentHeight = 0;
  7032. var contentWidth = 0;
  7033. // For `textWidth: 100%`
  7034. var pendingList = [];
  7035. var stlPadding = style.textPadding;
  7036. var truncate = style.truncate;
  7037. var truncateWidth = truncate && truncate.outerWidth;
  7038. var truncateHeight = truncate && truncate.outerHeight;
  7039. if (stlPadding) {
  7040. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  7041. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  7042. }
  7043. // Calculate layout info of tokens.
  7044. for (var i = 0; i < lines.length; i++) {
  7045. var line = lines[i];
  7046. var lineHeight = 0;
  7047. var lineWidth = 0;
  7048. for (var j = 0; j < line.tokens.length; j++) {
  7049. var token = line.tokens[j];
  7050. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  7051. // textPadding should not inherit from style.
  7052. var textPadding = token.textPadding = tokenStyle.textPadding;
  7053. // textFont has been asigned to font by `normalizeStyle`.
  7054. var font = token.font = tokenStyle.font || style.font;
  7055. // textHeight can be used when textVerticalAlign is specified in token.
  7056. var tokenHeight = token.textHeight = retrieve2(
  7057. // textHeight should not be inherited, consider it can be specified
  7058. // as box height of the block.
  7059. tokenStyle.textHeight, getLineHeight(font)
  7060. );
  7061. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  7062. token.height = tokenHeight;
  7063. token.lineHeight = retrieve3(
  7064. tokenStyle.textLineHeight, style.textLineHeight, tokenHeight
  7065. );
  7066. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  7067. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  7068. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  7069. return {lines: [], width: 0, height: 0};
  7070. }
  7071. token.textWidth = getWidth(token.text, font);
  7072. var tokenWidth = tokenStyle.textWidth;
  7073. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto';
  7074. // Percent width, can be `100%`, can be used in drawing separate
  7075. // line when box width is needed to be auto.
  7076. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  7077. token.percentWidth = tokenWidth;
  7078. pendingList.push(token);
  7079. tokenWidth = 0;
  7080. // Do not truncate in this case, because there is no user case
  7081. // and it is too complicated.
  7082. }
  7083. else {
  7084. if (tokenWidthNotSpecified) {
  7085. tokenWidth = token.textWidth;
  7086. // FIXME: If image is not loaded and textWidth is not specified, calling
  7087. // `getBoundingRect()` will not get correct result.
  7088. var textBackgroundColor = tokenStyle.textBackgroundColor;
  7089. var bgImg = textBackgroundColor && textBackgroundColor.image;
  7090. // Use cases:
  7091. // (1) If image is not loaded, it will be loaded at render phase and call
  7092. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  7093. // image, and then the right size will be calculated here at the next tick.
  7094. // See `graphic/helper/text.js`.
  7095. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  7096. // use `imageHelper.findExistImage` to find cached image.
  7097. // `imageHelper.findExistImage` will always be called here before
  7098. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  7099. // which ensures that image will not be rendered before correct size calcualted.
  7100. if (bgImg) {
  7101. bgImg = findExistImage(bgImg);
  7102. if (isImageReady(bgImg)) {
  7103. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  7104. }
  7105. }
  7106. }
  7107. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  7108. tokenWidth += paddingW;
  7109. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  7110. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  7111. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  7112. token.text = '';
  7113. token.textWidth = tokenWidth = 0;
  7114. }
  7115. else {
  7116. token.text = truncateText(
  7117. token.text, remianTruncWidth - paddingW, font, truncate.ellipsis,
  7118. {minChar: truncate.minChar}
  7119. );
  7120. token.textWidth = getWidth(token.text, font);
  7121. tokenWidth = token.textWidth + paddingW;
  7122. }
  7123. }
  7124. }
  7125. lineWidth += (token.width = tokenWidth);
  7126. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  7127. }
  7128. line.width = lineWidth;
  7129. line.lineHeight = lineHeight;
  7130. contentHeight += lineHeight;
  7131. contentWidth = Math.max(contentWidth, lineWidth);
  7132. }
  7133. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  7134. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  7135. if (stlPadding) {
  7136. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  7137. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  7138. }
  7139. for (var i = 0; i < pendingList.length; i++) {
  7140. var token = pendingList[i];
  7141. var percentWidth = token.percentWidth;
  7142. // Should not base on outerWidth, because token can not be placed out of padding.
  7143. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  7144. }
  7145. return contentBlock;
  7146. }
  7147. function pushTokens(block, str, styleName) {
  7148. var isEmptyStr = str === '';
  7149. var strs = str.split('\n');
  7150. var lines = block.lines;
  7151. for (var i = 0; i < strs.length; i++) {
  7152. var text = strs[i];
  7153. var token = {
  7154. styleName: styleName,
  7155. text: text,
  7156. isLineHolder: !text && !isEmptyStr
  7157. };
  7158. // The first token should be appended to the last line.
  7159. if (!i) {
  7160. var tokens = (lines[lines.length - 1] || (lines[0] = {tokens: []})).tokens;
  7161. // Consider cases:
  7162. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  7163. // (which is a placeholder) should be replaced by new token.
  7164. // (2) A image backage, where token likes {a|}.
  7165. // (3) A redundant '' will affect textAlign in line.
  7166. // (4) tokens with the same tplName should not be merged, because
  7167. // they should be displayed in different box (with border and padding).
  7168. var tokensLen = tokens.length;
  7169. (tokensLen === 1 && tokens[0].isLineHolder)
  7170. ? (tokens[0] = token)
  7171. // Consider text is '', only insert when it is the "lineHolder" or
  7172. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  7173. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  7174. }
  7175. // Other tokens always start a new line.
  7176. else {
  7177. // If there is '', insert it as a placeholder.
  7178. lines.push({tokens: [token]});
  7179. }
  7180. }
  7181. }
  7182. function makeFont(style) {
  7183. // FIXME in node-canvas fontWeight is before fontStyle
  7184. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  7185. var font = (style.fontSize || style.fontFamily) && [
  7186. style.fontStyle,
  7187. style.fontWeight,
  7188. (style.fontSize || 12) + 'px',
  7189. // If font properties are defined, `fontFamily` should not be ignored.
  7190. style.fontFamily || 'sans-serif'
  7191. ].join(' ');
  7192. return font && trim(font) || style.textFont || style.font;
  7193. }
  7194. /**
  7195. * @param {Object} ctx
  7196. * @param {Object} shape
  7197. * @param {number} shape.x
  7198. * @param {number} shape.y
  7199. * @param {number} shape.width
  7200. * @param {number} shape.height
  7201. * @param {number} shape.r
  7202. */
  7203. function buildPath(ctx, shape) {
  7204. var x = shape.x;
  7205. var y = shape.y;
  7206. var width = shape.width;
  7207. var height = shape.height;
  7208. var r = shape.r;
  7209. var r1;
  7210. var r2;
  7211. var r3;
  7212. var r4;
  7213. // Convert width and height to positive for better borderRadius
  7214. if (width < 0) {
  7215. x = x + width;
  7216. width = -width;
  7217. }
  7218. if (height < 0) {
  7219. y = y + height;
  7220. height = -height;
  7221. }
  7222. if (typeof r === 'number') {
  7223. r1 = r2 = r3 = r4 = r;
  7224. }
  7225. else if (r instanceof Array) {
  7226. if (r.length === 1) {
  7227. r1 = r2 = r3 = r4 = r[0];
  7228. }
  7229. else if (r.length === 2) {
  7230. r1 = r3 = r[0];
  7231. r2 = r4 = r[1];
  7232. }
  7233. else if (r.length === 3) {
  7234. r1 = r[0];
  7235. r2 = r4 = r[1];
  7236. r3 = r[2];
  7237. }
  7238. else {
  7239. r1 = r[0];
  7240. r2 = r[1];
  7241. r3 = r[2];
  7242. r4 = r[3];
  7243. }
  7244. }
  7245. else {
  7246. r1 = r2 = r3 = r4 = 0;
  7247. }
  7248. var total;
  7249. if (r1 + r2 > width) {
  7250. total = r1 + r2;
  7251. r1 *= width / total;
  7252. r2 *= width / total;
  7253. }
  7254. if (r3 + r4 > width) {
  7255. total = r3 + r4;
  7256. r3 *= width / total;
  7257. r4 *= width / total;
  7258. }
  7259. if (r2 + r3 > height) {
  7260. total = r2 + r3;
  7261. r2 *= height / total;
  7262. r3 *= height / total;
  7263. }
  7264. if (r1 + r4 > height) {
  7265. total = r1 + r4;
  7266. r1 *= height / total;
  7267. r4 *= height / total;
  7268. }
  7269. ctx.moveTo(x + r1, y);
  7270. ctx.lineTo(x + width - r2, y);
  7271. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  7272. ctx.lineTo(x + width, y + height - r3);
  7273. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  7274. ctx.lineTo(x + r4, y + height);
  7275. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  7276. ctx.lineTo(x, y + r1);
  7277. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  7278. }
  7279. var DEFAULT_FONT = DEFAULT_FONT$1;
  7280. // TODO: Have not support 'start', 'end' yet.
  7281. var VALID_TEXT_ALIGN = {left: 1, right: 1, center: 1};
  7282. var VALID_TEXT_VERTICAL_ALIGN = {top: 1, bottom: 1, middle: 1};
  7283. // Different from `STYLE_COMMON_PROPS` of `graphic/Style`,
  7284. // the default value of shadowColor is `'transparent'`.
  7285. var SHADOW_STYLE_COMMON_PROPS = [
  7286. ['textShadowBlur', 'shadowBlur', 0],
  7287. ['textShadowOffsetX', 'shadowOffsetX', 0],
  7288. ['textShadowOffsetY', 'shadowOffsetY', 0],
  7289. ['textShadowColor', 'shadowColor', 'transparent']
  7290. ];
  7291. var _tmpTextPositionResult = {};
  7292. var _tmpBoxPositionResult = {};
  7293. /**
  7294. * @param {module:zrender/graphic/Style} style
  7295. * @return {module:zrender/graphic/Style} The input style.
  7296. */
  7297. function normalizeTextStyle(style) {
  7298. normalizeStyle(style);
  7299. each$1(style.rich, normalizeStyle);
  7300. return style;
  7301. }
  7302. function normalizeStyle(style) {
  7303. if (style) {
  7304. style.font = makeFont(style);
  7305. var textAlign = style.textAlign;
  7306. textAlign === 'middle' && (textAlign = 'center');
  7307. style.textAlign = (
  7308. textAlign == null || VALID_TEXT_ALIGN[textAlign]
  7309. ) ? textAlign : 'left';
  7310. // Compatible with textBaseline.
  7311. var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
  7312. textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
  7313. style.textVerticalAlign = (
  7314. textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign]
  7315. ) ? textVerticalAlign : 'top';
  7316. var textPadding = style.textPadding;
  7317. if (textPadding) {
  7318. style.textPadding = normalizeCssArray(style.textPadding);
  7319. }
  7320. }
  7321. }
  7322. /**
  7323. * @param {CanvasRenderingContext2D} ctx
  7324. * @param {string} text
  7325. * @param {module:zrender/graphic/Style} style
  7326. * @param {Object|boolean} [rect] {x, y, width, height}
  7327. * If set false, rect text is not used.
  7328. * @param {Element|module:zrender/graphic/helper/constant.WILL_BE_RESTORED} [prevEl] For ctx prop cache.
  7329. */
  7330. function renderText(hostEl, ctx, text, style, rect, prevEl) {
  7331. style.rich
  7332. ? renderRichText(hostEl, ctx, text, style, rect, prevEl)
  7333. : renderPlainText(hostEl, ctx, text, style, rect, prevEl);
  7334. }
  7335. // Avoid setting to ctx according to prevEl if possible for
  7336. // performance in scenarios of large amount text.
  7337. function renderPlainText(hostEl, ctx, text, style, rect, prevEl) {
  7338. 'use strict';
  7339. var needDrawBg = needDrawBackground(style);
  7340. var prevStyle;
  7341. var checkCache = false;
  7342. var cachedByMe = ctx.__attrCachedBy === ContextCachedBy.PLAIN_TEXT;
  7343. // Only take and check cache for `Text` el, but not RectText.
  7344. if (prevEl !== WILL_BE_RESTORED) {
  7345. if (prevEl) {
  7346. prevStyle = prevEl.style;
  7347. checkCache = !needDrawBg && cachedByMe && prevStyle;
  7348. }
  7349. // Prevent from using cache in `Style::bind`, because of the case:
  7350. // ctx property is modified by other properties than `Style::bind`
  7351. // used, and Style::bind is called next.
  7352. ctx.__attrCachedBy = needDrawBg ? ContextCachedBy.NONE : ContextCachedBy.PLAIN_TEXT;
  7353. }
  7354. // Since this will be restored, prevent from using these props to check cache in the next
  7355. // entering of this method. But do not need to clear other cache like `Style::bind`.
  7356. else if (cachedByMe) {
  7357. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7358. }
  7359. var styleFont = style.font || DEFAULT_FONT;
  7360. // PENDING
  7361. // Only `Text` el set `font` and keep it (`RectText` will restore). So theoretically
  7362. // we can make font cache on ctx, which can cache for text el that are discontinuous.
  7363. // But layer save/restore needed to be considered.
  7364. // if (styleFont !== ctx.__fontCache) {
  7365. // ctx.font = styleFont;
  7366. // if (prevEl !== WILL_BE_RESTORED) {
  7367. // ctx.__fontCache = styleFont;
  7368. // }
  7369. // }
  7370. if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) {
  7371. ctx.font = styleFont;
  7372. }
  7373. // Use the final font from context-2d, because the final
  7374. // font might not be the style.font when it is illegal.
  7375. // But get `ctx.font` might be time consuming.
  7376. var computedFont = hostEl.__computedFont;
  7377. if (hostEl.__styleFont !== styleFont) {
  7378. hostEl.__styleFont = styleFont;
  7379. computedFont = hostEl.__computedFont = ctx.font;
  7380. }
  7381. var textPadding = style.textPadding;
  7382. var textLineHeight = style.textLineHeight;
  7383. var contentBlock = hostEl.__textCotentBlock;
  7384. if (!contentBlock || hostEl.__dirtyText) {
  7385. contentBlock = hostEl.__textCotentBlock = parsePlainText(
  7386. text, computedFont, textPadding, textLineHeight, style.truncate
  7387. );
  7388. }
  7389. var outerHeight = contentBlock.outerHeight;
  7390. var textLines = contentBlock.lines;
  7391. var lineHeight = contentBlock.lineHeight;
  7392. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7393. var baseX = boxPos.baseX;
  7394. var baseY = boxPos.baseY;
  7395. var textAlign = boxPos.textAlign || 'left';
  7396. var textVerticalAlign = boxPos.textVerticalAlign;
  7397. // Origin of textRotation should be the base point of text drawing.
  7398. applyTextRotation(ctx, style, rect, baseX, baseY);
  7399. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7400. var textX = baseX;
  7401. var textY = boxY;
  7402. if (needDrawBg || textPadding) {
  7403. // Consider performance, do not call getTextWidth util necessary.
  7404. var textWidth = getWidth(text, computedFont);
  7405. var outerWidth = textWidth;
  7406. textPadding && (outerWidth += textPadding[1] + textPadding[3]);
  7407. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7408. needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  7409. if (textPadding) {
  7410. textX = getTextXForPadding(baseX, textAlign, textPadding);
  7411. textY += textPadding[0];
  7412. }
  7413. }
  7414. // Always set textAlign and textBase line, because it is difficute to calculate
  7415. // textAlign from prevEl, and we dont sure whether textAlign will be reset if
  7416. // font set happened.
  7417. ctx.textAlign = textAlign;
  7418. // Force baseline to be "middle". Otherwise, if using "top", the
  7419. // text will offset downward a little bit in font "Microsoft YaHei".
  7420. ctx.textBaseline = 'middle';
  7421. // Set text opacity
  7422. ctx.globalAlpha = style.opacity || 1;
  7423. // Always set shadowBlur and shadowOffset to avoid leak from displayable.
  7424. for (var i = 0; i < SHADOW_STYLE_COMMON_PROPS.length; i++) {
  7425. var propItem = SHADOW_STYLE_COMMON_PROPS[i];
  7426. var styleProp = propItem[0];
  7427. var ctxProp = propItem[1];
  7428. var val = style[styleProp];
  7429. if (!checkCache || val !== prevStyle[styleProp]) {
  7430. ctx[ctxProp] = fixShadow(ctx, ctxProp, val || propItem[2]);
  7431. }
  7432. }
  7433. // `textBaseline` is set as 'middle'.
  7434. textY += lineHeight / 2;
  7435. var textStrokeWidth = style.textStrokeWidth;
  7436. var textStrokeWidthPrev = checkCache ? prevStyle.textStrokeWidth : null;
  7437. var strokeWidthChanged = !checkCache || textStrokeWidth !== textStrokeWidthPrev;
  7438. var strokeChanged = !checkCache || strokeWidthChanged || style.textStroke !== prevStyle.textStroke;
  7439. var textStroke = getStroke(style.textStroke, textStrokeWidth);
  7440. var textFill = getFill(style.textFill);
  7441. if (textStroke) {
  7442. if (strokeWidthChanged) {
  7443. ctx.lineWidth = textStrokeWidth;
  7444. }
  7445. if (strokeChanged) {
  7446. ctx.strokeStyle = textStroke;
  7447. }
  7448. }
  7449. if (textFill) {
  7450. if (!checkCache || style.textFill !== prevStyle.textFill) {
  7451. ctx.fillStyle = textFill;
  7452. }
  7453. }
  7454. // Optimize simply, in most cases only one line exists.
  7455. if (textLines.length === 1) {
  7456. // Fill after stroke so the outline will not cover the main part.
  7457. textStroke && ctx.strokeText(textLines[0], textX, textY);
  7458. textFill && ctx.fillText(textLines[0], textX, textY);
  7459. }
  7460. else {
  7461. for (var i = 0; i < textLines.length; i++) {
  7462. // Fill after stroke so the outline will not cover the main part.
  7463. textStroke && ctx.strokeText(textLines[i], textX, textY);
  7464. textFill && ctx.fillText(textLines[i], textX, textY);
  7465. textY += lineHeight;
  7466. }
  7467. }
  7468. }
  7469. function renderRichText(hostEl, ctx, text, style, rect, prevEl) {
  7470. // Do not do cache for rich text because of the complexity.
  7471. // But `RectText` this will be restored, do not need to clear other cache like `Style::bind`.
  7472. if (prevEl !== WILL_BE_RESTORED) {
  7473. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7474. }
  7475. var contentBlock = hostEl.__textCotentBlock;
  7476. if (!contentBlock || hostEl.__dirtyText) {
  7477. contentBlock = hostEl.__textCotentBlock = parseRichText(text, style);
  7478. }
  7479. drawRichText(hostEl, ctx, contentBlock, style, rect);
  7480. }
  7481. function drawRichText(hostEl, ctx, contentBlock, style, rect) {
  7482. var contentWidth = contentBlock.width;
  7483. var outerWidth = contentBlock.outerWidth;
  7484. var outerHeight = contentBlock.outerHeight;
  7485. var textPadding = style.textPadding;
  7486. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7487. var baseX = boxPos.baseX;
  7488. var baseY = boxPos.baseY;
  7489. var textAlign = boxPos.textAlign;
  7490. var textVerticalAlign = boxPos.textVerticalAlign;
  7491. // Origin of textRotation should be the base point of text drawing.
  7492. applyTextRotation(ctx, style, rect, baseX, baseY);
  7493. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7494. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7495. var xLeft = boxX;
  7496. var lineTop = boxY;
  7497. if (textPadding) {
  7498. xLeft += textPadding[3];
  7499. lineTop += textPadding[0];
  7500. }
  7501. var xRight = xLeft + contentWidth;
  7502. needDrawBackground(style) && drawBackground(
  7503. hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight
  7504. );
  7505. for (var i = 0; i < contentBlock.lines.length; i++) {
  7506. var line = contentBlock.lines[i];
  7507. var tokens = line.tokens;
  7508. var tokenCount = tokens.length;
  7509. var lineHeight = line.lineHeight;
  7510. var usedWidth = line.width;
  7511. var leftIndex = 0;
  7512. var lineXLeft = xLeft;
  7513. var lineXRight = xRight;
  7514. var rightIndex = tokenCount - 1;
  7515. var token;
  7516. while (
  7517. leftIndex < tokenCount
  7518. && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')
  7519. ) {
  7520. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
  7521. usedWidth -= token.width;
  7522. lineXLeft += token.width;
  7523. leftIndex++;
  7524. }
  7525. while (
  7526. rightIndex >= 0
  7527. && (token = tokens[rightIndex], token.textAlign === 'right')
  7528. ) {
  7529. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
  7530. usedWidth -= token.width;
  7531. lineXRight -= token.width;
  7532. rightIndex--;
  7533. }
  7534. // The other tokens are placed as textAlign 'center' if there is enough space.
  7535. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
  7536. while (leftIndex <= rightIndex) {
  7537. token = tokens[leftIndex];
  7538. // Consider width specified by user, use 'center' rather than 'left'.
  7539. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
  7540. lineXLeft += token.width;
  7541. leftIndex++;
  7542. }
  7543. lineTop += lineHeight;
  7544. }
  7545. }
  7546. function applyTextRotation(ctx, style, rect, x, y) {
  7547. // textRotation only apply in RectText.
  7548. if (rect && style.textRotation) {
  7549. var origin = style.textOrigin;
  7550. if (origin === 'center') {
  7551. x = rect.width / 2 + rect.x;
  7552. y = rect.height / 2 + rect.y;
  7553. }
  7554. else if (origin) {
  7555. x = origin[0] + rect.x;
  7556. y = origin[1] + rect.y;
  7557. }
  7558. ctx.translate(x, y);
  7559. // Positive: anticlockwise
  7560. ctx.rotate(-style.textRotation);
  7561. ctx.translate(-x, -y);
  7562. }
  7563. }
  7564. function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
  7565. var tokenStyle = style.rich[token.styleName] || {};
  7566. tokenStyle.text = token.text;
  7567. // 'ctx.textBaseline' is always set as 'middle', for sake of
  7568. // the bias of "Microsoft YaHei".
  7569. var textVerticalAlign = token.textVerticalAlign;
  7570. var y = lineTop + lineHeight / 2;
  7571. if (textVerticalAlign === 'top') {
  7572. y = lineTop + token.height / 2;
  7573. }
  7574. else if (textVerticalAlign === 'bottom') {
  7575. y = lineTop + lineHeight - token.height / 2;
  7576. }
  7577. !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(
  7578. hostEl,
  7579. ctx,
  7580. tokenStyle,
  7581. textAlign === 'right'
  7582. ? x - token.width
  7583. : textAlign === 'center'
  7584. ? x - token.width / 2
  7585. : x,
  7586. y - token.height / 2,
  7587. token.width,
  7588. token.height
  7589. );
  7590. var textPadding = token.textPadding;
  7591. if (textPadding) {
  7592. x = getTextXForPadding(x, textAlign, textPadding);
  7593. y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
  7594. }
  7595. setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
  7596. setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
  7597. setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
  7598. setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
  7599. setCtx(ctx, 'textAlign', textAlign);
  7600. // Force baseline to be "middle". Otherwise, if using "top", the
  7601. // text will offset downward a little bit in font "Microsoft YaHei".
  7602. setCtx(ctx, 'textBaseline', 'middle');
  7603. setCtx(ctx, 'font', token.font || DEFAULT_FONT);
  7604. var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
  7605. var textFill = getFill(tokenStyle.textFill || style.textFill);
  7606. var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth);
  7607. // Fill after stroke so the outline will not cover the main part.
  7608. if (textStroke) {
  7609. setCtx(ctx, 'lineWidth', textStrokeWidth);
  7610. setCtx(ctx, 'strokeStyle', textStroke);
  7611. ctx.strokeText(token.text, x, y);
  7612. }
  7613. if (textFill) {
  7614. setCtx(ctx, 'fillStyle', textFill);
  7615. ctx.fillText(token.text, x, y);
  7616. }
  7617. }
  7618. function needDrawBackground(style) {
  7619. return !!(
  7620. style.textBackgroundColor
  7621. || (style.textBorderWidth && style.textBorderColor)
  7622. );
  7623. }
  7624. // style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius, text}
  7625. // shape: {x, y, width, height}
  7626. function drawBackground(hostEl, ctx, style, x, y, width, height) {
  7627. var textBackgroundColor = style.textBackgroundColor;
  7628. var textBorderWidth = style.textBorderWidth;
  7629. var textBorderColor = style.textBorderColor;
  7630. var isPlainBg = isString(textBackgroundColor);
  7631. setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
  7632. setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
  7633. setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
  7634. setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
  7635. if (isPlainBg || (textBorderWidth && textBorderColor)) {
  7636. ctx.beginPath();
  7637. var textBorderRadius = style.textBorderRadius;
  7638. if (!textBorderRadius) {
  7639. ctx.rect(x, y, width, height);
  7640. }
  7641. else {
  7642. buildPath(ctx, {
  7643. x: x, y: y, width: width, height: height, r: textBorderRadius
  7644. });
  7645. }
  7646. ctx.closePath();
  7647. }
  7648. if (isPlainBg) {
  7649. setCtx(ctx, 'fillStyle', textBackgroundColor);
  7650. if (style.fillOpacity != null) {
  7651. var originalGlobalAlpha = ctx.globalAlpha;
  7652. ctx.globalAlpha = style.fillOpacity * style.opacity;
  7653. ctx.fill();
  7654. ctx.globalAlpha = originalGlobalAlpha;
  7655. }
  7656. else {
  7657. ctx.fill();
  7658. }
  7659. }
  7660. else if (isObject$1(textBackgroundColor)) {
  7661. var image = textBackgroundColor.image;
  7662. image = createOrUpdateImage(
  7663. image, null, hostEl, onBgImageLoaded, textBackgroundColor
  7664. );
  7665. if (image && isImageReady(image)) {
  7666. ctx.drawImage(image, x, y, width, height);
  7667. }
  7668. }
  7669. if (textBorderWidth && textBorderColor) {
  7670. setCtx(ctx, 'lineWidth', textBorderWidth);
  7671. setCtx(ctx, 'strokeStyle', textBorderColor);
  7672. if (style.strokeOpacity != null) {
  7673. var originalGlobalAlpha = ctx.globalAlpha;
  7674. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  7675. ctx.stroke();
  7676. ctx.globalAlpha = originalGlobalAlpha;
  7677. }
  7678. else {
  7679. ctx.stroke();
  7680. }
  7681. }
  7682. }
  7683. function onBgImageLoaded(image, textBackgroundColor) {
  7684. // Replace image, so that `contain/text.js#parseRichText`
  7685. // will get correct result in next tick.
  7686. textBackgroundColor.image = image;
  7687. }
  7688. function getBoxPosition(out, hostEl, style, rect) {
  7689. var baseX = style.x || 0;
  7690. var baseY = style.y || 0;
  7691. var textAlign = style.textAlign;
  7692. var textVerticalAlign = style.textVerticalAlign;
  7693. // Text position represented by coord
  7694. if (rect) {
  7695. var textPosition = style.textPosition;
  7696. if (textPosition instanceof Array) {
  7697. // Percent
  7698. baseX = rect.x + parsePercent(textPosition[0], rect.width);
  7699. baseY = rect.y + parsePercent(textPosition[1], rect.height);
  7700. }
  7701. else {
  7702. var res = (hostEl && hostEl.calculateTextPosition)
  7703. ? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect)
  7704. : calculateTextPosition(_tmpTextPositionResult, style, rect);
  7705. baseX = res.x;
  7706. baseY = res.y;
  7707. // Default align and baseline when has textPosition
  7708. textAlign = textAlign || res.textAlign;
  7709. textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
  7710. }
  7711. // textOffset is only support in RectText, otherwise
  7712. // we have to adjust boundingRect for textOffset.
  7713. var textOffset = style.textOffset;
  7714. if (textOffset) {
  7715. baseX += textOffset[0];
  7716. baseY += textOffset[1];
  7717. }
  7718. }
  7719. out = out || {};
  7720. out.baseX = baseX;
  7721. out.baseY = baseY;
  7722. out.textAlign = textAlign;
  7723. out.textVerticalAlign = textVerticalAlign;
  7724. return out;
  7725. }
  7726. function setCtx(ctx, prop, value) {
  7727. ctx[prop] = fixShadow(ctx, prop, value);
  7728. return ctx[prop];
  7729. }
  7730. /**
  7731. * @param {string} [stroke] If specified, do not check style.textStroke.
  7732. * @param {string} [lineWidth] If specified, do not check style.textStroke.
  7733. * @param {number} style
  7734. */
  7735. function getStroke(stroke, lineWidth) {
  7736. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  7737. ? null
  7738. // TODO pattern and gradient?
  7739. : (stroke.image || stroke.colorStops)
  7740. ? '#000'
  7741. : stroke;
  7742. }
  7743. function getFill(fill) {
  7744. return (fill == null || fill === 'none')
  7745. ? null
  7746. // TODO pattern and gradient?
  7747. : (fill.image || fill.colorStops)
  7748. ? '#000'
  7749. : fill;
  7750. }
  7751. function parsePercent(value, maxValue) {
  7752. if (typeof value === 'string') {
  7753. if (value.lastIndexOf('%') >= 0) {
  7754. return parseFloat(value) / 100 * maxValue;
  7755. }
  7756. return parseFloat(value);
  7757. }
  7758. return value;
  7759. }
  7760. function getTextXForPadding(x, textAlign, textPadding) {
  7761. return textAlign === 'right'
  7762. ? (x - textPadding[1])
  7763. : textAlign === 'center'
  7764. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  7765. : (x + textPadding[3]);
  7766. }
  7767. /**
  7768. * @param {string} text
  7769. * @param {module:zrender/Style} style
  7770. * @return {boolean}
  7771. */
  7772. function needDrawText(text, style) {
  7773. return text != null
  7774. && (text
  7775. || style.textBackgroundColor
  7776. || (style.textBorderWidth && style.textBorderColor)
  7777. || style.textPadding
  7778. );
  7779. }
  7780. /**
  7781. * Mixin for drawing text in a element bounding rect
  7782. * @module zrender/mixin/RectText
  7783. */
  7784. var tmpRect$1 = new BoundingRect();
  7785. var RectText = function () {};
  7786. RectText.prototype = {
  7787. constructor: RectText,
  7788. /**
  7789. * Draw text in a rect with specified position.
  7790. * @param {CanvasRenderingContext2D} ctx
  7791. * @param {Object} rect Displayable rect
  7792. */
  7793. drawRectText: function (ctx, rect) {
  7794. var style = this.style;
  7795. rect = style.textRect || rect;
  7796. // Optimize, avoid normalize every time.
  7797. this.__dirty && normalizeTextStyle(style, true);
  7798. var text = style.text;
  7799. // Convert to string
  7800. text != null && (text += '');
  7801. if (!needDrawText(text, style)) {
  7802. return;
  7803. }
  7804. // FIXME
  7805. // Do not provide prevEl to `textHelper.renderText` for ctx prop cache,
  7806. // but use `ctx.save()` and `ctx.restore()`. Because the cache for rect
  7807. // text propably break the cache for its host elements.
  7808. ctx.save();
  7809. // Transform rect to view space
  7810. var transform = this.transform;
  7811. if (!style.transformText) {
  7812. if (transform) {
  7813. tmpRect$1.copy(rect);
  7814. tmpRect$1.applyTransform(transform);
  7815. rect = tmpRect$1;
  7816. }
  7817. }
  7818. else {
  7819. this.setTransform(ctx);
  7820. }
  7821. // transformText and textRotation can not be used at the same time.
  7822. renderText(this, ctx, text, style, rect, WILL_BE_RESTORED);
  7823. ctx.restore();
  7824. }
  7825. };
  7826. /**
  7827. * Base class of all displayable graphic objects
  7828. * @module zrender/graphic/Displayable
  7829. */
  7830. /**
  7831. * @alias module:zrender/graphic/Displayable
  7832. * @extends module:zrender/Element
  7833. * @extends module:zrender/graphic/mixin/RectText
  7834. */
  7835. function Displayable(opts) {
  7836. opts = opts || {};
  7837. Element.call(this, opts);
  7838. // Extend properties
  7839. for (var name in opts) {
  7840. if (
  7841. opts.hasOwnProperty(name)
  7842. && name !== 'style'
  7843. ) {
  7844. this[name] = opts[name];
  7845. }
  7846. }
  7847. /**
  7848. * @type {module:zrender/graphic/Style}
  7849. */
  7850. this.style = new Style(opts.style, this);
  7851. this._rect = null;
  7852. // Shapes for cascade clipping.
  7853. // Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.
  7854. // because it is easy to only using null to check whether clipPaths changed.
  7855. this.__clipPaths = null;
  7856. // FIXME Stateful must be mixined after style is setted
  7857. // Stateful.call(this, opts);
  7858. }
  7859. Displayable.prototype = {
  7860. constructor: Displayable,
  7861. type: 'displayable',
  7862. /**
  7863. * Dirty flag. From which painter will determine if this displayable object needs brush.
  7864. * @name module:zrender/graphic/Displayable#__dirty
  7865. * @type {boolean}
  7866. */
  7867. __dirty: true,
  7868. /**
  7869. * Whether the displayable object is visible. when it is true, the displayable object
  7870. * is not drawn, but the mouse event can still trigger the object.
  7871. * @name module:/zrender/graphic/Displayable#invisible
  7872. * @type {boolean}
  7873. * @default false
  7874. */
  7875. invisible: false,
  7876. /**
  7877. * @name module:/zrender/graphic/Displayable#z
  7878. * @type {number}
  7879. * @default 0
  7880. */
  7881. z: 0,
  7882. /**
  7883. * @name module:/zrender/graphic/Displayable#z
  7884. * @type {number}
  7885. * @default 0
  7886. */
  7887. z2: 0,
  7888. /**
  7889. * The z level determines the displayable object can be drawn in which layer canvas.
  7890. * @name module:/zrender/graphic/Displayable#zlevel
  7891. * @type {number}
  7892. * @default 0
  7893. */
  7894. zlevel: 0,
  7895. /**
  7896. * Whether it can be dragged.
  7897. * @name module:/zrender/graphic/Displayable#draggable
  7898. * @type {boolean}
  7899. * @default false
  7900. */
  7901. draggable: false,
  7902. /**
  7903. * Whether is it dragging.
  7904. * @name module:/zrender/graphic/Displayable#draggable
  7905. * @type {boolean}
  7906. * @default false
  7907. */
  7908. dragging: false,
  7909. /**
  7910. * Whether to respond to mouse events.
  7911. * @name module:/zrender/graphic/Displayable#silent
  7912. * @type {boolean}
  7913. * @default false
  7914. */
  7915. silent: false,
  7916. /**
  7917. * If enable culling
  7918. * @type {boolean}
  7919. * @default false
  7920. */
  7921. culling: false,
  7922. /**
  7923. * Mouse cursor when hovered
  7924. * @name module:/zrender/graphic/Displayable#cursor
  7925. * @type {string}
  7926. */
  7927. cursor: 'pointer',
  7928. /**
  7929. * If hover area is bounding rect
  7930. * @name module:/zrender/graphic/Displayable#rectHover
  7931. * @type {string}
  7932. */
  7933. rectHover: false,
  7934. /**
  7935. * Render the element progressively when the value >= 0,
  7936. * usefull for large data.
  7937. * @type {boolean}
  7938. */
  7939. progressive: false,
  7940. /**
  7941. * @type {boolean}
  7942. */
  7943. incremental: false,
  7944. /**
  7945. * Scale ratio for global scale.
  7946. * @type {boolean}
  7947. */
  7948. globalScaleRatio: 1,
  7949. beforeBrush: function (ctx) {},
  7950. afterBrush: function (ctx) {},
  7951. /**
  7952. * Graphic drawing method.
  7953. * @param {CanvasRenderingContext2D} ctx
  7954. */
  7955. // Interface
  7956. brush: function (ctx, prevEl) {},
  7957. /**
  7958. * Get the minimum bounding box.
  7959. * @return {module:zrender/core/BoundingRect}
  7960. */
  7961. // Interface
  7962. getBoundingRect: function () {},
  7963. /**
  7964. * If displayable element contain coord x, y
  7965. * @param {number} x
  7966. * @param {number} y
  7967. * @return {boolean}
  7968. */
  7969. contain: function (x, y) {
  7970. return this.rectContain(x, y);
  7971. },
  7972. /**
  7973. * @param {Function} cb
  7974. * @param {} context
  7975. */
  7976. traverse: function (cb, context) {
  7977. cb.call(context, this);
  7978. },
  7979. /**
  7980. * If bounding rect of element contain coord x, y
  7981. * @param {number} x
  7982. * @param {number} y
  7983. * @return {boolean}
  7984. */
  7985. rectContain: function (x, y) {
  7986. var coord = this.transformCoordToLocal(x, y);
  7987. var rect = this.getBoundingRect();
  7988. return rect.contain(coord[0], coord[1]);
  7989. },
  7990. /**
  7991. * Mark displayable element dirty and refresh next frame
  7992. */
  7993. dirty: function () {
  7994. this.__dirty = this.__dirtyText = true;
  7995. this._rect = null;
  7996. this.__zr && this.__zr.refresh();
  7997. },
  7998. /**
  7999. * If displayable object binded any event
  8000. * @return {boolean}
  8001. */
  8002. // TODO, events bound by bind
  8003. // isSilent: function () {
  8004. // return !(
  8005. // this.hoverable || this.draggable
  8006. // || this.onmousemove || this.onmouseover || this.onmouseout
  8007. // || this.onmousedown || this.onmouseup || this.onclick
  8008. // || this.ondragenter || this.ondragover || this.ondragleave
  8009. // || this.ondrop
  8010. // );
  8011. // },
  8012. /**
  8013. * Alias for animate('style')
  8014. * @param {boolean} loop
  8015. */
  8016. animateStyle: function (loop) {
  8017. return this.animate('style', loop);
  8018. },
  8019. attrKV: function (key, value) {
  8020. if (key !== 'style') {
  8021. Element.prototype.attrKV.call(this, key, value);
  8022. }
  8023. else {
  8024. this.style.set(value);
  8025. }
  8026. },
  8027. /**
  8028. * @param {Object|string} key
  8029. * @param {*} value
  8030. */
  8031. setStyle: function (key, value) {
  8032. this.style.set(key, value);
  8033. this.dirty(false);
  8034. return this;
  8035. },
  8036. /**
  8037. * Use given style object
  8038. * @param {Object} obj
  8039. */
  8040. useStyle: function (obj) {
  8041. this.style = new Style(obj, this);
  8042. this.dirty(false);
  8043. return this;
  8044. },
  8045. /**
  8046. * The string value of `textPosition` needs to be calculated to a real postion.
  8047. * For example, `'inside'` is calculated to `[rect.width/2, rect.height/2]`
  8048. * by default. See `contain/text.js#calculateTextPosition` for more details.
  8049. * But some coutom shapes like "pin", "flag" have center that is not exactly
  8050. * `[width/2, height/2]`. So we provide this hook to customize the calculation
  8051. * for those shapes. It will be called if the `style.textPosition` is a string.
  8052. * @param {Obejct} [out] Prepared out object. If not provided, this method should
  8053. * be responsible for creating one.
  8054. * @param {module:zrender/graphic/Style} style
  8055. * @param {Object} rect {x, y, width, height}
  8056. * @return {Obejct} out The same as the input out.
  8057. * {
  8058. * x: number. mandatory.
  8059. * y: number. mandatory.
  8060. * textAlign: string. optional. use style.textAlign by default.
  8061. * textVerticalAlign: string. optional. use style.textVerticalAlign by default.
  8062. * }
  8063. */
  8064. calculateTextPosition: null
  8065. };
  8066. inherits(Displayable, Element);
  8067. mixin(Displayable, RectText);
  8068. /**
  8069. * @alias zrender/graphic/Image
  8070. * @extends module:zrender/graphic/Displayable
  8071. * @constructor
  8072. * @param {Object} opts
  8073. */
  8074. function ZImage(opts) {
  8075. Displayable.call(this, opts);
  8076. }
  8077. ZImage.prototype = {
  8078. constructor: ZImage,
  8079. type: 'image',
  8080. brush: function (ctx, prevEl) {
  8081. var style = this.style;
  8082. var src = style.image;
  8083. // Must bind each time
  8084. style.bind(ctx, this, prevEl);
  8085. var image = this._image = createOrUpdateImage(
  8086. src,
  8087. this._image,
  8088. this,
  8089. this.onload
  8090. );
  8091. if (!image || !isImageReady(image)) {
  8092. return;
  8093. }
  8094. // 图片已经加载完成
  8095. // if (image.nodeName.toUpperCase() == 'IMG') {
  8096. // if (!image.complete) {
  8097. // return;
  8098. // }
  8099. // }
  8100. // Else is canvas
  8101. var x = style.x || 0;
  8102. var y = style.y || 0;
  8103. var width = style.width;
  8104. var height = style.height;
  8105. var aspect = image.width / image.height;
  8106. if (width == null && height != null) {
  8107. // Keep image/height ratio
  8108. width = height * aspect;
  8109. }
  8110. else if (height == null && width != null) {
  8111. height = width / aspect;
  8112. }
  8113. else if (width == null && height == null) {
  8114. width = image.width;
  8115. height = image.height;
  8116. }
  8117. // 设置transform
  8118. this.setTransform(ctx);
  8119. if (style.sWidth && style.sHeight) {
  8120. var sx = style.sx || 0;
  8121. var sy = style.sy || 0;
  8122. ctx.drawImage(
  8123. image,
  8124. sx, sy, style.sWidth, style.sHeight,
  8125. x, y, width, height
  8126. );
  8127. }
  8128. else if (style.sx && style.sy) {
  8129. var sx = style.sx;
  8130. var sy = style.sy;
  8131. var sWidth = width - sx;
  8132. var sHeight = height - sy;
  8133. ctx.drawImage(
  8134. image,
  8135. sx, sy, sWidth, sHeight,
  8136. x, y, width, height
  8137. );
  8138. }
  8139. else {
  8140. ctx.drawImage(image, x, y, width, height);
  8141. }
  8142. // Draw rect text
  8143. if (style.text != null) {
  8144. // Only restore transform when needs draw text.
  8145. this.restoreTransform(ctx);
  8146. this.drawRectText(ctx, this.getBoundingRect());
  8147. }
  8148. },
  8149. getBoundingRect: function () {
  8150. var style = this.style;
  8151. if (!this._rect) {
  8152. this._rect = new BoundingRect(
  8153. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  8154. );
  8155. }
  8156. return this._rect;
  8157. }
  8158. };
  8159. inherits(ZImage, Displayable);
  8160. var HOVER_LAYER_ZLEVEL = 1e5;
  8161. var CANVAS_ZLEVEL = 314159;
  8162. var EL_AFTER_INCREMENTAL_INC = 0.01;
  8163. var INCREMENTAL_INC = 0.001;
  8164. function parseInt10(val) {
  8165. return parseInt(val, 10);
  8166. }
  8167. function isLayerValid(layer) {
  8168. if (!layer) {
  8169. return false;
  8170. }
  8171. if (layer.__builtin__) {
  8172. return true;
  8173. }
  8174. if (typeof (layer.resize) !== 'function'
  8175. || typeof (layer.refresh) !== 'function'
  8176. ) {
  8177. return false;
  8178. }
  8179. return true;
  8180. }
  8181. var tmpRect = new BoundingRect(0, 0, 0, 0);
  8182. var viewRect = new BoundingRect(0, 0, 0, 0);
  8183. function isDisplayableCulled(el, width, height) {
  8184. tmpRect.copy(el.getBoundingRect());
  8185. if (el.transform) {
  8186. tmpRect.applyTransform(el.transform);
  8187. }
  8188. viewRect.width = width;
  8189. viewRect.height = height;
  8190. return !tmpRect.intersect(viewRect);
  8191. }
  8192. function isClipPathChanged(clipPaths, prevClipPaths) {
  8193. // displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
  8194. if (clipPaths === prevClipPaths) {
  8195. return false;
  8196. }
  8197. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  8198. return true;
  8199. }
  8200. for (var i = 0; i < clipPaths.length; i++) {
  8201. if (clipPaths[i] !== prevClipPaths[i]) {
  8202. return true;
  8203. }
  8204. }
  8205. return false;
  8206. }
  8207. function doClip(clipPaths, ctx) {
  8208. for (var i = 0; i < clipPaths.length; i++) {
  8209. var clipPath = clipPaths[i];
  8210. clipPath.setTransform(ctx);
  8211. ctx.beginPath();
  8212. clipPath.buildPath(ctx, clipPath.shape);
  8213. ctx.clip();
  8214. // Transform back
  8215. clipPath.restoreTransform(ctx);
  8216. }
  8217. }
  8218. function createRoot(width, height) {
  8219. var domRoot = document.createElement('div');
  8220. // domRoot.onselectstart = returnFalse; // Avoid page selected
  8221. domRoot.style.cssText = [
  8222. 'position:relative',
  8223. // IOS13 safari probably has a compositing bug (z order of the canvas and the consequent
  8224. // dom does not act as expected) when some of the parent dom has
  8225. // `-webkit-overflow-scrolling: touch;` and the webpage is longer than one screen and
  8226. // the canvas is not at the top part of the page.
  8227. // Check `https://bugs.webkit.org/show_bug.cgi?id=203681` for more details. We remove
  8228. // this `overflow:hidden` to avoid the bug.
  8229. // 'overflow:hidden',
  8230. 'width:' + width + 'px',
  8231. 'height:' + height + 'px',
  8232. 'padding:0',
  8233. 'margin:0',
  8234. 'border-width:0'
  8235. ].join(';') + ';';
  8236. return domRoot;
  8237. }
  8238. /**
  8239. * @alias module:zrender/Painter
  8240. * @constructor
  8241. * @param {HTMLElement} root 绘图容器
  8242. * @param {module:zrender/Storage} storage
  8243. * @param {Object} opts
  8244. */
  8245. var Painter = function (root, storage, opts) {
  8246. this.type = 'canvas';
  8247. // In node environment using node-canvas
  8248. var singleCanvas = !root.nodeName // In node ?
  8249. || root.nodeName.toUpperCase() === 'CANVAS';
  8250. this._opts = opts = extend({}, opts || {});
  8251. /**
  8252. * @type {number}
  8253. */
  8254. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  8255. /**
  8256. * @type {boolean}
  8257. * @private
  8258. */
  8259. this._singleCanvas = singleCanvas;
  8260. /**
  8261. * 绘图容器
  8262. * @type {HTMLElement}
  8263. */
  8264. this.root = root;
  8265. var rootStyle = root.style;
  8266. if (rootStyle) {
  8267. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  8268. rootStyle['-webkit-user-select'] =
  8269. rootStyle['user-select'] =
  8270. rootStyle['-webkit-touch-callout'] = 'none';
  8271. root.innerHTML = '';
  8272. }
  8273. /**
  8274. * @type {module:zrender/Storage}
  8275. */
  8276. this.storage = storage;
  8277. /**
  8278. * @type {Array.<number>}
  8279. * @private
  8280. */
  8281. var zlevelList = this._zlevelList = [];
  8282. /**
  8283. * @type {Object.<string, module:zrender/Layer>}
  8284. * @private
  8285. */
  8286. var layers = this._layers = {};
  8287. /**
  8288. * @type {Object.<string, Object>}
  8289. * @private
  8290. */
  8291. this._layerConfig = {};
  8292. /**
  8293. * zrender will do compositing when root is a canvas and have multiple zlevels.
  8294. */
  8295. this._needsManuallyCompositing = false;
  8296. if (!singleCanvas) {
  8297. this._width = this._getSize(0);
  8298. this._height = this._getSize(1);
  8299. var domRoot = this._domRoot = createRoot(
  8300. this._width, this._height
  8301. );
  8302. root.appendChild(domRoot);
  8303. }
  8304. else {
  8305. var width = root.width;
  8306. var height = root.height;
  8307. if (opts.width != null) {
  8308. width = opts.width;
  8309. }
  8310. if (opts.height != null) {
  8311. height = opts.height;
  8312. }
  8313. this.dpr = opts.devicePixelRatio || 1;
  8314. // Use canvas width and height directly
  8315. root.width = width * this.dpr;
  8316. root.height = height * this.dpr;
  8317. this._width = width;
  8318. this._height = height;
  8319. // Create layer if only one given canvas
  8320. // Device can be specified to create a high dpi image.
  8321. var mainLayer = new Layer(root, this, this.dpr);
  8322. mainLayer.__builtin__ = true;
  8323. mainLayer.initContext();
  8324. // FIXME Use canvas width and height
  8325. // mainLayer.resize(width, height);
  8326. layers[CANVAS_ZLEVEL] = mainLayer;
  8327. mainLayer.zlevel = CANVAS_ZLEVEL;
  8328. // Not use common zlevel.
  8329. zlevelList.push(CANVAS_ZLEVEL);
  8330. this._domRoot = root;
  8331. }
  8332. /**
  8333. * @type {module:zrender/Layer}
  8334. * @private
  8335. */
  8336. this._hoverlayer = null;
  8337. this._hoverElements = [];
  8338. };
  8339. Painter.prototype = {
  8340. constructor: Painter,
  8341. getType: function () {
  8342. return 'canvas';
  8343. },
  8344. /**
  8345. * If painter use a single canvas
  8346. * @return {boolean}
  8347. */
  8348. isSingleCanvas: function () {
  8349. return this._singleCanvas;
  8350. },
  8351. /**
  8352. * @return {HTMLDivElement}
  8353. */
  8354. getViewportRoot: function () {
  8355. return this._domRoot;
  8356. },
  8357. getViewportRootOffset: function () {
  8358. var viewportRoot = this.getViewportRoot();
  8359. if (viewportRoot) {
  8360. return {
  8361. offsetLeft: viewportRoot.offsetLeft || 0,
  8362. offsetTop: viewportRoot.offsetTop || 0
  8363. };
  8364. }
  8365. },
  8366. /**
  8367. * 刷新
  8368. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  8369. */
  8370. refresh: function (paintAll) {
  8371. var list = this.storage.getDisplayList(true);
  8372. var zlevelList = this._zlevelList;
  8373. this._redrawId = Math.random();
  8374. this._paintList(list, paintAll, this._redrawId);
  8375. // Paint custum layers
  8376. for (var i = 0; i < zlevelList.length; i++) {
  8377. var z = zlevelList[i];
  8378. var layer = this._layers[z];
  8379. if (!layer.__builtin__ && layer.refresh) {
  8380. var clearColor = i === 0 ? this._backgroundColor : null;
  8381. layer.refresh(clearColor);
  8382. }
  8383. }
  8384. this.refreshHover();
  8385. return this;
  8386. },
  8387. addHover: function (el, hoverStyle) {
  8388. if (el.__hoverMir) {
  8389. return;
  8390. }
  8391. var elMirror = new el.constructor({
  8392. style: el.style,
  8393. shape: el.shape,
  8394. z: el.z,
  8395. z2: el.z2,
  8396. silent: el.silent
  8397. });
  8398. elMirror.__from = el;
  8399. el.__hoverMir = elMirror;
  8400. hoverStyle && elMirror.setStyle(hoverStyle);
  8401. this._hoverElements.push(elMirror);
  8402. return elMirror;
  8403. },
  8404. removeHover: function (el) {
  8405. var elMirror = el.__hoverMir;
  8406. var hoverElements = this._hoverElements;
  8407. var idx = indexOf(hoverElements, elMirror);
  8408. if (idx >= 0) {
  8409. hoverElements.splice(idx, 1);
  8410. }
  8411. el.__hoverMir = null;
  8412. },
  8413. clearHover: function (el) {
  8414. var hoverElements = this._hoverElements;
  8415. for (var i = 0; i < hoverElements.length; i++) {
  8416. var from = hoverElements[i].__from;
  8417. if (from) {
  8418. from.__hoverMir = null;
  8419. }
  8420. }
  8421. hoverElements.length = 0;
  8422. },
  8423. refreshHover: function () {
  8424. var hoverElements = this._hoverElements;
  8425. var len = hoverElements.length;
  8426. var hoverLayer = this._hoverlayer;
  8427. hoverLayer && hoverLayer.clear();
  8428. if (!len) {
  8429. return;
  8430. }
  8431. sort(hoverElements, this.storage.displayableSortFunc);
  8432. // Use a extream large zlevel
  8433. // FIXME?
  8434. if (!hoverLayer) {
  8435. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  8436. }
  8437. var scope = {};
  8438. hoverLayer.ctx.save();
  8439. for (var i = 0; i < len;) {
  8440. var el = hoverElements[i];
  8441. var originalEl = el.__from;
  8442. // Original el is removed
  8443. // PENDING
  8444. if (!(originalEl && originalEl.__zr)) {
  8445. hoverElements.splice(i, 1);
  8446. originalEl.__hoverMir = null;
  8447. len--;
  8448. continue;
  8449. }
  8450. i++;
  8451. // Use transform
  8452. // FIXME style and shape ?
  8453. if (!originalEl.invisible) {
  8454. el.transform = originalEl.transform;
  8455. el.invTransform = originalEl.invTransform;
  8456. el.__clipPaths = originalEl.__clipPaths;
  8457. // el.
  8458. this._doPaintEl(el, hoverLayer, true, scope);
  8459. }
  8460. }
  8461. hoverLayer.ctx.restore();
  8462. },
  8463. getHoverLayer: function () {
  8464. return this.getLayer(HOVER_LAYER_ZLEVEL);
  8465. },
  8466. _paintList: function (list, paintAll, redrawId) {
  8467. if (this._redrawId !== redrawId) {
  8468. return;
  8469. }
  8470. paintAll = paintAll || false;
  8471. this._updateLayerStatus(list);
  8472. var finished = this._doPaintList(list, paintAll);
  8473. if (this._needsManuallyCompositing) {
  8474. this._compositeManually();
  8475. }
  8476. if (!finished) {
  8477. var self = this;
  8478. requestAnimationFrame(function () {
  8479. self._paintList(list, paintAll, redrawId);
  8480. });
  8481. }
  8482. },
  8483. _compositeManually: function () {
  8484. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  8485. var width = this._domRoot.width;
  8486. var height = this._domRoot.height;
  8487. ctx.clearRect(0, 0, width, height);
  8488. // PENDING, If only builtin layer?
  8489. this.eachBuiltinLayer(function (layer) {
  8490. if (layer.virtual) {
  8491. ctx.drawImage(layer.dom, 0, 0, width, height);
  8492. }
  8493. });
  8494. },
  8495. _doPaintList: function (list, paintAll) {
  8496. var layerList = [];
  8497. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  8498. var zlevel = this._zlevelList[zi];
  8499. var layer = this._layers[zlevel];
  8500. if (layer.__builtin__
  8501. && layer !== this._hoverlayer
  8502. && (layer.__dirty || paintAll)
  8503. ) {
  8504. layerList.push(layer);
  8505. }
  8506. }
  8507. var finished = true;
  8508. for (var k = 0; k < layerList.length; k++) {
  8509. var layer = layerList[k];
  8510. var ctx = layer.ctx;
  8511. var scope = {};
  8512. ctx.save();
  8513. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  8514. var useTimer = !paintAll && layer.incremental && Date.now;
  8515. var startTime = useTimer && Date.now();
  8516. var clearColor = layer.zlevel === this._zlevelList[0]
  8517. ? this._backgroundColor : null;
  8518. // All elements in this layer are cleared.
  8519. if (layer.__startIndex === layer.__endIndex) {
  8520. layer.clear(false, clearColor);
  8521. }
  8522. else if (start === layer.__startIndex) {
  8523. var firstEl = list[start];
  8524. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  8525. layer.clear(false, clearColor);
  8526. }
  8527. }
  8528. if (start === -1) {
  8529. console.error('For some unknown reason. drawIndex is -1');
  8530. start = layer.__startIndex;
  8531. }
  8532. for (var i = start; i < layer.__endIndex; i++) {
  8533. var el = list[i];
  8534. this._doPaintEl(el, layer, paintAll, scope);
  8535. el.__dirty = el.__dirtyText = false;
  8536. if (useTimer) {
  8537. // Date.now can be executed in 13,025,305 ops/second.
  8538. var dTime = Date.now() - startTime;
  8539. // Give 15 millisecond to draw.
  8540. // The rest elements will be drawn in the next frame.
  8541. if (dTime > 15) {
  8542. break;
  8543. }
  8544. }
  8545. }
  8546. layer.__drawIndex = i;
  8547. if (layer.__drawIndex < layer.__endIndex) {
  8548. finished = false;
  8549. }
  8550. if (scope.prevElClipPaths) {
  8551. // Needs restore the state. If last drawn element is in the clipping area.
  8552. ctx.restore();
  8553. }
  8554. ctx.restore();
  8555. }
  8556. if (env$1.wxa) {
  8557. // Flush for weixin application
  8558. each$1(this._layers, function (layer) {
  8559. if (layer && layer.ctx && layer.ctx.draw) {
  8560. layer.ctx.draw();
  8561. }
  8562. });
  8563. }
  8564. return finished;
  8565. },
  8566. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  8567. var ctx = currentLayer.ctx;
  8568. var m = el.transform;
  8569. if (
  8570. (currentLayer.__dirty || forcePaint)
  8571. // Ignore invisible element
  8572. && !el.invisible
  8573. // Ignore transparent element
  8574. && el.style.opacity !== 0
  8575. // Ignore scale 0 element, in some environment like node-canvas
  8576. // Draw a scale 0 element can cause all following draw wrong
  8577. // And setTransform with scale 0 will cause set back transform failed.
  8578. && !(m && !m[0] && !m[3])
  8579. // Ignore culled element
  8580. && !(el.culling && isDisplayableCulled(el, this._width, this._height))
  8581. ) {
  8582. var clipPaths = el.__clipPaths;
  8583. var prevElClipPaths = scope.prevElClipPaths;
  8584. // Optimize when clipping on group with several elements
  8585. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  8586. // If has previous clipping state, restore from it
  8587. if (prevElClipPaths) {
  8588. ctx.restore();
  8589. scope.prevElClipPaths = null;
  8590. // Reset prevEl since context has been restored
  8591. scope.prevEl = null;
  8592. }
  8593. // New clipping state
  8594. if (clipPaths) {
  8595. ctx.save();
  8596. doClip(clipPaths, ctx);
  8597. scope.prevElClipPaths = clipPaths;
  8598. }
  8599. }
  8600. el.beforeBrush && el.beforeBrush(ctx);
  8601. el.brush(ctx, scope.prevEl || null);
  8602. scope.prevEl = el;
  8603. el.afterBrush && el.afterBrush(ctx);
  8604. }
  8605. },
  8606. /**
  8607. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  8608. * @param {number} zlevel
  8609. * @param {boolean} virtual Virtual layer will not be inserted into dom.
  8610. * @return {module:zrender/Layer}
  8611. */
  8612. getLayer: function (zlevel, virtual) {
  8613. if (this._singleCanvas && !this._needsManuallyCompositing) {
  8614. zlevel = CANVAS_ZLEVEL;
  8615. }
  8616. var layer = this._layers[zlevel];
  8617. if (!layer) {
  8618. // Create a new layer
  8619. layer = new Layer('zr_' + zlevel, this, this.dpr);
  8620. layer.zlevel = zlevel;
  8621. layer.__builtin__ = true;
  8622. if (this._layerConfig[zlevel]) {
  8623. merge(layer, this._layerConfig[zlevel], true);
  8624. }
  8625. // TODO Remove EL_AFTER_INCREMENTAL_INC magic number
  8626. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  8627. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  8628. }
  8629. if (virtual) {
  8630. layer.virtual = virtual;
  8631. }
  8632. this.insertLayer(zlevel, layer);
  8633. // Context is created after dom inserted to document
  8634. // Or excanvas will get 0px clientWidth and clientHeight
  8635. layer.initContext();
  8636. }
  8637. return layer;
  8638. },
  8639. insertLayer: function (zlevel, layer) {
  8640. var layersMap = this._layers;
  8641. var zlevelList = this._zlevelList;
  8642. var len = zlevelList.length;
  8643. var prevLayer = null;
  8644. var i = -1;
  8645. var domRoot = this._domRoot;
  8646. if (layersMap[zlevel]) {
  8647. logError$1('ZLevel ' + zlevel + ' has been used already');
  8648. return;
  8649. }
  8650. // Check if is a valid layer
  8651. if (!isLayerValid(layer)) {
  8652. logError$1('Layer of zlevel ' + zlevel + ' is not valid');
  8653. return;
  8654. }
  8655. if (len > 0 && zlevel > zlevelList[0]) {
  8656. for (i = 0; i < len - 1; i++) {
  8657. if (
  8658. zlevelList[i] < zlevel
  8659. && zlevelList[i + 1] > zlevel
  8660. ) {
  8661. break;
  8662. }
  8663. }
  8664. prevLayer = layersMap[zlevelList[i]];
  8665. }
  8666. zlevelList.splice(i + 1, 0, zlevel);
  8667. layersMap[zlevel] = layer;
  8668. // Vitual layer will not directly show on the screen.
  8669. // (It can be a WebGL layer and assigned to a ZImage element)
  8670. // But it still under management of zrender.
  8671. if (!layer.virtual) {
  8672. if (prevLayer) {
  8673. var prevDom = prevLayer.dom;
  8674. if (prevDom.nextSibling) {
  8675. domRoot.insertBefore(
  8676. layer.dom,
  8677. prevDom.nextSibling
  8678. );
  8679. }
  8680. else {
  8681. domRoot.appendChild(layer.dom);
  8682. }
  8683. }
  8684. else {
  8685. if (domRoot.firstChild) {
  8686. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  8687. }
  8688. else {
  8689. domRoot.appendChild(layer.dom);
  8690. }
  8691. }
  8692. }
  8693. },
  8694. // Iterate each layer
  8695. eachLayer: function (cb, context) {
  8696. var zlevelList = this._zlevelList;
  8697. var z;
  8698. var i;
  8699. for (i = 0; i < zlevelList.length; i++) {
  8700. z = zlevelList[i];
  8701. cb.call(context, this._layers[z], z);
  8702. }
  8703. },
  8704. // Iterate each buildin layer
  8705. eachBuiltinLayer: function (cb, context) {
  8706. var zlevelList = this._zlevelList;
  8707. var layer;
  8708. var z;
  8709. var i;
  8710. for (i = 0; i < zlevelList.length; i++) {
  8711. z = zlevelList[i];
  8712. layer = this._layers[z];
  8713. if (layer.__builtin__) {
  8714. cb.call(context, layer, z);
  8715. }
  8716. }
  8717. },
  8718. // Iterate each other layer except buildin layer
  8719. eachOtherLayer: function (cb, context) {
  8720. var zlevelList = this._zlevelList;
  8721. var layer;
  8722. var z;
  8723. var i;
  8724. for (i = 0; i < zlevelList.length; i++) {
  8725. z = zlevelList[i];
  8726. layer = this._layers[z];
  8727. if (!layer.__builtin__) {
  8728. cb.call(context, layer, z);
  8729. }
  8730. }
  8731. },
  8732. /**
  8733. * 获取所有已创建的层
  8734. * @param {Array.<module:zrender/Layer>} [prevLayer]
  8735. */
  8736. getLayers: function () {
  8737. return this._layers;
  8738. },
  8739. _updateLayerStatus: function (list) {
  8740. this.eachBuiltinLayer(function (layer, z) {
  8741. layer.__dirty = layer.__used = false;
  8742. });
  8743. function updatePrevLayer(idx) {
  8744. if (prevLayer) {
  8745. if (prevLayer.__endIndex !== idx) {
  8746. prevLayer.__dirty = true;
  8747. }
  8748. prevLayer.__endIndex = idx;
  8749. }
  8750. }
  8751. if (this._singleCanvas) {
  8752. for (var i = 1; i < list.length; i++) {
  8753. var el = list[i];
  8754. if (el.zlevel !== list[i - 1].zlevel || el.incremental) {
  8755. this._needsManuallyCompositing = true;
  8756. break;
  8757. }
  8758. }
  8759. }
  8760. var prevLayer = null;
  8761. var incrementalLayerCount = 0;
  8762. var prevZlevel;
  8763. for (var i = 0; i < list.length; i++) {
  8764. var el = list[i];
  8765. var zlevel = el.zlevel;
  8766. var layer;
  8767. if (prevZlevel !== zlevel) {
  8768. prevZlevel = zlevel;
  8769. incrementalLayerCount = 0;
  8770. }
  8771. // TODO Not use magic number on zlevel.
  8772. // Each layer with increment element can be separated to 3 layers.
  8773. // (Other Element drawn after incremental element)
  8774. // -----------------zlevel + EL_AFTER_INCREMENTAL_INC--------------------
  8775. // (Incremental element)
  8776. // ----------------------zlevel + INCREMENTAL_INC------------------------
  8777. // (Element drawn before incremental element)
  8778. // --------------------------------zlevel--------------------------------
  8779. if (el.incremental) {
  8780. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  8781. layer.incremental = true;
  8782. incrementalLayerCount = 1;
  8783. }
  8784. else {
  8785. layer = this.getLayer(
  8786. zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0),
  8787. this._needsManuallyCompositing
  8788. );
  8789. }
  8790. if (!layer.__builtin__) {
  8791. logError$1('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  8792. }
  8793. if (layer !== prevLayer) {
  8794. layer.__used = true;
  8795. if (layer.__startIndex !== i) {
  8796. layer.__dirty = true;
  8797. }
  8798. layer.__startIndex = i;
  8799. if (!layer.incremental) {
  8800. layer.__drawIndex = i;
  8801. }
  8802. else {
  8803. // Mark layer draw index needs to update.
  8804. layer.__drawIndex = -1;
  8805. }
  8806. updatePrevLayer(i);
  8807. prevLayer = layer;
  8808. }
  8809. if (el.__dirty) {
  8810. layer.__dirty = true;
  8811. if (layer.incremental && layer.__drawIndex < 0) {
  8812. // Start draw from the first dirty element.
  8813. layer.__drawIndex = i;
  8814. }
  8815. }
  8816. }
  8817. updatePrevLayer(i);
  8818. this.eachBuiltinLayer(function (layer, z) {
  8819. // Used in last frame but not in this frame. Needs clear
  8820. if (!layer.__used && layer.getElementCount() > 0) {
  8821. layer.__dirty = true;
  8822. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  8823. }
  8824. // For incremental layer. In case start index changed and no elements are dirty.
  8825. if (layer.__dirty && layer.__drawIndex < 0) {
  8826. layer.__drawIndex = layer.__startIndex;
  8827. }
  8828. });
  8829. },
  8830. /**
  8831. * 清除hover层外所有内容
  8832. */
  8833. clear: function () {
  8834. this.eachBuiltinLayer(this._clearLayer);
  8835. return this;
  8836. },
  8837. _clearLayer: function (layer) {
  8838. layer.clear();
  8839. },
  8840. setBackgroundColor: function (backgroundColor) {
  8841. this._backgroundColor = backgroundColor;
  8842. },
  8843. /**
  8844. * 修改指定zlevel的绘制参数
  8845. *
  8846. * @param {string} zlevel
  8847. * @param {Object} config 配置对象
  8848. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  8849. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  8850. * @param {number} [config.lastFrameAlpha=0.7]
  8851. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  8852. */
  8853. configLayer: function (zlevel, config) {
  8854. if (config) {
  8855. var layerConfig = this._layerConfig;
  8856. if (!layerConfig[zlevel]) {
  8857. layerConfig[zlevel] = config;
  8858. }
  8859. else {
  8860. merge(layerConfig[zlevel], config, true);
  8861. }
  8862. for (var i = 0; i < this._zlevelList.length; i++) {
  8863. var _zlevel = this._zlevelList[i];
  8864. // TODO Remove EL_AFTER_INCREMENTAL_INC magic number
  8865. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  8866. var layer = this._layers[_zlevel];
  8867. merge(layer, layerConfig[zlevel], true);
  8868. }
  8869. }
  8870. }
  8871. },
  8872. /**
  8873. * 删除指定层
  8874. * @param {number} zlevel 层所在的zlevel
  8875. */
  8876. delLayer: function (zlevel) {
  8877. var layers = this._layers;
  8878. var zlevelList = this._zlevelList;
  8879. var layer = layers[zlevel];
  8880. if (!layer) {
  8881. return;
  8882. }
  8883. layer.dom.parentNode.removeChild(layer.dom);
  8884. delete layers[zlevel];
  8885. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  8886. },
  8887. /**
  8888. * 区域大小变化后重绘
  8889. */
  8890. resize: function (width, height) {
  8891. if (!this._domRoot.style) { // Maybe in node or worker
  8892. if (width == null || height == null) {
  8893. return;
  8894. }
  8895. this._width = width;
  8896. this._height = height;
  8897. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  8898. }
  8899. else {
  8900. var domRoot = this._domRoot;
  8901. // FIXME Why ?
  8902. domRoot.style.display = 'none';
  8903. // Save input w/h
  8904. var opts = this._opts;
  8905. width != null && (opts.width = width);
  8906. height != null && (opts.height = height);
  8907. width = this._getSize(0);
  8908. height = this._getSize(1);
  8909. domRoot.style.display = '';
  8910. // 优化没有实际改变的resize
  8911. if (this._width !== width || height !== this._height) {
  8912. domRoot.style.width = width + 'px';
  8913. domRoot.style.height = height + 'px';
  8914. for (var id in this._layers) {
  8915. if (this._layers.hasOwnProperty(id)) {
  8916. this._layers[id].resize(width, height);
  8917. }
  8918. }
  8919. each$1(this._progressiveLayers, function (layer) {
  8920. layer.resize(width, height);
  8921. });
  8922. this.refresh(true);
  8923. }
  8924. this._width = width;
  8925. this._height = height;
  8926. }
  8927. return this;
  8928. },
  8929. /**
  8930. * 清除单独的一个层
  8931. * @param {number} zlevel
  8932. */
  8933. clearLayer: function (zlevel) {
  8934. var layer = this._layers[zlevel];
  8935. if (layer) {
  8936. layer.clear();
  8937. }
  8938. },
  8939. /**
  8940. * 释放
  8941. */
  8942. dispose: function () {
  8943. this.root.innerHTML = '';
  8944. this.root =
  8945. this.storage =
  8946. this._domRoot =
  8947. this._layers = null;
  8948. },
  8949. /**
  8950. * Get canvas which has all thing rendered
  8951. * @param {Object} opts
  8952. * @param {string} [opts.backgroundColor]
  8953. * @param {number} [opts.pixelRatio]
  8954. */
  8955. getRenderedCanvas: function (opts) {
  8956. opts = opts || {};
  8957. if (this._singleCanvas && !this._compositeManually) {
  8958. return this._layers[CANVAS_ZLEVEL].dom;
  8959. }
  8960. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  8961. imageLayer.initContext();
  8962. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  8963. if (opts.pixelRatio <= this.dpr) {
  8964. this.refresh();
  8965. var width = imageLayer.dom.width;
  8966. var height = imageLayer.dom.height;
  8967. var ctx = imageLayer.ctx;
  8968. this.eachLayer(function (layer) {
  8969. if (layer.__builtin__) {
  8970. ctx.drawImage(layer.dom, 0, 0, width, height);
  8971. }
  8972. else if (layer.renderToCanvas) {
  8973. imageLayer.ctx.save();
  8974. layer.renderToCanvas(imageLayer.ctx);
  8975. imageLayer.ctx.restore();
  8976. }
  8977. });
  8978. }
  8979. else {
  8980. // PENDING, echarts-gl and incremental rendering.
  8981. var scope = {};
  8982. var displayList = this.storage.getDisplayList(true);
  8983. for (var i = 0; i < displayList.length; i++) {
  8984. var el = displayList[i];
  8985. this._doPaintEl(el, imageLayer, true, scope);
  8986. }
  8987. }
  8988. return imageLayer.dom;
  8989. },
  8990. /**
  8991. * 获取绘图区域宽度
  8992. */
  8993. getWidth: function () {
  8994. return this._width;
  8995. },
  8996. /**
  8997. * 获取绘图区域高度
  8998. */
  8999. getHeight: function () {
  9000. return this._height;
  9001. },
  9002. _getSize: function (whIdx) {
  9003. var opts = this._opts;
  9004. var wh = ['width', 'height'][whIdx];
  9005. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  9006. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  9007. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  9008. if (opts[wh] != null && opts[wh] !== 'auto') {
  9009. return parseFloat(opts[wh]);
  9010. }
  9011. var root = this.root;
  9012. // IE8 does not support getComputedStyle, but it use VML.
  9013. var stl = document.defaultView.getComputedStyle(root);
  9014. return (
  9015. (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  9016. - (parseInt10(stl[plt]) || 0)
  9017. - (parseInt10(stl[prb]) || 0)
  9018. ) | 0;
  9019. },
  9020. pathToImage: function (path, dpr) {
  9021. dpr = dpr || this.dpr;
  9022. var canvas = document.createElement('canvas');
  9023. var ctx = canvas.getContext('2d');
  9024. var rect = path.getBoundingRect();
  9025. var style = path.style;
  9026. var shadowBlurSize = style.shadowBlur * dpr;
  9027. var shadowOffsetX = style.shadowOffsetX * dpr;
  9028. var shadowOffsetY = style.shadowOffsetY * dpr;
  9029. var lineWidth = style.hasStroke() ? style.lineWidth : 0;
  9030. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  9031. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  9032. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  9033. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  9034. var width = rect.width + leftMargin + rightMargin;
  9035. var height = rect.height + topMargin + bottomMargin;
  9036. canvas.width = width * dpr;
  9037. canvas.height = height * dpr;
  9038. ctx.scale(dpr, dpr);
  9039. ctx.clearRect(0, 0, width, height);
  9040. ctx.dpr = dpr;
  9041. var pathTransform = {
  9042. position: path.position,
  9043. rotation: path.rotation,
  9044. scale: path.scale
  9045. };
  9046. path.position = [leftMargin - rect.x, topMargin - rect.y];
  9047. path.rotation = 0;
  9048. path.scale = [1, 1];
  9049. path.updateTransform();
  9050. if (path) {
  9051. path.brush(ctx);
  9052. }
  9053. var ImageShape = ZImage;
  9054. var imgShape = new ImageShape({
  9055. style: {
  9056. x: 0,
  9057. y: 0,
  9058. image: canvas
  9059. }
  9060. });
  9061. if (pathTransform.position != null) {
  9062. imgShape.position = path.position = pathTransform.position;
  9063. }
  9064. if (pathTransform.rotation != null) {
  9065. imgShape.rotation = path.rotation = pathTransform.rotation;
  9066. }
  9067. if (pathTransform.scale != null) {
  9068. imgShape.scale = path.scale = pathTransform.scale;
  9069. }
  9070. return imgShape;
  9071. }
  9072. };
  9073. /**
  9074. * Animation main class, dispatch and manage all animation controllers
  9075. *
  9076. * @module zrender/animation/Animation
  9077. * @author pissang(https://github.com/pissang)
  9078. */
  9079. // TODO Additive animation
  9080. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  9081. // https://developer.apple.com/videos/wwdc2014/#236
  9082. /**
  9083. * @typedef {Object} IZRenderStage
  9084. * @property {Function} update
  9085. */
  9086. /**
  9087. * @alias module:zrender/animation/Animation
  9088. * @constructor
  9089. * @param {Object} [options]
  9090. * @param {Function} [options.onframe]
  9091. * @param {IZRenderStage} [options.stage]
  9092. * @example
  9093. * var animation = new Animation();
  9094. * var obj = {
  9095. * x: 100,
  9096. * y: 100
  9097. * };
  9098. * animation.animate(node.position)
  9099. * .when(1000, {
  9100. * x: 500,
  9101. * y: 500
  9102. * })
  9103. * .when(2000, {
  9104. * x: 100,
  9105. * y: 100
  9106. * })
  9107. * .start('spline');
  9108. */
  9109. var Animation = function (options) {
  9110. options = options || {};
  9111. this.stage = options.stage || {};
  9112. this.onframe = options.onframe || function () {};
  9113. // private properties
  9114. this._clips = [];
  9115. this._running = false;
  9116. this._time;
  9117. this._pausedTime;
  9118. this._pauseStart;
  9119. this._paused = false;
  9120. Eventful.call(this);
  9121. };
  9122. Animation.prototype = {
  9123. constructor: Animation,
  9124. /**
  9125. * Add clip
  9126. * @param {module:zrender/animation/Clip} clip
  9127. */
  9128. addClip: function (clip) {
  9129. this._clips.push(clip);
  9130. },
  9131. /**
  9132. * Add animator
  9133. * @param {module:zrender/animation/Animator} animator
  9134. */
  9135. addAnimator: function (animator) {
  9136. animator.animation = this;
  9137. var clips = animator.getClips();
  9138. for (var i = 0; i < clips.length; i++) {
  9139. this.addClip(clips[i]);
  9140. }
  9141. },
  9142. /**
  9143. * Delete animation clip
  9144. * @param {module:zrender/animation/Clip} clip
  9145. */
  9146. removeClip: function (clip) {
  9147. var idx = indexOf(this._clips, clip);
  9148. if (idx >= 0) {
  9149. this._clips.splice(idx, 1);
  9150. }
  9151. },
  9152. /**
  9153. * Delete animation clip
  9154. * @param {module:zrender/animation/Animator} animator
  9155. */
  9156. removeAnimator: function (animator) {
  9157. var clips = animator.getClips();
  9158. for (var i = 0; i < clips.length; i++) {
  9159. this.removeClip(clips[i]);
  9160. }
  9161. animator.animation = null;
  9162. },
  9163. _update: function () {
  9164. var time = new Date().getTime() - this._pausedTime;
  9165. var delta = time - this._time;
  9166. var clips = this._clips;
  9167. var len = clips.length;
  9168. var deferredEvents = [];
  9169. var deferredClips = [];
  9170. for (var i = 0; i < len; i++) {
  9171. var clip = clips[i];
  9172. var e = clip.step(time, delta);
  9173. // Throw out the events need to be called after
  9174. // stage.update, like destroy
  9175. if (e) {
  9176. deferredEvents.push(e);
  9177. deferredClips.push(clip);
  9178. }
  9179. }
  9180. // Remove the finished clip
  9181. for (var i = 0; i < len;) {
  9182. if (clips[i]._needsRemove) {
  9183. clips[i] = clips[len - 1];
  9184. clips.pop();
  9185. len--;
  9186. }
  9187. else {
  9188. i++;
  9189. }
  9190. }
  9191. len = deferredEvents.length;
  9192. for (var i = 0; i < len; i++) {
  9193. deferredClips[i].fire(deferredEvents[i]);
  9194. }
  9195. this._time = time;
  9196. this.onframe(delta);
  9197. // 'frame' should be triggered before stage, because upper application
  9198. // depends on the sequence (e.g., echarts-stream and finish
  9199. // event judge)
  9200. this.trigger('frame', delta);
  9201. if (this.stage.update) {
  9202. this.stage.update();
  9203. }
  9204. },
  9205. _startLoop: function () {
  9206. var self = this;
  9207. this._running = true;
  9208. function step() {
  9209. if (self._running) {
  9210. requestAnimationFrame(step);
  9211. !self._paused && self._update();
  9212. }
  9213. }
  9214. requestAnimationFrame(step);
  9215. },
  9216. /**
  9217. * Start animation.
  9218. */
  9219. start: function () {
  9220. this._time = new Date().getTime();
  9221. this._pausedTime = 0;
  9222. this._startLoop();
  9223. },
  9224. /**
  9225. * Stop animation.
  9226. */
  9227. stop: function () {
  9228. this._running = false;
  9229. },
  9230. /**
  9231. * Pause animation.
  9232. */
  9233. pause: function () {
  9234. if (!this._paused) {
  9235. this._pauseStart = new Date().getTime();
  9236. this._paused = true;
  9237. }
  9238. },
  9239. /**
  9240. * Resume animation.
  9241. */
  9242. resume: function () {
  9243. if (this._paused) {
  9244. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  9245. this._paused = false;
  9246. }
  9247. },
  9248. /**
  9249. * Clear animation.
  9250. */
  9251. clear: function () {
  9252. this._clips = [];
  9253. },
  9254. /**
  9255. * Whether animation finished.
  9256. */
  9257. isFinished: function () {
  9258. return !this._clips.length;
  9259. },
  9260. /**
  9261. * Creat animator for a target, whose props can be animated.
  9262. *
  9263. * @param {Object} target
  9264. * @param {Object} options
  9265. * @param {boolean} [options.loop=false] Whether loop animation.
  9266. * @param {Function} [options.getter=null] Get value from target.
  9267. * @param {Function} [options.setter=null] Set value to target.
  9268. * @return {module:zrender/animation/Animation~Animator}
  9269. */
  9270. // TODO Gap
  9271. animate: function (target, options) {
  9272. options = options || {};
  9273. var animator = new Animator(
  9274. target,
  9275. options.loop,
  9276. options.getter,
  9277. options.setter
  9278. );
  9279. this.addAnimator(animator);
  9280. return animator;
  9281. }
  9282. };
  9283. mixin(Animation, Eventful);
  9284. /* global document */
  9285. var TOUCH_CLICK_DELAY = 300;
  9286. var globalEventSupported = env$1.domSupported;
  9287. var localNativeListenerNames = (function () {
  9288. var mouseHandlerNames = [
  9289. 'click', 'dblclick', 'mousewheel', 'mouseout',
  9290. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  9291. ];
  9292. var touchHandlerNames = [
  9293. 'touchstart', 'touchend', 'touchmove'
  9294. ];
  9295. var pointerEventNameMap = {
  9296. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  9297. };
  9298. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  9299. var nm = name.replace('mouse', 'pointer');
  9300. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  9301. });
  9302. return {
  9303. mouse: mouseHandlerNames,
  9304. touch: touchHandlerNames,
  9305. pointer: pointerHandlerNames
  9306. };
  9307. })();
  9308. var globalNativeListenerNames = {
  9309. mouse: ['mousemove', 'mouseup'],
  9310. pointer: ['pointermove', 'pointerup']
  9311. };
  9312. function eventNameFix(name) {
  9313. return (name === 'mousewheel' && env$1.browser.firefox) ? 'DOMMouseScroll' : name;
  9314. }
  9315. function isPointerFromTouch(event) {
  9316. var pointerType = event.pointerType;
  9317. return pointerType === 'pen' || pointerType === 'touch';
  9318. }
  9319. // function useMSGuesture(handlerProxy, event) {
  9320. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  9321. // }
  9322. // function onMSGestureChange(proxy, event) {
  9323. // if (event.translationX || event.translationY) {
  9324. // // mousemove is carried by MSGesture to reduce the sensitivity.
  9325. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  9326. // }
  9327. // if (event.scale !== 1) {
  9328. // event.pinchX = event.offsetX;
  9329. // event.pinchY = event.offsetY;
  9330. // event.pinchScale = event.scale;
  9331. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  9332. // }
  9333. // }
  9334. /**
  9335. * Prevent mouse event from being dispatched after Touch Events action
  9336. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  9337. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  9338. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  9339. * Result: Blocking Mouse Events for 700ms.
  9340. *
  9341. * @param {DOMHandlerScope} scope
  9342. */
  9343. function setTouchTimer(scope) {
  9344. scope.touching = true;
  9345. if (scope.touchTimer != null) {
  9346. clearTimeout(scope.touchTimer);
  9347. scope.touchTimer = null;
  9348. }
  9349. scope.touchTimer = setTimeout(function () {
  9350. scope.touching = false;
  9351. scope.touchTimer = null;
  9352. }, 700);
  9353. }
  9354. // Mark touch, which is useful in distinguish touch and
  9355. // mouse event in upper applicatoin.
  9356. function markTouch(event) {
  9357. event && (event.zrByTouch = true);
  9358. }
  9359. // function markTriggeredFromLocal(event) {
  9360. // event && (event.__zrIsFromLocal = true);
  9361. // }
  9362. // function isTriggeredFromLocal(instance, event) {
  9363. // return !!(event && event.__zrIsFromLocal);
  9364. // }
  9365. function normalizeGlobalEvent(instance, event) {
  9366. // offsetX, offsetY still need to be calculated. They are necessary in the event
  9367. // handlers of the upper applications. Set `true` to force calculate them.
  9368. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  9369. }
  9370. /**
  9371. * Detect whether the given el is in `painterRoot`.
  9372. */
  9373. function isLocalEl(instance, el) {
  9374. var elTmp = el;
  9375. var isLocal = false;
  9376. while (elTmp && elTmp.nodeType !== 9
  9377. && !(
  9378. isLocal = elTmp.domBelongToZr
  9379. || (elTmp !== el && elTmp === instance.painterRoot)
  9380. )
  9381. ) {
  9382. elTmp = elTmp.parentNode;
  9383. }
  9384. return isLocal;
  9385. }
  9386. /**
  9387. * Make a fake event but not change the original event,
  9388. * becuase the global event probably be used by other
  9389. * listeners not belonging to zrender.
  9390. * @class
  9391. */
  9392. function FakeGlobalEvent(instance, event) {
  9393. this.type = event.type;
  9394. this.target = this.currentTarget = instance.dom;
  9395. this.pointerType = event.pointerType;
  9396. // Necessray for the force calculation of zrX, zrY
  9397. this.clientX = event.clientX;
  9398. this.clientY = event.clientY;
  9399. // Because we do not mount global listeners to touch events,
  9400. // we do not copy `targetTouches` and `changedTouches` here.
  9401. }
  9402. var fakeGlobalEventProto = FakeGlobalEvent.prototype;
  9403. // we make the default methods on the event do nothing,
  9404. // otherwise it is dangerous. See more details in
  9405. // [Drag outside] in `Handler.js`.
  9406. fakeGlobalEventProto.stopPropagation =
  9407. fakeGlobalEventProto.stopImmediatePropagation =
  9408. fakeGlobalEventProto.preventDefault = noop;
  9409. /**
  9410. * Local DOM Handlers
  9411. * @this {HandlerProxy}
  9412. */
  9413. var localDOMHandlers = {
  9414. mousedown: function (event) {
  9415. event = normalizeEvent(this.dom, event);
  9416. this._mayPointerCapture = [event.zrX, event.zrY];
  9417. this.trigger('mousedown', event);
  9418. },
  9419. mousemove: function (event) {
  9420. event = normalizeEvent(this.dom, event);
  9421. var downPoint = this._mayPointerCapture;
  9422. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  9423. togglePointerCapture(this, true);
  9424. }
  9425. this.trigger('mousemove', event);
  9426. },
  9427. mouseup: function (event) {
  9428. event = normalizeEvent(this.dom, event);
  9429. togglePointerCapture(this, false);
  9430. this.trigger('mouseup', event);
  9431. },
  9432. mouseout: function (event) {
  9433. event = normalizeEvent(this.dom, event);
  9434. // Similarly to the browser did on `document` and touch event,
  9435. // `globalout` will be delayed to final pointer cature release.
  9436. if (this._pointerCapturing) {
  9437. event.zrEventControl = 'no_globalout';
  9438. }
  9439. // There might be some doms created by upper layer application
  9440. // at the same level of painter.getViewportRoot() (e.g., tooltip
  9441. // dom created by echarts), where 'globalout' event should not
  9442. // be triggered when mouse enters these doms. (But 'mouseout'
  9443. // should be triggered at the original hovered element as usual).
  9444. var element = event.toElement || event.relatedTarget;
  9445. event.zrIsToLocalDOM = isLocalEl(this, element);
  9446. this.trigger('mouseout', event);
  9447. },
  9448. touchstart: function (event) {
  9449. // Default mouse behaviour should not be disabled here.
  9450. // For example, page may needs to be slided.
  9451. event = normalizeEvent(this.dom, event);
  9452. markTouch(event);
  9453. this._lastTouchMoment = new Date();
  9454. this.handler.processGesture(event, 'start');
  9455. // For consistent event listener for both touch device and mouse device,
  9456. // we simulate "mouseover-->mousedown" in touch device. So we trigger
  9457. // `mousemove` here (to trigger `mouseover` inside), and then trigger
  9458. // `mousedown`.
  9459. localDOMHandlers.mousemove.call(this, event);
  9460. localDOMHandlers.mousedown.call(this, event);
  9461. },
  9462. touchmove: function (event) {
  9463. event = normalizeEvent(this.dom, event);
  9464. markTouch(event);
  9465. this.handler.processGesture(event, 'change');
  9466. // Mouse move should always be triggered no matter whether
  9467. // there is gestrue event, because mouse move and pinch may
  9468. // be used at the same time.
  9469. localDOMHandlers.mousemove.call(this, event);
  9470. },
  9471. touchend: function (event) {
  9472. event = normalizeEvent(this.dom, event);
  9473. markTouch(event);
  9474. this.handler.processGesture(event, 'end');
  9475. localDOMHandlers.mouseup.call(this, event);
  9476. // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  9477. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  9478. // we can conveniently implement "hover style" in both PC and touch device just
  9479. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  9480. // to remove "hover style" on an element, without any additional code for
  9481. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  9482. // style" will remain for user view)
  9483. // click event should always be triggered no matter whether
  9484. // there is gestrue event. System click can not be prevented.
  9485. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  9486. localDOMHandlers.click.call(this, event);
  9487. }
  9488. },
  9489. pointerdown: function (event) {
  9490. localDOMHandlers.mousedown.call(this, event);
  9491. // if (useMSGuesture(this, event)) {
  9492. // this._msGesture.addPointer(event.pointerId);
  9493. // }
  9494. },
  9495. pointermove: function (event) {
  9496. // FIXME
  9497. // pointermove is so sensitive that it always triggered when
  9498. // tap(click) on touch screen, which affect some judgement in
  9499. // upper application. So, we dont support mousemove on MS touch
  9500. // device yet.
  9501. if (!isPointerFromTouch(event)) {
  9502. localDOMHandlers.mousemove.call(this, event);
  9503. }
  9504. },
  9505. pointerup: function (event) {
  9506. localDOMHandlers.mouseup.call(this, event);
  9507. },
  9508. pointerout: function (event) {
  9509. // pointerout will be triggered when tap on touch screen
  9510. // (IE11+/Edge on MS Surface) after click event triggered,
  9511. // which is inconsistent with the mousout behavior we defined
  9512. // in touchend. So we unify them.
  9513. // (check localDOMHandlers.touchend for detailed explanation)
  9514. if (!isPointerFromTouch(event)) {
  9515. localDOMHandlers.mouseout.call(this, event);
  9516. }
  9517. }
  9518. };
  9519. /**
  9520. * Othere DOM UI Event handlers for zr dom.
  9521. * @this {HandlerProxy}
  9522. */
  9523. each$1(['click', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  9524. localDOMHandlers[name] = function (event) {
  9525. event = normalizeEvent(this.dom, event);
  9526. this.trigger(name, event);
  9527. };
  9528. });
  9529. /**
  9530. * DOM UI Event handlers for global page.
  9531. *
  9532. * [Caution]:
  9533. * those handlers should both support in capture phase and bubble phase!
  9534. *
  9535. * @this {HandlerProxy}
  9536. */
  9537. var globalDOMHandlers = {
  9538. pointermove: function (event) {
  9539. // FIXME
  9540. // pointermove is so sensitive that it always triggered when
  9541. // tap(click) on touch screen, which affect some judgement in
  9542. // upper application. So, we dont support mousemove on MS touch
  9543. // device yet.
  9544. if (!isPointerFromTouch(event)) {
  9545. globalDOMHandlers.mousemove.call(this, event);
  9546. }
  9547. },
  9548. pointerup: function (event) {
  9549. globalDOMHandlers.mouseup.call(this, event);
  9550. },
  9551. mousemove: function (event) {
  9552. this.trigger('mousemove', event);
  9553. },
  9554. mouseup: function (event) {
  9555. var pointerCaptureReleasing = this._pointerCapturing;
  9556. togglePointerCapture(this, false);
  9557. this.trigger('mouseup', event);
  9558. if (pointerCaptureReleasing) {
  9559. event.zrEventControl = 'only_globalout';
  9560. this.trigger('mouseout', event);
  9561. }
  9562. }
  9563. };
  9564. /**
  9565. * @param {HandlerProxy} instance
  9566. * @param {DOMHandlerScope} scope
  9567. */
  9568. function mountLocalDOMEventListeners(instance, scope) {
  9569. var domHandlers = scope.domHandlers;
  9570. if (env$1.pointerEventsSupported) { // Only IE11+/Edge
  9571. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  9572. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  9573. // at the same time.
  9574. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  9575. // screen, which do not occurs in pointer event.
  9576. // So we use pointer event to both detect touch gesture and mouse behavior.
  9577. each$1(localNativeListenerNames.pointer, function (nativeEventName) {
  9578. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9579. // markTriggeredFromLocal(event);
  9580. domHandlers[nativeEventName].call(instance, event);
  9581. });
  9582. });
  9583. // FIXME
  9584. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  9585. // which does not prevent defuault behavior occasionally (which may cause view port
  9586. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  9587. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  9588. // touch screen. And we only support click behavior on MS touch screen now.
  9589. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  9590. // We dont support touch on IE on win7.
  9591. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  9592. // if (typeof MSGesture === 'function') {
  9593. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  9594. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  9595. // }
  9596. }
  9597. else {
  9598. if (env$1.touchEventsSupported) {
  9599. each$1(localNativeListenerNames.touch, function (nativeEventName) {
  9600. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9601. // markTriggeredFromLocal(event);
  9602. domHandlers[nativeEventName].call(instance, event);
  9603. setTouchTimer(scope);
  9604. });
  9605. });
  9606. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  9607. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  9608. }
  9609. // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  9610. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  9611. // mouse event can not be handle in those devices.
  9612. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  9613. // mouseevent after touch event triggered, see `setTouchTimer`.
  9614. each$1(localNativeListenerNames.mouse, function (nativeEventName) {
  9615. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9616. event = getNativeEvent(event);
  9617. if (!scope.touching) {
  9618. // markTriggeredFromLocal(event);
  9619. domHandlers[nativeEventName].call(instance, event);
  9620. }
  9621. });
  9622. });
  9623. }
  9624. }
  9625. /**
  9626. * @param {HandlerProxy} instance
  9627. * @param {DOMHandlerScope} scope
  9628. */
  9629. function mountGlobalDOMEventListeners(instance, scope) {
  9630. // Only IE11+/Edge. See the comment in `mountLocalDOMEventListeners`.
  9631. if (env$1.pointerEventsSupported) {
  9632. each$1(globalNativeListenerNames.pointer, mount);
  9633. }
  9634. // Touch event has implemented "drag outside" so we do not mount global listener for touch event.
  9635. // (see https://www.w3.org/TR/touch-events/#the-touchmove-event)
  9636. // We do not consider "both-support-touch-and-mouse device" for this feature (see the comment of
  9637. // `mountLocalDOMEventListeners`) to avoid bugs util some requirements come.
  9638. else if (!env$1.touchEventsSupported) {
  9639. each$1(globalNativeListenerNames.mouse, mount);
  9640. }
  9641. function mount(nativeEventName) {
  9642. function nativeEventListener(event) {
  9643. event = getNativeEvent(event);
  9644. // See the reason in [Drag outside] in `Handler.js`
  9645. // This checking supports both `useCapture` or not.
  9646. // PENDING: if there is performance issue in some devices,
  9647. // we probably can not use `useCapture` and change a easier
  9648. // to judes whether local (mark).
  9649. if (!isLocalEl(instance, event.target)) {
  9650. event = normalizeGlobalEvent(instance, event);
  9651. scope.domHandlers[nativeEventName].call(instance, event);
  9652. }
  9653. }
  9654. mountSingleDOMEventListener(
  9655. scope, nativeEventName, nativeEventListener,
  9656. {capture: true} // See [Drag Outside] in `Handler.js`
  9657. );
  9658. }
  9659. }
  9660. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  9661. scope.mounted[nativeEventName] = listener;
  9662. scope.listenerOpts[nativeEventName] = opt;
  9663. addEventListener(scope.domTarget, eventNameFix(nativeEventName), listener, opt);
  9664. }
  9665. function unmountDOMEventListeners(scope) {
  9666. var mounted = scope.mounted;
  9667. for (var nativeEventName in mounted) {
  9668. if (mounted.hasOwnProperty(nativeEventName)) {
  9669. removeEventListener(
  9670. scope.domTarget, eventNameFix(nativeEventName), mounted[nativeEventName],
  9671. scope.listenerOpts[nativeEventName]
  9672. );
  9673. }
  9674. }
  9675. scope.mounted = {};
  9676. }
  9677. /**
  9678. * See [Drag Outside] in `Handler.js`.
  9679. * @implement
  9680. * @param {boolean} isPointerCapturing Should never be `null`/`undefined`.
  9681. * `true`: start to capture pointer if it is not capturing.
  9682. * `false`: end the capture if it is capturing.
  9683. */
  9684. function togglePointerCapture(instance, isPointerCapturing) {
  9685. instance._mayPointerCapture = null;
  9686. if (globalEventSupported && (instance._pointerCapturing ^ isPointerCapturing)) {
  9687. instance._pointerCapturing = isPointerCapturing;
  9688. var globalHandlerScope = instance._globalHandlerScope;
  9689. isPointerCapturing
  9690. ? mountGlobalDOMEventListeners(instance, globalHandlerScope)
  9691. : unmountDOMEventListeners(globalHandlerScope);
  9692. }
  9693. }
  9694. /**
  9695. * @inner
  9696. * @class
  9697. */
  9698. function DOMHandlerScope(domTarget, domHandlers) {
  9699. this.domTarget = domTarget;
  9700. this.domHandlers = domHandlers;
  9701. // Key: eventName, value: mounted handler funcitons.
  9702. // Used for unmount.
  9703. this.mounted = {};
  9704. this.listenerOpts = {};
  9705. this.touchTimer = null;
  9706. this.touching = false;
  9707. }
  9708. /**
  9709. * @public
  9710. * @class
  9711. */
  9712. function HandlerDomProxy(dom, painterRoot) {
  9713. Eventful.call(this);
  9714. this.dom = dom;
  9715. this.painterRoot = painterRoot;
  9716. this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  9717. if (globalEventSupported) {
  9718. this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  9719. }
  9720. /**
  9721. * @type {boolean}
  9722. */
  9723. this._pointerCapturing = false;
  9724. /**
  9725. * @type {Array.<number>} [x, y] or null.
  9726. */
  9727. this._mayPointerCapture = null;
  9728. mountLocalDOMEventListeners(this, this._localHandlerScope);
  9729. }
  9730. var handlerDomProxyProto = HandlerDomProxy.prototype;
  9731. handlerDomProxyProto.dispose = function () {
  9732. unmountDOMEventListeners(this._localHandlerScope);
  9733. if (globalEventSupported) {
  9734. unmountDOMEventListeners(this._globalHandlerScope);
  9735. }
  9736. };
  9737. handlerDomProxyProto.setCursor = function (cursorStyle) {
  9738. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  9739. };
  9740. mixin(HandlerDomProxy, Eventful);
  9741. /*!
  9742. * ZRender, a high performance 2d drawing library.
  9743. *
  9744. * Copyright (c) 2013, Baidu Inc.
  9745. * All rights reserved.
  9746. *
  9747. * LICENSE
  9748. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  9749. */
  9750. var useVML = !env$1.canvasSupported;
  9751. var painterCtors = {
  9752. canvas: Painter
  9753. };
  9754. /**
  9755. * @type {string}
  9756. */
  9757. var version$1 = '4.3.2';
  9758. /**
  9759. * Initializing a zrender instance
  9760. * @param {HTMLElement} dom
  9761. * @param {Object} [opts]
  9762. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9763. * @param {number} [opts.devicePixelRatio]
  9764. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9765. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9766. * @return {module:zrender/ZRender}
  9767. */
  9768. function init$1(dom, opts) {
  9769. var zr = new ZRender(guid(), dom, opts);
  9770. return zr;
  9771. }
  9772. /**
  9773. * Dispose zrender instance
  9774. * @param {module:zrender/ZRender} zr
  9775. */
  9776. /**
  9777. * Get zrender instance by id
  9778. * @param {string} id zrender instance id
  9779. * @return {module:zrender/ZRender}
  9780. */
  9781. /**
  9782. * @module zrender/ZRender
  9783. */
  9784. /**
  9785. * @constructor
  9786. * @alias module:zrender/ZRender
  9787. * @param {string} id
  9788. * @param {HTMLElement} dom
  9789. * @param {Object} opts
  9790. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9791. * @param {number} [opts.devicePixelRatio]
  9792. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  9793. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  9794. */
  9795. var ZRender = function (id, dom, opts) {
  9796. opts = opts || {};
  9797. /**
  9798. * @type {HTMLDomElement}
  9799. */
  9800. this.dom = dom;
  9801. /**
  9802. * @type {string}
  9803. */
  9804. this.id = id;
  9805. var self = this;
  9806. var storage = new Storage();
  9807. var rendererType = opts.renderer;
  9808. // TODO WebGL
  9809. if (useVML) {
  9810. if (!painterCtors.vml) {
  9811. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  9812. }
  9813. rendererType = 'vml';
  9814. }
  9815. else if (!rendererType || !painterCtors[rendererType]) {
  9816. rendererType = 'canvas';
  9817. }
  9818. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  9819. this.storage = storage;
  9820. this.painter = painter;
  9821. var handerProxy = (!env$1.node && !env$1.worker) ? new HandlerDomProxy(painter.getViewportRoot(), painter.root) : null;
  9822. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  9823. /**
  9824. * @type {module:zrender/animation/Animation}
  9825. */
  9826. this.animation = new Animation({
  9827. stage: {
  9828. update: bind(this.flush, this)
  9829. }
  9830. });
  9831. this.animation.start();
  9832. /**
  9833. * @type {boolean}
  9834. * @private
  9835. */
  9836. this._needsRefresh;
  9837. // 修改 storage.delFromStorage, 每次删除元素之前删除动画
  9838. // FIXME 有点ugly
  9839. var oldDelFromStorage = storage.delFromStorage;
  9840. var oldAddToStorage = storage.addToStorage;
  9841. storage.delFromStorage = function (el) {
  9842. oldDelFromStorage.call(storage, el);
  9843. el && el.removeSelfFromZr(self);
  9844. };
  9845. storage.addToStorage = function (el) {
  9846. oldAddToStorage.call(storage, el);
  9847. el.addSelfToZr(self);
  9848. };
  9849. };
  9850. ZRender.prototype = {
  9851. constructor: ZRender,
  9852. /**
  9853. * 获取实例唯一标识
  9854. * @return {string}
  9855. */
  9856. getId: function () {
  9857. return this.id;
  9858. },
  9859. /**
  9860. * 添加元素
  9861. * @param {module:zrender/Element} el
  9862. */
  9863. add: function (el) {
  9864. this.storage.addRoot(el);
  9865. this._needsRefresh = true;
  9866. },
  9867. /**
  9868. * 删除元素
  9869. * @param {module:zrender/Element} el
  9870. */
  9871. remove: function (el) {
  9872. this.storage.delRoot(el);
  9873. this._needsRefresh = true;
  9874. },
  9875. /**
  9876. * Change configuration of layer
  9877. * @param {string} zLevel
  9878. * @param {Object} config
  9879. * @param {string} [config.clearColor=0] Clear color
  9880. * @param {string} [config.motionBlur=false] If enable motion blur
  9881. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  9882. */
  9883. configLayer: function (zLevel, config) {
  9884. if (this.painter.configLayer) {
  9885. this.painter.configLayer(zLevel, config);
  9886. }
  9887. this._needsRefresh = true;
  9888. },
  9889. /**
  9890. * Set background color
  9891. * @param {string} backgroundColor
  9892. */
  9893. setBackgroundColor: function (backgroundColor) {
  9894. if (this.painter.setBackgroundColor) {
  9895. this.painter.setBackgroundColor(backgroundColor);
  9896. }
  9897. this._needsRefresh = true;
  9898. },
  9899. /**
  9900. * Repaint the canvas immediately
  9901. */
  9902. refreshImmediately: function () {
  9903. // var start = new Date();
  9904. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  9905. // Or it will cause zrender refreshes again and again.
  9906. this._needsRefresh = this._needsRefreshHover = false;
  9907. this.painter.refresh();
  9908. // Avoid trigger zr.refresh in Element#beforeUpdate hook
  9909. this._needsRefresh = this._needsRefreshHover = false;
  9910. // var end = new Date();
  9911. // var log = document.getElementById('log');
  9912. // if (log) {
  9913. // log.innerHTML = log.innerHTML + '<br>' + (end - start);
  9914. // }
  9915. },
  9916. /**
  9917. * Mark and repaint the canvas in the next frame of browser
  9918. */
  9919. refresh: function () {
  9920. this._needsRefresh = true;
  9921. },
  9922. /**
  9923. * Perform all refresh
  9924. */
  9925. flush: function () {
  9926. var triggerRendered;
  9927. if (this._needsRefresh) {
  9928. triggerRendered = true;
  9929. this.refreshImmediately();
  9930. }
  9931. if (this._needsRefreshHover) {
  9932. triggerRendered = true;
  9933. this.refreshHoverImmediately();
  9934. }
  9935. triggerRendered && this.trigger('rendered');
  9936. },
  9937. /**
  9938. * Add element to hover layer
  9939. * @param {module:zrender/Element} el
  9940. * @param {Object} style
  9941. */
  9942. addHover: function (el, style) {
  9943. if (this.painter.addHover) {
  9944. var elMirror = this.painter.addHover(el, style);
  9945. this.refreshHover();
  9946. return elMirror;
  9947. }
  9948. },
  9949. /**
  9950. * Add element from hover layer
  9951. * @param {module:zrender/Element} el
  9952. */
  9953. removeHover: function (el) {
  9954. if (this.painter.removeHover) {
  9955. this.painter.removeHover(el);
  9956. this.refreshHover();
  9957. }
  9958. },
  9959. /**
  9960. * Clear all hover elements in hover layer
  9961. * @param {module:zrender/Element} el
  9962. */
  9963. clearHover: function () {
  9964. if (this.painter.clearHover) {
  9965. this.painter.clearHover();
  9966. this.refreshHover();
  9967. }
  9968. },
  9969. /**
  9970. * Refresh hover in next frame
  9971. */
  9972. refreshHover: function () {
  9973. this._needsRefreshHover = true;
  9974. },
  9975. /**
  9976. * Refresh hover immediately
  9977. */
  9978. refreshHoverImmediately: function () {
  9979. this._needsRefreshHover = false;
  9980. this.painter.refreshHover && this.painter.refreshHover();
  9981. },
  9982. /**
  9983. * Resize the canvas.
  9984. * Should be invoked when container size is changed
  9985. * @param {Object} [opts]
  9986. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9987. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9988. */
  9989. resize: function (opts) {
  9990. opts = opts || {};
  9991. this.painter.resize(opts.width, opts.height);
  9992. this.handler.resize();
  9993. },
  9994. /**
  9995. * Stop and clear all animation immediately
  9996. */
  9997. clearAnimation: function () {
  9998. this.animation.clear();
  9999. },
  10000. /**
  10001. * Get container width
  10002. */
  10003. getWidth: function () {
  10004. return this.painter.getWidth();
  10005. },
  10006. /**
  10007. * Get container height
  10008. */
  10009. getHeight: function () {
  10010. return this.painter.getHeight();
  10011. },
  10012. /**
  10013. * Export the canvas as Base64 URL
  10014. * @param {string} type
  10015. * @param {string} [backgroundColor='#fff']
  10016. * @return {string} Base64 URL
  10017. */
  10018. // toDataURL: function(type, backgroundColor) {
  10019. // return this.painter.getRenderedCanvas({
  10020. // backgroundColor: backgroundColor
  10021. // }).toDataURL(type);
  10022. // },
  10023. /**
  10024. * Converting a path to image.
  10025. * It has much better performance of drawing image rather than drawing a vector path.
  10026. * @param {module:zrender/graphic/Path} e
  10027. * @param {number} width
  10028. * @param {number} height
  10029. */
  10030. pathToImage: function (e, dpr) {
  10031. return this.painter.pathToImage(e, dpr);
  10032. },
  10033. /**
  10034. * Set default cursor
  10035. * @param {string} [cursorStyle='default'] 例如 crosshair
  10036. */
  10037. setCursorStyle: function (cursorStyle) {
  10038. this.handler.setCursorStyle(cursorStyle);
  10039. },
  10040. /**
  10041. * Find hovered element
  10042. * @param {number} x
  10043. * @param {number} y
  10044. * @return {Object} {target, topTarget}
  10045. */
  10046. findHover: function (x, y) {
  10047. return this.handler.findHover(x, y);
  10048. },
  10049. /**
  10050. * Bind event
  10051. *
  10052. * @param {string} eventName Event name
  10053. * @param {Function} eventHandler Handler function
  10054. * @param {Object} [context] Context object
  10055. */
  10056. on: function (eventName, eventHandler, context) {
  10057. this.handler.on(eventName, eventHandler, context);
  10058. },
  10059. /**
  10060. * Unbind event
  10061. * @param {string} eventName Event name
  10062. * @param {Function} [eventHandler] Handler function
  10063. */
  10064. off: function (eventName, eventHandler) {
  10065. this.handler.off(eventName, eventHandler);
  10066. },
  10067. /**
  10068. * Trigger event manually
  10069. *
  10070. * @param {string} eventName Event name
  10071. * @param {event=} event Event object
  10072. */
  10073. trigger: function (eventName, event) {
  10074. this.handler.trigger(eventName, event);
  10075. },
  10076. /**
  10077. * Clear all objects and the canvas.
  10078. */
  10079. clear: function () {
  10080. this.storage.delRoot();
  10081. this.painter.clear();
  10082. },
  10083. /**
  10084. * Dispose self.
  10085. */
  10086. dispose: function () {
  10087. this.animation.stop();
  10088. this.clear();
  10089. this.storage.dispose();
  10090. this.painter.dispose();
  10091. this.handler.dispose();
  10092. this.animation =
  10093. this.storage =
  10094. this.painter =
  10095. this.handler = null;
  10096. }
  10097. };
  10098. /*
  10099. * Licensed to the Apache Software Foundation (ASF) under one
  10100. * or more contributor license agreements. See the NOTICE file
  10101. * distributed with this work for additional information
  10102. * regarding copyright ownership. The ASF licenses this file
  10103. * to you under the Apache License, Version 2.0 (the
  10104. * "License"); you may not use this file except in compliance
  10105. * with the License. You may obtain a copy of the License at
  10106. *
  10107. * http://www.apache.org/licenses/LICENSE-2.0
  10108. *
  10109. * Unless required by applicable law or agreed to in writing,
  10110. * software distributed under the License is distributed on an
  10111. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10112. * KIND, either express or implied. See the License for the
  10113. * specific language governing permissions and limitations
  10114. * under the License.
  10115. */
  10116. var each$2 = each$1;
  10117. var isObject$2 = isObject$1;
  10118. var isArray$1 = isArray;
  10119. /**
  10120. * Make the name displayable. But we should
  10121. * make sure it is not duplicated with user
  10122. * specified name, so use '\0';
  10123. */
  10124. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  10125. /**
  10126. * If value is not array, then translate it to array.
  10127. * @param {*} value
  10128. * @return {Array} [value] or value
  10129. */
  10130. function normalizeToArray(value) {
  10131. return value instanceof Array
  10132. ? value
  10133. : value == null
  10134. ? []
  10135. : [value];
  10136. }
  10137. /**
  10138. * Sync default option between normal and emphasis like `position` and `show`
  10139. * In case some one will write code like
  10140. * label: {
  10141. * show: false,
  10142. * position: 'outside',
  10143. * fontSize: 18
  10144. * },
  10145. * emphasis: {
  10146. * label: { show: true }
  10147. * }
  10148. * @param {Object} opt
  10149. * @param {string} key
  10150. * @param {Array.<string>} subOpts
  10151. */
  10152. function defaultEmphasis(opt, key, subOpts) {
  10153. // Caution: performance sensitive.
  10154. if (opt) {
  10155. opt[key] = opt[key] || {};
  10156. opt.emphasis = opt.emphasis || {};
  10157. opt.emphasis[key] = opt.emphasis[key] || {};
  10158. // Default emphasis option from normal
  10159. for (var i = 0, len = subOpts.length; i < len; i++) {
  10160. var subOptName = subOpts[i];
  10161. if (!opt.emphasis[key].hasOwnProperty(subOptName)
  10162. && opt[key].hasOwnProperty(subOptName)
  10163. ) {
  10164. opt.emphasis[key][subOptName] = opt[key][subOptName];
  10165. }
  10166. }
  10167. }
  10168. }
  10169. var TEXT_STYLE_OPTIONS = [
  10170. 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  10171. 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth',
  10172. 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline',
  10173. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY',
  10174. 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY',
  10175. 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'
  10176. ];
  10177. // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  10178. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  10179. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  10180. // // FIXME: deprecated, check and remove it.
  10181. // 'textStyle'
  10182. // ]);
  10183. /**
  10184. * The method do not ensure performance.
  10185. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  10186. * This helper method retieves value from data.
  10187. * @param {string|number|Date|Array|Object} dataItem
  10188. * @return {number|string|Date|Array.<number|string|Date>}
  10189. */
  10190. function getDataItemValue(dataItem) {
  10191. return (isObject$2(dataItem) && !isArray$1(dataItem) && !(dataItem instanceof Date))
  10192. ? dataItem.value : dataItem;
  10193. }
  10194. /**
  10195. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  10196. * This helper method determine if dataItem has extra option besides value
  10197. * @param {string|number|Date|Array|Object} dataItem
  10198. */
  10199. function isDataItemOption(dataItem) {
  10200. return isObject$2(dataItem)
  10201. && !(dataItem instanceof Array);
  10202. // // markLine data can be array
  10203. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  10204. }
  10205. /**
  10206. * Mapping to exists for merge.
  10207. *
  10208. * @public
  10209. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  10210. * @param {Object|Array.<Object>} newCptOptions
  10211. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  10212. * index of which is the same as exists.
  10213. */
  10214. function mappingToExists(exists, newCptOptions) {
  10215. // Mapping by the order by original option (but not order of
  10216. // new option) in merge mode. Because we should ensure
  10217. // some specified index (like xAxisIndex) is consistent with
  10218. // original option, which is easy to understand, espatially in
  10219. // media query. And in most case, merge option is used to
  10220. // update partial option but not be expected to change order.
  10221. newCptOptions = (newCptOptions || []).slice();
  10222. var result = map(exists || [], function (obj, index) {
  10223. return {exist: obj};
  10224. });
  10225. // Mapping by id or name if specified.
  10226. each$2(newCptOptions, function (cptOption, index) {
  10227. if (!isObject$2(cptOption)) {
  10228. return;
  10229. }
  10230. // id has highest priority.
  10231. for (var i = 0; i < result.length; i++) {
  10232. if (!result[i].option // Consider name: two map to one.
  10233. && cptOption.id != null
  10234. && result[i].exist.id === cptOption.id + ''
  10235. ) {
  10236. result[i].option = cptOption;
  10237. newCptOptions[index] = null;
  10238. return;
  10239. }
  10240. }
  10241. for (var i = 0; i < result.length; i++) {
  10242. var exist = result[i].exist;
  10243. if (!result[i].option // Consider name: two map to one.
  10244. // Can not match when both ids exist but different.
  10245. && (exist.id == null || cptOption.id == null)
  10246. && cptOption.name != null
  10247. && !isIdInner(cptOption)
  10248. && !isIdInner(exist)
  10249. && exist.name === cptOption.name + ''
  10250. ) {
  10251. result[i].option = cptOption;
  10252. newCptOptions[index] = null;
  10253. return;
  10254. }
  10255. }
  10256. });
  10257. // Otherwise mapping by index.
  10258. each$2(newCptOptions, function (cptOption, index) {
  10259. if (!isObject$2(cptOption)) {
  10260. return;
  10261. }
  10262. var i = 0;
  10263. for (; i < result.length; i++) {
  10264. var exist = result[i].exist;
  10265. if (!result[i].option
  10266. // Existing model that already has id should be able to
  10267. // mapped to (because after mapping performed model may
  10268. // be assigned with a id, whish should not affect next
  10269. // mapping), except those has inner id.
  10270. && !isIdInner(exist)
  10271. // Caution:
  10272. // Do not overwrite id. But name can be overwritten,
  10273. // because axis use name as 'show label text'.
  10274. // 'exist' always has id and name and we dont
  10275. // need to check it.
  10276. && cptOption.id == null
  10277. ) {
  10278. result[i].option = cptOption;
  10279. break;
  10280. }
  10281. }
  10282. if (i >= result.length) {
  10283. result.push({option: cptOption});
  10284. }
  10285. });
  10286. return result;
  10287. }
  10288. /**
  10289. * Make id and name for mapping result (result of mappingToExists)
  10290. * into `keyInfo` field.
  10291. *
  10292. * @public
  10293. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  10294. * which order is the same as exists.
  10295. * @return {Array.<Object>} The input.
  10296. */
  10297. function makeIdAndName(mapResult) {
  10298. // We use this id to hash component models and view instances
  10299. // in echarts. id can be specified by user, or auto generated.
  10300. // The id generation rule ensures new view instance are able
  10301. // to mapped to old instance when setOption are called in
  10302. // no-merge mode. So we generate model id by name and plus
  10303. // type in view id.
  10304. // name can be duplicated among components, which is convenient
  10305. // to specify multi components (like series) by one name.
  10306. // Ensure that each id is distinct.
  10307. var idMap = createHashMap();
  10308. each$2(mapResult, function (item, index) {
  10309. var existCpt = item.exist;
  10310. existCpt && idMap.set(existCpt.id, item);
  10311. });
  10312. each$2(mapResult, function (item, index) {
  10313. var opt = item.option;
  10314. assert$1(
  10315. !opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item,
  10316. 'id duplicates: ' + (opt && opt.id)
  10317. );
  10318. opt && opt.id != null && idMap.set(opt.id, item);
  10319. !item.keyInfo && (item.keyInfo = {});
  10320. });
  10321. // Make name and id.
  10322. each$2(mapResult, function (item, index) {
  10323. var existCpt = item.exist;
  10324. var opt = item.option;
  10325. var keyInfo = item.keyInfo;
  10326. if (!isObject$2(opt)) {
  10327. return;
  10328. }
  10329. // name can be overwitten. Consider case: axis.name = '20km'.
  10330. // But id generated by name will not be changed, which affect
  10331. // only in that case: setOption with 'not merge mode' and view
  10332. // instance will be recreated, which can be accepted.
  10333. keyInfo.name = opt.name != null
  10334. ? opt.name + ''
  10335. : existCpt
  10336. ? existCpt.name
  10337. // Avoid diffferent series has the same name,
  10338. // because name may be used like in color pallet.
  10339. : DUMMY_COMPONENT_NAME_PREFIX + index;
  10340. if (existCpt) {
  10341. keyInfo.id = existCpt.id;
  10342. }
  10343. else if (opt.id != null) {
  10344. keyInfo.id = opt.id + '';
  10345. }
  10346. else {
  10347. // Consider this situatoin:
  10348. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  10349. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  10350. // Series with the same name between optionA and optionB
  10351. // should be mapped.
  10352. var idNum = 0;
  10353. do {
  10354. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  10355. }
  10356. while (idMap.get(keyInfo.id));
  10357. }
  10358. idMap.set(keyInfo.id, item);
  10359. });
  10360. }
  10361. function isNameSpecified(componentModel) {
  10362. var name = componentModel.name;
  10363. // Is specified when `indexOf` get -1 or > 0.
  10364. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  10365. }
  10366. /**
  10367. * @public
  10368. * @param {Object} cptOption
  10369. * @return {boolean}
  10370. */
  10371. function isIdInner(cptOption) {
  10372. return isObject$2(cptOption)
  10373. && cptOption.id
  10374. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  10375. }
  10376. /**
  10377. * A helper for removing duplicate items between batchA and batchB,
  10378. * and in themselves, and categorize by series.
  10379. *
  10380. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10381. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10382. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  10383. */
  10384. /**
  10385. * @param {module:echarts/data/List} data
  10386. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  10387. * each of which can be Array or primary type.
  10388. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  10389. */
  10390. function queryDataIndex(data, payload) {
  10391. if (payload.dataIndexInside != null) {
  10392. return payload.dataIndexInside;
  10393. }
  10394. else if (payload.dataIndex != null) {
  10395. return isArray(payload.dataIndex)
  10396. ? map(payload.dataIndex, function (value) {
  10397. return data.indexOfRawIndex(value);
  10398. })
  10399. : data.indexOfRawIndex(payload.dataIndex);
  10400. }
  10401. else if (payload.name != null) {
  10402. return isArray(payload.name)
  10403. ? map(payload.name, function (value) {
  10404. return data.indexOfName(value);
  10405. })
  10406. : data.indexOfName(payload.name);
  10407. }
  10408. }
  10409. /**
  10410. * Enable property storage to any host object.
  10411. * Notice: Serialization is not supported.
  10412. *
  10413. * For example:
  10414. * var inner = zrUitl.makeInner();
  10415. *
  10416. * function some1(hostObj) {
  10417. * inner(hostObj).someProperty = 1212;
  10418. * ...
  10419. * }
  10420. * function some2() {
  10421. * var fields = inner(this);
  10422. * fields.someProperty1 = 1212;
  10423. * fields.someProperty2 = 'xx';
  10424. * ...
  10425. * }
  10426. *
  10427. * @return {Function}
  10428. */
  10429. function makeInner() {
  10430. // Consider different scope by es module import.
  10431. var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
  10432. return function (hostObj) {
  10433. return hostObj[key] || (hostObj[key] = {});
  10434. };
  10435. }
  10436. var innerUniqueIndex = 0;
  10437. /**
  10438. * @param {module:echarts/model/Global} ecModel
  10439. * @param {string|Object} finder
  10440. * If string, e.g., 'geo', means {geoIndex: 0}.
  10441. * If Object, could contain some of these properties below:
  10442. * {
  10443. * seriesIndex, seriesId, seriesName,
  10444. * geoIndex, geoId, geoName,
  10445. * bmapIndex, bmapId, bmapName,
  10446. * xAxisIndex, xAxisId, xAxisName,
  10447. * yAxisIndex, yAxisId, yAxisName,
  10448. * gridIndex, gridId, gridName,
  10449. * ... (can be extended)
  10450. * }
  10451. * Each properties can be number|string|Array.<number>|Array.<string>
  10452. * For example, a finder could be
  10453. * {
  10454. * seriesIndex: 3,
  10455. * geoId: ['aa', 'cc'],
  10456. * gridName: ['xx', 'rr']
  10457. * }
  10458. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  10459. * If nothing or null/undefined specified, return nothing.
  10460. * @param {Object} [opt]
  10461. * @param {string} [opt.defaultMainType]
  10462. * @param {Array.<string>} [opt.includeMainTypes]
  10463. * @return {Object} result like:
  10464. * {
  10465. * seriesModels: [seriesModel1, seriesModel2],
  10466. * seriesModel: seriesModel1, // The first model
  10467. * geoModels: [geoModel1, geoModel2],
  10468. * geoModel: geoModel1, // The first model
  10469. * ...
  10470. * }
  10471. */
  10472. function parseFinder(ecModel, finder, opt) {
  10473. if (isString(finder)) {
  10474. var obj = {};
  10475. obj[finder + 'Index'] = 0;
  10476. finder = obj;
  10477. }
  10478. var defaultMainType = opt && opt.defaultMainType;
  10479. if (defaultMainType
  10480. && !has(finder, defaultMainType + 'Index')
  10481. && !has(finder, defaultMainType + 'Id')
  10482. && !has(finder, defaultMainType + 'Name')
  10483. ) {
  10484. finder[defaultMainType + 'Index'] = 0;
  10485. }
  10486. var result = {};
  10487. each$2(finder, function (value, key) {
  10488. var value = finder[key];
  10489. // Exclude 'dataIndex' and other illgal keys.
  10490. if (key === 'dataIndex' || key === 'dataIndexInside') {
  10491. result[key] = value;
  10492. return;
  10493. }
  10494. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  10495. var mainType = parsedKey[1];
  10496. var queryType = (parsedKey[2] || '').toLowerCase();
  10497. if (!mainType
  10498. || !queryType
  10499. || value == null
  10500. || (queryType === 'index' && value === 'none')
  10501. || (opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0)
  10502. ) {
  10503. return;
  10504. }
  10505. var queryParam = {mainType: mainType};
  10506. if (queryType !== 'index' || value !== 'all') {
  10507. queryParam[queryType] = value;
  10508. }
  10509. var models = ecModel.queryComponents(queryParam);
  10510. result[mainType + 'Models'] = models;
  10511. result[mainType + 'Model'] = models[0];
  10512. });
  10513. return result;
  10514. }
  10515. function has(obj, prop) {
  10516. return obj && obj.hasOwnProperty(prop);
  10517. }
  10518. function setAttribute(dom, key, value) {
  10519. dom.setAttribute
  10520. ? dom.setAttribute(key, value)
  10521. : (dom[key] = value);
  10522. }
  10523. function getAttribute(dom, key) {
  10524. return dom.getAttribute
  10525. ? dom.getAttribute(key)
  10526. : dom[key];
  10527. }
  10528. function getTooltipRenderMode(renderModeOption) {
  10529. if (renderModeOption === 'auto') {
  10530. // Using html when `document` exists, use richText otherwise
  10531. return env$1.domSupported ? 'html' : 'richText';
  10532. }
  10533. else {
  10534. return renderModeOption || 'html';
  10535. }
  10536. }
  10537. /**
  10538. * Group a list by key.
  10539. *
  10540. * @param {Array} array
  10541. * @param {Function} getKey
  10542. * param {*} Array item
  10543. * return {string} key
  10544. * @return {Object} Result
  10545. * {Array}: keys,
  10546. * {module:zrender/core/util/HashMap} buckets: {key -> Array}
  10547. */
  10548. /*
  10549. * Licensed to the Apache Software Foundation (ASF) under one
  10550. * or more contributor license agreements. See the NOTICE file
  10551. * distributed with this work for additional information
  10552. * regarding copyright ownership. The ASF licenses this file
  10553. * to you under the Apache License, Version 2.0 (the
  10554. * "License"); you may not use this file except in compliance
  10555. * with the License. You may obtain a copy of the License at
  10556. *
  10557. * http://www.apache.org/licenses/LICENSE-2.0
  10558. *
  10559. * Unless required by applicable law or agreed to in writing,
  10560. * software distributed under the License is distributed on an
  10561. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10562. * KIND, either express or implied. See the License for the
  10563. * specific language governing permissions and limitations
  10564. * under the License.
  10565. */
  10566. var TYPE_DELIMITER = '.';
  10567. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  10568. /**
  10569. * Notice, parseClassType('') should returns {main: '', sub: ''}
  10570. * @public
  10571. */
  10572. function parseClassType$1(componentType) {
  10573. var ret = {main: '', sub: ''};
  10574. if (componentType) {
  10575. componentType = componentType.split(TYPE_DELIMITER);
  10576. ret.main = componentType[0] || '';
  10577. ret.sub = componentType[1] || '';
  10578. }
  10579. return ret;
  10580. }
  10581. /**
  10582. * @public
  10583. */
  10584. function checkClassType(componentType) {
  10585. assert$1(
  10586. /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),
  10587. 'componentType "' + componentType + '" illegal'
  10588. );
  10589. }
  10590. /**
  10591. * @public
  10592. */
  10593. function enableClassExtend(RootClass, mandatoryMethods) {
  10594. RootClass.$constructor = RootClass;
  10595. RootClass.extend = function (proto) {
  10596. if (__DEV__) {
  10597. each$1(mandatoryMethods, function (method) {
  10598. if (!proto[method]) {
  10599. console.warn(
  10600. 'Method `' + method + '` should be implemented'
  10601. + (proto.type ? ' in ' + proto.type : '') + '.'
  10602. );
  10603. }
  10604. });
  10605. }
  10606. var superClass = this;
  10607. var ExtendedClass = function () {
  10608. if (!proto.$constructor) {
  10609. superClass.apply(this, arguments);
  10610. }
  10611. else {
  10612. proto.$constructor.apply(this, arguments);
  10613. }
  10614. };
  10615. extend(ExtendedClass.prototype, proto);
  10616. ExtendedClass.extend = this.extend;
  10617. ExtendedClass.superCall = superCall;
  10618. ExtendedClass.superApply = superApply;
  10619. inherits(ExtendedClass, this);
  10620. ExtendedClass.superClass = superClass;
  10621. return ExtendedClass;
  10622. };
  10623. }
  10624. var classBase = 0;
  10625. /**
  10626. * Can not use instanceof, consider different scope by
  10627. * cross domain or es module import in ec extensions.
  10628. * Mount a method "isInstance()" to Clz.
  10629. */
  10630. function enableClassCheck(Clz) {
  10631. var classAttr = ['__\0is_clz', classBase++, Math.random().toFixed(3)].join('_');
  10632. Clz.prototype[classAttr] = true;
  10633. if (__DEV__) {
  10634. assert$1(!Clz.isInstance, 'The method "is" can not be defined.');
  10635. }
  10636. Clz.isInstance = function (obj) {
  10637. return !!(obj && obj[classAttr]);
  10638. };
  10639. }
  10640. // superCall should have class info, which can not be fetch from 'this'.
  10641. // Consider this case:
  10642. // class A has method f,
  10643. // class B inherits class A, overrides method f, f call superApply('f'),
  10644. // class C inherits class B, do not overrides method f,
  10645. // then when method of class C is called, dead loop occured.
  10646. function superCall(context, methodName) {
  10647. var args = slice(arguments, 2);
  10648. return this.superClass.prototype[methodName].apply(context, args);
  10649. }
  10650. function superApply(context, methodName, args) {
  10651. return this.superClass.prototype[methodName].apply(context, args);
  10652. }
  10653. /**
  10654. * @param {Object} entity
  10655. * @param {Object} options
  10656. * @param {boolean} [options.registerWhenExtend]
  10657. * @public
  10658. */
  10659. function enableClassManagement(entity, options) {
  10660. options = options || {};
  10661. /**
  10662. * Component model classes
  10663. * key: componentType,
  10664. * value:
  10665. * componentClass, when componentType is 'xxx'
  10666. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  10667. * @type {Object}
  10668. */
  10669. var storage = {};
  10670. entity.registerClass = function (Clazz, componentType) {
  10671. if (componentType) {
  10672. checkClassType(componentType);
  10673. componentType = parseClassType$1(componentType);
  10674. if (!componentType.sub) {
  10675. if (__DEV__) {
  10676. if (storage[componentType.main]) {
  10677. console.warn(componentType.main + ' exists.');
  10678. }
  10679. }
  10680. storage[componentType.main] = Clazz;
  10681. }
  10682. else if (componentType.sub !== IS_CONTAINER) {
  10683. var container = makeContainer(componentType);
  10684. container[componentType.sub] = Clazz;
  10685. }
  10686. }
  10687. return Clazz;
  10688. };
  10689. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  10690. var Clazz = storage[componentMainType];
  10691. if (Clazz && Clazz[IS_CONTAINER]) {
  10692. Clazz = subType ? Clazz[subType] : null;
  10693. }
  10694. if (throwWhenNotFound && !Clazz) {
  10695. throw new Error(
  10696. !subType
  10697. ? componentMainType + '.' + 'type should be specified.'
  10698. : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
  10699. );
  10700. }
  10701. return Clazz;
  10702. };
  10703. entity.getClassesByMainType = function (componentType) {
  10704. componentType = parseClassType$1(componentType);
  10705. var result = [];
  10706. var obj = storage[componentType.main];
  10707. if (obj && obj[IS_CONTAINER]) {
  10708. each$1(obj, function (o, type) {
  10709. type !== IS_CONTAINER && result.push(o);
  10710. });
  10711. }
  10712. else {
  10713. result.push(obj);
  10714. }
  10715. return result;
  10716. };
  10717. entity.hasClass = function (componentType) {
  10718. // Just consider componentType.main.
  10719. componentType = parseClassType$1(componentType);
  10720. return !!storage[componentType.main];
  10721. };
  10722. /**
  10723. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  10724. */
  10725. entity.getAllClassMainTypes = function () {
  10726. var types = [];
  10727. each$1(storage, function (obj, type) {
  10728. types.push(type);
  10729. });
  10730. return types;
  10731. };
  10732. /**
  10733. * If a main type is container and has sub types
  10734. * @param {string} mainType
  10735. * @return {boolean}
  10736. */
  10737. entity.hasSubTypes = function (componentType) {
  10738. componentType = parseClassType$1(componentType);
  10739. var obj = storage[componentType.main];
  10740. return obj && obj[IS_CONTAINER];
  10741. };
  10742. entity.parseClassType = parseClassType$1;
  10743. function makeContainer(componentType) {
  10744. var container = storage[componentType.main];
  10745. if (!container || !container[IS_CONTAINER]) {
  10746. container = storage[componentType.main] = {};
  10747. container[IS_CONTAINER] = true;
  10748. }
  10749. return container;
  10750. }
  10751. if (options.registerWhenExtend) {
  10752. var originalExtend = entity.extend;
  10753. if (originalExtend) {
  10754. entity.extend = function (proto) {
  10755. var ExtendedClass = originalExtend.call(this, proto);
  10756. return entity.registerClass(ExtendedClass, proto.type);
  10757. };
  10758. }
  10759. }
  10760. return entity;
  10761. }
  10762. /**
  10763. * @param {string|Array.<string>} properties
  10764. */
  10765. /*
  10766. * Licensed to the Apache Software Foundation (ASF) under one
  10767. * or more contributor license agreements. See the NOTICE file
  10768. * distributed with this work for additional information
  10769. * regarding copyright ownership. The ASF licenses this file
  10770. * to you under the Apache License, Version 2.0 (the
  10771. * "License"); you may not use this file except in compliance
  10772. * with the License. You may obtain a copy of the License at
  10773. *
  10774. * http://www.apache.org/licenses/LICENSE-2.0
  10775. *
  10776. * Unless required by applicable law or agreed to in writing,
  10777. * software distributed under the License is distributed on an
  10778. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10779. * KIND, either express or implied. See the License for the
  10780. * specific language governing permissions and limitations
  10781. * under the License.
  10782. */
  10783. // TODO Parse shadow style
  10784. // TODO Only shallow path support
  10785. var makeStyleMapper = function (properties) {
  10786. // Normalize
  10787. for (var i = 0; i < properties.length; i++) {
  10788. if (!properties[i][1]) {
  10789. properties[i][1] = properties[i][0];
  10790. }
  10791. }
  10792. return function (model, excludes, includes) {
  10793. var style = {};
  10794. for (var i = 0; i < properties.length; i++) {
  10795. var propName = properties[i][1];
  10796. if ((excludes && indexOf(excludes, propName) >= 0)
  10797. || (includes && indexOf(includes, propName) < 0)
  10798. ) {
  10799. continue;
  10800. }
  10801. var val = model.getShallow(propName);
  10802. if (val != null) {
  10803. style[properties[i][0]] = val;
  10804. }
  10805. }
  10806. return style;
  10807. };
  10808. };
  10809. /*
  10810. * Licensed to the Apache Software Foundation (ASF) under one
  10811. * or more contributor license agreements. See the NOTICE file
  10812. * distributed with this work for additional information
  10813. * regarding copyright ownership. The ASF licenses this file
  10814. * to you under the Apache License, Version 2.0 (the
  10815. * "License"); you may not use this file except in compliance
  10816. * with the License. You may obtain a copy of the License at
  10817. *
  10818. * http://www.apache.org/licenses/LICENSE-2.0
  10819. *
  10820. * Unless required by applicable law or agreed to in writing,
  10821. * software distributed under the License is distributed on an
  10822. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10823. * KIND, either express or implied. See the License for the
  10824. * specific language governing permissions and limitations
  10825. * under the License.
  10826. */
  10827. var getLineStyle = makeStyleMapper(
  10828. [
  10829. ['lineWidth', 'width'],
  10830. ['stroke', 'color'],
  10831. ['opacity'],
  10832. ['shadowBlur'],
  10833. ['shadowOffsetX'],
  10834. ['shadowOffsetY'],
  10835. ['shadowColor']
  10836. ]
  10837. );
  10838. var lineStyleMixin = {
  10839. getLineStyle: function (excludes) {
  10840. var style = getLineStyle(this, excludes);
  10841. // Always set lineDash whether dashed, otherwise we can not
  10842. // erase the previous style when assigning to el.style.
  10843. style.lineDash = this.getLineDash(style.lineWidth);
  10844. return style;
  10845. },
  10846. getLineDash: function (lineWidth) {
  10847. if (lineWidth == null) {
  10848. lineWidth = 1;
  10849. }
  10850. var lineType = this.get('type');
  10851. var dotSize = Math.max(lineWidth, 2);
  10852. var dashSize = lineWidth * 4;
  10853. return (lineType === 'solid' || lineType == null)
  10854. // Use `false` but not `null` for the solid line here, because `null` might be
  10855. // ignored when assigning to `el.style`. e.g., when setting `lineStyle.type` as
  10856. // `'dashed'` and `emphasis.lineStyle.type` as `'solid'` in graph series, the
  10857. // `lineDash` gotten form the latter one is not able to erase that from the former
  10858. // one if using `null` here according to the emhpsis strategy in `util/graphic.js`.
  10859. ? false
  10860. : lineType === 'dashed'
  10861. ? [dashSize, dashSize]
  10862. : [dotSize, dotSize];
  10863. }
  10864. };
  10865. /*
  10866. * Licensed to the Apache Software Foundation (ASF) under one
  10867. * or more contributor license agreements. See the NOTICE file
  10868. * distributed with this work for additional information
  10869. * regarding copyright ownership. The ASF licenses this file
  10870. * to you under the Apache License, Version 2.0 (the
  10871. * "License"); you may not use this file except in compliance
  10872. * with the License. You may obtain a copy of the License at
  10873. *
  10874. * http://www.apache.org/licenses/LICENSE-2.0
  10875. *
  10876. * Unless required by applicable law or agreed to in writing,
  10877. * software distributed under the License is distributed on an
  10878. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10879. * KIND, either express or implied. See the License for the
  10880. * specific language governing permissions and limitations
  10881. * under the License.
  10882. */
  10883. var getAreaStyle = makeStyleMapper(
  10884. [
  10885. ['fill', 'color'],
  10886. ['shadowBlur'],
  10887. ['shadowOffsetX'],
  10888. ['shadowOffsetY'],
  10889. ['opacity'],
  10890. ['shadowColor']
  10891. ]
  10892. );
  10893. var areaStyleMixin = {
  10894. getAreaStyle: function (excludes, includes) {
  10895. return getAreaStyle(this, excludes, includes);
  10896. }
  10897. };
  10898. /**
  10899. * 曲线辅助模块
  10900. * @module zrender/core/curve
  10901. * @author pissang(https://www.github.com/pissang)
  10902. */
  10903. var mathPow = Math.pow;
  10904. var mathSqrt$2 = Math.sqrt;
  10905. var EPSILON$1 = 1e-8;
  10906. var EPSILON_NUMERIC = 1e-4;
  10907. var THREE_SQRT = mathSqrt$2(3);
  10908. var ONE_THIRD = 1 / 3;
  10909. // 临时变量
  10910. var _v0 = create();
  10911. var _v1 = create();
  10912. var _v2 = create();
  10913. function isAroundZero(val) {
  10914. return val > -EPSILON$1 && val < EPSILON$1;
  10915. }
  10916. function isNotAroundZero$1(val) {
  10917. return val > EPSILON$1 || val < -EPSILON$1;
  10918. }
  10919. /**
  10920. * 计算三次贝塞尔值
  10921. * @memberOf module:zrender/core/curve
  10922. * @param {number} p0
  10923. * @param {number} p1
  10924. * @param {number} p2
  10925. * @param {number} p3
  10926. * @param {number} t
  10927. * @return {number}
  10928. */
  10929. function cubicAt(p0, p1, p2, p3, t) {
  10930. var onet = 1 - t;
  10931. return onet * onet * (onet * p0 + 3 * t * p1)
  10932. + t * t * (t * p3 + 3 * onet * p2);
  10933. }
  10934. /**
  10935. * 计算三次贝塞尔导数值
  10936. * @memberOf module:zrender/core/curve
  10937. * @param {number} p0
  10938. * @param {number} p1
  10939. * @param {number} p2
  10940. * @param {number} p3
  10941. * @param {number} t
  10942. * @return {number}
  10943. */
  10944. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10945. var onet = 1 - t;
  10946. return 3 * (
  10947. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  10948. + (p3 - p2) * t * t
  10949. );
  10950. }
  10951. /**
  10952. * 计算三次贝塞尔方程根,使用盛金公式
  10953. * @memberOf module:zrender/core/curve
  10954. * @param {number} p0
  10955. * @param {number} p1
  10956. * @param {number} p2
  10957. * @param {number} p3
  10958. * @param {number} val
  10959. * @param {Array.<number>} roots
  10960. * @return {number} 有效根数目
  10961. */
  10962. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10963. // Evaluate roots of cubic functions
  10964. var a = p3 + 3 * (p1 - p2) - p0;
  10965. var b = 3 * (p2 - p1 * 2 + p0);
  10966. var c = 3 * (p1 - p0);
  10967. var d = p0 - val;
  10968. var A = b * b - 3 * a * c;
  10969. var B = b * c - 9 * a * d;
  10970. var C = c * c - 3 * b * d;
  10971. var n = 0;
  10972. if (isAroundZero(A) && isAroundZero(B)) {
  10973. if (isAroundZero(b)) {
  10974. roots[0] = 0;
  10975. }
  10976. else {
  10977. var t1 = -c / b; //t1, t2, t3, b is not zero
  10978. if (t1 >= 0 && t1 <= 1) {
  10979. roots[n++] = t1;
  10980. }
  10981. }
  10982. }
  10983. else {
  10984. var disc = B * B - 4 * A * C;
  10985. if (isAroundZero(disc)) {
  10986. var K = B / A;
  10987. var t1 = -b / a + K; // t1, a is not zero
  10988. var t2 = -K / 2; // t2, t3
  10989. if (t1 >= 0 && t1 <= 1) {
  10990. roots[n++] = t1;
  10991. }
  10992. if (t2 >= 0 && t2 <= 1) {
  10993. roots[n++] = t2;
  10994. }
  10995. }
  10996. else if (disc > 0) {
  10997. var discSqrt = mathSqrt$2(disc);
  10998. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10999. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  11000. if (Y1 < 0) {
  11001. Y1 = -mathPow(-Y1, ONE_THIRD);
  11002. }
  11003. else {
  11004. Y1 = mathPow(Y1, ONE_THIRD);
  11005. }
  11006. if (Y2 < 0) {
  11007. Y2 = -mathPow(-Y2, ONE_THIRD);
  11008. }
  11009. else {
  11010. Y2 = mathPow(Y2, ONE_THIRD);
  11011. }
  11012. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  11013. if (t1 >= 0 && t1 <= 1) {
  11014. roots[n++] = t1;
  11015. }
  11016. }
  11017. else {
  11018. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt$2(A * A * A));
  11019. var theta = Math.acos(T) / 3;
  11020. var ASqrt = mathSqrt$2(A);
  11021. var tmp = Math.cos(theta);
  11022. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  11023. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  11024. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  11025. if (t1 >= 0 && t1 <= 1) {
  11026. roots[n++] = t1;
  11027. }
  11028. if (t2 >= 0 && t2 <= 1) {
  11029. roots[n++] = t2;
  11030. }
  11031. if (t3 >= 0 && t3 <= 1) {
  11032. roots[n++] = t3;
  11033. }
  11034. }
  11035. }
  11036. return n;
  11037. }
  11038. /**
  11039. * 计算三次贝塞尔方程极限值的位置
  11040. * @memberOf module:zrender/core/curve
  11041. * @param {number} p0
  11042. * @param {number} p1
  11043. * @param {number} p2
  11044. * @param {number} p3
  11045. * @param {Array.<number>} extrema
  11046. * @return {number} 有效数目
  11047. */
  11048. function cubicExtrema(p0, p1, p2, p3, extrema) {
  11049. var b = 6 * p2 - 12 * p1 + 6 * p0;
  11050. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  11051. var c = 3 * p1 - 3 * p0;
  11052. var n = 0;
  11053. if (isAroundZero(a)) {
  11054. if (isNotAroundZero$1(b)) {
  11055. var t1 = -c / b;
  11056. if (t1 >= 0 && t1 <= 1) {
  11057. extrema[n++] = t1;
  11058. }
  11059. }
  11060. }
  11061. else {
  11062. var disc = b * b - 4 * a * c;
  11063. if (isAroundZero(disc)) {
  11064. extrema[0] = -b / (2 * a);
  11065. }
  11066. else if (disc > 0) {
  11067. var discSqrt = mathSqrt$2(disc);
  11068. var t1 = (-b + discSqrt) / (2 * a);
  11069. var t2 = (-b - discSqrt) / (2 * a);
  11070. if (t1 >= 0 && t1 <= 1) {
  11071. extrema[n++] = t1;
  11072. }
  11073. if (t2 >= 0 && t2 <= 1) {
  11074. extrema[n++] = t2;
  11075. }
  11076. }
  11077. }
  11078. return n;
  11079. }
  11080. /**
  11081. * 细分三次贝塞尔曲线
  11082. * @memberOf module:zrender/core/curve
  11083. * @param {number} p0
  11084. * @param {number} p1
  11085. * @param {number} p2
  11086. * @param {number} p3
  11087. * @param {number} t
  11088. * @param {Array.<number>} out
  11089. */
  11090. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  11091. var p01 = (p1 - p0) * t + p0;
  11092. var p12 = (p2 - p1) * t + p1;
  11093. var p23 = (p3 - p2) * t + p2;
  11094. var p012 = (p12 - p01) * t + p01;
  11095. var p123 = (p23 - p12) * t + p12;
  11096. var p0123 = (p123 - p012) * t + p012;
  11097. // Seg0
  11098. out[0] = p0;
  11099. out[1] = p01;
  11100. out[2] = p012;
  11101. out[3] = p0123;
  11102. // Seg1
  11103. out[4] = p0123;
  11104. out[5] = p123;
  11105. out[6] = p23;
  11106. out[7] = p3;
  11107. }
  11108. /**
  11109. * 投射点到三次贝塞尔曲线上,返回投射距离。
  11110. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11111. * @param {number} x0
  11112. * @param {number} y0
  11113. * @param {number} x1
  11114. * @param {number} y1
  11115. * @param {number} x2
  11116. * @param {number} y2
  11117. * @param {number} x3
  11118. * @param {number} y3
  11119. * @param {number} x
  11120. * @param {number} y
  11121. * @param {Array.<number>} [out] 投射点
  11122. * @return {number}
  11123. */
  11124. function cubicProjectPoint(
  11125. x0, y0, x1, y1, x2, y2, x3, y3,
  11126. x, y, out
  11127. ) {
  11128. // http://pomax.github.io/bezierinfo/#projections
  11129. var t;
  11130. var interval = 0.005;
  11131. var d = Infinity;
  11132. var prev;
  11133. var next;
  11134. var d1;
  11135. var d2;
  11136. _v0[0] = x;
  11137. _v0[1] = y;
  11138. // 先粗略估计一下可能的最小距离的 t 值
  11139. // PENDING
  11140. for (var _t = 0; _t < 1; _t += 0.05) {
  11141. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  11142. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  11143. d1 = distSquare(_v0, _v1);
  11144. if (d1 < d) {
  11145. t = _t;
  11146. d = d1;
  11147. }
  11148. }
  11149. d = Infinity;
  11150. // At most 32 iteration
  11151. for (var i = 0; i < 32; i++) {
  11152. if (interval < EPSILON_NUMERIC) {
  11153. break;
  11154. }
  11155. prev = t - interval;
  11156. next = t + interval;
  11157. // t - interval
  11158. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  11159. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  11160. d1 = distSquare(_v1, _v0);
  11161. if (prev >= 0 && d1 < d) {
  11162. t = prev;
  11163. d = d1;
  11164. }
  11165. else {
  11166. // t + interval
  11167. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  11168. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  11169. d2 = distSquare(_v2, _v0);
  11170. if (next <= 1 && d2 < d) {
  11171. t = next;
  11172. d = d2;
  11173. }
  11174. else {
  11175. interval *= 0.5;
  11176. }
  11177. }
  11178. }
  11179. // t
  11180. if (out) {
  11181. out[0] = cubicAt(x0, x1, x2, x3, t);
  11182. out[1] = cubicAt(y0, y1, y2, y3, t);
  11183. }
  11184. // console.log(interval, i);
  11185. return mathSqrt$2(d);
  11186. }
  11187. /**
  11188. * 计算二次方贝塞尔值
  11189. * @param {number} p0
  11190. * @param {number} p1
  11191. * @param {number} p2
  11192. * @param {number} t
  11193. * @return {number}
  11194. */
  11195. function quadraticAt(p0, p1, p2, t) {
  11196. var onet = 1 - t;
  11197. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  11198. }
  11199. /**
  11200. * 计算二次方贝塞尔导数值
  11201. * @param {number} p0
  11202. * @param {number} p1
  11203. * @param {number} p2
  11204. * @param {number} t
  11205. * @return {number}
  11206. */
  11207. function quadraticDerivativeAt(p0, p1, p2, t) {
  11208. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  11209. }
  11210. /**
  11211. * 计算二次方贝塞尔方程根
  11212. * @param {number} p0
  11213. * @param {number} p1
  11214. * @param {number} p2
  11215. * @param {number} t
  11216. * @param {Array.<number>} roots
  11217. * @return {number} 有效根数目
  11218. */
  11219. function quadraticRootAt(p0, p1, p2, val, roots) {
  11220. var a = p0 - 2 * p1 + p2;
  11221. var b = 2 * (p1 - p0);
  11222. var c = p0 - val;
  11223. var n = 0;
  11224. if (isAroundZero(a)) {
  11225. if (isNotAroundZero$1(b)) {
  11226. var t1 = -c / b;
  11227. if (t1 >= 0 && t1 <= 1) {
  11228. roots[n++] = t1;
  11229. }
  11230. }
  11231. }
  11232. else {
  11233. var disc = b * b - 4 * a * c;
  11234. if (isAroundZero(disc)) {
  11235. var t1 = -b / (2 * a);
  11236. if (t1 >= 0 && t1 <= 1) {
  11237. roots[n++] = t1;
  11238. }
  11239. }
  11240. else if (disc > 0) {
  11241. var discSqrt = mathSqrt$2(disc);
  11242. var t1 = (-b + discSqrt) / (2 * a);
  11243. var t2 = (-b - discSqrt) / (2 * a);
  11244. if (t1 >= 0 && t1 <= 1) {
  11245. roots[n++] = t1;
  11246. }
  11247. if (t2 >= 0 && t2 <= 1) {
  11248. roots[n++] = t2;
  11249. }
  11250. }
  11251. }
  11252. return n;
  11253. }
  11254. /**
  11255. * 计算二次贝塞尔方程极限值
  11256. * @memberOf module:zrender/core/curve
  11257. * @param {number} p0
  11258. * @param {number} p1
  11259. * @param {number} p2
  11260. * @return {number}
  11261. */
  11262. function quadraticExtremum(p0, p1, p2) {
  11263. var divider = p0 + p2 - 2 * p1;
  11264. if (divider === 0) {
  11265. // p1 is center of p0 and p2
  11266. return 0.5;
  11267. }
  11268. else {
  11269. return (p0 - p1) / divider;
  11270. }
  11271. }
  11272. /**
  11273. * 细分二次贝塞尔曲线
  11274. * @memberOf module:zrender/core/curve
  11275. * @param {number} p0
  11276. * @param {number} p1
  11277. * @param {number} p2
  11278. * @param {number} t
  11279. * @param {Array.<number>} out
  11280. */
  11281. function quadraticSubdivide(p0, p1, p2, t, out) {
  11282. var p01 = (p1 - p0) * t + p0;
  11283. var p12 = (p2 - p1) * t + p1;
  11284. var p012 = (p12 - p01) * t + p01;
  11285. // Seg0
  11286. out[0] = p0;
  11287. out[1] = p01;
  11288. out[2] = p012;
  11289. // Seg1
  11290. out[3] = p012;
  11291. out[4] = p12;
  11292. out[5] = p2;
  11293. }
  11294. /**
  11295. * 投射点到二次贝塞尔曲线上,返回投射距离。
  11296. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11297. * @param {number} x0
  11298. * @param {number} y0
  11299. * @param {number} x1
  11300. * @param {number} y1
  11301. * @param {number} x2
  11302. * @param {number} y2
  11303. * @param {number} x
  11304. * @param {number} y
  11305. * @param {Array.<number>} out 投射点
  11306. * @return {number}
  11307. */
  11308. function quadraticProjectPoint(
  11309. x0, y0, x1, y1, x2, y2,
  11310. x, y, out
  11311. ) {
  11312. // http://pomax.github.io/bezierinfo/#projections
  11313. var t;
  11314. var interval = 0.005;
  11315. var d = Infinity;
  11316. _v0[0] = x;
  11317. _v0[1] = y;
  11318. // 先粗略估计一下可能的最小距离的 t 值
  11319. // PENDING
  11320. for (var _t = 0; _t < 1; _t += 0.05) {
  11321. _v1[0] = quadraticAt(x0, x1, x2, _t);
  11322. _v1[1] = quadraticAt(y0, y1, y2, _t);
  11323. var d1 = distSquare(_v0, _v1);
  11324. if (d1 < d) {
  11325. t = _t;
  11326. d = d1;
  11327. }
  11328. }
  11329. d = Infinity;
  11330. // At most 32 iteration
  11331. for (var i = 0; i < 32; i++) {
  11332. if (interval < EPSILON_NUMERIC) {
  11333. break;
  11334. }
  11335. var prev = t - interval;
  11336. var next = t + interval;
  11337. // t - interval
  11338. _v1[0] = quadraticAt(x0, x1, x2, prev);
  11339. _v1[1] = quadraticAt(y0, y1, y2, prev);
  11340. var d1 = distSquare(_v1, _v0);
  11341. if (prev >= 0 && d1 < d) {
  11342. t = prev;
  11343. d = d1;
  11344. }
  11345. else {
  11346. // t + interval
  11347. _v2[0] = quadraticAt(x0, x1, x2, next);
  11348. _v2[1] = quadraticAt(y0, y1, y2, next);
  11349. var d2 = distSquare(_v2, _v0);
  11350. if (next <= 1 && d2 < d) {
  11351. t = next;
  11352. d = d2;
  11353. }
  11354. else {
  11355. interval *= 0.5;
  11356. }
  11357. }
  11358. }
  11359. // t
  11360. if (out) {
  11361. out[0] = quadraticAt(x0, x1, x2, t);
  11362. out[1] = quadraticAt(y0, y1, y2, t);
  11363. }
  11364. // console.log(interval, i);
  11365. return mathSqrt$2(d);
  11366. }
  11367. /**
  11368. * @author Yi Shen(https://github.com/pissang)
  11369. */
  11370. var mathMin$3 = Math.min;
  11371. var mathMax$3 = Math.max;
  11372. var mathSin$2 = Math.sin;
  11373. var mathCos$2 = Math.cos;
  11374. var PI2 = Math.PI * 2;
  11375. var start = create();
  11376. var end = create();
  11377. var extremity = create();
  11378. /**
  11379. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  11380. * @module zrender/core/bbox
  11381. * @param {Array<Object>} points 顶点数组
  11382. * @param {number} min
  11383. * @param {number} max
  11384. */
  11385. function fromPoints(points, min$$1, max$$1) {
  11386. if (points.length === 0) {
  11387. return;
  11388. }
  11389. var p = points[0];
  11390. var left = p[0];
  11391. var right = p[0];
  11392. var top = p[1];
  11393. var bottom = p[1];
  11394. var i;
  11395. for (i = 1; i < points.length; i++) {
  11396. p = points[i];
  11397. left = mathMin$3(left, p[0]);
  11398. right = mathMax$3(right, p[0]);
  11399. top = mathMin$3(top, p[1]);
  11400. bottom = mathMax$3(bottom, p[1]);
  11401. }
  11402. min$$1[0] = left;
  11403. min$$1[1] = top;
  11404. max$$1[0] = right;
  11405. max$$1[1] = bottom;
  11406. }
  11407. /**
  11408. * @memberOf module:zrender/core/bbox
  11409. * @param {number} x0
  11410. * @param {number} y0
  11411. * @param {number} x1
  11412. * @param {number} y1
  11413. * @param {Array.<number>} min
  11414. * @param {Array.<number>} max
  11415. */
  11416. function fromLine(x0, y0, x1, y1, min$$1, max$$1) {
  11417. min$$1[0] = mathMin$3(x0, x1);
  11418. min$$1[1] = mathMin$3(y0, y1);
  11419. max$$1[0] = mathMax$3(x0, x1);
  11420. max$$1[1] = mathMax$3(y0, y1);
  11421. }
  11422. var xDim = [];
  11423. var yDim = [];
  11424. /**
  11425. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  11426. * @memberOf module:zrender/core/bbox
  11427. * @param {number} x0
  11428. * @param {number} y0
  11429. * @param {number} x1
  11430. * @param {number} y1
  11431. * @param {number} x2
  11432. * @param {number} y2
  11433. * @param {number} x3
  11434. * @param {number} y3
  11435. * @param {Array.<number>} min
  11436. * @param {Array.<number>} max
  11437. */
  11438. function fromCubic(
  11439. x0, y0, x1, y1, x2, y2, x3, y3, min$$1, max$$1
  11440. ) {
  11441. var cubicExtrema$$1 = cubicExtrema;
  11442. var cubicAt$$1 = cubicAt;
  11443. var i;
  11444. var n = cubicExtrema$$1(x0, x1, x2, x3, xDim);
  11445. min$$1[0] = Infinity;
  11446. min$$1[1] = Infinity;
  11447. max$$1[0] = -Infinity;
  11448. max$$1[1] = -Infinity;
  11449. for (i = 0; i < n; i++) {
  11450. var x = cubicAt$$1(x0, x1, x2, x3, xDim[i]);
  11451. min$$1[0] = mathMin$3(x, min$$1[0]);
  11452. max$$1[0] = mathMax$3(x, max$$1[0]);
  11453. }
  11454. n = cubicExtrema$$1(y0, y1, y2, y3, yDim);
  11455. for (i = 0; i < n; i++) {
  11456. var y = cubicAt$$1(y0, y1, y2, y3, yDim[i]);
  11457. min$$1[1] = mathMin$3(y, min$$1[1]);
  11458. max$$1[1] = mathMax$3(y, max$$1[1]);
  11459. }
  11460. min$$1[0] = mathMin$3(x0, min$$1[0]);
  11461. max$$1[0] = mathMax$3(x0, max$$1[0]);
  11462. min$$1[0] = mathMin$3(x3, min$$1[0]);
  11463. max$$1[0] = mathMax$3(x3, max$$1[0]);
  11464. min$$1[1] = mathMin$3(y0, min$$1[1]);
  11465. max$$1[1] = mathMax$3(y0, max$$1[1]);
  11466. min$$1[1] = mathMin$3(y3, min$$1[1]);
  11467. max$$1[1] = mathMax$3(y3, max$$1[1]);
  11468. }
  11469. /**
  11470. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  11471. * @memberOf module:zrender/core/bbox
  11472. * @param {number} x0
  11473. * @param {number} y0
  11474. * @param {number} x1
  11475. * @param {number} y1
  11476. * @param {number} x2
  11477. * @param {number} y2
  11478. * @param {Array.<number>} min
  11479. * @param {Array.<number>} max
  11480. */
  11481. function fromQuadratic(x0, y0, x1, y1, x2, y2, min$$1, max$$1) {
  11482. var quadraticExtremum$$1 = quadraticExtremum;
  11483. var quadraticAt$$1 = quadraticAt;
  11484. // Find extremities, where derivative in x dim or y dim is zero
  11485. var tx =
  11486. mathMax$3(
  11487. mathMin$3(quadraticExtremum$$1(x0, x1, x2), 1), 0
  11488. );
  11489. var ty =
  11490. mathMax$3(
  11491. mathMin$3(quadraticExtremum$$1(y0, y1, y2), 1), 0
  11492. );
  11493. var x = quadraticAt$$1(x0, x1, x2, tx);
  11494. var y = quadraticAt$$1(y0, y1, y2, ty);
  11495. min$$1[0] = mathMin$3(x0, x2, x);
  11496. min$$1[1] = mathMin$3(y0, y2, y);
  11497. max$$1[0] = mathMax$3(x0, x2, x);
  11498. max$$1[1] = mathMax$3(y0, y2, y);
  11499. }
  11500. /**
  11501. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  11502. * @method
  11503. * @memberOf module:zrender/core/bbox
  11504. * @param {number} x
  11505. * @param {number} y
  11506. * @param {number} rx
  11507. * @param {number} ry
  11508. * @param {number} startAngle
  11509. * @param {number} endAngle
  11510. * @param {number} anticlockwise
  11511. * @param {Array.<number>} min
  11512. * @param {Array.<number>} max
  11513. */
  11514. function fromArc(
  11515. x, y, rx, ry, startAngle, endAngle, anticlockwise, min$$1, max$$1
  11516. ) {
  11517. var vec2Min = min;
  11518. var vec2Max = max;
  11519. var diff = Math.abs(startAngle - endAngle);
  11520. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  11521. // Is a circle
  11522. min$$1[0] = x - rx;
  11523. min$$1[1] = y - ry;
  11524. max$$1[0] = x + rx;
  11525. max$$1[1] = y + ry;
  11526. return;
  11527. }
  11528. start[0] = mathCos$2(startAngle) * rx + x;
  11529. start[1] = mathSin$2(startAngle) * ry + y;
  11530. end[0] = mathCos$2(endAngle) * rx + x;
  11531. end[1] = mathSin$2(endAngle) * ry + y;
  11532. vec2Min(min$$1, start, end);
  11533. vec2Max(max$$1, start, end);
  11534. // Thresh to [0, Math.PI * 2]
  11535. startAngle = startAngle % (PI2);
  11536. if (startAngle < 0) {
  11537. startAngle = startAngle + PI2;
  11538. }
  11539. endAngle = endAngle % (PI2);
  11540. if (endAngle < 0) {
  11541. endAngle = endAngle + PI2;
  11542. }
  11543. if (startAngle > endAngle && !anticlockwise) {
  11544. endAngle += PI2;
  11545. }
  11546. else if (startAngle < endAngle && anticlockwise) {
  11547. startAngle += PI2;
  11548. }
  11549. if (anticlockwise) {
  11550. var tmp = endAngle;
  11551. endAngle = startAngle;
  11552. startAngle = tmp;
  11553. }
  11554. // var number = 0;
  11555. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  11556. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  11557. if (angle > startAngle) {
  11558. extremity[0] = mathCos$2(angle) * rx + x;
  11559. extremity[1] = mathSin$2(angle) * ry + y;
  11560. vec2Min(min$$1, extremity, min$$1);
  11561. vec2Max(max$$1, extremity, max$$1);
  11562. }
  11563. }
  11564. }
  11565. /**
  11566. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  11567. * 可以用于 isInsidePath 判断以及获取boundingRect
  11568. *
  11569. * @module zrender/core/PathProxy
  11570. * @author Yi Shen (http://www.github.com/pissang)
  11571. */
  11572. // TODO getTotalLength, getPointAtLength
  11573. /* global Float32Array */
  11574. var CMD = {
  11575. M: 1,
  11576. L: 2,
  11577. C: 3,
  11578. Q: 4,
  11579. A: 5,
  11580. Z: 6,
  11581. // Rect
  11582. R: 7
  11583. };
  11584. // var CMD_MEM_SIZE = {
  11585. // M: 3,
  11586. // L: 3,
  11587. // C: 7,
  11588. // Q: 5,
  11589. // A: 9,
  11590. // R: 5,
  11591. // Z: 1
  11592. // };
  11593. var min$1 = [];
  11594. var max$1 = [];
  11595. var min2 = [];
  11596. var max2 = [];
  11597. var mathMin$2 = Math.min;
  11598. var mathMax$2 = Math.max;
  11599. var mathCos$1 = Math.cos;
  11600. var mathSin$1 = Math.sin;
  11601. var mathSqrt$1 = Math.sqrt;
  11602. var mathAbs = Math.abs;
  11603. var hasTypedArray = typeof Float32Array !== 'undefined';
  11604. /**
  11605. * @alias module:zrender/core/PathProxy
  11606. * @constructor
  11607. */
  11608. var PathProxy = function (notSaveData) {
  11609. this._saveData = !(notSaveData || false);
  11610. if (this._saveData) {
  11611. /**
  11612. * Path data. Stored as flat array
  11613. * @type {Array.<Object>}
  11614. */
  11615. this.data = [];
  11616. }
  11617. this._ctx = null;
  11618. };
  11619. /**
  11620. * 快速计算Path包围盒(并不是最小包围盒)
  11621. * @return {Object}
  11622. */
  11623. PathProxy.prototype = {
  11624. constructor: PathProxy,
  11625. _xi: 0,
  11626. _yi: 0,
  11627. _x0: 0,
  11628. _y0: 0,
  11629. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  11630. _ux: 0,
  11631. _uy: 0,
  11632. _len: 0,
  11633. _lineDash: null,
  11634. _dashOffset: 0,
  11635. _dashIdx: 0,
  11636. _dashSum: 0,
  11637. /**
  11638. * @readOnly
  11639. */
  11640. setScale: function (sx, sy, segmentIgnoreThreshold) {
  11641. // Compat. Previously there is no segmentIgnoreThreshold.
  11642. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  11643. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  11644. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  11645. },
  11646. getContext: function () {
  11647. return this._ctx;
  11648. },
  11649. /**
  11650. * @param {CanvasRenderingContext2D} ctx
  11651. * @return {module:zrender/core/PathProxy}
  11652. */
  11653. beginPath: function (ctx) {
  11654. this._ctx = ctx;
  11655. ctx && ctx.beginPath();
  11656. ctx && (this.dpr = ctx.dpr);
  11657. // Reset
  11658. if (this._saveData) {
  11659. this._len = 0;
  11660. }
  11661. if (this._lineDash) {
  11662. this._lineDash = null;
  11663. this._dashOffset = 0;
  11664. }
  11665. return this;
  11666. },
  11667. /**
  11668. * @param {number} x
  11669. * @param {number} y
  11670. * @return {module:zrender/core/PathProxy}
  11671. */
  11672. moveTo: function (x, y) {
  11673. this.addData(CMD.M, x, y);
  11674. this._ctx && this._ctx.moveTo(x, y);
  11675. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11676. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11677. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11678. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11679. this._x0 = x;
  11680. this._y0 = y;
  11681. this._xi = x;
  11682. this._yi = y;
  11683. return this;
  11684. },
  11685. /**
  11686. * @param {number} x
  11687. * @param {number} y
  11688. * @return {module:zrender/core/PathProxy}
  11689. */
  11690. lineTo: function (x, y) {
  11691. var exceedUnit = mathAbs(x - this._xi) > this._ux
  11692. || mathAbs(y - this._yi) > this._uy
  11693. // Force draw the first segment
  11694. || this._len < 5;
  11695. this.addData(CMD.L, x, y);
  11696. if (this._ctx && exceedUnit) {
  11697. this._needsDash() ? this._dashedLineTo(x, y)
  11698. : this._ctx.lineTo(x, y);
  11699. }
  11700. if (exceedUnit) {
  11701. this._xi = x;
  11702. this._yi = y;
  11703. }
  11704. return this;
  11705. },
  11706. /**
  11707. * @param {number} x1
  11708. * @param {number} y1
  11709. * @param {number} x2
  11710. * @param {number} y2
  11711. * @param {number} x3
  11712. * @param {number} y3
  11713. * @return {module:zrender/core/PathProxy}
  11714. */
  11715. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11716. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11717. if (this._ctx) {
  11718. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  11719. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11720. }
  11721. this._xi = x3;
  11722. this._yi = y3;
  11723. return this;
  11724. },
  11725. /**
  11726. * @param {number} x1
  11727. * @param {number} y1
  11728. * @param {number} x2
  11729. * @param {number} y2
  11730. * @return {module:zrender/core/PathProxy}
  11731. */
  11732. quadraticCurveTo: function (x1, y1, x2, y2) {
  11733. this.addData(CMD.Q, x1, y1, x2, y2);
  11734. if (this._ctx) {
  11735. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  11736. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11737. }
  11738. this._xi = x2;
  11739. this._yi = y2;
  11740. return this;
  11741. },
  11742. /**
  11743. * @param {number} cx
  11744. * @param {number} cy
  11745. * @param {number} r
  11746. * @param {number} startAngle
  11747. * @param {number} endAngle
  11748. * @param {boolean} anticlockwise
  11749. * @return {module:zrender/core/PathProxy}
  11750. */
  11751. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11752. this.addData(
  11753. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  11754. );
  11755. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11756. this._xi = mathCos$1(endAngle) * r + cx;
  11757. this._yi = mathSin$1(endAngle) * r + cy;
  11758. return this;
  11759. },
  11760. // TODO
  11761. arcTo: function (x1, y1, x2, y2, radius) {
  11762. if (this._ctx) {
  11763. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11764. }
  11765. return this;
  11766. },
  11767. // TODO
  11768. rect: function (x, y, w, h) {
  11769. this._ctx && this._ctx.rect(x, y, w, h);
  11770. this.addData(CMD.R, x, y, w, h);
  11771. return this;
  11772. },
  11773. /**
  11774. * @return {module:zrender/core/PathProxy}
  11775. */
  11776. closePath: function () {
  11777. this.addData(CMD.Z);
  11778. var ctx = this._ctx;
  11779. var x0 = this._x0;
  11780. var y0 = this._y0;
  11781. if (ctx) {
  11782. this._needsDash() && this._dashedLineTo(x0, y0);
  11783. ctx.closePath();
  11784. }
  11785. this._xi = x0;
  11786. this._yi = y0;
  11787. return this;
  11788. },
  11789. /**
  11790. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11791. * stroke 同样
  11792. * @param {CanvasRenderingContext2D} ctx
  11793. * @return {module:zrender/core/PathProxy}
  11794. */
  11795. fill: function (ctx) {
  11796. ctx && ctx.fill();
  11797. this.toStatic();
  11798. },
  11799. /**
  11800. * @param {CanvasRenderingContext2D} ctx
  11801. * @return {module:zrender/core/PathProxy}
  11802. */
  11803. stroke: function (ctx) {
  11804. ctx && ctx.stroke();
  11805. this.toStatic();
  11806. },
  11807. /**
  11808. * 必须在其它绘制命令前调用
  11809. * Must be invoked before all other path drawing methods
  11810. * @return {module:zrender/core/PathProxy}
  11811. */
  11812. setLineDash: function (lineDash) {
  11813. if (lineDash instanceof Array) {
  11814. this._lineDash = lineDash;
  11815. this._dashIdx = 0;
  11816. var lineDashSum = 0;
  11817. for (var i = 0; i < lineDash.length; i++) {
  11818. lineDashSum += lineDash[i];
  11819. }
  11820. this._dashSum = lineDashSum;
  11821. }
  11822. return this;
  11823. },
  11824. /**
  11825. * 必须在其它绘制命令前调用
  11826. * Must be invoked before all other path drawing methods
  11827. * @return {module:zrender/core/PathProxy}
  11828. */
  11829. setLineDashOffset: function (offset) {
  11830. this._dashOffset = offset;
  11831. return this;
  11832. },
  11833. /**
  11834. *
  11835. * @return {boolean}
  11836. */
  11837. len: function () {
  11838. return this._len;
  11839. },
  11840. /**
  11841. * 直接设置 Path 数据
  11842. */
  11843. setData: function (data) {
  11844. var len$$1 = data.length;
  11845. if (!(this.data && this.data.length === len$$1) && hasTypedArray) {
  11846. this.data = new Float32Array(len$$1);
  11847. }
  11848. for (var i = 0; i < len$$1; i++) {
  11849. this.data[i] = data[i];
  11850. }
  11851. this._len = len$$1;
  11852. },
  11853. /**
  11854. * 添加子路径
  11855. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11856. */
  11857. appendPath: function (path) {
  11858. if (!(path instanceof Array)) {
  11859. path = [path];
  11860. }
  11861. var len$$1 = path.length;
  11862. var appendSize = 0;
  11863. var offset = this._len;
  11864. for (var i = 0; i < len$$1; i++) {
  11865. appendSize += path[i].len();
  11866. }
  11867. if (hasTypedArray && (this.data instanceof Float32Array)) {
  11868. this.data = new Float32Array(offset + appendSize);
  11869. }
  11870. for (var i = 0; i < len$$1; i++) {
  11871. var appendPathData = path[i].data;
  11872. for (var k = 0; k < appendPathData.length; k++) {
  11873. this.data[offset++] = appendPathData[k];
  11874. }
  11875. }
  11876. this._len = offset;
  11877. },
  11878. /**
  11879. * 填充 Path 数据。
  11880. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11881. */
  11882. addData: function (cmd) {
  11883. if (!this._saveData) {
  11884. return;
  11885. }
  11886. var data = this.data;
  11887. if (this._len + arguments.length > data.length) {
  11888. // 因为之前的数组已经转换成静态的 Float32Array
  11889. // 所以不够用时需要扩展一个新的动态数组
  11890. this._expandData();
  11891. data = this.data;
  11892. }
  11893. for (var i = 0; i < arguments.length; i++) {
  11894. data[this._len++] = arguments[i];
  11895. }
  11896. this._prevCmd = cmd;
  11897. },
  11898. _expandData: function () {
  11899. // Only if data is Float32Array
  11900. if (!(this.data instanceof Array)) {
  11901. var newData = [];
  11902. for (var i = 0; i < this._len; i++) {
  11903. newData[i] = this.data[i];
  11904. }
  11905. this.data = newData;
  11906. }
  11907. },
  11908. /**
  11909. * If needs js implemented dashed line
  11910. * @return {boolean}
  11911. * @private
  11912. */
  11913. _needsDash: function () {
  11914. return this._lineDash;
  11915. },
  11916. _dashedLineTo: function (x1, y1) {
  11917. var dashSum = this._dashSum;
  11918. var offset = this._dashOffset;
  11919. var lineDash = this._lineDash;
  11920. var ctx = this._ctx;
  11921. var x0 = this._xi;
  11922. var y0 = this._yi;
  11923. var dx = x1 - x0;
  11924. var dy = y1 - y0;
  11925. var dist$$1 = mathSqrt$1(dx * dx + dy * dy);
  11926. var x = x0;
  11927. var y = y0;
  11928. var dash;
  11929. var nDash = lineDash.length;
  11930. var idx;
  11931. dx /= dist$$1;
  11932. dy /= dist$$1;
  11933. if (offset < 0) {
  11934. // Convert to positive offset
  11935. offset = dashSum + offset;
  11936. }
  11937. offset %= dashSum;
  11938. x -= offset * dx;
  11939. y -= offset * dy;
  11940. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  11941. || (dx === 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  11942. idx = this._dashIdx;
  11943. dash = lineDash[idx];
  11944. x += dx * dash;
  11945. y += dy * dash;
  11946. this._dashIdx = (idx + 1) % nDash;
  11947. // Skip positive offset
  11948. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  11949. continue;
  11950. }
  11951. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  11952. dx >= 0 ? mathMin$2(x, x1) : mathMax$2(x, x1),
  11953. dy >= 0 ? mathMin$2(y, y1) : mathMax$2(y, y1)
  11954. );
  11955. }
  11956. // Offset for next lineTo
  11957. dx = x - x1;
  11958. dy = y - y1;
  11959. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11960. },
  11961. // Not accurate dashed line to
  11962. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11963. var dashSum = this._dashSum;
  11964. var offset = this._dashOffset;
  11965. var lineDash = this._lineDash;
  11966. var ctx = this._ctx;
  11967. var x0 = this._xi;
  11968. var y0 = this._yi;
  11969. var t;
  11970. var dx;
  11971. var dy;
  11972. var cubicAt$$1 = cubicAt;
  11973. var bezierLen = 0;
  11974. var idx = this._dashIdx;
  11975. var nDash = lineDash.length;
  11976. var x;
  11977. var y;
  11978. var tmpLen = 0;
  11979. if (offset < 0) {
  11980. // Convert to positive offset
  11981. offset = dashSum + offset;
  11982. }
  11983. offset %= dashSum;
  11984. // Bezier approx length
  11985. for (t = 0; t < 1; t += 0.1) {
  11986. dx = cubicAt$$1(x0, x1, x2, x3, t + 0.1)
  11987. - cubicAt$$1(x0, x1, x2, x3, t);
  11988. dy = cubicAt$$1(y0, y1, y2, y3, t + 0.1)
  11989. - cubicAt$$1(y0, y1, y2, y3, t);
  11990. bezierLen += mathSqrt$1(dx * dx + dy * dy);
  11991. }
  11992. // Find idx after add offset
  11993. for (; idx < nDash; idx++) {
  11994. tmpLen += lineDash[idx];
  11995. if (tmpLen > offset) {
  11996. break;
  11997. }
  11998. }
  11999. t = (tmpLen - offset) / bezierLen;
  12000. while (t <= 1) {
  12001. x = cubicAt$$1(x0, x1, x2, x3, t);
  12002. y = cubicAt$$1(y0, y1, y2, y3, t);
  12003. // Use line to approximate dashed bezier
  12004. // Bad result if dash is long
  12005. idx % 2 ? ctx.moveTo(x, y)
  12006. : ctx.lineTo(x, y);
  12007. t += lineDash[idx] / bezierLen;
  12008. idx = (idx + 1) % nDash;
  12009. }
  12010. // Finish the last segment and calculate the new offset
  12011. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  12012. dx = x3 - x;
  12013. dy = y3 - y;
  12014. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  12015. },
  12016. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  12017. // Convert quadratic to cubic using degree elevation
  12018. var x3 = x2;
  12019. var y3 = y2;
  12020. x2 = (x2 + 2 * x1) / 3;
  12021. y2 = (y2 + 2 * y1) / 3;
  12022. x1 = (this._xi + 2 * x1) / 3;
  12023. y1 = (this._yi + 2 * y1) / 3;
  12024. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  12025. },
  12026. /**
  12027. * 转成静态的 Float32Array 减少堆内存占用
  12028. * Convert dynamic array to static Float32Array
  12029. */
  12030. toStatic: function () {
  12031. var data = this.data;
  12032. if (data instanceof Array) {
  12033. data.length = this._len;
  12034. if (hasTypedArray) {
  12035. this.data = new Float32Array(data);
  12036. }
  12037. }
  12038. },
  12039. /**
  12040. * @return {module:zrender/core/BoundingRect}
  12041. */
  12042. getBoundingRect: function () {
  12043. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  12044. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  12045. var data = this.data;
  12046. var xi = 0;
  12047. var yi = 0;
  12048. var x0 = 0;
  12049. var y0 = 0;
  12050. for (var i = 0; i < data.length;) {
  12051. var cmd = data[i++];
  12052. if (i === 1) {
  12053. // 如果第一个命令是 L, C, Q
  12054. // 则 previous point 同绘制命令的第一个 point
  12055. //
  12056. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12057. xi = data[i];
  12058. yi = data[i + 1];
  12059. x0 = xi;
  12060. y0 = yi;
  12061. }
  12062. switch (cmd) {
  12063. case CMD.M:
  12064. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  12065. // 在 closePath 的时候使用
  12066. x0 = data[i++];
  12067. y0 = data[i++];
  12068. xi = x0;
  12069. yi = y0;
  12070. min2[0] = x0;
  12071. min2[1] = y0;
  12072. max2[0] = x0;
  12073. max2[1] = y0;
  12074. break;
  12075. case CMD.L:
  12076. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  12077. xi = data[i++];
  12078. yi = data[i++];
  12079. break;
  12080. case CMD.C:
  12081. fromCubic(
  12082. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12083. min2, max2
  12084. );
  12085. xi = data[i++];
  12086. yi = data[i++];
  12087. break;
  12088. case CMD.Q:
  12089. fromQuadratic(
  12090. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  12091. min2, max2
  12092. );
  12093. xi = data[i++];
  12094. yi = data[i++];
  12095. break;
  12096. case CMD.A:
  12097. // TODO Arc 判断的开销比较大
  12098. var cx = data[i++];
  12099. var cy = data[i++];
  12100. var rx = data[i++];
  12101. var ry = data[i++];
  12102. var startAngle = data[i++];
  12103. var endAngle = data[i++] + startAngle;
  12104. // TODO Arc 旋转
  12105. i += 1;
  12106. var anticlockwise = 1 - data[i++];
  12107. if (i === 1) {
  12108. // 直接使用 arc 命令
  12109. // 第一个命令起点还未定义
  12110. x0 = mathCos$1(startAngle) * rx + cx;
  12111. y0 = mathSin$1(startAngle) * ry + cy;
  12112. }
  12113. fromArc(
  12114. cx, cy, rx, ry, startAngle, endAngle,
  12115. anticlockwise, min2, max2
  12116. );
  12117. xi = mathCos$1(endAngle) * rx + cx;
  12118. yi = mathSin$1(endAngle) * ry + cy;
  12119. break;
  12120. case CMD.R:
  12121. x0 = xi = data[i++];
  12122. y0 = yi = data[i++];
  12123. var width = data[i++];
  12124. var height = data[i++];
  12125. // Use fromLine
  12126. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  12127. break;
  12128. case CMD.Z:
  12129. xi = x0;
  12130. yi = y0;
  12131. break;
  12132. }
  12133. // Union
  12134. min(min$1, min$1, min2);
  12135. max(max$1, max$1, max2);
  12136. }
  12137. // No data
  12138. if (i === 0) {
  12139. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  12140. }
  12141. return new BoundingRect(
  12142. min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]
  12143. );
  12144. },
  12145. /**
  12146. * Rebuild path from current data
  12147. * Rebuild path will not consider javascript implemented line dash.
  12148. * @param {CanvasRenderingContext2D} ctx
  12149. */
  12150. rebuildPath: function (ctx) {
  12151. var d = this.data;
  12152. var x0;
  12153. var y0;
  12154. var xi;
  12155. var yi;
  12156. var x;
  12157. var y;
  12158. var ux = this._ux;
  12159. var uy = this._uy;
  12160. var len$$1 = this._len;
  12161. for (var i = 0; i < len$$1;) {
  12162. var cmd = d[i++];
  12163. if (i === 1) {
  12164. // 如果第一个命令是 L, C, Q
  12165. // 则 previous point 同绘制命令的第一个 point
  12166. //
  12167. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12168. xi = d[i];
  12169. yi = d[i + 1];
  12170. x0 = xi;
  12171. y0 = yi;
  12172. }
  12173. switch (cmd) {
  12174. case CMD.M:
  12175. x0 = xi = d[i++];
  12176. y0 = yi = d[i++];
  12177. ctx.moveTo(xi, yi);
  12178. break;
  12179. case CMD.L:
  12180. x = d[i++];
  12181. y = d[i++];
  12182. // Not draw too small seg between
  12183. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len$$1 - 1) {
  12184. ctx.lineTo(x, y);
  12185. xi = x;
  12186. yi = y;
  12187. }
  12188. break;
  12189. case CMD.C:
  12190. ctx.bezierCurveTo(
  12191. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  12192. );
  12193. xi = d[i - 2];
  12194. yi = d[i - 1];
  12195. break;
  12196. case CMD.Q:
  12197. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  12198. xi = d[i - 2];
  12199. yi = d[i - 1];
  12200. break;
  12201. case CMD.A:
  12202. var cx = d[i++];
  12203. var cy = d[i++];
  12204. var rx = d[i++];
  12205. var ry = d[i++];
  12206. var theta = d[i++];
  12207. var dTheta = d[i++];
  12208. var psi = d[i++];
  12209. var fs = d[i++];
  12210. var r = (rx > ry) ? rx : ry;
  12211. var scaleX = (rx > ry) ? 1 : rx / ry;
  12212. var scaleY = (rx > ry) ? ry / rx : 1;
  12213. var isEllipse = Math.abs(rx - ry) > 1e-3;
  12214. var endAngle = theta + dTheta;
  12215. if (isEllipse) {
  12216. ctx.translate(cx, cy);
  12217. ctx.rotate(psi);
  12218. ctx.scale(scaleX, scaleY);
  12219. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  12220. ctx.scale(1 / scaleX, 1 / scaleY);
  12221. ctx.rotate(-psi);
  12222. ctx.translate(-cx, -cy);
  12223. }
  12224. else {
  12225. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  12226. }
  12227. if (i === 1) {
  12228. // 直接使用 arc 命令
  12229. // 第一个命令起点还未定义
  12230. x0 = mathCos$1(theta) * rx + cx;
  12231. y0 = mathSin$1(theta) * ry + cy;
  12232. }
  12233. xi = mathCos$1(endAngle) * rx + cx;
  12234. yi = mathSin$1(endAngle) * ry + cy;
  12235. break;
  12236. case CMD.R:
  12237. x0 = xi = d[i];
  12238. y0 = yi = d[i + 1];
  12239. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  12240. break;
  12241. case CMD.Z:
  12242. ctx.closePath();
  12243. xi = x0;
  12244. yi = y0;
  12245. }
  12246. }
  12247. }
  12248. };
  12249. PathProxy.CMD = CMD;
  12250. /**
  12251. * 线段包含判断
  12252. * @param {number} x0
  12253. * @param {number} y0
  12254. * @param {number} x1
  12255. * @param {number} y1
  12256. * @param {number} lineWidth
  12257. * @param {number} x
  12258. * @param {number} y
  12259. * @return {boolean}
  12260. */
  12261. function containStroke$1(x0, y0, x1, y1, lineWidth, x, y) {
  12262. if (lineWidth === 0) {
  12263. return false;
  12264. }
  12265. var _l = lineWidth;
  12266. var _a = 0;
  12267. var _b = x0;
  12268. // Quick reject
  12269. if (
  12270. (y > y0 + _l && y > y1 + _l)
  12271. || (y < y0 - _l && y < y1 - _l)
  12272. || (x > x0 + _l && x > x1 + _l)
  12273. || (x < x0 - _l && x < x1 - _l)
  12274. ) {
  12275. return false;
  12276. }
  12277. if (x0 !== x1) {
  12278. _a = (y0 - y1) / (x0 - x1);
  12279. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  12280. }
  12281. else {
  12282. return Math.abs(x - x0) <= _l / 2;
  12283. }
  12284. var tmp = _a * x - y + _b;
  12285. var _s = tmp * tmp / (_a * _a + 1);
  12286. return _s <= _l / 2 * _l / 2;
  12287. }
  12288. /**
  12289. * 三次贝塞尔曲线描边包含判断
  12290. * @param {number} x0
  12291. * @param {number} y0
  12292. * @param {number} x1
  12293. * @param {number} y1
  12294. * @param {number} x2
  12295. * @param {number} y2
  12296. * @param {number} x3
  12297. * @param {number} y3
  12298. * @param {number} lineWidth
  12299. * @param {number} x
  12300. * @param {number} y
  12301. * @return {boolean}
  12302. */
  12303. function containStroke$2(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  12304. if (lineWidth === 0) {
  12305. return false;
  12306. }
  12307. var _l = lineWidth;
  12308. // Quick reject
  12309. if (
  12310. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  12311. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  12312. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  12313. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  12314. ) {
  12315. return false;
  12316. }
  12317. var d = cubicProjectPoint(
  12318. x0, y0, x1, y1, x2, y2, x3, y3,
  12319. x, y, null
  12320. );
  12321. return d <= _l / 2;
  12322. }
  12323. /**
  12324. * 二次贝塞尔曲线描边包含判断
  12325. * @param {number} x0
  12326. * @param {number} y0
  12327. * @param {number} x1
  12328. * @param {number} y1
  12329. * @param {number} x2
  12330. * @param {number} y2
  12331. * @param {number} lineWidth
  12332. * @param {number} x
  12333. * @param {number} y
  12334. * @return {boolean}
  12335. */
  12336. function containStroke$3(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  12337. if (lineWidth === 0) {
  12338. return false;
  12339. }
  12340. var _l = lineWidth;
  12341. // Quick reject
  12342. if (
  12343. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  12344. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  12345. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  12346. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  12347. ) {
  12348. return false;
  12349. }
  12350. var d = quadraticProjectPoint(
  12351. x0, y0, x1, y1, x2, y2,
  12352. x, y, null
  12353. );
  12354. return d <= _l / 2;
  12355. }
  12356. var PI2$3 = Math.PI * 2;
  12357. function normalizeRadian(angle) {
  12358. angle %= PI2$3;
  12359. if (angle < 0) {
  12360. angle += PI2$3;
  12361. }
  12362. return angle;
  12363. }
  12364. var PI2$2 = Math.PI * 2;
  12365. /**
  12366. * 圆弧描边包含判断
  12367. * @param {number} cx
  12368. * @param {number} cy
  12369. * @param {number} r
  12370. * @param {number} startAngle
  12371. * @param {number} endAngle
  12372. * @param {boolean} anticlockwise
  12373. * @param {number} lineWidth
  12374. * @param {number} x
  12375. * @param {number} y
  12376. * @return {Boolean}
  12377. */
  12378. function containStroke$4(
  12379. cx, cy, r, startAngle, endAngle, anticlockwise,
  12380. lineWidth, x, y
  12381. ) {
  12382. if (lineWidth === 0) {
  12383. return false;
  12384. }
  12385. var _l = lineWidth;
  12386. x -= cx;
  12387. y -= cy;
  12388. var d = Math.sqrt(x * x + y * y);
  12389. if ((d - _l > r) || (d + _l < r)) {
  12390. return false;
  12391. }
  12392. if (Math.abs(startAngle - endAngle) % PI2$2 < 1e-4) {
  12393. // Is a circle
  12394. return true;
  12395. }
  12396. if (anticlockwise) {
  12397. var tmp = startAngle;
  12398. startAngle = normalizeRadian(endAngle);
  12399. endAngle = normalizeRadian(tmp);
  12400. }
  12401. else {
  12402. startAngle = normalizeRadian(startAngle);
  12403. endAngle = normalizeRadian(endAngle);
  12404. }
  12405. if (startAngle > endAngle) {
  12406. endAngle += PI2$2;
  12407. }
  12408. var angle = Math.atan2(y, x);
  12409. if (angle < 0) {
  12410. angle += PI2$2;
  12411. }
  12412. return (angle >= startAngle && angle <= endAngle)
  12413. || (angle + PI2$2 >= startAngle && angle + PI2$2 <= endAngle);
  12414. }
  12415. function windingLine(x0, y0, x1, y1, x, y) {
  12416. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  12417. return 0;
  12418. }
  12419. // Ignore horizontal line
  12420. if (y1 === y0) {
  12421. return 0;
  12422. }
  12423. var dir = y1 < y0 ? 1 : -1;
  12424. var t = (y - y0) / (y1 - y0);
  12425. // Avoid winding error when intersection point is the connect point of two line of polygon
  12426. if (t === 1 || t === 0) {
  12427. dir = y1 < y0 ? 0.5 : -0.5;
  12428. }
  12429. var x_ = t * (x1 - x0) + x0;
  12430. // If (x, y) on the line, considered as "contain".
  12431. return x_ === x ? Infinity : x_ > x ? dir : 0;
  12432. }
  12433. var CMD$1 = PathProxy.CMD;
  12434. var PI2$1 = Math.PI * 2;
  12435. var EPSILON$2 = 1e-4;
  12436. function isAroundEqual(a, b) {
  12437. return Math.abs(a - b) < EPSILON$2;
  12438. }
  12439. // 临时数组
  12440. var roots = [-1, -1, -1];
  12441. var extrema = [-1, -1];
  12442. function swapExtrema() {
  12443. var tmp = extrema[0];
  12444. extrema[0] = extrema[1];
  12445. extrema[1] = tmp;
  12446. }
  12447. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  12448. // Quick reject
  12449. if (
  12450. (y > y0 && y > y1 && y > y2 && y > y3)
  12451. || (y < y0 && y < y1 && y < y2 && y < y3)
  12452. ) {
  12453. return 0;
  12454. }
  12455. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  12456. if (nRoots === 0) {
  12457. return 0;
  12458. }
  12459. else {
  12460. var w = 0;
  12461. var nExtrema = -1;
  12462. var y0_;
  12463. var y1_;
  12464. for (var i = 0; i < nRoots; i++) {
  12465. var t = roots[i];
  12466. // Avoid winding error when intersection point is the connect point of two line of polygon
  12467. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  12468. var x_ = cubicAt(x0, x1, x2, x3, t);
  12469. if (x_ < x) { // Quick reject
  12470. continue;
  12471. }
  12472. if (nExtrema < 0) {
  12473. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  12474. if (extrema[1] < extrema[0] && nExtrema > 1) {
  12475. swapExtrema();
  12476. }
  12477. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  12478. if (nExtrema > 1) {
  12479. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  12480. }
  12481. }
  12482. if (nExtrema === 2) {
  12483. // 分成三段单调函数
  12484. if (t < extrema[0]) {
  12485. w += y0_ < y0 ? unit : -unit;
  12486. }
  12487. else if (t < extrema[1]) {
  12488. w += y1_ < y0_ ? unit : -unit;
  12489. }
  12490. else {
  12491. w += y3 < y1_ ? unit : -unit;
  12492. }
  12493. }
  12494. else {
  12495. // 分成两段单调函数
  12496. if (t < extrema[0]) {
  12497. w += y0_ < y0 ? unit : -unit;
  12498. }
  12499. else {
  12500. w += y3 < y0_ ? unit : -unit;
  12501. }
  12502. }
  12503. }
  12504. return w;
  12505. }
  12506. }
  12507. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  12508. // Quick reject
  12509. if (
  12510. (y > y0 && y > y1 && y > y2)
  12511. || (y < y0 && y < y1 && y < y2)
  12512. ) {
  12513. return 0;
  12514. }
  12515. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  12516. if (nRoots === 0) {
  12517. return 0;
  12518. }
  12519. else {
  12520. var t = quadraticExtremum(y0, y1, y2);
  12521. if (t >= 0 && t <= 1) {
  12522. var w = 0;
  12523. var y_ = quadraticAt(y0, y1, y2, t);
  12524. for (var i = 0; i < nRoots; i++) {
  12525. // Remove one endpoint.
  12526. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  12527. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  12528. if (x_ < x) { // Quick reject
  12529. continue;
  12530. }
  12531. if (roots[i] < t) {
  12532. w += y_ < y0 ? unit : -unit;
  12533. }
  12534. else {
  12535. w += y2 < y_ ? unit : -unit;
  12536. }
  12537. }
  12538. return w;
  12539. }
  12540. else {
  12541. // Remove one endpoint.
  12542. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  12543. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  12544. if (x_ < x) { // Quick reject
  12545. return 0;
  12546. }
  12547. return y2 < y0 ? unit : -unit;
  12548. }
  12549. }
  12550. }
  12551. // TODO
  12552. // Arc 旋转
  12553. function windingArc(
  12554. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  12555. ) {
  12556. y -= cy;
  12557. if (y > r || y < -r) {
  12558. return 0;
  12559. }
  12560. var tmp = Math.sqrt(r * r - y * y);
  12561. roots[0] = -tmp;
  12562. roots[1] = tmp;
  12563. var diff = Math.abs(startAngle - endAngle);
  12564. if (diff < 1e-4) {
  12565. return 0;
  12566. }
  12567. if (diff % PI2$1 < 1e-4) {
  12568. // Is a circle
  12569. startAngle = 0;
  12570. endAngle = PI2$1;
  12571. var dir = anticlockwise ? 1 : -1;
  12572. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  12573. return dir;
  12574. }
  12575. else {
  12576. return 0;
  12577. }
  12578. }
  12579. if (anticlockwise) {
  12580. var tmp = startAngle;
  12581. startAngle = normalizeRadian(endAngle);
  12582. endAngle = normalizeRadian(tmp);
  12583. }
  12584. else {
  12585. startAngle = normalizeRadian(startAngle);
  12586. endAngle = normalizeRadian(endAngle);
  12587. }
  12588. if (startAngle > endAngle) {
  12589. endAngle += PI2$1;
  12590. }
  12591. var w = 0;
  12592. for (var i = 0; i < 2; i++) {
  12593. var x_ = roots[i];
  12594. if (x_ + cx > x) {
  12595. var angle = Math.atan2(y, x_);
  12596. var dir = anticlockwise ? 1 : -1;
  12597. if (angle < 0) {
  12598. angle = PI2$1 + angle;
  12599. }
  12600. if (
  12601. (angle >= startAngle && angle <= endAngle)
  12602. || (angle + PI2$1 >= startAngle && angle + PI2$1 <= endAngle)
  12603. ) {
  12604. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  12605. dir = -dir;
  12606. }
  12607. w += dir;
  12608. }
  12609. }
  12610. }
  12611. return w;
  12612. }
  12613. function containPath(data, lineWidth, isStroke, x, y) {
  12614. var w = 0;
  12615. var xi = 0;
  12616. var yi = 0;
  12617. var x0 = 0;
  12618. var y0 = 0;
  12619. for (var i = 0; i < data.length;) {
  12620. var cmd = data[i++];
  12621. // Begin a new subpath
  12622. if (cmd === CMD$1.M && i > 1) {
  12623. // Close previous subpath
  12624. if (!isStroke) {
  12625. w += windingLine(xi, yi, x0, y0, x, y);
  12626. }
  12627. // 如果被任何一个 subpath 包含
  12628. // if (w !== 0) {
  12629. // return true;
  12630. // }
  12631. }
  12632. if (i === 1) {
  12633. // 如果第一个命令是 L, C, Q
  12634. // 则 previous point 同绘制命令的第一个 point
  12635. //
  12636. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12637. xi = data[i];
  12638. yi = data[i + 1];
  12639. x0 = xi;
  12640. y0 = yi;
  12641. }
  12642. switch (cmd) {
  12643. case CMD$1.M:
  12644. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  12645. // 在 closePath 的时候使用
  12646. x0 = data[i++];
  12647. y0 = data[i++];
  12648. xi = x0;
  12649. yi = y0;
  12650. break;
  12651. case CMD$1.L:
  12652. if (isStroke) {
  12653. if (containStroke$1(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  12654. return true;
  12655. }
  12656. }
  12657. else {
  12658. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  12659. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  12660. }
  12661. xi = data[i++];
  12662. yi = data[i++];
  12663. break;
  12664. case CMD$1.C:
  12665. if (isStroke) {
  12666. if (containStroke$2(xi, yi,
  12667. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12668. lineWidth, x, y
  12669. )) {
  12670. return true;
  12671. }
  12672. }
  12673. else {
  12674. w += windingCubic(
  12675. xi, yi,
  12676. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12677. x, y
  12678. ) || 0;
  12679. }
  12680. xi = data[i++];
  12681. yi = data[i++];
  12682. break;
  12683. case CMD$1.Q:
  12684. if (isStroke) {
  12685. if (containStroke$3(xi, yi,
  12686. data[i++], data[i++], data[i], data[i + 1],
  12687. lineWidth, x, y
  12688. )) {
  12689. return true;
  12690. }
  12691. }
  12692. else {
  12693. w += windingQuadratic(
  12694. xi, yi,
  12695. data[i++], data[i++], data[i], data[i + 1],
  12696. x, y
  12697. ) || 0;
  12698. }
  12699. xi = data[i++];
  12700. yi = data[i++];
  12701. break;
  12702. case CMD$1.A:
  12703. // TODO Arc 判断的开销比较大
  12704. var cx = data[i++];
  12705. var cy = data[i++];
  12706. var rx = data[i++];
  12707. var ry = data[i++];
  12708. var theta = data[i++];
  12709. var dTheta = data[i++];
  12710. // TODO Arc 旋转
  12711. i += 1;
  12712. var anticlockwise = 1 - data[i++];
  12713. var x1 = Math.cos(theta) * rx + cx;
  12714. var y1 = Math.sin(theta) * ry + cy;
  12715. // 不是直接使用 arc 命令
  12716. if (i > 1) {
  12717. w += windingLine(xi, yi, x1, y1, x, y);
  12718. }
  12719. else {
  12720. // 第一个命令起点还未定义
  12721. x0 = x1;
  12722. y0 = y1;
  12723. }
  12724. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  12725. var _x = (x - cx) * ry / rx + cx;
  12726. if (isStroke) {
  12727. if (containStroke$4(
  12728. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12729. lineWidth, _x, y
  12730. )) {
  12731. return true;
  12732. }
  12733. }
  12734. else {
  12735. w += windingArc(
  12736. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12737. _x, y
  12738. );
  12739. }
  12740. xi = Math.cos(theta + dTheta) * rx + cx;
  12741. yi = Math.sin(theta + dTheta) * ry + cy;
  12742. break;
  12743. case CMD$1.R:
  12744. x0 = xi = data[i++];
  12745. y0 = yi = data[i++];
  12746. var width = data[i++];
  12747. var height = data[i++];
  12748. var x1 = x0 + width;
  12749. var y1 = y0 + height;
  12750. if (isStroke) {
  12751. if (containStroke$1(x0, y0, x1, y0, lineWidth, x, y)
  12752. || containStroke$1(x1, y0, x1, y1, lineWidth, x, y)
  12753. || containStroke$1(x1, y1, x0, y1, lineWidth, x, y)
  12754. || containStroke$1(x0, y1, x0, y0, lineWidth, x, y)
  12755. ) {
  12756. return true;
  12757. }
  12758. }
  12759. else {
  12760. // FIXME Clockwise ?
  12761. w += windingLine(x1, y0, x1, y1, x, y);
  12762. w += windingLine(x0, y1, x0, y0, x, y);
  12763. }
  12764. break;
  12765. case CMD$1.Z:
  12766. if (isStroke) {
  12767. if (containStroke$1(
  12768. xi, yi, x0, y0, lineWidth, x, y
  12769. )) {
  12770. return true;
  12771. }
  12772. }
  12773. else {
  12774. // Close a subpath
  12775. w += windingLine(xi, yi, x0, y0, x, y);
  12776. // 如果被任何一个 subpath 包含
  12777. // FIXME subpaths may overlap
  12778. // if (w !== 0) {
  12779. // return true;
  12780. // }
  12781. }
  12782. xi = x0;
  12783. yi = y0;
  12784. break;
  12785. }
  12786. }
  12787. if (!isStroke && !isAroundEqual(yi, y0)) {
  12788. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  12789. }
  12790. return w !== 0;
  12791. }
  12792. function contain(pathData, x, y) {
  12793. return containPath(pathData, 0, false, x, y);
  12794. }
  12795. function containStroke(pathData, lineWidth, x, y) {
  12796. return containPath(pathData, lineWidth, true, x, y);
  12797. }
  12798. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  12799. var abs = Math.abs;
  12800. var pathProxyForDraw = new PathProxy(true);
  12801. /**
  12802. * @alias module:zrender/graphic/Path
  12803. * @extends module:zrender/graphic/Displayable
  12804. * @constructor
  12805. * @param {Object} opts
  12806. */
  12807. function Path(opts) {
  12808. Displayable.call(this, opts);
  12809. /**
  12810. * @type {module:zrender/core/PathProxy}
  12811. * @readOnly
  12812. */
  12813. this.path = null;
  12814. }
  12815. Path.prototype = {
  12816. constructor: Path,
  12817. type: 'path',
  12818. __dirtyPath: true,
  12819. strokeContainThreshold: 5,
  12820. // This item default to be false. But in map series in echarts,
  12821. // in order to improve performance, it should be set to true,
  12822. // so the shorty segment won't draw.
  12823. segmentIgnoreThreshold: 0,
  12824. /**
  12825. * See `module:zrender/src/graphic/helper/subPixelOptimize`.
  12826. * @type {boolean}
  12827. */
  12828. subPixelOptimize: false,
  12829. brush: function (ctx, prevEl) {
  12830. var style = this.style;
  12831. var path = this.path || pathProxyForDraw;
  12832. var hasStroke = style.hasStroke();
  12833. var hasFill = style.hasFill();
  12834. var fill = style.fill;
  12835. var stroke = style.stroke;
  12836. var hasFillGradient = hasFill && !!(fill.colorStops);
  12837. var hasStrokeGradient = hasStroke && !!(stroke.colorStops);
  12838. var hasFillPattern = hasFill && !!(fill.image);
  12839. var hasStrokePattern = hasStroke && !!(stroke.image);
  12840. style.bind(ctx, this, prevEl);
  12841. this.setTransform(ctx);
  12842. if (this.__dirty) {
  12843. var rect;
  12844. // Update gradient because bounding rect may changed
  12845. if (hasFillGradient) {
  12846. rect = rect || this.getBoundingRect();
  12847. this._fillGradient = style.getGradient(ctx, fill, rect);
  12848. }
  12849. if (hasStrokeGradient) {
  12850. rect = rect || this.getBoundingRect();
  12851. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  12852. }
  12853. }
  12854. // Use the gradient or pattern
  12855. if (hasFillGradient) {
  12856. // PENDING If may have affect the state
  12857. ctx.fillStyle = this._fillGradient;
  12858. }
  12859. else if (hasFillPattern) {
  12860. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  12861. }
  12862. if (hasStrokeGradient) {
  12863. ctx.strokeStyle = this._strokeGradient;
  12864. }
  12865. else if (hasStrokePattern) {
  12866. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  12867. }
  12868. var lineDash = style.lineDash;
  12869. var lineDashOffset = style.lineDashOffset;
  12870. var ctxLineDash = !!ctx.setLineDash;
  12871. // Update path sx, sy
  12872. var scale = this.getGlobalScale();
  12873. path.setScale(scale[0], scale[1], this.segmentIgnoreThreshold);
  12874. // Proxy context
  12875. // Rebuild path in following 2 cases
  12876. // 1. Path is dirty
  12877. // 2. Path needs javascript implemented lineDash stroking.
  12878. // In this case, lineDash information will not be saved in PathProxy
  12879. if (this.__dirtyPath
  12880. || (lineDash && !ctxLineDash && hasStroke)
  12881. ) {
  12882. path.beginPath(ctx);
  12883. // Setting line dash before build path
  12884. if (lineDash && !ctxLineDash) {
  12885. path.setLineDash(lineDash);
  12886. path.setLineDashOffset(lineDashOffset);
  12887. }
  12888. this.buildPath(path, this.shape, false);
  12889. // Clear path dirty flag
  12890. if (this.path) {
  12891. this.__dirtyPath = false;
  12892. }
  12893. }
  12894. else {
  12895. // Replay path building
  12896. ctx.beginPath();
  12897. this.path.rebuildPath(ctx);
  12898. }
  12899. if (hasFill) {
  12900. if (style.fillOpacity != null) {
  12901. var originalGlobalAlpha = ctx.globalAlpha;
  12902. ctx.globalAlpha = style.fillOpacity * style.opacity;
  12903. path.fill(ctx);
  12904. ctx.globalAlpha = originalGlobalAlpha;
  12905. }
  12906. else {
  12907. path.fill(ctx);
  12908. }
  12909. }
  12910. if (lineDash && ctxLineDash) {
  12911. ctx.setLineDash(lineDash);
  12912. ctx.lineDashOffset = lineDashOffset;
  12913. }
  12914. if (hasStroke) {
  12915. if (style.strokeOpacity != null) {
  12916. var originalGlobalAlpha = ctx.globalAlpha;
  12917. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  12918. path.stroke(ctx);
  12919. ctx.globalAlpha = originalGlobalAlpha;
  12920. }
  12921. else {
  12922. path.stroke(ctx);
  12923. }
  12924. }
  12925. if (lineDash && ctxLineDash) {
  12926. // PENDING
  12927. // Remove lineDash
  12928. ctx.setLineDash([]);
  12929. }
  12930. // Draw rect text
  12931. if (style.text != null) {
  12932. // Only restore transform when needs draw text.
  12933. this.restoreTransform(ctx);
  12934. this.drawRectText(ctx, this.getBoundingRect());
  12935. }
  12936. },
  12937. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  12938. // Like in circle
  12939. buildPath: function (ctx, shapeCfg, inBundle) {},
  12940. createPathProxy: function () {
  12941. this.path = new PathProxy();
  12942. },
  12943. getBoundingRect: function () {
  12944. var rect = this._rect;
  12945. var style = this.style;
  12946. var needsUpdateRect = !rect;
  12947. if (needsUpdateRect) {
  12948. var path = this.path;
  12949. if (!path) {
  12950. // Create path on demand.
  12951. path = this.path = new PathProxy();
  12952. }
  12953. if (this.__dirtyPath) {
  12954. path.beginPath();
  12955. this.buildPath(path, this.shape, false);
  12956. }
  12957. rect = path.getBoundingRect();
  12958. }
  12959. this._rect = rect;
  12960. if (style.hasStroke()) {
  12961. // Needs update rect with stroke lineWidth when
  12962. // 1. Element changes scale or lineWidth
  12963. // 2. Shape is changed
  12964. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  12965. if (this.__dirty || needsUpdateRect) {
  12966. rectWithStroke.copy(rect);
  12967. // FIXME Must after updateTransform
  12968. var w = style.lineWidth;
  12969. // PENDING, Min line width is needed when line is horizontal or vertical
  12970. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  12971. // Only add extra hover lineWidth when there are no fill
  12972. if (!style.hasFill()) {
  12973. w = Math.max(w, this.strokeContainThreshold || 4);
  12974. }
  12975. // Consider line width
  12976. // Line scale can't be 0;
  12977. if (lineScale > 1e-10) {
  12978. rectWithStroke.width += w / lineScale;
  12979. rectWithStroke.height += w / lineScale;
  12980. rectWithStroke.x -= w / lineScale / 2;
  12981. rectWithStroke.y -= w / lineScale / 2;
  12982. }
  12983. }
  12984. // Return rect with stroke
  12985. return rectWithStroke;
  12986. }
  12987. return rect;
  12988. },
  12989. contain: function (x, y) {
  12990. var localPos = this.transformCoordToLocal(x, y);
  12991. var rect = this.getBoundingRect();
  12992. var style = this.style;
  12993. x = localPos[0];
  12994. y = localPos[1];
  12995. if (rect.contain(x, y)) {
  12996. var pathData = this.path.data;
  12997. if (style.hasStroke()) {
  12998. var lineWidth = style.lineWidth;
  12999. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  13000. // Line scale can't be 0;
  13001. if (lineScale > 1e-10) {
  13002. // Only add extra hover lineWidth when there are no fill
  13003. if (!style.hasFill()) {
  13004. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  13005. }
  13006. if (containStroke(
  13007. pathData, lineWidth / lineScale, x, y
  13008. )) {
  13009. return true;
  13010. }
  13011. }
  13012. }
  13013. if (style.hasFill()) {
  13014. return contain(pathData, x, y);
  13015. }
  13016. }
  13017. return false;
  13018. },
  13019. /**
  13020. * @param {boolean} dirtyPath
  13021. */
  13022. dirty: function (dirtyPath) {
  13023. if (dirtyPath == null) {
  13024. dirtyPath = true;
  13025. }
  13026. // Only mark dirty, not mark clean
  13027. if (dirtyPath) {
  13028. this.__dirtyPath = dirtyPath;
  13029. this._rect = null;
  13030. }
  13031. this.__dirty = this.__dirtyText = true;
  13032. this.__zr && this.__zr.refresh();
  13033. // Used as a clipping path
  13034. if (this.__clipTarget) {
  13035. this.__clipTarget.dirty();
  13036. }
  13037. },
  13038. /**
  13039. * Alias for animate('shape')
  13040. * @param {boolean} loop
  13041. */
  13042. animateShape: function (loop) {
  13043. return this.animate('shape', loop);
  13044. },
  13045. // Overwrite attrKV
  13046. attrKV: function (key, value) {
  13047. // FIXME
  13048. if (key === 'shape') {
  13049. this.setShape(value);
  13050. this.__dirtyPath = true;
  13051. this._rect = null;
  13052. }
  13053. else {
  13054. Displayable.prototype.attrKV.call(this, key, value);
  13055. }
  13056. },
  13057. /**
  13058. * @param {Object|string} key
  13059. * @param {*} value
  13060. */
  13061. setShape: function (key, value) {
  13062. var shape = this.shape;
  13063. // Path from string may not have shape
  13064. if (shape) {
  13065. if (isObject$1(key)) {
  13066. for (var name in key) {
  13067. if (key.hasOwnProperty(name)) {
  13068. shape[name] = key[name];
  13069. }
  13070. }
  13071. }
  13072. else {
  13073. shape[key] = value;
  13074. }
  13075. this.dirty(true);
  13076. }
  13077. return this;
  13078. },
  13079. getLineScale: function () {
  13080. var m = this.transform;
  13081. // Get the line scale.
  13082. // Determinant of `m` means how much the area is enlarged by the
  13083. // transformation. So its square root can be used as a scale factor
  13084. // for width.
  13085. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  13086. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  13087. : 1;
  13088. }
  13089. };
  13090. /**
  13091. * 扩展一个 Path element, 比如星形,圆等。
  13092. * Extend a path element
  13093. * @param {Object} props
  13094. * @param {string} props.type Path type
  13095. * @param {Function} props.init Initialize
  13096. * @param {Function} props.buildPath Overwrite buildPath method
  13097. * @param {Object} [props.style] Extended default style config
  13098. * @param {Object} [props.shape] Extended default shape config
  13099. */
  13100. Path.extend = function (defaults$$1) {
  13101. var Sub = function (opts) {
  13102. Path.call(this, opts);
  13103. if (defaults$$1.style) {
  13104. // Extend default style
  13105. this.style.extendFrom(defaults$$1.style, false);
  13106. }
  13107. // Extend default shape
  13108. var defaultShape = defaults$$1.shape;
  13109. if (defaultShape) {
  13110. this.shape = this.shape || {};
  13111. var thisShape = this.shape;
  13112. for (var name in defaultShape) {
  13113. if (
  13114. !thisShape.hasOwnProperty(name)
  13115. && defaultShape.hasOwnProperty(name)
  13116. ) {
  13117. thisShape[name] = defaultShape[name];
  13118. }
  13119. }
  13120. }
  13121. defaults$$1.init && defaults$$1.init.call(this, opts);
  13122. };
  13123. inherits(Sub, Path);
  13124. // FIXME 不能 extend position, rotation 等引用对象
  13125. for (var name in defaults$$1) {
  13126. // Extending prototype values and methods
  13127. if (name !== 'style' && name !== 'shape') {
  13128. Sub.prototype[name] = defaults$$1[name];
  13129. }
  13130. }
  13131. return Sub;
  13132. };
  13133. inherits(Path, Displayable);
  13134. var CMD$2 = PathProxy.CMD;
  13135. var points = [[], [], []];
  13136. var mathSqrt$3 = Math.sqrt;
  13137. var mathAtan2 = Math.atan2;
  13138. var transformPath = function (path, m) {
  13139. var data = path.data;
  13140. var cmd;
  13141. var nPoint;
  13142. var i;
  13143. var j;
  13144. var k;
  13145. var p;
  13146. var M = CMD$2.M;
  13147. var C = CMD$2.C;
  13148. var L = CMD$2.L;
  13149. var R = CMD$2.R;
  13150. var A = CMD$2.A;
  13151. var Q = CMD$2.Q;
  13152. for (i = 0, j = 0; i < data.length;) {
  13153. cmd = data[i++];
  13154. j = i;
  13155. nPoint = 0;
  13156. switch (cmd) {
  13157. case M:
  13158. nPoint = 1;
  13159. break;
  13160. case L:
  13161. nPoint = 1;
  13162. break;
  13163. case C:
  13164. nPoint = 3;
  13165. break;
  13166. case Q:
  13167. nPoint = 2;
  13168. break;
  13169. case A:
  13170. var x = m[4];
  13171. var y = m[5];
  13172. var sx = mathSqrt$3(m[0] * m[0] + m[1] * m[1]);
  13173. var sy = mathSqrt$3(m[2] * m[2] + m[3] * m[3]);
  13174. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  13175. // cx
  13176. data[i] *= sx;
  13177. data[i++] += x;
  13178. // cy
  13179. data[i] *= sy;
  13180. data[i++] += y;
  13181. // Scale rx and ry
  13182. // FIXME Assume psi is 0 here
  13183. data[i++] *= sx;
  13184. data[i++] *= sy;
  13185. // Start angle
  13186. data[i++] += angle;
  13187. // end angle
  13188. data[i++] += angle;
  13189. // FIXME psi
  13190. i += 2;
  13191. j = i;
  13192. break;
  13193. case R:
  13194. // x0, y0
  13195. p[0] = data[i++];
  13196. p[1] = data[i++];
  13197. applyTransform(p, p, m);
  13198. data[j++] = p[0];
  13199. data[j++] = p[1];
  13200. // x1, y1
  13201. p[0] += data[i++];
  13202. p[1] += data[i++];
  13203. applyTransform(p, p, m);
  13204. data[j++] = p[0];
  13205. data[j++] = p[1];
  13206. }
  13207. for (k = 0; k < nPoint; k++) {
  13208. var p = points[k];
  13209. p[0] = data[i++];
  13210. p[1] = data[i++];
  13211. applyTransform(p, p, m);
  13212. // Write back
  13213. data[j++] = p[0];
  13214. data[j++] = p[1];
  13215. }
  13216. }
  13217. };
  13218. // command chars
  13219. // var cc = [
  13220. // 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  13221. // 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  13222. // ];
  13223. var mathSqrt = Math.sqrt;
  13224. var mathSin = Math.sin;
  13225. var mathCos = Math.cos;
  13226. var PI = Math.PI;
  13227. var vMag = function (v) {
  13228. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  13229. };
  13230. var vRatio = function (u, v) {
  13231. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  13232. };
  13233. var vAngle = function (u, v) {
  13234. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  13235. * Math.acos(vRatio(u, v));
  13236. };
  13237. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  13238. var psi = psiDeg * (PI / 180.0);
  13239. var xp = mathCos(psi) * (x1 - x2) / 2.0
  13240. + mathSin(psi) * (y1 - y2) / 2.0;
  13241. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  13242. + mathCos(psi) * (y1 - y2) / 2.0;
  13243. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  13244. if (lambda > 1) {
  13245. rx *= mathSqrt(lambda);
  13246. ry *= mathSqrt(lambda);
  13247. }
  13248. var f = (fa === fs ? -1 : 1)
  13249. * mathSqrt((((rx * rx) * (ry * ry))
  13250. - ((rx * rx) * (yp * yp))
  13251. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  13252. + (ry * ry) * (xp * xp))
  13253. ) || 0;
  13254. var cxp = f * rx * yp / ry;
  13255. var cyp = f * -ry * xp / rx;
  13256. var cx = (x1 + x2) / 2.0
  13257. + mathCos(psi) * cxp
  13258. - mathSin(psi) * cyp;
  13259. var cy = (y1 + y2) / 2.0
  13260. + mathSin(psi) * cxp
  13261. + mathCos(psi) * cyp;
  13262. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  13263. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  13264. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  13265. var dTheta = vAngle(u, v);
  13266. if (vRatio(u, v) <= -1) {
  13267. dTheta = PI;
  13268. }
  13269. if (vRatio(u, v) >= 1) {
  13270. dTheta = 0;
  13271. }
  13272. if (fs === 0 && dTheta > 0) {
  13273. dTheta = dTheta - 2 * PI;
  13274. }
  13275. if (fs === 1 && dTheta < 0) {
  13276. dTheta = dTheta + 2 * PI;
  13277. }
  13278. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  13279. }
  13280. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  13281. // Consider case:
  13282. // (1) delimiter can be comma or space, where continuous commas
  13283. // or spaces should be seen as one comma.
  13284. // (2) value can be like:
  13285. // '2e-4', 'l.5.9' (ignore 0), 'M-10-10', 'l-2.43e-1,34.9983',
  13286. // 'l-.5E1,54', '121-23-44-11' (no delimiter)
  13287. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  13288. // var valueSplitReg = /[\s,]+/;
  13289. function createPathProxyFromString(data) {
  13290. if (!data) {
  13291. return new PathProxy();
  13292. }
  13293. // var data = data.replace(/-/g, ' -')
  13294. // .replace(/ /g, ' ')
  13295. // .replace(/ /g, ',')
  13296. // .replace(/,,/g, ',');
  13297. // var n;
  13298. // create pipes so that we can split the data
  13299. // for (n = 0; n < cc.length; n++) {
  13300. // cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  13301. // }
  13302. // data = data.replace(/-/g, ',-');
  13303. // create array
  13304. // var arr = cs.split('|');
  13305. // init context point
  13306. var cpx = 0;
  13307. var cpy = 0;
  13308. var subpathX = cpx;
  13309. var subpathY = cpy;
  13310. var prevCmd;
  13311. var path = new PathProxy();
  13312. var CMD = PathProxy.CMD;
  13313. // commandReg.lastIndex = 0;
  13314. // var cmdResult;
  13315. // while ((cmdResult = commandReg.exec(data)) != null) {
  13316. // var cmdStr = cmdResult[1];
  13317. // var cmdContent = cmdResult[2];
  13318. var cmdList = data.match(commandReg);
  13319. for (var l = 0; l < cmdList.length; l++) {
  13320. var cmdText = cmdList[l];
  13321. var cmdStr = cmdText.charAt(0);
  13322. var cmd;
  13323. // String#split is faster a little bit than String#replace or RegExp#exec.
  13324. // var p = cmdContent.split(valueSplitReg);
  13325. // var pLen = 0;
  13326. // for (var i = 0; i < p.length; i++) {
  13327. // // '' and other invalid str => NaN
  13328. // var val = parseFloat(p[i]);
  13329. // !isNaN(val) && (p[pLen++] = val);
  13330. // }
  13331. var p = cmdText.match(numberReg) || [];
  13332. var pLen = p.length;
  13333. for (var i = 0; i < pLen; i++) {
  13334. p[i] = parseFloat(p[i]);
  13335. }
  13336. var off = 0;
  13337. while (off < pLen) {
  13338. var ctlPtx;
  13339. var ctlPty;
  13340. var rx;
  13341. var ry;
  13342. var psi;
  13343. var fa;
  13344. var fs;
  13345. var x1 = cpx;
  13346. var y1 = cpy;
  13347. // convert l, H, h, V, and v to L
  13348. switch (cmdStr) {
  13349. case 'l':
  13350. cpx += p[off++];
  13351. cpy += p[off++];
  13352. cmd = CMD.L;
  13353. path.addData(cmd, cpx, cpy);
  13354. break;
  13355. case 'L':
  13356. cpx = p[off++];
  13357. cpy = p[off++];
  13358. cmd = CMD.L;
  13359. path.addData(cmd, cpx, cpy);
  13360. break;
  13361. case 'm':
  13362. cpx += p[off++];
  13363. cpy += p[off++];
  13364. cmd = CMD.M;
  13365. path.addData(cmd, cpx, cpy);
  13366. subpathX = cpx;
  13367. subpathY = cpy;
  13368. cmdStr = 'l';
  13369. break;
  13370. case 'M':
  13371. cpx = p[off++];
  13372. cpy = p[off++];
  13373. cmd = CMD.M;
  13374. path.addData(cmd, cpx, cpy);
  13375. subpathX = cpx;
  13376. subpathY = cpy;
  13377. cmdStr = 'L';
  13378. break;
  13379. case 'h':
  13380. cpx += p[off++];
  13381. cmd = CMD.L;
  13382. path.addData(cmd, cpx, cpy);
  13383. break;
  13384. case 'H':
  13385. cpx = p[off++];
  13386. cmd = CMD.L;
  13387. path.addData(cmd, cpx, cpy);
  13388. break;
  13389. case 'v':
  13390. cpy += p[off++];
  13391. cmd = CMD.L;
  13392. path.addData(cmd, cpx, cpy);
  13393. break;
  13394. case 'V':
  13395. cpy = p[off++];
  13396. cmd = CMD.L;
  13397. path.addData(cmd, cpx, cpy);
  13398. break;
  13399. case 'C':
  13400. cmd = CMD.C;
  13401. path.addData(
  13402. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  13403. );
  13404. cpx = p[off - 2];
  13405. cpy = p[off - 1];
  13406. break;
  13407. case 'c':
  13408. cmd = CMD.C;
  13409. path.addData(
  13410. cmd,
  13411. p[off++] + cpx, p[off++] + cpy,
  13412. p[off++] + cpx, p[off++] + cpy,
  13413. p[off++] + cpx, p[off++] + cpy
  13414. );
  13415. cpx += p[off - 2];
  13416. cpy += p[off - 1];
  13417. break;
  13418. case 'S':
  13419. ctlPtx = cpx;
  13420. ctlPty = cpy;
  13421. var len = path.len();
  13422. var pathData = path.data;
  13423. if (prevCmd === CMD.C) {
  13424. ctlPtx += cpx - pathData[len - 4];
  13425. ctlPty += cpy - pathData[len - 3];
  13426. }
  13427. cmd = CMD.C;
  13428. x1 = p[off++];
  13429. y1 = p[off++];
  13430. cpx = p[off++];
  13431. cpy = p[off++];
  13432. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13433. break;
  13434. case 's':
  13435. ctlPtx = cpx;
  13436. ctlPty = cpy;
  13437. var len = path.len();
  13438. var pathData = path.data;
  13439. if (prevCmd === CMD.C) {
  13440. ctlPtx += cpx - pathData[len - 4];
  13441. ctlPty += cpy - pathData[len - 3];
  13442. }
  13443. cmd = CMD.C;
  13444. x1 = cpx + p[off++];
  13445. y1 = cpy + p[off++];
  13446. cpx += p[off++];
  13447. cpy += p[off++];
  13448. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13449. break;
  13450. case 'Q':
  13451. x1 = p[off++];
  13452. y1 = p[off++];
  13453. cpx = p[off++];
  13454. cpy = p[off++];
  13455. cmd = CMD.Q;
  13456. path.addData(cmd, x1, y1, cpx, cpy);
  13457. break;
  13458. case 'q':
  13459. x1 = p[off++] + cpx;
  13460. y1 = p[off++] + cpy;
  13461. cpx += p[off++];
  13462. cpy += p[off++];
  13463. cmd = CMD.Q;
  13464. path.addData(cmd, x1, y1, cpx, cpy);
  13465. break;
  13466. case 'T':
  13467. ctlPtx = cpx;
  13468. ctlPty = cpy;
  13469. var len = path.len();
  13470. var pathData = path.data;
  13471. if (prevCmd === CMD.Q) {
  13472. ctlPtx += cpx - pathData[len - 4];
  13473. ctlPty += cpy - pathData[len - 3];
  13474. }
  13475. cpx = p[off++];
  13476. cpy = p[off++];
  13477. cmd = CMD.Q;
  13478. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13479. break;
  13480. case 't':
  13481. ctlPtx = cpx;
  13482. ctlPty = cpy;
  13483. var len = path.len();
  13484. var pathData = path.data;
  13485. if (prevCmd === CMD.Q) {
  13486. ctlPtx += cpx - pathData[len - 4];
  13487. ctlPty += cpy - pathData[len - 3];
  13488. }
  13489. cpx += p[off++];
  13490. cpy += p[off++];
  13491. cmd = CMD.Q;
  13492. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13493. break;
  13494. case 'A':
  13495. rx = p[off++];
  13496. ry = p[off++];
  13497. psi = p[off++];
  13498. fa = p[off++];
  13499. fs = p[off++];
  13500. x1 = cpx, y1 = cpy;
  13501. cpx = p[off++];
  13502. cpy = p[off++];
  13503. cmd = CMD.A;
  13504. processArc(
  13505. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  13506. );
  13507. break;
  13508. case 'a':
  13509. rx = p[off++];
  13510. ry = p[off++];
  13511. psi = p[off++];
  13512. fa = p[off++];
  13513. fs = p[off++];
  13514. x1 = cpx, y1 = cpy;
  13515. cpx += p[off++];
  13516. cpy += p[off++];
  13517. cmd = CMD.A;
  13518. processArc(
  13519. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  13520. );
  13521. break;
  13522. }
  13523. }
  13524. if (cmdStr === 'z' || cmdStr === 'Z') {
  13525. cmd = CMD.Z;
  13526. path.addData(cmd);
  13527. // z may be in the middle of the path.
  13528. cpx = subpathX;
  13529. cpy = subpathY;
  13530. }
  13531. prevCmd = cmd;
  13532. }
  13533. path.toStatic();
  13534. return path;
  13535. }
  13536. // TODO Optimize double memory cost problem
  13537. function createPathOptions(str, opts) {
  13538. var pathProxy = createPathProxyFromString(str);
  13539. opts = opts || {};
  13540. opts.buildPath = function (path) {
  13541. if (path.setData) {
  13542. path.setData(pathProxy.data);
  13543. // Svg and vml renderer don't have context
  13544. var ctx = path.getContext();
  13545. if (ctx) {
  13546. path.rebuildPath(ctx);
  13547. }
  13548. }
  13549. else {
  13550. var ctx = path;
  13551. pathProxy.rebuildPath(ctx);
  13552. }
  13553. };
  13554. opts.applyTransform = function (m) {
  13555. transformPath(pathProxy, m);
  13556. this.dirty(true);
  13557. };
  13558. return opts;
  13559. }
  13560. /**
  13561. * Create a Path object from path string data
  13562. * http://www.w3.org/TR/SVG/paths.html#PathData
  13563. * @param {Object} opts Other options
  13564. */
  13565. function createFromString(str, opts) {
  13566. return new Path(createPathOptions(str, opts));
  13567. }
  13568. /**
  13569. * Create a Path class from path string data
  13570. * @param {string} str
  13571. * @param {Object} opts Other options
  13572. */
  13573. function extendFromString(str, opts) {
  13574. return Path.extend(createPathOptions(str, opts));
  13575. }
  13576. /**
  13577. * Merge multiple paths
  13578. */
  13579. // TODO Apply transform
  13580. // TODO stroke dash
  13581. // TODO Optimize double memory cost problem
  13582. function mergePath$1(pathEls, opts) {
  13583. var pathList = [];
  13584. var len = pathEls.length;
  13585. for (var i = 0; i < len; i++) {
  13586. var pathEl = pathEls[i];
  13587. if (!pathEl.path) {
  13588. pathEl.createPathProxy();
  13589. }
  13590. if (pathEl.__dirtyPath) {
  13591. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  13592. }
  13593. pathList.push(pathEl.path);
  13594. }
  13595. var pathBundle = new Path(opts);
  13596. // Need path proxy.
  13597. pathBundle.createPathProxy();
  13598. pathBundle.buildPath = function (path) {
  13599. path.appendPath(pathList);
  13600. // Svg and vml renderer don't have context
  13601. var ctx = path.getContext();
  13602. if (ctx) {
  13603. path.rebuildPath(ctx);
  13604. }
  13605. };
  13606. return pathBundle;
  13607. }
  13608. /**
  13609. * @alias zrender/graphic/Text
  13610. * @extends module:zrender/graphic/Displayable
  13611. * @constructor
  13612. * @param {Object} opts
  13613. */
  13614. var Text = function (opts) { // jshint ignore:line
  13615. Displayable.call(this, opts);
  13616. };
  13617. Text.prototype = {
  13618. constructor: Text,
  13619. type: 'text',
  13620. brush: function (ctx, prevEl) {
  13621. var style = this.style;
  13622. // Optimize, avoid normalize every time.
  13623. this.__dirty && normalizeTextStyle(style, true);
  13624. // Use props with prefix 'text'.
  13625. style.fill = style.stroke = style.shadowBlur = style.shadowColor =
  13626. style.shadowOffsetX = style.shadowOffsetY = null;
  13627. var text = style.text;
  13628. // Convert to string
  13629. text != null && (text += '');
  13630. // Do not apply style.bind in Text node. Because the real bind job
  13631. // is in textHelper.renderText, and performance of text render should
  13632. // be considered.
  13633. // style.bind(ctx, this, prevEl);
  13634. if (!needDrawText(text, style)) {
  13635. // The current el.style is not applied
  13636. // and should not be used as cache.
  13637. ctx.__attrCachedBy = ContextCachedBy.NONE;
  13638. return;
  13639. }
  13640. this.setTransform(ctx);
  13641. renderText(this, ctx, text, style, null, prevEl);
  13642. this.restoreTransform(ctx);
  13643. },
  13644. getBoundingRect: function () {
  13645. var style = this.style;
  13646. // Optimize, avoid normalize every time.
  13647. this.__dirty && normalizeTextStyle(style, true);
  13648. if (!this._rect) {
  13649. var text = style.text;
  13650. text != null ? (text += '') : (text = '');
  13651. var rect = getBoundingRect(
  13652. style.text + '',
  13653. style.font,
  13654. style.textAlign,
  13655. style.textVerticalAlign,
  13656. style.textPadding,
  13657. style.textLineHeight,
  13658. style.rich
  13659. );
  13660. rect.x += style.x || 0;
  13661. rect.y += style.y || 0;
  13662. if (getStroke(style.textStroke, style.textStrokeWidth)) {
  13663. var w = style.textStrokeWidth;
  13664. rect.x -= w / 2;
  13665. rect.y -= w / 2;
  13666. rect.width += w;
  13667. rect.height += w;
  13668. }
  13669. this._rect = rect;
  13670. }
  13671. return this._rect;
  13672. }
  13673. };
  13674. inherits(Text, Displayable);
  13675. /**
  13676. * 圆形
  13677. * @module zrender/shape/Circle
  13678. */
  13679. var Circle = Path.extend({
  13680. type: 'circle',
  13681. shape: {
  13682. cx: 0,
  13683. cy: 0,
  13684. r: 0
  13685. },
  13686. buildPath: function (ctx, shape, inBundle) {
  13687. // Better stroking in ShapeBundle
  13688. // Always do it may have performence issue ( fill may be 2x more cost)
  13689. if (inBundle) {
  13690. ctx.moveTo(shape.cx + shape.r, shape.cy);
  13691. }
  13692. // else {
  13693. // if (ctx.allocate && !ctx.data.length) {
  13694. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  13695. // }
  13696. // }
  13697. // Better stroking in ShapeBundle
  13698. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  13699. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  13700. }
  13701. });
  13702. // Fix weird bug in some version of IE11 (like 11.0.9600.178**),
  13703. // where exception "unexpected call to method or property access"
  13704. // might be thrown when calling ctx.fill or ctx.stroke after a path
  13705. // whose area size is zero is drawn and ctx.clip() is called and
  13706. // shadowBlur is set. See #4572, #3112, #5777.
  13707. // (e.g.,
  13708. // ctx.moveTo(10, 10);
  13709. // ctx.lineTo(20, 10);
  13710. // ctx.closePath();
  13711. // ctx.clip();
  13712. // ctx.shadowBlur = 10;
  13713. // ...
  13714. // ctx.fill();
  13715. // )
  13716. var shadowTemp = [
  13717. ['shadowBlur', 0],
  13718. ['shadowColor', '#000'],
  13719. ['shadowOffsetX', 0],
  13720. ['shadowOffsetY', 0]
  13721. ];
  13722. var fixClipWithShadow = function (orignalBrush) {
  13723. // version string can be: '11.0'
  13724. return (env$1.browser.ie && env$1.browser.version >= 11)
  13725. ? function () {
  13726. var clipPaths = this.__clipPaths;
  13727. var style = this.style;
  13728. var modified;
  13729. if (clipPaths) {
  13730. for (var i = 0; i < clipPaths.length; i++) {
  13731. var clipPath = clipPaths[i];
  13732. var shape = clipPath && clipPath.shape;
  13733. var type = clipPath && clipPath.type;
  13734. if (shape && (
  13735. (type === 'sector' && shape.startAngle === shape.endAngle)
  13736. || (type === 'rect' && (!shape.width || !shape.height))
  13737. )) {
  13738. for (var j = 0; j < shadowTemp.length; j++) {
  13739. // It is save to put shadowTemp static, because shadowTemp
  13740. // will be all modified each item brush called.
  13741. shadowTemp[j][2] = style[shadowTemp[j][0]];
  13742. style[shadowTemp[j][0]] = shadowTemp[j][1];
  13743. }
  13744. modified = true;
  13745. break;
  13746. }
  13747. }
  13748. }
  13749. orignalBrush.apply(this, arguments);
  13750. if (modified) {
  13751. for (var j = 0; j < shadowTemp.length; j++) {
  13752. style[shadowTemp[j][0]] = shadowTemp[j][2];
  13753. }
  13754. }
  13755. }
  13756. : orignalBrush;
  13757. };
  13758. /**
  13759. * 扇形
  13760. * @module zrender/graphic/shape/Sector
  13761. */
  13762. var Sector = Path.extend({
  13763. type: 'sector',
  13764. shape: {
  13765. cx: 0,
  13766. cy: 0,
  13767. r0: 0,
  13768. r: 0,
  13769. startAngle: 0,
  13770. endAngle: Math.PI * 2,
  13771. clockwise: true
  13772. },
  13773. brush: fixClipWithShadow(Path.prototype.brush),
  13774. buildPath: function (ctx, shape) {
  13775. var x = shape.cx;
  13776. var y = shape.cy;
  13777. var r0 = Math.max(shape.r0 || 0, 0);
  13778. var r = Math.max(shape.r, 0);
  13779. var startAngle = shape.startAngle;
  13780. var endAngle = shape.endAngle;
  13781. var clockwise = shape.clockwise;
  13782. var unitX = Math.cos(startAngle);
  13783. var unitY = Math.sin(startAngle);
  13784. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  13785. ctx.lineTo(unitX * r + x, unitY * r + y);
  13786. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13787. ctx.lineTo(
  13788. Math.cos(endAngle) * r0 + x,
  13789. Math.sin(endAngle) * r0 + y
  13790. );
  13791. if (r0 !== 0) {
  13792. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  13793. }
  13794. ctx.closePath();
  13795. }
  13796. });
  13797. /**
  13798. * 圆环
  13799. * @module zrender/graphic/shape/Ring
  13800. */
  13801. var Ring = Path.extend({
  13802. type: 'ring',
  13803. shape: {
  13804. cx: 0,
  13805. cy: 0,
  13806. r: 0,
  13807. r0: 0
  13808. },
  13809. buildPath: function (ctx, shape) {
  13810. var x = shape.cx;
  13811. var y = shape.cy;
  13812. var PI2 = Math.PI * 2;
  13813. ctx.moveTo(x + shape.r, y);
  13814. ctx.arc(x, y, shape.r, 0, PI2, false);
  13815. ctx.moveTo(x + shape.r0, y);
  13816. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13817. }
  13818. });
  13819. /**
  13820. * Catmull-Rom spline 插值折线
  13821. * @module zrender/shape/util/smoothSpline
  13822. * @author pissang (https://www.github.com/pissang)
  13823. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13824. * errorrik (errorrik@gmail.com)
  13825. */
  13826. /**
  13827. * @inner
  13828. */
  13829. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  13830. var v0 = (p2 - p0) * 0.5;
  13831. var v1 = (p3 - p1) * 0.5;
  13832. return (2 * (p1 - p2) + v0 + v1) * t3
  13833. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  13834. + v0 * t + p1;
  13835. }
  13836. /**
  13837. * @alias module:zrender/shape/util/smoothSpline
  13838. * @param {Array} points 线段顶点数组
  13839. * @param {boolean} isLoop
  13840. * @return {Array}
  13841. */
  13842. var smoothSpline = function (points, isLoop) {
  13843. var len$$1 = points.length;
  13844. var ret = [];
  13845. var distance$$1 = 0;
  13846. for (var i = 1; i < len$$1; i++) {
  13847. distance$$1 += distance(points[i - 1], points[i]);
  13848. }
  13849. var segs = distance$$1 / 2;
  13850. segs = segs < len$$1 ? len$$1 : segs;
  13851. for (var i = 0; i < segs; i++) {
  13852. var pos = i / (segs - 1) * (isLoop ? len$$1 : len$$1 - 1);
  13853. var idx = Math.floor(pos);
  13854. var w = pos - idx;
  13855. var p0;
  13856. var p1 = points[idx % len$$1];
  13857. var p2;
  13858. var p3;
  13859. if (!isLoop) {
  13860. p0 = points[idx === 0 ? idx : idx - 1];
  13861. p2 = points[idx > len$$1 - 2 ? len$$1 - 1 : idx + 1];
  13862. p3 = points[idx > len$$1 - 3 ? len$$1 - 1 : idx + 2];
  13863. }
  13864. else {
  13865. p0 = points[(idx - 1 + len$$1) % len$$1];
  13866. p2 = points[(idx + 1) % len$$1];
  13867. p3 = points[(idx + 2) % len$$1];
  13868. }
  13869. var w2 = w * w;
  13870. var w3 = w * w2;
  13871. ret.push([
  13872. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  13873. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  13874. ]);
  13875. }
  13876. return ret;
  13877. };
  13878. /**
  13879. * 贝塞尔平滑曲线
  13880. * @module zrender/shape/util/smoothBezier
  13881. * @author pissang (https://www.github.com/pissang)
  13882. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13883. * errorrik (errorrik@gmail.com)
  13884. */
  13885. /**
  13886. * 贝塞尔平滑曲线
  13887. * @alias module:zrender/shape/util/smoothBezier
  13888. * @param {Array} points 线段顶点数组
  13889. * @param {number} smooth 平滑等级, 0-1
  13890. * @param {boolean} isLoop
  13891. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  13892. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  13893. * 整个折线的包围盒做一个并集用来约束控制点。
  13894. * @param {Array} 计算出来的控制点数组
  13895. */
  13896. var smoothBezier = function (points, smooth, isLoop, constraint) {
  13897. var cps = [];
  13898. var v = [];
  13899. var v1 = [];
  13900. var v2 = [];
  13901. var prevPoint;
  13902. var nextPoint;
  13903. var min$$1;
  13904. var max$$1;
  13905. if (constraint) {
  13906. min$$1 = [Infinity, Infinity];
  13907. max$$1 = [-Infinity, -Infinity];
  13908. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13909. min(min$$1, min$$1, points[i]);
  13910. max(max$$1, max$$1, points[i]);
  13911. }
  13912. // 与指定的包围盒做并集
  13913. min(min$$1, min$$1, constraint[0]);
  13914. max(max$$1, max$$1, constraint[1]);
  13915. }
  13916. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13917. var point = points[i];
  13918. if (isLoop) {
  13919. prevPoint = points[i ? i - 1 : len$$1 - 1];
  13920. nextPoint = points[(i + 1) % len$$1];
  13921. }
  13922. else {
  13923. if (i === 0 || i === len$$1 - 1) {
  13924. cps.push(clone$1(points[i]));
  13925. continue;
  13926. }
  13927. else {
  13928. prevPoint = points[i - 1];
  13929. nextPoint = points[i + 1];
  13930. }
  13931. }
  13932. sub(v, nextPoint, prevPoint);
  13933. // use degree to scale the handle length
  13934. scale(v, v, smooth);
  13935. var d0 = distance(point, prevPoint);
  13936. var d1 = distance(point, nextPoint);
  13937. var sum = d0 + d1;
  13938. if (sum !== 0) {
  13939. d0 /= sum;
  13940. d1 /= sum;
  13941. }
  13942. scale(v1, v, -d0);
  13943. scale(v2, v, d1);
  13944. var cp0 = add([], point, v1);
  13945. var cp1 = add([], point, v2);
  13946. if (constraint) {
  13947. max(cp0, cp0, min$$1);
  13948. min(cp0, cp0, max$$1);
  13949. max(cp1, cp1, min$$1);
  13950. min(cp1, cp1, max$$1);
  13951. }
  13952. cps.push(cp0);
  13953. cps.push(cp1);
  13954. }
  13955. if (isLoop) {
  13956. cps.push(cps.shift());
  13957. }
  13958. return cps;
  13959. };
  13960. function buildPath$1(ctx, shape, closePath) {
  13961. var points = shape.points;
  13962. var smooth = shape.smooth;
  13963. if (points && points.length >= 2) {
  13964. if (smooth && smooth !== 'spline') {
  13965. var controlPoints = smoothBezier(
  13966. points, smooth, closePath, shape.smoothConstraint
  13967. );
  13968. ctx.moveTo(points[0][0], points[0][1]);
  13969. var len = points.length;
  13970. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13971. var cp1 = controlPoints[i * 2];
  13972. var cp2 = controlPoints[i * 2 + 1];
  13973. var p = points[(i + 1) % len];
  13974. ctx.bezierCurveTo(
  13975. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  13976. );
  13977. }
  13978. }
  13979. else {
  13980. if (smooth === 'spline') {
  13981. points = smoothSpline(points, closePath);
  13982. }
  13983. ctx.moveTo(points[0][0], points[0][1]);
  13984. for (var i = 1, l = points.length; i < l; i++) {
  13985. ctx.lineTo(points[i][0], points[i][1]);
  13986. }
  13987. }
  13988. closePath && ctx.closePath();
  13989. }
  13990. }
  13991. /**
  13992. * 多边形
  13993. * @module zrender/shape/Polygon
  13994. */
  13995. var Polygon = Path.extend({
  13996. type: 'polygon',
  13997. shape: {
  13998. points: null,
  13999. smooth: false,
  14000. smoothConstraint: null
  14001. },
  14002. buildPath: function (ctx, shape) {
  14003. buildPath$1(ctx, shape, true);
  14004. }
  14005. });
  14006. /**
  14007. * @module zrender/graphic/shape/Polyline
  14008. */
  14009. var Polyline = Path.extend({
  14010. type: 'polyline',
  14011. shape: {
  14012. points: null,
  14013. smooth: false,
  14014. smoothConstraint: null
  14015. },
  14016. style: {
  14017. stroke: '#000',
  14018. fill: null
  14019. },
  14020. buildPath: function (ctx, shape) {
  14021. buildPath$1(ctx, shape, false);
  14022. }
  14023. });
  14024. /**
  14025. * Sub-pixel optimize for canvas rendering, prevent from blur
  14026. * when rendering a thin vertical/horizontal line.
  14027. */
  14028. var round = Math.round;
  14029. /**
  14030. * Sub pixel optimize line for canvas
  14031. *
  14032. * @param {Object} outputShape The modification will be performed on `outputShape`.
  14033. * `outputShape` and `inputShape` can be the same object.
  14034. * `outputShape` object can be used repeatly, because all of
  14035. * the `x1`, `x2`, `y1`, `y2` will be assigned in this method.
  14036. * @param {Object} [inputShape]
  14037. * @param {number} [inputShape.x1]
  14038. * @param {number} [inputShape.y1]
  14039. * @param {number} [inputShape.x2]
  14040. * @param {number} [inputShape.y2]
  14041. * @param {Object} [style]
  14042. * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.
  14043. */
  14044. function subPixelOptimizeLine$1(outputShape, inputShape, style) {
  14045. if (!inputShape) {
  14046. return;
  14047. }
  14048. var x1 = inputShape.x1;
  14049. var x2 = inputShape.x2;
  14050. var y1 = inputShape.y1;
  14051. var y2 = inputShape.y2;
  14052. outputShape.x1 = x1;
  14053. outputShape.x2 = x2;
  14054. outputShape.y1 = y1;
  14055. outputShape.y2 = y2;
  14056. var lineWidth = style && style.lineWidth;
  14057. if (!lineWidth) {
  14058. return;
  14059. }
  14060. if (round(x1 * 2) === round(x2 * 2)) {
  14061. outputShape.x1 = outputShape.x2 = subPixelOptimize$1(x1, lineWidth, true);
  14062. }
  14063. if (round(y1 * 2) === round(y2 * 2)) {
  14064. outputShape.y1 = outputShape.y2 = subPixelOptimize$1(y1, lineWidth, true);
  14065. }
  14066. }
  14067. /**
  14068. * Sub pixel optimize rect for canvas
  14069. *
  14070. * @param {Object} outputShape The modification will be performed on `outputShape`.
  14071. * `outputShape` and `inputShape` can be the same object.
  14072. * `outputShape` object can be used repeatly, because all of
  14073. * the `x`, `y`, `width`, `height` will be assigned in this method.
  14074. * @param {Object} [inputShape]
  14075. * @param {number} [inputShape.x]
  14076. * @param {number} [inputShape.y]
  14077. * @param {number} [inputShape.width]
  14078. * @param {number} [inputShape.height]
  14079. * @param {Object} [style]
  14080. * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.
  14081. */
  14082. function subPixelOptimizeRect$1(outputShape, inputShape, style) {
  14083. if (!inputShape) {
  14084. return;
  14085. }
  14086. var originX = inputShape.x;
  14087. var originY = inputShape.y;
  14088. var originWidth = inputShape.width;
  14089. var originHeight = inputShape.height;
  14090. outputShape.x = originX;
  14091. outputShape.y = originY;
  14092. outputShape.width = originWidth;
  14093. outputShape.height = originHeight;
  14094. var lineWidth = style && style.lineWidth;
  14095. if (!lineWidth) {
  14096. return;
  14097. }
  14098. outputShape.x = subPixelOptimize$1(originX, lineWidth, true);
  14099. outputShape.y = subPixelOptimize$1(originY, lineWidth, true);
  14100. outputShape.width = Math.max(
  14101. subPixelOptimize$1(originX + originWidth, lineWidth, false) - outputShape.x,
  14102. originWidth === 0 ? 0 : 1
  14103. );
  14104. outputShape.height = Math.max(
  14105. subPixelOptimize$1(originY + originHeight, lineWidth, false) - outputShape.y,
  14106. originHeight === 0 ? 0 : 1
  14107. );
  14108. }
  14109. /**
  14110. * Sub pixel optimize for canvas
  14111. *
  14112. * @param {number} position Coordinate, such as x, y
  14113. * @param {number} lineWidth If `null`/`undefined`/`0`, do not optimize.
  14114. * @param {boolean=} positiveOrNegative Default false (negative).
  14115. * @return {number} Optimized position.
  14116. */
  14117. function subPixelOptimize$1(position, lineWidth, positiveOrNegative) {
  14118. if (!lineWidth) {
  14119. return position;
  14120. }
  14121. // Assure that (position + lineWidth / 2) is near integer edge,
  14122. // otherwise line will be fuzzy in canvas.
  14123. var doubledPosition = round(position * 2);
  14124. return (doubledPosition + round(lineWidth)) % 2 === 0
  14125. ? doubledPosition / 2
  14126. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  14127. }
  14128. /**
  14129. * 矩形
  14130. * @module zrender/graphic/shape/Rect
  14131. */
  14132. // Avoid create repeatly.
  14133. var subPixelOptimizeOutputShape = {};
  14134. var Rect = Path.extend({
  14135. type: 'rect',
  14136. shape: {
  14137. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  14138. // r缩写为1 相当于 [1, 1, 1, 1]
  14139. // r缩写为[1] 相当于 [1, 1, 1, 1]
  14140. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  14141. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  14142. r: 0,
  14143. x: 0,
  14144. y: 0,
  14145. width: 0,
  14146. height: 0
  14147. },
  14148. buildPath: function (ctx, shape) {
  14149. var x;
  14150. var y;
  14151. var width;
  14152. var height;
  14153. if (this.subPixelOptimize) {
  14154. subPixelOptimizeRect$1(subPixelOptimizeOutputShape, shape, this.style);
  14155. x = subPixelOptimizeOutputShape.x;
  14156. y = subPixelOptimizeOutputShape.y;
  14157. width = subPixelOptimizeOutputShape.width;
  14158. height = subPixelOptimizeOutputShape.height;
  14159. subPixelOptimizeOutputShape.r = shape.r;
  14160. shape = subPixelOptimizeOutputShape;
  14161. }
  14162. else {
  14163. x = shape.x;
  14164. y = shape.y;
  14165. width = shape.width;
  14166. height = shape.height;
  14167. }
  14168. if (!shape.r) {
  14169. ctx.rect(x, y, width, height);
  14170. }
  14171. else {
  14172. buildPath(ctx, shape);
  14173. }
  14174. ctx.closePath();
  14175. return;
  14176. }
  14177. });
  14178. /**
  14179. * 直线
  14180. * @module zrender/graphic/shape/Line
  14181. */
  14182. // Avoid create repeatly.
  14183. var subPixelOptimizeOutputShape$1 = {};
  14184. var Line = Path.extend({
  14185. type: 'line',
  14186. shape: {
  14187. // Start point
  14188. x1: 0,
  14189. y1: 0,
  14190. // End point
  14191. x2: 0,
  14192. y2: 0,
  14193. percent: 1
  14194. },
  14195. style: {
  14196. stroke: '#000',
  14197. fill: null
  14198. },
  14199. buildPath: function (ctx, shape) {
  14200. var x1;
  14201. var y1;
  14202. var x2;
  14203. var y2;
  14204. if (this.subPixelOptimize) {
  14205. subPixelOptimizeLine$1(subPixelOptimizeOutputShape$1, shape, this.style);
  14206. x1 = subPixelOptimizeOutputShape$1.x1;
  14207. y1 = subPixelOptimizeOutputShape$1.y1;
  14208. x2 = subPixelOptimizeOutputShape$1.x2;
  14209. y2 = subPixelOptimizeOutputShape$1.y2;
  14210. }
  14211. else {
  14212. x1 = shape.x1;
  14213. y1 = shape.y1;
  14214. x2 = shape.x2;
  14215. y2 = shape.y2;
  14216. }
  14217. var percent = shape.percent;
  14218. if (percent === 0) {
  14219. return;
  14220. }
  14221. ctx.moveTo(x1, y1);
  14222. if (percent < 1) {
  14223. x2 = x1 * (1 - percent) + x2 * percent;
  14224. y2 = y1 * (1 - percent) + y2 * percent;
  14225. }
  14226. ctx.lineTo(x2, y2);
  14227. },
  14228. /**
  14229. * Get point at percent
  14230. * @param {number} percent
  14231. * @return {Array.<number>}
  14232. */
  14233. pointAt: function (p) {
  14234. var shape = this.shape;
  14235. return [
  14236. shape.x1 * (1 - p) + shape.x2 * p,
  14237. shape.y1 * (1 - p) + shape.y2 * p
  14238. ];
  14239. }
  14240. });
  14241. /**
  14242. * 贝塞尔曲线
  14243. * @module zrender/shape/BezierCurve
  14244. */
  14245. var out = [];
  14246. function someVectorAt(shape, t, isTangent) {
  14247. var cpx2 = shape.cpx2;
  14248. var cpy2 = shape.cpy2;
  14249. if (cpx2 === null || cpy2 === null) {
  14250. return [
  14251. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  14252. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  14253. ];
  14254. }
  14255. else {
  14256. return [
  14257. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  14258. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  14259. ];
  14260. }
  14261. }
  14262. var BezierCurve = Path.extend({
  14263. type: 'bezier-curve',
  14264. shape: {
  14265. x1: 0,
  14266. y1: 0,
  14267. x2: 0,
  14268. y2: 0,
  14269. cpx1: 0,
  14270. cpy1: 0,
  14271. // cpx2: 0,
  14272. // cpy2: 0
  14273. // Curve show percent, for animating
  14274. percent: 1
  14275. },
  14276. style: {
  14277. stroke: '#000',
  14278. fill: null
  14279. },
  14280. buildPath: function (ctx, shape) {
  14281. var x1 = shape.x1;
  14282. var y1 = shape.y1;
  14283. var x2 = shape.x2;
  14284. var y2 = shape.y2;
  14285. var cpx1 = shape.cpx1;
  14286. var cpy1 = shape.cpy1;
  14287. var cpx2 = shape.cpx2;
  14288. var cpy2 = shape.cpy2;
  14289. var percent = shape.percent;
  14290. if (percent === 0) {
  14291. return;
  14292. }
  14293. ctx.moveTo(x1, y1);
  14294. if (cpx2 == null || cpy2 == null) {
  14295. if (percent < 1) {
  14296. quadraticSubdivide(
  14297. x1, cpx1, x2, percent, out
  14298. );
  14299. cpx1 = out[1];
  14300. x2 = out[2];
  14301. quadraticSubdivide(
  14302. y1, cpy1, y2, percent, out
  14303. );
  14304. cpy1 = out[1];
  14305. y2 = out[2];
  14306. }
  14307. ctx.quadraticCurveTo(
  14308. cpx1, cpy1,
  14309. x2, y2
  14310. );
  14311. }
  14312. else {
  14313. if (percent < 1) {
  14314. cubicSubdivide(
  14315. x1, cpx1, cpx2, x2, percent, out
  14316. );
  14317. cpx1 = out[1];
  14318. cpx2 = out[2];
  14319. x2 = out[3];
  14320. cubicSubdivide(
  14321. y1, cpy1, cpy2, y2, percent, out
  14322. );
  14323. cpy1 = out[1];
  14324. cpy2 = out[2];
  14325. y2 = out[3];
  14326. }
  14327. ctx.bezierCurveTo(
  14328. cpx1, cpy1,
  14329. cpx2, cpy2,
  14330. x2, y2
  14331. );
  14332. }
  14333. },
  14334. /**
  14335. * Get point at percent
  14336. * @param {number} t
  14337. * @return {Array.<number>}
  14338. */
  14339. pointAt: function (t) {
  14340. return someVectorAt(this.shape, t, false);
  14341. },
  14342. /**
  14343. * Get tangent at percent
  14344. * @param {number} t
  14345. * @return {Array.<number>}
  14346. */
  14347. tangentAt: function (t) {
  14348. var p = someVectorAt(this.shape, t, true);
  14349. return normalize(p, p);
  14350. }
  14351. });
  14352. /**
  14353. * 圆弧
  14354. * @module zrender/graphic/shape/Arc
  14355. */
  14356. var Arc = Path.extend({
  14357. type: 'arc',
  14358. shape: {
  14359. cx: 0,
  14360. cy: 0,
  14361. r: 0,
  14362. startAngle: 0,
  14363. endAngle: Math.PI * 2,
  14364. clockwise: true
  14365. },
  14366. style: {
  14367. stroke: '#000',
  14368. fill: null
  14369. },
  14370. buildPath: function (ctx, shape) {
  14371. var x = shape.cx;
  14372. var y = shape.cy;
  14373. var r = Math.max(shape.r, 0);
  14374. var startAngle = shape.startAngle;
  14375. var endAngle = shape.endAngle;
  14376. var clockwise = shape.clockwise;
  14377. var unitX = Math.cos(startAngle);
  14378. var unitY = Math.sin(startAngle);
  14379. ctx.moveTo(unitX * r + x, unitY * r + y);
  14380. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14381. }
  14382. });
  14383. // CompoundPath to improve performance
  14384. var CompoundPath = Path.extend({
  14385. type: 'compound',
  14386. shape: {
  14387. paths: null
  14388. },
  14389. _updatePathDirty: function () {
  14390. var dirtyPath = this.__dirtyPath;
  14391. var paths = this.shape.paths;
  14392. for (var i = 0; i < paths.length; i++) {
  14393. // Mark as dirty if any subpath is dirty
  14394. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  14395. }
  14396. this.__dirtyPath = dirtyPath;
  14397. this.__dirty = this.__dirty || dirtyPath;
  14398. },
  14399. beforeBrush: function () {
  14400. this._updatePathDirty();
  14401. var paths = this.shape.paths || [];
  14402. var scale = this.getGlobalScale();
  14403. // Update path scale
  14404. for (var i = 0; i < paths.length; i++) {
  14405. if (!paths[i].path) {
  14406. paths[i].createPathProxy();
  14407. }
  14408. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  14409. }
  14410. },
  14411. buildPath: function (ctx, shape) {
  14412. var paths = shape.paths || [];
  14413. for (var i = 0; i < paths.length; i++) {
  14414. paths[i].buildPath(ctx, paths[i].shape, true);
  14415. }
  14416. },
  14417. afterBrush: function () {
  14418. var paths = this.shape.paths || [];
  14419. for (var i = 0; i < paths.length; i++) {
  14420. paths[i].__dirtyPath = false;
  14421. }
  14422. },
  14423. getBoundingRect: function () {
  14424. this._updatePathDirty();
  14425. return Path.prototype.getBoundingRect.call(this);
  14426. }
  14427. });
  14428. /**
  14429. * @param {Array.<Object>} colorStops
  14430. */
  14431. var Gradient = function (colorStops) {
  14432. this.colorStops = colorStops || [];
  14433. };
  14434. Gradient.prototype = {
  14435. constructor: Gradient,
  14436. addColorStop: function (offset, color) {
  14437. this.colorStops.push({
  14438. offset: offset,
  14439. color: color
  14440. });
  14441. }
  14442. };
  14443. /**
  14444. * x, y, x2, y2 are all percent from 0 to 1
  14445. * @param {number} [x=0]
  14446. * @param {number} [y=0]
  14447. * @param {number} [x2=1]
  14448. * @param {number} [y2=0]
  14449. * @param {Array.<Object>} colorStops
  14450. * @param {boolean} [globalCoord=false]
  14451. */
  14452. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  14453. // Should do nothing more in this constructor. Because gradient can be
  14454. // declard by `color: {type: 'linear', colorStops: ...}`, where
  14455. // this constructor will not be called.
  14456. this.x = x == null ? 0 : x;
  14457. this.y = y == null ? 0 : y;
  14458. this.x2 = x2 == null ? 1 : x2;
  14459. this.y2 = y2 == null ? 0 : y2;
  14460. // Can be cloned
  14461. this.type = 'linear';
  14462. // If use global coord
  14463. this.global = globalCoord || false;
  14464. Gradient.call(this, colorStops);
  14465. };
  14466. LinearGradient.prototype = {
  14467. constructor: LinearGradient
  14468. };
  14469. inherits(LinearGradient, Gradient);
  14470. /**
  14471. * x, y, r are all percent from 0 to 1
  14472. * @param {number} [x=0.5]
  14473. * @param {number} [y=0.5]
  14474. * @param {number} [r=0.5]
  14475. * @param {Array.<Object>} [colorStops]
  14476. * @param {boolean} [globalCoord=false]
  14477. */
  14478. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  14479. // Should do nothing more in this constructor. Because gradient can be
  14480. // declard by `color: {type: 'radial', colorStops: ...}`, where
  14481. // this constructor will not be called.
  14482. this.x = x == null ? 0.5 : x;
  14483. this.y = y == null ? 0.5 : y;
  14484. this.r = r == null ? 0.5 : r;
  14485. // Can be cloned
  14486. this.type = 'radial';
  14487. // If use global coord
  14488. this.global = globalCoord || false;
  14489. Gradient.call(this, colorStops);
  14490. };
  14491. RadialGradient.prototype = {
  14492. constructor: RadialGradient
  14493. };
  14494. inherits(RadialGradient, Gradient);
  14495. /**
  14496. * Displayable for incremental rendering. It will be rendered in a separate layer
  14497. * IncrementalDisplay have two main methods. `clearDisplayables` and `addDisplayables`
  14498. * addDisplayables will render the added displayables incremetally.
  14499. *
  14500. * It use a not clearFlag to tell the painter don't clear the layer if it's the first element.
  14501. */
  14502. // TODO Style override ?
  14503. function IncrementalDisplayble(opts) {
  14504. Displayable.call(this, opts);
  14505. this._displayables = [];
  14506. this._temporaryDisplayables = [];
  14507. this._cursor = 0;
  14508. this.notClear = true;
  14509. }
  14510. IncrementalDisplayble.prototype.incremental = true;
  14511. IncrementalDisplayble.prototype.clearDisplaybles = function () {
  14512. this._displayables = [];
  14513. this._temporaryDisplayables = [];
  14514. this._cursor = 0;
  14515. this.dirty();
  14516. this.notClear = false;
  14517. };
  14518. IncrementalDisplayble.prototype.addDisplayable = function (displayable, notPersistent) {
  14519. if (notPersistent) {
  14520. this._temporaryDisplayables.push(displayable);
  14521. }
  14522. else {
  14523. this._displayables.push(displayable);
  14524. }
  14525. this.dirty();
  14526. };
  14527. IncrementalDisplayble.prototype.addDisplayables = function (displayables, notPersistent) {
  14528. notPersistent = notPersistent || false;
  14529. for (var i = 0; i < displayables.length; i++) {
  14530. this.addDisplayable(displayables[i], notPersistent);
  14531. }
  14532. };
  14533. IncrementalDisplayble.prototype.eachPendingDisplayable = function (cb) {
  14534. for (var i = this._cursor; i < this._displayables.length; i++) {
  14535. cb && cb(this._displayables[i]);
  14536. }
  14537. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14538. cb && cb(this._temporaryDisplayables[i]);
  14539. }
  14540. };
  14541. IncrementalDisplayble.prototype.update = function () {
  14542. this.updateTransform();
  14543. for (var i = this._cursor; i < this._displayables.length; i++) {
  14544. var displayable = this._displayables[i];
  14545. // PENDING
  14546. displayable.parent = this;
  14547. displayable.update();
  14548. displayable.parent = null;
  14549. }
  14550. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14551. var displayable = this._temporaryDisplayables[i];
  14552. // PENDING
  14553. displayable.parent = this;
  14554. displayable.update();
  14555. displayable.parent = null;
  14556. }
  14557. };
  14558. IncrementalDisplayble.prototype.brush = function (ctx, prevEl) {
  14559. // Render persistant displayables.
  14560. for (var i = this._cursor; i < this._displayables.length; i++) {
  14561. var displayable = this._displayables[i];
  14562. displayable.beforeBrush && displayable.beforeBrush(ctx);
  14563. displayable.brush(ctx, i === this._cursor ? null : this._displayables[i - 1]);
  14564. displayable.afterBrush && displayable.afterBrush(ctx);
  14565. }
  14566. this._cursor = i;
  14567. // Render temporary displayables.
  14568. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14569. var displayable = this._temporaryDisplayables[i];
  14570. displayable.beforeBrush && displayable.beforeBrush(ctx);
  14571. displayable.brush(ctx, i === 0 ? null : this._temporaryDisplayables[i - 1]);
  14572. displayable.afterBrush && displayable.afterBrush(ctx);
  14573. }
  14574. this._temporaryDisplayables = [];
  14575. this.notClear = true;
  14576. };
  14577. var m = [];
  14578. IncrementalDisplayble.prototype.getBoundingRect = function () {
  14579. if (!this._rect) {
  14580. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  14581. for (var i = 0; i < this._displayables.length; i++) {
  14582. var displayable = this._displayables[i];
  14583. var childRect = displayable.getBoundingRect().clone();
  14584. if (displayable.needLocalTransform()) {
  14585. childRect.applyTransform(displayable.getLocalTransform(m));
  14586. }
  14587. rect.union(childRect);
  14588. }
  14589. this._rect = rect;
  14590. }
  14591. return this._rect;
  14592. };
  14593. IncrementalDisplayble.prototype.contain = function (x, y) {
  14594. var localPos = this.transformCoordToLocal(x, y);
  14595. var rect = this.getBoundingRect();
  14596. if (rect.contain(localPos[0], localPos[1])) {
  14597. for (var i = 0; i < this._displayables.length; i++) {
  14598. var displayable = this._displayables[i];
  14599. if (displayable.contain(x, y)) {
  14600. return true;
  14601. }
  14602. }
  14603. }
  14604. return false;
  14605. };
  14606. inherits(IncrementalDisplayble, Displayable);
  14607. /*
  14608. * Licensed to the Apache Software Foundation (ASF) under one
  14609. * or more contributor license agreements. See the NOTICE file
  14610. * distributed with this work for additional information
  14611. * regarding copyright ownership. The ASF licenses this file
  14612. * to you under the Apache License, Version 2.0 (the
  14613. * "License"); you may not use this file except in compliance
  14614. * with the License. You may obtain a copy of the License at
  14615. *
  14616. * http://www.apache.org/licenses/LICENSE-2.0
  14617. *
  14618. * Unless required by applicable law or agreed to in writing,
  14619. * software distributed under the License is distributed on an
  14620. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14621. * KIND, either express or implied. See the License for the
  14622. * specific language governing permissions and limitations
  14623. * under the License.
  14624. */
  14625. var mathMax$1 = Math.max;
  14626. var mathMin$1 = Math.min;
  14627. var EMPTY_OBJ = {};
  14628. var Z2_EMPHASIS_LIFT = 1;
  14629. // key: label model property nane, value: style property name.
  14630. var CACHED_LABEL_STYLE_PROPERTIES = {
  14631. color: 'textFill',
  14632. textBorderColor: 'textStroke',
  14633. textBorderWidth: 'textStrokeWidth'
  14634. };
  14635. var EMPHASIS = 'emphasis';
  14636. var NORMAL = 'normal';
  14637. // Reserve 0 as default.
  14638. var _highlightNextDigit = 1;
  14639. var _highlightKeyMap = {};
  14640. var _customShapeMap = {};
  14641. /**
  14642. * Extend shape with parameters
  14643. */
  14644. function extendShape(opts) {
  14645. return Path.extend(opts);
  14646. }
  14647. /**
  14648. * Extend path
  14649. */
  14650. function extendPath(pathData, opts) {
  14651. return extendFromString(pathData, opts);
  14652. }
  14653. /**
  14654. * Register a user defined shape.
  14655. * The shape class can be fetched by `getShapeClass`
  14656. * This method will overwrite the registered shapes, including
  14657. * the registered built-in shapes, if using the same `name`.
  14658. * The shape can be used in `custom series` and
  14659. * `graphic component` by declaring `{type: name}`.
  14660. *
  14661. * @param {string} name
  14662. * @param {Object} ShapeClass Can be generated by `extendShape`.
  14663. */
  14664. function registerShape(name, ShapeClass) {
  14665. _customShapeMap[name] = ShapeClass;
  14666. }
  14667. /**
  14668. * Find shape class registered by `registerShape`. Usually used in
  14669. * fetching user defined shape.
  14670. *
  14671. * [Caution]:
  14672. * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared
  14673. * to use user registered shapes.
  14674. * Because the built-in shape (see `getBuiltInShape`) will be registered by
  14675. * `registerShape` by default. That enables users to get both built-in
  14676. * shapes as well as the shapes belonging to themsleves. But users can overwrite
  14677. * the built-in shapes by using names like 'circle', 'rect' via calling
  14678. * `registerShape`. So the echarts inner featrues should not fetch shapes from here
  14679. * in case that it is overwritten by users, except that some features, like
  14680. * `custom series`, `graphic component`, do it deliberately.
  14681. *
  14682. * (2) In the features like `custom series`, `graphic component`, the user input
  14683. * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic
  14684. * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names
  14685. * are reserved names, that is, if some user register a shape named `'image'`,
  14686. * the shape will not be used. If we intending to add some more reserved names
  14687. * in feature, that might bring break changes (disable some existing user shape
  14688. * names). But that case probably rearly happen. So we dont make more mechanism
  14689. * to resolve this issue here.
  14690. *
  14691. * @param {string} name
  14692. * @return {Object} The shape class. If not found, return nothing.
  14693. */
  14694. function getShapeClass(name) {
  14695. if (_customShapeMap.hasOwnProperty(name)) {
  14696. return _customShapeMap[name];
  14697. }
  14698. }
  14699. /**
  14700. * Create a path element from path data string
  14701. * @param {string} pathData
  14702. * @param {Object} opts
  14703. * @param {module:zrender/core/BoundingRect} rect
  14704. * @param {string} [layout=cover] 'center' or 'cover'
  14705. */
  14706. function makePath(pathData, opts, rect, layout) {
  14707. var path = createFromString(pathData, opts);
  14708. if (rect) {
  14709. if (layout === 'center') {
  14710. rect = centerGraphic(rect, path.getBoundingRect());
  14711. }
  14712. resizePath(path, rect);
  14713. }
  14714. return path;
  14715. }
  14716. /**
  14717. * Create a image element from image url
  14718. * @param {string} imageUrl image url
  14719. * @param {Object} opts options
  14720. * @param {module:zrender/core/BoundingRect} rect constrain rect
  14721. * @param {string} [layout=cover] 'center' or 'cover'
  14722. */
  14723. function makeImage(imageUrl, rect, layout) {
  14724. var path = new ZImage({
  14725. style: {
  14726. image: imageUrl,
  14727. x: rect.x,
  14728. y: rect.y,
  14729. width: rect.width,
  14730. height: rect.height
  14731. },
  14732. onload: function (img) {
  14733. if (layout === 'center') {
  14734. var boundingRect = {
  14735. width: img.width,
  14736. height: img.height
  14737. };
  14738. path.setStyle(centerGraphic(rect, boundingRect));
  14739. }
  14740. }
  14741. });
  14742. return path;
  14743. }
  14744. /**
  14745. * Get position of centered element in bounding box.
  14746. *
  14747. * @param {Object} rect element local bounding box
  14748. * @param {Object} boundingRect constraint bounding box
  14749. * @return {Object} element position containing x, y, width, and height
  14750. */
  14751. function centerGraphic(rect, boundingRect) {
  14752. // Set rect to center, keep width / height ratio.
  14753. var aspect = boundingRect.width / boundingRect.height;
  14754. var width = rect.height * aspect;
  14755. var height;
  14756. if (width <= rect.width) {
  14757. height = rect.height;
  14758. }
  14759. else {
  14760. width = rect.width;
  14761. height = width / aspect;
  14762. }
  14763. var cx = rect.x + rect.width / 2;
  14764. var cy = rect.y + rect.height / 2;
  14765. return {
  14766. x: cx - width / 2,
  14767. y: cy - height / 2,
  14768. width: width,
  14769. height: height
  14770. };
  14771. }
  14772. var mergePath = mergePath$1;
  14773. /**
  14774. * Resize a path to fit the rect
  14775. * @param {module:zrender/graphic/Path} path
  14776. * @param {Object} rect
  14777. */
  14778. function resizePath(path, rect) {
  14779. if (!path.applyTransform) {
  14780. return;
  14781. }
  14782. var pathRect = path.getBoundingRect();
  14783. var m = pathRect.calculateTransform(rect);
  14784. path.applyTransform(m);
  14785. }
  14786. /**
  14787. * Sub pixel optimize line for canvas
  14788. *
  14789. * @param {Object} param
  14790. * @param {Object} [param.shape]
  14791. * @param {number} [param.shape.x1]
  14792. * @param {number} [param.shape.y1]
  14793. * @param {number} [param.shape.x2]
  14794. * @param {number} [param.shape.y2]
  14795. * @param {Object} [param.style]
  14796. * @param {number} [param.style.lineWidth]
  14797. * @return {Object} Modified param
  14798. */
  14799. function subPixelOptimizeLine(param) {
  14800. subPixelOptimizeLine$1(param.shape, param.shape, param.style);
  14801. return param;
  14802. }
  14803. /**
  14804. * Sub pixel optimize rect for canvas
  14805. *
  14806. * @param {Object} param
  14807. * @param {Object} [param.shape]
  14808. * @param {number} [param.shape.x]
  14809. * @param {number} [param.shape.y]
  14810. * @param {number} [param.shape.width]
  14811. * @param {number} [param.shape.height]
  14812. * @param {Object} [param.style]
  14813. * @param {number} [param.style.lineWidth]
  14814. * @return {Object} Modified param
  14815. */
  14816. function subPixelOptimizeRect(param) {
  14817. subPixelOptimizeRect$1(param.shape, param.shape, param.style);
  14818. return param;
  14819. }
  14820. /**
  14821. * Sub pixel optimize for canvas
  14822. *
  14823. * @param {number} position Coordinate, such as x, y
  14824. * @param {number} lineWidth Should be nonnegative integer.
  14825. * @param {boolean=} positiveOrNegative Default false (negative).
  14826. * @return {number} Optimized position.
  14827. */
  14828. var subPixelOptimize = subPixelOptimize$1;
  14829. function hasFillOrStroke(fillOrStroke) {
  14830. return fillOrStroke != null && fillOrStroke !== 'none';
  14831. }
  14832. // Most lifted color are duplicated.
  14833. var liftedColorMap = createHashMap();
  14834. var liftedColorCount = 0;
  14835. function liftColor(color) {
  14836. if (typeof color !== 'string') {
  14837. return color;
  14838. }
  14839. var liftedColor = liftedColorMap.get(color);
  14840. if (!liftedColor) {
  14841. liftedColor = lift(color, -0.1);
  14842. if (liftedColorCount < 10000) {
  14843. liftedColorMap.set(color, liftedColor);
  14844. liftedColorCount++;
  14845. }
  14846. }
  14847. return liftedColor;
  14848. }
  14849. function cacheElementStl(el) {
  14850. if (!el.__hoverStlDirty) {
  14851. return;
  14852. }
  14853. el.__hoverStlDirty = false;
  14854. var hoverStyle = el.__hoverStl;
  14855. if (!hoverStyle) {
  14856. el.__cachedNormalStl = el.__cachedNormalZ2 = null;
  14857. return;
  14858. }
  14859. var normalStyle = el.__cachedNormalStl = {};
  14860. el.__cachedNormalZ2 = el.z2;
  14861. var elStyle = el.style;
  14862. for (var name in hoverStyle) {
  14863. // See comment in `singleEnterEmphasis`.
  14864. if (hoverStyle[name] != null) {
  14865. normalStyle[name] = elStyle[name];
  14866. }
  14867. }
  14868. // Always cache fill and stroke to normalStyle for lifting color.
  14869. normalStyle.fill = elStyle.fill;
  14870. normalStyle.stroke = elStyle.stroke;
  14871. }
  14872. function singleEnterEmphasis(el) {
  14873. var hoverStl = el.__hoverStl;
  14874. if (!hoverStl || el.__highlighted) {
  14875. return;
  14876. }
  14877. var zr = el.__zr;
  14878. var useHoverLayer = el.useHoverLayer && zr && zr.painter.type === 'canvas';
  14879. el.__highlighted = useHoverLayer ? 'layer' : 'plain';
  14880. if (el.isGroup || (!zr && el.useHoverLayer)) {
  14881. return;
  14882. }
  14883. var elTarget = el;
  14884. var targetStyle = el.style;
  14885. if (useHoverLayer) {
  14886. elTarget = zr.addHover(el);
  14887. targetStyle = elTarget.style;
  14888. }
  14889. rollbackDefaultTextStyle(targetStyle);
  14890. if (!useHoverLayer) {
  14891. cacheElementStl(elTarget);
  14892. }
  14893. // styles can be:
  14894. // {
  14895. // label: {
  14896. // show: false,
  14897. // position: 'outside',
  14898. // fontSize: 18
  14899. // },
  14900. // emphasis: {
  14901. // label: {
  14902. // show: true
  14903. // }
  14904. // }
  14905. // },
  14906. // where properties of `emphasis` may not appear in `normal`. We previously use
  14907. // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.
  14908. // But consider rich text and setOption in merge mode, it is impossible to cover
  14909. // all properties in merge. So we use merge mode when setting style here.
  14910. // But we choose the merge strategy that only properties that is not `null/undefined`.
  14911. // Because when making a textStyle (espacially rich text), it is not easy to distinguish
  14912. // `hasOwnProperty` and `null/undefined` in code, so we trade them as the same for simplicity.
  14913. // But this strategy brings a trouble that `null/undefined` can not be used to remove
  14914. // style any more in `emphasis`. Users can both set properties directly on normal and
  14915. // emphasis to avoid this issue, or we might support `'none'` for this case if required.
  14916. targetStyle.extendFrom(hoverStl);
  14917. setDefaultHoverFillStroke(targetStyle, hoverStl, 'fill');
  14918. setDefaultHoverFillStroke(targetStyle, hoverStl, 'stroke');
  14919. applyDefaultTextStyle(targetStyle);
  14920. if (!useHoverLayer) {
  14921. el.dirty(false);
  14922. el.z2 += Z2_EMPHASIS_LIFT;
  14923. }
  14924. }
  14925. function setDefaultHoverFillStroke(targetStyle, hoverStyle, prop) {
  14926. if (!hasFillOrStroke(hoverStyle[prop]) && hasFillOrStroke(targetStyle[prop])) {
  14927. targetStyle[prop] = liftColor(targetStyle[prop]);
  14928. }
  14929. }
  14930. function singleEnterNormal(el) {
  14931. var highlighted = el.__highlighted;
  14932. if (!highlighted) {
  14933. return;
  14934. }
  14935. el.__highlighted = false;
  14936. if (el.isGroup) {
  14937. return;
  14938. }
  14939. if (highlighted === 'layer') {
  14940. el.__zr && el.__zr.removeHover(el);
  14941. }
  14942. else {
  14943. var style = el.style;
  14944. var normalStl = el.__cachedNormalStl;
  14945. if (normalStl) {
  14946. rollbackDefaultTextStyle(style);
  14947. el.setStyle(normalStl);
  14948. applyDefaultTextStyle(style);
  14949. }
  14950. // `__cachedNormalZ2` will not be reset if calling `setElementHoverStyle`
  14951. // when `el` is on emphasis state. So here by comparing with 1, we try
  14952. // hard to make the bug case rare.
  14953. var normalZ2 = el.__cachedNormalZ2;
  14954. if (normalZ2 != null && el.z2 - normalZ2 === Z2_EMPHASIS_LIFT) {
  14955. el.z2 = normalZ2;
  14956. }
  14957. }
  14958. }
  14959. function traverseUpdate(el, updater, commonParam) {
  14960. // If root is group, also enter updater for `highDownOnUpdate`.
  14961. var fromState = NORMAL;
  14962. var toState = NORMAL;
  14963. var trigger;
  14964. // See the rule of `highDownOnUpdate` on `graphic.setAsHighDownDispatcher`.
  14965. el.__highlighted && (fromState = EMPHASIS, trigger = true);
  14966. updater(el, commonParam);
  14967. el.__highlighted && (toState = EMPHASIS, trigger = true);
  14968. el.isGroup && el.traverse(function (child) {
  14969. !child.isGroup && updater(child, commonParam);
  14970. });
  14971. trigger && el.__highDownOnUpdate && el.__highDownOnUpdate(fromState, toState);
  14972. }
  14973. /**
  14974. * Set hover style (namely "emphasis style") of element, based on the current
  14975. * style of the given `el`.
  14976. * This method should be called after all of the normal styles have been adopted
  14977. * to the `el`. See the reason on `setHoverStyle`.
  14978. *
  14979. * @param {module:zrender/Element} el Should not be `zrender/container/Group`.
  14980. * @param {Object} [el.hoverStyle] Can be set on el or its descendants,
  14981. * e.g., `el.hoverStyle = ...; graphic.setHoverStyle(el); `.
  14982. * Often used when item group has a label element and it's hoverStyle is different.
  14983. * @param {Object|boolean} [hoverStl] The specified hover style.
  14984. * If set as `false`, disable the hover style.
  14985. * Similarly, The `el.hoverStyle` can alse be set
  14986. * as `false` to disable the hover style.
  14987. * Otherwise, use the default hover style if not provided.
  14988. */
  14989. function setElementHoverStyle(el, hoverStl) {
  14990. // For performance consideration, it might be better to make the "hover style" only the
  14991. // difference properties from the "normal style", but not a entire copy of all styles.
  14992. hoverStl = el.__hoverStl = hoverStl !== false && (el.hoverStyle || hoverStl || {});
  14993. el.__hoverStlDirty = true;
  14994. // FIXME
  14995. // It is not completely right to save "normal"/"emphasis" flag on elements.
  14996. // It probably should be saved on `data` of series. Consider the cases:
  14997. // (1) A highlighted elements are moved out of the view port and re-enter
  14998. // again by dataZoom.
  14999. // (2) call `setOption` and replace elements totally when they are highlighted.
  15000. if (el.__highlighted) {
  15001. // Consider the case:
  15002. // The styles of a highlighted `el` is being updated. The new "emphasis style"
  15003. // should be adapted to the `el`. Notice here new "normal styles" should have
  15004. // been set outside and the cached "normal style" is out of date.
  15005. el.__cachedNormalStl = null;
  15006. // Do not clear `__cachedNormalZ2` here, because setting `z2` is not a constraint
  15007. // of this method. In most cases, `z2` is not set and hover style should be able
  15008. // to rollback. Of course, that would bring bug, but only in a rare case, see
  15009. // `doSingleLeaveHover` for details.
  15010. singleEnterNormal(el);
  15011. singleEnterEmphasis(el);
  15012. }
  15013. }
  15014. function onElementMouseOver(e) {
  15015. !shouldSilent(this, e)
  15016. // "emphasis" event highlight has higher priority than mouse highlight.
  15017. && !this.__highByOuter
  15018. && traverseUpdate(this, singleEnterEmphasis);
  15019. }
  15020. function onElementMouseOut(e) {
  15021. !shouldSilent(this, e)
  15022. // "emphasis" event highlight has higher priority than mouse highlight.
  15023. && !this.__highByOuter
  15024. && traverseUpdate(this, singleEnterNormal);
  15025. }
  15026. function onElementEmphasisEvent(highlightDigit) {
  15027. this.__highByOuter |= 1 << (highlightDigit || 0);
  15028. traverseUpdate(this, singleEnterEmphasis);
  15029. }
  15030. function onElementNormalEvent(highlightDigit) {
  15031. !(this.__highByOuter &= ~(1 << (highlightDigit || 0)))
  15032. && traverseUpdate(this, singleEnterNormal);
  15033. }
  15034. function shouldSilent(el, e) {
  15035. return el.__highDownSilentOnTouch && e.zrByTouch;
  15036. }
  15037. /**
  15038. * Set hover style (namely "emphasis style") of element,
  15039. * based on the current style of the given `el`.
  15040. *
  15041. * (1)
  15042. * **CONSTRAINTS** for this method:
  15043. * <A> This method MUST be called after all of the normal styles having been adopted
  15044. * to the `el`.
  15045. * <B> The input `hoverStyle` (that is, "emphasis style") MUST be the subset of the
  15046. * "normal style" having been set to the el.
  15047. * <C> `color` MUST be one of the "normal styles" (because color might be lifted as
  15048. * a default hover style).
  15049. *
  15050. * The reason: this method treat the current style of the `el` as the "normal style"
  15051. * and cache them when enter/update the "emphasis style". Consider the case: the `el`
  15052. * is in "emphasis" state and `setOption`/`dispatchAction` trigger the style updating
  15053. * logic, where the el should shift from the original emphasis style to the new
  15054. * "emphasis style" and should be able to "downplay" back to the new "normal style".
  15055. *
  15056. * Indeed, it is error-prone to make a interface has so many constraints, but I have
  15057. * not found a better solution yet to fit the backward compatibility, performance and
  15058. * the current programming style.
  15059. *
  15060. * (2)
  15061. * Call the method for a "root" element once. Do not call it for each descendants.
  15062. * If the descendants elemenets of a group has itself hover style different from the
  15063. * root group, we can simply mount the style on `el.hoverStyle` for them, but should
  15064. * not call this method for them.
  15065. *
  15066. * (3) These input parameters can be set directly on `el`:
  15067. *
  15068. * @param {module:zrender/Element} el
  15069. * @param {Object} [el.hoverStyle] See `graphic.setElementHoverStyle`.
  15070. * @param {boolean} [el.highDownSilentOnTouch=false] See `graphic.setAsHighDownDispatcher`.
  15071. * @param {Function} [el.highDownOnUpdate] See `graphic.setAsHighDownDispatcher`.
  15072. * @param {Object|boolean} [hoverStyle] See `graphic.setElementHoverStyle`.
  15073. */
  15074. function setHoverStyle(el, hoverStyle) {
  15075. setAsHighDownDispatcher(el, true);
  15076. traverseUpdate(el, setElementHoverStyle, hoverStyle);
  15077. }
  15078. /**
  15079. * @param {module:zrender/Element} el
  15080. * @param {Function} [el.highDownOnUpdate] Called when state updated.
  15081. * Since `setHoverStyle` has the constraint that it must be called after
  15082. * all of the normal style updated, `highDownOnUpdate` is not needed to
  15083. * trigger if both `fromState` and `toState` is 'normal', and needed to
  15084. * trigger if both `fromState` and `toState` is 'emphasis', which enables
  15085. * to sync outside style settings to "emphasis" state.
  15086. * @this {string} This dispatcher `el`.
  15087. * @param {string} fromState Can be "normal" or "emphasis".
  15088. * `fromState` might equal to `toState`,
  15089. * for example, when this method is called when `el` is
  15090. * on "emphasis" state.
  15091. * @param {string} toState Can be "normal" or "emphasis".
  15092. *
  15093. * FIXME
  15094. * CAUTION: Do not expose `highDownOnUpdate` outside echarts.
  15095. * Because it is not a complete solution. The update
  15096. * listener should not have been mount in element,
  15097. * and the normal/emphasis state should not have
  15098. * mantained on elements.
  15099. *
  15100. * @param {boolean} [el.highDownSilentOnTouch=false]
  15101. * In touch device, mouseover event will be trigger on touchstart event
  15102. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  15103. * conveniently use hoverStyle when tap on touch screen without additional
  15104. * code for compatibility.
  15105. * But if the chart/component has select feature, which usually also use
  15106. * hoverStyle, there might be conflict between 'select-highlight' and
  15107. * 'hover-highlight' especially when roam is enabled (see geo for example).
  15108. * In this case, `highDownSilentOnTouch` should be used to disable
  15109. * hover-highlight on touch device.
  15110. * @param {boolean} [asDispatcher=true] If `false`, do not set as "highDownDispatcher".
  15111. */
  15112. function setAsHighDownDispatcher(el, asDispatcher) {
  15113. var disable = asDispatcher === false;
  15114. // Make `highDownSilentOnTouch` and `highDownOnUpdate` only work after
  15115. // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.
  15116. el.__highDownSilentOnTouch = el.highDownSilentOnTouch;
  15117. el.__highDownOnUpdate = el.highDownOnUpdate;
  15118. // Simple optimize, since this method might be
  15119. // called for each elements of a group in some cases.
  15120. if (!disable || el.__highDownDispatcher) {
  15121. var method = disable ? 'off' : 'on';
  15122. // Duplicated function will be auto-ignored, see Eventful.js.
  15123. el[method]('mouseover', onElementMouseOver)[method]('mouseout', onElementMouseOut);
  15124. // Emphasis, normal can be triggered manually by API or other components like hover link.
  15125. el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent);
  15126. // Also keep previous record.
  15127. el.__highByOuter = el.__highByOuter || 0;
  15128. el.__highDownDispatcher = !disable;
  15129. }
  15130. }
  15131. /**
  15132. * @param {module:zrender/src/Element} el
  15133. * @return {boolean}
  15134. */
  15135. function isHighDownDispatcher(el) {
  15136. return !!(el && el.__highDownDispatcher);
  15137. }
  15138. /**
  15139. * Support hightlight/downplay record on each elements.
  15140. * For the case: hover highlight/downplay (legend, visualMap, ...) and
  15141. * user triggerred hightlight/downplay should not conflict.
  15142. * Only all of the highlightDigit cleared, return to normal.
  15143. * @param {string} highlightKey
  15144. * @return {number} highlightDigit
  15145. */
  15146. function getHighlightDigit(highlightKey) {
  15147. var highlightDigit = _highlightKeyMap[highlightKey];
  15148. if (highlightDigit == null && _highlightNextDigit <= 32) {
  15149. highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;
  15150. }
  15151. return highlightDigit;
  15152. }
  15153. /**
  15154. * See more info in `setTextStyleCommon`.
  15155. * @param {Object|module:zrender/graphic/Style} normalStyle
  15156. * @param {Object} emphasisStyle
  15157. * @param {module:echarts/model/Model} normalModel
  15158. * @param {module:echarts/model/Model} emphasisModel
  15159. * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.
  15160. * @param {string|Function} [opt.defaultText]
  15161. * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by
  15162. * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  15163. * @param {number} [opt.labelDataIndex] Fetch text by
  15164. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  15165. * @param {number} [opt.labelDimIndex] Fetch text by
  15166. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  15167. * @param {string} [opt.labelProp] Fetch text by
  15168. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  15169. * @param {Object} [normalSpecified]
  15170. * @param {Object} [emphasisSpecified]
  15171. */
  15172. function setLabelStyle(
  15173. normalStyle, emphasisStyle,
  15174. normalModel, emphasisModel,
  15175. opt,
  15176. normalSpecified, emphasisSpecified
  15177. ) {
  15178. opt = opt || EMPTY_OBJ;
  15179. var labelFetcher = opt.labelFetcher;
  15180. var labelDataIndex = opt.labelDataIndex;
  15181. var labelDimIndex = opt.labelDimIndex;
  15182. var labelProp = opt.labelProp;
  15183. // This scenario, `label.normal.show = true; label.emphasis.show = false`,
  15184. // is not supported util someone requests.
  15185. var showNormal = normalModel.getShallow('show');
  15186. var showEmphasis = emphasisModel.getShallow('show');
  15187. // Consider performance, only fetch label when necessary.
  15188. // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,
  15189. // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.
  15190. var baseText;
  15191. if (showNormal || showEmphasis) {
  15192. if (labelFetcher) {
  15193. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, labelProp);
  15194. }
  15195. if (baseText == null) {
  15196. baseText = isFunction$1(opt.defaultText) ? opt.defaultText(labelDataIndex, opt) : opt.defaultText;
  15197. }
  15198. }
  15199. var normalStyleText = showNormal ? baseText : null;
  15200. var emphasisStyleText = showEmphasis
  15201. ? retrieve2(
  15202. labelFetcher
  15203. ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex, labelProp)
  15204. : null,
  15205. baseText
  15206. )
  15207. : null;
  15208. // Optimize: If style.text is null, text will not be drawn.
  15209. if (normalStyleText != null || emphasisStyleText != null) {
  15210. // Always set `textStyle` even if `normalStyle.text` is null, because default
  15211. // values have to be set on `normalStyle`.
  15212. // If we set default values on `emphasisStyle`, consider case:
  15213. // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`
  15214. // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`
  15215. // Then the 'red' will not work on emphasis.
  15216. setTextStyle(normalStyle, normalModel, normalSpecified, opt);
  15217. setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);
  15218. }
  15219. normalStyle.text = normalStyleText;
  15220. emphasisStyle.text = emphasisStyleText;
  15221. }
  15222. /**
  15223. * Modify label style manually.
  15224. * Only works after `setLabelStyle` and `setElementHoverStyle` called.
  15225. *
  15226. * @param {module:zrender/src/Element} el
  15227. * @param {Object} [normalStyleProps] optional
  15228. * @param {Object} [emphasisStyleProps] optional
  15229. */
  15230. function modifyLabelStyle(el, normalStyleProps, emphasisStyleProps) {
  15231. var elStyle = el.style;
  15232. if (normalStyleProps) {
  15233. rollbackDefaultTextStyle(elStyle);
  15234. el.setStyle(normalStyleProps);
  15235. applyDefaultTextStyle(elStyle);
  15236. }
  15237. elStyle = el.__hoverStl;
  15238. if (emphasisStyleProps && elStyle) {
  15239. rollbackDefaultTextStyle(elStyle);
  15240. extend(elStyle, emphasisStyleProps);
  15241. applyDefaultTextStyle(elStyle);
  15242. }
  15243. }
  15244. /**
  15245. * Set basic textStyle properties.
  15246. * See more info in `setTextStyleCommon`.
  15247. * @param {Object|module:zrender/graphic/Style} textStyle
  15248. * @param {module:echarts/model/Model} model
  15249. * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.
  15250. * @param {Object} [opt] See `opt` of `setTextStyleCommon`.
  15251. * @param {boolean} [isEmphasis]
  15252. */
  15253. function setTextStyle(
  15254. textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis
  15255. ) {
  15256. setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);
  15257. specifiedTextStyle && extend(textStyle, specifiedTextStyle);
  15258. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  15259. return textStyle;
  15260. }
  15261. /**
  15262. * Set text option in the style.
  15263. * See more info in `setTextStyleCommon`.
  15264. * @deprecated
  15265. * @param {Object} textStyle
  15266. * @param {module:echarts/model/Model} labelModel
  15267. * @param {string|boolean} defaultColor Default text color.
  15268. * If set as false, it will be processed as a emphasis style.
  15269. */
  15270. function setText(textStyle, labelModel, defaultColor) {
  15271. var opt = {isRectText: true};
  15272. var isEmphasis;
  15273. if (defaultColor === false) {
  15274. isEmphasis = true;
  15275. }
  15276. else {
  15277. // Support setting color as 'auto' to get visual color.
  15278. opt.autoColor = defaultColor;
  15279. }
  15280. setTextStyleCommon(textStyle, labelModel, opt, isEmphasis);
  15281. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  15282. }
  15283. /**
  15284. * The uniform entry of set text style, that is, retrieve style definitions
  15285. * from `model` and set to `textStyle` object.
  15286. *
  15287. * Never in merge mode, but in overwrite mode, that is, all of the text style
  15288. * properties will be set. (Consider the states of normal and emphasis and
  15289. * default value can be adopted, merge would make the logic too complicated
  15290. * to manage.)
  15291. *
  15292. * The `textStyle` object can either be a plain object or an instance of
  15293. * `zrender/src/graphic/Style`, and either be the style of normal or emphasis.
  15294. * After this mothod called, the `textStyle` object can then be used in
  15295. * `el.setStyle(textStyle)` or `el.hoverStyle = textStyle`.
  15296. *
  15297. * Default value will be adopted and `insideRollbackOpt` will be created.
  15298. * See `applyDefaultTextStyle` `rollbackDefaultTextStyle` for more details.
  15299. *
  15300. * opt: {
  15301. * disableBox: boolean, Whether diable drawing box of block (outer most).
  15302. * isRectText: boolean,
  15303. * autoColor: string, specify a color when color is 'auto',
  15304. * for textFill, textStroke, textBackgroundColor, and textBorderColor.
  15305. * If autoColor specified, it is used as default textFill.
  15306. * useInsideStyle:
  15307. * `true`: Use inside style (textFill, textStroke, textStrokeWidth)
  15308. * if `textFill` is not specified.
  15309. * `false`: Do not use inside style.
  15310. * `null/undefined`: use inside style if `isRectText` is true and
  15311. * `textFill` is not specified and textPosition contains `'inside'`.
  15312. * forceRich: boolean
  15313. * }
  15314. */
  15315. function setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {
  15316. // Consider there will be abnormal when merge hover style to normal style if given default value.
  15317. opt = opt || EMPTY_OBJ;
  15318. if (opt.isRectText) {
  15319. var textPosition;
  15320. if (opt.getTextPosition) {
  15321. textPosition = opt.getTextPosition(textStyleModel, isEmphasis);
  15322. }
  15323. else {
  15324. textPosition = textStyleModel.getShallow('position')
  15325. || (isEmphasis ? null : 'inside');
  15326. // 'outside' is not a valid zr textPostion value, but used
  15327. // in bar series, and magric type should be considered.
  15328. textPosition === 'outside' && (textPosition = 'top');
  15329. }
  15330. textStyle.textPosition = textPosition;
  15331. textStyle.textOffset = textStyleModel.getShallow('offset');
  15332. var labelRotate = textStyleModel.getShallow('rotate');
  15333. labelRotate != null && (labelRotate *= Math.PI / 180);
  15334. textStyle.textRotation = labelRotate;
  15335. textStyle.textDistance = retrieve2(
  15336. textStyleModel.getShallow('distance'), isEmphasis ? null : 5
  15337. );
  15338. }
  15339. var ecModel = textStyleModel.ecModel;
  15340. var globalTextStyle = ecModel && ecModel.option.textStyle;
  15341. // Consider case:
  15342. // {
  15343. // data: [{
  15344. // value: 12,
  15345. // label: {
  15346. // rich: {
  15347. // // no 'a' here but using parent 'a'.
  15348. // }
  15349. // }
  15350. // }],
  15351. // rich: {
  15352. // a: { ... }
  15353. // }
  15354. // }
  15355. var richItemNames = getRichItemNames(textStyleModel);
  15356. var richResult;
  15357. if (richItemNames) {
  15358. richResult = {};
  15359. for (var name in richItemNames) {
  15360. if (richItemNames.hasOwnProperty(name)) {
  15361. // Cascade is supported in rich.
  15362. var richTextStyle = textStyleModel.getModel(['rich', name]);
  15363. // In rich, never `disableBox`.
  15364. // FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  15365. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  15366. // That might confuses users. So probably we should put `textStyleModel` as the
  15367. // root ancestor of the `richTextStyle`. But that would be a break change.
  15368. setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);
  15369. }
  15370. }
  15371. }
  15372. textStyle.rich = richResult;
  15373. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);
  15374. if (opt.forceRich && !opt.textStyle) {
  15375. opt.textStyle = {};
  15376. }
  15377. return textStyle;
  15378. }
  15379. // Consider case:
  15380. // {
  15381. // data: [{
  15382. // value: 12,
  15383. // label: {
  15384. // rich: {
  15385. // // no 'a' here but using parent 'a'.
  15386. // }
  15387. // }
  15388. // }],
  15389. // rich: {
  15390. // a: { ... }
  15391. // }
  15392. // }
  15393. function getRichItemNames(textStyleModel) {
  15394. // Use object to remove duplicated names.
  15395. var richItemNameMap;
  15396. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  15397. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  15398. if (rich) {
  15399. richItemNameMap = richItemNameMap || {};
  15400. for (var name in rich) {
  15401. if (rich.hasOwnProperty(name)) {
  15402. richItemNameMap[name] = 1;
  15403. }
  15404. }
  15405. }
  15406. textStyleModel = textStyleModel.parentModel;
  15407. }
  15408. return richItemNameMap;
  15409. }
  15410. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {
  15411. // In merge mode, default value should not be given.
  15412. globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;
  15413. textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt)
  15414. || globalTextStyle.color;
  15415. textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt)
  15416. || globalTextStyle.textBorderColor;
  15417. textStyle.textStrokeWidth = retrieve2(
  15418. textStyleModel.getShallow('textBorderWidth'),
  15419. globalTextStyle.textBorderWidth
  15420. );
  15421. if (!isEmphasis) {
  15422. if (isBlock) {
  15423. textStyle.insideRollbackOpt = opt;
  15424. applyDefaultTextStyle(textStyle);
  15425. }
  15426. // Set default finally.
  15427. if (textStyle.textFill == null) {
  15428. textStyle.textFill = opt.autoColor;
  15429. }
  15430. }
  15431. // Do not use `getFont` here, because merge should be supported, where
  15432. // part of these properties may be changed in emphasis style, and the
  15433. // others should remain their original value got from normal style.
  15434. textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;
  15435. textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;
  15436. textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;
  15437. textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;
  15438. textStyle.textAlign = textStyleModel.getShallow('align');
  15439. textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign')
  15440. || textStyleModel.getShallow('baseline');
  15441. textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');
  15442. textStyle.textWidth = textStyleModel.getShallow('width');
  15443. textStyle.textHeight = textStyleModel.getShallow('height');
  15444. textStyle.textTag = textStyleModel.getShallow('tag');
  15445. if (!isBlock || !opt.disableBox) {
  15446. textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);
  15447. textStyle.textPadding = textStyleModel.getShallow('padding');
  15448. textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);
  15449. textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');
  15450. textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');
  15451. textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');
  15452. textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');
  15453. textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');
  15454. textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');
  15455. }
  15456. textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor')
  15457. || globalTextStyle.textShadowColor;
  15458. textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur')
  15459. || globalTextStyle.textShadowBlur;
  15460. textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX')
  15461. || globalTextStyle.textShadowOffsetX;
  15462. textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY')
  15463. || globalTextStyle.textShadowOffsetY;
  15464. }
  15465. function getAutoColor(color, opt) {
  15466. return color !== 'auto' ? color : (opt && opt.autoColor) ? opt.autoColor : null;
  15467. }
  15468. /**
  15469. * Give some default value to the input `textStyle` object, based on the current settings
  15470. * in this `textStyle` object.
  15471. *
  15472. * The Scenario:
  15473. * when text position is `inside` and `textFill` is not specified, we show
  15474. * text border by default for better view. But it should be considered that text position
  15475. * might be changed when hovering or being emphasis, where the `insideRollback` is used to
  15476. * restore the style.
  15477. *
  15478. * Usage (& NOTICE):
  15479. * When a style object (eithor plain object or instance of `zrender/src/graphic/Style`) is
  15480. * about to be modified on its text related properties, `rollbackDefaultTextStyle` should
  15481. * be called before the modification and `applyDefaultTextStyle` should be called after that.
  15482. * (For the case that all of the text related properties is reset, like `setTextStyleCommon`
  15483. * does, `rollbackDefaultTextStyle` is not needed to be called).
  15484. */
  15485. function applyDefaultTextStyle(textStyle) {
  15486. var textPosition = textStyle.textPosition;
  15487. var opt = textStyle.insideRollbackOpt;
  15488. var insideRollback;
  15489. if (opt && textStyle.textFill == null) {
  15490. var autoColor = opt.autoColor;
  15491. var isRectText = opt.isRectText;
  15492. var useInsideStyle = opt.useInsideStyle;
  15493. var useInsideStyleCache = useInsideStyle !== false
  15494. && (useInsideStyle === true
  15495. || (isRectText
  15496. && textPosition
  15497. // textPosition can be [10, 30]
  15498. && typeof textPosition === 'string'
  15499. && textPosition.indexOf('inside') >= 0
  15500. )
  15501. );
  15502. var useAutoColorCache = !useInsideStyleCache && autoColor != null;
  15503. // All of the props declared in `CACHED_LABEL_STYLE_PROPERTIES` are to be cached.
  15504. if (useInsideStyleCache || useAutoColorCache) {
  15505. insideRollback = {
  15506. textFill: textStyle.textFill,
  15507. textStroke: textStyle.textStroke,
  15508. textStrokeWidth: textStyle.textStrokeWidth
  15509. };
  15510. }
  15511. if (useInsideStyleCache) {
  15512. textStyle.textFill = '#fff';
  15513. // Consider text with #fff overflow its container.
  15514. if (textStyle.textStroke == null) {
  15515. textStyle.textStroke = autoColor;
  15516. textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);
  15517. }
  15518. }
  15519. if (useAutoColorCache) {
  15520. textStyle.textFill = autoColor;
  15521. }
  15522. }
  15523. // Always set `insideRollback`, so that the previous one can be cleared.
  15524. textStyle.insideRollback = insideRollback;
  15525. }
  15526. /**
  15527. * Consider the case: in a scatter,
  15528. * label: {
  15529. * normal: {position: 'inside'},
  15530. * emphasis: {position: 'top'}
  15531. * }
  15532. * In the normal state, the `textFill` will be set as '#fff' for pretty view (see
  15533. * `applyDefaultTextStyle`), but when switching to emphasis state, the `textFill`
  15534. * should be retured to 'autoColor', but not keep '#fff'.
  15535. */
  15536. function rollbackDefaultTextStyle(style) {
  15537. var insideRollback = style.insideRollback;
  15538. if (insideRollback) {
  15539. // Reset all of the props in `CACHED_LABEL_STYLE_PROPERTIES`.
  15540. style.textFill = insideRollback.textFill;
  15541. style.textStroke = insideRollback.textStroke;
  15542. style.textStrokeWidth = insideRollback.textStrokeWidth;
  15543. style.insideRollback = null;
  15544. }
  15545. }
  15546. function getFont(opt, ecModel) {
  15547. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  15548. return trim([
  15549. // FIXME in node-canvas fontWeight is before fontStyle
  15550. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '',
  15551. opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '',
  15552. (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px',
  15553. opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'
  15554. ].join(' '));
  15555. }
  15556. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  15557. if (typeof dataIndex === 'function') {
  15558. cb = dataIndex;
  15559. dataIndex = null;
  15560. }
  15561. // Do not check 'animation' property directly here. Consider this case:
  15562. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  15563. // but its parent model (`seriesModel`) does.
  15564. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  15565. if (animationEnabled) {
  15566. var postfix = isUpdate ? 'Update' : '';
  15567. var duration = animatableModel.getShallow('animationDuration' + postfix);
  15568. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  15569. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  15570. if (typeof animationDelay === 'function') {
  15571. animationDelay = animationDelay(
  15572. dataIndex,
  15573. animatableModel.getAnimationDelayParams
  15574. ? animatableModel.getAnimationDelayParams(el, dataIndex)
  15575. : null
  15576. );
  15577. }
  15578. if (typeof duration === 'function') {
  15579. duration = duration(dataIndex);
  15580. }
  15581. duration > 0
  15582. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb)
  15583. : (el.stopAnimation(), el.attr(props), cb && cb());
  15584. }
  15585. else {
  15586. el.stopAnimation();
  15587. el.attr(props);
  15588. cb && cb();
  15589. }
  15590. }
  15591. /**
  15592. * Update graphic element properties with or without animation according to the
  15593. * configuration in series.
  15594. *
  15595. * Caution: this method will stop previous animation.
  15596. * So do not use this method to one element twice before
  15597. * animation starts, unless you know what you are doing.
  15598. *
  15599. * @param {module:zrender/Element} el
  15600. * @param {Object} props
  15601. * @param {module:echarts/model/Model} [animatableModel]
  15602. * @param {number} [dataIndex]
  15603. * @param {Function} [cb]
  15604. * @example
  15605. * graphic.updateProps(el, {
  15606. * position: [100, 100]
  15607. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  15608. * // Or
  15609. * graphic.updateProps(el, {
  15610. * position: [100, 100]
  15611. * }, seriesModel, function () { console.log('Animation done!'); });
  15612. */
  15613. function updateProps(el, props, animatableModel, dataIndex, cb) {
  15614. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  15615. }
  15616. /**
  15617. * Init graphic element properties with or without animation according to the
  15618. * configuration in series.
  15619. *
  15620. * Caution: this method will stop previous animation.
  15621. * So do not use this method to one element twice before
  15622. * animation starts, unless you know what you are doing.
  15623. *
  15624. * @param {module:zrender/Element} el
  15625. * @param {Object} props
  15626. * @param {module:echarts/model/Model} [animatableModel]
  15627. * @param {number} [dataIndex]
  15628. * @param {Function} cb
  15629. */
  15630. function initProps(el, props, animatableModel, dataIndex, cb) {
  15631. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  15632. }
  15633. /**
  15634. * Get transform matrix of target (param target),
  15635. * in coordinate of its ancestor (param ancestor)
  15636. *
  15637. * @param {module:zrender/mixin/Transformable} target
  15638. * @param {module:zrender/mixin/Transformable} [ancestor]
  15639. */
  15640. function getTransform(target, ancestor) {
  15641. var mat = identity([]);
  15642. while (target && target !== ancestor) {
  15643. mul$1(mat, target.getLocalTransform(), mat);
  15644. target = target.parent;
  15645. }
  15646. return mat;
  15647. }
  15648. /**
  15649. * Apply transform to an vertex.
  15650. * @param {Array.<number>} target [x, y]
  15651. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  15652. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  15653. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  15654. * @param {boolean=} invert Whether use invert matrix.
  15655. * @return {Array.<number>} [x, y]
  15656. */
  15657. function applyTransform$1(target, transform, invert$$1) {
  15658. if (transform && !isArrayLike(transform)) {
  15659. transform = Transformable.getLocalTransform(transform);
  15660. }
  15661. if (invert$$1) {
  15662. transform = invert([], transform);
  15663. }
  15664. return applyTransform([], target, transform);
  15665. }
  15666. /**
  15667. * @param {string} direction 'left' 'right' 'top' 'bottom'
  15668. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  15669. * @param {boolean=} invert Whether use invert matrix.
  15670. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  15671. */
  15672. function transformDirection(direction, transform, invert$$1) {
  15673. // Pick a base, ensure that transform result will not be (0, 0).
  15674. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  15675. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  15676. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  15677. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  15678. var vertex = [
  15679. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  15680. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  15681. ];
  15682. vertex = applyTransform$1(vertex, transform, invert$$1);
  15683. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  15684. ? (vertex[0] > 0 ? 'right' : 'left')
  15685. : (vertex[1] > 0 ? 'bottom' : 'top');
  15686. }
  15687. /**
  15688. * Apply group transition animation from g1 to g2.
  15689. * If no animatableModel, no animation.
  15690. */
  15691. function groupTransition(g1, g2, animatableModel, cb) {
  15692. if (!g1 || !g2) {
  15693. return;
  15694. }
  15695. function getElMap(g) {
  15696. var elMap = {};
  15697. g.traverse(function (el) {
  15698. if (!el.isGroup && el.anid) {
  15699. elMap[el.anid] = el;
  15700. }
  15701. });
  15702. return elMap;
  15703. }
  15704. function getAnimatableProps(el) {
  15705. var obj = {
  15706. position: clone$1(el.position),
  15707. rotation: el.rotation
  15708. };
  15709. if (el.shape) {
  15710. obj.shape = extend({}, el.shape);
  15711. }
  15712. return obj;
  15713. }
  15714. var elMap1 = getElMap(g1);
  15715. g2.traverse(function (el) {
  15716. if (!el.isGroup && el.anid) {
  15717. var oldEl = elMap1[el.anid];
  15718. if (oldEl) {
  15719. var newProp = getAnimatableProps(el);
  15720. el.attr(getAnimatableProps(oldEl));
  15721. updateProps(el, newProp, animatableModel, el.dataIndex);
  15722. }
  15723. // else {
  15724. // if (el.previousProps) {
  15725. // graphic.updateProps
  15726. // }
  15727. // }
  15728. }
  15729. });
  15730. }
  15731. /**
  15732. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  15733. * @param {Object} rect {x, y, width, height}
  15734. * @return {Array.<Array.<number>>} A new clipped points.
  15735. */
  15736. function clipPointsByRect(points, rect) {
  15737. // FIXME: this way migth be incorrect when grpahic clipped by a corner.
  15738. // and when element have border.
  15739. return map(points, function (point) {
  15740. var x = point[0];
  15741. x = mathMax$1(x, rect.x);
  15742. x = mathMin$1(x, rect.x + rect.width);
  15743. var y = point[1];
  15744. y = mathMax$1(y, rect.y);
  15745. y = mathMin$1(y, rect.y + rect.height);
  15746. return [x, y];
  15747. });
  15748. }
  15749. /**
  15750. * @param {Object} targetRect {x, y, width, height}
  15751. * @param {Object} rect {x, y, width, height}
  15752. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  15753. */
  15754. function clipRectByRect(targetRect, rect) {
  15755. var x = mathMax$1(targetRect.x, rect.x);
  15756. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  15757. var y = mathMax$1(targetRect.y, rect.y);
  15758. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height);
  15759. // If the total rect is cliped, nothing, including the border,
  15760. // should be painted. So return undefined.
  15761. if (x2 >= x && y2 >= y) {
  15762. return {
  15763. x: x,
  15764. y: y,
  15765. width: x2 - x,
  15766. height: y2 - y
  15767. };
  15768. }
  15769. }
  15770. /**
  15771. * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.
  15772. * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.
  15773. * @param {Object} [rect] {x, y, width, height}
  15774. * @return {module:zrender/Element} Icon path or image element.
  15775. */
  15776. function createIcon(iconStr, opt, rect) {
  15777. opt = extend({rectHover: true}, opt);
  15778. var style = opt.style = {strokeNoScale: true};
  15779. rect = rect || {x: -1, y: -1, width: 2, height: 2};
  15780. if (iconStr) {
  15781. return iconStr.indexOf('image://') === 0
  15782. ? (
  15783. style.image = iconStr.slice(8),
  15784. defaults(style, rect),
  15785. new ZImage(opt)
  15786. )
  15787. : (
  15788. makePath(
  15789. iconStr.replace('path://', ''),
  15790. opt,
  15791. rect,
  15792. 'center'
  15793. )
  15794. );
  15795. }
  15796. }
  15797. /**
  15798. * Return `true` if the given line (line `a`) and the given polygon
  15799. * are intersect.
  15800. * Note that we do not count colinear as intersect here because no
  15801. * requirement for that. We could do that if required in future.
  15802. *
  15803. * @param {number} a1x
  15804. * @param {number} a1y
  15805. * @param {number} a2x
  15806. * @param {number} a2y
  15807. * @param {Array.<Array.<number>>} points Points of the polygon.
  15808. * @return {boolean}
  15809. */
  15810. function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {
  15811. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  15812. var p = points[i];
  15813. if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {
  15814. return true;
  15815. }
  15816. p2 = p;
  15817. }
  15818. }
  15819. /**
  15820. * Return `true` if the given two lines (line `a` and line `b`)
  15821. * are intersect.
  15822. * Note that we do not count colinear as intersect here because no
  15823. * requirement for that. We could do that if required in future.
  15824. *
  15825. * @param {number} a1x
  15826. * @param {number} a1y
  15827. * @param {number} a2x
  15828. * @param {number} a2y
  15829. * @param {number} b1x
  15830. * @param {number} b1y
  15831. * @param {number} b2x
  15832. * @param {number} b2y
  15833. * @return {boolean}
  15834. */
  15835. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  15836. // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.
  15837. var mx = a2x - a1x;
  15838. var my = a2y - a1y;
  15839. var nx = b2x - b1x;
  15840. var ny = b2y - b1y;
  15841. // `vec_m` and `vec_n` are parallel iff
  15842. // exising `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.
  15843. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  15844. if (nearZero(nmCrossProduct)) {
  15845. return false;
  15846. }
  15847. // `vec_m` and `vec_n` are intersect iff
  15848. // existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,
  15849. // such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`
  15850. // and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.
  15851. var b1a1x = a1x - b1x;
  15852. var b1a1y = a1y - b1y;
  15853. var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;
  15854. if (q < 0 || q > 1) {
  15855. return false;
  15856. }
  15857. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  15858. if (p < 0 || p > 1) {
  15859. return false;
  15860. }
  15861. return true;
  15862. }
  15863. /**
  15864. * Cross product of 2-dimension vector.
  15865. */
  15866. function crossProduct2d(x1, y1, x2, y2) {
  15867. return x1 * y2 - x2 * y1;
  15868. }
  15869. function nearZero(val) {
  15870. return val <= (1e-6) && val >= -(1e-6);
  15871. }
  15872. // Register built-in shapes. These shapes might be overwirtten
  15873. // by users, although we do not recommend that.
  15874. registerShape('circle', Circle);
  15875. registerShape('sector', Sector);
  15876. registerShape('ring', Ring);
  15877. registerShape('polygon', Polygon);
  15878. registerShape('polyline', Polyline);
  15879. registerShape('rect', Rect);
  15880. registerShape('line', Line);
  15881. registerShape('bezierCurve', BezierCurve);
  15882. registerShape('arc', Arc);
  15883. var graphic = (Object.freeze || Object)({
  15884. Z2_EMPHASIS_LIFT: Z2_EMPHASIS_LIFT,
  15885. CACHED_LABEL_STYLE_PROPERTIES: CACHED_LABEL_STYLE_PROPERTIES,
  15886. extendShape: extendShape,
  15887. extendPath: extendPath,
  15888. registerShape: registerShape,
  15889. getShapeClass: getShapeClass,
  15890. makePath: makePath,
  15891. makeImage: makeImage,
  15892. mergePath: mergePath,
  15893. resizePath: resizePath,
  15894. subPixelOptimizeLine: subPixelOptimizeLine,
  15895. subPixelOptimizeRect: subPixelOptimizeRect,
  15896. subPixelOptimize: subPixelOptimize,
  15897. setElementHoverStyle: setElementHoverStyle,
  15898. setHoverStyle: setHoverStyle,
  15899. setAsHighDownDispatcher: setAsHighDownDispatcher,
  15900. isHighDownDispatcher: isHighDownDispatcher,
  15901. getHighlightDigit: getHighlightDigit,
  15902. setLabelStyle: setLabelStyle,
  15903. modifyLabelStyle: modifyLabelStyle,
  15904. setTextStyle: setTextStyle,
  15905. setText: setText,
  15906. getFont: getFont,
  15907. updateProps: updateProps,
  15908. initProps: initProps,
  15909. getTransform: getTransform,
  15910. applyTransform: applyTransform$1,
  15911. transformDirection: transformDirection,
  15912. groupTransition: groupTransition,
  15913. clipPointsByRect: clipPointsByRect,
  15914. clipRectByRect: clipRectByRect,
  15915. createIcon: createIcon,
  15916. linePolygonIntersect: linePolygonIntersect,
  15917. lineLineIntersect: lineLineIntersect,
  15918. Group: Group,
  15919. Image: ZImage,
  15920. Text: Text,
  15921. Circle: Circle,
  15922. Sector: Sector,
  15923. Ring: Ring,
  15924. Polygon: Polygon,
  15925. Polyline: Polyline,
  15926. Rect: Rect,
  15927. Line: Line,
  15928. BezierCurve: BezierCurve,
  15929. Arc: Arc,
  15930. IncrementalDisplayable: IncrementalDisplayble,
  15931. CompoundPath: CompoundPath,
  15932. LinearGradient: LinearGradient,
  15933. RadialGradient: RadialGradient,
  15934. BoundingRect: BoundingRect
  15935. });
  15936. /*
  15937. * Licensed to the Apache Software Foundation (ASF) under one
  15938. * or more contributor license agreements. See the NOTICE file
  15939. * distributed with this work for additional information
  15940. * regarding copyright ownership. The ASF licenses this file
  15941. * to you under the Apache License, Version 2.0 (the
  15942. * "License"); you may not use this file except in compliance
  15943. * with the License. You may obtain a copy of the License at
  15944. *
  15945. * http://www.apache.org/licenses/LICENSE-2.0
  15946. *
  15947. * Unless required by applicable law or agreed to in writing,
  15948. * software distributed under the License is distributed on an
  15949. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15950. * KIND, either express or implied. See the License for the
  15951. * specific language governing permissions and limitations
  15952. * under the License.
  15953. */
  15954. var PATH_COLOR = ['textStyle', 'color'];
  15955. var textStyleMixin = {
  15956. /**
  15957. * Get color property or get color from option.textStyle.color
  15958. * @param {boolean} [isEmphasis]
  15959. * @return {string}
  15960. */
  15961. getTextColor: function (isEmphasis) {
  15962. var ecModel = this.ecModel;
  15963. return this.getShallow('color')
  15964. || (
  15965. (!isEmphasis && ecModel) ? ecModel.get(PATH_COLOR) : null
  15966. );
  15967. },
  15968. /**
  15969. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  15970. * @return {string}
  15971. */
  15972. getFont: function () {
  15973. return getFont({
  15974. fontStyle: this.getShallow('fontStyle'),
  15975. fontWeight: this.getShallow('fontWeight'),
  15976. fontSize: this.getShallow('fontSize'),
  15977. fontFamily: this.getShallow('fontFamily')
  15978. }, this.ecModel);
  15979. },
  15980. getTextRect: function (text) {
  15981. return getBoundingRect(
  15982. text,
  15983. this.getFont(),
  15984. this.getShallow('align'),
  15985. this.getShallow('verticalAlign') || this.getShallow('baseline'),
  15986. this.getShallow('padding'),
  15987. this.getShallow('lineHeight'),
  15988. this.getShallow('rich'),
  15989. this.getShallow('truncateText')
  15990. );
  15991. }
  15992. };
  15993. /*
  15994. * Licensed to the Apache Software Foundation (ASF) under one
  15995. * or more contributor license agreements. See the NOTICE file
  15996. * distributed with this work for additional information
  15997. * regarding copyright ownership. The ASF licenses this file
  15998. * to you under the Apache License, Version 2.0 (the
  15999. * "License"); you may not use this file except in compliance
  16000. * with the License. You may obtain a copy of the License at
  16001. *
  16002. * http://www.apache.org/licenses/LICENSE-2.0
  16003. *
  16004. * Unless required by applicable law or agreed to in writing,
  16005. * software distributed under the License is distributed on an
  16006. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16007. * KIND, either express or implied. See the License for the
  16008. * specific language governing permissions and limitations
  16009. * under the License.
  16010. */
  16011. var getItemStyle = makeStyleMapper(
  16012. [
  16013. ['fill', 'color'],
  16014. ['stroke', 'borderColor'],
  16015. ['lineWidth', 'borderWidth'],
  16016. ['opacity'],
  16017. ['shadowBlur'],
  16018. ['shadowOffsetX'],
  16019. ['shadowOffsetY'],
  16020. ['shadowColor'],
  16021. ['textPosition'],
  16022. ['textAlign']
  16023. ]
  16024. );
  16025. var itemStyleMixin = {
  16026. getItemStyle: function (excludes, includes) {
  16027. var style = getItemStyle(this, excludes, includes);
  16028. var lineDash = this.getBorderLineDash();
  16029. lineDash && (style.lineDash = lineDash);
  16030. return style;
  16031. },
  16032. getBorderLineDash: function () {
  16033. var lineType = this.get('borderType');
  16034. return (lineType === 'solid' || lineType == null) ? null
  16035. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  16036. }
  16037. };
  16038. /*
  16039. * Licensed to the Apache Software Foundation (ASF) under one
  16040. * or more contributor license agreements. See the NOTICE file
  16041. * distributed with this work for additional information
  16042. * regarding copyright ownership. The ASF licenses this file
  16043. * to you under the Apache License, Version 2.0 (the
  16044. * "License"); you may not use this file except in compliance
  16045. * with the License. You may obtain a copy of the License at
  16046. *
  16047. * http://www.apache.org/licenses/LICENSE-2.0
  16048. *
  16049. * Unless required by applicable law or agreed to in writing,
  16050. * software distributed under the License is distributed on an
  16051. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16052. * KIND, either express or implied. See the License for the
  16053. * specific language governing permissions and limitations
  16054. * under the License.
  16055. */
  16056. /**
  16057. * @module echarts/model/Model
  16058. */
  16059. var mixin$1 = mixin;
  16060. var inner = makeInner();
  16061. /**
  16062. * @alias module:echarts/model/Model
  16063. * @constructor
  16064. * @param {Object} [option]
  16065. * @param {module:echarts/model/Model} [parentModel]
  16066. * @param {module:echarts/model/Global} [ecModel]
  16067. */
  16068. function Model(option, parentModel, ecModel) {
  16069. /**
  16070. * @type {module:echarts/model/Model}
  16071. * @readOnly
  16072. */
  16073. this.parentModel = parentModel;
  16074. /**
  16075. * @type {module:echarts/model/Global}
  16076. * @readOnly
  16077. */
  16078. this.ecModel = ecModel;
  16079. /**
  16080. * @type {Object}
  16081. * @protected
  16082. */
  16083. this.option = option;
  16084. // Simple optimization
  16085. // if (this.init) {
  16086. // if (arguments.length <= 4) {
  16087. // this.init(option, parentModel, ecModel, extraOpt);
  16088. // }
  16089. // else {
  16090. // this.init.apply(this, arguments);
  16091. // }
  16092. // }
  16093. }
  16094. Model.prototype = {
  16095. constructor: Model,
  16096. /**
  16097. * Model 的初始化函数
  16098. * @param {Object} option
  16099. */
  16100. init: null,
  16101. /**
  16102. * 从新的 Option merge
  16103. */
  16104. mergeOption: function (option) {
  16105. merge(this.option, option, true);
  16106. },
  16107. /**
  16108. * @param {string|Array.<string>} path
  16109. * @param {boolean} [ignoreParent=false]
  16110. * @return {*}
  16111. */
  16112. get: function (path, ignoreParent) {
  16113. if (path == null) {
  16114. return this.option;
  16115. }
  16116. return doGet(
  16117. this.option,
  16118. this.parsePath(path),
  16119. !ignoreParent && getParent(this, path)
  16120. );
  16121. },
  16122. /**
  16123. * @param {string} key
  16124. * @param {boolean} [ignoreParent=false]
  16125. * @return {*}
  16126. */
  16127. getShallow: function (key, ignoreParent) {
  16128. var option = this.option;
  16129. var val = option == null ? option : option[key];
  16130. var parentModel = !ignoreParent && getParent(this, key);
  16131. if (val == null && parentModel) {
  16132. val = parentModel.getShallow(key);
  16133. }
  16134. return val;
  16135. },
  16136. /**
  16137. * @param {string|Array.<string>} [path]
  16138. * @param {module:echarts/model/Model} [parentModel]
  16139. * @return {module:echarts/model/Model}
  16140. */
  16141. getModel: function (path, parentModel) {
  16142. var obj = path == null
  16143. ? this.option
  16144. : doGet(this.option, path = this.parsePath(path));
  16145. var thisParentModel;
  16146. parentModel = parentModel || (
  16147. (thisParentModel = getParent(this, path))
  16148. && thisParentModel.getModel(path)
  16149. );
  16150. return new Model(obj, parentModel, this.ecModel);
  16151. },
  16152. /**
  16153. * If model has option
  16154. */
  16155. isEmpty: function () {
  16156. return this.option == null;
  16157. },
  16158. restoreData: function () {},
  16159. // Pending
  16160. clone: function () {
  16161. var Ctor = this.constructor;
  16162. return new Ctor(clone(this.option));
  16163. },
  16164. setReadOnly: function (properties) {
  16165. // clazzUtil.setReadOnly(this, properties);
  16166. },
  16167. // If path is null/undefined, return null/undefined.
  16168. parsePath: function (path) {
  16169. if (typeof path === 'string') {
  16170. path = path.split('.');
  16171. }
  16172. return path;
  16173. },
  16174. /**
  16175. * @param {Function} getParentMethod
  16176. * param {Array.<string>|string} path
  16177. * return {module:echarts/model/Model}
  16178. */
  16179. customizeGetParent: function (getParentMethod) {
  16180. inner(this).getParent = getParentMethod;
  16181. },
  16182. isAnimationEnabled: function () {
  16183. if (!env$1.node) {
  16184. if (this.option.animation != null) {
  16185. return !!this.option.animation;
  16186. }
  16187. else if (this.parentModel) {
  16188. return this.parentModel.isAnimationEnabled();
  16189. }
  16190. }
  16191. }
  16192. };
  16193. function doGet(obj, pathArr, parentModel) {
  16194. for (var i = 0; i < pathArr.length; i++) {
  16195. // Ignore empty
  16196. if (!pathArr[i]) {
  16197. continue;
  16198. }
  16199. // obj could be number/string/... (like 0)
  16200. obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;
  16201. if (obj == null) {
  16202. break;
  16203. }
  16204. }
  16205. if (obj == null && parentModel) {
  16206. obj = parentModel.get(pathArr);
  16207. }
  16208. return obj;
  16209. }
  16210. // `path` can be null/undefined
  16211. function getParent(model, path) {
  16212. var getParentMethod = inner(model).getParent;
  16213. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  16214. }
  16215. // Enable Model.extend.
  16216. enableClassExtend(Model);
  16217. enableClassCheck(Model);
  16218. mixin$1(Model, lineStyleMixin);
  16219. mixin$1(Model, areaStyleMixin);
  16220. mixin$1(Model, textStyleMixin);
  16221. mixin$1(Model, itemStyleMixin);
  16222. /*
  16223. * Licensed to the Apache Software Foundation (ASF) under one
  16224. * or more contributor license agreements. See the NOTICE file
  16225. * distributed with this work for additional information
  16226. * regarding copyright ownership. The ASF licenses this file
  16227. * to you under the Apache License, Version 2.0 (the
  16228. * "License"); you may not use this file except in compliance
  16229. * with the License. You may obtain a copy of the License at
  16230. *
  16231. * http://www.apache.org/licenses/LICENSE-2.0
  16232. *
  16233. * Unless required by applicable law or agreed to in writing,
  16234. * software distributed under the License is distributed on an
  16235. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16236. * KIND, either express or implied. See the License for the
  16237. * specific language governing permissions and limitations
  16238. * under the License.
  16239. */
  16240. var base = 0;
  16241. /**
  16242. * @public
  16243. * @param {string} type
  16244. * @return {string}
  16245. */
  16246. function getUID(type) {
  16247. // Considering the case of crossing js context,
  16248. // use Math.random to make id as unique as possible.
  16249. return [(type || ''), base++, Math.random().toFixed(5)].join('_');
  16250. }
  16251. /**
  16252. * @inner
  16253. */
  16254. function enableSubTypeDefaulter(entity) {
  16255. var subTypeDefaulters = {};
  16256. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  16257. componentType = parseClassType$1(componentType);
  16258. subTypeDefaulters[componentType.main] = defaulter;
  16259. };
  16260. entity.determineSubType = function (componentType, option) {
  16261. var type = option.type;
  16262. if (!type) {
  16263. var componentTypeMain = parseClassType$1(componentType).main;
  16264. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  16265. type = subTypeDefaulters[componentTypeMain](option);
  16266. }
  16267. }
  16268. return type;
  16269. };
  16270. return entity;
  16271. }
  16272. /**
  16273. * Topological travel on Activity Network (Activity On Vertices).
  16274. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  16275. *
  16276. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  16277. *
  16278. * If there is circle dependencey, Error will be thrown.
  16279. *
  16280. */
  16281. function enableTopologicalTravel(entity, dependencyGetter) {
  16282. /**
  16283. * @public
  16284. * @param {Array.<string>} targetNameList Target Component type list.
  16285. * Can be ['aa', 'bb', 'aa.xx']
  16286. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  16287. * @param {Function} callback Params: componentType, dependencies.
  16288. * @param {Object} context Scope of callback.
  16289. */
  16290. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  16291. if (!targetNameList.length) {
  16292. return;
  16293. }
  16294. var result = makeDepndencyGraph(fullNameList);
  16295. var graph = result.graph;
  16296. var stack = result.noEntryList;
  16297. var targetNameSet = {};
  16298. each$1(targetNameList, function (name) {
  16299. targetNameSet[name] = true;
  16300. });
  16301. while (stack.length) {
  16302. var currComponentType = stack.pop();
  16303. var currVertex = graph[currComponentType];
  16304. var isInTargetNameSet = !!targetNameSet[currComponentType];
  16305. if (isInTargetNameSet) {
  16306. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  16307. delete targetNameSet[currComponentType];
  16308. }
  16309. each$1(
  16310. currVertex.successor,
  16311. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  16312. );
  16313. }
  16314. each$1(targetNameSet, function () {
  16315. throw new Error('Circle dependency may exists');
  16316. });
  16317. function removeEdge(succComponentType) {
  16318. graph[succComponentType].entryCount--;
  16319. if (graph[succComponentType].entryCount === 0) {
  16320. stack.push(succComponentType);
  16321. }
  16322. }
  16323. // Consider this case: legend depends on series, and we call
  16324. // chart.setOption({series: [...]}), where only series is in option.
  16325. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  16326. // not be called, but only sereis.mergeOption is called. Thus legend
  16327. // have no chance to update its local record about series (like which
  16328. // name of series is available in legend).
  16329. function removeEdgeAndAdd(succComponentType) {
  16330. targetNameSet[succComponentType] = true;
  16331. removeEdge(succComponentType);
  16332. }
  16333. };
  16334. /**
  16335. * DepndencyGraph: {Object}
  16336. * key: conponentType,
  16337. * value: {
  16338. * successor: [conponentTypes...],
  16339. * originalDeps: [conponentTypes...],
  16340. * entryCount: {number}
  16341. * }
  16342. */
  16343. function makeDepndencyGraph(fullNameList) {
  16344. var graph = {};
  16345. var noEntryList = [];
  16346. each$1(fullNameList, function (name) {
  16347. var thisItem = createDependencyGraphItem(graph, name);
  16348. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  16349. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  16350. thisItem.entryCount = availableDeps.length;
  16351. if (thisItem.entryCount === 0) {
  16352. noEntryList.push(name);
  16353. }
  16354. each$1(availableDeps, function (dependentName) {
  16355. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  16356. thisItem.predecessor.push(dependentName);
  16357. }
  16358. var thatItem = createDependencyGraphItem(graph, dependentName);
  16359. if (indexOf(thatItem.successor, dependentName) < 0) {
  16360. thatItem.successor.push(name);
  16361. }
  16362. });
  16363. });
  16364. return {graph: graph, noEntryList: noEntryList};
  16365. }
  16366. function createDependencyGraphItem(graph, name) {
  16367. if (!graph[name]) {
  16368. graph[name] = {predecessor: [], successor: []};
  16369. }
  16370. return graph[name];
  16371. }
  16372. function getAvailableDependencies(originalDeps, fullNameList) {
  16373. var availableDeps = [];
  16374. each$1(originalDeps, function (dep) {
  16375. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  16376. });
  16377. return availableDeps;
  16378. }
  16379. }
  16380. /*
  16381. * Licensed to the Apache Software Foundation (ASF) under one
  16382. * or more contributor license agreements. See the NOTICE file
  16383. * distributed with this work for additional information
  16384. * regarding copyright ownership. The ASF licenses this file
  16385. * to you under the Apache License, Version 2.0 (the
  16386. * "License"); you may not use this file except in compliance
  16387. * with the License. You may obtain a copy of the License at
  16388. *
  16389. * http://www.apache.org/licenses/LICENSE-2.0
  16390. *
  16391. * Unless required by applicable law or agreed to in writing,
  16392. * software distributed under the License is distributed on an
  16393. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16394. * KIND, either express or implied. See the License for the
  16395. * specific language governing permissions and limitations
  16396. * under the License.
  16397. */
  16398. /*
  16399. * A third-party license is embeded for some of the code in this file:
  16400. * The method "quantile" was copied from "d3.js".
  16401. * (See more details in the comment of the method below.)
  16402. * The use of the source code of this file is also subject to the terms
  16403. * and consitions of the license of "d3.js" (BSD-3Clause, see
  16404. * </licenses/LICENSE-d3>).
  16405. */
  16406. var RADIAN_EPSILON = 1e-4;
  16407. function _trim(str) {
  16408. return str.replace(/^\s+|\s+$/g, '');
  16409. }
  16410. /**
  16411. * Linear mapping a value from domain to range
  16412. * @memberOf module:echarts/util/number
  16413. * @param {(number|Array.<number>)} val
  16414. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  16415. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  16416. * @param {boolean} clamp
  16417. * @return {(number|Array.<number>}
  16418. */
  16419. function linearMap(val, domain, range, clamp) {
  16420. var subDomain = domain[1] - domain[0];
  16421. var subRange = range[1] - range[0];
  16422. if (subDomain === 0) {
  16423. return subRange === 0
  16424. ? range[0]
  16425. : (range[0] + range[1]) / 2;
  16426. }
  16427. // Avoid accuracy problem in edge, such as
  16428. // 146.39 - 62.83 === 83.55999999999999.
  16429. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  16430. // It is a little verbose for efficiency considering this method
  16431. // is a hotspot.
  16432. if (clamp) {
  16433. if (subDomain > 0) {
  16434. if (val <= domain[0]) {
  16435. return range[0];
  16436. }
  16437. else if (val >= domain[1]) {
  16438. return range[1];
  16439. }
  16440. }
  16441. else {
  16442. if (val >= domain[0]) {
  16443. return range[0];
  16444. }
  16445. else if (val <= domain[1]) {
  16446. return range[1];
  16447. }
  16448. }
  16449. }
  16450. else {
  16451. if (val === domain[0]) {
  16452. return range[0];
  16453. }
  16454. if (val === domain[1]) {
  16455. return range[1];
  16456. }
  16457. }
  16458. return (val - domain[0]) / subDomain * subRange + range[0];
  16459. }
  16460. /**
  16461. * Convert a percent string to absolute number.
  16462. * Returns NaN if percent is not a valid string or number
  16463. * @memberOf module:echarts/util/number
  16464. * @param {string|number} percent
  16465. * @param {number} all
  16466. * @return {number}
  16467. */
  16468. function parsePercent$1(percent, all) {
  16469. switch (percent) {
  16470. case 'center':
  16471. case 'middle':
  16472. percent = '50%';
  16473. break;
  16474. case 'left':
  16475. case 'top':
  16476. percent = '0%';
  16477. break;
  16478. case 'right':
  16479. case 'bottom':
  16480. percent = '100%';
  16481. break;
  16482. }
  16483. if (typeof percent === 'string') {
  16484. if (_trim(percent).match(/%$/)) {
  16485. return parseFloat(percent) / 100 * all;
  16486. }
  16487. return parseFloat(percent);
  16488. }
  16489. return percent == null ? NaN : +percent;
  16490. }
  16491. /**
  16492. * (1) Fix rounding error of float numbers.
  16493. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  16494. *
  16495. * @param {number} x
  16496. * @param {number} [precision]
  16497. * @param {boolean} [returnStr]
  16498. * @return {number|string}
  16499. */
  16500. function round$1(x, precision, returnStr) {
  16501. if (precision == null) {
  16502. precision = 10;
  16503. }
  16504. // Avoid range error
  16505. precision = Math.min(Math.max(0, precision), 20);
  16506. x = (+x).toFixed(precision);
  16507. return returnStr ? x : +x;
  16508. }
  16509. /**
  16510. * asc sort arr.
  16511. * The input arr will be modified.
  16512. *
  16513. * @param {Array} arr
  16514. * @return {Array} The input arr.
  16515. */
  16516. /**
  16517. * Get precision
  16518. * @param {number} val
  16519. */
  16520. /**
  16521. * @param {string|number} val
  16522. * @return {number}
  16523. */
  16524. function getPrecisionSafe(val) {
  16525. var str = val.toString();
  16526. // Consider scientific notation: '3.4e-12' '3.4e+12'
  16527. var eIndex = str.indexOf('e');
  16528. if (eIndex > 0) {
  16529. var precision = +str.slice(eIndex + 1);
  16530. return precision < 0 ? -precision : 0;
  16531. }
  16532. else {
  16533. var dotIndex = str.indexOf('.');
  16534. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  16535. }
  16536. }
  16537. /**
  16538. * Minimal dicernible data precisioin according to a single pixel.
  16539. *
  16540. * @param {Array.<number>} dataExtent
  16541. * @param {Array.<number>} pixelExtent
  16542. * @return {number} precision
  16543. */
  16544. function getPixelPrecision(dataExtent, pixelExtent) {
  16545. var log = Math.log;
  16546. var LN10 = Math.LN10;
  16547. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  16548. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  16549. // toFixed() digits argument must be between 0 and 20.
  16550. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  16551. return !isFinite(precision) ? 20 : precision;
  16552. }
  16553. /**
  16554. * Get a data of given precision, assuring the sum of percentages
  16555. * in valueList is 1.
  16556. * The largest remainer method is used.
  16557. * https://en.wikipedia.org/wiki/Largest_remainder_method
  16558. *
  16559. * @param {Array.<number>} valueList a list of all data
  16560. * @param {number} idx index of the data to be processed in valueList
  16561. * @param {number} precision integer number showing digits of precision
  16562. * @return {number} percent ranging from 0 to 100
  16563. */
  16564. function getPercentWithPrecision(valueList, idx, precision) {
  16565. if (!valueList[idx]) {
  16566. return 0;
  16567. }
  16568. var sum = reduce(valueList, function (acc, val) {
  16569. return acc + (isNaN(val) ? 0 : val);
  16570. }, 0);
  16571. if (sum === 0) {
  16572. return 0;
  16573. }
  16574. var digits = Math.pow(10, precision);
  16575. var votesPerQuota = map(valueList, function (val) {
  16576. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  16577. });
  16578. var targetSeats = digits * 100;
  16579. var seats = map(votesPerQuota, function (votes) {
  16580. // Assign automatic seats.
  16581. return Math.floor(votes);
  16582. });
  16583. var currentSum = reduce(seats, function (acc, val) {
  16584. return acc + val;
  16585. }, 0);
  16586. var remainder = map(votesPerQuota, function (votes, idx) {
  16587. return votes - seats[idx];
  16588. });
  16589. // Has remainding votes.
  16590. while (currentSum < targetSeats) {
  16591. // Find next largest remainder.
  16592. var max = Number.NEGATIVE_INFINITY;
  16593. var maxId = null;
  16594. for (var i = 0, len = remainder.length; i < len; ++i) {
  16595. if (remainder[i] > max) {
  16596. max = remainder[i];
  16597. maxId = i;
  16598. }
  16599. }
  16600. // Add a vote to max remainder.
  16601. ++seats[maxId];
  16602. remainder[maxId] = 0;
  16603. ++currentSum;
  16604. }
  16605. return seats[idx] / digits;
  16606. }
  16607. // Number.MAX_SAFE_INTEGER, ie do not support.
  16608. /**
  16609. * To 0 - 2 * PI, considering negative radian.
  16610. * @param {number} radian
  16611. * @return {number}
  16612. */
  16613. function remRadian(radian) {
  16614. var pi2 = Math.PI * 2;
  16615. return (radian % pi2 + pi2) % pi2;
  16616. }
  16617. /**
  16618. * @param {type} radian
  16619. * @return {boolean}
  16620. */
  16621. function isRadianAroundZero(val) {
  16622. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  16623. }
  16624. /* eslint-disable */
  16625. 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
  16626. /* eslint-enable */
  16627. /**
  16628. * @param {string|Date|number} value These values can be accepted:
  16629. * + An instance of Date, represent a time in its own time zone.
  16630. * + Or string in a subset of ISO 8601, only including:
  16631. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  16632. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  16633. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  16634. * all of which will be treated as local time if time zone is not specified
  16635. * (see <https://momentjs.com/>).
  16636. * + Or other string format, including (all of which will be treated as loacal time):
  16637. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  16638. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  16639. * + a timestamp, which represent a time in UTC.
  16640. * @return {Date} date
  16641. */
  16642. function parseDate(value) {
  16643. if (value instanceof Date) {
  16644. return value;
  16645. }
  16646. else if (typeof value === 'string') {
  16647. // Different browsers parse date in different way, so we parse it manually.
  16648. // Some other issues:
  16649. // new Date('1970-01-01') is UTC,
  16650. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  16651. // See issue #3623
  16652. var match = TIME_REG.exec(value);
  16653. if (!match) {
  16654. // return Invalid Date.
  16655. return new Date(NaN);
  16656. }
  16657. // Use local time when no timezone offset specifed.
  16658. if (!match[8]) {
  16659. // match[n] can only be string or undefined.
  16660. // But take care of '12' + 1 => '121'.
  16661. return new Date(
  16662. +match[1],
  16663. +(match[2] || 1) - 1,
  16664. +match[3] || 1,
  16665. +match[4] || 0,
  16666. +(match[5] || 0),
  16667. +match[6] || 0,
  16668. +match[7] || 0
  16669. );
  16670. }
  16671. // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  16672. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  16673. // For example, system timezone is set as "Time Zone: America/Toronto",
  16674. // then these code will get different result:
  16675. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  16676. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  16677. // So we should not use `new Date`, but use `Date.UTC`.
  16678. else {
  16679. var hour = +match[4] || 0;
  16680. if (match[8].toUpperCase() !== 'Z') {
  16681. hour -= match[8].slice(0, 3);
  16682. }
  16683. return new Date(Date.UTC(
  16684. +match[1],
  16685. +(match[2] || 1) - 1,
  16686. +match[3] || 1,
  16687. hour,
  16688. +(match[5] || 0),
  16689. +match[6] || 0,
  16690. +match[7] || 0
  16691. ));
  16692. }
  16693. }
  16694. else if (value == null) {
  16695. return new Date(NaN);
  16696. }
  16697. return new Date(Math.round(value));
  16698. }
  16699. /**
  16700. * Quantity of a number. e.g. 0.1, 1, 10, 100
  16701. *
  16702. * @param {number} val
  16703. * @return {number}
  16704. */
  16705. function quantity(val) {
  16706. return Math.pow(10, quantityExponent(val));
  16707. }
  16708. /**
  16709. * Exponent of the quantity of a number
  16710. * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
  16711. *
  16712. * @param {number} val non-negative value
  16713. * @return {number}
  16714. */
  16715. function quantityExponent(val) {
  16716. if (val === 0) {
  16717. return 0;
  16718. }
  16719. var exp = Math.floor(Math.log(val) / Math.LN10);
  16720. /**
  16721. * exp is expected to be the rounded-down result of the base-10 log of val.
  16722. * But due to the precision loss with Math.log(val), we need to restore it
  16723. * using 10^exp to make sure we can get val back from exp. #11249
  16724. */
  16725. if (val / Math.pow(10, exp) >= 10) {
  16726. exp++;
  16727. }
  16728. return exp;
  16729. }
  16730. /**
  16731. * find a “nice” number approximately equal to x. Round the number if round = true,
  16732. * take ceiling if round = false. The primary observation is that the “nicest”
  16733. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  16734. *
  16735. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  16736. *
  16737. * @param {number} val Non-negative value.
  16738. * @param {boolean} round
  16739. * @return {number}
  16740. */
  16741. function nice(val, round) {
  16742. var exponent = quantityExponent(val);
  16743. var exp10 = Math.pow(10, exponent);
  16744. var f = val / exp10; // 1 <= f < 10
  16745. var nf;
  16746. if (round) {
  16747. if (f < 1.5) {
  16748. nf = 1;
  16749. }
  16750. else if (f < 2.5) {
  16751. nf = 2;
  16752. }
  16753. else if (f < 4) {
  16754. nf = 3;
  16755. }
  16756. else if (f < 7) {
  16757. nf = 5;
  16758. }
  16759. else {
  16760. nf = 10;
  16761. }
  16762. }
  16763. else {
  16764. if (f < 1) {
  16765. nf = 1;
  16766. }
  16767. else if (f < 2) {
  16768. nf = 2;
  16769. }
  16770. else if (f < 3) {
  16771. nf = 3;
  16772. }
  16773. else if (f < 5) {
  16774. nf = 5;
  16775. }
  16776. else {
  16777. nf = 10;
  16778. }
  16779. }
  16780. val = nf * exp10;
  16781. // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  16782. // 20 is the uppper bound of toFixed.
  16783. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  16784. }
  16785. /**
  16786. * This code was copied from "d3.js"
  16787. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  16788. * See the license statement at the head of this file.
  16789. * @param {Array.<number>} ascArr
  16790. */
  16791. /**
  16792. * Order intervals asc, and split them when overlap.
  16793. * expect(numberUtil.reformIntervals([
  16794. * {interval: [18, 62], close: [1, 1]},
  16795. * {interval: [-Infinity, -70], close: [0, 0]},
  16796. * {interval: [-70, -26], close: [1, 1]},
  16797. * {interval: [-26, 18], close: [1, 1]},
  16798. * {interval: [62, 150], close: [1, 1]},
  16799. * {interval: [106, 150], close: [1, 1]},
  16800. * {interval: [150, Infinity], close: [0, 0]}
  16801. * ])).toEqual([
  16802. * {interval: [-Infinity, -70], close: [0, 0]},
  16803. * {interval: [-70, -26], close: [1, 1]},
  16804. * {interval: [-26, 18], close: [0, 1]},
  16805. * {interval: [18, 62], close: [0, 1]},
  16806. * {interval: [62, 150], close: [0, 1]},
  16807. * {interval: [150, Infinity], close: [0, 0]}
  16808. * ]);
  16809. * @param {Array.<Object>} list, where `close` mean open or close
  16810. * of the interval, and Infinity can be used.
  16811. * @return {Array.<Object>} The origin list, which has been reformed.
  16812. */
  16813. /**
  16814. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  16815. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  16816. * subtraction forces infinities to NaN
  16817. *
  16818. * @param {*} v
  16819. * @return {boolean}
  16820. */
  16821. /*
  16822. * Licensed to the Apache Software Foundation (ASF) under one
  16823. * or more contributor license agreements. See the NOTICE file
  16824. * distributed with this work for additional information
  16825. * regarding copyright ownership. The ASF licenses this file
  16826. * to you under the Apache License, Version 2.0 (the
  16827. * "License"); you may not use this file except in compliance
  16828. * with the License. You may obtain a copy of the License at
  16829. *
  16830. * http://www.apache.org/licenses/LICENSE-2.0
  16831. *
  16832. * Unless required by applicable law or agreed to in writing,
  16833. * software distributed under the License is distributed on an
  16834. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16835. * KIND, either express or implied. See the License for the
  16836. * specific language governing permissions and limitations
  16837. * under the License.
  16838. */
  16839. // import Text from 'zrender/src/graphic/Text';
  16840. /**
  16841. * add commas after every three numbers
  16842. * @param {string|number} x
  16843. * @return {string}
  16844. */
  16845. function addCommas(x) {
  16846. if (isNaN(x)) {
  16847. return '-';
  16848. }
  16849. x = (x + '').split('.');
  16850. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,')
  16851. + (x.length > 1 ? ('.' + x[1]) : '');
  16852. }
  16853. /**
  16854. * @param {string} str
  16855. * @param {boolean} [upperCaseFirst=false]
  16856. * @return {string} str
  16857. */
  16858. var normalizeCssArray$1 = normalizeCssArray;
  16859. var replaceReg = /([&<>"'])/g;
  16860. var replaceMap = {
  16861. '&': '&amp;',
  16862. '<': '&lt;',
  16863. '>': '&gt;',
  16864. '"': '&quot;',
  16865. '\'': '&#39;'
  16866. };
  16867. function encodeHTML(source) {
  16868. return source == null
  16869. ? ''
  16870. : (source + '').replace(replaceReg, function (str, c) {
  16871. return replaceMap[c];
  16872. });
  16873. }
  16874. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  16875. var wrapVar = function (varName, seriesIdx) {
  16876. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  16877. };
  16878. /**
  16879. * Template formatter
  16880. * @param {string} tpl
  16881. * @param {Array.<Object>|Object} paramsList
  16882. * @param {boolean} [encode=false]
  16883. * @return {string}
  16884. */
  16885. function formatTpl(tpl, paramsList, encode) {
  16886. if (!isArray(paramsList)) {
  16887. paramsList = [paramsList];
  16888. }
  16889. var seriesLen = paramsList.length;
  16890. if (!seriesLen) {
  16891. return '';
  16892. }
  16893. var $vars = paramsList[0].$vars || [];
  16894. for (var i = 0; i < $vars.length; i++) {
  16895. var alias = TPL_VAR_ALIAS[i];
  16896. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  16897. }
  16898. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  16899. for (var k = 0; k < $vars.length; k++) {
  16900. var val = paramsList[seriesIdx][$vars[k]];
  16901. tpl = tpl.replace(
  16902. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  16903. encode ? encodeHTML(val) : val
  16904. );
  16905. }
  16906. }
  16907. return tpl;
  16908. }
  16909. /**
  16910. * simple Template formatter
  16911. *
  16912. * @param {string} tpl
  16913. * @param {Object} param
  16914. * @param {boolean} [encode=false]
  16915. * @return {string}
  16916. */
  16917. /**
  16918. * @param {Object|string} [opt] If string, means color.
  16919. * @param {string} [opt.color]
  16920. * @param {string} [opt.extraCssText]
  16921. * @param {string} [opt.type='item'] 'item' or 'subItem'
  16922. * @param {string} [opt.renderMode='html'] render mode of tooltip, 'html' or 'richText'
  16923. * @param {string} [opt.markerId='X'] id name for marker. If only one marker is in a rich text, this can be omitted.
  16924. * @return {string}
  16925. */
  16926. function getTooltipMarker(opt, extraCssText) {
  16927. opt = isString(opt) ? {color: opt, extraCssText: extraCssText} : (opt || {});
  16928. var color = opt.color;
  16929. var type = opt.type;
  16930. var extraCssText = opt.extraCssText;
  16931. var renderMode = opt.renderMode || 'html';
  16932. var markerId = opt.markerId || 'X';
  16933. if (!color) {
  16934. return '';
  16935. }
  16936. if (renderMode === 'html') {
  16937. return type === 'subItem'
  16938. ? '<span style="display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;'
  16939. + 'border-radius:4px;width:4px;height:4px;background-color:'
  16940. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>'
  16941. : '<span style="display:inline-block;margin-right:5px;'
  16942. + 'border-radius:10px;width:10px;height:10px;background-color:'
  16943. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>';
  16944. }
  16945. else {
  16946. // Space for rich element marker
  16947. return {
  16948. renderMode: renderMode,
  16949. content: '{marker' + markerId + '|} ',
  16950. style: {
  16951. color: color
  16952. }
  16953. };
  16954. }
  16955. }
  16956. function pad(str, len) {
  16957. str += '';
  16958. return '0000'.substr(0, len - str.length) + str;
  16959. }
  16960. /**
  16961. * ISO Date format
  16962. * @param {string} tpl
  16963. * @param {number} value
  16964. * @param {boolean} [isUTC=false] Default in local time.
  16965. * see `module:echarts/scale/Time`
  16966. * and `module:echarts/util/number#parseDate`.
  16967. * @inner
  16968. */
  16969. function formatTime(tpl, value, isUTC) {
  16970. if (tpl === 'week'
  16971. || tpl === 'month'
  16972. || tpl === 'quarter'
  16973. || tpl === 'half-year'
  16974. || tpl === 'year'
  16975. ) {
  16976. tpl = 'MM-dd\nyyyy';
  16977. }
  16978. var date = parseDate(value);
  16979. var utc = isUTC ? 'UTC' : '';
  16980. var y = date['get' + utc + 'FullYear']();
  16981. var M = date['get' + utc + 'Month']() + 1;
  16982. var d = date['get' + utc + 'Date']();
  16983. var h = date['get' + utc + 'Hours']();
  16984. var m = date['get' + utc + 'Minutes']();
  16985. var s = date['get' + utc + 'Seconds']();
  16986. var S = date['get' + utc + 'Milliseconds']();
  16987. tpl = tpl.replace('MM', pad(M, 2))
  16988. .replace('M', M)
  16989. .replace('yyyy', y)
  16990. .replace('yy', y % 100)
  16991. .replace('dd', pad(d, 2))
  16992. .replace('d', d)
  16993. .replace('hh', pad(h, 2))
  16994. .replace('h', h)
  16995. .replace('mm', pad(m, 2))
  16996. .replace('m', m)
  16997. .replace('ss', pad(s, 2))
  16998. .replace('s', s)
  16999. .replace('SSS', pad(S, 3));
  17000. return tpl;
  17001. }
  17002. /**
  17003. * Capital first
  17004. * @param {string} str
  17005. * @return {string}
  17006. */
  17007. var truncateText$1 = truncateText;
  17008. /**
  17009. * @public
  17010. * @param {Object} opt
  17011. * @param {string} opt.text
  17012. * @param {string} opt.font
  17013. * @param {string} [opt.textAlign='left']
  17014. * @param {string} [opt.textVerticalAlign='top']
  17015. * @param {Array.<number>} [opt.textPadding]
  17016. * @param {number} [opt.textLineHeight]
  17017. * @param {Object} [opt.rich]
  17018. * @param {Object} [opt.truncate]
  17019. * @return {Object} {x, y, width, height, lineHeight}
  17020. */
  17021. /**
  17022. * @deprecated
  17023. * the `textLineHeight` was added later.
  17024. * For backward compatiblility, put it as the last parameter.
  17025. * But deprecated this interface. Please use `getTextBoundingRect` instead.
  17026. */
  17027. /**
  17028. * open new tab
  17029. * @param {string} link url
  17030. * @param {string} target blank or self
  17031. */
  17032. /*
  17033. * Licensed to the Apache Software Foundation (ASF) under one
  17034. * or more contributor license agreements. See the NOTICE file
  17035. * distributed with this work for additional information
  17036. * regarding copyright ownership. The ASF licenses this file
  17037. * to you under the Apache License, Version 2.0 (the
  17038. * "License"); you may not use this file except in compliance
  17039. * with the License. You may obtain a copy of the License at
  17040. *
  17041. * http://www.apache.org/licenses/LICENSE-2.0
  17042. *
  17043. * Unless required by applicable law or agreed to in writing,
  17044. * software distributed under the License is distributed on an
  17045. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17046. * KIND, either express or implied. See the License for the
  17047. * specific language governing permissions and limitations
  17048. * under the License.
  17049. */
  17050. // Layout helpers for each component positioning
  17051. var each$3 = each$1;
  17052. /**
  17053. * @public
  17054. */
  17055. var LOCATION_PARAMS = [
  17056. 'left', 'right', 'top', 'bottom', 'width', 'height'
  17057. ];
  17058. /**
  17059. * @public
  17060. */
  17061. var HV_NAMES = [
  17062. ['width', 'left', 'right'],
  17063. ['height', 'top', 'bottom']
  17064. ];
  17065. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  17066. var x = 0;
  17067. var y = 0;
  17068. if (maxWidth == null) {
  17069. maxWidth = Infinity;
  17070. }
  17071. if (maxHeight == null) {
  17072. maxHeight = Infinity;
  17073. }
  17074. var currentLineMaxSize = 0;
  17075. group.eachChild(function (child, idx) {
  17076. var position = child.position;
  17077. var rect = child.getBoundingRect();
  17078. var nextChild = group.childAt(idx + 1);
  17079. var nextChildRect = nextChild && nextChild.getBoundingRect();
  17080. var nextX;
  17081. var nextY;
  17082. if (orient === 'horizontal') {
  17083. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  17084. nextX = x + moveX;
  17085. // Wrap when width exceeds maxWidth or meet a `newline` group
  17086. // FIXME compare before adding gap?
  17087. if (nextX > maxWidth || child.newline) {
  17088. x = 0;
  17089. nextX = moveX;
  17090. y += currentLineMaxSize + gap;
  17091. currentLineMaxSize = rect.height;
  17092. }
  17093. else {
  17094. // FIXME: consider rect.y is not `0`?
  17095. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  17096. }
  17097. }
  17098. else {
  17099. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  17100. nextY = y + moveY;
  17101. // Wrap when width exceeds maxHeight or meet a `newline` group
  17102. if (nextY > maxHeight || child.newline) {
  17103. x += currentLineMaxSize + gap;
  17104. y = 0;
  17105. nextY = moveY;
  17106. currentLineMaxSize = rect.width;
  17107. }
  17108. else {
  17109. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  17110. }
  17111. }
  17112. if (child.newline) {
  17113. return;
  17114. }
  17115. position[0] = x;
  17116. position[1] = y;
  17117. orient === 'horizontal'
  17118. ? (x = nextX + gap)
  17119. : (y = nextY + gap);
  17120. });
  17121. }
  17122. /**
  17123. * VBox or HBox layouting
  17124. * @param {string} orient
  17125. * @param {module:zrender/container/Group} group
  17126. * @param {number} gap
  17127. * @param {number} [width=Infinity]
  17128. * @param {number} [height=Infinity]
  17129. */
  17130. /**
  17131. * VBox layouting
  17132. * @param {module:zrender/container/Group} group
  17133. * @param {number} gap
  17134. * @param {number} [width=Infinity]
  17135. * @param {number} [height=Infinity]
  17136. */
  17137. var vbox = curry(boxLayout, 'vertical');
  17138. /**
  17139. * HBox layouting
  17140. * @param {module:zrender/container/Group} group
  17141. * @param {number} gap
  17142. * @param {number} [width=Infinity]
  17143. * @param {number} [height=Infinity]
  17144. */
  17145. var hbox = curry(boxLayout, 'horizontal');
  17146. /**
  17147. * If x or x2 is not specified or 'center' 'left' 'right',
  17148. * the width would be as long as possible.
  17149. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  17150. * the height would be as long as possible.
  17151. *
  17152. * @param {Object} positionInfo
  17153. * @param {number|string} [positionInfo.x]
  17154. * @param {number|string} [positionInfo.y]
  17155. * @param {number|string} [positionInfo.x2]
  17156. * @param {number|string} [positionInfo.y2]
  17157. * @param {Object} containerRect {width, height}
  17158. * @param {string|number} margin
  17159. * @return {Object} {width, height}
  17160. */
  17161. /**
  17162. * Parse position info.
  17163. *
  17164. * @param {Object} positionInfo
  17165. * @param {number|string} [positionInfo.left]
  17166. * @param {number|string} [positionInfo.top]
  17167. * @param {number|string} [positionInfo.right]
  17168. * @param {number|string} [positionInfo.bottom]
  17169. * @param {number|string} [positionInfo.width]
  17170. * @param {number|string} [positionInfo.height]
  17171. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  17172. * @param {Object} containerRect
  17173. * @param {string|number} [margin]
  17174. *
  17175. * @return {module:zrender/core/BoundingRect}
  17176. */
  17177. function getLayoutRect(
  17178. positionInfo, containerRect, margin
  17179. ) {
  17180. margin = normalizeCssArray$1(margin || 0);
  17181. var containerWidth = containerRect.width;
  17182. var containerHeight = containerRect.height;
  17183. var left = parsePercent$1(positionInfo.left, containerWidth);
  17184. var top = parsePercent$1(positionInfo.top, containerHeight);
  17185. var right = parsePercent$1(positionInfo.right, containerWidth);
  17186. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  17187. var width = parsePercent$1(positionInfo.width, containerWidth);
  17188. var height = parsePercent$1(positionInfo.height, containerHeight);
  17189. var verticalMargin = margin[2] + margin[0];
  17190. var horizontalMargin = margin[1] + margin[3];
  17191. var aspect = positionInfo.aspect;
  17192. // If width is not specified, calculate width from left and right
  17193. if (isNaN(width)) {
  17194. width = containerWidth - right - horizontalMargin - left;
  17195. }
  17196. if (isNaN(height)) {
  17197. height = containerHeight - bottom - verticalMargin - top;
  17198. }
  17199. if (aspect != null) {
  17200. // If width and height are not given
  17201. // 1. Graph should not exceeds the container
  17202. // 2. Aspect must be keeped
  17203. // 3. Graph should take the space as more as possible
  17204. // FIXME
  17205. // Margin is not considered, because there is no case that both
  17206. // using margin and aspect so far.
  17207. if (isNaN(width) && isNaN(height)) {
  17208. if (aspect > containerWidth / containerHeight) {
  17209. width = containerWidth * 0.8;
  17210. }
  17211. else {
  17212. height = containerHeight * 0.8;
  17213. }
  17214. }
  17215. // Calculate width or height with given aspect
  17216. if (isNaN(width)) {
  17217. width = aspect * height;
  17218. }
  17219. if (isNaN(height)) {
  17220. height = width / aspect;
  17221. }
  17222. }
  17223. // If left is not specified, calculate left from right and width
  17224. if (isNaN(left)) {
  17225. left = containerWidth - right - width - horizontalMargin;
  17226. }
  17227. if (isNaN(top)) {
  17228. top = containerHeight - bottom - height - verticalMargin;
  17229. }
  17230. // Align left and top
  17231. switch (positionInfo.left || positionInfo.right) {
  17232. case 'center':
  17233. left = containerWidth / 2 - width / 2 - margin[3];
  17234. break;
  17235. case 'right':
  17236. left = containerWidth - width - horizontalMargin;
  17237. break;
  17238. }
  17239. switch (positionInfo.top || positionInfo.bottom) {
  17240. case 'middle':
  17241. case 'center':
  17242. top = containerHeight / 2 - height / 2 - margin[0];
  17243. break;
  17244. case 'bottom':
  17245. top = containerHeight - height - verticalMargin;
  17246. break;
  17247. }
  17248. // If something is wrong and left, top, width, height are calculated as NaN
  17249. left = left || 0;
  17250. top = top || 0;
  17251. if (isNaN(width)) {
  17252. // Width may be NaN if only one value is given except width
  17253. width = containerWidth - horizontalMargin - left - (right || 0);
  17254. }
  17255. if (isNaN(height)) {
  17256. // Height may be NaN if only one value is given except height
  17257. height = containerHeight - verticalMargin - top - (bottom || 0);
  17258. }
  17259. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  17260. rect.margin = margin;
  17261. return rect;
  17262. }
  17263. /**
  17264. * Position a zr element in viewport
  17265. * Group position is specified by either
  17266. * {left, top}, {right, bottom}
  17267. * If all properties exists, right and bottom will be igonred.
  17268. *
  17269. * Logic:
  17270. * 1. Scale (against origin point in parent coord)
  17271. * 2. Rotate (against origin point in parent coord)
  17272. * 3. Traslate (with el.position by this method)
  17273. * So this method only fixes the last step 'Traslate', which does not affect
  17274. * scaling and rotating.
  17275. *
  17276. * If be called repeatly with the same input el, the same result will be gotten.
  17277. *
  17278. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  17279. * @param {Object} positionInfo
  17280. * @param {number|string} [positionInfo.left]
  17281. * @param {number|string} [positionInfo.top]
  17282. * @param {number|string} [positionInfo.right]
  17283. * @param {number|string} [positionInfo.bottom]
  17284. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  17285. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  17286. * @param {Object} containerRect
  17287. * @param {string|number} margin
  17288. * @param {Object} [opt]
  17289. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  17290. * @param {Array.<number>} [opt.boundingMode='all']
  17291. * Specify how to calculate boundingRect when locating.
  17292. * 'all': Position the boundingRect that is transformed and uioned
  17293. * both itself and its descendants.
  17294. * This mode simplies confine the elements in the bounding
  17295. * of their container (e.g., using 'right: 0').
  17296. * 'raw': Position the boundingRect that is not transformed and only itself.
  17297. * This mode is useful when you want a element can overflow its
  17298. * container. (Consider a rotated circle needs to be located in a corner.)
  17299. * In this mode positionInfo.width/height can only be number.
  17300. */
  17301. /**
  17302. * @param {Object} option Contains some of the properties in HV_NAMES.
  17303. * @param {number} hvIdx 0: horizontal; 1: vertical.
  17304. */
  17305. /**
  17306. * Consider Case:
  17307. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  17308. * through setOption or media query, using normal zrUtil.merge will cause
  17309. * {right: 0} does not take effect.
  17310. *
  17311. * @example
  17312. * ComponentModel.extend({
  17313. * init: function () {
  17314. * ...
  17315. * var inputPositionParams = layout.getLayoutParams(option);
  17316. * this.mergeOption(inputPositionParams);
  17317. * },
  17318. * mergeOption: function (newOption) {
  17319. * newOption && zrUtil.merge(thisOption, newOption, true);
  17320. * layout.mergeLayoutParam(thisOption, newOption);
  17321. * }
  17322. * });
  17323. *
  17324. * @param {Object} targetOption
  17325. * @param {Object} newOption
  17326. * @param {Object|string} [opt]
  17327. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  17328. * that width (or height) should not be calculated by left and right (or top and bottom).
  17329. */
  17330. function mergeLayoutParam(targetOption, newOption, opt) {
  17331. !isObject$1(opt) && (opt = {});
  17332. var ignoreSize = opt.ignoreSize;
  17333. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  17334. var hResult = merge$$1(HV_NAMES[0], 0);
  17335. var vResult = merge$$1(HV_NAMES[1], 1);
  17336. copy(HV_NAMES[0], targetOption, hResult);
  17337. copy(HV_NAMES[1], targetOption, vResult);
  17338. function merge$$1(names, hvIdx) {
  17339. var newParams = {};
  17340. var newValueCount = 0;
  17341. var merged = {};
  17342. var mergedValueCount = 0;
  17343. var enoughParamNumber = 2;
  17344. each$3(names, function (name) {
  17345. merged[name] = targetOption[name];
  17346. });
  17347. each$3(names, function (name) {
  17348. // Consider case: newOption.width is null, which is
  17349. // set by user for removing width setting.
  17350. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  17351. hasValue(newParams, name) && newValueCount++;
  17352. hasValue(merged, name) && mergedValueCount++;
  17353. });
  17354. if (ignoreSize[hvIdx]) {
  17355. // Only one of left/right is premitted to exist.
  17356. if (hasValue(newOption, names[1])) {
  17357. merged[names[2]] = null;
  17358. }
  17359. else if (hasValue(newOption, names[2])) {
  17360. merged[names[1]] = null;
  17361. }
  17362. return merged;
  17363. }
  17364. // Case: newOption: {width: ..., right: ...},
  17365. // or targetOption: {right: ...} and newOption: {width: ...},
  17366. // There is no conflict when merged only has params count
  17367. // little than enoughParamNumber.
  17368. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  17369. return merged;
  17370. }
  17371. // Case: newOption: {width: ..., right: ...},
  17372. // Than we can make sure user only want those two, and ignore
  17373. // all origin params in targetOption.
  17374. else if (newValueCount >= enoughParamNumber) {
  17375. return newParams;
  17376. }
  17377. else {
  17378. // Chose another param from targetOption by priority.
  17379. for (var i = 0; i < names.length; i++) {
  17380. var name = names[i];
  17381. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  17382. newParams[name] = targetOption[name];
  17383. break;
  17384. }
  17385. }
  17386. return newParams;
  17387. }
  17388. }
  17389. function hasProp(obj, name) {
  17390. return obj.hasOwnProperty(name);
  17391. }
  17392. function hasValue(obj, name) {
  17393. return obj[name] != null && obj[name] !== 'auto';
  17394. }
  17395. function copy(names, target, source) {
  17396. each$3(names, function (name) {
  17397. target[name] = source[name];
  17398. });
  17399. }
  17400. }
  17401. /**
  17402. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17403. * @param {Object} source
  17404. * @return {Object} Result contains those props.
  17405. */
  17406. function getLayoutParams(source) {
  17407. return copyLayoutParams({}, source);
  17408. }
  17409. /**
  17410. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17411. * @param {Object} source
  17412. * @return {Object} Result contains those props.
  17413. */
  17414. function copyLayoutParams(target, source) {
  17415. source && target && each$3(LOCATION_PARAMS, function (name) {
  17416. source.hasOwnProperty(name) && (target[name] = source[name]);
  17417. });
  17418. return target;
  17419. }
  17420. /*
  17421. * Licensed to the Apache Software Foundation (ASF) under one
  17422. * or more contributor license agreements. See the NOTICE file
  17423. * distributed with this work for additional information
  17424. * regarding copyright ownership. The ASF licenses this file
  17425. * to you under the Apache License, Version 2.0 (the
  17426. * "License"); you may not use this file except in compliance
  17427. * with the License. You may obtain a copy of the License at
  17428. *
  17429. * http://www.apache.org/licenses/LICENSE-2.0
  17430. *
  17431. * Unless required by applicable law or agreed to in writing,
  17432. * software distributed under the License is distributed on an
  17433. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17434. * KIND, either express or implied. See the License for the
  17435. * specific language governing permissions and limitations
  17436. * under the License.
  17437. */
  17438. var boxLayoutMixin = {
  17439. getBoxLayoutParams: function () {
  17440. return {
  17441. left: this.get('left'),
  17442. top: this.get('top'),
  17443. right: this.get('right'),
  17444. bottom: this.get('bottom'),
  17445. width: this.get('width'),
  17446. height: this.get('height')
  17447. };
  17448. }
  17449. };
  17450. /*
  17451. * Licensed to the Apache Software Foundation (ASF) under one
  17452. * or more contributor license agreements. See the NOTICE file
  17453. * distributed with this work for additional information
  17454. * regarding copyright ownership. The ASF licenses this file
  17455. * to you under the Apache License, Version 2.0 (the
  17456. * "License"); you may not use this file except in compliance
  17457. * with the License. You may obtain a copy of the License at
  17458. *
  17459. * http://www.apache.org/licenses/LICENSE-2.0
  17460. *
  17461. * Unless required by applicable law or agreed to in writing,
  17462. * software distributed under the License is distributed on an
  17463. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17464. * KIND, either express or implied. See the License for the
  17465. * specific language governing permissions and limitations
  17466. * under the License.
  17467. */
  17468. /**
  17469. * Component model
  17470. *
  17471. * @module echarts/model/Component
  17472. */
  17473. var inner$1 = makeInner();
  17474. /**
  17475. * @alias module:echarts/model/Component
  17476. * @constructor
  17477. * @param {Object} option
  17478. * @param {module:echarts/model/Model} parentModel
  17479. * @param {module:echarts/model/Model} ecModel
  17480. */
  17481. var ComponentModel = Model.extend({
  17482. type: 'component',
  17483. /**
  17484. * @readOnly
  17485. * @type {string}
  17486. */
  17487. id: '',
  17488. /**
  17489. * Because simplified concept is probably better, series.name (or component.name)
  17490. * has been having too many resposibilities:
  17491. * (1) Generating id (which requires name in option should not be modified).
  17492. * (2) As an index to mapping series when merging option or calling API (a name
  17493. * can refer to more then one components, which is convinient is some case).
  17494. * (3) Display.
  17495. * @readOnly
  17496. */
  17497. name: '',
  17498. /**
  17499. * @readOnly
  17500. * @type {string}
  17501. */
  17502. mainType: '',
  17503. /**
  17504. * @readOnly
  17505. * @type {string}
  17506. */
  17507. subType: '',
  17508. /**
  17509. * @readOnly
  17510. * @type {number}
  17511. */
  17512. componentIndex: 0,
  17513. /**
  17514. * @type {Object}
  17515. * @protected
  17516. */
  17517. defaultOption: null,
  17518. /**
  17519. * @type {module:echarts/model/Global}
  17520. * @readOnly
  17521. */
  17522. ecModel: null,
  17523. /**
  17524. * key: componentType
  17525. * value: Component model list, can not be null.
  17526. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  17527. * @readOnly
  17528. */
  17529. dependentModels: [],
  17530. /**
  17531. * @type {string}
  17532. * @readOnly
  17533. */
  17534. uid: null,
  17535. /**
  17536. * Support merge layout params.
  17537. * Only support 'box' now (left/right/top/bottom/width/height).
  17538. * @type {string|Object} Object can be {ignoreSize: true}
  17539. * @readOnly
  17540. */
  17541. layoutMode: null,
  17542. $constructor: function (option, parentModel, ecModel, extraOpt) {
  17543. Model.call(this, option, parentModel, ecModel, extraOpt);
  17544. this.uid = getUID('ec_cpt_model');
  17545. },
  17546. init: function (option, parentModel, ecModel, extraOpt) {
  17547. this.mergeDefaultAndTheme(option, ecModel);
  17548. },
  17549. mergeDefaultAndTheme: function (option, ecModel) {
  17550. var layoutMode = this.layoutMode;
  17551. var inputPositionParams = layoutMode
  17552. ? getLayoutParams(option) : {};
  17553. var themeModel = ecModel.getTheme();
  17554. merge(option, themeModel.get(this.mainType));
  17555. merge(option, this.getDefaultOption());
  17556. if (layoutMode) {
  17557. mergeLayoutParam(option, inputPositionParams, layoutMode);
  17558. }
  17559. },
  17560. mergeOption: function (option, extraOpt) {
  17561. merge(this.option, option, true);
  17562. var layoutMode = this.layoutMode;
  17563. if (layoutMode) {
  17564. mergeLayoutParam(this.option, option, layoutMode);
  17565. }
  17566. },
  17567. // Hooker after init or mergeOption
  17568. optionUpdated: function (newCptOption, isInit) {},
  17569. getDefaultOption: function () {
  17570. var fields = inner$1(this);
  17571. if (!fields.defaultOption) {
  17572. var optList = [];
  17573. var Class = this.constructor;
  17574. while (Class) {
  17575. var opt = Class.prototype.defaultOption;
  17576. opt && optList.push(opt);
  17577. Class = Class.superClass;
  17578. }
  17579. var defaultOption = {};
  17580. for (var i = optList.length - 1; i >= 0; i--) {
  17581. defaultOption = merge(defaultOption, optList[i], true);
  17582. }
  17583. fields.defaultOption = defaultOption;
  17584. }
  17585. return fields.defaultOption;
  17586. },
  17587. getReferringComponents: function (mainType) {
  17588. return this.ecModel.queryComponents({
  17589. mainType: mainType,
  17590. index: this.get(mainType + 'Index', true),
  17591. id: this.get(mainType + 'Id', true)
  17592. });
  17593. }
  17594. });
  17595. // Reset ComponentModel.extend, add preConstruct.
  17596. // clazzUtil.enableClassExtend(
  17597. // ComponentModel,
  17598. // function (option, parentModel, ecModel, extraOpt) {
  17599. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  17600. // zrUtil.extend(this, extraOpt);
  17601. // this.uid = componentUtil.getUID('componentModel');
  17602. // // this.setReadOnly([
  17603. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  17604. // // 'dependentModels', 'componentIndex'
  17605. // // ]);
  17606. // }
  17607. // );
  17608. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  17609. enableClassManagement(
  17610. ComponentModel, {registerWhenExtend: true}
  17611. );
  17612. enableSubTypeDefaulter(ComponentModel);
  17613. // Add capability of ComponentModel.topologicalTravel.
  17614. enableTopologicalTravel(ComponentModel, getDependencies);
  17615. function getDependencies(componentType) {
  17616. var deps = [];
  17617. each$1(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  17618. deps = deps.concat(Clazz.prototype.dependencies || []);
  17619. });
  17620. // Ensure main type.
  17621. deps = map(deps, function (type) {
  17622. return parseClassType$1(type).main;
  17623. });
  17624. // Hack dataset for convenience.
  17625. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  17626. deps.unshift('dataset');
  17627. }
  17628. return deps;
  17629. }
  17630. mixin(ComponentModel, boxLayoutMixin);
  17631. /*
  17632. * Licensed to the Apache Software Foundation (ASF) under one
  17633. * or more contributor license agreements. See the NOTICE file
  17634. * distributed with this work for additional information
  17635. * regarding copyright ownership. The ASF licenses this file
  17636. * to you under the Apache License, Version 2.0 (the
  17637. * "License"); you may not use this file except in compliance
  17638. * with the License. You may obtain a copy of the License at
  17639. *
  17640. * http://www.apache.org/licenses/LICENSE-2.0
  17641. *
  17642. * Unless required by applicable law or agreed to in writing,
  17643. * software distributed under the License is distributed on an
  17644. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17645. * KIND, either express or implied. See the License for the
  17646. * specific language governing permissions and limitations
  17647. * under the License.
  17648. */
  17649. var platform = '';
  17650. // Navigator not exists in node
  17651. if (typeof navigator !== 'undefined') {
  17652. platform = navigator.platform || '';
  17653. }
  17654. var globalDefault = {
  17655. // backgroundColor: 'rgba(0,0,0,0)',
  17656. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  17657. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  17658. // Light colors:
  17659. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  17660. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  17661. // Dark colors:
  17662. color: [
  17663. '#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83',
  17664. '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'
  17665. ],
  17666. gradientColor: ['#f6efa6', '#d88273', '#bf444c'],
  17667. // If xAxis and yAxis declared, grid is created by default.
  17668. // grid: {},
  17669. textStyle: {
  17670. // color: '#000',
  17671. // decoration: 'none',
  17672. // PENDING
  17673. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  17674. // fontFamily: 'Arial, Verdana, sans-serif',
  17675. fontSize: 12,
  17676. fontStyle: 'normal',
  17677. fontWeight: 'normal'
  17678. },
  17679. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  17680. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  17681. // Default is source-over
  17682. blendMode: null,
  17683. animation: 'auto',
  17684. animationDuration: 1000,
  17685. animationDurationUpdate: 300,
  17686. animationEasing: 'exponentialOut',
  17687. animationEasingUpdate: 'cubicOut',
  17688. animationThreshold: 2000,
  17689. // Configuration for progressive/incremental rendering
  17690. progressiveThreshold: 3000,
  17691. progressive: 400,
  17692. // Threshold of if use single hover layer to optimize.
  17693. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  17694. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  17695. // which is unexpected.
  17696. // see example <echarts/test/heatmap-large.html>.
  17697. hoverLayerThreshold: 3000,
  17698. // See: module:echarts/scale/Time
  17699. useUTC: false
  17700. };
  17701. /*
  17702. * Licensed to the Apache Software Foundation (ASF) under one
  17703. * or more contributor license agreements. See the NOTICE file
  17704. * distributed with this work for additional information
  17705. * regarding copyright ownership. The ASF licenses this file
  17706. * to you under the Apache License, Version 2.0 (the
  17707. * "License"); you may not use this file except in compliance
  17708. * with the License. You may obtain a copy of the License at
  17709. *
  17710. * http://www.apache.org/licenses/LICENSE-2.0
  17711. *
  17712. * Unless required by applicable law or agreed to in writing,
  17713. * software distributed under the License is distributed on an
  17714. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17715. * KIND, either express or implied. See the License for the
  17716. * specific language governing permissions and limitations
  17717. * under the License.
  17718. */
  17719. var inner$2 = makeInner();
  17720. function getNearestColorPalette(colors, requestColorNum) {
  17721. var paletteNum = colors.length;
  17722. // TODO colors must be in order
  17723. for (var i = 0; i < paletteNum; i++) {
  17724. if (colors[i].length > requestColorNum) {
  17725. return colors[i];
  17726. }
  17727. }
  17728. return colors[paletteNum - 1];
  17729. }
  17730. var colorPaletteMixin = {
  17731. clearColorPalette: function () {
  17732. inner$2(this).colorIdx = 0;
  17733. inner$2(this).colorNameMap = {};
  17734. },
  17735. /**
  17736. * @param {string} name MUST NOT be null/undefined. Otherwise call this function
  17737. * twise with the same parameters will get different result.
  17738. * @param {Object} [scope=this]
  17739. * @param {Object} [requestColorNum]
  17740. * @return {string} color string.
  17741. */
  17742. getColorFromPalette: function (name, scope, requestColorNum) {
  17743. scope = scope || this;
  17744. var scopeFields = inner$2(scope);
  17745. var colorIdx = scopeFields.colorIdx || 0;
  17746. var colorNameMap = scopeFields.colorNameMap = scopeFields.colorNameMap || {};
  17747. // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  17748. if (colorNameMap.hasOwnProperty(name)) {
  17749. return colorNameMap[name];
  17750. }
  17751. var defaultColorPalette = normalizeToArray(this.get('color', true));
  17752. var layeredColorPalette = this.get('colorLayer', true);
  17753. var colorPalette = ((requestColorNum == null || !layeredColorPalette)
  17754. ? defaultColorPalette : getNearestColorPalette(layeredColorPalette, requestColorNum));
  17755. // In case can't find in layered color palette.
  17756. colorPalette = colorPalette || defaultColorPalette;
  17757. if (!colorPalette || !colorPalette.length) {
  17758. return;
  17759. }
  17760. var color = colorPalette[colorIdx];
  17761. if (name) {
  17762. colorNameMap[name] = color;
  17763. }
  17764. scopeFields.colorIdx = (colorIdx + 1) % colorPalette.length;
  17765. return color;
  17766. }
  17767. };
  17768. /*
  17769. * Licensed to the Apache Software Foundation (ASF) under one
  17770. * or more contributor license agreements. See the NOTICE file
  17771. * distributed with this work for additional information
  17772. * regarding copyright ownership. The ASF licenses this file
  17773. * to you under the Apache License, Version 2.0 (the
  17774. * "License"); you may not use this file except in compliance
  17775. * with the License. You may obtain a copy of the License at
  17776. *
  17777. * http://www.apache.org/licenses/LICENSE-2.0
  17778. *
  17779. * Unless required by applicable law or agreed to in writing,
  17780. * software distributed under the License is distributed on an
  17781. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17782. * KIND, either express or implied. See the License for the
  17783. * specific language governing permissions and limitations
  17784. * under the License.
  17785. */
  17786. // Avoid typo.
  17787. var SOURCE_FORMAT_ORIGINAL = 'original';
  17788. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  17789. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  17790. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  17791. var SOURCE_FORMAT_UNKNOWN = 'unknown';
  17792. // ??? CHANGE A NAME
  17793. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  17794. var SERIES_LAYOUT_BY_COLUMN = 'column';
  17795. var SERIES_LAYOUT_BY_ROW = 'row';
  17796. /*
  17797. * Licensed to the Apache Software Foundation (ASF) under one
  17798. * or more contributor license agreements. See the NOTICE file
  17799. * distributed with this work for additional information
  17800. * regarding copyright ownership. The ASF licenses this file
  17801. * to you under the Apache License, Version 2.0 (the
  17802. * "License"); you may not use this file except in compliance
  17803. * with the License. You may obtain a copy of the License at
  17804. *
  17805. * http://www.apache.org/licenses/LICENSE-2.0
  17806. *
  17807. * Unless required by applicable law or agreed to in writing,
  17808. * software distributed under the License is distributed on an
  17809. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17810. * KIND, either express or implied. See the License for the
  17811. * specific language governing permissions and limitations
  17812. * under the License.
  17813. */
  17814. /**
  17815. * [sourceFormat]
  17816. *
  17817. * + "original":
  17818. * This format is only used in series.data, where
  17819. * itemStyle can be specified in data item.
  17820. *
  17821. * + "arrayRows":
  17822. * [
  17823. * ['product', 'score', 'amount'],
  17824. * ['Matcha Latte', 89.3, 95.8],
  17825. * ['Milk Tea', 92.1, 89.4],
  17826. * ['Cheese Cocoa', 94.4, 91.2],
  17827. * ['Walnut Brownie', 85.4, 76.9]
  17828. * ]
  17829. *
  17830. * + "objectRows":
  17831. * [
  17832. * {product: 'Matcha Latte', score: 89.3, amount: 95.8},
  17833. * {product: 'Milk Tea', score: 92.1, amount: 89.4},
  17834. * {product: 'Cheese Cocoa', score: 94.4, amount: 91.2},
  17835. * {product: 'Walnut Brownie', score: 85.4, amount: 76.9}
  17836. * ]
  17837. *
  17838. * + "keyedColumns":
  17839. * {
  17840. * 'product': ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
  17841. * 'count': [823, 235, 1042, 988],
  17842. * 'score': [95.8, 81.4, 91.2, 76.9]
  17843. * }
  17844. *
  17845. * + "typedArray"
  17846. *
  17847. * + "unknown"
  17848. */
  17849. /**
  17850. * @constructor
  17851. * @param {Object} fields
  17852. * @param {string} fields.sourceFormat
  17853. * @param {Array|Object} fields.fromDataset
  17854. * @param {Array|Object} [fields.data]
  17855. * @param {string} [seriesLayoutBy='column']
  17856. * @param {Array.<Object|string>} [dimensionsDefine]
  17857. * @param {Objet|HashMap} [encodeDefine]
  17858. * @param {number} [startIndex=0]
  17859. * @param {number} [dimensionsDetectCount]
  17860. */
  17861. function Source(fields) {
  17862. /**
  17863. * @type {boolean}
  17864. */
  17865. this.fromDataset = fields.fromDataset;
  17866. /**
  17867. * Not null/undefined.
  17868. * @type {Array|Object}
  17869. */
  17870. this.data = fields.data || (
  17871. fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []
  17872. );
  17873. /**
  17874. * See also "detectSourceFormat".
  17875. * Not null/undefined.
  17876. * @type {string}
  17877. */
  17878. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
  17879. /**
  17880. * 'row' or 'column'
  17881. * Not null/undefined.
  17882. * @type {string} seriesLayoutBy
  17883. */
  17884. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  17885. /**
  17886. * dimensions definition in option.
  17887. * can be null/undefined.
  17888. * @type {Array.<Object|string>}
  17889. */
  17890. this.dimensionsDefine = fields.dimensionsDefine;
  17891. /**
  17892. * encode definition in option.
  17893. * can be null/undefined.
  17894. * @type {Objet|HashMap}
  17895. */
  17896. this.encodeDefine = fields.encodeDefine && createHashMap(fields.encodeDefine);
  17897. /**
  17898. * Not null/undefined, uint.
  17899. * @type {number}
  17900. */
  17901. this.startIndex = fields.startIndex || 0;
  17902. /**
  17903. * Can be null/undefined (when unknown), uint.
  17904. * @type {number}
  17905. */
  17906. this.dimensionsDetectCount = fields.dimensionsDetectCount;
  17907. }
  17908. /**
  17909. * Wrap original series data for some compatibility cases.
  17910. */
  17911. Source.seriesDataToSource = function (data) {
  17912. return new Source({
  17913. data: data,
  17914. sourceFormat: isTypedArray(data)
  17915. ? SOURCE_FORMAT_TYPED_ARRAY
  17916. : SOURCE_FORMAT_ORIGINAL,
  17917. fromDataset: false
  17918. });
  17919. };
  17920. enableClassCheck(Source);
  17921. /*
  17922. * Licensed to the Apache Software Foundation (ASF) under one
  17923. * or more contributor license agreements. See the NOTICE file
  17924. * distributed with this work for additional information
  17925. * regarding copyright ownership. The ASF licenses this file
  17926. * to you under the Apache License, Version 2.0 (the
  17927. * "License"); you may not use this file except in compliance
  17928. * with the License. You may obtain a copy of the License at
  17929. *
  17930. * http://www.apache.org/licenses/LICENSE-2.0
  17931. *
  17932. * Unless required by applicable law or agreed to in writing,
  17933. * software distributed under the License is distributed on an
  17934. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17935. * KIND, either express or implied. See the License for the
  17936. * specific language governing permissions and limitations
  17937. * under the License.
  17938. */
  17939. // The result of `guessOrdinal`.
  17940. var BE_ORDINAL = {
  17941. Must: 1, // Encounter string but not '-' and not number-like.
  17942. Might: 2, // Encounter string but number-like.
  17943. Not: 3 // Other cases
  17944. };
  17945. var inner$3 = makeInner();
  17946. /**
  17947. * @see {module:echarts/data/Source}
  17948. * @param {module:echarts/component/dataset/DatasetModel} datasetModel
  17949. * @return {string} sourceFormat
  17950. */
  17951. function detectSourceFormat(datasetModel) {
  17952. var data = datasetModel.option.source;
  17953. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  17954. if (isTypedArray(data)) {
  17955. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  17956. }
  17957. else if (isArray(data)) {
  17958. // FIXME Whether tolerate null in top level array?
  17959. if (data.length === 0) {
  17960. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17961. }
  17962. for (var i = 0, len = data.length; i < len; i++) {
  17963. var item = data[i];
  17964. if (item == null) {
  17965. continue;
  17966. }
  17967. else if (isArray(item)) {
  17968. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17969. break;
  17970. }
  17971. else if (isObject$1(item)) {
  17972. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  17973. break;
  17974. }
  17975. }
  17976. }
  17977. else if (isObject$1(data)) {
  17978. for (var key in data) {
  17979. if (data.hasOwnProperty(key) && isArrayLike(data[key])) {
  17980. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  17981. break;
  17982. }
  17983. }
  17984. }
  17985. else if (data != null) {
  17986. throw new Error('Invalid data');
  17987. }
  17988. inner$3(datasetModel).sourceFormat = sourceFormat;
  17989. }
  17990. /**
  17991. * [Scenarios]:
  17992. * (1) Provide source data directly:
  17993. * series: {
  17994. * encode: {...},
  17995. * dimensions: [...]
  17996. * seriesLayoutBy: 'row',
  17997. * data: [[...]]
  17998. * }
  17999. * (2) Refer to datasetModel.
  18000. * series: [{
  18001. * encode: {...}
  18002. * // Ignore datasetIndex means `datasetIndex: 0`
  18003. * // and the dimensions defination in dataset is used
  18004. * }, {
  18005. * encode: {...},
  18006. * seriesLayoutBy: 'column',
  18007. * datasetIndex: 1
  18008. * }]
  18009. *
  18010. * Get data from series itself or datset.
  18011. * @return {module:echarts/data/Source} source
  18012. */
  18013. function getSource(seriesModel) {
  18014. return inner$3(seriesModel).source;
  18015. }
  18016. /**
  18017. * MUST be called before mergeOption of all series.
  18018. * @param {module:echarts/model/Global} ecModel
  18019. */
  18020. function resetSourceDefaulter(ecModel) {
  18021. // `datasetMap` is used to make default encode.
  18022. inner$3(ecModel).datasetMap = createHashMap();
  18023. }
  18024. /**
  18025. * [Caution]:
  18026. * MUST be called after series option merged and
  18027. * before "series.getInitailData()" called.
  18028. *
  18029. * [The rule of making default encode]:
  18030. * Category axis (if exists) alway map to the first dimension.
  18031. * Each other axis occupies a subsequent dimension.
  18032. *
  18033. * [Why make default encode]:
  18034. * Simplify the typing of encode in option, avoiding the case like that:
  18035. * series: [{encode: {x: 0, y: 1}}, {encode: {x: 0, y: 2}}, {encode: {x: 0, y: 3}}],
  18036. * where the "y" have to be manually typed as "1, 2, 3, ...".
  18037. *
  18038. * @param {module:echarts/model/Series} seriesModel
  18039. */
  18040. function prepareSource(seriesModel) {
  18041. var seriesOption = seriesModel.option;
  18042. var data = seriesOption.data;
  18043. var sourceFormat = isTypedArray(data)
  18044. ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  18045. var fromDataset = false;
  18046. var seriesLayoutBy = seriesOption.seriesLayoutBy;
  18047. var sourceHeader = seriesOption.sourceHeader;
  18048. var dimensionsDefine = seriesOption.dimensions;
  18049. var datasetModel = getDatasetModel(seriesModel);
  18050. if (datasetModel) {
  18051. var datasetOption = datasetModel.option;
  18052. data = datasetOption.source;
  18053. sourceFormat = inner$3(datasetModel).sourceFormat;
  18054. fromDataset = true;
  18055. // These settings from series has higher priority.
  18056. seriesLayoutBy = seriesLayoutBy || datasetOption.seriesLayoutBy;
  18057. sourceHeader == null && (sourceHeader = datasetOption.sourceHeader);
  18058. dimensionsDefine = dimensionsDefine || datasetOption.dimensions;
  18059. }
  18060. var completeResult = completeBySourceData(
  18061. data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine
  18062. );
  18063. inner$3(seriesModel).source = new Source({
  18064. data: data,
  18065. fromDataset: fromDataset,
  18066. seriesLayoutBy: seriesLayoutBy,
  18067. sourceFormat: sourceFormat,
  18068. dimensionsDefine: completeResult.dimensionsDefine,
  18069. startIndex: completeResult.startIndex,
  18070. dimensionsDetectCount: completeResult.dimensionsDetectCount,
  18071. // Note: dataset option does not have `encode`.
  18072. encodeDefine: seriesOption.encode
  18073. });
  18074. }
  18075. // return {startIndex, dimensionsDefine, dimensionsCount}
  18076. function completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine) {
  18077. if (!data) {
  18078. return {dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine)};
  18079. }
  18080. var dimensionsDetectCount;
  18081. var startIndex;
  18082. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  18083. // Rule: Most of the first line are string: it is header.
  18084. // Caution: consider a line with 5 string and 1 number,
  18085. // it still can not be sure it is a head, because the
  18086. // 5 string may be 5 values of category columns.
  18087. if (sourceHeader === 'auto' || sourceHeader == null) {
  18088. arrayRowsTravelFirst(function (val) {
  18089. // '-' is regarded as null/undefined.
  18090. if (val != null && val !== '-') {
  18091. if (isString(val)) {
  18092. startIndex == null && (startIndex = 1);
  18093. }
  18094. else {
  18095. startIndex = 0;
  18096. }
  18097. }
  18098. // 10 is an experience number, avoid long loop.
  18099. }, seriesLayoutBy, data, 10);
  18100. }
  18101. else {
  18102. startIndex = sourceHeader ? 1 : 0;
  18103. }
  18104. if (!dimensionsDefine && startIndex === 1) {
  18105. dimensionsDefine = [];
  18106. arrayRowsTravelFirst(function (val, index) {
  18107. dimensionsDefine[index] = val != null ? val : '';
  18108. }, seriesLayoutBy, data);
  18109. }
  18110. dimensionsDetectCount = dimensionsDefine
  18111. ? dimensionsDefine.length
  18112. : seriesLayoutBy === SERIES_LAYOUT_BY_ROW
  18113. ? data.length
  18114. : data[0]
  18115. ? data[0].length
  18116. : null;
  18117. }
  18118. else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  18119. if (!dimensionsDefine) {
  18120. dimensionsDefine = objectRowsCollectDimensions(data);
  18121. }
  18122. }
  18123. else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18124. if (!dimensionsDefine) {
  18125. dimensionsDefine = [];
  18126. each$1(data, function (colArr, key) {
  18127. dimensionsDefine.push(key);
  18128. });
  18129. }
  18130. }
  18131. else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  18132. var value0 = getDataItemValue(data[0]);
  18133. dimensionsDetectCount = isArray(value0) && value0.length || 1;
  18134. }
  18135. else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  18136. if (__DEV__) {
  18137. assert$1(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');
  18138. }
  18139. }
  18140. return {
  18141. startIndex: startIndex,
  18142. dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine),
  18143. dimensionsDetectCount: dimensionsDetectCount
  18144. };
  18145. }
  18146. // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  18147. // which is reasonable. But dimension name is duplicated.
  18148. // Returns undefined or an array contains only object without null/undefiend or string.
  18149. function normalizeDimensionsDefine(dimensionsDefine) {
  18150. if (!dimensionsDefine) {
  18151. // The meaning of null/undefined is different from empty array.
  18152. return;
  18153. }
  18154. var nameMap = createHashMap();
  18155. return map(dimensionsDefine, function (item, index) {
  18156. item = extend({}, isObject$1(item) ? item : {name: item});
  18157. // User can set null in dimensions.
  18158. // We dont auto specify name, othewise a given name may
  18159. // cause it be refered unexpectedly.
  18160. if (item.name == null) {
  18161. return item;
  18162. }
  18163. // Also consider number form like 2012.
  18164. item.name += '';
  18165. // User may also specify displayName.
  18166. // displayName will always exists except user not
  18167. // specified or dim name is not specified or detected.
  18168. // (A auto generated dim name will not be used as
  18169. // displayName).
  18170. if (item.displayName == null) {
  18171. item.displayName = item.name;
  18172. }
  18173. var exist = nameMap.get(item.name);
  18174. if (!exist) {
  18175. nameMap.set(item.name, {count: 1});
  18176. }
  18177. else {
  18178. item.name += '-' + exist.count++;
  18179. }
  18180. return item;
  18181. });
  18182. }
  18183. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  18184. maxLoop == null && (maxLoop = Infinity);
  18185. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18186. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18187. cb(data[i] ? data[i][0] : null, i);
  18188. }
  18189. }
  18190. else {
  18191. var value0 = data[0] || [];
  18192. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  18193. cb(value0[i], i);
  18194. }
  18195. }
  18196. }
  18197. function objectRowsCollectDimensions(data) {
  18198. var firstIndex = 0;
  18199. var obj;
  18200. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  18201. if (obj) {
  18202. var dimensions = [];
  18203. each$1(obj, function (value, key) {
  18204. dimensions.push(key);
  18205. });
  18206. return dimensions;
  18207. }
  18208. }
  18209. /**
  18210. * [The strategy of the arrengment of data dimensions for dataset]:
  18211. * "value way": all axes are non-category axes. So series one by one take
  18212. * several (the number is coordSysDims.length) dimensions from dataset.
  18213. * The result of data arrengment of data dimensions like:
  18214. * | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |
  18215. * "category way": at least one axis is category axis. So the the first data
  18216. * dimension is always mapped to the first category axis and shared by
  18217. * all of the series. The other data dimensions are taken by series like
  18218. * "value way" does.
  18219. * The result of data arrengment of data dimensions like:
  18220. * | ser_shared_x | ser0_y | ser1_y | ser2_y |
  18221. *
  18222. * @param {Array.<Object|string>} coordDimensions [{name: <string>, type: <string>, dimsDef: <Array>}, ...]
  18223. * @param {module:model/Series} seriesModel
  18224. * @param {module:data/Source} source
  18225. * @return {Object} encode Never be `null/undefined`.
  18226. */
  18227. function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {
  18228. var encode = {};
  18229. var datasetModel = getDatasetModel(seriesModel);
  18230. // Currently only make default when using dataset, util more reqirements occur.
  18231. if (!datasetModel || !coordDimensions) {
  18232. return encode;
  18233. }
  18234. var encodeItemName = [];
  18235. var encodeSeriesName = [];
  18236. var ecModel = seriesModel.ecModel;
  18237. var datasetMap = inner$3(ecModel).datasetMap;
  18238. var key = datasetModel.uid + '_' + source.seriesLayoutBy;
  18239. var baseCategoryDimIndex;
  18240. var categoryWayValueDimStart;
  18241. coordDimensions = coordDimensions.slice();
  18242. each$1(coordDimensions, function (coordDimInfo, coordDimIdx) {
  18243. !isObject$1(coordDimInfo) && (coordDimensions[coordDimIdx] = {name: coordDimInfo});
  18244. if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {
  18245. baseCategoryDimIndex = coordDimIdx;
  18246. categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimensions[coordDimIdx]);
  18247. }
  18248. encode[coordDimInfo.name] = [];
  18249. });
  18250. var datasetRecord = datasetMap.get(key)
  18251. || datasetMap.set(key, {categoryWayDim: categoryWayValueDimStart, valueWayDim: 0});
  18252. // TODO
  18253. // Auto detect first time axis and do arrangement.
  18254. each$1(coordDimensions, function (coordDimInfo, coordDimIdx) {
  18255. var coordDimName = coordDimInfo.name;
  18256. var count = getDataDimCountOnCoordDim(coordDimInfo);
  18257. // In value way.
  18258. if (baseCategoryDimIndex == null) {
  18259. var start = datasetRecord.valueWayDim;
  18260. pushDim(encode[coordDimName], start, count);
  18261. pushDim(encodeSeriesName, start, count);
  18262. datasetRecord.valueWayDim += count;
  18263. // ??? TODO give a better default series name rule?
  18264. // especially when encode x y specified.
  18265. // consider: when mutiple series share one dimension
  18266. // category axis, series name should better use
  18267. // the other dimsion name. On the other hand, use
  18268. // both dimensions name.
  18269. }
  18270. // In category way, the first category axis.
  18271. else if (baseCategoryDimIndex === coordDimIdx) {
  18272. pushDim(encode[coordDimName], 0, count);
  18273. pushDim(encodeItemName, 0, count);
  18274. }
  18275. // In category way, the other axis.
  18276. else {
  18277. var start = datasetRecord.categoryWayDim;
  18278. pushDim(encode[coordDimName], start, count);
  18279. pushDim(encodeSeriesName, start, count);
  18280. datasetRecord.categoryWayDim += count;
  18281. }
  18282. });
  18283. function pushDim(dimIdxArr, idxFrom, idxCount) {
  18284. for (var i = 0; i < idxCount; i++) {
  18285. dimIdxArr.push(idxFrom + i);
  18286. }
  18287. }
  18288. function getDataDimCountOnCoordDim(coordDimInfo) {
  18289. var dimsDef = coordDimInfo.dimsDef;
  18290. return dimsDef ? dimsDef.length : 1;
  18291. }
  18292. encodeItemName.length && (encode.itemName = encodeItemName);
  18293. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  18294. return encode;
  18295. }
  18296. /**
  18297. * Work for data like [{name: ..., value: ...}, ...].
  18298. *
  18299. * @param {module:model/Series} seriesModel
  18300. * @param {module:data/Source} source
  18301. * @return {Object} encode Never be `null/undefined`.
  18302. */
  18303. function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) {
  18304. var encode = {};
  18305. var datasetModel = getDatasetModel(seriesModel);
  18306. // Currently only make default when using dataset, util more reqirements occur.
  18307. if (!datasetModel) {
  18308. return encode;
  18309. }
  18310. var sourceFormat = source.sourceFormat;
  18311. var dimensionsDefine = source.dimensionsDefine;
  18312. var potentialNameDimIndex;
  18313. if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18314. each$1(dimensionsDefine, function (dim, idx) {
  18315. if ((isObject$1(dim) ? dim.name : dim) === 'name') {
  18316. potentialNameDimIndex = idx;
  18317. }
  18318. });
  18319. }
  18320. // idxResult: {v, n}.
  18321. var idxResult = (function () {
  18322. var idxRes0 = {};
  18323. var idxRes1 = {};
  18324. var guessRecords = [];
  18325. // 5 is an experience value.
  18326. for (var i = 0, len = Math.min(5, dimCount); i < len; i++) {
  18327. var guessResult = doGuessOrdinal(
  18328. source.data, sourceFormat, source.seriesLayoutBy,
  18329. dimensionsDefine, source.startIndex, i
  18330. );
  18331. guessRecords.push(guessResult);
  18332. var isPureNumber = guessResult === BE_ORDINAL.Not;
  18333. // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,
  18334. // and then find a name dim with the priority:
  18335. // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself".
  18336. if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {
  18337. idxRes0.v = i;
  18338. }
  18339. if (idxRes0.n == null
  18340. || (idxRes0.n === idxRes0.v)
  18341. || (!isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not)
  18342. ) {
  18343. idxRes0.n = i;
  18344. }
  18345. if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {
  18346. return idxRes0;
  18347. }
  18348. // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not),
  18349. // find the first BE_ORDINAL.Might as the value dim,
  18350. // and then find a name dim with the priority:
  18351. // "other dim" > "the value dim itself".
  18352. // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be
  18353. // treated as number.
  18354. if (!isPureNumber) {
  18355. if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) {
  18356. idxRes1.v = i;
  18357. }
  18358. if (idxRes1.n == null || (idxRes1.n === idxRes1.v)) {
  18359. idxRes1.n = i;
  18360. }
  18361. }
  18362. }
  18363. function fulfilled(idxResult) {
  18364. return idxResult.v != null && idxResult.n != null;
  18365. }
  18366. return fulfilled(idxRes0) ? idxRes0 : fulfilled(idxRes1) ? idxRes1 : null;
  18367. })();
  18368. if (idxResult) {
  18369. encode.value = idxResult.v;
  18370. // `potentialNameDimIndex` has highest priority.
  18371. var nameDimIndex = potentialNameDimIndex != null ? potentialNameDimIndex : idxResult.n;
  18372. // By default, label use itemName in charts.
  18373. // So we dont set encodeLabel here.
  18374. encode.itemName = [nameDimIndex];
  18375. encode.seriesName = [nameDimIndex];
  18376. }
  18377. return encode;
  18378. }
  18379. /**
  18380. * If return null/undefined, indicate that should not use datasetModel.
  18381. */
  18382. function getDatasetModel(seriesModel) {
  18383. var option = seriesModel.option;
  18384. // Caution: consider the scenario:
  18385. // A dataset is declared and a series is not expected to use the dataset,
  18386. // and at the beginning `setOption({series: { noData })` (just prepare other
  18387. // option but no data), then `setOption({series: {data: [...]}); In this case,
  18388. // the user should set an empty array to avoid that dataset is used by default.
  18389. var thisData = option.data;
  18390. if (!thisData) {
  18391. return seriesModel.ecModel.getComponent('dataset', option.datasetIndex || 0);
  18392. }
  18393. }
  18394. /**
  18395. * The rule should not be complex, otherwise user might not
  18396. * be able to known where the data is wrong.
  18397. * The code is ugly, but how to make it neat?
  18398. *
  18399. * @param {module:echars/data/Source} source
  18400. * @param {number} dimIndex
  18401. * @return {BE_ORDINAL} guess result.
  18402. */
  18403. function guessOrdinal(source, dimIndex) {
  18404. return doGuessOrdinal(
  18405. source.data,
  18406. source.sourceFormat,
  18407. source.seriesLayoutBy,
  18408. source.dimensionsDefine,
  18409. source.startIndex,
  18410. dimIndex
  18411. );
  18412. }
  18413. // dimIndex may be overflow source data.
  18414. // return {BE_ORDINAL}
  18415. function doGuessOrdinal(
  18416. data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex
  18417. ) {
  18418. var result;
  18419. // Experience value.
  18420. var maxLoop = 5;
  18421. if (isTypedArray(data)) {
  18422. return BE_ORDINAL.Not;
  18423. }
  18424. // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  18425. // always exists in source.
  18426. var dimName;
  18427. var dimType;
  18428. if (dimensionsDefine) {
  18429. var dimDefItem = dimensionsDefine[dimIndex];
  18430. if (isObject$1(dimDefItem)) {
  18431. dimName = dimDefItem.name;
  18432. dimType = dimDefItem.type;
  18433. }
  18434. else if (isString(dimDefItem)) {
  18435. dimName = dimDefItem;
  18436. }
  18437. }
  18438. if (dimType != null) {
  18439. return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;
  18440. }
  18441. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  18442. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18443. var sample = data[dimIndex];
  18444. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  18445. if ((result = detectValue(sample[startIndex + i])) != null) {
  18446. return result;
  18447. }
  18448. }
  18449. }
  18450. else {
  18451. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18452. var row = data[startIndex + i];
  18453. if (row && (result = detectValue(row[dimIndex])) != null) {
  18454. return result;
  18455. }
  18456. }
  18457. }
  18458. }
  18459. else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  18460. if (!dimName) {
  18461. return BE_ORDINAL.Not;
  18462. }
  18463. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18464. var item = data[i];
  18465. if (item && (result = detectValue(item[dimName])) != null) {
  18466. return result;
  18467. }
  18468. }
  18469. }
  18470. else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18471. if (!dimName) {
  18472. return BE_ORDINAL.Not;
  18473. }
  18474. var sample = data[dimName];
  18475. if (!sample || isTypedArray(sample)) {
  18476. return BE_ORDINAL.Not;
  18477. }
  18478. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  18479. if ((result = detectValue(sample[i])) != null) {
  18480. return result;
  18481. }
  18482. }
  18483. }
  18484. else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  18485. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18486. var item = data[i];
  18487. var val = getDataItemValue(item);
  18488. if (!isArray(val)) {
  18489. return BE_ORDINAL.Not;
  18490. }
  18491. if ((result = detectValue(val[dimIndex])) != null) {
  18492. return result;
  18493. }
  18494. }
  18495. }
  18496. function detectValue(val) {
  18497. var beStr = isString(val);
  18498. // Consider usage convenience, '1', '2' will be treated as "number".
  18499. // `isFinit('')` get `true`.
  18500. if (val != null && isFinite(val) && val !== '') {
  18501. return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;
  18502. }
  18503. else if (beStr && val !== '-') {
  18504. return BE_ORDINAL.Must;
  18505. }
  18506. }
  18507. return BE_ORDINAL.Not;
  18508. }
  18509. /*
  18510. * Licensed to the Apache Software Foundation (ASF) under one
  18511. * or more contributor license agreements. See the NOTICE file
  18512. * distributed with this work for additional information
  18513. * regarding copyright ownership. The ASF licenses this file
  18514. * to you under the Apache License, Version 2.0 (the
  18515. * "License"); you may not use this file except in compliance
  18516. * with the License. You may obtain a copy of the License at
  18517. *
  18518. * http://www.apache.org/licenses/LICENSE-2.0
  18519. *
  18520. * Unless required by applicable law or agreed to in writing,
  18521. * software distributed under the License is distributed on an
  18522. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18523. * KIND, either express or implied. See the License for the
  18524. * specific language governing permissions and limitations
  18525. * under the License.
  18526. */
  18527. /**
  18528. * ECharts global model
  18529. *
  18530. * @module {echarts/model/Global}
  18531. */
  18532. /**
  18533. * Caution: If the mechanism should be changed some day, these cases
  18534. * should be considered:
  18535. *
  18536. * (1) In `merge option` mode, if using the same option to call `setOption`
  18537. * many times, the result should be the same (try our best to ensure that).
  18538. * (2) In `merge option` mode, if a component has no id/name specified, it
  18539. * will be merged by index, and the result sequence of the components is
  18540. * consistent to the original sequence.
  18541. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  18542. * `mergeOption` in module:echarts/model/OptionManager.
  18543. */
  18544. var OPTION_INNER_KEY = '\0_ec_inner';
  18545. /**
  18546. * @alias module:echarts/model/Global
  18547. *
  18548. * @param {Object} option
  18549. * @param {module:echarts/model/Model} parentModel
  18550. * @param {Object} theme
  18551. */
  18552. var GlobalModel = Model.extend({
  18553. init: function (option, parentModel, theme, optionManager) {
  18554. theme = theme || {};
  18555. this.option = null; // Mark as not initialized.
  18556. /**
  18557. * @type {module:echarts/model/Model}
  18558. * @private
  18559. */
  18560. this._theme = new Model(theme);
  18561. /**
  18562. * @type {module:echarts/model/OptionManager}
  18563. */
  18564. this._optionManager = optionManager;
  18565. },
  18566. setOption: function (option, optionPreprocessorFuncs) {
  18567. assert$1(
  18568. !(OPTION_INNER_KEY in option),
  18569. 'please use chart.getOption()'
  18570. );
  18571. this._optionManager.setOption(option, optionPreprocessorFuncs);
  18572. this.resetOption(null);
  18573. },
  18574. /**
  18575. * @param {string} type null/undefined: reset all.
  18576. * 'recreate': force recreate all.
  18577. * 'timeline': only reset timeline option
  18578. * 'media': only reset media query option
  18579. * @return {boolean} Whether option changed.
  18580. */
  18581. resetOption: function (type) {
  18582. var optionChanged = false;
  18583. var optionManager = this._optionManager;
  18584. if (!type || type === 'recreate') {
  18585. var baseOption = optionManager.mountOption(type === 'recreate');
  18586. if (!this.option || type === 'recreate') {
  18587. initBase.call(this, baseOption);
  18588. }
  18589. else {
  18590. this.restoreData();
  18591. this.mergeOption(baseOption);
  18592. }
  18593. optionChanged = true;
  18594. }
  18595. if (type === 'timeline' || type === 'media') {
  18596. this.restoreData();
  18597. }
  18598. if (!type || type === 'recreate' || type === 'timeline') {
  18599. var timelineOption = optionManager.getTimelineOption(this);
  18600. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  18601. }
  18602. if (!type || type === 'recreate' || type === 'media') {
  18603. var mediaOptions = optionManager.getMediaOption(this, this._api);
  18604. if (mediaOptions.length) {
  18605. each$1(mediaOptions, function (mediaOption) {
  18606. this.mergeOption(mediaOption, optionChanged = true);
  18607. }, this);
  18608. }
  18609. }
  18610. return optionChanged;
  18611. },
  18612. /**
  18613. * @protected
  18614. */
  18615. mergeOption: function (newOption) {
  18616. var option = this.option;
  18617. var componentsMap = this._componentsMap;
  18618. var newCptTypes = [];
  18619. resetSourceDefaulter(this);
  18620. // If no component class, merge directly.
  18621. // For example: color, animaiton options, etc.
  18622. each$1(newOption, function (componentOption, mainType) {
  18623. if (componentOption == null) {
  18624. return;
  18625. }
  18626. if (!ComponentModel.hasClass(mainType)) {
  18627. // globalSettingTask.dirty();
  18628. option[mainType] = option[mainType] == null
  18629. ? clone(componentOption)
  18630. : merge(option[mainType], componentOption, true);
  18631. }
  18632. else if (mainType) {
  18633. newCptTypes.push(mainType);
  18634. }
  18635. });
  18636. ComponentModel.topologicalTravel(
  18637. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  18638. );
  18639. function visitComponent(mainType, dependencies) {
  18640. var newCptOptionList = normalizeToArray(newOption[mainType]);
  18641. var mapResult = mappingToExists(
  18642. componentsMap.get(mainType), newCptOptionList
  18643. );
  18644. makeIdAndName(mapResult);
  18645. // Set mainType and complete subType.
  18646. each$1(mapResult, function (item, index) {
  18647. var opt = item.option;
  18648. if (isObject$1(opt)) {
  18649. item.keyInfo.mainType = mainType;
  18650. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  18651. }
  18652. });
  18653. var dependentModels = getComponentsByTypes(
  18654. componentsMap, dependencies
  18655. );
  18656. option[mainType] = [];
  18657. componentsMap.set(mainType, []);
  18658. each$1(mapResult, function (resultItem, index) {
  18659. var componentModel = resultItem.exist;
  18660. var newCptOption = resultItem.option;
  18661. assert$1(
  18662. isObject$1(newCptOption) || componentModel,
  18663. 'Empty component definition'
  18664. );
  18665. // Consider where is no new option and should be merged using {},
  18666. // see removeEdgeAndAdd in topologicalTravel and
  18667. // ComponentModel.getAllClassMainTypes.
  18668. if (!newCptOption) {
  18669. componentModel.mergeOption({}, this);
  18670. componentModel.optionUpdated({}, false);
  18671. }
  18672. else {
  18673. var ComponentModelClass = ComponentModel.getClass(
  18674. mainType, resultItem.keyInfo.subType, true
  18675. );
  18676. if (componentModel && componentModel.constructor === ComponentModelClass) {
  18677. componentModel.name = resultItem.keyInfo.name;
  18678. // componentModel.settingTask && componentModel.settingTask.dirty();
  18679. componentModel.mergeOption(newCptOption, this);
  18680. componentModel.optionUpdated(newCptOption, false);
  18681. }
  18682. else {
  18683. // PENDING Global as parent ?
  18684. var extraOpt = extend(
  18685. {
  18686. dependentModels: dependentModels,
  18687. componentIndex: index
  18688. },
  18689. resultItem.keyInfo
  18690. );
  18691. componentModel = new ComponentModelClass(
  18692. newCptOption, this, this, extraOpt
  18693. );
  18694. extend(componentModel, extraOpt);
  18695. componentModel.init(newCptOption, this, this, extraOpt);
  18696. // Call optionUpdated after init.
  18697. // newCptOption has been used as componentModel.option
  18698. // and may be merged with theme and default, so pass null
  18699. // to avoid confusion.
  18700. componentModel.optionUpdated(null, true);
  18701. }
  18702. }
  18703. componentsMap.get(mainType)[index] = componentModel;
  18704. option[mainType][index] = componentModel.option;
  18705. }, this);
  18706. // Backup series for filtering.
  18707. if (mainType === 'series') {
  18708. createSeriesIndices(this, componentsMap.get('series'));
  18709. }
  18710. }
  18711. this._seriesIndicesMap = createHashMap(
  18712. this._seriesIndices = this._seriesIndices || []
  18713. );
  18714. },
  18715. /**
  18716. * Get option for output (cloned option and inner info removed)
  18717. * @public
  18718. * @return {Object}
  18719. */
  18720. getOption: function () {
  18721. var option = clone(this.option);
  18722. each$1(option, function (opts, mainType) {
  18723. if (ComponentModel.hasClass(mainType)) {
  18724. var opts = normalizeToArray(opts);
  18725. for (var i = opts.length - 1; i >= 0; i--) {
  18726. // Remove options with inner id.
  18727. if (isIdInner(opts[i])) {
  18728. opts.splice(i, 1);
  18729. }
  18730. }
  18731. option[mainType] = opts;
  18732. }
  18733. });
  18734. delete option[OPTION_INNER_KEY];
  18735. return option;
  18736. },
  18737. /**
  18738. * @return {module:echarts/model/Model}
  18739. */
  18740. getTheme: function () {
  18741. return this._theme;
  18742. },
  18743. /**
  18744. * @param {string} mainType
  18745. * @param {number} [idx=0]
  18746. * @return {module:echarts/model/Component}
  18747. */
  18748. getComponent: function (mainType, idx) {
  18749. var list = this._componentsMap.get(mainType);
  18750. if (list) {
  18751. return list[idx || 0];
  18752. }
  18753. },
  18754. /**
  18755. * If none of index and id and name used, return all components with mainType.
  18756. * @param {Object} condition
  18757. * @param {string} condition.mainType
  18758. * @param {string} [condition.subType] If ignore, only query by mainType
  18759. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  18760. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  18761. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  18762. * @return {Array.<module:echarts/model/Component>}
  18763. */
  18764. queryComponents: function (condition) {
  18765. var mainType = condition.mainType;
  18766. if (!mainType) {
  18767. return [];
  18768. }
  18769. var index = condition.index;
  18770. var id = condition.id;
  18771. var name = condition.name;
  18772. var cpts = this._componentsMap.get(mainType);
  18773. if (!cpts || !cpts.length) {
  18774. return [];
  18775. }
  18776. var result;
  18777. if (index != null) {
  18778. if (!isArray(index)) {
  18779. index = [index];
  18780. }
  18781. result = filter(map(index, function (idx) {
  18782. return cpts[idx];
  18783. }), function (val) {
  18784. return !!val;
  18785. });
  18786. }
  18787. else if (id != null) {
  18788. var isIdArray = isArray(id);
  18789. result = filter(cpts, function (cpt) {
  18790. return (isIdArray && indexOf(id, cpt.id) >= 0)
  18791. || (!isIdArray && cpt.id === id);
  18792. });
  18793. }
  18794. else if (name != null) {
  18795. var isNameArray = isArray(name);
  18796. result = filter(cpts, function (cpt) {
  18797. return (isNameArray && indexOf(name, cpt.name) >= 0)
  18798. || (!isNameArray && cpt.name === name);
  18799. });
  18800. }
  18801. else {
  18802. // Return all components with mainType
  18803. result = cpts.slice();
  18804. }
  18805. return filterBySubType(result, condition);
  18806. },
  18807. /**
  18808. * The interface is different from queryComponents,
  18809. * which is convenient for inner usage.
  18810. *
  18811. * @usage
  18812. * var result = findComponents(
  18813. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  18814. * );
  18815. * var result = findComponents(
  18816. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  18817. * );
  18818. * var result = findComponents(
  18819. * {mainType: 'series',
  18820. * filter: function (model, index) {...}}
  18821. * );
  18822. * // result like [component0, componnet1, ...]
  18823. *
  18824. * @param {Object} condition
  18825. * @param {string} condition.mainType Mandatory.
  18826. * @param {string} [condition.subType] Optional.
  18827. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  18828. * where xxx is mainType.
  18829. * If query attribute is null/undefined or has no index/id/name,
  18830. * do not filtering by query conditions, which is convenient for
  18831. * no-payload situations or when target of action is global.
  18832. * @param {Function} [condition.filter] parameter: component, return boolean.
  18833. * @return {Array.<module:echarts/model/Component>}
  18834. */
  18835. findComponents: function (condition) {
  18836. var query = condition.query;
  18837. var mainType = condition.mainType;
  18838. var queryCond = getQueryCond(query);
  18839. var result = queryCond
  18840. ? this.queryComponents(queryCond)
  18841. : this._componentsMap.get(mainType);
  18842. return doFilter(filterBySubType(result, condition));
  18843. function getQueryCond(q) {
  18844. var indexAttr = mainType + 'Index';
  18845. var idAttr = mainType + 'Id';
  18846. var nameAttr = mainType + 'Name';
  18847. return q && (
  18848. q[indexAttr] != null
  18849. || q[idAttr] != null
  18850. || q[nameAttr] != null
  18851. )
  18852. ? {
  18853. mainType: mainType,
  18854. // subType will be filtered finally.
  18855. index: q[indexAttr],
  18856. id: q[idAttr],
  18857. name: q[nameAttr]
  18858. }
  18859. : null;
  18860. }
  18861. function doFilter(res) {
  18862. return condition.filter
  18863. ? filter(res, condition.filter)
  18864. : res;
  18865. }
  18866. },
  18867. /**
  18868. * @usage
  18869. * eachComponent('legend', function (legendModel, index) {
  18870. * ...
  18871. * });
  18872. * eachComponent(function (componentType, model, index) {
  18873. * // componentType does not include subType
  18874. * // (componentType is 'xxx' but not 'xxx.aa')
  18875. * });
  18876. * eachComponent(
  18877. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  18878. * function (model, index) {...}
  18879. * );
  18880. * eachComponent(
  18881. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  18882. * function (model, index) {...}
  18883. * );
  18884. *
  18885. * @param {string|Object=} mainType When mainType is object, the definition
  18886. * is the same as the method 'findComponents'.
  18887. * @param {Function} cb
  18888. * @param {*} context
  18889. */
  18890. eachComponent: function (mainType, cb, context) {
  18891. var componentsMap = this._componentsMap;
  18892. if (typeof mainType === 'function') {
  18893. context = cb;
  18894. cb = mainType;
  18895. componentsMap.each(function (components, componentType) {
  18896. each$1(components, function (component, index) {
  18897. cb.call(context, componentType, component, index);
  18898. });
  18899. });
  18900. }
  18901. else if (isString(mainType)) {
  18902. each$1(componentsMap.get(mainType), cb, context);
  18903. }
  18904. else if (isObject$1(mainType)) {
  18905. var queryResult = this.findComponents(mainType);
  18906. each$1(queryResult, cb, context);
  18907. }
  18908. },
  18909. /**
  18910. * @param {string} name
  18911. * @return {Array.<module:echarts/model/Series>}
  18912. */
  18913. getSeriesByName: function (name) {
  18914. var series = this._componentsMap.get('series');
  18915. return filter(series, function (oneSeries) {
  18916. return oneSeries.name === name;
  18917. });
  18918. },
  18919. /**
  18920. * @param {number} seriesIndex
  18921. * @return {module:echarts/model/Series}
  18922. */
  18923. getSeriesByIndex: function (seriesIndex) {
  18924. return this._componentsMap.get('series')[seriesIndex];
  18925. },
  18926. /**
  18927. * Get series list before filtered by type.
  18928. * FIXME: rename to getRawSeriesByType?
  18929. *
  18930. * @param {string} subType
  18931. * @return {Array.<module:echarts/model/Series>}
  18932. */
  18933. getSeriesByType: function (subType) {
  18934. var series = this._componentsMap.get('series');
  18935. return filter(series, function (oneSeries) {
  18936. return oneSeries.subType === subType;
  18937. });
  18938. },
  18939. /**
  18940. * @return {Array.<module:echarts/model/Series>}
  18941. */
  18942. getSeries: function () {
  18943. return this._componentsMap.get('series').slice();
  18944. },
  18945. /**
  18946. * @return {number}
  18947. */
  18948. getSeriesCount: function () {
  18949. return this._componentsMap.get('series').length;
  18950. },
  18951. /**
  18952. * After filtering, series may be different
  18953. * frome raw series.
  18954. *
  18955. * @param {Function} cb
  18956. * @param {*} context
  18957. */
  18958. eachSeries: function (cb, context) {
  18959. assertSeriesInitialized(this);
  18960. each$1(this._seriesIndices, function (rawSeriesIndex) {
  18961. var series = this._componentsMap.get('series')[rawSeriesIndex];
  18962. cb.call(context, series, rawSeriesIndex);
  18963. }, this);
  18964. },
  18965. /**
  18966. * Iterate raw series before filtered.
  18967. *
  18968. * @param {Function} cb
  18969. * @param {*} context
  18970. */
  18971. eachRawSeries: function (cb, context) {
  18972. each$1(this._componentsMap.get('series'), cb, context);
  18973. },
  18974. /**
  18975. * After filtering, series may be different.
  18976. * frome raw series.
  18977. *
  18978. * @param {string} subType.
  18979. * @param {Function} cb
  18980. * @param {*} context
  18981. */
  18982. eachSeriesByType: function (subType, cb, context) {
  18983. assertSeriesInitialized(this);
  18984. each$1(this._seriesIndices, function (rawSeriesIndex) {
  18985. var series = this._componentsMap.get('series')[rawSeriesIndex];
  18986. if (series.subType === subType) {
  18987. cb.call(context, series, rawSeriesIndex);
  18988. }
  18989. }, this);
  18990. },
  18991. /**
  18992. * Iterate raw series before filtered of given type.
  18993. *
  18994. * @parma {string} subType
  18995. * @param {Function} cb
  18996. * @param {*} context
  18997. */
  18998. eachRawSeriesByType: function (subType, cb, context) {
  18999. return each$1(this.getSeriesByType(subType), cb, context);
  19000. },
  19001. /**
  19002. * @param {module:echarts/model/Series} seriesModel
  19003. */
  19004. isSeriesFiltered: function (seriesModel) {
  19005. assertSeriesInitialized(this);
  19006. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  19007. },
  19008. /**
  19009. * @return {Array.<number>}
  19010. */
  19011. getCurrentSeriesIndices: function () {
  19012. return (this._seriesIndices || []).slice();
  19013. },
  19014. /**
  19015. * @param {Function} cb
  19016. * @param {*} context
  19017. */
  19018. filterSeries: function (cb, context) {
  19019. assertSeriesInitialized(this);
  19020. var filteredSeries = filter(
  19021. this._componentsMap.get('series'), cb, context
  19022. );
  19023. createSeriesIndices(this, filteredSeries);
  19024. },
  19025. restoreData: function (payload) {
  19026. var componentsMap = this._componentsMap;
  19027. createSeriesIndices(this, componentsMap.get('series'));
  19028. var componentTypes = [];
  19029. componentsMap.each(function (components, componentType) {
  19030. componentTypes.push(componentType);
  19031. });
  19032. ComponentModel.topologicalTravel(
  19033. componentTypes,
  19034. ComponentModel.getAllClassMainTypes(),
  19035. function (componentType, dependencies) {
  19036. each$1(componentsMap.get(componentType), function (component) {
  19037. (componentType !== 'series' || !isNotTargetSeries(component, payload))
  19038. && component.restoreData();
  19039. });
  19040. }
  19041. );
  19042. }
  19043. });
  19044. function isNotTargetSeries(seriesModel, payload) {
  19045. if (payload) {
  19046. var index = payload.seiresIndex;
  19047. var id = payload.seriesId;
  19048. var name = payload.seriesName;
  19049. return (index != null && seriesModel.componentIndex !== index)
  19050. || (id != null && seriesModel.id !== id)
  19051. || (name != null && seriesModel.name !== name);
  19052. }
  19053. }
  19054. /**
  19055. * @inner
  19056. */
  19057. function mergeTheme(option, theme) {
  19058. // PENDING
  19059. // NOT use `colorLayer` in theme if option has `color`
  19060. var notMergeColorLayer = option.color && !option.colorLayer;
  19061. each$1(theme, function (themeItem, name) {
  19062. if (name === 'colorLayer' && notMergeColorLayer) {
  19063. return;
  19064. }
  19065. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  19066. if (!ComponentModel.hasClass(name)) {
  19067. if (typeof themeItem === 'object') {
  19068. option[name] = !option[name]
  19069. ? clone(themeItem)
  19070. : merge(option[name], themeItem, false);
  19071. }
  19072. else {
  19073. if (option[name] == null) {
  19074. option[name] = themeItem;
  19075. }
  19076. }
  19077. }
  19078. });
  19079. }
  19080. function initBase(baseOption) {
  19081. baseOption = baseOption;
  19082. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  19083. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  19084. this.option = {};
  19085. this.option[OPTION_INNER_KEY] = 1;
  19086. /**
  19087. * Init with series: [], in case of calling findSeries method
  19088. * before series initialized.
  19089. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  19090. * @private
  19091. */
  19092. this._componentsMap = createHashMap({series: []});
  19093. /**
  19094. * Mapping between filtered series list and raw series list.
  19095. * key: filtered series indices, value: raw series indices.
  19096. * @type {Array.<nubmer>}
  19097. * @private
  19098. */
  19099. this._seriesIndices;
  19100. this._seriesIndicesMap;
  19101. mergeTheme(baseOption, this._theme.option);
  19102. // TODO Needs clone when merging to the unexisted property
  19103. merge(baseOption, globalDefault, false);
  19104. this.mergeOption(baseOption);
  19105. }
  19106. /**
  19107. * @inner
  19108. * @param {Array.<string>|string} types model types
  19109. * @return {Object} key: {string} type, value: {Array.<Object>} models
  19110. */
  19111. function getComponentsByTypes(componentsMap, types) {
  19112. if (!isArray(types)) {
  19113. types = types ? [types] : [];
  19114. }
  19115. var ret = {};
  19116. each$1(types, function (type) {
  19117. ret[type] = (componentsMap.get(type) || []).slice();
  19118. });
  19119. return ret;
  19120. }
  19121. /**
  19122. * @inner
  19123. */
  19124. function determineSubType(mainType, newCptOption, existComponent) {
  19125. var subType = newCptOption.type
  19126. ? newCptOption.type
  19127. : existComponent
  19128. ? existComponent.subType
  19129. // Use determineSubType only when there is no existComponent.
  19130. : ComponentModel.determineSubType(mainType, newCptOption);
  19131. // tooltip, markline, markpoint may always has no subType
  19132. return subType;
  19133. }
  19134. /**
  19135. * @inner
  19136. */
  19137. function createSeriesIndices(ecModel, seriesModels) {
  19138. ecModel._seriesIndicesMap = createHashMap(
  19139. ecModel._seriesIndices = map(seriesModels, function (series) {
  19140. return series.componentIndex;
  19141. }) || []
  19142. );
  19143. }
  19144. /**
  19145. * @inner
  19146. */
  19147. function filterBySubType(components, condition) {
  19148. // Using hasOwnProperty for restrict. Consider
  19149. // subType is undefined in user payload.
  19150. return condition.hasOwnProperty('subType')
  19151. ? filter(components, function (cpt) {
  19152. return cpt.subType === condition.subType;
  19153. })
  19154. : components;
  19155. }
  19156. /**
  19157. * @inner
  19158. */
  19159. function assertSeriesInitialized(ecModel) {
  19160. // Components that use _seriesIndices should depends on series component,
  19161. // which make sure that their initialization is after series.
  19162. if (__DEV__) {
  19163. if (!ecModel._seriesIndices) {
  19164. throw new Error('Option should contains series.');
  19165. }
  19166. }
  19167. }
  19168. mixin(GlobalModel, colorPaletteMixin);
  19169. /*
  19170. * Licensed to the Apache Software Foundation (ASF) under one
  19171. * or more contributor license agreements. See the NOTICE file
  19172. * distributed with this work for additional information
  19173. * regarding copyright ownership. The ASF licenses this file
  19174. * to you under the Apache License, Version 2.0 (the
  19175. * "License"); you may not use this file except in compliance
  19176. * with the License. You may obtain a copy of the License at
  19177. *
  19178. * http://www.apache.org/licenses/LICENSE-2.0
  19179. *
  19180. * Unless required by applicable law or agreed to in writing,
  19181. * software distributed under the License is distributed on an
  19182. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19183. * KIND, either express or implied. See the License for the
  19184. * specific language governing permissions and limitations
  19185. * under the License.
  19186. */
  19187. var echartsAPIList = [
  19188. 'getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed',
  19189. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption',
  19190. 'getViewOfComponentModel', 'getViewOfSeriesModel'
  19191. ];
  19192. // And `getCoordinateSystems` and `getComponentByElement` will be injected in echarts.js
  19193. function ExtensionAPI(chartInstance) {
  19194. each$1(echartsAPIList, function (name) {
  19195. this[name] = bind(chartInstance[name], chartInstance);
  19196. }, this);
  19197. }
  19198. /*
  19199. * Licensed to the Apache Software Foundation (ASF) under one
  19200. * or more contributor license agreements. See the NOTICE file
  19201. * distributed with this work for additional information
  19202. * regarding copyright ownership. The ASF licenses this file
  19203. * to you under the Apache License, Version 2.0 (the
  19204. * "License"); you may not use this file except in compliance
  19205. * with the License. You may obtain a copy of the License at
  19206. *
  19207. * http://www.apache.org/licenses/LICENSE-2.0
  19208. *
  19209. * Unless required by applicable law or agreed to in writing,
  19210. * software distributed under the License is distributed on an
  19211. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19212. * KIND, either express or implied. See the License for the
  19213. * specific language governing permissions and limitations
  19214. * under the License.
  19215. */
  19216. var coordinateSystemCreators = {};
  19217. function CoordinateSystemManager() {
  19218. this._coordinateSystems = [];
  19219. }
  19220. CoordinateSystemManager.prototype = {
  19221. constructor: CoordinateSystemManager,
  19222. create: function (ecModel, api) {
  19223. var coordinateSystems = [];
  19224. each$1(coordinateSystemCreators, function (creater, type) {
  19225. var list = creater.create(ecModel, api);
  19226. coordinateSystems = coordinateSystems.concat(list || []);
  19227. });
  19228. this._coordinateSystems = coordinateSystems;
  19229. },
  19230. update: function (ecModel, api) {
  19231. each$1(this._coordinateSystems, function (coordSys) {
  19232. coordSys.update && coordSys.update(ecModel, api);
  19233. });
  19234. },
  19235. getCoordinateSystems: function () {
  19236. return this._coordinateSystems.slice();
  19237. }
  19238. };
  19239. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  19240. coordinateSystemCreators[type] = coordinateSystemCreator;
  19241. };
  19242. CoordinateSystemManager.get = function (type) {
  19243. return coordinateSystemCreators[type];
  19244. };
  19245. /*
  19246. * Licensed to the Apache Software Foundation (ASF) under one
  19247. * or more contributor license agreements. See the NOTICE file
  19248. * distributed with this work for additional information
  19249. * regarding copyright ownership. The ASF licenses this file
  19250. * to you under the Apache License, Version 2.0 (the
  19251. * "License"); you may not use this file except in compliance
  19252. * with the License. You may obtain a copy of the License at
  19253. *
  19254. * http://www.apache.org/licenses/LICENSE-2.0
  19255. *
  19256. * Unless required by applicable law or agreed to in writing,
  19257. * software distributed under the License is distributed on an
  19258. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19259. * KIND, either express or implied. See the License for the
  19260. * specific language governing permissions and limitations
  19261. * under the License.
  19262. */
  19263. /**
  19264. * ECharts option manager
  19265. *
  19266. * @module {echarts/model/OptionManager}
  19267. */
  19268. var each$4 = each$1;
  19269. var clone$3 = clone;
  19270. var map$1 = map;
  19271. var merge$1 = merge;
  19272. var QUERY_REG = /^(min|max)?(.+)$/;
  19273. /**
  19274. * TERM EXPLANATIONS:
  19275. *
  19276. * [option]:
  19277. *
  19278. * An object that contains definitions of components. For example:
  19279. * var option = {
  19280. * title: {...},
  19281. * legend: {...},
  19282. * visualMap: {...},
  19283. * series: [
  19284. * {data: [...]},
  19285. * {data: [...]},
  19286. * ...
  19287. * ]
  19288. * };
  19289. *
  19290. * [rawOption]:
  19291. *
  19292. * An object input to echarts.setOption. 'rawOption' may be an
  19293. * 'option', or may be an object contains multi-options. For example:
  19294. * var option = {
  19295. * baseOption: {
  19296. * title: {...},
  19297. * legend: {...},
  19298. * series: [
  19299. * {data: [...]},
  19300. * {data: [...]},
  19301. * ...
  19302. * ]
  19303. * },
  19304. * timeline: {...},
  19305. * options: [
  19306. * {title: {...}, series: {data: [...]}},
  19307. * {title: {...}, series: {data: [...]}},
  19308. * ...
  19309. * ],
  19310. * media: [
  19311. * {
  19312. * query: {maxWidth: 320},
  19313. * option: {series: {x: 20}, visualMap: {show: false}}
  19314. * },
  19315. * {
  19316. * query: {minWidth: 320, maxWidth: 720},
  19317. * option: {series: {x: 500}, visualMap: {show: true}}
  19318. * },
  19319. * {
  19320. * option: {series: {x: 1200}, visualMap: {show: true}}
  19321. * }
  19322. * ]
  19323. * };
  19324. *
  19325. * @alias module:echarts/model/OptionManager
  19326. * @param {module:echarts/ExtensionAPI} api
  19327. */
  19328. function OptionManager(api) {
  19329. /**
  19330. * @private
  19331. * @type {module:echarts/ExtensionAPI}
  19332. */
  19333. this._api = api;
  19334. /**
  19335. * @private
  19336. * @type {Array.<number>}
  19337. */
  19338. this._timelineOptions = [];
  19339. /**
  19340. * @private
  19341. * @type {Array.<Object>}
  19342. */
  19343. this._mediaList = [];
  19344. /**
  19345. * @private
  19346. * @type {Object}
  19347. */
  19348. this._mediaDefault;
  19349. /**
  19350. * -1, means default.
  19351. * empty means no media.
  19352. * @private
  19353. * @type {Array.<number>}
  19354. */
  19355. this._currentMediaIndices = [];
  19356. /**
  19357. * @private
  19358. * @type {Object}
  19359. */
  19360. this._optionBackup;
  19361. /**
  19362. * @private
  19363. * @type {Object}
  19364. */
  19365. this._newBaseOption;
  19366. }
  19367. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  19368. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  19369. // rawOption cloned and backuped when timeline changed, which does no
  19370. // good to performance. What's more, that both timeline and setOption
  19371. // method supply 'notMerge' brings complex and some problems.
  19372. // Consider this case:
  19373. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  19374. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  19375. OptionManager.prototype = {
  19376. constructor: OptionManager,
  19377. /**
  19378. * @public
  19379. * @param {Object} rawOption Raw option.
  19380. * @param {module:echarts/model/Global} ecModel
  19381. * @param {Array.<Function>} optionPreprocessorFuncs
  19382. * @return {Object} Init option
  19383. */
  19384. setOption: function (rawOption, optionPreprocessorFuncs) {
  19385. if (rawOption) {
  19386. // That set dat primitive is dangerous if user reuse the data when setOption again.
  19387. each$1(normalizeToArray(rawOption.series), function (series) {
  19388. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  19389. });
  19390. }
  19391. // Caution: some series modify option data, if do not clone,
  19392. // it should ensure that the repeat modify correctly
  19393. // (create a new object when modify itself).
  19394. rawOption = clone$3(rawOption);
  19395. // FIXME
  19396. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  19397. var oldOptionBackup = this._optionBackup;
  19398. var newParsedOption = parseRawOption.call(
  19399. this, rawOption, optionPreprocessorFuncs, !oldOptionBackup
  19400. );
  19401. this._newBaseOption = newParsedOption.baseOption;
  19402. // For setOption at second time (using merge mode);
  19403. if (oldOptionBackup) {
  19404. // Only baseOption can be merged.
  19405. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  19406. // For simplicity, timeline options and media options do not support merge,
  19407. // that is, if you `setOption` twice and both has timeline options, the latter
  19408. // timeline opitons will not be merged to the formers, but just substitude them.
  19409. if (newParsedOption.timelineOptions.length) {
  19410. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  19411. }
  19412. if (newParsedOption.mediaList.length) {
  19413. oldOptionBackup.mediaList = newParsedOption.mediaList;
  19414. }
  19415. if (newParsedOption.mediaDefault) {
  19416. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  19417. }
  19418. }
  19419. else {
  19420. this._optionBackup = newParsedOption;
  19421. }
  19422. },
  19423. /**
  19424. * @param {boolean} isRecreate
  19425. * @return {Object}
  19426. */
  19427. mountOption: function (isRecreate) {
  19428. var optionBackup = this._optionBackup;
  19429. // TODO
  19430. // 如果没有reset功能则不clone。
  19431. this._timelineOptions = map$1(optionBackup.timelineOptions, clone$3);
  19432. this._mediaList = map$1(optionBackup.mediaList, clone$3);
  19433. this._mediaDefault = clone$3(optionBackup.mediaDefault);
  19434. this._currentMediaIndices = [];
  19435. return clone$3(isRecreate
  19436. // this._optionBackup.baseOption, which is created at the first `setOption`
  19437. // called, and is merged into every new option by inner method `mergeOption`
  19438. // each time `setOption` called, can be only used in `isRecreate`, because
  19439. // its reliability is under suspicion. In other cases option merge is
  19440. // performed by `model.mergeOption`.
  19441. ? optionBackup.baseOption : this._newBaseOption
  19442. );
  19443. },
  19444. /**
  19445. * @param {module:echarts/model/Global} ecModel
  19446. * @return {Object}
  19447. */
  19448. getTimelineOption: function (ecModel) {
  19449. var option;
  19450. var timelineOptions = this._timelineOptions;
  19451. if (timelineOptions.length) {
  19452. // getTimelineOption can only be called after ecModel inited,
  19453. // so we can get currentIndex from timelineModel.
  19454. var timelineModel = ecModel.getComponent('timeline');
  19455. if (timelineModel) {
  19456. option = clone$3(
  19457. timelineOptions[timelineModel.getCurrentIndex()],
  19458. true
  19459. );
  19460. }
  19461. }
  19462. return option;
  19463. },
  19464. /**
  19465. * @param {module:echarts/model/Global} ecModel
  19466. * @return {Array.<Object>}
  19467. */
  19468. getMediaOption: function (ecModel) {
  19469. var ecWidth = this._api.getWidth();
  19470. var ecHeight = this._api.getHeight();
  19471. var mediaList = this._mediaList;
  19472. var mediaDefault = this._mediaDefault;
  19473. var indices = [];
  19474. var result = [];
  19475. // No media defined.
  19476. if (!mediaList.length && !mediaDefault) {
  19477. return result;
  19478. }
  19479. // Multi media may be applied, the latter defined media has higher priority.
  19480. for (var i = 0, len = mediaList.length; i < len; i++) {
  19481. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  19482. indices.push(i);
  19483. }
  19484. }
  19485. // FIXME
  19486. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  19487. if (!indices.length && mediaDefault) {
  19488. indices = [-1];
  19489. }
  19490. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  19491. result = map$1(indices, function (index) {
  19492. return clone$3(
  19493. index === -1 ? mediaDefault.option : mediaList[index].option
  19494. );
  19495. });
  19496. }
  19497. // Otherwise return nothing.
  19498. this._currentMediaIndices = indices;
  19499. return result;
  19500. }
  19501. };
  19502. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  19503. var timelineOptions = [];
  19504. var mediaList = [];
  19505. var mediaDefault;
  19506. var baseOption;
  19507. // Compatible with ec2.
  19508. var timelineOpt = rawOption.timeline;
  19509. if (rawOption.baseOption) {
  19510. baseOption = rawOption.baseOption;
  19511. }
  19512. // For timeline
  19513. if (timelineOpt || rawOption.options) {
  19514. baseOption = baseOption || {};
  19515. timelineOptions = (rawOption.options || []).slice();
  19516. }
  19517. // For media query
  19518. if (rawOption.media) {
  19519. baseOption = baseOption || {};
  19520. var media = rawOption.media;
  19521. each$4(media, function (singleMedia) {
  19522. if (singleMedia && singleMedia.option) {
  19523. if (singleMedia.query) {
  19524. mediaList.push(singleMedia);
  19525. }
  19526. else if (!mediaDefault) {
  19527. // Use the first media default.
  19528. mediaDefault = singleMedia;
  19529. }
  19530. }
  19531. });
  19532. }
  19533. // For normal option
  19534. if (!baseOption) {
  19535. baseOption = rawOption;
  19536. }
  19537. // Set timelineOpt to baseOption in ec3,
  19538. // which is convenient for merge option.
  19539. if (!baseOption.timeline) {
  19540. baseOption.timeline = timelineOpt;
  19541. }
  19542. // Preprocess.
  19543. each$4([baseOption].concat(timelineOptions)
  19544. .concat(map(mediaList, function (media) {
  19545. return media.option;
  19546. })),
  19547. function (option) {
  19548. each$4(optionPreprocessorFuncs, function (preProcess) {
  19549. preProcess(option, isNew);
  19550. });
  19551. }
  19552. );
  19553. return {
  19554. baseOption: baseOption,
  19555. timelineOptions: timelineOptions,
  19556. mediaDefault: mediaDefault,
  19557. mediaList: mediaList
  19558. };
  19559. }
  19560. /**
  19561. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  19562. * Support: width, height, aspectRatio
  19563. * Can use max or min as prefix.
  19564. */
  19565. function applyMediaQuery(query, ecWidth, ecHeight) {
  19566. var realMap = {
  19567. width: ecWidth,
  19568. height: ecHeight,
  19569. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  19570. };
  19571. var applicatable = true;
  19572. each$1(query, function (value, attr) {
  19573. var matched = attr.match(QUERY_REG);
  19574. if (!matched || !matched[1] || !matched[2]) {
  19575. return;
  19576. }
  19577. var operator = matched[1];
  19578. var realAttr = matched[2].toLowerCase();
  19579. if (!compare(realMap[realAttr], value, operator)) {
  19580. applicatable = false;
  19581. }
  19582. });
  19583. return applicatable;
  19584. }
  19585. function compare(real, expect, operator) {
  19586. if (operator === 'min') {
  19587. return real >= expect;
  19588. }
  19589. else if (operator === 'max') {
  19590. return real <= expect;
  19591. }
  19592. else { // Equals
  19593. return real === expect;
  19594. }
  19595. }
  19596. function indicesEquals(indices1, indices2) {
  19597. // indices is always order by asc and has only finite number.
  19598. return indices1.join(',') === indices2.join(',');
  19599. }
  19600. /**
  19601. * Consider case:
  19602. * `chart.setOption(opt1);`
  19603. * Then user do some interaction like dataZoom, dataView changing.
  19604. * `chart.setOption(opt2);`
  19605. * Then user press 'reset button' in toolbox.
  19606. *
  19607. * After doing that all of the interaction effects should be reset, the
  19608. * chart should be the same as the result of invoke
  19609. * `chart.setOption(opt1); chart.setOption(opt2);`.
  19610. *
  19611. * Although it is not able ensure that
  19612. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  19613. * `chart.setOption(merge(opt1, opt2));` exactly,
  19614. * this might be the only simple way to implement that feature.
  19615. *
  19616. * MEMO: We've considered some other approaches:
  19617. * 1. Each model handle its self restoration but not uniform treatment.
  19618. * (Too complex in logic and error-prone)
  19619. * 2. Use a shadow ecModel. (Performace expensive)
  19620. */
  19621. function mergeOption(oldOption, newOption) {
  19622. newOption = newOption || {};
  19623. each$4(newOption, function (newCptOpt, mainType) {
  19624. if (newCptOpt == null) {
  19625. return;
  19626. }
  19627. var oldCptOpt = oldOption[mainType];
  19628. if (!ComponentModel.hasClass(mainType)) {
  19629. oldOption[mainType] = merge$1(oldCptOpt, newCptOpt, true);
  19630. }
  19631. else {
  19632. newCptOpt = normalizeToArray(newCptOpt);
  19633. oldCptOpt = normalizeToArray(oldCptOpt);
  19634. var mapResult = mappingToExists(oldCptOpt, newCptOpt);
  19635. oldOption[mainType] = map$1(mapResult, function (item) {
  19636. return (item.option && item.exist)
  19637. ? merge$1(item.exist, item.option, true)
  19638. : (item.exist || item.option);
  19639. });
  19640. }
  19641. });
  19642. }
  19643. /*
  19644. * Licensed to the Apache Software Foundation (ASF) under one
  19645. * or more contributor license agreements. See the NOTICE file
  19646. * distributed with this work for additional information
  19647. * regarding copyright ownership. The ASF licenses this file
  19648. * to you under the Apache License, Version 2.0 (the
  19649. * "License"); you may not use this file except in compliance
  19650. * with the License. You may obtain a copy of the License at
  19651. *
  19652. * http://www.apache.org/licenses/LICENSE-2.0
  19653. *
  19654. * Unless required by applicable law or agreed to in writing,
  19655. * software distributed under the License is distributed on an
  19656. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19657. * KIND, either express or implied. See the License for the
  19658. * specific language governing permissions and limitations
  19659. * under the License.
  19660. */
  19661. var each$5 = each$1;
  19662. var isObject$3 = isObject$1;
  19663. var POSSIBLE_STYLES = [
  19664. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  19665. 'chordStyle', 'label', 'labelLine'
  19666. ];
  19667. function compatEC2ItemStyle(opt) {
  19668. var itemStyleOpt = opt && opt.itemStyle;
  19669. if (!itemStyleOpt) {
  19670. return;
  19671. }
  19672. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  19673. var styleName = POSSIBLE_STYLES[i];
  19674. var normalItemStyleOpt = itemStyleOpt.normal;
  19675. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  19676. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  19677. opt[styleName] = opt[styleName] || {};
  19678. if (!opt[styleName].normal) {
  19679. opt[styleName].normal = normalItemStyleOpt[styleName];
  19680. }
  19681. else {
  19682. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  19683. }
  19684. normalItemStyleOpt[styleName] = null;
  19685. }
  19686. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  19687. opt[styleName] = opt[styleName] || {};
  19688. if (!opt[styleName].emphasis) {
  19689. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  19690. }
  19691. else {
  19692. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  19693. }
  19694. emphasisItemStyleOpt[styleName] = null;
  19695. }
  19696. }
  19697. }
  19698. function convertNormalEmphasis(opt, optType, useExtend) {
  19699. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  19700. var normalOpt = opt[optType].normal;
  19701. var emphasisOpt = opt[optType].emphasis;
  19702. if (normalOpt) {
  19703. // Timeline controlStyle has other properties besides normal and emphasis
  19704. if (useExtend) {
  19705. opt[optType].normal = opt[optType].emphasis = null;
  19706. defaults(opt[optType], normalOpt);
  19707. }
  19708. else {
  19709. opt[optType] = normalOpt;
  19710. }
  19711. }
  19712. if (emphasisOpt) {
  19713. opt.emphasis = opt.emphasis || {};
  19714. opt.emphasis[optType] = emphasisOpt;
  19715. }
  19716. }
  19717. }
  19718. function removeEC3NormalStatus(opt) {
  19719. convertNormalEmphasis(opt, 'itemStyle');
  19720. convertNormalEmphasis(opt, 'lineStyle');
  19721. convertNormalEmphasis(opt, 'areaStyle');
  19722. convertNormalEmphasis(opt, 'label');
  19723. convertNormalEmphasis(opt, 'labelLine');
  19724. // treemap
  19725. convertNormalEmphasis(opt, 'upperLabel');
  19726. // graph
  19727. convertNormalEmphasis(opt, 'edgeLabel');
  19728. }
  19729. function compatTextStyle(opt, propName) {
  19730. // Check whether is not object (string\null\undefined ...)
  19731. var labelOptSingle = isObject$3(opt) && opt[propName];
  19732. var textStyle = isObject$3(labelOptSingle) && labelOptSingle.textStyle;
  19733. if (textStyle) {
  19734. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  19735. var propName = TEXT_STYLE_OPTIONS[i];
  19736. if (textStyle.hasOwnProperty(propName)) {
  19737. labelOptSingle[propName] = textStyle[propName];
  19738. }
  19739. }
  19740. }
  19741. }
  19742. function compatEC3CommonStyles(opt) {
  19743. if (opt) {
  19744. removeEC3NormalStatus(opt);
  19745. compatTextStyle(opt, 'label');
  19746. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  19747. }
  19748. }
  19749. function processSeries(seriesOpt) {
  19750. if (!isObject$3(seriesOpt)) {
  19751. return;
  19752. }
  19753. compatEC2ItemStyle(seriesOpt);
  19754. removeEC3NormalStatus(seriesOpt);
  19755. compatTextStyle(seriesOpt, 'label');
  19756. // treemap
  19757. compatTextStyle(seriesOpt, 'upperLabel');
  19758. // graph
  19759. compatTextStyle(seriesOpt, 'edgeLabel');
  19760. if (seriesOpt.emphasis) {
  19761. compatTextStyle(seriesOpt.emphasis, 'label');
  19762. // treemap
  19763. compatTextStyle(seriesOpt.emphasis, 'upperLabel');
  19764. // graph
  19765. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  19766. }
  19767. var markPoint = seriesOpt.markPoint;
  19768. if (markPoint) {
  19769. compatEC2ItemStyle(markPoint);
  19770. compatEC3CommonStyles(markPoint);
  19771. }
  19772. var markLine = seriesOpt.markLine;
  19773. if (markLine) {
  19774. compatEC2ItemStyle(markLine);
  19775. compatEC3CommonStyles(markLine);
  19776. }
  19777. var markArea = seriesOpt.markArea;
  19778. if (markArea) {
  19779. compatEC3CommonStyles(markArea);
  19780. }
  19781. var data = seriesOpt.data;
  19782. // Break with ec3: if `setOption` again, there may be no `type` in option,
  19783. // then the backward compat based on option type will not be performed.
  19784. if (seriesOpt.type === 'graph') {
  19785. data = data || seriesOpt.nodes;
  19786. var edgeData = seriesOpt.links || seriesOpt.edges;
  19787. if (edgeData && !isTypedArray(edgeData)) {
  19788. for (var i = 0; i < edgeData.length; i++) {
  19789. compatEC3CommonStyles(edgeData[i]);
  19790. }
  19791. }
  19792. each$1(seriesOpt.categories, function (opt) {
  19793. removeEC3NormalStatus(opt);
  19794. });
  19795. }
  19796. if (data && !isTypedArray(data)) {
  19797. for (var i = 0; i < data.length; i++) {
  19798. compatEC3CommonStyles(data[i]);
  19799. }
  19800. }
  19801. // mark point data
  19802. var markPoint = seriesOpt.markPoint;
  19803. if (markPoint && markPoint.data) {
  19804. var mpData = markPoint.data;
  19805. for (var i = 0; i < mpData.length; i++) {
  19806. compatEC3CommonStyles(mpData[i]);
  19807. }
  19808. }
  19809. // mark line data
  19810. var markLine = seriesOpt.markLine;
  19811. if (markLine && markLine.data) {
  19812. var mlData = markLine.data;
  19813. for (var i = 0; i < mlData.length; i++) {
  19814. if (isArray(mlData[i])) {
  19815. compatEC3CommonStyles(mlData[i][0]);
  19816. compatEC3CommonStyles(mlData[i][1]);
  19817. }
  19818. else {
  19819. compatEC3CommonStyles(mlData[i]);
  19820. }
  19821. }
  19822. }
  19823. // Series
  19824. if (seriesOpt.type === 'gauge') {
  19825. compatTextStyle(seriesOpt, 'axisLabel');
  19826. compatTextStyle(seriesOpt, 'title');
  19827. compatTextStyle(seriesOpt, 'detail');
  19828. }
  19829. else if (seriesOpt.type === 'treemap') {
  19830. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  19831. each$1(seriesOpt.levels, function (opt) {
  19832. removeEC3NormalStatus(opt);
  19833. });
  19834. }
  19835. else if (seriesOpt.type === 'tree') {
  19836. removeEC3NormalStatus(seriesOpt.leaves);
  19837. }
  19838. // sunburst starts from ec4, so it does not need to compat levels.
  19839. }
  19840. function toArr(o) {
  19841. return isArray(o) ? o : o ? [o] : [];
  19842. }
  19843. function toObj(o) {
  19844. return (isArray(o) ? o[0] : o) || {};
  19845. }
  19846. var compatStyle = function (option, isTheme) {
  19847. each$5(toArr(option.series), function (seriesOpt) {
  19848. isObject$3(seriesOpt) && processSeries(seriesOpt);
  19849. });
  19850. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  19851. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  19852. each$5(
  19853. axes,
  19854. function (axisName) {
  19855. each$5(toArr(option[axisName]), function (axisOpt) {
  19856. if (axisOpt) {
  19857. compatTextStyle(axisOpt, 'axisLabel');
  19858. compatTextStyle(axisOpt.axisPointer, 'label');
  19859. }
  19860. });
  19861. }
  19862. );
  19863. each$5(toArr(option.parallel), function (parallelOpt) {
  19864. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  19865. compatTextStyle(parallelAxisDefault, 'axisLabel');
  19866. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  19867. });
  19868. each$5(toArr(option.calendar), function (calendarOpt) {
  19869. convertNormalEmphasis(calendarOpt, 'itemStyle');
  19870. compatTextStyle(calendarOpt, 'dayLabel');
  19871. compatTextStyle(calendarOpt, 'monthLabel');
  19872. compatTextStyle(calendarOpt, 'yearLabel');
  19873. });
  19874. // radar.name.textStyle
  19875. each$5(toArr(option.radar), function (radarOpt) {
  19876. compatTextStyle(radarOpt, 'name');
  19877. });
  19878. each$5(toArr(option.geo), function (geoOpt) {
  19879. if (isObject$3(geoOpt)) {
  19880. compatEC3CommonStyles(geoOpt);
  19881. each$5(toArr(geoOpt.regions), function (regionObj) {
  19882. compatEC3CommonStyles(regionObj);
  19883. });
  19884. }
  19885. });
  19886. each$5(toArr(option.timeline), function (timelineOpt) {
  19887. compatEC3CommonStyles(timelineOpt);
  19888. convertNormalEmphasis(timelineOpt, 'label');
  19889. convertNormalEmphasis(timelineOpt, 'itemStyle');
  19890. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  19891. var data = timelineOpt.data;
  19892. isArray(data) && each$1(data, function (item) {
  19893. if (isObject$1(item)) {
  19894. convertNormalEmphasis(item, 'label');
  19895. convertNormalEmphasis(item, 'itemStyle');
  19896. }
  19897. });
  19898. });
  19899. each$5(toArr(option.toolbox), function (toolboxOpt) {
  19900. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  19901. each$5(toolboxOpt.feature, function (featureOpt) {
  19902. convertNormalEmphasis(featureOpt, 'iconStyle');
  19903. });
  19904. });
  19905. compatTextStyle(toObj(option.axisPointer), 'label');
  19906. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  19907. };
  19908. /*
  19909. * Licensed to the Apache Software Foundation (ASF) under one
  19910. * or more contributor license agreements. See the NOTICE file
  19911. * distributed with this work for additional information
  19912. * regarding copyright ownership. The ASF licenses this file
  19913. * to you under the Apache License, Version 2.0 (the
  19914. * "License"); you may not use this file except in compliance
  19915. * with the License. You may obtain a copy of the License at
  19916. *
  19917. * http://www.apache.org/licenses/LICENSE-2.0
  19918. *
  19919. * Unless required by applicable law or agreed to in writing,
  19920. * software distributed under the License is distributed on an
  19921. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19922. * KIND, either express or implied. See the License for the
  19923. * specific language governing permissions and limitations
  19924. * under the License.
  19925. */
  19926. // Compatitable with 2.0
  19927. function get(opt, path) {
  19928. path = path.split(',');
  19929. var obj = opt;
  19930. for (var i = 0; i < path.length; i++) {
  19931. obj = obj && obj[path[i]];
  19932. if (obj == null) {
  19933. break;
  19934. }
  19935. }
  19936. return obj;
  19937. }
  19938. function set$1(opt, path, val, overwrite) {
  19939. path = path.split(',');
  19940. var obj = opt;
  19941. var key;
  19942. for (var i = 0; i < path.length - 1; i++) {
  19943. key = path[i];
  19944. if (obj[key] == null) {
  19945. obj[key] = {};
  19946. }
  19947. obj = obj[key];
  19948. }
  19949. if (overwrite || obj[path[i]] == null) {
  19950. obj[path[i]] = val;
  19951. }
  19952. }
  19953. function compatLayoutProperties(option) {
  19954. each$1(LAYOUT_PROPERTIES, function (prop) {
  19955. if (prop[0] in option && !(prop[1] in option)) {
  19956. option[prop[1]] = option[prop[0]];
  19957. }
  19958. });
  19959. }
  19960. var LAYOUT_PROPERTIES = [
  19961. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  19962. ];
  19963. var COMPATITABLE_COMPONENTS = [
  19964. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  19965. ];
  19966. var backwardCompat = function (option, isTheme) {
  19967. compatStyle(option, isTheme);
  19968. // Make sure series array for model initialization.
  19969. option.series = normalizeToArray(option.series);
  19970. each$1(option.series, function (seriesOpt) {
  19971. if (!isObject$1(seriesOpt)) {
  19972. return;
  19973. }
  19974. var seriesType = seriesOpt.type;
  19975. if (seriesType === 'line') {
  19976. if (seriesOpt.clipOverflow != null) {
  19977. seriesOpt.clip = seriesOpt.clipOverflow;
  19978. }
  19979. }
  19980. else if (seriesType === 'pie' || seriesType === 'gauge') {
  19981. if (seriesOpt.clockWise != null) {
  19982. seriesOpt.clockwise = seriesOpt.clockWise;
  19983. }
  19984. }
  19985. else if (seriesType === 'gauge') {
  19986. var pointerColor = get(seriesOpt, 'pointer.color');
  19987. pointerColor != null
  19988. && set$1(seriesOpt, 'itemStyle.color', pointerColor);
  19989. }
  19990. compatLayoutProperties(seriesOpt);
  19991. });
  19992. // dataRange has changed to visualMap
  19993. if (option.dataRange) {
  19994. option.visualMap = option.dataRange;
  19995. }
  19996. each$1(COMPATITABLE_COMPONENTS, function (componentName) {
  19997. var options = option[componentName];
  19998. if (options) {
  19999. if (!isArray(options)) {
  20000. options = [options];
  20001. }
  20002. each$1(options, function (option) {
  20003. compatLayoutProperties(option);
  20004. });
  20005. }
  20006. });
  20007. };
  20008. /*
  20009. * Licensed to the Apache Software Foundation (ASF) under one
  20010. * or more contributor license agreements. See the NOTICE file
  20011. * distributed with this work for additional information
  20012. * regarding copyright ownership. The ASF licenses this file
  20013. * to you under the Apache License, Version 2.0 (the
  20014. * "License"); you may not use this file except in compliance
  20015. * with the License. You may obtain a copy of the License at
  20016. *
  20017. * http://www.apache.org/licenses/LICENSE-2.0
  20018. *
  20019. * Unless required by applicable law or agreed to in writing,
  20020. * software distributed under the License is distributed on an
  20021. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20022. * KIND, either express or implied. See the License for the
  20023. * specific language governing permissions and limitations
  20024. * under the License.
  20025. */
  20026. // (1) [Caution]: the logic is correct based on the premises:
  20027. // data processing stage is blocked in stream.
  20028. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  20029. // (2) Only register once when import repeatly.
  20030. // Should be executed after series filtered and before stack calculation.
  20031. var dataStack = function (ecModel) {
  20032. var stackInfoMap = createHashMap();
  20033. ecModel.eachSeries(function (seriesModel) {
  20034. var stack = seriesModel.get('stack');
  20035. // Compatibal: when `stack` is set as '', do not stack.
  20036. if (stack) {
  20037. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  20038. var data = seriesModel.getData();
  20039. var stackInfo = {
  20040. // Used for calculate axis extent automatically.
  20041. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  20042. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  20043. stackedDimension: data.getCalculationInfo('stackedDimension'),
  20044. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  20045. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  20046. data: data,
  20047. seriesModel: seriesModel
  20048. };
  20049. // If stacked on axis that do not support data stack.
  20050. if (!stackInfo.stackedDimension
  20051. || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)
  20052. ) {
  20053. return;
  20054. }
  20055. stackInfoList.length && data.setCalculationInfo(
  20056. 'stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel
  20057. );
  20058. stackInfoList.push(stackInfo);
  20059. }
  20060. });
  20061. stackInfoMap.each(calculateStack);
  20062. };
  20063. function calculateStack(stackInfoList) {
  20064. each$1(stackInfoList, function (targetStackInfo, idxInStack) {
  20065. var resultVal = [];
  20066. var resultNaN = [NaN, NaN];
  20067. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  20068. var targetData = targetStackInfo.data;
  20069. var isStackedByIndex = targetStackInfo.isStackedByIndex;
  20070. // Should not write on raw data, because stack series model list changes
  20071. // depending on legend selection.
  20072. var newData = targetData.map(dims, function (v0, v1, dataIndex) {
  20073. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex);
  20074. // Consider `connectNulls` of line area, if value is NaN, stackedOver
  20075. // should also be NaN, to draw a appropriate belt area.
  20076. if (isNaN(sum)) {
  20077. return resultNaN;
  20078. }
  20079. var byValue;
  20080. var stackedDataRawIndex;
  20081. if (isStackedByIndex) {
  20082. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  20083. }
  20084. else {
  20085. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  20086. }
  20087. // If stackOver is NaN, chart view will render point on value start.
  20088. var stackedOver = NaN;
  20089. for (var j = idxInStack - 1; j >= 0; j--) {
  20090. var stackInfo = stackInfoList[j];
  20091. // Has been optimized by inverted indices on `stackedByDimension`.
  20092. if (!isStackedByIndex) {
  20093. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  20094. }
  20095. if (stackedDataRawIndex >= 0) {
  20096. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex);
  20097. // Considering positive stack, negative stack and empty data
  20098. if ((sum >= 0 && val > 0) // Positive stack
  20099. || (sum <= 0 && val < 0) // Negative stack
  20100. ) {
  20101. sum += val;
  20102. stackedOver = val;
  20103. break;
  20104. }
  20105. }
  20106. }
  20107. resultVal[0] = sum;
  20108. resultVal[1] = stackedOver;
  20109. return resultVal;
  20110. });
  20111. targetData.hostModel.setData(newData);
  20112. // Update for consequent calculation
  20113. targetStackInfo.data = newData;
  20114. });
  20115. }
  20116. /*
  20117. * Licensed to the Apache Software Foundation (ASF) under one
  20118. * or more contributor license agreements. See the NOTICE file
  20119. * distributed with this work for additional information
  20120. * regarding copyright ownership. The ASF licenses this file
  20121. * to you under the Apache License, Version 2.0 (the
  20122. * "License"); you may not use this file except in compliance
  20123. * with the License. You may obtain a copy of the License at
  20124. *
  20125. * http://www.apache.org/licenses/LICENSE-2.0
  20126. *
  20127. * Unless required by applicable law or agreed to in writing,
  20128. * software distributed under the License is distributed on an
  20129. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20130. * KIND, either express or implied. See the License for the
  20131. * specific language governing permissions and limitations
  20132. * under the License.
  20133. */
  20134. // TODO
  20135. // ??? refactor? check the outer usage of data provider.
  20136. // merge with defaultDimValueGetter?
  20137. /**
  20138. * If normal array used, mutable chunk size is supported.
  20139. * If typed array used, chunk size must be fixed.
  20140. */
  20141. function DefaultDataProvider(source, dimSize) {
  20142. if (!Source.isInstance(source)) {
  20143. source = Source.seriesDataToSource(source);
  20144. }
  20145. this._source = source;
  20146. var data = this._data = source.data;
  20147. var sourceFormat = source.sourceFormat;
  20148. // Typed array. TODO IE10+?
  20149. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  20150. if (__DEV__) {
  20151. if (dimSize == null) {
  20152. throw new Error('Typed array data must specify dimension size');
  20153. }
  20154. }
  20155. this._offset = 0;
  20156. this._dimSize = dimSize;
  20157. this._data = data;
  20158. }
  20159. var methods = providerMethods[
  20160. sourceFormat === SOURCE_FORMAT_ARRAY_ROWS
  20161. ? sourceFormat + '_' + source.seriesLayoutBy
  20162. : sourceFormat
  20163. ];
  20164. if (__DEV__) {
  20165. assert$1(methods, 'Invalide sourceFormat: ' + sourceFormat);
  20166. }
  20167. extend(this, methods);
  20168. }
  20169. var providerProto = DefaultDataProvider.prototype;
  20170. // If data is pure without style configuration
  20171. providerProto.pure = false;
  20172. // If data is persistent and will not be released after use.
  20173. providerProto.persistent = true;
  20174. // ???! FIXME legacy data provider do not has method getSource
  20175. providerProto.getSource = function () {
  20176. return this._source;
  20177. };
  20178. var providerMethods = {
  20179. 'arrayRows_column': {
  20180. pure: true,
  20181. count: function () {
  20182. return Math.max(0, this._data.length - this._source.startIndex);
  20183. },
  20184. getItem: function (idx) {
  20185. return this._data[idx + this._source.startIndex];
  20186. },
  20187. appendData: appendDataSimply
  20188. },
  20189. 'arrayRows_row': {
  20190. pure: true,
  20191. count: function () {
  20192. var row = this._data[0];
  20193. return row ? Math.max(0, row.length - this._source.startIndex) : 0;
  20194. },
  20195. getItem: function (idx) {
  20196. idx += this._source.startIndex;
  20197. var item = [];
  20198. var data = this._data;
  20199. for (var i = 0; i < data.length; i++) {
  20200. var row = data[i];
  20201. item.push(row ? row[idx] : null);
  20202. }
  20203. return item;
  20204. },
  20205. appendData: function () {
  20206. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  20207. }
  20208. },
  20209. 'objectRows': {
  20210. pure: true,
  20211. count: countSimply,
  20212. getItem: getItemSimply,
  20213. appendData: appendDataSimply
  20214. },
  20215. 'keyedColumns': {
  20216. pure: true,
  20217. count: function () {
  20218. var dimName = this._source.dimensionsDefine[0].name;
  20219. var col = this._data[dimName];
  20220. return col ? col.length : 0;
  20221. },
  20222. getItem: function (idx) {
  20223. var item = [];
  20224. var dims = this._source.dimensionsDefine;
  20225. for (var i = 0; i < dims.length; i++) {
  20226. var col = this._data[dims[i].name];
  20227. item.push(col ? col[idx] : null);
  20228. }
  20229. return item;
  20230. },
  20231. appendData: function (newData) {
  20232. var data = this._data;
  20233. each$1(newData, function (newCol, key) {
  20234. var oldCol = data[key] || (data[key] = []);
  20235. for (var i = 0; i < (newCol || []).length; i++) {
  20236. oldCol.push(newCol[i]);
  20237. }
  20238. });
  20239. }
  20240. },
  20241. 'original': {
  20242. count: countSimply,
  20243. getItem: getItemSimply,
  20244. appendData: appendDataSimply
  20245. },
  20246. 'typedArray': {
  20247. persistent: false,
  20248. pure: true,
  20249. count: function () {
  20250. return this._data ? (this._data.length / this._dimSize) : 0;
  20251. },
  20252. getItem: function (idx, out) {
  20253. idx = idx - this._offset;
  20254. out = out || [];
  20255. var offset = this._dimSize * idx;
  20256. for (var i = 0; i < this._dimSize; i++) {
  20257. out[i] = this._data[offset + i];
  20258. }
  20259. return out;
  20260. },
  20261. appendData: function (newData) {
  20262. if (__DEV__) {
  20263. assert$1(
  20264. isTypedArray(newData),
  20265. 'Added data must be TypedArray if data in initialization is TypedArray'
  20266. );
  20267. }
  20268. this._data = newData;
  20269. },
  20270. // Clean self if data is already used.
  20271. clean: function () {
  20272. // PENDING
  20273. this._offset += this.count();
  20274. this._data = null;
  20275. }
  20276. }
  20277. };
  20278. function countSimply() {
  20279. return this._data.length;
  20280. }
  20281. function getItemSimply(idx) {
  20282. return this._data[idx];
  20283. }
  20284. function appendDataSimply(newData) {
  20285. for (var i = 0; i < newData.length; i++) {
  20286. this._data.push(newData[i]);
  20287. }
  20288. }
  20289. var rawValueGetters = {
  20290. arrayRows: getRawValueSimply,
  20291. objectRows: function (dataItem, dataIndex, dimIndex, dimName) {
  20292. return dimIndex != null ? dataItem[dimName] : dataItem;
  20293. },
  20294. keyedColumns: getRawValueSimply,
  20295. original: function (dataItem, dataIndex, dimIndex, dimName) {
  20296. // FIXME
  20297. // In some case (markpoint in geo (geo-map.html)), dataItem
  20298. // is {coord: [...]}
  20299. var value = getDataItemValue(dataItem);
  20300. return (dimIndex == null || !(value instanceof Array))
  20301. ? value
  20302. : value[dimIndex];
  20303. },
  20304. typedArray: getRawValueSimply
  20305. };
  20306. function getRawValueSimply(dataItem, dataIndex, dimIndex, dimName) {
  20307. return dimIndex != null ? dataItem[dimIndex] : dataItem;
  20308. }
  20309. var defaultDimValueGetters = {
  20310. arrayRows: getDimValueSimply,
  20311. objectRows: function (dataItem, dimName, dataIndex, dimIndex) {
  20312. return converDataValue(dataItem[dimName], this._dimensionInfos[dimName]);
  20313. },
  20314. keyedColumns: getDimValueSimply,
  20315. original: function (dataItem, dimName, dataIndex, dimIndex) {
  20316. // Performance sensitive, do not use modelUtil.getDataItemValue.
  20317. // If dataItem is an plain object with no value field, the var `value`
  20318. // will be assigned with the object, but it will be tread correctly
  20319. // in the `convertDataValue`.
  20320. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  20321. // If any dataItem is like { value: 10 }
  20322. if (!this._rawData.pure && isDataItemOption(dataItem)) {
  20323. this.hasItemOption = true;
  20324. }
  20325. return converDataValue(
  20326. (value instanceof Array)
  20327. ? value[dimIndex]
  20328. // If value is a single number or something else not array.
  20329. : value,
  20330. this._dimensionInfos[dimName]
  20331. );
  20332. },
  20333. typedArray: function (dataItem, dimName, dataIndex, dimIndex) {
  20334. return dataItem[dimIndex];
  20335. }
  20336. };
  20337. function getDimValueSimply(dataItem, dimName, dataIndex, dimIndex) {
  20338. return converDataValue(dataItem[dimIndex], this._dimensionInfos[dimName]);
  20339. }
  20340. /**
  20341. * This helper method convert value in data.
  20342. * @param {string|number|Date} value
  20343. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  20344. * If "dimInfo.ordinalParseAndSave", ordinal value can be parsed.
  20345. */
  20346. function converDataValue(value, dimInfo) {
  20347. // Performance sensitive.
  20348. var dimType = dimInfo && dimInfo.type;
  20349. if (dimType === 'ordinal') {
  20350. // If given value is a category string
  20351. var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
  20352. return ordinalMeta
  20353. ? ordinalMeta.parseAndCollect(value)
  20354. : value;
  20355. }
  20356. if (dimType === 'time'
  20357. // spead up when using timestamp
  20358. && typeof value !== 'number'
  20359. && value != null
  20360. && value !== '-'
  20361. ) {
  20362. value = +parseDate(value);
  20363. }
  20364. // dimType defaults 'number'.
  20365. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  20366. // parse to NaN.
  20367. return (value == null || value === '')
  20368. ? NaN
  20369. // If string (like '-'), using '+' parse to NaN
  20370. // If object, also parse to NaN
  20371. : +value;
  20372. }
  20373. // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  20374. // Consider persistent.
  20375. // Caution: why use raw value to display on label or tooltip?
  20376. // A reason is to avoid format. For example time value we do not know
  20377. // how to format is expected. More over, if stack is used, calculated
  20378. // value may be 0.91000000001, which have brings trouble to display.
  20379. // TODO: consider how to treat null/undefined/NaN when display?
  20380. /**
  20381. * @param {module:echarts/data/List} data
  20382. * @param {number} dataIndex
  20383. * @param {string|number} [dim] dimName or dimIndex
  20384. * @return {Array.<number>|string|number} can be null/undefined.
  20385. */
  20386. function retrieveRawValue(data, dataIndex, dim) {
  20387. if (!data) {
  20388. return;
  20389. }
  20390. // Consider data may be not persistent.
  20391. var dataItem = data.getRawDataItem(dataIndex);
  20392. if (dataItem == null) {
  20393. return;
  20394. }
  20395. var sourceFormat = data.getProvider().getSource().sourceFormat;
  20396. var dimName;
  20397. var dimIndex;
  20398. var dimInfo = data.getDimensionInfo(dim);
  20399. if (dimInfo) {
  20400. dimName = dimInfo.name;
  20401. dimIndex = dimInfo.index;
  20402. }
  20403. return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);
  20404. }
  20405. /**
  20406. * Compatible with some cases (in pie, map) like:
  20407. * data: [{name: 'xx', value: 5, selected: true}, ...]
  20408. * where only sourceFormat is 'original' and 'objectRows' supported.
  20409. *
  20410. * ??? TODO
  20411. * Supported detail options in data item when using 'arrayRows'.
  20412. *
  20413. * @param {module:echarts/data/List} data
  20414. * @param {number} dataIndex
  20415. * @param {string} attr like 'selected'
  20416. */
  20417. function retrieveRawAttr(data, dataIndex, attr) {
  20418. if (!data) {
  20419. return;
  20420. }
  20421. var sourceFormat = data.getProvider().getSource().sourceFormat;
  20422. if (sourceFormat !== SOURCE_FORMAT_ORIGINAL
  20423. && sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS
  20424. ) {
  20425. return;
  20426. }
  20427. var dataItem = data.getRawDataItem(dataIndex);
  20428. if (sourceFormat === SOURCE_FORMAT_ORIGINAL && !isObject$1(dataItem)) {
  20429. dataItem = null;
  20430. }
  20431. if (dataItem) {
  20432. return dataItem[attr];
  20433. }
  20434. }
  20435. /*
  20436. * Licensed to the Apache Software Foundation (ASF) under one
  20437. * or more contributor license agreements. See the NOTICE file
  20438. * distributed with this work for additional information
  20439. * regarding copyright ownership. The ASF licenses this file
  20440. * to you under the Apache License, Version 2.0 (the
  20441. * "License"); you may not use this file except in compliance
  20442. * with the License. You may obtain a copy of the License at
  20443. *
  20444. * http://www.apache.org/licenses/LICENSE-2.0
  20445. *
  20446. * Unless required by applicable law or agreed to in writing,
  20447. * software distributed under the License is distributed on an
  20448. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20449. * KIND, either express or implied. See the License for the
  20450. * specific language governing permissions and limitations
  20451. * under the License.
  20452. */
  20453. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g;
  20454. // PENDING A little ugly
  20455. var dataFormatMixin = {
  20456. /**
  20457. * Get params for formatter
  20458. * @param {number} dataIndex
  20459. * @param {string} [dataType]
  20460. * @return {Object}
  20461. */
  20462. getDataParams: function (dataIndex, dataType) {
  20463. var data = this.getData(dataType);
  20464. var rawValue = this.getRawValue(dataIndex, dataType);
  20465. var rawDataIndex = data.getRawIndex(dataIndex);
  20466. var name = data.getName(dataIndex);
  20467. var itemOpt = data.getRawDataItem(dataIndex);
  20468. var color = data.getItemVisual(dataIndex, 'color');
  20469. var borderColor = data.getItemVisual(dataIndex, 'borderColor');
  20470. var tooltipModel = this.ecModel.getComponent('tooltip');
  20471. var renderModeOption = tooltipModel && tooltipModel.get('renderMode');
  20472. var renderMode = getTooltipRenderMode(renderModeOption);
  20473. var mainType = this.mainType;
  20474. var isSeries = mainType === 'series';
  20475. var userOutput = data.userOutput;
  20476. return {
  20477. componentType: mainType,
  20478. componentSubType: this.subType,
  20479. componentIndex: this.componentIndex,
  20480. seriesType: isSeries ? this.subType : null,
  20481. seriesIndex: this.seriesIndex,
  20482. seriesId: isSeries ? this.id : null,
  20483. seriesName: isSeries ? this.name : null,
  20484. name: name,
  20485. dataIndex: rawDataIndex,
  20486. data: itemOpt,
  20487. dataType: dataType,
  20488. value: rawValue,
  20489. color: color,
  20490. borderColor: borderColor,
  20491. dimensionNames: userOutput ? userOutput.dimensionNames : null,
  20492. encode: userOutput ? userOutput.encode : null,
  20493. marker: getTooltipMarker({
  20494. color: color,
  20495. renderMode: renderMode
  20496. }),
  20497. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  20498. $vars: ['seriesName', 'name', 'value']
  20499. };
  20500. },
  20501. /**
  20502. * Format label
  20503. * @param {number} dataIndex
  20504. * @param {string} [status='normal'] 'normal' or 'emphasis'
  20505. * @param {string} [dataType]
  20506. * @param {number} [dimIndex] Only used in some chart that
  20507. * use formatter in different dimensions, like radar.
  20508. * @param {string} [labelProp='label']
  20509. * @return {string} If not formatter, return null/undefined
  20510. */
  20511. getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {
  20512. status = status || 'normal';
  20513. var data = this.getData(dataType);
  20514. var itemModel = data.getItemModel(dataIndex);
  20515. var params = this.getDataParams(dataIndex, dataType);
  20516. if (dimIndex != null && (params.value instanceof Array)) {
  20517. params.value = params.value[dimIndex];
  20518. }
  20519. var formatter = itemModel.get(
  20520. status === 'normal'
  20521. ? [labelProp || 'label', 'formatter']
  20522. : [status, labelProp || 'label', 'formatter']
  20523. );
  20524. if (typeof formatter === 'function') {
  20525. params.status = status;
  20526. params.dimensionIndex = dimIndex;
  20527. return formatter(params);
  20528. }
  20529. else if (typeof formatter === 'string') {
  20530. var str = formatTpl(formatter, params);
  20531. // Support 'aaa{@[3]}bbb{@product}ccc'.
  20532. // Do not support '}' in dim name util have to.
  20533. return str.replace(DIMENSION_LABEL_REG, function (origin, dim) {
  20534. var len = dim.length;
  20535. if (dim.charAt(0) === '[' && dim.charAt(len - 1) === ']') {
  20536. dim = +dim.slice(1, len - 1); // Also: '[]' => 0
  20537. }
  20538. return retrieveRawValue(data, dataIndex, dim);
  20539. });
  20540. }
  20541. },
  20542. /**
  20543. * Get raw value in option
  20544. * @param {number} idx
  20545. * @param {string} [dataType]
  20546. * @return {Array|number|string}
  20547. */
  20548. getRawValue: function (idx, dataType) {
  20549. return retrieveRawValue(this.getData(dataType), idx);
  20550. },
  20551. /**
  20552. * Should be implemented.
  20553. * @param {number} dataIndex
  20554. * @param {boolean} [multipleSeries=false]
  20555. * @param {number} [dataType]
  20556. * @return {string} tooltip string
  20557. */
  20558. formatTooltip: function () {
  20559. // Empty function
  20560. }
  20561. };
  20562. /*
  20563. * Licensed to the Apache Software Foundation (ASF) under one
  20564. * or more contributor license agreements. See the NOTICE file
  20565. * distributed with this work for additional information
  20566. * regarding copyright ownership. The ASF licenses this file
  20567. * to you under the Apache License, Version 2.0 (the
  20568. * "License"); you may not use this file except in compliance
  20569. * with the License. You may obtain a copy of the License at
  20570. *
  20571. * http://www.apache.org/licenses/LICENSE-2.0
  20572. *
  20573. * Unless required by applicable law or agreed to in writing,
  20574. * software distributed under the License is distributed on an
  20575. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20576. * KIND, either express or implied. See the License for the
  20577. * specific language governing permissions and limitations
  20578. * under the License.
  20579. */
  20580. /**
  20581. * @param {Object} define
  20582. * @return See the return of `createTask`.
  20583. */
  20584. function createTask(define) {
  20585. return new Task(define);
  20586. }
  20587. /**
  20588. * @constructor
  20589. * @param {Object} define
  20590. * @param {Function} define.reset Custom reset
  20591. * @param {Function} [define.plan] Returns 'reset' indicate reset immediately.
  20592. * @param {Function} [define.count] count is used to determin data task.
  20593. * @param {Function} [define.onDirty] count is used to determin data task.
  20594. */
  20595. function Task(define) {
  20596. define = define || {};
  20597. this._reset = define.reset;
  20598. this._plan = define.plan;
  20599. this._count = define.count;
  20600. this._onDirty = define.onDirty;
  20601. this._dirty = true;
  20602. // Context must be specified implicitly, to
  20603. // avoid miss update context when model changed.
  20604. this.context;
  20605. }
  20606. var taskProto = Task.prototype;
  20607. /**
  20608. * @param {Object} performArgs
  20609. * @param {number} [performArgs.step] Specified step.
  20610. * @param {number} [performArgs.skip] Skip customer perform call.
  20611. * @param {number} [performArgs.modBy] Sampling window size.
  20612. * @param {number} [performArgs.modDataCount] Sampling count.
  20613. */
  20614. taskProto.perform = function (performArgs) {
  20615. var upTask = this._upstream;
  20616. var skip = performArgs && performArgs.skip;
  20617. // TODO some refactor.
  20618. // Pull data. Must pull data each time, because context.data
  20619. // may be updated by Series.setData.
  20620. if (this._dirty && upTask) {
  20621. var context = this.context;
  20622. context.data = context.outputData = upTask.context.outputData;
  20623. }
  20624. if (this.__pipeline) {
  20625. this.__pipeline.currentTask = this;
  20626. }
  20627. var planResult;
  20628. if (this._plan && !skip) {
  20629. planResult = this._plan(this.context);
  20630. }
  20631. // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  20632. // elements uniformed distributed when progress, especially when moving or zooming.
  20633. var lastModBy = normalizeModBy(this._modBy);
  20634. var lastModDataCount = this._modDataCount || 0;
  20635. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  20636. var modDataCount = performArgs && performArgs.modDataCount || 0;
  20637. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  20638. planResult = 'reset';
  20639. }
  20640. function normalizeModBy(val) {
  20641. !(val >= 1) && (val = 1); // jshint ignore:line
  20642. return val;
  20643. }
  20644. var forceFirstProgress;
  20645. if (this._dirty || planResult === 'reset') {
  20646. this._dirty = false;
  20647. forceFirstProgress = reset(this, skip);
  20648. }
  20649. this._modBy = modBy;
  20650. this._modDataCount = modDataCount;
  20651. var step = performArgs && performArgs.step;
  20652. if (upTask) {
  20653. if (__DEV__) {
  20654. assert$1(upTask._outputDueEnd != null);
  20655. }
  20656. this._dueEnd = upTask._outputDueEnd;
  20657. }
  20658. // DataTask or overallTask
  20659. else {
  20660. if (__DEV__) {
  20661. assert$1(!this._progress || this._count);
  20662. }
  20663. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  20664. }
  20665. // Note: Stubs, that its host overall task let it has progress, has progress.
  20666. // If no progress, pass index from upstream to downstream each time plan called.
  20667. if (this._progress) {
  20668. var start = this._dueIndex;
  20669. var end = Math.min(
  20670. step != null ? this._dueIndex + step : Infinity,
  20671. this._dueEnd
  20672. );
  20673. if (!skip && (forceFirstProgress || start < end)) {
  20674. var progress = this._progress;
  20675. if (isArray(progress)) {
  20676. for (var i = 0; i < progress.length; i++) {
  20677. doProgress(this, progress[i], start, end, modBy, modDataCount);
  20678. }
  20679. }
  20680. else {
  20681. doProgress(this, progress, start, end, modBy, modDataCount);
  20682. }
  20683. }
  20684. this._dueIndex = end;
  20685. // If no `outputDueEnd`, assume that output data and
  20686. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  20687. var outputDueEnd = this._settedOutputEnd != null
  20688. ? this._settedOutputEnd : end;
  20689. if (__DEV__) {
  20690. // ??? Can not rollback.
  20691. assert$1(outputDueEnd >= this._outputDueEnd);
  20692. }
  20693. this._outputDueEnd = outputDueEnd;
  20694. }
  20695. else {
  20696. // (1) Some overall task has no progress.
  20697. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  20698. // This should always be performed so it can be passed to downstream.
  20699. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null
  20700. ? this._settedOutputEnd : this._dueEnd;
  20701. }
  20702. return this.unfinished();
  20703. };
  20704. var iterator = (function () {
  20705. var end;
  20706. var current;
  20707. var modBy;
  20708. var modDataCount;
  20709. var winCount;
  20710. var it = {
  20711. reset: function (s, e, sStep, sCount) {
  20712. current = s;
  20713. end = e;
  20714. modBy = sStep;
  20715. modDataCount = sCount;
  20716. winCount = Math.ceil(modDataCount / modBy);
  20717. it.next = (modBy > 1 && modDataCount > 0) ? modNext : sequentialNext;
  20718. }
  20719. };
  20720. return it;
  20721. function sequentialNext() {
  20722. return current < end ? current++ : null;
  20723. }
  20724. function modNext() {
  20725. var dataIndex = (current % winCount) * modBy + Math.ceil(current / winCount);
  20726. var result = current >= end
  20727. ? null
  20728. : dataIndex < modDataCount
  20729. ? dataIndex
  20730. // If modDataCount is smaller than data.count() (consider `appendData` case),
  20731. // Use normal linear rendering mode.
  20732. : current;
  20733. current++;
  20734. return result;
  20735. }
  20736. })();
  20737. taskProto.dirty = function () {
  20738. this._dirty = true;
  20739. this._onDirty && this._onDirty(this.context);
  20740. };
  20741. function doProgress(taskIns, progress, start, end, modBy, modDataCount) {
  20742. iterator.reset(start, end, modBy, modDataCount);
  20743. taskIns._callingProgress = progress;
  20744. taskIns._callingProgress({
  20745. start: start, end: end, count: end - start, next: iterator.next
  20746. }, taskIns.context);
  20747. }
  20748. function reset(taskIns, skip) {
  20749. taskIns._dueIndex = taskIns._outputDueEnd = taskIns._dueEnd = 0;
  20750. taskIns._settedOutputEnd = null;
  20751. var progress;
  20752. var forceFirstProgress;
  20753. if (!skip && taskIns._reset) {
  20754. progress = taskIns._reset(taskIns.context);
  20755. if (progress && progress.progress) {
  20756. forceFirstProgress = progress.forceFirstProgress;
  20757. progress = progress.progress;
  20758. }
  20759. // To simplify no progress checking, array must has item.
  20760. if (isArray(progress) && !progress.length) {
  20761. progress = null;
  20762. }
  20763. }
  20764. taskIns._progress = progress;
  20765. taskIns._modBy = taskIns._modDataCount = null;
  20766. var downstream = taskIns._downstream;
  20767. downstream && downstream.dirty();
  20768. return forceFirstProgress;
  20769. }
  20770. /**
  20771. * @return {boolean}
  20772. */
  20773. taskProto.unfinished = function () {
  20774. return this._progress && this._dueIndex < this._dueEnd;
  20775. };
  20776. /**
  20777. * @param {Object} downTask The downstream task.
  20778. * @return {Object} The downstream task.
  20779. */
  20780. taskProto.pipe = function (downTask) {
  20781. if (__DEV__) {
  20782. assert$1(downTask && !downTask._disposed && downTask !== this);
  20783. }
  20784. // If already downstream, do not dirty downTask.
  20785. if (this._downstream !== downTask || this._dirty) {
  20786. this._downstream = downTask;
  20787. downTask._upstream = this;
  20788. downTask.dirty();
  20789. }
  20790. };
  20791. taskProto.dispose = function () {
  20792. if (this._disposed) {
  20793. return;
  20794. }
  20795. this._upstream && (this._upstream._downstream = null);
  20796. this._downstream && (this._downstream._upstream = null);
  20797. this._dirty = false;
  20798. this._disposed = true;
  20799. };
  20800. taskProto.getUpstream = function () {
  20801. return this._upstream;
  20802. };
  20803. taskProto.getDownstream = function () {
  20804. return this._downstream;
  20805. };
  20806. taskProto.setOutputEnd = function (end) {
  20807. // This only happend in dataTask, dataZoom, map, currently.
  20808. // where dataZoom do not set end each time, but only set
  20809. // when reset. So we should record the setted end, in case
  20810. // that the stub of dataZoom perform again and earse the
  20811. // setted end by upstream.
  20812. this._outputDueEnd = this._settedOutputEnd = end;
  20813. };
  20814. ///////////////////////////////////////////////////////////
  20815. // For stream debug (Should be commented out after used!)
  20816. // Usage: printTask(this, 'begin');
  20817. // Usage: printTask(this, null, {someExtraProp});
  20818. // function printTask(task, prefix, extra) {
  20819. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  20820. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  20821. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  20822. // var props = [];
  20823. // if (task.__pipeline) {
  20824. // var val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  20825. // props.push({text: 'idx', value: val});
  20826. // } else {
  20827. // var stubCount = 0;
  20828. // task.agentStubMap.each(() => stubCount++);
  20829. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  20830. // }
  20831. // props.push({text: 'uid', value: task.uidDebug});
  20832. // if (task.__pipeline) {
  20833. // props.push({text: 'pid', value: task.__pipeline.id});
  20834. // task.agent && props.push(
  20835. // {text: 'stubFor', value: task.agent.uidDebug}
  20836. // );
  20837. // }
  20838. // props.push(
  20839. // {text: 'dirty', value: task._dirty},
  20840. // {text: 'dueIndex', value: task._dueIndex},
  20841. // {text: 'dueEnd', value: task._dueEnd},
  20842. // {text: 'outputDueEnd', value: task._outputDueEnd}
  20843. // );
  20844. // if (extra) {
  20845. // Object.keys(extra).forEach(key => {
  20846. // props.push({text: key, value: extra[key]});
  20847. // });
  20848. // }
  20849. // var args = ['color: blue'];
  20850. // var msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  20851. // args.push('color: black', 'color: red'),
  20852. // `${item.text}: %c${item.value}`
  20853. // )).join('%c, ');
  20854. // console.log.apply(console, [msg].concat(args));
  20855. // // console.log(this);
  20856. // }
  20857. /*
  20858. * Licensed to the Apache Software Foundation (ASF) under one
  20859. * or more contributor license agreements. See the NOTICE file
  20860. * distributed with this work for additional information
  20861. * regarding copyright ownership. The ASF licenses this file
  20862. * to you under the Apache License, Version 2.0 (the
  20863. * "License"); you may not use this file except in compliance
  20864. * with the License. You may obtain a copy of the License at
  20865. *
  20866. * http://www.apache.org/licenses/LICENSE-2.0
  20867. *
  20868. * Unless required by applicable law or agreed to in writing,
  20869. * software distributed under the License is distributed on an
  20870. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20871. * KIND, either express or implied. See the License for the
  20872. * specific language governing permissions and limitations
  20873. * under the License.
  20874. */
  20875. var inner$4 = makeInner();
  20876. var SeriesModel = ComponentModel.extend({
  20877. type: 'series.__base__',
  20878. /**
  20879. * @readOnly
  20880. */
  20881. seriesIndex: 0,
  20882. // coodinateSystem will be injected in the echarts/CoordinateSystem
  20883. coordinateSystem: null,
  20884. /**
  20885. * @type {Object}
  20886. * @protected
  20887. */
  20888. defaultOption: null,
  20889. /**
  20890. * legend visual provider to the legend component
  20891. * @type {Object}
  20892. */
  20893. // PENDING
  20894. legendVisualProvider: null,
  20895. /**
  20896. * Access path of color for visual
  20897. */
  20898. visualColorAccessPath: 'itemStyle.color',
  20899. /**
  20900. * Access path of borderColor for visual
  20901. */
  20902. visualBorderColorAccessPath: 'itemStyle.borderColor',
  20903. /**
  20904. * Support merge layout params.
  20905. * Only support 'box' now (left/right/top/bottom/width/height).
  20906. * @type {string|Object} Object can be {ignoreSize: true}
  20907. * @readOnly
  20908. */
  20909. layoutMode: null,
  20910. init: function (option, parentModel, ecModel, extraOpt) {
  20911. /**
  20912. * @type {number}
  20913. * @readOnly
  20914. */
  20915. this.seriesIndex = this.componentIndex;
  20916. this.dataTask = createTask({
  20917. count: dataTaskCount,
  20918. reset: dataTaskReset
  20919. });
  20920. this.dataTask.context = {model: this};
  20921. this.mergeDefaultAndTheme(option, ecModel);
  20922. prepareSource(this);
  20923. var data = this.getInitialData(option, ecModel);
  20924. wrapData(data, this);
  20925. this.dataTask.context.data = data;
  20926. if (__DEV__) {
  20927. assert$1(data, 'getInitialData returned invalid data.');
  20928. }
  20929. /**
  20930. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  20931. * @private
  20932. */
  20933. inner$4(this).dataBeforeProcessed = data;
  20934. // If we reverse the order (make data firstly, and then make
  20935. // dataBeforeProcessed by cloneShallow), cloneShallow will
  20936. // cause data.graph.data !== data when using
  20937. // module:echarts/data/Graph or module:echarts/data/Tree.
  20938. // See module:echarts/data/helper/linkList
  20939. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  20940. // init or merge stage, because the data can be restored. So we do not `restoreData`
  20941. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  20942. // Call `seriesModel.getRawData()` instead.
  20943. // this.restoreData();
  20944. autoSeriesName(this);
  20945. },
  20946. /**
  20947. * Util for merge default and theme to option
  20948. * @param {Object} option
  20949. * @param {module:echarts/model/Global} ecModel
  20950. */
  20951. mergeDefaultAndTheme: function (option, ecModel) {
  20952. var layoutMode = this.layoutMode;
  20953. var inputPositionParams = layoutMode
  20954. ? getLayoutParams(option) : {};
  20955. // Backward compat: using subType on theme.
  20956. // But if name duplicate between series subType
  20957. // (for example: parallel) add component mainType,
  20958. // add suffix 'Series'.
  20959. var themeSubType = this.subType;
  20960. if (ComponentModel.hasClass(themeSubType)) {
  20961. themeSubType += 'Series';
  20962. }
  20963. merge(
  20964. option,
  20965. ecModel.getTheme().get(this.subType)
  20966. );
  20967. merge(option, this.getDefaultOption());
  20968. // Default label emphasis `show`
  20969. defaultEmphasis(option, 'label', ['show']);
  20970. this.fillDataTextStyle(option.data);
  20971. if (layoutMode) {
  20972. mergeLayoutParam(option, inputPositionParams, layoutMode);
  20973. }
  20974. },
  20975. mergeOption: function (newSeriesOption, ecModel) {
  20976. // this.settingTask.dirty();
  20977. newSeriesOption = merge(this.option, newSeriesOption, true);
  20978. this.fillDataTextStyle(newSeriesOption.data);
  20979. var layoutMode = this.layoutMode;
  20980. if (layoutMode) {
  20981. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  20982. }
  20983. prepareSource(this);
  20984. var data = this.getInitialData(newSeriesOption, ecModel);
  20985. wrapData(data, this);
  20986. this.dataTask.dirty();
  20987. this.dataTask.context.data = data;
  20988. inner$4(this).dataBeforeProcessed = data;
  20989. autoSeriesName(this);
  20990. },
  20991. fillDataTextStyle: function (data) {
  20992. // Default data label emphasis `show`
  20993. // FIXME Tree structure data ?
  20994. // FIXME Performance ?
  20995. if (data && !isTypedArray(data)) {
  20996. var props = ['show'];
  20997. for (var i = 0; i < data.length; i++) {
  20998. if (data[i] && data[i].label) {
  20999. defaultEmphasis(data[i], 'label', props);
  21000. }
  21001. }
  21002. }
  21003. },
  21004. /**
  21005. * Init a data structure from data related option in series
  21006. * Must be overwritten
  21007. */
  21008. getInitialData: function () {},
  21009. /**
  21010. * Append data to list
  21011. * @param {Object} params
  21012. * @param {Array|TypedArray} params.data
  21013. */
  21014. appendData: function (params) {
  21015. // FIXME ???
  21016. // (1) If data from dataset, forbidden append.
  21017. // (2) support append data of dataset.
  21018. var data = this.getRawData();
  21019. data.appendData(params.data);
  21020. },
  21021. /**
  21022. * Consider some method like `filter`, `map` need make new data,
  21023. * We should make sure that `seriesModel.getData()` get correct
  21024. * data in the stream procedure. So we fetch data from upstream
  21025. * each time `task.perform` called.
  21026. * @param {string} [dataType]
  21027. * @return {module:echarts/data/List}
  21028. */
  21029. getData: function (dataType) {
  21030. var task = getCurrentTask(this);
  21031. if (task) {
  21032. var data = task.context.data;
  21033. return dataType == null ? data : data.getLinkedData(dataType);
  21034. }
  21035. else {
  21036. // When series is not alive (that may happen when click toolbox
  21037. // restore or setOption with not merge mode), series data may
  21038. // be still need to judge animation or something when graphic
  21039. // elements want to know whether fade out.
  21040. return inner$4(this).data;
  21041. }
  21042. },
  21043. /**
  21044. * @param {module:echarts/data/List} data
  21045. */
  21046. setData: function (data) {
  21047. var task = getCurrentTask(this);
  21048. if (task) {
  21049. var context = task.context;
  21050. // Consider case: filter, data sample.
  21051. if (context.data !== data && task.modifyOutputEnd) {
  21052. task.setOutputEnd(data.count());
  21053. }
  21054. context.outputData = data;
  21055. // Caution: setData should update context.data,
  21056. // Because getData may be called multiply in a
  21057. // single stage and expect to get the data just
  21058. // set. (For example, AxisProxy, x y both call
  21059. // getData and setDate sequentially).
  21060. // So the context.data should be fetched from
  21061. // upstream each time when a stage starts to be
  21062. // performed.
  21063. if (task !== this.dataTask) {
  21064. context.data = data;
  21065. }
  21066. }
  21067. inner$4(this).data = data;
  21068. },
  21069. /**
  21070. * @see {module:echarts/data/helper/sourceHelper#getSource}
  21071. * @return {module:echarts/data/Source} source
  21072. */
  21073. getSource: function () {
  21074. return getSource(this);
  21075. },
  21076. /**
  21077. * Get data before processed
  21078. * @return {module:echarts/data/List}
  21079. */
  21080. getRawData: function () {
  21081. return inner$4(this).dataBeforeProcessed;
  21082. },
  21083. /**
  21084. * Get base axis if has coordinate system and has axis.
  21085. * By default use coordSys.getBaseAxis();
  21086. * Can be overrided for some chart.
  21087. * @return {type} description
  21088. */
  21089. getBaseAxis: function () {
  21090. var coordSys = this.coordinateSystem;
  21091. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  21092. },
  21093. // FIXME
  21094. /**
  21095. * Default tooltip formatter
  21096. *
  21097. * @param {number} dataIndex
  21098. * @param {boolean} [multipleSeries=false]
  21099. * @param {number} [dataType]
  21100. * @param {string} [renderMode='html'] valid values: 'html' and 'richText'.
  21101. * 'html' is used for rendering tooltip in extra DOM form, and the result
  21102. * string is used as DOM HTML content.
  21103. * 'richText' is used for rendering tooltip in rich text form, for those where
  21104. * DOM operation is not supported.
  21105. * @return {Object} formatted tooltip with `html` and `markers`
  21106. */
  21107. formatTooltip: function (dataIndex, multipleSeries, dataType, renderMode) {
  21108. var series = this;
  21109. renderMode = renderMode || 'html';
  21110. var newLine = renderMode === 'html' ? '<br/>' : '\n';
  21111. var isRichText = renderMode === 'richText';
  21112. var markers = {};
  21113. var markerId = 0;
  21114. function formatArrayValue(value) {
  21115. // ??? TODO refactor these logic.
  21116. // check: category-no-encode-has-axis-data in dataset.html
  21117. var vertially = reduce(value, function (vertially, val, idx) {
  21118. var dimItem = data.getDimensionInfo(idx);
  21119. return vertially |= dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  21120. }, 0);
  21121. var result = [];
  21122. tooltipDims.length
  21123. ? each$1(tooltipDims, function (dim) {
  21124. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  21125. })
  21126. // By default, all dims is used on tooltip.
  21127. : each$1(value, setEachItem);
  21128. function setEachItem(val, dim) {
  21129. var dimInfo = data.getDimensionInfo(dim);
  21130. // If `dimInfo.tooltip` is not set, show tooltip.
  21131. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  21132. return;
  21133. }
  21134. var dimType = dimInfo.type;
  21135. var markName = 'sub' + series.seriesIndex + 'at' + markerId;
  21136. var dimHead = getTooltipMarker({
  21137. color: color,
  21138. type: 'subItem',
  21139. renderMode: renderMode,
  21140. markerId: markName
  21141. });
  21142. var dimHeadStr = typeof dimHead === 'string' ? dimHead : dimHead.content;
  21143. var valStr = (vertially
  21144. ? dimHeadStr + encodeHTML(dimInfo.displayName || '-') + ': '
  21145. : ''
  21146. )
  21147. // FIXME should not format time for raw data?
  21148. + encodeHTML(dimType === 'ordinal'
  21149. ? val + ''
  21150. : dimType === 'time'
  21151. ? (multipleSeries ? '' : formatTime('yyyy/MM/dd hh:mm:ss', val))
  21152. : addCommas(val)
  21153. );
  21154. valStr && result.push(valStr);
  21155. if (isRichText) {
  21156. markers[markName] = color;
  21157. ++markerId;
  21158. }
  21159. }
  21160. var newLine = vertially ? (isRichText ? '\n' : '<br/>') : '';
  21161. var content = newLine + result.join(newLine || ', ');
  21162. return {
  21163. renderMode: renderMode,
  21164. content: content,
  21165. style: markers
  21166. };
  21167. }
  21168. function formatSingleValue(val) {
  21169. // return encodeHTML(addCommas(val));
  21170. return {
  21171. renderMode: renderMode,
  21172. content: encodeHTML(addCommas(val)),
  21173. style: markers
  21174. };
  21175. }
  21176. var data = this.getData();
  21177. var tooltipDims = data.mapDimension('defaultedTooltip', true);
  21178. var tooltipDimLen = tooltipDims.length;
  21179. var value = this.getRawValue(dataIndex);
  21180. var isValueArr = isArray(value);
  21181. var color = data.getItemVisual(dataIndex, 'color');
  21182. if (isObject$1(color) && color.colorStops) {
  21183. color = (color.colorStops[0] || {}).color;
  21184. }
  21185. color = color || 'transparent';
  21186. // Complicated rule for pretty tooltip.
  21187. var formattedValue = (tooltipDimLen > 1 || (isValueArr && !tooltipDimLen))
  21188. ? formatArrayValue(value)
  21189. : tooltipDimLen
  21190. ? formatSingleValue(retrieveRawValue(data, dataIndex, tooltipDims[0]))
  21191. : formatSingleValue(isValueArr ? value[0] : value);
  21192. var content = formattedValue.content;
  21193. var markName = series.seriesIndex + 'at' + markerId;
  21194. var colorEl = getTooltipMarker({
  21195. color: color,
  21196. type: 'item',
  21197. renderMode: renderMode,
  21198. markerId: markName
  21199. });
  21200. markers[markName] = color;
  21201. ++markerId;
  21202. var name = data.getName(dataIndex);
  21203. var seriesName = this.name;
  21204. if (!isNameSpecified(this)) {
  21205. seriesName = '';
  21206. }
  21207. seriesName = seriesName
  21208. ? encodeHTML(seriesName) + (!multipleSeries ? newLine : ': ')
  21209. : '';
  21210. var colorStr = typeof colorEl === 'string' ? colorEl : colorEl.content;
  21211. var html = !multipleSeries
  21212. ? seriesName + colorStr
  21213. + (name
  21214. ? encodeHTML(name) + ': ' + content
  21215. : content
  21216. )
  21217. : colorStr + seriesName + content;
  21218. return {
  21219. html: html,
  21220. markers: markers
  21221. };
  21222. },
  21223. /**
  21224. * @return {boolean}
  21225. */
  21226. isAnimationEnabled: function () {
  21227. if (env$1.node) {
  21228. return false;
  21229. }
  21230. var animationEnabled = this.getShallow('animation');
  21231. if (animationEnabled) {
  21232. if (this.getData().count() > this.getShallow('animationThreshold')) {
  21233. animationEnabled = false;
  21234. }
  21235. }
  21236. return animationEnabled;
  21237. },
  21238. restoreData: function () {
  21239. this.dataTask.dirty();
  21240. },
  21241. getColorFromPalette: function (name, scope, requestColorNum) {
  21242. var ecModel = this.ecModel;
  21243. // PENDING
  21244. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope, requestColorNum);
  21245. if (!color) {
  21246. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  21247. }
  21248. return color;
  21249. },
  21250. /**
  21251. * Use `data.mapDimension(coordDim, true)` instead.
  21252. * @deprecated
  21253. */
  21254. coordDimToDataDim: function (coordDim) {
  21255. return this.getRawData().mapDimension(coordDim, true);
  21256. },
  21257. /**
  21258. * Get progressive rendering count each step
  21259. * @return {number}
  21260. */
  21261. getProgressive: function () {
  21262. return this.get('progressive');
  21263. },
  21264. /**
  21265. * Get progressive rendering count each step
  21266. * @return {number}
  21267. */
  21268. getProgressiveThreshold: function () {
  21269. return this.get('progressiveThreshold');
  21270. },
  21271. /**
  21272. * Get data indices for show tooltip content. See tooltip.
  21273. * @abstract
  21274. * @param {Array.<string>|string} dim
  21275. * @param {Array.<number>} value
  21276. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  21277. * @return {Object} {dataIndices, nestestValue}.
  21278. */
  21279. getAxisTooltipData: null,
  21280. /**
  21281. * See tooltip.
  21282. * @abstract
  21283. * @param {number} dataIndex
  21284. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  21285. */
  21286. getTooltipPosition: null,
  21287. /**
  21288. * @see {module:echarts/stream/Scheduler}
  21289. */
  21290. pipeTask: null,
  21291. /**
  21292. * Convinient for override in extended class.
  21293. * @protected
  21294. * @type {Function}
  21295. */
  21296. preventIncremental: null,
  21297. /**
  21298. * @public
  21299. * @readOnly
  21300. * @type {Object}
  21301. */
  21302. pipelineContext: null
  21303. });
  21304. mixin(SeriesModel, dataFormatMixin);
  21305. mixin(SeriesModel, colorPaletteMixin);
  21306. /**
  21307. * MUST be called after `prepareSource` called
  21308. * Here we need to make auto series, especially for auto legend. But we
  21309. * do not modify series.name in option to avoid side effects.
  21310. */
  21311. function autoSeriesName(seriesModel) {
  21312. // User specified name has higher priority, otherwise it may cause
  21313. // series can not be queried unexpectedly.
  21314. var name = seriesModel.name;
  21315. if (!isNameSpecified(seriesModel)) {
  21316. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  21317. }
  21318. }
  21319. function getSeriesAutoName(seriesModel) {
  21320. var data = seriesModel.getRawData();
  21321. var dataDims = data.mapDimension('seriesName', true);
  21322. var nameArr = [];
  21323. each$1(dataDims, function (dataDim) {
  21324. var dimInfo = data.getDimensionInfo(dataDim);
  21325. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  21326. });
  21327. return nameArr.join(' ');
  21328. }
  21329. function dataTaskCount(context) {
  21330. return context.model.getRawData().count();
  21331. }
  21332. function dataTaskReset(context) {
  21333. var seriesModel = context.model;
  21334. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  21335. return dataTaskProgress;
  21336. }
  21337. function dataTaskProgress(param, context) {
  21338. // Avoid repead cloneShallow when data just created in reset.
  21339. if (context.outputData && param.end > context.outputData.count()) {
  21340. context.model.getRawData().cloneShallow(context.outputData);
  21341. }
  21342. }
  21343. // TODO refactor
  21344. function wrapData(data, seriesModel) {
  21345. each$1(data.CHANGABLE_METHODS, function (methodName) {
  21346. data.wrapMethod(methodName, curry(onDataSelfChange, seriesModel));
  21347. });
  21348. }
  21349. function onDataSelfChange(seriesModel) {
  21350. var task = getCurrentTask(seriesModel);
  21351. if (task) {
  21352. // Consider case: filter, selectRange
  21353. task.setOutputEnd(this.count());
  21354. }
  21355. }
  21356. function getCurrentTask(seriesModel) {
  21357. var scheduler = (seriesModel.ecModel || {}).scheduler;
  21358. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  21359. if (pipeline) {
  21360. // When pipline finished, the currrentTask keep the last
  21361. // task (renderTask).
  21362. var task = pipeline.currentTask;
  21363. if (task) {
  21364. var agentStubMap = task.agentStubMap;
  21365. if (agentStubMap) {
  21366. task = agentStubMap.get(seriesModel.uid);
  21367. }
  21368. }
  21369. return task;
  21370. }
  21371. }
  21372. /*
  21373. * Licensed to the Apache Software Foundation (ASF) under one
  21374. * or more contributor license agreements. See the NOTICE file
  21375. * distributed with this work for additional information
  21376. * regarding copyright ownership. The ASF licenses this file
  21377. * to you under the Apache License, Version 2.0 (the
  21378. * "License"); you may not use this file except in compliance
  21379. * with the License. You may obtain a copy of the License at
  21380. *
  21381. * http://www.apache.org/licenses/LICENSE-2.0
  21382. *
  21383. * Unless required by applicable law or agreed to in writing,
  21384. * software distributed under the License is distributed on an
  21385. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21386. * KIND, either express or implied. See the License for the
  21387. * specific language governing permissions and limitations
  21388. * under the License.
  21389. */
  21390. var Component = function () {
  21391. /**
  21392. * @type {module:zrender/container/Group}
  21393. * @readOnly
  21394. */
  21395. this.group = new Group();
  21396. /**
  21397. * @type {string}
  21398. * @readOnly
  21399. */
  21400. this.uid = getUID('viewComponent');
  21401. };
  21402. Component.prototype = {
  21403. constructor: Component,
  21404. init: function (ecModel, api) {},
  21405. render: function (componentModel, ecModel, api, payload) {},
  21406. dispose: function () {},
  21407. /**
  21408. * @param {string} eventType
  21409. * @param {Object} query
  21410. * @param {module:zrender/Element} targetEl
  21411. * @param {Object} packedEvent
  21412. * @return {boolen} Pass only when return `true`.
  21413. */
  21414. filterForExposedEvent: null
  21415. };
  21416. var componentProto = Component.prototype;
  21417. componentProto.updateView =
  21418. componentProto.updateLayout =
  21419. componentProto.updateVisual =
  21420. function (seriesModel, ecModel, api, payload) {
  21421. // Do nothing;
  21422. };
  21423. // Enable Component.extend.
  21424. enableClassExtend(Component);
  21425. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  21426. enableClassManagement(Component, {registerWhenExtend: true});
  21427. /*
  21428. * Licensed to the Apache Software Foundation (ASF) under one
  21429. * or more contributor license agreements. See the NOTICE file
  21430. * distributed with this work for additional information
  21431. * regarding copyright ownership. The ASF licenses this file
  21432. * to you under the Apache License, Version 2.0 (the
  21433. * "License"); you may not use this file except in compliance
  21434. * with the License. You may obtain a copy of the License at
  21435. *
  21436. * http://www.apache.org/licenses/LICENSE-2.0
  21437. *
  21438. * Unless required by applicable law or agreed to in writing,
  21439. * software distributed under the License is distributed on an
  21440. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21441. * KIND, either express or implied. See the License for the
  21442. * specific language governing permissions and limitations
  21443. * under the License.
  21444. */
  21445. /**
  21446. * @return {string} If large mode changed, return string 'reset';
  21447. */
  21448. var createRenderPlanner = function () {
  21449. var inner = makeInner();
  21450. return function (seriesModel) {
  21451. var fields = inner(seriesModel);
  21452. var pipelineContext = seriesModel.pipelineContext;
  21453. var originalLarge = fields.large;
  21454. var originalProgressive = fields.progressiveRender;
  21455. // FIXME: if the planner works on a filtered series, `pipelineContext` does not
  21456. // exists. See #11611 . Probably we need to modify this structure, see the comment
  21457. // on `performRawSeries` in `Schedular.js`.
  21458. var large = fields.large = pipelineContext && pipelineContext.large;
  21459. var progressive = fields.progressiveRender = pipelineContext && pipelineContext.progressiveRender;
  21460. return !!((originalLarge ^ large) || (originalProgressive ^ progressive)) && 'reset';
  21461. };
  21462. };
  21463. /*
  21464. * Licensed to the Apache Software Foundation (ASF) under one
  21465. * or more contributor license agreements. See the NOTICE file
  21466. * distributed with this work for additional information
  21467. * regarding copyright ownership. The ASF licenses this file
  21468. * to you under the Apache License, Version 2.0 (the
  21469. * "License"); you may not use this file except in compliance
  21470. * with the License. You may obtain a copy of the License at
  21471. *
  21472. * http://www.apache.org/licenses/LICENSE-2.0
  21473. *
  21474. * Unless required by applicable law or agreed to in writing,
  21475. * software distributed under the License is distributed on an
  21476. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21477. * KIND, either express or implied. See the License for the
  21478. * specific language governing permissions and limitations
  21479. * under the License.
  21480. */
  21481. var inner$5 = makeInner();
  21482. var renderPlanner = createRenderPlanner();
  21483. function Chart() {
  21484. /**
  21485. * @type {module:zrender/container/Group}
  21486. * @readOnly
  21487. */
  21488. this.group = new Group();
  21489. /**
  21490. * @type {string}
  21491. * @readOnly
  21492. */
  21493. this.uid = getUID('viewChart');
  21494. this.renderTask = createTask({
  21495. plan: renderTaskPlan,
  21496. reset: renderTaskReset
  21497. });
  21498. this.renderTask.context = {view: this};
  21499. }
  21500. Chart.prototype = {
  21501. type: 'chart',
  21502. /**
  21503. * Init the chart.
  21504. * @param {module:echarts/model/Global} ecModel
  21505. * @param {module:echarts/ExtensionAPI} api
  21506. */
  21507. init: function (ecModel, api) {},
  21508. /**
  21509. * Render the chart.
  21510. * @param {module:echarts/model/Series} seriesModel
  21511. * @param {module:echarts/model/Global} ecModel
  21512. * @param {module:echarts/ExtensionAPI} api
  21513. * @param {Object} payload
  21514. */
  21515. render: function (seriesModel, ecModel, api, payload) {},
  21516. /**
  21517. * Highlight series or specified data item.
  21518. * @param {module:echarts/model/Series} seriesModel
  21519. * @param {module:echarts/model/Global} ecModel
  21520. * @param {module:echarts/ExtensionAPI} api
  21521. * @param {Object} payload
  21522. */
  21523. highlight: function (seriesModel, ecModel, api, payload) {
  21524. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  21525. },
  21526. /**
  21527. * Downplay series or specified data item.
  21528. * @param {module:echarts/model/Series} seriesModel
  21529. * @param {module:echarts/model/Global} ecModel
  21530. * @param {module:echarts/ExtensionAPI} api
  21531. * @param {Object} payload
  21532. */
  21533. downplay: function (seriesModel, ecModel, api, payload) {
  21534. toggleHighlight(seriesModel.getData(), payload, 'normal');
  21535. },
  21536. /**
  21537. * Remove self.
  21538. * @param {module:echarts/model/Global} ecModel
  21539. * @param {module:echarts/ExtensionAPI} api
  21540. */
  21541. remove: function (ecModel, api) {
  21542. this.group.removeAll();
  21543. },
  21544. /**
  21545. * Dispose self.
  21546. * @param {module:echarts/model/Global} ecModel
  21547. * @param {module:echarts/ExtensionAPI} api
  21548. */
  21549. dispose: function () {},
  21550. /**
  21551. * Rendering preparation in progressive mode.
  21552. * @param {module:echarts/model/Series} seriesModel
  21553. * @param {module:echarts/model/Global} ecModel
  21554. * @param {module:echarts/ExtensionAPI} api
  21555. * @param {Object} payload
  21556. */
  21557. incrementalPrepareRender: null,
  21558. /**
  21559. * Render in progressive mode.
  21560. * @param {Object} params See taskParams in `stream/task.js`
  21561. * @param {module:echarts/model/Series} seriesModel
  21562. * @param {module:echarts/model/Global} ecModel
  21563. * @param {module:echarts/ExtensionAPI} api
  21564. * @param {Object} payload
  21565. */
  21566. incrementalRender: null,
  21567. /**
  21568. * Update transform directly.
  21569. * @param {module:echarts/model/Series} seriesModel
  21570. * @param {module:echarts/model/Global} ecModel
  21571. * @param {module:echarts/ExtensionAPI} api
  21572. * @param {Object} payload
  21573. * @return {Object} {update: true}
  21574. */
  21575. updateTransform: null,
  21576. /**
  21577. * The view contains the given point.
  21578. * @interface
  21579. * @param {Array.<number>} point
  21580. * @return {boolean}
  21581. */
  21582. // containPoint: function () {}
  21583. /**
  21584. * @param {string} eventType
  21585. * @param {Object} query
  21586. * @param {module:zrender/Element} targetEl
  21587. * @param {Object} packedEvent
  21588. * @return {boolen} Pass only when return `true`.
  21589. */
  21590. filterForExposedEvent: null
  21591. };
  21592. var chartProto = Chart.prototype;
  21593. chartProto.updateView =
  21594. chartProto.updateLayout =
  21595. chartProto.updateVisual =
  21596. function (seriesModel, ecModel, api, payload) {
  21597. this.render(seriesModel, ecModel, api, payload);
  21598. };
  21599. /**
  21600. * Set state of single element
  21601. * @param {module:zrender/Element} el
  21602. * @param {string} state 'normal'|'emphasis'
  21603. * @param {number} highlightDigit
  21604. */
  21605. function elSetState(el, state, highlightDigit) {
  21606. if (el) {
  21607. el.trigger(state, highlightDigit);
  21608. if (el.isGroup
  21609. // Simple optimize.
  21610. && !isHighDownDispatcher(el)
  21611. ) {
  21612. for (var i = 0, len = el.childCount(); i < len; i++) {
  21613. elSetState(el.childAt(i), state, highlightDigit);
  21614. }
  21615. }
  21616. }
  21617. }
  21618. /**
  21619. * @param {module:echarts/data/List} data
  21620. * @param {Object} payload
  21621. * @param {string} state 'normal'|'emphasis'
  21622. */
  21623. function toggleHighlight(data, payload, state) {
  21624. var dataIndex = queryDataIndex(data, payload);
  21625. var highlightDigit = (payload && payload.highlightKey != null)
  21626. ? getHighlightDigit(payload.highlightKey)
  21627. : null;
  21628. if (dataIndex != null) {
  21629. each$1(normalizeToArray(dataIndex), function (dataIdx) {
  21630. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  21631. });
  21632. }
  21633. else {
  21634. data.eachItemGraphicEl(function (el) {
  21635. elSetState(el, state, highlightDigit);
  21636. });
  21637. }
  21638. }
  21639. // Enable Chart.extend.
  21640. enableClassExtend(Chart, ['dispose']);
  21641. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  21642. enableClassManagement(Chart, {registerWhenExtend: true});
  21643. Chart.markUpdateMethod = function (payload, methodName) {
  21644. inner$5(payload).updateMethod = methodName;
  21645. };
  21646. function renderTaskPlan(context) {
  21647. return renderPlanner(context.model);
  21648. }
  21649. function renderTaskReset(context) {
  21650. var seriesModel = context.model;
  21651. var ecModel = context.ecModel;
  21652. var api = context.api;
  21653. var payload = context.payload;
  21654. // ???! remove updateView updateVisual
  21655. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  21656. var view = context.view;
  21657. var updateMethod = payload && inner$5(payload).updateMethod;
  21658. var methodName = progressiveRender
  21659. ? 'incrementalPrepareRender'
  21660. : (updateMethod && view[updateMethod])
  21661. ? updateMethod
  21662. // `appendData` is also supported when data amount
  21663. // is less than progressive threshold.
  21664. : 'render';
  21665. if (methodName !== 'render') {
  21666. view[methodName](seriesModel, ecModel, api, payload);
  21667. }
  21668. return progressMethodMap[methodName];
  21669. }
  21670. var progressMethodMap = {
  21671. incrementalPrepareRender: {
  21672. progress: function (params, context) {
  21673. context.view.incrementalRender(
  21674. params, context.model, context.ecModel, context.api, context.payload
  21675. );
  21676. }
  21677. },
  21678. render: {
  21679. // Put view.render in `progress` to support appendData. But in this case
  21680. // view.render should not be called in reset, otherwise it will be called
  21681. // twise. Use `forceFirstProgress` to make sure that view.render is called
  21682. // in any cases.
  21683. forceFirstProgress: true,
  21684. progress: function (params, context) {
  21685. context.view.render(
  21686. context.model, context.ecModel, context.api, context.payload
  21687. );
  21688. }
  21689. }
  21690. };
  21691. /*
  21692. * Licensed to the Apache Software Foundation (ASF) under one
  21693. * or more contributor license agreements. See the NOTICE file
  21694. * distributed with this work for additional information
  21695. * regarding copyright ownership. The ASF licenses this file
  21696. * to you under the Apache License, Version 2.0 (the
  21697. * "License"); you may not use this file except in compliance
  21698. * with the License. You may obtain a copy of the License at
  21699. *
  21700. * http://www.apache.org/licenses/LICENSE-2.0
  21701. *
  21702. * Unless required by applicable law or agreed to in writing,
  21703. * software distributed under the License is distributed on an
  21704. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21705. * KIND, either express or implied. See the License for the
  21706. * specific language governing permissions and limitations
  21707. * under the License.
  21708. */
  21709. /**
  21710. * @public
  21711. * @param {(Function)} fn
  21712. * @param {number} [delay=0] Unit: ms.
  21713. * @param {boolean} [debounce=false]
  21714. * true: If call interval less than `delay`, only the last call works.
  21715. * false: If call interval less than `delay, call works on fixed rate.
  21716. * @return {(Function)} throttled fn.
  21717. */
  21718. function throttle(fn, delay, debounce) {
  21719. var currCall;
  21720. var lastCall = 0;
  21721. var lastExec = 0;
  21722. var timer = null;
  21723. var diff;
  21724. var scope;
  21725. var args;
  21726. var debounceNextCall;
  21727. delay = delay || 0;
  21728. function exec() {
  21729. lastExec = (new Date()).getTime();
  21730. timer = null;
  21731. fn.apply(scope, args || []);
  21732. }
  21733. var cb = function () {
  21734. currCall = (new Date()).getTime();
  21735. scope = this;
  21736. args = arguments;
  21737. var thisDelay = debounceNextCall || delay;
  21738. var thisDebounce = debounceNextCall || debounce;
  21739. debounceNextCall = null;
  21740. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  21741. clearTimeout(timer);
  21742. // Here we should make sure that: the `exec` SHOULD NOT be called later
  21743. // than a new call of `cb`, that is, preserving the command order. Consider
  21744. // calculating "scale rate" when roaming as an example. When a call of `cb`
  21745. // happens, either the `exec` is called dierectly, or the call is delayed.
  21746. // But the delayed call should never be later than next call of `cb`. Under
  21747. // this assurance, we can simply update view state each time `dispatchAction`
  21748. // triggered by user roaming, but not need to add extra code to avoid the
  21749. // state being "rolled-back".
  21750. if (thisDebounce) {
  21751. timer = setTimeout(exec, thisDelay);
  21752. }
  21753. else {
  21754. if (diff >= 0) {
  21755. exec();
  21756. }
  21757. else {
  21758. timer = setTimeout(exec, -diff);
  21759. }
  21760. }
  21761. lastCall = currCall;
  21762. };
  21763. /**
  21764. * Clear throttle.
  21765. * @public
  21766. */
  21767. cb.clear = function () {
  21768. if (timer) {
  21769. clearTimeout(timer);
  21770. timer = null;
  21771. }
  21772. };
  21773. /**
  21774. * Enable debounce once.
  21775. */
  21776. cb.debounceNextCall = function (debounceDelay) {
  21777. debounceNextCall = debounceDelay;
  21778. };
  21779. return cb;
  21780. }
  21781. /**
  21782. * Create throttle method or update throttle rate.
  21783. *
  21784. * @example
  21785. * ComponentView.prototype.render = function () {
  21786. * ...
  21787. * throttle.createOrUpdate(
  21788. * this,
  21789. * '_dispatchAction',
  21790. * this.model.get('throttle'),
  21791. * 'fixRate'
  21792. * );
  21793. * };
  21794. * ComponentView.prototype.remove = function () {
  21795. * throttle.clear(this, '_dispatchAction');
  21796. * };
  21797. * ComponentView.prototype.dispose = function () {
  21798. * throttle.clear(this, '_dispatchAction');
  21799. * };
  21800. *
  21801. * @public
  21802. * @param {Object} obj
  21803. * @param {string} fnAttr
  21804. * @param {number} [rate]
  21805. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  21806. * @return {Function} throttled function.
  21807. */
  21808. /**
  21809. * Clear throttle. Example see throttle.createOrUpdate.
  21810. *
  21811. * @public
  21812. * @param {Object} obj
  21813. * @param {string} fnAttr
  21814. */
  21815. /*
  21816. * Licensed to the Apache Software Foundation (ASF) under one
  21817. * or more contributor license agreements. See the NOTICE file
  21818. * distributed with this work for additional information
  21819. * regarding copyright ownership. The ASF licenses this file
  21820. * to you under the Apache License, Version 2.0 (the
  21821. * "License"); you may not use this file except in compliance
  21822. * with the License. You may obtain a copy of the License at
  21823. *
  21824. * http://www.apache.org/licenses/LICENSE-2.0
  21825. *
  21826. * Unless required by applicable law or agreed to in writing,
  21827. * software distributed under the License is distributed on an
  21828. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21829. * KIND, either express or implied. See the License for the
  21830. * specific language governing permissions and limitations
  21831. * under the License.
  21832. */
  21833. var seriesColor = {
  21834. createOnAllSeries: true,
  21835. performRawSeries: true,
  21836. reset: function (seriesModel, ecModel) {
  21837. var data = seriesModel.getData();
  21838. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.color').split('.');
  21839. // Set in itemStyle
  21840. var color = seriesModel.get(colorAccessPath);
  21841. var colorCallback = (isFunction$1(color) && !(color instanceof Gradient))
  21842. ? color : null;
  21843. // Default color
  21844. if (!color || colorCallback) {
  21845. color = seriesModel.getColorFromPalette(
  21846. // TODO series count changed.
  21847. seriesModel.name, null, ecModel.getSeriesCount()
  21848. );
  21849. }
  21850. data.setVisual('color', color);
  21851. var borderColorAccessPath = (seriesModel.visualBorderColorAccessPath || 'itemStyle.borderColor').split('.');
  21852. var borderColor = seriesModel.get(borderColorAccessPath);
  21853. data.setVisual('borderColor', borderColor);
  21854. // Only visible series has each data be visual encoded
  21855. if (!ecModel.isSeriesFiltered(seriesModel)) {
  21856. if (colorCallback) {
  21857. data.each(function (idx) {
  21858. data.setItemVisual(
  21859. idx, 'color', colorCallback(seriesModel.getDataParams(idx))
  21860. );
  21861. });
  21862. }
  21863. // itemStyle in each data item
  21864. var dataEach = function (data, idx) {
  21865. var itemModel = data.getItemModel(idx);
  21866. var color = itemModel.get(colorAccessPath, true);
  21867. var borderColor = itemModel.get(borderColorAccessPath, true);
  21868. if (color != null) {
  21869. data.setItemVisual(idx, 'color', color);
  21870. }
  21871. if (borderColor != null) {
  21872. data.setItemVisual(idx, 'borderColor', borderColor);
  21873. }
  21874. };
  21875. return { dataEach: data.hasItemOption ? dataEach : null };
  21876. }
  21877. }
  21878. };
  21879. /*
  21880. * Licensed to the Apache Software Foundation (ASF) under one
  21881. * or more contributor license agreements. See the NOTICE file
  21882. * distributed with this work for additional information
  21883. * regarding copyright ownership. The ASF licenses this file
  21884. * to you under the Apache License, Version 2.0 (the
  21885. * "License"); you may not use this file except in compliance
  21886. * with the License. You may obtain a copy of the License at
  21887. *
  21888. * http://www.apache.org/licenses/LICENSE-2.0
  21889. *
  21890. * Unless required by applicable law or agreed to in writing,
  21891. * software distributed under the License is distributed on an
  21892. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21893. * KIND, either express or implied. See the License for the
  21894. * specific language governing permissions and limitations
  21895. * under the License.
  21896. */
  21897. /**
  21898. * Language: (Simplified) Chinese.
  21899. */
  21900. var lang = {
  21901. legend: {
  21902. selector: {
  21903. all: '全选',
  21904. inverse: '反选'
  21905. }
  21906. },
  21907. toolbox: {
  21908. brush: {
  21909. title: {
  21910. rect: '矩形选择',
  21911. polygon: '圈选',
  21912. lineX: '横向选择',
  21913. lineY: '纵向选择',
  21914. keep: '保持选择',
  21915. clear: '清除选择'
  21916. }
  21917. },
  21918. dataView: {
  21919. title: '数据视图',
  21920. lang: ['数据视图', '关闭', '刷新']
  21921. },
  21922. dataZoom: {
  21923. title: {
  21924. zoom: '区域缩放',
  21925. back: '区域缩放还原'
  21926. }
  21927. },
  21928. magicType: {
  21929. title: {
  21930. line: '切换为折线图',
  21931. bar: '切换为柱状图',
  21932. stack: '切换为堆叠',
  21933. tiled: '切换为平铺'
  21934. }
  21935. },
  21936. restore: {
  21937. title: '还原'
  21938. },
  21939. saveAsImage: {
  21940. title: '保存为图片',
  21941. lang: ['右键另存为图片']
  21942. }
  21943. },
  21944. series: {
  21945. typeNames: {
  21946. pie: '饼图',
  21947. bar: '柱状图',
  21948. line: '折线图',
  21949. scatter: '散点图',
  21950. effectScatter: '涟漪散点图',
  21951. radar: '雷达图',
  21952. tree: '树图',
  21953. treemap: '矩形树图',
  21954. boxplot: '箱型图',
  21955. candlestick: 'K线图',
  21956. k: 'K线图',
  21957. heatmap: '热力图',
  21958. map: '地图',
  21959. parallel: '平行坐标图',
  21960. lines: '线图',
  21961. graph: '关系图',
  21962. sankey: '桑基图',
  21963. funnel: '漏斗图',
  21964. gauge: '仪表盘图',
  21965. pictorialBar: '象形柱图',
  21966. themeRiver: '主题河流图',
  21967. sunburst: '旭日图'
  21968. }
  21969. },
  21970. aria: {
  21971. general: {
  21972. withTitle: '这是一个关于“{title}”的图表。',
  21973. withoutTitle: '这是一个图表,'
  21974. },
  21975. series: {
  21976. single: {
  21977. prefix: '',
  21978. withName: '图表类型是{seriesType},表示{seriesName}。',
  21979. withoutName: '图表类型是{seriesType}。'
  21980. },
  21981. multiple: {
  21982. prefix: '它由{seriesCount}个图表系列组成。',
  21983. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  21984. withoutName: '第{seriesId}个系列是一个{seriesType},',
  21985. separator: {
  21986. middle: ';',
  21987. end: '。'
  21988. }
  21989. }
  21990. },
  21991. data: {
  21992. allData: '其数据是——',
  21993. partialData: '其中,前{displayCnt}项是——',
  21994. withName: '{name}的数据是{value}',
  21995. withoutName: '{value}',
  21996. separator: {
  21997. middle: ',',
  21998. end: ''
  21999. }
  22000. }
  22001. }
  22002. };
  22003. /*
  22004. * Licensed to the Apache Software Foundation (ASF) under one
  22005. * or more contributor license agreements. See the NOTICE file
  22006. * distributed with this work for additional information
  22007. * regarding copyright ownership. The ASF licenses this file
  22008. * to you under the Apache License, Version 2.0 (the
  22009. * "License"); you may not use this file except in compliance
  22010. * with the License. You may obtain a copy of the License at
  22011. *
  22012. * http://www.apache.org/licenses/LICENSE-2.0
  22013. *
  22014. * Unless required by applicable law or agreed to in writing,
  22015. * software distributed under the License is distributed on an
  22016. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22017. * KIND, either express or implied. See the License for the
  22018. * specific language governing permissions and limitations
  22019. * under the License.
  22020. */
  22021. var aria = function (dom, ecModel) {
  22022. var ariaModel = ecModel.getModel('aria');
  22023. if (!ariaModel.get('show')) {
  22024. return;
  22025. }
  22026. else if (ariaModel.get('description')) {
  22027. dom.setAttribute('aria-label', ariaModel.get('description'));
  22028. return;
  22029. }
  22030. var seriesCnt = 0;
  22031. ecModel.eachSeries(function (seriesModel, idx) {
  22032. ++seriesCnt;
  22033. }, this);
  22034. var maxDataCnt = ariaModel.get('data.maxCount') || 10;
  22035. var maxSeriesCnt = ariaModel.get('series.maxCount') || 10;
  22036. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  22037. var ariaLabel;
  22038. if (seriesCnt < 1) {
  22039. // No series, no aria label
  22040. return;
  22041. }
  22042. else {
  22043. var title = getTitle();
  22044. if (title) {
  22045. ariaLabel = replace(getConfig('general.withTitle'), {
  22046. title: title
  22047. });
  22048. }
  22049. else {
  22050. ariaLabel = getConfig('general.withoutTitle');
  22051. }
  22052. var seriesLabels = [];
  22053. var prefix = seriesCnt > 1
  22054. ? 'series.multiple.prefix'
  22055. : 'series.single.prefix';
  22056. ariaLabel += replace(getConfig(prefix), { seriesCount: seriesCnt });
  22057. ecModel.eachSeries(function (seriesModel, idx) {
  22058. if (idx < displaySeriesCnt) {
  22059. var seriesLabel;
  22060. var seriesName = seriesModel.get('name');
  22061. var seriesTpl = 'series.'
  22062. + (seriesCnt > 1 ? 'multiple' : 'single') + '.';
  22063. seriesLabel = getConfig(seriesName
  22064. ? seriesTpl + 'withName'
  22065. : seriesTpl + 'withoutName');
  22066. seriesLabel = replace(seriesLabel, {
  22067. seriesId: seriesModel.seriesIndex,
  22068. seriesName: seriesModel.get('name'),
  22069. seriesType: getSeriesTypeName(seriesModel.subType)
  22070. });
  22071. var data = seriesModel.getData();
  22072. window.data = data;
  22073. if (data.count() > maxDataCnt) {
  22074. // Show part of data
  22075. seriesLabel += replace(getConfig('data.partialData'), {
  22076. displayCnt: maxDataCnt
  22077. });
  22078. }
  22079. else {
  22080. seriesLabel += getConfig('data.allData');
  22081. }
  22082. var dataLabels = [];
  22083. for (var i = 0; i < data.count(); i++) {
  22084. if (i < maxDataCnt) {
  22085. var name = data.getName(i);
  22086. var value = retrieveRawValue(data, i);
  22087. dataLabels.push(
  22088. replace(
  22089. name
  22090. ? getConfig('data.withName')
  22091. : getConfig('data.withoutName'),
  22092. {
  22093. name: name,
  22094. value: value
  22095. }
  22096. )
  22097. );
  22098. }
  22099. }
  22100. seriesLabel += dataLabels
  22101. .join(getConfig('data.separator.middle'))
  22102. + getConfig('data.separator.end');
  22103. seriesLabels.push(seriesLabel);
  22104. }
  22105. });
  22106. ariaLabel += seriesLabels
  22107. .join(getConfig('series.multiple.separator.middle'))
  22108. + getConfig('series.multiple.separator.end');
  22109. dom.setAttribute('aria-label', ariaLabel);
  22110. }
  22111. function replace(str, keyValues) {
  22112. if (typeof str !== 'string') {
  22113. return str;
  22114. }
  22115. var result = str;
  22116. each$1(keyValues, function (value, key) {
  22117. result = result.replace(
  22118. new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'),
  22119. value
  22120. );
  22121. });
  22122. return result;
  22123. }
  22124. function getConfig(path) {
  22125. var userConfig = ariaModel.get(path);
  22126. if (userConfig == null) {
  22127. var pathArr = path.split('.');
  22128. var result = lang.aria;
  22129. for (var i = 0; i < pathArr.length; ++i) {
  22130. result = result[pathArr[i]];
  22131. }
  22132. return result;
  22133. }
  22134. else {
  22135. return userConfig;
  22136. }
  22137. }
  22138. function getTitle() {
  22139. var title = ecModel.getModel('title').option;
  22140. if (title && title.length) {
  22141. title = title[0];
  22142. }
  22143. return title && title.text;
  22144. }
  22145. function getSeriesTypeName(type) {
  22146. return lang.series.typeNames[type] || '自定义图';
  22147. }
  22148. };
  22149. /*
  22150. * Licensed to the Apache Software Foundation (ASF) under one
  22151. * or more contributor license agreements. See the NOTICE file
  22152. * distributed with this work for additional information
  22153. * regarding copyright ownership. The ASF licenses this file
  22154. * to you under the Apache License, Version 2.0 (the
  22155. * "License"); you may not use this file except in compliance
  22156. * with the License. You may obtain a copy of the License at
  22157. *
  22158. * http://www.apache.org/licenses/LICENSE-2.0
  22159. *
  22160. * Unless required by applicable law or agreed to in writing,
  22161. * software distributed under the License is distributed on an
  22162. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22163. * KIND, either express or implied. See the License for the
  22164. * specific language governing permissions and limitations
  22165. * under the License.
  22166. */
  22167. var PI$1 = Math.PI;
  22168. /**
  22169. * @param {module:echarts/ExtensionAPI} api
  22170. * @param {Object} [opts]
  22171. * @param {string} [opts.text]
  22172. * @param {string} [opts.color]
  22173. * @param {string} [opts.textColor]
  22174. * @return {module:zrender/Element}
  22175. */
  22176. var loadingDefault = function (api, opts) {
  22177. opts = opts || {};
  22178. defaults(opts, {
  22179. text: 'loading',
  22180. textColor: '#000',
  22181. fontSize: '12px',
  22182. maskColor: 'rgba(255, 255, 255, 0.8)',
  22183. showSpinner: true,
  22184. color: '#c23531',
  22185. spinnerRadius: 10,
  22186. lineWidth: 5,
  22187. zlevel: 0
  22188. });
  22189. var group = new Group();
  22190. var mask = new Rect({
  22191. style: {
  22192. fill: opts.maskColor
  22193. },
  22194. zlevel: opts.zlevel,
  22195. z: 10000
  22196. });
  22197. group.add(mask);
  22198. var font = opts.fontSize + ' sans-serif';
  22199. var labelRect = new Rect({
  22200. style: {
  22201. fill: 'none',
  22202. text: opts.text,
  22203. font: font,
  22204. textPosition: 'right',
  22205. textDistance: 10,
  22206. textFill: opts.textColor
  22207. },
  22208. zlevel: opts.zlevel,
  22209. z: 10001
  22210. });
  22211. group.add(labelRect);
  22212. if (opts.showSpinner) {
  22213. var arc = new Arc({
  22214. shape: {
  22215. startAngle: -PI$1 / 2,
  22216. endAngle: -PI$1 / 2 + 0.1,
  22217. r: opts.spinnerRadius
  22218. },
  22219. style: {
  22220. stroke: opts.color,
  22221. lineCap: 'round',
  22222. lineWidth: opts.lineWidth
  22223. },
  22224. zlevel: opts.zlevel,
  22225. z: 10001
  22226. });
  22227. arc.animateShape(true)
  22228. .when(1000, {
  22229. endAngle: PI$1 * 3 / 2
  22230. })
  22231. .start('circularInOut');
  22232. arc.animateShape(true)
  22233. .when(1000, {
  22234. startAngle: PI$1 * 3 / 2
  22235. })
  22236. .delay(300)
  22237. .start('circularInOut');
  22238. group.add(arc);
  22239. }
  22240. // Inject resize
  22241. group.resize = function () {
  22242. var textWidth = getWidth(opts.text, font);
  22243. var r = opts.showSpinner ? opts.spinnerRadius : 0;
  22244. // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  22245. // textDistance needs to be calculated when both animation and text exist
  22246. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2
  22247. // only show the text
  22248. - (opts.showSpinner ? 0 : textWidth / 2);
  22249. var cy = api.getHeight() / 2;
  22250. opts.showSpinner && arc.setShape({
  22251. cx: cx,
  22252. cy: cy
  22253. });
  22254. labelRect.setShape({
  22255. x: cx - r,
  22256. y: cy - r,
  22257. width: r * 2,
  22258. height: r * 2
  22259. });
  22260. mask.setShape({
  22261. x: 0,
  22262. y: 0,
  22263. width: api.getWidth(),
  22264. height: api.getHeight()
  22265. });
  22266. };
  22267. group.resize();
  22268. return group;
  22269. };
  22270. /*
  22271. * Licensed to the Apache Software Foundation (ASF) under one
  22272. * or more contributor license agreements. See the NOTICE file
  22273. * distributed with this work for additional information
  22274. * regarding copyright ownership. The ASF licenses this file
  22275. * to you under the Apache License, Version 2.0 (the
  22276. * "License"); you may not use this file except in compliance
  22277. * with the License. You may obtain a copy of the License at
  22278. *
  22279. * http://www.apache.org/licenses/LICENSE-2.0
  22280. *
  22281. * Unless required by applicable law or agreed to in writing,
  22282. * software distributed under the License is distributed on an
  22283. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22284. * KIND, either express or implied. See the License for the
  22285. * specific language governing permissions and limitations
  22286. * under the License.
  22287. */
  22288. /**
  22289. * @module echarts/stream/Scheduler
  22290. */
  22291. /**
  22292. * @constructor
  22293. */
  22294. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  22295. this.ecInstance = ecInstance;
  22296. this.api = api;
  22297. this.unfinished;
  22298. // Fix current processors in case that in some rear cases that
  22299. // processors might be registered after echarts instance created.
  22300. // Register processors incrementally for a echarts instance is
  22301. // not supported by this stream architecture.
  22302. var dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  22303. var visualHandlers = this._visualHandlers = visualHandlers.slice();
  22304. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  22305. /**
  22306. * @private
  22307. * @type {
  22308. * [handlerUID: string]: {
  22309. * seriesTaskMap?: {
  22310. * [seriesUID: string]: Task
  22311. * },
  22312. * overallTask?: Task
  22313. * }
  22314. * }
  22315. */
  22316. this._stageTaskMap = createHashMap();
  22317. }
  22318. var proto = Scheduler.prototype;
  22319. /**
  22320. * @param {module:echarts/model/Global} ecModel
  22321. * @param {Object} payload
  22322. */
  22323. proto.restoreData = function (ecModel, payload) {
  22324. // TODO: Only restore needed series and components, but not all components.
  22325. // Currently `restoreData` of all of the series and component will be called.
  22326. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  22327. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  22328. // and some components like coordinate system, axes, dataZoom, visualMap only
  22329. // need their target series refresh.
  22330. // (1) If we are implementing this feature some day, we should consider these cases:
  22331. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  22332. // on the settings of `dataZoom`), it should be re-performed if the component
  22333. // is modified by `setOption`.
  22334. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  22335. // it should be re-performed when the result array of `getTargetSeries` changed.
  22336. // We use `dependencies` to cover these issues.
  22337. // (3) How to update target series when coordinate system related components modified.
  22338. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  22339. // and this case all of the tasks will be set as dirty.
  22340. ecModel.restoreData(payload);
  22341. // Theoretically an overall task not only depends on each of its target series, but also
  22342. // depends on all of the series.
  22343. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  22344. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  22345. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  22346. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  22347. // probably cause state chaos (consider `dataZoomProcessor`).
  22348. this._stageTaskMap.each(function (taskRecord) {
  22349. var overallTask = taskRecord.overallTask;
  22350. overallTask && overallTask.dirty();
  22351. });
  22352. };
  22353. // If seriesModel provided, incremental threshold is check by series data.
  22354. proto.getPerformArgs = function (task, isBlock) {
  22355. // For overall task
  22356. if (!task.__pipeline) {
  22357. return;
  22358. }
  22359. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  22360. var pCtx = pipeline.context;
  22361. var incremental = !isBlock
  22362. && pipeline.progressiveEnabled
  22363. && (!pCtx || pCtx.progressiveRender)
  22364. && task.__idxInPipeline > pipeline.blockIndex;
  22365. var step = incremental ? pipeline.step : null;
  22366. var modDataCount = pCtx && pCtx.modDataCount;
  22367. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  22368. return {step: step, modBy: modBy, modDataCount: modDataCount};
  22369. };
  22370. proto.getPipeline = function (pipelineId) {
  22371. return this._pipelineMap.get(pipelineId);
  22372. };
  22373. /**
  22374. * Current, progressive rendering starts from visual and layout.
  22375. * Always detect render mode in the same stage, avoiding that incorrect
  22376. * detection caused by data filtering.
  22377. * Caution:
  22378. * `updateStreamModes` use `seriesModel.getData()`.
  22379. */
  22380. proto.updateStreamModes = function (seriesModel, view) {
  22381. var pipeline = this._pipelineMap.get(seriesModel.uid);
  22382. var data = seriesModel.getData();
  22383. var dataLen = data.count();
  22384. // `progressiveRender` means that can render progressively in each
  22385. // animation frame. Note that some types of series do not provide
  22386. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  22387. // use the term `incremental` but not `progressive` to describe the
  22388. // case that `chart.appendData`.
  22389. var progressiveRender = pipeline.progressiveEnabled
  22390. && view.incrementalPrepareRender
  22391. && dataLen >= pipeline.threshold;
  22392. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold');
  22393. // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  22394. // see `test/candlestick-large3.html`
  22395. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  22396. seriesModel.pipelineContext = pipeline.context = {
  22397. progressiveRender: progressiveRender,
  22398. modDataCount: modDataCount,
  22399. large: large
  22400. };
  22401. };
  22402. proto.restorePipelines = function (ecModel) {
  22403. var scheduler = this;
  22404. var pipelineMap = scheduler._pipelineMap = createHashMap();
  22405. ecModel.eachSeries(function (seriesModel) {
  22406. var progressive = seriesModel.getProgressive();
  22407. var pipelineId = seriesModel.uid;
  22408. pipelineMap.set(pipelineId, {
  22409. id: pipelineId,
  22410. head: null,
  22411. tail: null,
  22412. threshold: seriesModel.getProgressiveThreshold(),
  22413. progressiveEnabled: progressive
  22414. && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  22415. blockIndex: -1,
  22416. step: Math.round(progressive || 700),
  22417. count: 0
  22418. });
  22419. pipe(scheduler, seriesModel, seriesModel.dataTask);
  22420. });
  22421. };
  22422. proto.prepareStageTasks = function () {
  22423. var stageTaskMap = this._stageTaskMap;
  22424. var ecModel = this.ecInstance.getModel();
  22425. var api = this.api;
  22426. each$1(this._allHandlers, function (handler) {
  22427. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, []);
  22428. handler.reset && createSeriesStageTask(this, handler, record, ecModel, api);
  22429. handler.overallReset && createOverallStageTask(this, handler, record, ecModel, api);
  22430. }, this);
  22431. };
  22432. proto.prepareView = function (view, model, ecModel, api) {
  22433. var renderTask = view.renderTask;
  22434. var context = renderTask.context;
  22435. context.model = model;
  22436. context.ecModel = ecModel;
  22437. context.api = api;
  22438. renderTask.__block = !view.incrementalPrepareRender;
  22439. pipe(this, model, renderTask);
  22440. };
  22441. proto.performDataProcessorTasks = function (ecModel, payload) {
  22442. // If we do not use `block` here, it should be considered when to update modes.
  22443. performStageTasks(this, this._dataProcessorHandlers, ecModel, payload, {block: true});
  22444. };
  22445. // opt
  22446. // opt.visualType: 'visual' or 'layout'
  22447. // opt.setDirty
  22448. proto.performVisualTasks = function (ecModel, payload, opt) {
  22449. performStageTasks(this, this._visualHandlers, ecModel, payload, opt);
  22450. };
  22451. function performStageTasks(scheduler, stageHandlers, ecModel, payload, opt) {
  22452. opt = opt || {};
  22453. var unfinished;
  22454. each$1(stageHandlers, function (stageHandler, idx) {
  22455. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  22456. return;
  22457. }
  22458. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  22459. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  22460. var overallTask = stageHandlerRecord.overallTask;
  22461. if (overallTask) {
  22462. var overallNeedDirty;
  22463. var agentStubMap = overallTask.agentStubMap;
  22464. agentStubMap.each(function (stub) {
  22465. if (needSetDirty(opt, stub)) {
  22466. stub.dirty();
  22467. overallNeedDirty = true;
  22468. }
  22469. });
  22470. overallNeedDirty && overallTask.dirty();
  22471. updatePayload(overallTask, payload);
  22472. var performArgs = scheduler.getPerformArgs(overallTask, opt.block);
  22473. // Execute stubs firstly, which may set the overall task dirty,
  22474. // then execute the overall task. And stub will call seriesModel.setData,
  22475. // which ensures that in the overallTask seriesModel.getData() will not
  22476. // return incorrect data.
  22477. agentStubMap.each(function (stub) {
  22478. stub.perform(performArgs);
  22479. });
  22480. unfinished |= overallTask.perform(performArgs);
  22481. }
  22482. else if (seriesTaskMap) {
  22483. seriesTaskMap.each(function (task, pipelineId) {
  22484. if (needSetDirty(opt, task)) {
  22485. task.dirty();
  22486. }
  22487. var performArgs = scheduler.getPerformArgs(task, opt.block);
  22488. // FIXME
  22489. // if intending to decalare `performRawSeries` in handlers, only
  22490. // stream-independent (specifically, data item independent) operations can be
  22491. // performed. Because is a series is filtered, most of the tasks will not
  22492. // be performed. A stream-dependent operation probably cause wrong biz logic.
  22493. // Perhaps we should not provide a separate callback for this case instead
  22494. // of providing the config `performRawSeries`. The stream-dependent operaions
  22495. // and stream-independent operations should better not be mixed.
  22496. performArgs.skip = !stageHandler.performRawSeries
  22497. && ecModel.isSeriesFiltered(task.context.model);
  22498. updatePayload(task, payload);
  22499. unfinished |= task.perform(performArgs);
  22500. });
  22501. }
  22502. });
  22503. function needSetDirty(opt, task) {
  22504. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  22505. }
  22506. scheduler.unfinished |= unfinished;
  22507. }
  22508. proto.performSeriesTasks = function (ecModel) {
  22509. var unfinished;
  22510. ecModel.eachSeries(function (seriesModel) {
  22511. // Progress to the end for dataInit and dataRestore.
  22512. unfinished |= seriesModel.dataTask.perform();
  22513. });
  22514. this.unfinished |= unfinished;
  22515. };
  22516. proto.plan = function () {
  22517. // Travel pipelines, check block.
  22518. this._pipelineMap.each(function (pipeline) {
  22519. var task = pipeline.tail;
  22520. do {
  22521. if (task.__block) {
  22522. pipeline.blockIndex = task.__idxInPipeline;
  22523. break;
  22524. }
  22525. task = task.getUpstream();
  22526. }
  22527. while (task);
  22528. });
  22529. };
  22530. var updatePayload = proto.updatePayload = function (task, payload) {
  22531. payload !== 'remain' && (task.context.payload = payload);
  22532. };
  22533. function createSeriesStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  22534. var seriesTaskMap = stageHandlerRecord.seriesTaskMap
  22535. || (stageHandlerRecord.seriesTaskMap = createHashMap());
  22536. var seriesType = stageHandler.seriesType;
  22537. var getTargetSeries = stageHandler.getTargetSeries;
  22538. // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  22539. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  22540. // it works but it may cause other irrelevant charts blocked.
  22541. if (stageHandler.createOnAllSeries) {
  22542. ecModel.eachRawSeries(create);
  22543. }
  22544. else if (seriesType) {
  22545. ecModel.eachRawSeriesByType(seriesType, create);
  22546. }
  22547. else if (getTargetSeries) {
  22548. getTargetSeries(ecModel, api).each(create);
  22549. }
  22550. function create(seriesModel) {
  22551. var pipelineId = seriesModel.uid;
  22552. // Init tasks for each seriesModel only once.
  22553. // Reuse original task instance.
  22554. var task = seriesTaskMap.get(pipelineId)
  22555. || seriesTaskMap.set(pipelineId, createTask({
  22556. plan: seriesTaskPlan,
  22557. reset: seriesTaskReset,
  22558. count: seriesTaskCount
  22559. }));
  22560. task.context = {
  22561. model: seriesModel,
  22562. ecModel: ecModel,
  22563. api: api,
  22564. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  22565. plan: stageHandler.plan,
  22566. reset: stageHandler.reset,
  22567. scheduler: scheduler
  22568. };
  22569. pipe(scheduler, seriesModel, task);
  22570. }
  22571. // Clear unused series tasks.
  22572. var pipelineMap = scheduler._pipelineMap;
  22573. seriesTaskMap.each(function (task, pipelineId) {
  22574. if (!pipelineMap.get(pipelineId)) {
  22575. task.dispose();
  22576. seriesTaskMap.removeKey(pipelineId);
  22577. }
  22578. });
  22579. }
  22580. function createOverallStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  22581. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask
  22582. // For overall task, the function only be called on reset stage.
  22583. || createTask({reset: overallTaskReset});
  22584. overallTask.context = {
  22585. ecModel: ecModel,
  22586. api: api,
  22587. overallReset: stageHandler.overallReset,
  22588. scheduler: scheduler
  22589. };
  22590. // Reuse orignal stubs.
  22591. var agentStubMap = overallTask.agentStubMap = overallTask.agentStubMap || createHashMap();
  22592. var seriesType = stageHandler.seriesType;
  22593. var getTargetSeries = stageHandler.getTargetSeries;
  22594. var overallProgress = true;
  22595. var modifyOutputEnd = stageHandler.modifyOutputEnd;
  22596. // An overall task with seriesType detected or has `getTargetSeries`, we add
  22597. // stub in each pipelines, it will set the overall task dirty when the pipeline
  22598. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  22599. // we set the pipeline block.
  22600. if (seriesType) {
  22601. ecModel.eachRawSeriesByType(seriesType, createStub);
  22602. }
  22603. else if (getTargetSeries) {
  22604. getTargetSeries(ecModel, api).each(createStub);
  22605. }
  22606. // Otherwise, (usually it is legancy case), the overall task will only be
  22607. // executed when upstream dirty. Otherwise the progressive rendering of all
  22608. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  22609. // dirty info from upsteam.
  22610. else {
  22611. overallProgress = false;
  22612. each$1(ecModel.getSeries(), createStub);
  22613. }
  22614. function createStub(seriesModel) {
  22615. var pipelineId = seriesModel.uid;
  22616. var stub = agentStubMap.get(pipelineId);
  22617. if (!stub) {
  22618. stub = agentStubMap.set(pipelineId, createTask(
  22619. {reset: stubReset, onDirty: stubOnDirty}
  22620. ));
  22621. // When the result of `getTargetSeries` changed, the overallTask
  22622. // should be set as dirty and re-performed.
  22623. overallTask.dirty();
  22624. }
  22625. stub.context = {
  22626. model: seriesModel,
  22627. overallProgress: overallProgress,
  22628. modifyOutputEnd: modifyOutputEnd
  22629. };
  22630. stub.agent = overallTask;
  22631. stub.__block = overallProgress;
  22632. pipe(scheduler, seriesModel, stub);
  22633. }
  22634. // Clear unused stubs.
  22635. var pipelineMap = scheduler._pipelineMap;
  22636. agentStubMap.each(function (stub, pipelineId) {
  22637. if (!pipelineMap.get(pipelineId)) {
  22638. stub.dispose();
  22639. // When the result of `getTargetSeries` changed, the overallTask
  22640. // should be set as dirty and re-performed.
  22641. overallTask.dirty();
  22642. agentStubMap.removeKey(pipelineId);
  22643. }
  22644. });
  22645. }
  22646. function overallTaskReset(context) {
  22647. context.overallReset(
  22648. context.ecModel, context.api, context.payload
  22649. );
  22650. }
  22651. function stubReset(context, upstreamContext) {
  22652. return context.overallProgress && stubProgress;
  22653. }
  22654. function stubProgress() {
  22655. this.agent.dirty();
  22656. this.getDownstream().dirty();
  22657. }
  22658. function stubOnDirty() {
  22659. this.agent && this.agent.dirty();
  22660. }
  22661. function seriesTaskPlan(context) {
  22662. return context.plan && context.plan(
  22663. context.model, context.ecModel, context.api, context.payload
  22664. );
  22665. }
  22666. function seriesTaskReset(context) {
  22667. if (context.useClearVisual) {
  22668. context.data.clearAllVisual();
  22669. }
  22670. var resetDefines = context.resetDefines = normalizeToArray(context.reset(
  22671. context.model, context.ecModel, context.api, context.payload
  22672. ));
  22673. return resetDefines.length > 1
  22674. ? map(resetDefines, function (v, idx) {
  22675. return makeSeriesTaskProgress(idx);
  22676. })
  22677. : singleSeriesTaskProgress;
  22678. }
  22679. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  22680. function makeSeriesTaskProgress(resetDefineIdx) {
  22681. return function (params, context) {
  22682. var data = context.data;
  22683. var resetDefine = context.resetDefines[resetDefineIdx];
  22684. if (resetDefine && resetDefine.dataEach) {
  22685. for (var i = params.start; i < params.end; i++) {
  22686. resetDefine.dataEach(data, i);
  22687. }
  22688. }
  22689. else if (resetDefine && resetDefine.progress) {
  22690. resetDefine.progress(params, data);
  22691. }
  22692. };
  22693. }
  22694. function seriesTaskCount(context) {
  22695. return context.data.count();
  22696. }
  22697. function pipe(scheduler, seriesModel, task) {
  22698. var pipelineId = seriesModel.uid;
  22699. var pipeline = scheduler._pipelineMap.get(pipelineId);
  22700. !pipeline.head && (pipeline.head = task);
  22701. pipeline.tail && pipeline.tail.pipe(task);
  22702. pipeline.tail = task;
  22703. task.__idxInPipeline = pipeline.count++;
  22704. task.__pipeline = pipeline;
  22705. }
  22706. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  22707. if (isFunction$1(stageHandler)) {
  22708. stageHandler = {
  22709. overallReset: stageHandler,
  22710. seriesType: detectSeriseType(stageHandler)
  22711. };
  22712. }
  22713. stageHandler.uid = getUID('stageHandler');
  22714. visualType && (stageHandler.visualType = visualType);
  22715. return stageHandler;
  22716. };
  22717. /**
  22718. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  22719. * To ensure that they can work normally, they should work in block mode, that is,
  22720. * they should not be started util the previous tasks finished. So they cause the
  22721. * progressive rendering disabled. We try to detect the series type, to narrow down
  22722. * the block range to only the series type they concern, but not all series.
  22723. */
  22724. function detectSeriseType(legacyFunc) {
  22725. seriesType = null;
  22726. try {
  22727. // Assume there is no async when calling `eachSeriesByType`.
  22728. legacyFunc(ecModelMock, apiMock);
  22729. }
  22730. catch (e) {
  22731. }
  22732. return seriesType;
  22733. }
  22734. var ecModelMock = {};
  22735. var apiMock = {};
  22736. var seriesType;
  22737. mockMethods(ecModelMock, GlobalModel);
  22738. mockMethods(apiMock, ExtensionAPI);
  22739. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  22740. seriesType = type;
  22741. };
  22742. ecModelMock.eachComponent = function (cond) {
  22743. if (cond.mainType === 'series' && cond.subType) {
  22744. seriesType = cond.subType;
  22745. }
  22746. };
  22747. function mockMethods(target, Clz) {
  22748. /* eslint-disable */
  22749. for (var name in Clz.prototype) {
  22750. // Do not use hasOwnProperty
  22751. target[name] = noop;
  22752. }
  22753. /* eslint-enable */
  22754. }
  22755. /*
  22756. * Licensed to the Apache Software Foundation (ASF) under one
  22757. * or more contributor license agreements. See the NOTICE file
  22758. * distributed with this work for additional information
  22759. * regarding copyright ownership. The ASF licenses this file
  22760. * to you under the Apache License, Version 2.0 (the
  22761. * "License"); you may not use this file except in compliance
  22762. * with the License. You may obtain a copy of the License at
  22763. *
  22764. * http://www.apache.org/licenses/LICENSE-2.0
  22765. *
  22766. * Unless required by applicable law or agreed to in writing,
  22767. * software distributed under the License is distributed on an
  22768. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22769. * KIND, either express or implied. See the License for the
  22770. * specific language governing permissions and limitations
  22771. * under the License.
  22772. */
  22773. var colorAll = [
  22774. '#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C', '#ff9f7f',
  22775. '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'
  22776. ];
  22777. var lightTheme = {
  22778. color: colorAll,
  22779. colorLayer: [
  22780. ['#37A2DA', '#ffd85c', '#fd7b5f'],
  22781. ['#37A2DA', '#67E0E3', '#FFDB5C', '#ff9f7f', '#E062AE', '#9d96f5'],
  22782. ['#37A2DA', '#32C5E9', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#e7bcf3', '#8378EA', '#96BFFF'],
  22783. colorAll
  22784. ]
  22785. };
  22786. /*
  22787. * Licensed to the Apache Software Foundation (ASF) under one
  22788. * or more contributor license agreements. See the NOTICE file
  22789. * distributed with this work for additional information
  22790. * regarding copyright ownership. The ASF licenses this file
  22791. * to you under the Apache License, Version 2.0 (the
  22792. * "License"); you may not use this file except in compliance
  22793. * with the License. You may obtain a copy of the License at
  22794. *
  22795. * http://www.apache.org/licenses/LICENSE-2.0
  22796. *
  22797. * Unless required by applicable law or agreed to in writing,
  22798. * software distributed under the License is distributed on an
  22799. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22800. * KIND, either express or implied. See the License for the
  22801. * specific language governing permissions and limitations
  22802. * under the License.
  22803. */
  22804. var contrastColor = '#eee';
  22805. var axisCommon = function () {
  22806. return {
  22807. axisLine: {
  22808. lineStyle: {
  22809. color: contrastColor
  22810. }
  22811. },
  22812. axisTick: {
  22813. lineStyle: {
  22814. color: contrastColor
  22815. }
  22816. },
  22817. axisLabel: {
  22818. textStyle: {
  22819. color: contrastColor
  22820. }
  22821. },
  22822. splitLine: {
  22823. lineStyle: {
  22824. type: 'dashed',
  22825. color: '#aaa'
  22826. }
  22827. },
  22828. splitArea: {
  22829. areaStyle: {
  22830. color: contrastColor
  22831. }
  22832. }
  22833. };
  22834. };
  22835. var colorPalette = [
  22836. '#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53',
  22837. '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42'
  22838. ];
  22839. var theme = {
  22840. color: colorPalette,
  22841. backgroundColor: '#333',
  22842. tooltip: {
  22843. axisPointer: {
  22844. lineStyle: {
  22845. color: contrastColor
  22846. },
  22847. crossStyle: {
  22848. color: contrastColor
  22849. },
  22850. label: {
  22851. color: '#000'
  22852. }
  22853. }
  22854. },
  22855. legend: {
  22856. textStyle: {
  22857. color: contrastColor
  22858. }
  22859. },
  22860. textStyle: {
  22861. color: contrastColor
  22862. },
  22863. title: {
  22864. textStyle: {
  22865. color: contrastColor
  22866. }
  22867. },
  22868. toolbox: {
  22869. iconStyle: {
  22870. normal: {
  22871. borderColor: contrastColor
  22872. }
  22873. }
  22874. },
  22875. dataZoom: {
  22876. textStyle: {
  22877. color: contrastColor
  22878. }
  22879. },
  22880. visualMap: {
  22881. textStyle: {
  22882. color: contrastColor
  22883. }
  22884. },
  22885. timeline: {
  22886. lineStyle: {
  22887. color: contrastColor
  22888. },
  22889. itemStyle: {
  22890. normal: {
  22891. color: colorPalette[1]
  22892. }
  22893. },
  22894. label: {
  22895. normal: {
  22896. textStyle: {
  22897. color: contrastColor
  22898. }
  22899. }
  22900. },
  22901. controlStyle: {
  22902. normal: {
  22903. color: contrastColor,
  22904. borderColor: contrastColor
  22905. }
  22906. }
  22907. },
  22908. timeAxis: axisCommon(),
  22909. logAxis: axisCommon(),
  22910. valueAxis: axisCommon(),
  22911. categoryAxis: axisCommon(),
  22912. line: {
  22913. symbol: 'circle'
  22914. },
  22915. graph: {
  22916. color: colorPalette
  22917. },
  22918. gauge: {
  22919. title: {
  22920. textStyle: {
  22921. color: contrastColor
  22922. }
  22923. }
  22924. },
  22925. candlestick: {
  22926. itemStyle: {
  22927. normal: {
  22928. color: '#FD1050',
  22929. color0: '#0CF49B',
  22930. borderColor: '#FD1050',
  22931. borderColor0: '#0CF49B'
  22932. }
  22933. }
  22934. }
  22935. };
  22936. theme.categoryAxis.splitLine.show = false;
  22937. /*
  22938. * Licensed to the Apache Software Foundation (ASF) under one
  22939. * or more contributor license agreements. See the NOTICE file
  22940. * distributed with this work for additional information
  22941. * regarding copyright ownership. The ASF licenses this file
  22942. * to you under the Apache License, Version 2.0 (the
  22943. * "License"); you may not use this file except in compliance
  22944. * with the License. You may obtain a copy of the License at
  22945. *
  22946. * http://www.apache.org/licenses/LICENSE-2.0
  22947. *
  22948. * Unless required by applicable law or agreed to in writing,
  22949. * software distributed under the License is distributed on an
  22950. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22951. * KIND, either express or implied. See the License for the
  22952. * specific language governing permissions and limitations
  22953. * under the License.
  22954. */
  22955. /**
  22956. * This module is imported by echarts directly.
  22957. *
  22958. * Notice:
  22959. * Always keep this file exists for backward compatibility.
  22960. * Because before 4.1.0, dataset is an optional component,
  22961. * some users may import this module manually.
  22962. */
  22963. ComponentModel.extend({
  22964. type: 'dataset',
  22965. /**
  22966. * @protected
  22967. */
  22968. defaultOption: {
  22969. // 'row', 'column'
  22970. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  22971. // null/'auto': auto detect header, see "module:echarts/data/helper/sourceHelper"
  22972. sourceHeader: null,
  22973. dimensions: null,
  22974. source: null
  22975. },
  22976. optionUpdated: function () {
  22977. detectSourceFormat(this);
  22978. }
  22979. });
  22980. Component.extend({
  22981. type: 'dataset'
  22982. });
  22983. /**
  22984. * 椭圆形状
  22985. * @module zrender/graphic/shape/Ellipse
  22986. */
  22987. var Ellipse = Path.extend({
  22988. type: 'ellipse',
  22989. shape: {
  22990. cx: 0, cy: 0,
  22991. rx: 0, ry: 0
  22992. },
  22993. buildPath: function (ctx, shape) {
  22994. var k = 0.5522848;
  22995. var x = shape.cx;
  22996. var y = shape.cy;
  22997. var a = shape.rx;
  22998. var b = shape.ry;
  22999. var ox = a * k; // 水平控制点偏移量
  23000. var oy = b * k; // 垂直控制点偏移量
  23001. // 从椭圆的左端点开始顺时针绘制四条三次贝塞尔曲线
  23002. ctx.moveTo(x - a, y);
  23003. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  23004. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  23005. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  23006. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  23007. ctx.closePath();
  23008. }
  23009. });
  23010. // import RadialGradient from '../graphic/RadialGradient';
  23011. // import Pattern from '../graphic/Pattern';
  23012. // import * as vector from '../core/vector';
  23013. // Most of the values can be separated by comma and/or white space.
  23014. var DILIMITER_REG = /[\s,]+/;
  23015. /**
  23016. * For big svg string, this method might be time consuming.
  23017. *
  23018. * @param {string} svg xml string
  23019. * @return {Object} xml root.
  23020. */
  23021. function parseXML(svg) {
  23022. if (isString(svg)) {
  23023. var parser = new DOMParser();
  23024. svg = parser.parseFromString(svg, 'text/xml');
  23025. }
  23026. // Document node. If using $.get, doc node may be input.
  23027. if (svg.nodeType === 9) {
  23028. svg = svg.firstChild;
  23029. }
  23030. // nodeName of <!DOCTYPE svg> is also 'svg'.
  23031. while (svg.nodeName.toLowerCase() !== 'svg' || svg.nodeType !== 1) {
  23032. svg = svg.nextSibling;
  23033. }
  23034. return svg;
  23035. }
  23036. function SVGParser() {
  23037. this._defs = {};
  23038. this._root = null;
  23039. this._isDefine = false;
  23040. this._isText = false;
  23041. }
  23042. SVGParser.prototype.parse = function (xml, opt) {
  23043. opt = opt || {};
  23044. var svg = parseXML(xml);
  23045. if (!svg) {
  23046. throw new Error('Illegal svg');
  23047. }
  23048. var root = new Group();
  23049. this._root = root;
  23050. // parse view port
  23051. var viewBox = svg.getAttribute('viewBox') || '';
  23052. // If width/height not specified, means "100%" of `opt.width/height`.
  23053. // TODO: Other percent value not supported yet.
  23054. var width = parseFloat(svg.getAttribute('width') || opt.width);
  23055. var height = parseFloat(svg.getAttribute('height') || opt.height);
  23056. // If width/height not specified, set as null for output.
  23057. isNaN(width) && (width = null);
  23058. isNaN(height) && (height = null);
  23059. // Apply inline style on svg element.
  23060. parseAttributes(svg, root, null, true);
  23061. var child = svg.firstChild;
  23062. while (child) {
  23063. this._parseNode(child, root);
  23064. child = child.nextSibling;
  23065. }
  23066. var viewBoxRect;
  23067. var viewBoxTransform;
  23068. if (viewBox) {
  23069. var viewBoxArr = trim(viewBox).split(DILIMITER_REG);
  23070. // Some invalid case like viewBox: 'none'.
  23071. if (viewBoxArr.length >= 4) {
  23072. viewBoxRect = {
  23073. x: parseFloat(viewBoxArr[0] || 0),
  23074. y: parseFloat(viewBoxArr[1] || 0),
  23075. width: parseFloat(viewBoxArr[2]),
  23076. height: parseFloat(viewBoxArr[3])
  23077. };
  23078. }
  23079. }
  23080. if (viewBoxRect && width != null && height != null) {
  23081. viewBoxTransform = makeViewBoxTransform(viewBoxRect, width, height);
  23082. if (!opt.ignoreViewBox) {
  23083. // If set transform on the output group, it probably bring trouble when
  23084. // some users only intend to show the clipped content inside the viewBox,
  23085. // but not intend to transform the output group. So we keep the output
  23086. // group no transform. If the user intend to use the viewBox as a
  23087. // camera, just set `opt.ignoreViewBox` as `true` and set transfrom
  23088. // manually according to the viewBox info in the output of this method.
  23089. var elRoot = root;
  23090. root = new Group();
  23091. root.add(elRoot);
  23092. elRoot.scale = viewBoxTransform.scale.slice();
  23093. elRoot.position = viewBoxTransform.position.slice();
  23094. }
  23095. }
  23096. // Some shapes might be overflow the viewport, which should be
  23097. // clipped despite whether the viewBox is used, as the SVG does.
  23098. if (!opt.ignoreRootClip && width != null && height != null) {
  23099. root.setClipPath(new Rect({
  23100. shape: {x: 0, y: 0, width: width, height: height}
  23101. }));
  23102. }
  23103. // Set width/height on group just for output the viewport size.
  23104. return {
  23105. root: root,
  23106. width: width,
  23107. height: height,
  23108. viewBoxRect: viewBoxRect,
  23109. viewBoxTransform: viewBoxTransform
  23110. };
  23111. };
  23112. SVGParser.prototype._parseNode = function (xmlNode, parentGroup) {
  23113. var nodeName = xmlNode.nodeName.toLowerCase();
  23114. // TODO
  23115. // support <style>...</style> in svg, where nodeName is 'style',
  23116. // CSS classes is defined globally wherever the style tags are declared.
  23117. if (nodeName === 'defs') {
  23118. // define flag
  23119. this._isDefine = true;
  23120. }
  23121. else if (nodeName === 'text') {
  23122. this._isText = true;
  23123. }
  23124. var el;
  23125. if (this._isDefine) {
  23126. var parser = defineParsers[nodeName];
  23127. if (parser) {
  23128. var def = parser.call(this, xmlNode);
  23129. var id = xmlNode.getAttribute('id');
  23130. if (id) {
  23131. this._defs[id] = def;
  23132. }
  23133. }
  23134. }
  23135. else {
  23136. var parser = nodeParsers[nodeName];
  23137. if (parser) {
  23138. el = parser.call(this, xmlNode, parentGroup);
  23139. parentGroup.add(el);
  23140. }
  23141. }
  23142. var child = xmlNode.firstChild;
  23143. while (child) {
  23144. if (child.nodeType === 1) {
  23145. this._parseNode(child, el);
  23146. }
  23147. // Is text
  23148. if (child.nodeType === 3 && this._isText) {
  23149. this._parseText(child, el);
  23150. }
  23151. child = child.nextSibling;
  23152. }
  23153. // Quit define
  23154. if (nodeName === 'defs') {
  23155. this._isDefine = false;
  23156. }
  23157. else if (nodeName === 'text') {
  23158. this._isText = false;
  23159. }
  23160. };
  23161. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  23162. if (xmlNode.nodeType === 1) {
  23163. var dx = xmlNode.getAttribute('dx') || 0;
  23164. var dy = xmlNode.getAttribute('dy') || 0;
  23165. this._textX += parseFloat(dx);
  23166. this._textY += parseFloat(dy);
  23167. }
  23168. var text = new Text({
  23169. style: {
  23170. text: xmlNode.textContent,
  23171. transformText: true
  23172. },
  23173. position: [this._textX || 0, this._textY || 0]
  23174. });
  23175. inheritStyle(parentGroup, text);
  23176. parseAttributes(xmlNode, text, this._defs);
  23177. var fontSize = text.style.fontSize;
  23178. if (fontSize && fontSize < 9) {
  23179. // PENDING
  23180. text.style.fontSize = 9;
  23181. text.scale = text.scale || [1, 1];
  23182. text.scale[0] *= fontSize / 9;
  23183. text.scale[1] *= fontSize / 9;
  23184. }
  23185. var rect = text.getBoundingRect();
  23186. this._textX += rect.width;
  23187. parentGroup.add(text);
  23188. return text;
  23189. };
  23190. var nodeParsers = {
  23191. 'g': function (xmlNode, parentGroup) {
  23192. var g = new Group();
  23193. inheritStyle(parentGroup, g);
  23194. parseAttributes(xmlNode, g, this._defs);
  23195. return g;
  23196. },
  23197. 'rect': function (xmlNode, parentGroup) {
  23198. var rect = new Rect();
  23199. inheritStyle(parentGroup, rect);
  23200. parseAttributes(xmlNode, rect, this._defs);
  23201. rect.setShape({
  23202. x: parseFloat(xmlNode.getAttribute('x') || 0),
  23203. y: parseFloat(xmlNode.getAttribute('y') || 0),
  23204. width: parseFloat(xmlNode.getAttribute('width') || 0),
  23205. height: parseFloat(xmlNode.getAttribute('height') || 0)
  23206. });
  23207. // console.log(xmlNode.getAttribute('transform'));
  23208. // console.log(rect.transform);
  23209. return rect;
  23210. },
  23211. 'circle': function (xmlNode, parentGroup) {
  23212. var circle = new Circle();
  23213. inheritStyle(parentGroup, circle);
  23214. parseAttributes(xmlNode, circle, this._defs);
  23215. circle.setShape({
  23216. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  23217. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  23218. r: parseFloat(xmlNode.getAttribute('r') || 0)
  23219. });
  23220. return circle;
  23221. },
  23222. 'line': function (xmlNode, parentGroup) {
  23223. var line = new Line();
  23224. inheritStyle(parentGroup, line);
  23225. parseAttributes(xmlNode, line, this._defs);
  23226. line.setShape({
  23227. x1: parseFloat(xmlNode.getAttribute('x1') || 0),
  23228. y1: parseFloat(xmlNode.getAttribute('y1') || 0),
  23229. x2: parseFloat(xmlNode.getAttribute('x2') || 0),
  23230. y2: parseFloat(xmlNode.getAttribute('y2') || 0)
  23231. });
  23232. return line;
  23233. },
  23234. 'ellipse': function (xmlNode, parentGroup) {
  23235. var ellipse = new Ellipse();
  23236. inheritStyle(parentGroup, ellipse);
  23237. parseAttributes(xmlNode, ellipse, this._defs);
  23238. ellipse.setShape({
  23239. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  23240. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  23241. rx: parseFloat(xmlNode.getAttribute('rx') || 0),
  23242. ry: parseFloat(xmlNode.getAttribute('ry') || 0)
  23243. });
  23244. return ellipse;
  23245. },
  23246. 'polygon': function (xmlNode, parentGroup) {
  23247. var points = xmlNode.getAttribute('points');
  23248. if (points) {
  23249. points = parsePoints(points);
  23250. }
  23251. var polygon = new Polygon({
  23252. shape: {
  23253. points: points || []
  23254. }
  23255. });
  23256. inheritStyle(parentGroup, polygon);
  23257. parseAttributes(xmlNode, polygon, this._defs);
  23258. return polygon;
  23259. },
  23260. 'polyline': function (xmlNode, parentGroup) {
  23261. var path = new Path();
  23262. inheritStyle(parentGroup, path);
  23263. parseAttributes(xmlNode, path, this._defs);
  23264. var points = xmlNode.getAttribute('points');
  23265. if (points) {
  23266. points = parsePoints(points);
  23267. }
  23268. var polyline = new Polyline({
  23269. shape: {
  23270. points: points || []
  23271. }
  23272. });
  23273. return polyline;
  23274. },
  23275. 'image': function (xmlNode, parentGroup) {
  23276. var img = new ZImage();
  23277. inheritStyle(parentGroup, img);
  23278. parseAttributes(xmlNode, img, this._defs);
  23279. img.setStyle({
  23280. image: xmlNode.getAttribute('xlink:href'),
  23281. x: xmlNode.getAttribute('x'),
  23282. y: xmlNode.getAttribute('y'),
  23283. width: xmlNode.getAttribute('width'),
  23284. height: xmlNode.getAttribute('height')
  23285. });
  23286. return img;
  23287. },
  23288. 'text': function (xmlNode, parentGroup) {
  23289. var x = xmlNode.getAttribute('x') || 0;
  23290. var y = xmlNode.getAttribute('y') || 0;
  23291. var dx = xmlNode.getAttribute('dx') || 0;
  23292. var dy = xmlNode.getAttribute('dy') || 0;
  23293. this._textX = parseFloat(x) + parseFloat(dx);
  23294. this._textY = parseFloat(y) + parseFloat(dy);
  23295. var g = new Group();
  23296. inheritStyle(parentGroup, g);
  23297. parseAttributes(xmlNode, g, this._defs);
  23298. return g;
  23299. },
  23300. 'tspan': function (xmlNode, parentGroup) {
  23301. var x = xmlNode.getAttribute('x');
  23302. var y = xmlNode.getAttribute('y');
  23303. if (x != null) {
  23304. // new offset x
  23305. this._textX = parseFloat(x);
  23306. }
  23307. if (y != null) {
  23308. // new offset y
  23309. this._textY = parseFloat(y);
  23310. }
  23311. var dx = xmlNode.getAttribute('dx') || 0;
  23312. var dy = xmlNode.getAttribute('dy') || 0;
  23313. var g = new Group();
  23314. inheritStyle(parentGroup, g);
  23315. parseAttributes(xmlNode, g, this._defs);
  23316. this._textX += dx;
  23317. this._textY += dy;
  23318. return g;
  23319. },
  23320. 'path': function (xmlNode, parentGroup) {
  23321. // TODO svg fill rule
  23322. // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
  23323. // path.style.globalCompositeOperation = 'xor';
  23324. var d = xmlNode.getAttribute('d') || '';
  23325. // Performance sensitive.
  23326. var path = createFromString(d);
  23327. inheritStyle(parentGroup, path);
  23328. parseAttributes(xmlNode, path, this._defs);
  23329. return path;
  23330. }
  23331. };
  23332. var defineParsers = {
  23333. 'lineargradient': function (xmlNode) {
  23334. var x1 = parseInt(xmlNode.getAttribute('x1') || 0, 10);
  23335. var y1 = parseInt(xmlNode.getAttribute('y1') || 0, 10);
  23336. var x2 = parseInt(xmlNode.getAttribute('x2') || 10, 10);
  23337. var y2 = parseInt(xmlNode.getAttribute('y2') || 0, 10);
  23338. var gradient = new LinearGradient(x1, y1, x2, y2);
  23339. _parseGradientColorStops(xmlNode, gradient);
  23340. return gradient;
  23341. },
  23342. 'radialgradient': function (xmlNode) {
  23343. }
  23344. };
  23345. function _parseGradientColorStops(xmlNode, gradient) {
  23346. var stop = xmlNode.firstChild;
  23347. while (stop) {
  23348. if (stop.nodeType === 1) {
  23349. var offset = stop.getAttribute('offset');
  23350. if (offset.indexOf('%') > 0) { // percentage
  23351. offset = parseInt(offset, 10) / 100;
  23352. }
  23353. else if (offset) { // number from 0 to 1
  23354. offset = parseFloat(offset);
  23355. }
  23356. else {
  23357. offset = 0;
  23358. }
  23359. var stopColor = stop.getAttribute('stop-color') || '#000000';
  23360. gradient.addColorStop(offset, stopColor);
  23361. }
  23362. stop = stop.nextSibling;
  23363. }
  23364. }
  23365. function inheritStyle(parent, child) {
  23366. if (parent && parent.__inheritedStyle) {
  23367. if (!child.__inheritedStyle) {
  23368. child.__inheritedStyle = {};
  23369. }
  23370. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  23371. }
  23372. }
  23373. function parsePoints(pointsString) {
  23374. var list = trim(pointsString).split(DILIMITER_REG);
  23375. var points = [];
  23376. for (var i = 0; i < list.length; i += 2) {
  23377. var x = parseFloat(list[i]);
  23378. var y = parseFloat(list[i + 1]);
  23379. points.push([x, y]);
  23380. }
  23381. return points;
  23382. }
  23383. var attributesMap = {
  23384. 'fill': 'fill',
  23385. 'stroke': 'stroke',
  23386. 'stroke-width': 'lineWidth',
  23387. 'opacity': 'opacity',
  23388. 'fill-opacity': 'fillOpacity',
  23389. 'stroke-opacity': 'strokeOpacity',
  23390. 'stroke-dasharray': 'lineDash',
  23391. 'stroke-dashoffset': 'lineDashOffset',
  23392. 'stroke-linecap': 'lineCap',
  23393. 'stroke-linejoin': 'lineJoin',
  23394. 'stroke-miterlimit': 'miterLimit',
  23395. 'font-family': 'fontFamily',
  23396. 'font-size': 'fontSize',
  23397. 'font-style': 'fontStyle',
  23398. 'font-weight': 'fontWeight',
  23399. 'text-align': 'textAlign',
  23400. 'alignment-baseline': 'textBaseline'
  23401. };
  23402. function parseAttributes(xmlNode, el, defs, onlyInlineStyle) {
  23403. var zrStyle = el.__inheritedStyle || {};
  23404. var isTextEl = el.type === 'text';
  23405. // TODO Shadow
  23406. if (xmlNode.nodeType === 1) {
  23407. parseTransformAttribute(xmlNode, el);
  23408. extend(zrStyle, parseStyleAttribute(xmlNode));
  23409. if (!onlyInlineStyle) {
  23410. for (var svgAttrName in attributesMap) {
  23411. if (attributesMap.hasOwnProperty(svgAttrName)) {
  23412. var attrValue = xmlNode.getAttribute(svgAttrName);
  23413. if (attrValue != null) {
  23414. zrStyle[attributesMap[svgAttrName]] = attrValue;
  23415. }
  23416. }
  23417. }
  23418. }
  23419. }
  23420. var elFillProp = isTextEl ? 'textFill' : 'fill';
  23421. var elStrokeProp = isTextEl ? 'textStroke' : 'stroke';
  23422. el.style = el.style || new Style();
  23423. var elStyle = el.style;
  23424. zrStyle.fill != null && elStyle.set(elFillProp, getPaint(zrStyle.fill, defs));
  23425. zrStyle.stroke != null && elStyle.set(elStrokeProp, getPaint(zrStyle.stroke, defs));
  23426. each$1([
  23427. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  23428. ], function (propName) {
  23429. var elPropName = (propName === 'lineWidth' && isTextEl) ? 'textStrokeWidth' : propName;
  23430. zrStyle[propName] != null && elStyle.set(elPropName, parseFloat(zrStyle[propName]));
  23431. });
  23432. if (!zrStyle.textBaseline || zrStyle.textBaseline === 'auto') {
  23433. zrStyle.textBaseline = 'alphabetic';
  23434. }
  23435. if (zrStyle.textBaseline === 'alphabetic') {
  23436. zrStyle.textBaseline = 'bottom';
  23437. }
  23438. if (zrStyle.textAlign === 'start') {
  23439. zrStyle.textAlign = 'left';
  23440. }
  23441. if (zrStyle.textAlign === 'end') {
  23442. zrStyle.textAlign = 'right';
  23443. }
  23444. each$1(['lineDashOffset', 'lineCap', 'lineJoin',
  23445. 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'textBaseline'
  23446. ], function (propName) {
  23447. zrStyle[propName] != null && elStyle.set(propName, zrStyle[propName]);
  23448. });
  23449. if (zrStyle.lineDash) {
  23450. el.style.lineDash = trim(zrStyle.lineDash).split(DILIMITER_REG);
  23451. }
  23452. if (elStyle[elStrokeProp] && elStyle[elStrokeProp] !== 'none') {
  23453. // enable stroke
  23454. el[elStrokeProp] = true;
  23455. }
  23456. el.__inheritedStyle = zrStyle;
  23457. }
  23458. var urlRegex = /url\(\s*#(.*?)\)/;
  23459. function getPaint(str, defs) {
  23460. // if (str === 'none') {
  23461. // return;
  23462. // }
  23463. var urlMatch = defs && str && str.match(urlRegex);
  23464. if (urlMatch) {
  23465. var url = trim(urlMatch[1]);
  23466. var def = defs[url];
  23467. return def;
  23468. }
  23469. return str;
  23470. }
  23471. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.e,]*)\)/g;
  23472. function parseTransformAttribute(xmlNode, node) {
  23473. var transform = xmlNode.getAttribute('transform');
  23474. if (transform) {
  23475. transform = transform.replace(/,/g, ' ');
  23476. var m = null;
  23477. var transformOps = [];
  23478. transform.replace(transformRegex, function (str, type, value) {
  23479. transformOps.push(type, value);
  23480. });
  23481. for (var i = transformOps.length - 1; i > 0; i -= 2) {
  23482. var value = transformOps[i];
  23483. var type = transformOps[i - 1];
  23484. m = m || create$1();
  23485. switch (type) {
  23486. case 'translate':
  23487. value = trim(value).split(DILIMITER_REG);
  23488. translate(m, m, [parseFloat(value[0]), parseFloat(value[1] || 0)]);
  23489. break;
  23490. case 'scale':
  23491. value = trim(value).split(DILIMITER_REG);
  23492. scale$1(m, m, [parseFloat(value[0]), parseFloat(value[1] || value[0])]);
  23493. break;
  23494. case 'rotate':
  23495. value = trim(value).split(DILIMITER_REG);
  23496. rotate(m, m, parseFloat(value[0]));
  23497. break;
  23498. case 'skew':
  23499. value = trim(value).split(DILIMITER_REG);
  23500. console.warn('Skew transform is not supported yet');
  23501. break;
  23502. case 'matrix':
  23503. var value = trim(value).split(DILIMITER_REG);
  23504. m[0] = parseFloat(value[0]);
  23505. m[1] = parseFloat(value[1]);
  23506. m[2] = parseFloat(value[2]);
  23507. m[3] = parseFloat(value[3]);
  23508. m[4] = parseFloat(value[4]);
  23509. m[5] = parseFloat(value[5]);
  23510. break;
  23511. }
  23512. }
  23513. node.setLocalTransform(m);
  23514. }
  23515. }
  23516. // Value may contain space.
  23517. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  23518. function parseStyleAttribute(xmlNode) {
  23519. var style = xmlNode.getAttribute('style');
  23520. var result = {};
  23521. if (!style) {
  23522. return result;
  23523. }
  23524. var styleList = {};
  23525. styleRegex.lastIndex = 0;
  23526. var styleRegResult;
  23527. while ((styleRegResult = styleRegex.exec(style)) != null) {
  23528. styleList[styleRegResult[1]] = styleRegResult[2];
  23529. }
  23530. for (var svgAttrName in attributesMap) {
  23531. if (attributesMap.hasOwnProperty(svgAttrName) && styleList[svgAttrName] != null) {
  23532. result[attributesMap[svgAttrName]] = styleList[svgAttrName];
  23533. }
  23534. }
  23535. return result;
  23536. }
  23537. /**
  23538. * @param {Array.<number>} viewBoxRect
  23539. * @param {number} width
  23540. * @param {number} height
  23541. * @return {Object} {scale, position}
  23542. */
  23543. function makeViewBoxTransform(viewBoxRect, width, height) {
  23544. var scaleX = width / viewBoxRect.width;
  23545. var scaleY = height / viewBoxRect.height;
  23546. var scale = Math.min(scaleX, scaleY);
  23547. // preserveAspectRatio 'xMidYMid'
  23548. var viewBoxScale = [scale, scale];
  23549. var viewBoxPosition = [
  23550. -(viewBoxRect.x + viewBoxRect.width / 2) * scale + width / 2,
  23551. -(viewBoxRect.y + viewBoxRect.height / 2) * scale + height / 2
  23552. ];
  23553. return {
  23554. scale: viewBoxScale,
  23555. position: viewBoxPosition
  23556. };
  23557. }
  23558. /**
  23559. * @param {string|XMLElement} xml
  23560. * @param {Object} [opt]
  23561. * @param {number} [opt.width] Default width if svg width not specified or is a percent value.
  23562. * @param {number} [opt.height] Default height if svg height not specified or is a percent value.
  23563. * @param {boolean} [opt.ignoreViewBox]
  23564. * @param {boolean} [opt.ignoreRootClip]
  23565. * @return {Object} result:
  23566. * {
  23567. * root: Group, The root of the the result tree of zrender shapes,
  23568. * width: number, the viewport width of the SVG,
  23569. * height: number, the viewport height of the SVG,
  23570. * viewBoxRect: {x, y, width, height}, the declared viewBox rect of the SVG, if exists,
  23571. * viewBoxTransform: the {scale, position} calculated by viewBox and viewport, is exists.
  23572. * }
  23573. */
  23574. /*
  23575. * Licensed to the Apache Software Foundation (ASF) under one
  23576. * or more contributor license agreements. See the NOTICE file
  23577. * distributed with this work for additional information
  23578. * regarding copyright ownership. The ASF licenses this file
  23579. * to you under the Apache License, Version 2.0 (the
  23580. * "License"); you may not use this file except in compliance
  23581. * with the License. You may obtain a copy of the License at
  23582. *
  23583. * http://www.apache.org/licenses/LICENSE-2.0
  23584. *
  23585. * Unless required by applicable law or agreed to in writing,
  23586. * software distributed under the License is distributed on an
  23587. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23588. * KIND, either express or implied. See the License for the
  23589. * specific language governing permissions and limitations
  23590. * under the License.
  23591. */
  23592. var storage = createHashMap();
  23593. // For minimize the code size of common echarts package,
  23594. // do not put too much logic in this module.
  23595. var mapDataStorage = {
  23596. // The format of record: see `echarts.registerMap`.
  23597. // Compatible with previous `echarts.registerMap`.
  23598. registerMap: function (mapName, rawGeoJson, rawSpecialAreas) {
  23599. var records;
  23600. if (isArray(rawGeoJson)) {
  23601. records = rawGeoJson;
  23602. }
  23603. else if (rawGeoJson.svg) {
  23604. records = [{
  23605. type: 'svg',
  23606. source: rawGeoJson.svg,
  23607. specialAreas: rawGeoJson.specialAreas
  23608. }];
  23609. }
  23610. else {
  23611. // Backward compatibility.
  23612. if (rawGeoJson.geoJson && !rawGeoJson.features) {
  23613. rawSpecialAreas = rawGeoJson.specialAreas;
  23614. rawGeoJson = rawGeoJson.geoJson;
  23615. }
  23616. records = [{
  23617. type: 'geoJSON',
  23618. source: rawGeoJson,
  23619. specialAreas: rawSpecialAreas
  23620. }];
  23621. }
  23622. each$1(records, function (record) {
  23623. var type = record.type;
  23624. type === 'geoJson' && (type = record.type = 'geoJSON');
  23625. var parse = parsers[type];
  23626. if (__DEV__) {
  23627. assert$1(parse, 'Illegal map type: ' + type);
  23628. }
  23629. parse(record);
  23630. });
  23631. return storage.set(mapName, records);
  23632. },
  23633. retrieveMap: function (mapName) {
  23634. return storage.get(mapName);
  23635. }
  23636. };
  23637. var parsers = {
  23638. geoJSON: function (record) {
  23639. var source = record.source;
  23640. record.geoJSON = !isString(source)
  23641. ? source
  23642. : (typeof JSON !== 'undefined' && JSON.parse)
  23643. ? JSON.parse(source)
  23644. : (new Function('return (' + source + ');'))();
  23645. },
  23646. // Only perform parse to XML object here, which might be time
  23647. // consiming for large SVG.
  23648. // Although convert XML to zrender element is also time consiming,
  23649. // if we do it here, the clone of zrender elements has to be
  23650. // required. So we do it once for each geo instance, util real
  23651. // performance issues call for optimizing it.
  23652. svg: function (record) {
  23653. record.svgXML = parseXML(record.source);
  23654. }
  23655. };
  23656. /*
  23657. * Licensed to the Apache Software Foundation (ASF) under one
  23658. * or more contributor license agreements. See the NOTICE file
  23659. * distributed with this work for additional information
  23660. * regarding copyright ownership. The ASF licenses this file
  23661. * to you under the Apache License, Version 2.0 (the
  23662. * "License"); you may not use this file except in compliance
  23663. * with the License. You may obtain a copy of the License at
  23664. *
  23665. * http://www.apache.org/licenses/LICENSE-2.0
  23666. *
  23667. * Unless required by applicable law or agreed to in writing,
  23668. * software distributed under the License is distributed on an
  23669. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23670. * KIND, either express or implied. See the License for the
  23671. * specific language governing permissions and limitations
  23672. * under the License.
  23673. */
  23674. var assert = assert$1;
  23675. var each = each$1;
  23676. var isFunction = isFunction$1;
  23677. var isObject = isObject$1;
  23678. var parseClassType = ComponentModel.parseClassType;
  23679. var version = '4.9.0';
  23680. var dependencies = {
  23681. zrender: '4.3.2'
  23682. };
  23683. var TEST_FRAME_REMAIN_TIME = 1;
  23684. var PRIORITY_PROCESSOR_FILTER = 1000;
  23685. var PRIORITY_PROCESSOR_SERIES_FILTER = 800;
  23686. var PRIORITY_PROCESSOR_DATASTACK = 900;
  23687. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  23688. var PRIORITY_VISUAL_LAYOUT = 1000;
  23689. var PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;
  23690. var PRIORITY_VISUAL_GLOBAL = 2000;
  23691. var PRIORITY_VISUAL_CHART = 3000;
  23692. var PRIORITY_VISUAL_POST_CHART_LAYOUT = 3500;
  23693. var PRIORITY_VISUAL_COMPONENT = 4000;
  23694. // FIXME
  23695. // necessary?
  23696. var PRIORITY_VISUAL_BRUSH = 5000;
  23697. var PRIORITY = {
  23698. PROCESSOR: {
  23699. FILTER: PRIORITY_PROCESSOR_FILTER,
  23700. SERIES_FILTER: PRIORITY_PROCESSOR_SERIES_FILTER,
  23701. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  23702. },
  23703. VISUAL: {
  23704. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  23705. PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,
  23706. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  23707. CHART: PRIORITY_VISUAL_CHART,
  23708. POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,
  23709. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  23710. BRUSH: PRIORITY_VISUAL_BRUSH
  23711. }
  23712. };
  23713. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  23714. // where they must not be invoked nestedly, except the only case: invoke
  23715. // dispatchAction with updateMethod "none" in main process.
  23716. // This flag is used to carry out this rule.
  23717. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  23718. var IN_MAIN_PROCESS = '__flagInMainProcess';
  23719. var OPTION_UPDATED = '__optionUpdated';
  23720. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  23721. function createRegisterEventWithLowercaseName(method, ignoreDisposed) {
  23722. return function (eventName, handler, context) {
  23723. if (!ignoreDisposed && this._disposed) {
  23724. disposedWarning(this.id);
  23725. return;
  23726. }
  23727. // Event name is all lowercase
  23728. eventName = eventName && eventName.toLowerCase();
  23729. Eventful.prototype[method].call(this, eventName, handler, context);
  23730. };
  23731. }
  23732. /**
  23733. * @module echarts~MessageCenter
  23734. */
  23735. function MessageCenter() {
  23736. Eventful.call(this);
  23737. }
  23738. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on', true);
  23739. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off', true);
  23740. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one', true);
  23741. mixin(MessageCenter, Eventful);
  23742. /**
  23743. * @module echarts~ECharts
  23744. */
  23745. function ECharts(dom, theme$$1, opts) {
  23746. opts = opts || {};
  23747. // Get theme by name
  23748. if (typeof theme$$1 === 'string') {
  23749. theme$$1 = themeStorage[theme$$1];
  23750. }
  23751. /**
  23752. * @type {string}
  23753. */
  23754. this.id;
  23755. /**
  23756. * Group id
  23757. * @type {string}
  23758. */
  23759. this.group;
  23760. /**
  23761. * @type {HTMLElement}
  23762. * @private
  23763. */
  23764. this._dom = dom;
  23765. var defaultRenderer = 'canvas';
  23766. if (__DEV__) {
  23767. defaultRenderer = (
  23768. typeof window === 'undefined' ? global : window
  23769. ).__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
  23770. }
  23771. /**
  23772. * @type {module:zrender/ZRender}
  23773. * @private
  23774. */
  23775. var zr = this._zr = init$1(dom, {
  23776. renderer: opts.renderer || defaultRenderer,
  23777. devicePixelRatio: opts.devicePixelRatio,
  23778. width: opts.width,
  23779. height: opts.height
  23780. });
  23781. /**
  23782. * Expect 60 fps.
  23783. * @type {Function}
  23784. * @private
  23785. */
  23786. this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  23787. var theme$$1 = clone(theme$$1);
  23788. theme$$1 && backwardCompat(theme$$1, true);
  23789. /**
  23790. * @type {Object}
  23791. * @private
  23792. */
  23793. this._theme = theme$$1;
  23794. /**
  23795. * @type {Array.<module:echarts/view/Chart>}
  23796. * @private
  23797. */
  23798. this._chartsViews = [];
  23799. /**
  23800. * @type {Object.<string, module:echarts/view/Chart>}
  23801. * @private
  23802. */
  23803. this._chartsMap = {};
  23804. /**
  23805. * @type {Array.<module:echarts/view/Component>}
  23806. * @private
  23807. */
  23808. this._componentsViews = [];
  23809. /**
  23810. * @type {Object.<string, module:echarts/view/Component>}
  23811. * @private
  23812. */
  23813. this._componentsMap = {};
  23814. /**
  23815. * @type {module:echarts/CoordinateSystem}
  23816. * @private
  23817. */
  23818. this._coordSysMgr = new CoordinateSystemManager();
  23819. /**
  23820. * @type {module:echarts/ExtensionAPI}
  23821. * @private
  23822. */
  23823. var api = this._api = createExtensionAPI(this);
  23824. // Sort on demand
  23825. function prioritySortFunc(a, b) {
  23826. return a.__prio - b.__prio;
  23827. }
  23828. sort(visualFuncs, prioritySortFunc);
  23829. sort(dataProcessorFuncs, prioritySortFunc);
  23830. /**
  23831. * @type {module:echarts/stream/Scheduler}
  23832. */
  23833. this._scheduler = new Scheduler(this, api, dataProcessorFuncs, visualFuncs);
  23834. Eventful.call(this, this._ecEventProcessor = new EventProcessor());
  23835. /**
  23836. * @type {module:echarts~MessageCenter}
  23837. * @private
  23838. */
  23839. this._messageCenter = new MessageCenter();
  23840. // Init mouse events
  23841. this._initEvents();
  23842. // In case some people write `window.onresize = chart.resize`
  23843. this.resize = bind(this.resize, this);
  23844. // Can't dispatch action during rendering procedure
  23845. this._pendingActions = [];
  23846. zr.animation.on('frame', this._onframe, this);
  23847. bindRenderedEvent(zr, this);
  23848. // ECharts instance can be used as value.
  23849. setAsPrimitive(this);
  23850. }
  23851. var echartsProto = ECharts.prototype;
  23852. echartsProto._onframe = function () {
  23853. if (this._disposed) {
  23854. return;
  23855. }
  23856. var scheduler = this._scheduler;
  23857. // Lazy update
  23858. if (this[OPTION_UPDATED]) {
  23859. var silent = this[OPTION_UPDATED].silent;
  23860. this[IN_MAIN_PROCESS] = true;
  23861. prepare(this);
  23862. updateMethods.update.call(this);
  23863. this[IN_MAIN_PROCESS] = false;
  23864. this[OPTION_UPDATED] = false;
  23865. flushPendingActions.call(this, silent);
  23866. triggerUpdatedEvent.call(this, silent);
  23867. }
  23868. // Avoid do both lazy update and progress in one frame.
  23869. else if (scheduler.unfinished) {
  23870. // Stream progress.
  23871. var remainTime = TEST_FRAME_REMAIN_TIME;
  23872. var ecModel = this._model;
  23873. var api = this._api;
  23874. scheduler.unfinished = false;
  23875. do {
  23876. var startTime = +new Date();
  23877. scheduler.performSeriesTasks(ecModel);
  23878. // Currently dataProcessorFuncs do not check threshold.
  23879. scheduler.performDataProcessorTasks(ecModel);
  23880. updateStreamModes(this, ecModel);
  23881. // Do not update coordinate system here. Because that coord system update in
  23882. // each frame is not a good user experience. So we follow the rule that
  23883. // the extent of the coordinate system is determin in the first frame (the
  23884. // frame is executed immedietely after task reset.
  23885. // this._coordSysMgr.update(ecModel, api);
  23886. // console.log('--- ec frame visual ---', remainTime);
  23887. scheduler.performVisualTasks(ecModel);
  23888. renderSeries(this, this._model, api, 'remain');
  23889. remainTime -= (+new Date() - startTime);
  23890. }
  23891. while (remainTime > 0 && scheduler.unfinished);
  23892. // Call flush explicitly for trigger finished event.
  23893. if (!scheduler.unfinished) {
  23894. this._zr.flush();
  23895. }
  23896. // Else, zr flushing be ensue within the same frame,
  23897. // because zr flushing is after onframe event.
  23898. }
  23899. };
  23900. /**
  23901. * @return {HTMLElement}
  23902. */
  23903. echartsProto.getDom = function () {
  23904. return this._dom;
  23905. };
  23906. /**
  23907. * @return {module:zrender~ZRender}
  23908. */
  23909. echartsProto.getZr = function () {
  23910. return this._zr;
  23911. };
  23912. /**
  23913. * Usage:
  23914. * chart.setOption(option, notMerge, lazyUpdate);
  23915. * chart.setOption(option, {
  23916. * notMerge: ...,
  23917. * lazyUpdate: ...,
  23918. * silent: ...
  23919. * });
  23920. *
  23921. * @param {Object} option
  23922. * @param {Object|boolean} [opts] opts or notMerge.
  23923. * @param {boolean} [opts.notMerge=false]
  23924. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  23925. */
  23926. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  23927. if (__DEV__) {
  23928. assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  23929. }
  23930. if (this._disposed) {
  23931. disposedWarning(this.id);
  23932. return;
  23933. }
  23934. var silent;
  23935. if (isObject(notMerge)) {
  23936. lazyUpdate = notMerge.lazyUpdate;
  23937. silent = notMerge.silent;
  23938. notMerge = notMerge.notMerge;
  23939. }
  23940. this[IN_MAIN_PROCESS] = true;
  23941. if (!this._model || notMerge) {
  23942. var optionManager = new OptionManager(this._api);
  23943. var theme$$1 = this._theme;
  23944. var ecModel = this._model = new GlobalModel();
  23945. ecModel.scheduler = this._scheduler;
  23946. ecModel.init(null, null, theme$$1, optionManager);
  23947. }
  23948. this._model.setOption(option, optionPreprocessorFuncs);
  23949. if (lazyUpdate) {
  23950. this[OPTION_UPDATED] = {silent: silent};
  23951. this[IN_MAIN_PROCESS] = false;
  23952. }
  23953. else {
  23954. prepare(this);
  23955. updateMethods.update.call(this);
  23956. // Ensure zr refresh sychronously, and then pixel in canvas can be
  23957. // fetched after `setOption`.
  23958. this._zr.flush();
  23959. this[OPTION_UPDATED] = false;
  23960. this[IN_MAIN_PROCESS] = false;
  23961. flushPendingActions.call(this, silent);
  23962. triggerUpdatedEvent.call(this, silent);
  23963. }
  23964. };
  23965. /**
  23966. * @DEPRECATED
  23967. */
  23968. echartsProto.setTheme = function () {
  23969. console.error('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  23970. };
  23971. /**
  23972. * @return {module:echarts/model/Global}
  23973. */
  23974. echartsProto.getModel = function () {
  23975. return this._model;
  23976. };
  23977. /**
  23978. * @return {Object}
  23979. */
  23980. echartsProto.getOption = function () {
  23981. return this._model && this._model.getOption();
  23982. };
  23983. /**
  23984. * @return {number}
  23985. */
  23986. echartsProto.getWidth = function () {
  23987. return this._zr.getWidth();
  23988. };
  23989. /**
  23990. * @return {number}
  23991. */
  23992. echartsProto.getHeight = function () {
  23993. return this._zr.getHeight();
  23994. };
  23995. /**
  23996. * @return {number}
  23997. */
  23998. echartsProto.getDevicePixelRatio = function () {
  23999. return this._zr.painter.dpr || window.devicePixelRatio || 1;
  24000. };
  24001. /**
  24002. * Get canvas which has all thing rendered
  24003. * @param {Object} opts
  24004. * @param {string} [opts.backgroundColor]
  24005. * @return {string}
  24006. */
  24007. echartsProto.getRenderedCanvas = function (opts) {
  24008. if (!env$1.canvasSupported) {
  24009. return;
  24010. }
  24011. opts = opts || {};
  24012. opts.pixelRatio = opts.pixelRatio || 1;
  24013. opts.backgroundColor = opts.backgroundColor
  24014. || this._model.get('backgroundColor');
  24015. var zr = this._zr;
  24016. // var list = zr.storage.getDisplayList();
  24017. // Stop animations
  24018. // Never works before in init animation, so remove it.
  24019. // zrUtil.each(list, function (el) {
  24020. // el.stopAnimation(true);
  24021. // });
  24022. return zr.painter.getRenderedCanvas(opts);
  24023. };
  24024. /**
  24025. * Get svg data url
  24026. * @return {string}
  24027. */
  24028. echartsProto.getSvgDataURL = function () {
  24029. if (!env$1.svgSupported) {
  24030. return;
  24031. }
  24032. var zr = this._zr;
  24033. var list = zr.storage.getDisplayList();
  24034. // Stop animations
  24035. each$1(list, function (el) {
  24036. el.stopAnimation(true);
  24037. });
  24038. return zr.painter.toDataURL();
  24039. };
  24040. /**
  24041. * @return {string}
  24042. * @param {Object} opts
  24043. * @param {string} [opts.type='png']
  24044. * @param {string} [opts.pixelRatio=1]
  24045. * @param {string} [opts.backgroundColor]
  24046. * @param {string} [opts.excludeComponents]
  24047. */
  24048. echartsProto.getDataURL = function (opts) {
  24049. if (this._disposed) {
  24050. disposedWarning(this.id);
  24051. return;
  24052. }
  24053. opts = opts || {};
  24054. var excludeComponents = opts.excludeComponents;
  24055. var ecModel = this._model;
  24056. var excludesComponentViews = [];
  24057. var self = this;
  24058. each(excludeComponents, function (componentType) {
  24059. ecModel.eachComponent({
  24060. mainType: componentType
  24061. }, function (component) {
  24062. var view = self._componentsMap[component.__viewId];
  24063. if (!view.group.ignore) {
  24064. excludesComponentViews.push(view);
  24065. view.group.ignore = true;
  24066. }
  24067. });
  24068. });
  24069. var url = this._zr.painter.getType() === 'svg'
  24070. ? this.getSvgDataURL()
  24071. : this.getRenderedCanvas(opts).toDataURL(
  24072. 'image/' + (opts && opts.type || 'png')
  24073. );
  24074. each(excludesComponentViews, function (view) {
  24075. view.group.ignore = false;
  24076. });
  24077. return url;
  24078. };
  24079. /**
  24080. * @return {string}
  24081. * @param {Object} opts
  24082. * @param {string} [opts.type='png']
  24083. * @param {string} [opts.pixelRatio=1]
  24084. * @param {string} [opts.backgroundColor]
  24085. */
  24086. echartsProto.getConnectedDataURL = function (opts) {
  24087. if (this._disposed) {
  24088. disposedWarning(this.id);
  24089. return;
  24090. }
  24091. if (!env$1.canvasSupported) {
  24092. return;
  24093. }
  24094. var isSvg = opts.type === 'svg';
  24095. var groupId = this.group;
  24096. var mathMin = Math.min;
  24097. var mathMax = Math.max;
  24098. var MAX_NUMBER = Infinity;
  24099. if (connectedGroups[groupId]) {
  24100. var left = MAX_NUMBER;
  24101. var top = MAX_NUMBER;
  24102. var right = -MAX_NUMBER;
  24103. var bottom = -MAX_NUMBER;
  24104. var canvasList = [];
  24105. var dpr = (opts && opts.pixelRatio) || 1;
  24106. each$1(instances, function (chart, id) {
  24107. if (chart.group === groupId) {
  24108. var canvas = isSvg
  24109. ? chart.getZr().painter.getSvgDom().innerHTML
  24110. : chart.getRenderedCanvas(clone(opts));
  24111. var boundingRect = chart.getDom().getBoundingClientRect();
  24112. left = mathMin(boundingRect.left, left);
  24113. top = mathMin(boundingRect.top, top);
  24114. right = mathMax(boundingRect.right, right);
  24115. bottom = mathMax(boundingRect.bottom, bottom);
  24116. canvasList.push({
  24117. dom: canvas,
  24118. left: boundingRect.left,
  24119. top: boundingRect.top
  24120. });
  24121. }
  24122. });
  24123. left *= dpr;
  24124. top *= dpr;
  24125. right *= dpr;
  24126. bottom *= dpr;
  24127. var width = right - left;
  24128. var height = bottom - top;
  24129. var targetCanvas = createCanvas();
  24130. var zr = init$1(targetCanvas, {
  24131. renderer: isSvg ? 'svg' : 'canvas'
  24132. });
  24133. zr.resize({
  24134. width: width,
  24135. height: height
  24136. });
  24137. if (isSvg) {
  24138. var content = '';
  24139. each(canvasList, function (item) {
  24140. var x = item.left - left;
  24141. var y = item.top - top;
  24142. content += '<g transform="translate(' + x + ','
  24143. + y + ')">' + item.dom + '</g>';
  24144. });
  24145. zr.painter.getSvgRoot().innerHTML = content;
  24146. if (opts.connectedBackgroundColor) {
  24147. zr.painter.setBackgroundColor(opts.connectedBackgroundColor);
  24148. }
  24149. zr.refreshImmediately();
  24150. return zr.painter.toDataURL();
  24151. }
  24152. else {
  24153. // Background between the charts
  24154. if (opts.connectedBackgroundColor) {
  24155. zr.add(new Rect({
  24156. shape: {
  24157. x: 0,
  24158. y: 0,
  24159. width: width,
  24160. height: height
  24161. },
  24162. style: {
  24163. fill: opts.connectedBackgroundColor
  24164. }
  24165. }));
  24166. }
  24167. each(canvasList, function (item) {
  24168. var img = new ZImage({
  24169. style: {
  24170. x: item.left * dpr - left,
  24171. y: item.top * dpr - top,
  24172. image: item.dom
  24173. }
  24174. });
  24175. zr.add(img);
  24176. });
  24177. zr.refreshImmediately();
  24178. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  24179. }
  24180. }
  24181. else {
  24182. return this.getDataURL(opts);
  24183. }
  24184. };
  24185. /**
  24186. * Convert from logical coordinate system to pixel coordinate system.
  24187. * See CoordinateSystem#convertToPixel.
  24188. * @param {string|Object} finder
  24189. * If string, e.g., 'geo', means {geoIndex: 0}.
  24190. * If Object, could contain some of these properties below:
  24191. * {
  24192. * seriesIndex / seriesId / seriesName,
  24193. * geoIndex / geoId, geoName,
  24194. * bmapIndex / bmapId / bmapName,
  24195. * xAxisIndex / xAxisId / xAxisName,
  24196. * yAxisIndex / yAxisId / yAxisName,
  24197. * gridIndex / gridId / gridName,
  24198. * ... (can be extended)
  24199. * }
  24200. * @param {Array|number} value
  24201. * @return {Array|number} result
  24202. */
  24203. echartsProto.convertToPixel = curry(doConvertPixel, 'convertToPixel');
  24204. /**
  24205. * Convert from pixel coordinate system to logical coordinate system.
  24206. * See CoordinateSystem#convertFromPixel.
  24207. * @param {string|Object} finder
  24208. * If string, e.g., 'geo', means {geoIndex: 0}.
  24209. * If Object, could contain some of these properties below:
  24210. * {
  24211. * seriesIndex / seriesId / seriesName,
  24212. * geoIndex / geoId / geoName,
  24213. * bmapIndex / bmapId / bmapName,
  24214. * xAxisIndex / xAxisId / xAxisName,
  24215. * yAxisIndex / yAxisId / yAxisName
  24216. * gridIndex / gridId / gridName,
  24217. * ... (can be extended)
  24218. * }
  24219. * @param {Array|number} value
  24220. * @return {Array|number} result
  24221. */
  24222. echartsProto.convertFromPixel = curry(doConvertPixel, 'convertFromPixel');
  24223. function doConvertPixel(methodName, finder, value) {
  24224. if (this._disposed) {
  24225. disposedWarning(this.id);
  24226. return;
  24227. }
  24228. var ecModel = this._model;
  24229. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  24230. var result;
  24231. finder = parseFinder(ecModel, finder);
  24232. for (var i = 0; i < coordSysList.length; i++) {
  24233. var coordSys = coordSysList[i];
  24234. if (coordSys[methodName]
  24235. && (result = coordSys[methodName](ecModel, finder, value)) != null
  24236. ) {
  24237. return result;
  24238. }
  24239. }
  24240. if (__DEV__) {
  24241. console.warn(
  24242. 'No coordinate system that supports ' + methodName + ' found by the given finder.'
  24243. );
  24244. }
  24245. }
  24246. /**
  24247. * Is the specified coordinate systems or components contain the given pixel point.
  24248. * @param {string|Object} finder
  24249. * If string, e.g., 'geo', means {geoIndex: 0}.
  24250. * If Object, could contain some of these properties below:
  24251. * {
  24252. * seriesIndex / seriesId / seriesName,
  24253. * geoIndex / geoId / geoName,
  24254. * bmapIndex / bmapId / bmapName,
  24255. * xAxisIndex / xAxisId / xAxisName,
  24256. * yAxisIndex / yAxisId / yAxisName,
  24257. * gridIndex / gridId / gridName,
  24258. * ... (can be extended)
  24259. * }
  24260. * @param {Array|number} value
  24261. * @return {boolean} result
  24262. */
  24263. echartsProto.containPixel = function (finder, value) {
  24264. if (this._disposed) {
  24265. disposedWarning(this.id);
  24266. return;
  24267. }
  24268. var ecModel = this._model;
  24269. var result;
  24270. finder = parseFinder(ecModel, finder);
  24271. each$1(finder, function (models, key) {
  24272. key.indexOf('Models') >= 0 && each$1(models, function (model) {
  24273. var coordSys = model.coordinateSystem;
  24274. if (coordSys && coordSys.containPoint) {
  24275. result |= !!coordSys.containPoint(value);
  24276. }
  24277. else if (key === 'seriesModels') {
  24278. var view = this._chartsMap[model.__viewId];
  24279. if (view && view.containPoint) {
  24280. result |= view.containPoint(value, model);
  24281. }
  24282. else {
  24283. if (__DEV__) {
  24284. console.warn(key + ': ' + (view
  24285. ? 'The found component do not support containPoint.'
  24286. : 'No view mapping to the found component.'
  24287. ));
  24288. }
  24289. }
  24290. }
  24291. else {
  24292. if (__DEV__) {
  24293. console.warn(key + ': containPoint is not supported');
  24294. }
  24295. }
  24296. }, this);
  24297. }, this);
  24298. return !!result;
  24299. };
  24300. /**
  24301. * Get visual from series or data.
  24302. * @param {string|Object} finder
  24303. * If string, e.g., 'series', means {seriesIndex: 0}.
  24304. * If Object, could contain some of these properties below:
  24305. * {
  24306. * seriesIndex / seriesId / seriesName,
  24307. * dataIndex / dataIndexInside
  24308. * }
  24309. * If dataIndex is not specified, series visual will be fetched,
  24310. * but not data item visual.
  24311. * If all of seriesIndex, seriesId, seriesName are not specified,
  24312. * visual will be fetched from first series.
  24313. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  24314. */
  24315. echartsProto.getVisual = function (finder, visualType) {
  24316. var ecModel = this._model;
  24317. finder = parseFinder(ecModel, finder, {defaultMainType: 'series'});
  24318. var seriesModel = finder.seriesModel;
  24319. if (__DEV__) {
  24320. if (!seriesModel) {
  24321. console.warn('There is no specified seires model');
  24322. }
  24323. }
  24324. var data = seriesModel.getData();
  24325. var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
  24326. ? finder.dataIndexInside
  24327. : finder.hasOwnProperty('dataIndex')
  24328. ? data.indexOfRawIndex(finder.dataIndex)
  24329. : null;
  24330. return dataIndexInside != null
  24331. ? data.getItemVisual(dataIndexInside, visualType)
  24332. : data.getVisual(visualType);
  24333. };
  24334. /**
  24335. * Get view of corresponding component model
  24336. * @param {module:echarts/model/Component} componentModel
  24337. * @return {module:echarts/view/Component}
  24338. */
  24339. echartsProto.getViewOfComponentModel = function (componentModel) {
  24340. return this._componentsMap[componentModel.__viewId];
  24341. };
  24342. /**
  24343. * Get view of corresponding series model
  24344. * @param {module:echarts/model/Series} seriesModel
  24345. * @return {module:echarts/view/Chart}
  24346. */
  24347. echartsProto.getViewOfSeriesModel = function (seriesModel) {
  24348. return this._chartsMap[seriesModel.__viewId];
  24349. };
  24350. var updateMethods = {
  24351. prepareAndUpdate: function (payload) {
  24352. prepare(this);
  24353. updateMethods.update.call(this, payload);
  24354. },
  24355. /**
  24356. * @param {Object} payload
  24357. * @private
  24358. */
  24359. update: function (payload) {
  24360. // console.profile && console.profile('update');
  24361. var ecModel = this._model;
  24362. var api = this._api;
  24363. var zr = this._zr;
  24364. var coordSysMgr = this._coordSysMgr;
  24365. var scheduler = this._scheduler;
  24366. // update before setOption
  24367. if (!ecModel) {
  24368. return;
  24369. }
  24370. scheduler.restoreData(ecModel, payload);
  24371. scheduler.performSeriesTasks(ecModel);
  24372. // TODO
  24373. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  24374. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  24375. // Create new coordinate system each update
  24376. // In LineView may save the old coordinate system and use it to get the orignal point
  24377. coordSysMgr.create(ecModel, api);
  24378. scheduler.performDataProcessorTasks(ecModel, payload);
  24379. // Current stream render is not supported in data process. So we can update
  24380. // stream modes after data processing, where the filtered data is used to
  24381. // deteming whether use progressive rendering.
  24382. updateStreamModes(this, ecModel);
  24383. // We update stream modes before coordinate system updated, then the modes info
  24384. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  24385. // the drawback is the full coord info can not be fetched. Fortunately this full
  24386. // coord is not requied in stream mode updater currently.
  24387. coordSysMgr.update(ecModel, api);
  24388. clearColorPalette(ecModel);
  24389. scheduler.performVisualTasks(ecModel, payload);
  24390. render(this, ecModel, api, payload);
  24391. // Set background
  24392. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  24393. // In IE8
  24394. if (!env$1.canvasSupported) {
  24395. var colorArr = parse(backgroundColor);
  24396. backgroundColor = stringify(colorArr, 'rgb');
  24397. if (colorArr[3] === 0) {
  24398. backgroundColor = 'transparent';
  24399. }
  24400. }
  24401. else {
  24402. zr.setBackgroundColor(backgroundColor);
  24403. }
  24404. performPostUpdateFuncs(ecModel, api);
  24405. // console.profile && console.profileEnd('update');
  24406. },
  24407. /**
  24408. * @param {Object} payload
  24409. * @private
  24410. */
  24411. updateTransform: function (payload) {
  24412. var ecModel = this._model;
  24413. var ecIns = this;
  24414. var api = this._api;
  24415. // update before setOption
  24416. if (!ecModel) {
  24417. return;
  24418. }
  24419. // ChartView.markUpdateMethod(payload, 'updateTransform');
  24420. var componentDirtyList = [];
  24421. ecModel.eachComponent(function (componentType, componentModel) {
  24422. var componentView = ecIns.getViewOfComponentModel(componentModel);
  24423. if (componentView && componentView.__alive) {
  24424. if (componentView.updateTransform) {
  24425. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  24426. result && result.update && componentDirtyList.push(componentView);
  24427. }
  24428. else {
  24429. componentDirtyList.push(componentView);
  24430. }
  24431. }
  24432. });
  24433. var seriesDirtyMap = createHashMap();
  24434. ecModel.eachSeries(function (seriesModel) {
  24435. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  24436. if (chartView.updateTransform) {
  24437. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  24438. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  24439. }
  24440. else {
  24441. seriesDirtyMap.set(seriesModel.uid, 1);
  24442. }
  24443. });
  24444. clearColorPalette(ecModel);
  24445. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24446. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  24447. this._scheduler.performVisualTasks(
  24448. ecModel, payload, {setDirty: true, dirtyMap: seriesDirtyMap}
  24449. );
  24450. // Currently, not call render of components. Geo render cost a lot.
  24451. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  24452. renderSeries(ecIns, ecModel, api, payload, seriesDirtyMap);
  24453. performPostUpdateFuncs(ecModel, this._api);
  24454. },
  24455. /**
  24456. * @param {Object} payload
  24457. * @private
  24458. */
  24459. updateView: function (payload) {
  24460. var ecModel = this._model;
  24461. // update before setOption
  24462. if (!ecModel) {
  24463. return;
  24464. }
  24465. Chart.markUpdateMethod(payload, 'updateView');
  24466. clearColorPalette(ecModel);
  24467. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24468. this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  24469. render(this, this._model, this._api, payload);
  24470. performPostUpdateFuncs(ecModel, this._api);
  24471. },
  24472. /**
  24473. * @param {Object} payload
  24474. * @private
  24475. */
  24476. updateVisual: function (payload) {
  24477. updateMethods.update.call(this, payload);
  24478. // var ecModel = this._model;
  24479. // // update before setOption
  24480. // if (!ecModel) {
  24481. // return;
  24482. // }
  24483. // ChartView.markUpdateMethod(payload, 'updateVisual');
  24484. // clearColorPalette(ecModel);
  24485. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24486. // this._scheduler.performVisualTasks(ecModel, payload, {visualType: 'visual', setDirty: true});
  24487. // render(this, this._model, this._api, payload);
  24488. // performPostUpdateFuncs(ecModel, this._api);
  24489. },
  24490. /**
  24491. * @param {Object} payload
  24492. * @private
  24493. */
  24494. updateLayout: function (payload) {
  24495. updateMethods.update.call(this, payload);
  24496. // var ecModel = this._model;
  24497. // // update before setOption
  24498. // if (!ecModel) {
  24499. // return;
  24500. // }
  24501. // ChartView.markUpdateMethod(payload, 'updateLayout');
  24502. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24503. // // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  24504. // this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  24505. // render(this, this._model, this._api, payload);
  24506. // performPostUpdateFuncs(ecModel, this._api);
  24507. }
  24508. };
  24509. function prepare(ecIns) {
  24510. var ecModel = ecIns._model;
  24511. var scheduler = ecIns._scheduler;
  24512. scheduler.restorePipelines(ecModel);
  24513. scheduler.prepareStageTasks();
  24514. prepareView(ecIns, 'component', ecModel, scheduler);
  24515. prepareView(ecIns, 'chart', ecModel, scheduler);
  24516. scheduler.plan();
  24517. }
  24518. /**
  24519. * @private
  24520. */
  24521. function updateDirectly(ecIns, method, payload, mainType, subType) {
  24522. var ecModel = ecIns._model;
  24523. // broadcast
  24524. if (!mainType) {
  24525. // FIXME
  24526. // Chart will not be update directly here, except set dirty.
  24527. // But there is no such scenario now.
  24528. each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
  24529. return;
  24530. }
  24531. var query = {};
  24532. query[mainType + 'Id'] = payload[mainType + 'Id'];
  24533. query[mainType + 'Index'] = payload[mainType + 'Index'];
  24534. query[mainType + 'Name'] = payload[mainType + 'Name'];
  24535. var condition = {mainType: mainType, query: query};
  24536. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  24537. var excludeSeriesId = payload.excludeSeriesId;
  24538. if (excludeSeriesId != null) {
  24539. excludeSeriesId = createHashMap(normalizeToArray(excludeSeriesId));
  24540. }
  24541. // If dispatchAction before setOption, do nothing.
  24542. ecModel && ecModel.eachComponent(condition, function (model) {
  24543. if (!excludeSeriesId || excludeSeriesId.get(model.id) == null) {
  24544. callView(ecIns[
  24545. mainType === 'series' ? '_chartsMap' : '_componentsMap'
  24546. ][model.__viewId]);
  24547. }
  24548. }, ecIns);
  24549. function callView(view) {
  24550. view && view.__alive && view[method] && view[method](
  24551. view.__model, ecModel, ecIns._api, payload
  24552. );
  24553. }
  24554. }
  24555. /**
  24556. * Resize the chart
  24557. * @param {Object} opts
  24558. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  24559. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  24560. * @param {boolean} [opts.silent=false]
  24561. */
  24562. echartsProto.resize = function (opts) {
  24563. if (__DEV__) {
  24564. assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  24565. }
  24566. if (this._disposed) {
  24567. disposedWarning(this.id);
  24568. return;
  24569. }
  24570. this._zr.resize(opts);
  24571. var ecModel = this._model;
  24572. // Resize loading effect
  24573. this._loadingFX && this._loadingFX.resize();
  24574. if (!ecModel) {
  24575. return;
  24576. }
  24577. var optionChanged = ecModel.resetOption('media');
  24578. var silent = opts && opts.silent;
  24579. this[IN_MAIN_PROCESS] = true;
  24580. optionChanged && prepare(this);
  24581. updateMethods.update.call(this);
  24582. this[IN_MAIN_PROCESS] = false;
  24583. flushPendingActions.call(this, silent);
  24584. triggerUpdatedEvent.call(this, silent);
  24585. };
  24586. function updateStreamModes(ecIns, ecModel) {
  24587. var chartsMap = ecIns._chartsMap;
  24588. var scheduler = ecIns._scheduler;
  24589. ecModel.eachSeries(function (seriesModel) {
  24590. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  24591. });
  24592. }
  24593. /**
  24594. * Show loading effect
  24595. * @param {string} [name='default']
  24596. * @param {Object} [cfg]
  24597. */
  24598. echartsProto.showLoading = function (name, cfg) {
  24599. if (this._disposed) {
  24600. disposedWarning(this.id);
  24601. return;
  24602. }
  24603. if (isObject(name)) {
  24604. cfg = name;
  24605. name = '';
  24606. }
  24607. name = name || 'default';
  24608. this.hideLoading();
  24609. if (!loadingEffects[name]) {
  24610. if (__DEV__) {
  24611. console.warn('Loading effects ' + name + ' not exists.');
  24612. }
  24613. return;
  24614. }
  24615. var el = loadingEffects[name](this._api, cfg);
  24616. var zr = this._zr;
  24617. this._loadingFX = el;
  24618. zr.add(el);
  24619. };
  24620. /**
  24621. * Hide loading effect
  24622. */
  24623. echartsProto.hideLoading = function () {
  24624. if (this._disposed) {
  24625. disposedWarning(this.id);
  24626. return;
  24627. }
  24628. this._loadingFX && this._zr.remove(this._loadingFX);
  24629. this._loadingFX = null;
  24630. };
  24631. /**
  24632. * @param {Object} eventObj
  24633. * @return {Object}
  24634. */
  24635. echartsProto.makeActionFromEvent = function (eventObj) {
  24636. var payload = extend({}, eventObj);
  24637. payload.type = eventActionMap[eventObj.type];
  24638. return payload;
  24639. };
  24640. /**
  24641. * @pubilc
  24642. * @param {Object} payload
  24643. * @param {string} [payload.type] Action type
  24644. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  24645. * @param {boolean} [opt.silent=false] Whether trigger events.
  24646. * @param {boolean} [opt.flush=undefined]
  24647. * true: Flush immediately, and then pixel in canvas can be fetched
  24648. * immediately. Caution: it might affect performance.
  24649. * false: Not flush.
  24650. * undefined: Auto decide whether perform flush.
  24651. */
  24652. echartsProto.dispatchAction = function (payload, opt) {
  24653. if (this._disposed) {
  24654. disposedWarning(this.id);
  24655. return;
  24656. }
  24657. if (!isObject(opt)) {
  24658. opt = {silent: !!opt};
  24659. }
  24660. if (!actions[payload.type]) {
  24661. return;
  24662. }
  24663. // Avoid dispatch action before setOption. Especially in `connect`.
  24664. if (!this._model) {
  24665. return;
  24666. }
  24667. // May dispatchAction in rendering procedure
  24668. if (this[IN_MAIN_PROCESS]) {
  24669. this._pendingActions.push(payload);
  24670. return;
  24671. }
  24672. doDispatchAction.call(this, payload, opt.silent);
  24673. if (opt.flush) {
  24674. this._zr.flush(true);
  24675. }
  24676. else if (opt.flush !== false && env$1.browser.weChat) {
  24677. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  24678. // hang when sliding page (on touch event), which cause that zr does not
  24679. // refresh util user interaction finished, which is not expected.
  24680. // But `dispatchAction` may be called too frequently when pan on touch
  24681. // screen, which impacts performance if do not throttle them.
  24682. this._throttledZrFlush();
  24683. }
  24684. flushPendingActions.call(this, opt.silent);
  24685. triggerUpdatedEvent.call(this, opt.silent);
  24686. };
  24687. function doDispatchAction(payload, silent) {
  24688. var payloadType = payload.type;
  24689. var escapeConnect = payload.escapeConnect;
  24690. var actionWrap = actions[payloadType];
  24691. var actionInfo = actionWrap.actionInfo;
  24692. var cptType = (actionInfo.update || 'update').split(':');
  24693. var updateMethod = cptType.pop();
  24694. cptType = cptType[0] != null && parseClassType(cptType[0]);
  24695. this[IN_MAIN_PROCESS] = true;
  24696. var payloads = [payload];
  24697. var batched = false;
  24698. // Batch action
  24699. if (payload.batch) {
  24700. batched = true;
  24701. payloads = map(payload.batch, function (item) {
  24702. item = defaults(extend({}, item), payload);
  24703. item.batch = null;
  24704. return item;
  24705. });
  24706. }
  24707. var eventObjBatch = [];
  24708. var eventObj;
  24709. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  24710. each(payloads, function (batchItem) {
  24711. // Action can specify the event by return it.
  24712. eventObj = actionWrap.action(batchItem, this._model, this._api);
  24713. // Emit event outside
  24714. eventObj = eventObj || extend({}, batchItem);
  24715. // Convert type to eventType
  24716. eventObj.type = actionInfo.event || eventObj.type;
  24717. eventObjBatch.push(eventObj);
  24718. // light update does not perform data process, layout and visual.
  24719. if (isHighDown) {
  24720. // method, payload, mainType, subType
  24721. updateDirectly(this, updateMethod, batchItem, 'series');
  24722. }
  24723. else if (cptType) {
  24724. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  24725. }
  24726. }, this);
  24727. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  24728. // Still dirty
  24729. if (this[OPTION_UPDATED]) {
  24730. // FIXME Pass payload ?
  24731. prepare(this);
  24732. updateMethods.update.call(this, payload);
  24733. this[OPTION_UPDATED] = false;
  24734. }
  24735. else {
  24736. updateMethods[updateMethod].call(this, payload);
  24737. }
  24738. }
  24739. // Follow the rule of action batch
  24740. if (batched) {
  24741. eventObj = {
  24742. type: actionInfo.event || payloadType,
  24743. escapeConnect: escapeConnect,
  24744. batch: eventObjBatch
  24745. };
  24746. }
  24747. else {
  24748. eventObj = eventObjBatch[0];
  24749. }
  24750. this[IN_MAIN_PROCESS] = false;
  24751. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  24752. }
  24753. function flushPendingActions(silent) {
  24754. var pendingActions = this._pendingActions;
  24755. while (pendingActions.length) {
  24756. var payload = pendingActions.shift();
  24757. doDispatchAction.call(this, payload, silent);
  24758. }
  24759. }
  24760. function triggerUpdatedEvent(silent) {
  24761. !silent && this.trigger('updated');
  24762. }
  24763. /**
  24764. * Event `rendered` is triggered when zr
  24765. * rendered. It is useful for realtime
  24766. * snapshot (reflect animation).
  24767. *
  24768. * Event `finished` is triggered when:
  24769. * (1) zrender rendering finished.
  24770. * (2) initial animation finished.
  24771. * (3) progressive rendering finished.
  24772. * (4) no pending action.
  24773. * (5) no delayed setOption needs to be processed.
  24774. */
  24775. function bindRenderedEvent(zr, ecIns) {
  24776. zr.on('rendered', function () {
  24777. ecIns.trigger('rendered');
  24778. // The `finished` event should not be triggered repeatly,
  24779. // so it should only be triggered when rendering indeed happend
  24780. // in zrender. (Consider the case that dipatchAction is keep
  24781. // triggering when mouse move).
  24782. if (
  24783. // Although zr is dirty if initial animation is not finished
  24784. // and this checking is called on frame, we also check
  24785. // animation finished for robustness.
  24786. zr.animation.isFinished()
  24787. && !ecIns[OPTION_UPDATED]
  24788. && !ecIns._scheduler.unfinished
  24789. && !ecIns._pendingActions.length
  24790. ) {
  24791. ecIns.trigger('finished');
  24792. }
  24793. });
  24794. }
  24795. /**
  24796. * @param {Object} params
  24797. * @param {number} params.seriesIndex
  24798. * @param {Array|TypedArray} params.data
  24799. */
  24800. echartsProto.appendData = function (params) {
  24801. if (this._disposed) {
  24802. disposedWarning(this.id);
  24803. return;
  24804. }
  24805. var seriesIndex = params.seriesIndex;
  24806. var ecModel = this.getModel();
  24807. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  24808. if (__DEV__) {
  24809. assert(params.data && seriesModel);
  24810. }
  24811. seriesModel.appendData(params);
  24812. // Note: `appendData` does not support that update extent of coordinate
  24813. // system, util some scenario require that. In the expected usage of
  24814. // `appendData`, the initial extent of coordinate system should better
  24815. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  24816. // the extent changed while `appendData`, the location of the painted
  24817. // graphic elements have to be changed, which make the usage of
  24818. // `appendData` meaningless.
  24819. this._scheduler.unfinished = true;
  24820. };
  24821. /**
  24822. * Register event
  24823. * @method
  24824. */
  24825. echartsProto.on = createRegisterEventWithLowercaseName('on', false);
  24826. echartsProto.off = createRegisterEventWithLowercaseName('off', false);
  24827. echartsProto.one = createRegisterEventWithLowercaseName('one', false);
  24828. /**
  24829. * Prepare view instances of charts and components
  24830. * @param {module:echarts/model/Global} ecModel
  24831. * @private
  24832. */
  24833. function prepareView(ecIns, type, ecModel, scheduler) {
  24834. var isComponent = type === 'component';
  24835. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  24836. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  24837. var zr = ecIns._zr;
  24838. var api = ecIns._api;
  24839. for (var i = 0; i < viewList.length; i++) {
  24840. viewList[i].__alive = false;
  24841. }
  24842. isComponent
  24843. ? ecModel.eachComponent(function (componentType, model) {
  24844. componentType !== 'series' && doPrepare(model);
  24845. })
  24846. : ecModel.eachSeries(doPrepare);
  24847. function doPrepare(model) {
  24848. // Consider: id same and type changed.
  24849. var viewId = '_ec_' + model.id + '_' + model.type;
  24850. var view = viewMap[viewId];
  24851. if (!view) {
  24852. var classType = parseClassType(model.type);
  24853. var Clazz = isComponent
  24854. ? Component.getClass(classType.main, classType.sub)
  24855. : Chart.getClass(classType.sub);
  24856. if (__DEV__) {
  24857. assert(Clazz, classType.sub + ' does not exist.');
  24858. }
  24859. view = new Clazz();
  24860. view.init(ecModel, api);
  24861. viewMap[viewId] = view;
  24862. viewList.push(view);
  24863. zr.add(view.group);
  24864. }
  24865. model.__viewId = view.__id = viewId;
  24866. view.__alive = true;
  24867. view.__model = model;
  24868. view.group.__ecComponentInfo = {
  24869. mainType: model.mainType,
  24870. index: model.componentIndex
  24871. };
  24872. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  24873. }
  24874. for (var i = 0; i < viewList.length;) {
  24875. var view = viewList[i];
  24876. if (!view.__alive) {
  24877. !isComponent && view.renderTask.dispose();
  24878. zr.remove(view.group);
  24879. view.dispose(ecModel, api);
  24880. viewList.splice(i, 1);
  24881. delete viewMap[view.__id];
  24882. view.__id = view.group.__ecComponentInfo = null;
  24883. }
  24884. else {
  24885. i++;
  24886. }
  24887. }
  24888. }
  24889. // /**
  24890. // * Encode visual infomation from data after data processing
  24891. // *
  24892. // * @param {module:echarts/model/Global} ecModel
  24893. // * @param {object} layout
  24894. // * @param {boolean} [layoutFilter] `true`: only layout,
  24895. // * `false`: only not layout,
  24896. // * `null`/`undefined`: all.
  24897. // * @param {string} taskBaseTag
  24898. // * @private
  24899. // */
  24900. // function startVisualEncoding(ecIns, ecModel, api, payload, layoutFilter) {
  24901. // each(visualFuncs, function (visual, index) {
  24902. // var isLayout = visual.isLayout;
  24903. // if (layoutFilter == null
  24904. // || (layoutFilter === false && !isLayout)
  24905. // || (layoutFilter === true && isLayout)
  24906. // ) {
  24907. // visual.func(ecModel, api, payload);
  24908. // }
  24909. // });
  24910. // }
  24911. function clearColorPalette(ecModel) {
  24912. ecModel.clearColorPalette();
  24913. ecModel.eachSeries(function (seriesModel) {
  24914. seriesModel.clearColorPalette();
  24915. });
  24916. }
  24917. function render(ecIns, ecModel, api, payload) {
  24918. renderComponents(ecIns, ecModel, api, payload);
  24919. each(ecIns._chartsViews, function (chart) {
  24920. chart.__alive = false;
  24921. });
  24922. renderSeries(ecIns, ecModel, api, payload);
  24923. // Remove groups of unrendered charts
  24924. each(ecIns._chartsViews, function (chart) {
  24925. if (!chart.__alive) {
  24926. chart.remove(ecModel, api);
  24927. }
  24928. });
  24929. }
  24930. function renderComponents(ecIns, ecModel, api, payload, dirtyList) {
  24931. each(dirtyList || ecIns._componentsViews, function (componentView) {
  24932. var componentModel = componentView.__model;
  24933. componentView.render(componentModel, ecModel, api, payload);
  24934. updateZ(componentModel, componentView);
  24935. });
  24936. }
  24937. /**
  24938. * Render each chart and component
  24939. * @private
  24940. */
  24941. function renderSeries(ecIns, ecModel, api, payload, dirtyMap) {
  24942. // Render all charts
  24943. var scheduler = ecIns._scheduler;
  24944. var unfinished;
  24945. ecModel.eachSeries(function (seriesModel) {
  24946. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  24947. chartView.__alive = true;
  24948. var renderTask = chartView.renderTask;
  24949. scheduler.updatePayload(renderTask, payload);
  24950. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  24951. renderTask.dirty();
  24952. }
  24953. unfinished |= renderTask.perform(scheduler.getPerformArgs(renderTask));
  24954. chartView.group.silent = !!seriesModel.get('silent');
  24955. updateZ(seriesModel, chartView);
  24956. updateBlend(seriesModel, chartView);
  24957. });
  24958. scheduler.unfinished |= unfinished;
  24959. // If use hover layer
  24960. updateHoverLayerStatus(ecIns, ecModel);
  24961. // Add aria
  24962. aria(ecIns._zr.dom, ecModel);
  24963. }
  24964. function performPostUpdateFuncs(ecModel, api) {
  24965. each(postUpdateFuncs, function (func) {
  24966. func(ecModel, api);
  24967. });
  24968. }
  24969. var MOUSE_EVENT_NAMES = [
  24970. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
  24971. 'mousedown', 'mouseup', 'globalout', 'contextmenu'
  24972. ];
  24973. /**
  24974. * @private
  24975. */
  24976. echartsProto._initEvents = function () {
  24977. each(MOUSE_EVENT_NAMES, function (eveName) {
  24978. var handler = function (e) {
  24979. var ecModel = this.getModel();
  24980. var el = e.target;
  24981. var params;
  24982. var isGlobalOut = eveName === 'globalout';
  24983. // no e.target when 'globalout'.
  24984. if (isGlobalOut) {
  24985. params = {};
  24986. }
  24987. else if (el && el.dataIndex != null) {
  24988. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  24989. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType, el) || {};
  24990. }
  24991. // If element has custom eventData of components
  24992. else if (el && el.eventData) {
  24993. params = extend({}, el.eventData);
  24994. }
  24995. // Contract: if params prepared in mouse event,
  24996. // these properties must be specified:
  24997. // {
  24998. // componentType: string (component main type)
  24999. // componentIndex: number
  25000. // }
  25001. // Otherwise event query can not work.
  25002. if (params) {
  25003. var componentType = params.componentType;
  25004. var componentIndex = params.componentIndex;
  25005. // Special handling for historic reason: when trigger by
  25006. // markLine/markPoint/markArea, the componentType is
  25007. // 'markLine'/'markPoint'/'markArea', but we should better
  25008. // enable them to be queried by seriesIndex, since their
  25009. // option is set in each series.
  25010. if (componentType === 'markLine'
  25011. || componentType === 'markPoint'
  25012. || componentType === 'markArea'
  25013. ) {
  25014. componentType = 'series';
  25015. componentIndex = params.seriesIndex;
  25016. }
  25017. var model = componentType && componentIndex != null
  25018. && ecModel.getComponent(componentType, componentIndex);
  25019. var view = model && this[
  25020. model.mainType === 'series' ? '_chartsMap' : '_componentsMap'
  25021. ][model.__viewId];
  25022. if (__DEV__) {
  25023. // `event.componentType` and `event[componentTpype + 'Index']` must not
  25024. // be missed, otherwise there is no way to distinguish source component.
  25025. // See `dataFormat.getDataParams`.
  25026. if (!isGlobalOut && !(model && view)) {
  25027. console.warn('model or view can not be found by params');
  25028. }
  25029. }
  25030. params.event = e;
  25031. params.type = eveName;
  25032. this._ecEventProcessor.eventInfo = {
  25033. targetEl: el,
  25034. packedEvent: params,
  25035. model: model,
  25036. view: view
  25037. };
  25038. this.trigger(eveName, params);
  25039. }
  25040. };
  25041. // Consider that some component (like tooltip, brush, ...)
  25042. // register zr event handler, but user event handler might
  25043. // do anything, such as call `setOption` or `dispatchAction`,
  25044. // which probably update any of the content and probably
  25045. // cause problem if it is called previous other inner handlers.
  25046. handler.zrEventfulCallAtLast = true;
  25047. this._zr.on(eveName, handler, this);
  25048. }, this);
  25049. each(eventActionMap, function (actionType, eventType) {
  25050. this._messageCenter.on(eventType, function (event) {
  25051. this.trigger(eventType, event);
  25052. }, this);
  25053. }, this);
  25054. };
  25055. /**
  25056. * @return {boolean}
  25057. */
  25058. echartsProto.isDisposed = function () {
  25059. return this._disposed;
  25060. };
  25061. /**
  25062. * Clear
  25063. */
  25064. echartsProto.clear = function () {
  25065. if (this._disposed) {
  25066. disposedWarning(this.id);
  25067. return;
  25068. }
  25069. this.setOption({ series: [] }, true);
  25070. };
  25071. /**
  25072. * Dispose instance
  25073. */
  25074. echartsProto.dispose = function () {
  25075. if (this._disposed) {
  25076. disposedWarning(this.id);
  25077. return;
  25078. }
  25079. this._disposed = true;
  25080. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  25081. var api = this._api;
  25082. var ecModel = this._model;
  25083. each(this._componentsViews, function (component) {
  25084. component.dispose(ecModel, api);
  25085. });
  25086. each(this._chartsViews, function (chart) {
  25087. chart.dispose(ecModel, api);
  25088. });
  25089. // Dispose after all views disposed
  25090. this._zr.dispose();
  25091. delete instances[this.id];
  25092. };
  25093. mixin(ECharts, Eventful);
  25094. function disposedWarning(id) {
  25095. if (__DEV__) {
  25096. console.warn('Instance ' + id + ' has been disposed');
  25097. }
  25098. }
  25099. function updateHoverLayerStatus(ecIns, ecModel) {
  25100. var zr = ecIns._zr;
  25101. var storage = zr.storage;
  25102. var elCount = 0;
  25103. storage.traverse(function (el) {
  25104. elCount++;
  25105. });
  25106. if (elCount > ecModel.get('hoverLayerThreshold') && !env$1.node) {
  25107. ecModel.eachSeries(function (seriesModel) {
  25108. if (seriesModel.preventUsingHoverLayer) {
  25109. return;
  25110. }
  25111. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  25112. if (chartView.__alive) {
  25113. chartView.group.traverse(function (el) {
  25114. // Don't switch back.
  25115. el.useHoverLayer = true;
  25116. });
  25117. }
  25118. });
  25119. }
  25120. }
  25121. /**
  25122. * Update chart progressive and blend.
  25123. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  25124. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  25125. */
  25126. function updateBlend(seriesModel, chartView) {
  25127. var blendMode = seriesModel.get('blendMode') || null;
  25128. if (__DEV__) {
  25129. if (!env$1.canvasSupported && blendMode && blendMode !== 'source-over') {
  25130. console.warn('Only canvas support blendMode');
  25131. }
  25132. }
  25133. chartView.group.traverse(function (el) {
  25134. // FIXME marker and other components
  25135. if (!el.isGroup) {
  25136. // Only set if blendMode is changed. In case element is incremental and don't wan't to rerender.
  25137. if (el.style.blend !== blendMode) {
  25138. el.setStyle('blend', blendMode);
  25139. }
  25140. }
  25141. if (el.eachPendingDisplayable) {
  25142. el.eachPendingDisplayable(function (displayable) {
  25143. displayable.setStyle('blend', blendMode);
  25144. });
  25145. }
  25146. });
  25147. }
  25148. /**
  25149. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  25150. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  25151. */
  25152. function updateZ(model, view) {
  25153. var z = model.get('z');
  25154. var zlevel = model.get('zlevel');
  25155. // Set z and zlevel
  25156. view.group.traverse(function (el) {
  25157. if (el.type !== 'group') {
  25158. z != null && (el.z = z);
  25159. zlevel != null && (el.zlevel = zlevel);
  25160. }
  25161. });
  25162. }
  25163. function createExtensionAPI(ecInstance) {
  25164. var coordSysMgr = ecInstance._coordSysMgr;
  25165. return extend(new ExtensionAPI(ecInstance), {
  25166. // Inject methods
  25167. getCoordinateSystems: bind(
  25168. coordSysMgr.getCoordinateSystems, coordSysMgr
  25169. ),
  25170. getComponentByElement: function (el) {
  25171. while (el) {
  25172. var modelInfo = el.__ecComponentInfo;
  25173. if (modelInfo != null) {
  25174. return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
  25175. }
  25176. el = el.parent;
  25177. }
  25178. }
  25179. });
  25180. }
  25181. /**
  25182. * @class
  25183. * Usage of query:
  25184. * `chart.on('click', query, handler);`
  25185. * The `query` can be:
  25186. * + The component type query string, only `mainType` or `mainType.subType`,
  25187. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  25188. * + The component query object, like:
  25189. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  25190. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  25191. * + The data query object, like:
  25192. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  25193. * + The other query object (cmponent customized query), like:
  25194. * `{element: 'some'}` (only available in custom series).
  25195. *
  25196. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  25197. * same as there is no such prop in the `query` object.
  25198. */
  25199. function EventProcessor() {
  25200. // These info required: targetEl, packedEvent, model, view
  25201. this.eventInfo;
  25202. }
  25203. EventProcessor.prototype = {
  25204. constructor: EventProcessor,
  25205. normalizeQuery: function (query) {
  25206. var cptQuery = {};
  25207. var dataQuery = {};
  25208. var otherQuery = {};
  25209. // `query` is `mainType` or `mainType.subType` of component.
  25210. if (isString(query)) {
  25211. var condCptType = parseClassType(query);
  25212. // `.main` and `.sub` may be ''.
  25213. cptQuery.mainType = condCptType.main || null;
  25214. cptQuery.subType = condCptType.sub || null;
  25215. }
  25216. // `query` is an object, convert to {mainType, index, name, id}.
  25217. else {
  25218. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  25219. // can not be used in `compomentModel.filterForExposedEvent`.
  25220. var suffixes = ['Index', 'Name', 'Id'];
  25221. var dataKeys = {name: 1, dataIndex: 1, dataType: 1};
  25222. each$1(query, function (val, key) {
  25223. var reserved = false;
  25224. for (var i = 0; i < suffixes.length; i++) {
  25225. var propSuffix = suffixes[i];
  25226. var suffixPos = key.lastIndexOf(propSuffix);
  25227. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  25228. var mainType = key.slice(0, suffixPos);
  25229. // Consider `dataIndex`.
  25230. if (mainType !== 'data') {
  25231. cptQuery.mainType = mainType;
  25232. cptQuery[propSuffix.toLowerCase()] = val;
  25233. reserved = true;
  25234. }
  25235. }
  25236. }
  25237. if (dataKeys.hasOwnProperty(key)) {
  25238. dataQuery[key] = val;
  25239. reserved = true;
  25240. }
  25241. if (!reserved) {
  25242. otherQuery[key] = val;
  25243. }
  25244. });
  25245. }
  25246. return {
  25247. cptQuery: cptQuery,
  25248. dataQuery: dataQuery,
  25249. otherQuery: otherQuery
  25250. };
  25251. },
  25252. filter: function (eventType, query, args) {
  25253. // They should be assigned before each trigger call.
  25254. var eventInfo = this.eventInfo;
  25255. if (!eventInfo) {
  25256. return true;
  25257. }
  25258. var targetEl = eventInfo.targetEl;
  25259. var packedEvent = eventInfo.packedEvent;
  25260. var model = eventInfo.model;
  25261. var view = eventInfo.view;
  25262. // For event like 'globalout'.
  25263. if (!model || !view) {
  25264. return true;
  25265. }
  25266. var cptQuery = query.cptQuery;
  25267. var dataQuery = query.dataQuery;
  25268. return check(cptQuery, model, 'mainType')
  25269. && check(cptQuery, model, 'subType')
  25270. && check(cptQuery, model, 'index', 'componentIndex')
  25271. && check(cptQuery, model, 'name')
  25272. && check(cptQuery, model, 'id')
  25273. && check(dataQuery, packedEvent, 'name')
  25274. && check(dataQuery, packedEvent, 'dataIndex')
  25275. && check(dataQuery, packedEvent, 'dataType')
  25276. && (!view.filterForExposedEvent || view.filterForExposedEvent(
  25277. eventType, query.otherQuery, targetEl, packedEvent
  25278. ));
  25279. function check(query, host, prop, propOnHost) {
  25280. return query[prop] == null || host[propOnHost || prop] === query[prop];
  25281. }
  25282. },
  25283. afterTrigger: function () {
  25284. // Make sure the eventInfo wont be used in next trigger.
  25285. this.eventInfo = null;
  25286. }
  25287. };
  25288. /**
  25289. * @type {Object} key: actionType.
  25290. * @inner
  25291. */
  25292. var actions = {};
  25293. /**
  25294. * Map eventType to actionType
  25295. * @type {Object}
  25296. */
  25297. var eventActionMap = {};
  25298. /**
  25299. * Data processor functions of each stage
  25300. * @type {Array.<Object.<string, Function>>}
  25301. * @inner
  25302. */
  25303. var dataProcessorFuncs = [];
  25304. /**
  25305. * @type {Array.<Function>}
  25306. * @inner
  25307. */
  25308. var optionPreprocessorFuncs = [];
  25309. /**
  25310. * @type {Array.<Function>}
  25311. * @inner
  25312. */
  25313. var postUpdateFuncs = [];
  25314. /**
  25315. * Visual encoding functions of each stage
  25316. * @type {Array.<Object.<string, Function>>}
  25317. */
  25318. var visualFuncs = [];
  25319. /**
  25320. * Theme storage
  25321. * @type {Object.<key, Object>}
  25322. */
  25323. var themeStorage = {};
  25324. /**
  25325. * Loading effects
  25326. */
  25327. var loadingEffects = {};
  25328. var instances = {};
  25329. var connectedGroups = {};
  25330. var idBase = new Date() - 0;
  25331. var groupIdBase = new Date() - 0;
  25332. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  25333. function enableConnect(chart) {
  25334. var STATUS_PENDING = 0;
  25335. var STATUS_UPDATING = 1;
  25336. var STATUS_UPDATED = 2;
  25337. var STATUS_KEY = '__connectUpdateStatus';
  25338. function updateConnectedChartsStatus(charts, status) {
  25339. for (var i = 0; i < charts.length; i++) {
  25340. var otherChart = charts[i];
  25341. otherChart[STATUS_KEY] = status;
  25342. }
  25343. }
  25344. each(eventActionMap, function (actionType, eventType) {
  25345. chart._messageCenter.on(eventType, function (event) {
  25346. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  25347. if (event && event.escapeConnect) {
  25348. return;
  25349. }
  25350. var action = chart.makeActionFromEvent(event);
  25351. var otherCharts = [];
  25352. each(instances, function (otherChart) {
  25353. if (otherChart !== chart && otherChart.group === chart.group) {
  25354. otherCharts.push(otherChart);
  25355. }
  25356. });
  25357. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  25358. each(otherCharts, function (otherChart) {
  25359. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  25360. otherChart.dispatchAction(action);
  25361. }
  25362. });
  25363. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  25364. }
  25365. });
  25366. });
  25367. }
  25368. /**
  25369. * @param {HTMLElement} dom
  25370. * @param {Object} [theme]
  25371. * @param {Object} opts
  25372. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  25373. * @param {string} [opts.renderer] Can choose 'canvas' or 'svg' to render the chart.
  25374. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  25375. * Can be 'auto' (the same as null/undefined)
  25376. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  25377. * Can be 'auto' (the same as null/undefined)
  25378. */
  25379. function init(dom, theme$$1, opts) {
  25380. if (__DEV__) {
  25381. // Check version
  25382. if ((version$1.replace('.', '') - 0) < (dependencies.zrender.replace('.', '') - 0)) {
  25383. throw new Error(
  25384. 'zrender/src ' + version$1
  25385. + ' is too old for ECharts ' + version
  25386. + '. Current version need ZRender '
  25387. + dependencies.zrender + '+'
  25388. );
  25389. }
  25390. if (!dom) {
  25391. throw new Error('Initialize failed: invalid dom.');
  25392. }
  25393. }
  25394. var existInstance = getInstanceByDom(dom);
  25395. if (existInstance) {
  25396. if (__DEV__) {
  25397. console.warn('There is a chart instance already initialized on the dom.');
  25398. }
  25399. return existInstance;
  25400. }
  25401. if (__DEV__) {
  25402. if (isDom(dom)
  25403. && dom.nodeName.toUpperCase() !== 'CANVAS'
  25404. && (
  25405. (!dom.clientWidth && (!opts || opts.width == null))
  25406. || (!dom.clientHeight && (!opts || opts.height == null))
  25407. )
  25408. ) {
  25409. console.warn('Can\'t get DOM width or height. Please check '
  25410. + 'dom.clientWidth and dom.clientHeight. They should not be 0.'
  25411. + 'For example, you may need to call this in the callback '
  25412. + 'of window.onload.');
  25413. }
  25414. }
  25415. var chart = new ECharts(dom, theme$$1, opts);
  25416. chart.id = 'ec_' + idBase++;
  25417. instances[chart.id] = chart;
  25418. setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  25419. enableConnect(chart);
  25420. return chart;
  25421. }
  25422. /**
  25423. * @return {string|Array.<module:echarts~ECharts>} groupId
  25424. */
  25425. function connect(groupId) {
  25426. // Is array of charts
  25427. if (isArray(groupId)) {
  25428. var charts = groupId;
  25429. groupId = null;
  25430. // If any chart has group
  25431. each(charts, function (chart) {
  25432. if (chart.group != null) {
  25433. groupId = chart.group;
  25434. }
  25435. });
  25436. groupId = groupId || ('g_' + groupIdBase++);
  25437. each(charts, function (chart) {
  25438. chart.group = groupId;
  25439. });
  25440. }
  25441. connectedGroups[groupId] = true;
  25442. return groupId;
  25443. }
  25444. /**
  25445. * @DEPRECATED
  25446. * @return {string} groupId
  25447. */
  25448. function disConnect(groupId) {
  25449. connectedGroups[groupId] = false;
  25450. }
  25451. /**
  25452. * @return {string} groupId
  25453. */
  25454. var disconnect = disConnect;
  25455. /**
  25456. * Dispose a chart instance
  25457. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  25458. */
  25459. function dispose(chart) {
  25460. if (typeof chart === 'string') {
  25461. chart = instances[chart];
  25462. }
  25463. else if (!(chart instanceof ECharts)) {
  25464. // Try to treat as dom
  25465. chart = getInstanceByDom(chart);
  25466. }
  25467. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  25468. chart.dispose();
  25469. }
  25470. }
  25471. /**
  25472. * @param {HTMLElement} dom
  25473. * @return {echarts~ECharts}
  25474. */
  25475. function getInstanceByDom(dom) {
  25476. return instances[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  25477. }
  25478. /**
  25479. * @param {string} key
  25480. * @return {echarts~ECharts}
  25481. */
  25482. function getInstanceById(key) {
  25483. return instances[key];
  25484. }
  25485. /**
  25486. * Register theme
  25487. */
  25488. function registerTheme(name, theme$$1) {
  25489. themeStorage[name] = theme$$1;
  25490. }
  25491. /**
  25492. * Register option preprocessor
  25493. * @param {Function} preprocessorFunc
  25494. */
  25495. function registerPreprocessor(preprocessorFunc) {
  25496. optionPreprocessorFuncs.push(preprocessorFunc);
  25497. }
  25498. /**
  25499. * @param {number} [priority=1000]
  25500. * @param {Object|Function} processor
  25501. */
  25502. function registerProcessor(priority, processor) {
  25503. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_FILTER);
  25504. }
  25505. /**
  25506. * Register postUpdater
  25507. * @param {Function} postUpdateFunc
  25508. */
  25509. function registerPostUpdate(postUpdateFunc) {
  25510. postUpdateFuncs.push(postUpdateFunc);
  25511. }
  25512. /**
  25513. * Usage:
  25514. * registerAction('someAction', 'someEvent', function () { ... });
  25515. * registerAction('someAction', function () { ... });
  25516. * registerAction(
  25517. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  25518. * function () { ... }
  25519. * );
  25520. *
  25521. * @param {(string|Object)} actionInfo
  25522. * @param {string} actionInfo.type
  25523. * @param {string} [actionInfo.event]
  25524. * @param {string} [actionInfo.update]
  25525. * @param {string} [eventName]
  25526. * @param {Function} action
  25527. */
  25528. function registerAction(actionInfo, eventName, action) {
  25529. if (typeof eventName === 'function') {
  25530. action = eventName;
  25531. eventName = '';
  25532. }
  25533. var actionType = isObject(actionInfo)
  25534. ? actionInfo.type
  25535. : ([actionInfo, actionInfo = {
  25536. event: eventName
  25537. }][0]);
  25538. // Event name is all lowercase
  25539. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  25540. eventName = actionInfo.event;
  25541. // Validate action type and event name.
  25542. assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  25543. if (!actions[actionType]) {
  25544. actions[actionType] = {action: action, actionInfo: actionInfo};
  25545. }
  25546. eventActionMap[eventName] = actionType;
  25547. }
  25548. /**
  25549. * @param {string} type
  25550. * @param {*} CoordinateSystem
  25551. */
  25552. function registerCoordinateSystem(type, CoordinateSystem$$1) {
  25553. CoordinateSystemManager.register(type, CoordinateSystem$$1);
  25554. }
  25555. /**
  25556. * Get dimensions of specified coordinate system.
  25557. * @param {string} type
  25558. * @return {Array.<string|Object>}
  25559. */
  25560. function getCoordinateSystemDimensions(type) {
  25561. var coordSysCreator = CoordinateSystemManager.get(type);
  25562. if (coordSysCreator) {
  25563. return coordSysCreator.getDimensionsInfo
  25564. ? coordSysCreator.getDimensionsInfo()
  25565. : coordSysCreator.dimensions.slice();
  25566. }
  25567. }
  25568. /**
  25569. * Layout is a special stage of visual encoding
  25570. * Most visual encoding like color are common for different chart
  25571. * But each chart has it's own layout algorithm
  25572. *
  25573. * @param {number} [priority=1000]
  25574. * @param {Function} layoutTask
  25575. */
  25576. function registerLayout(priority, layoutTask) {
  25577. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  25578. }
  25579. /**
  25580. * @param {number} [priority=3000]
  25581. * @param {module:echarts/stream/Task} visualTask
  25582. */
  25583. function registerVisual(priority, visualTask) {
  25584. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  25585. }
  25586. /**
  25587. * @param {Object|Function} fn: {seriesType, createOnAllSeries, performRawSeries, reset}
  25588. */
  25589. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  25590. if (isFunction(priority) || isObject(priority)) {
  25591. fn = priority;
  25592. priority = defaultPriority;
  25593. }
  25594. if (__DEV__) {
  25595. if (isNaN(priority) || priority == null) {
  25596. throw new Error('Illegal priority');
  25597. }
  25598. // Check duplicate
  25599. each(targetList, function (wrap) {
  25600. assert(wrap.__raw !== fn);
  25601. });
  25602. }
  25603. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  25604. stageHandler.__prio = priority;
  25605. stageHandler.__raw = fn;
  25606. targetList.push(stageHandler);
  25607. return stageHandler;
  25608. }
  25609. /**
  25610. * @param {string} name
  25611. */
  25612. function registerLoading(name, loadingFx) {
  25613. loadingEffects[name] = loadingFx;
  25614. }
  25615. /**
  25616. * @param {Object} opts
  25617. * @param {string} [superClass]
  25618. */
  25619. function extendComponentModel(opts/*, superClass*/) {
  25620. // var Clazz = ComponentModel;
  25621. // if (superClass) {
  25622. // var classType = parseClassType(superClass);
  25623. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  25624. // }
  25625. return ComponentModel.extend(opts);
  25626. }
  25627. /**
  25628. * @param {Object} opts
  25629. * @param {string} [superClass]
  25630. */
  25631. function extendComponentView(opts/*, superClass*/) {
  25632. // var Clazz = ComponentView;
  25633. // if (superClass) {
  25634. // var classType = parseClassType(superClass);
  25635. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  25636. // }
  25637. return Component.extend(opts);
  25638. }
  25639. /**
  25640. * @param {Object} opts
  25641. * @param {string} [superClass]
  25642. */
  25643. function extendSeriesModel(opts/*, superClass*/) {
  25644. // var Clazz = SeriesModel;
  25645. // if (superClass) {
  25646. // superClass = 'series.' + superClass.replace('series.', '');
  25647. // var classType = parseClassType(superClass);
  25648. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  25649. // }
  25650. return SeriesModel.extend(opts);
  25651. }
  25652. /**
  25653. * @param {Object} opts
  25654. * @param {string} [superClass]
  25655. */
  25656. function extendChartView(opts/*, superClass*/) {
  25657. // var Clazz = ChartView;
  25658. // if (superClass) {
  25659. // superClass = superClass.replace('series.', '');
  25660. // var classType = parseClassType(superClass);
  25661. // Clazz = ChartView.getClass(classType.main, true);
  25662. // }
  25663. return Chart.extend(opts);
  25664. }
  25665. /**
  25666. * ZRender need a canvas context to do measureText.
  25667. * But in node environment canvas may be created by node-canvas.
  25668. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  25669. *
  25670. * Be careful of using it in the browser.
  25671. *
  25672. * @param {Function} creator
  25673. * @example
  25674. * var Canvas = require('canvas');
  25675. * var echarts = require('echarts');
  25676. * echarts.setCanvasCreator(function () {
  25677. * // Small size is enough.
  25678. * return new Canvas(32, 32);
  25679. * });
  25680. */
  25681. function setCanvasCreator(creator) {
  25682. $override('createCanvas', creator);
  25683. }
  25684. /**
  25685. * @param {string} mapName
  25686. * @param {Array.<Object>|Object|string} geoJson
  25687. * @param {Object} [specialAreas]
  25688. *
  25689. * @example GeoJSON
  25690. * $.get('USA.json', function (geoJson) {
  25691. * echarts.registerMap('USA', geoJson);
  25692. * // Or
  25693. * echarts.registerMap('USA', {
  25694. * geoJson: geoJson,
  25695. * specialAreas: {}
  25696. * })
  25697. * });
  25698. *
  25699. * $.get('airport.svg', function (svg) {
  25700. * echarts.registerMap('airport', {
  25701. * svg: svg
  25702. * }
  25703. * });
  25704. *
  25705. * echarts.registerMap('eu', [
  25706. * {svg: eu-topographic.svg},
  25707. * {geoJSON: eu.json}
  25708. * ])
  25709. */
  25710. function registerMap(mapName, geoJson, specialAreas) {
  25711. mapDataStorage.registerMap(mapName, geoJson, specialAreas);
  25712. }
  25713. /**
  25714. * @param {string} mapName
  25715. * @return {Object}
  25716. */
  25717. function getMap(mapName) {
  25718. // For backward compatibility, only return the first one.
  25719. var records = mapDataStorage.retrieveMap(mapName);
  25720. return records && records[0] && {
  25721. geoJson: records[0].geoJSON,
  25722. specialAreas: records[0].specialAreas
  25723. };
  25724. }
  25725. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);
  25726. registerPreprocessor(backwardCompat);
  25727. registerProcessor(PRIORITY_PROCESSOR_DATASTACK, dataStack);
  25728. registerLoading('default', loadingDefault);
  25729. // Default actions
  25730. registerAction({
  25731. type: 'highlight',
  25732. event: 'highlight',
  25733. update: 'highlight'
  25734. }, noop);
  25735. registerAction({
  25736. type: 'downplay',
  25737. event: 'downplay',
  25738. update: 'downplay'
  25739. }, noop);
  25740. // Default theme
  25741. registerTheme('light', lightTheme);
  25742. registerTheme('dark', theme);
  25743. // For backward compatibility, where the namespace `dataTool` will
  25744. // be mounted on `echarts` is the extension `dataTool` is imported.
  25745. var dataTool = {};
  25746. /*
  25747. * Licensed to the Apache Software Foundation (ASF) under one
  25748. * or more contributor license agreements. See the NOTICE file
  25749. * distributed with this work for additional information
  25750. * regarding copyright ownership. The ASF licenses this file
  25751. * to you under the Apache License, Version 2.0 (the
  25752. * "License"); you may not use this file except in compliance
  25753. * with the License. You may obtain a copy of the License at
  25754. *
  25755. * http://www.apache.org/licenses/LICENSE-2.0
  25756. *
  25757. * Unless required by applicable law or agreed to in writing,
  25758. * software distributed under the License is distributed on an
  25759. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25760. * KIND, either express or implied. See the License for the
  25761. * specific language governing permissions and limitations
  25762. * under the License.
  25763. */
  25764. function defaultKeyGetter(item) {
  25765. return item;
  25766. }
  25767. /**
  25768. * @param {Array} oldArr
  25769. * @param {Array} newArr
  25770. * @param {Function} oldKeyGetter
  25771. * @param {Function} newKeyGetter
  25772. * @param {Object} [context] Can be visited by this.context in callback.
  25773. */
  25774. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {
  25775. this._old = oldArr;
  25776. this._new = newArr;
  25777. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  25778. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  25779. this.context = context;
  25780. }
  25781. DataDiffer.prototype = {
  25782. constructor: DataDiffer,
  25783. /**
  25784. * Callback function when add a data
  25785. */
  25786. add: function (func) {
  25787. this._add = func;
  25788. return this;
  25789. },
  25790. /**
  25791. * Callback function when update a data
  25792. */
  25793. update: function (func) {
  25794. this._update = func;
  25795. return this;
  25796. },
  25797. /**
  25798. * Callback function when remove a data
  25799. */
  25800. remove: function (func) {
  25801. this._remove = func;
  25802. return this;
  25803. },
  25804. execute: function () {
  25805. var oldArr = this._old;
  25806. var newArr = this._new;
  25807. var oldDataIndexMap = {};
  25808. var newDataIndexMap = {};
  25809. var oldDataKeyArr = [];
  25810. var newDataKeyArr = [];
  25811. var i;
  25812. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);
  25813. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);
  25814. for (i = 0; i < oldArr.length; i++) {
  25815. var key = oldDataKeyArr[i];
  25816. var idx = newDataIndexMap[key];
  25817. // idx can never be empty array here. see 'set null' logic below.
  25818. if (idx != null) {
  25819. // Consider there is duplicate key (for example, use dataItem.name as key).
  25820. // We should make sure every item in newArr and oldArr can be visited.
  25821. var len = idx.length;
  25822. if (len) {
  25823. len === 1 && (newDataIndexMap[key] = null);
  25824. idx = idx.shift();
  25825. }
  25826. else {
  25827. newDataIndexMap[key] = null;
  25828. }
  25829. this._update && this._update(idx, i);
  25830. }
  25831. else {
  25832. this._remove && this._remove(i);
  25833. }
  25834. }
  25835. for (var i = 0; i < newDataKeyArr.length; i++) {
  25836. var key = newDataKeyArr[i];
  25837. if (newDataIndexMap.hasOwnProperty(key)) {
  25838. var idx = newDataIndexMap[key];
  25839. if (idx == null) {
  25840. continue;
  25841. }
  25842. // idx can never be empty array here. see 'set null' logic above.
  25843. if (!idx.length) {
  25844. this._add && this._add(idx);
  25845. }
  25846. else {
  25847. for (var j = 0, len = idx.length; j < len; j++) {
  25848. this._add && this._add(idx[j]);
  25849. }
  25850. }
  25851. }
  25852. }
  25853. }
  25854. };
  25855. function initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {
  25856. for (var i = 0; i < arr.length; i++) {
  25857. // Add prefix to avoid conflict with Object.prototype.
  25858. var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);
  25859. var existence = map[key];
  25860. if (existence == null) {
  25861. keyArr.push(key);
  25862. map[key] = i;
  25863. }
  25864. else {
  25865. if (!existence.length) {
  25866. map[key] = existence = [existence];
  25867. }
  25868. existence.push(i);
  25869. }
  25870. }
  25871. }
  25872. /*
  25873. * Licensed to the Apache Software Foundation (ASF) under one
  25874. * or more contributor license agreements. See the NOTICE file
  25875. * distributed with this work for additional information
  25876. * regarding copyright ownership. The ASF licenses this file
  25877. * to you under the Apache License, Version 2.0 (the
  25878. * "License"); you may not use this file except in compliance
  25879. * with the License. You may obtain a copy of the License at
  25880. *
  25881. * http://www.apache.org/licenses/LICENSE-2.0
  25882. *
  25883. * Unless required by applicable law or agreed to in writing,
  25884. * software distributed under the License is distributed on an
  25885. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25886. * KIND, either express or implied. See the License for the
  25887. * specific language governing permissions and limitations
  25888. * under the License.
  25889. */
  25890. var OTHER_DIMENSIONS = createHashMap([
  25891. 'tooltip', 'label', 'itemName', 'itemId', 'seriesName'
  25892. ]);
  25893. function summarizeDimensions(data) {
  25894. var summary = {};
  25895. var encode = summary.encode = {};
  25896. var notExtraCoordDimMap = createHashMap();
  25897. var defaultedLabel = [];
  25898. var defaultedTooltip = [];
  25899. // See the comment of `List.js#userOutput`.
  25900. var userOutput = summary.userOutput = {
  25901. dimensionNames: data.dimensions.slice(),
  25902. encode: {}
  25903. };
  25904. each$1(data.dimensions, function (dimName) {
  25905. var dimItem = data.getDimensionInfo(dimName);
  25906. var coordDim = dimItem.coordDim;
  25907. if (coordDim) {
  25908. if (__DEV__) {
  25909. assert$1(OTHER_DIMENSIONS.get(coordDim) == null);
  25910. }
  25911. var coordDimIndex = dimItem.coordDimIndex;
  25912. getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
  25913. if (!dimItem.isExtraCoord) {
  25914. notExtraCoordDimMap.set(coordDim, 1);
  25915. // Use the last coord dim (and label friendly) as default label,
  25916. // because when dataset is used, it is hard to guess which dimension
  25917. // can be value dimension. If both show x, y on label is not look good,
  25918. // and conventionally y axis is focused more.
  25919. if (mayLabelDimType(dimItem.type)) {
  25920. defaultedLabel[0] = dimName;
  25921. }
  25922. // User output encode do not contain generated coords.
  25923. // And it only has index. User can use index to retrieve value from the raw item array.
  25924. getOrCreateEncodeArr(userOutput.encode, coordDim)[coordDimIndex] = dimItem.index;
  25925. }
  25926. if (dimItem.defaultTooltip) {
  25927. defaultedTooltip.push(dimName);
  25928. }
  25929. }
  25930. OTHER_DIMENSIONS.each(function (v, otherDim) {
  25931. var encodeArr = getOrCreateEncodeArr(encode, otherDim);
  25932. var dimIndex = dimItem.otherDims[otherDim];
  25933. if (dimIndex != null && dimIndex !== false) {
  25934. encodeArr[dimIndex] = dimItem.name;
  25935. }
  25936. });
  25937. });
  25938. var dataDimsOnCoord = [];
  25939. var encodeFirstDimNotExtra = {};
  25940. notExtraCoordDimMap.each(function (v, coordDim) {
  25941. var dimArr = encode[coordDim];
  25942. // ??? FIXME extra coord should not be set in dataDimsOnCoord.
  25943. // But should fix the case that radar axes: simplify the logic
  25944. // of `completeDimension`, remove `extraPrefix`.
  25945. encodeFirstDimNotExtra[coordDim] = dimArr[0];
  25946. // Not necessary to remove duplicate, because a data
  25947. // dim canot on more than one coordDim.
  25948. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  25949. });
  25950. summary.dataDimsOnCoord = dataDimsOnCoord;
  25951. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  25952. var encodeLabel = encode.label;
  25953. // FIXME `encode.label` is not recommanded, because formatter can not be set
  25954. // in this way. Use label.formatter instead. May be remove this approach someday.
  25955. if (encodeLabel && encodeLabel.length) {
  25956. defaultedLabel = encodeLabel.slice();
  25957. }
  25958. var encodeTooltip = encode.tooltip;
  25959. if (encodeTooltip && encodeTooltip.length) {
  25960. defaultedTooltip = encodeTooltip.slice();
  25961. }
  25962. else if (!defaultedTooltip.length) {
  25963. defaultedTooltip = defaultedLabel.slice();
  25964. }
  25965. encode.defaultedLabel = defaultedLabel;
  25966. encode.defaultedTooltip = defaultedTooltip;
  25967. return summary;
  25968. }
  25969. function getOrCreateEncodeArr(encode, dim) {
  25970. if (!encode.hasOwnProperty(dim)) {
  25971. encode[dim] = [];
  25972. }
  25973. return encode[dim];
  25974. }
  25975. function getDimensionTypeByAxis(axisType) {
  25976. return axisType === 'category'
  25977. ? 'ordinal'
  25978. : axisType === 'time'
  25979. ? 'time'
  25980. : 'float';
  25981. }
  25982. function mayLabelDimType(dimType) {
  25983. // In most cases, ordinal and time do not suitable for label.
  25984. // Ordinal info can be displayed on axis. Time is too long.
  25985. return !(dimType === 'ordinal' || dimType === 'time');
  25986. }
  25987. // function findTheLastDimMayLabel(data) {
  25988. // // Get last value dim
  25989. // var dimensions = data.dimensions.slice();
  25990. // var valueType;
  25991. // var valueDim;
  25992. // while (dimensions.length && (
  25993. // valueDim = dimensions.pop(),
  25994. // valueType = data.getDimensionInfo(valueDim).type,
  25995. // valueType === 'ordinal' || valueType === 'time'
  25996. // )) {} // jshint ignore:line
  25997. // return valueDim;
  25998. // }
  25999. /*
  26000. * Licensed to the Apache Software Foundation (ASF) under one
  26001. * or more contributor license agreements. See the NOTICE file
  26002. * distributed with this work for additional information
  26003. * regarding copyright ownership. The ASF licenses this file
  26004. * to you under the Apache License, Version 2.0 (the
  26005. * "License"); you may not use this file except in compliance
  26006. * with the License. You may obtain a copy of the License at
  26007. *
  26008. * http://www.apache.org/licenses/LICENSE-2.0
  26009. *
  26010. * Unless required by applicable law or agreed to in writing,
  26011. * software distributed under the License is distributed on an
  26012. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26013. * KIND, either express or implied. See the License for the
  26014. * specific language governing permissions and limitations
  26015. * under the License.
  26016. */
  26017. /**
  26018. * @class
  26019. * @param {Object|DataDimensionInfo} [opt] All of the fields will be shallow copied.
  26020. */
  26021. function DataDimensionInfo(opt) {
  26022. if (opt != null) {
  26023. extend(this, opt);
  26024. }
  26025. /**
  26026. * Dimension name.
  26027. * Mandatory.
  26028. * @type {string}
  26029. */
  26030. // this.name;
  26031. /**
  26032. * The origin name in dimsDef, see source helper.
  26033. * If displayName given, the tooltip will displayed vertically.
  26034. * Optional.
  26035. * @type {string}
  26036. */
  26037. // this.displayName;
  26038. /**
  26039. * Which coordSys dimension this dimension mapped to.
  26040. * A `coordDim` can be a "coordSysDim" that the coordSys required
  26041. * (for example, an item in `coordSysDims` of `model/referHelper#CoordSysInfo`),
  26042. * or an generated "extra coord name" if does not mapped to any "coordSysDim"
  26043. * (That is determined by whether `isExtraCoord` is `true`).
  26044. * Mandatory.
  26045. * @type {string}
  26046. */
  26047. // this.coordDim;
  26048. /**
  26049. * The index of this dimension in `series.encode[coordDim]`.
  26050. * Mandatory.
  26051. * @type {number}
  26052. */
  26053. // this.coordDimIndex;
  26054. /**
  26055. * Dimension type. The enumerable values are the key of
  26056. * `dataCtors` of `data/List`.
  26057. * Optional.
  26058. * @type {string}
  26059. */
  26060. // this.type;
  26061. /**
  26062. * This index of this dimension info in `data/List#_dimensionInfos`.
  26063. * Mandatory after added to `data/List`.
  26064. * @type {number}
  26065. */
  26066. // this.index;
  26067. /**
  26068. * The format of `otherDims` is:
  26069. * ```js
  26070. * {
  26071. * tooltip: number optional,
  26072. * label: number optional,
  26073. * itemName: number optional,
  26074. * seriesName: number optional,
  26075. * }
  26076. * ```
  26077. *
  26078. * A `series.encode` can specified these fields:
  26079. * ```js
  26080. * encode: {
  26081. * // "3, 1, 5" is the index of data dimension.
  26082. * tooltip: [3, 1, 5],
  26083. * label: [0, 3],
  26084. * ...
  26085. * }
  26086. * ```
  26087. * `otherDims` is the parse result of the `series.encode` above, like:
  26088. * ```js
  26089. * // Suppose the index of this data dimension is `3`.
  26090. * this.otherDims = {
  26091. * // `3` is at the index `0` of the `encode.tooltip`
  26092. * tooltip: 0,
  26093. * // `3` is at the index `1` of the `encode.tooltip`
  26094. * label: 1
  26095. * };
  26096. * ```
  26097. *
  26098. * This prop should never be `null`/`undefined` after initialized.
  26099. * @type {Object}
  26100. */
  26101. this.otherDims = {};
  26102. /**
  26103. * Be `true` if this dimension is not mapped to any "coordSysDim" that the
  26104. * "coordSys" required.
  26105. * Mandatory.
  26106. * @type {boolean}
  26107. */
  26108. // this.isExtraCoord;
  26109. /**
  26110. * @type {module:data/OrdinalMeta}
  26111. */
  26112. // this.ordinalMeta;
  26113. /**
  26114. * Whether to create inverted indices.
  26115. * @type {boolean}
  26116. */
  26117. // this.createInvertedIndices;
  26118. }
  26119. /*
  26120. * Licensed to the Apache Software Foundation (ASF) under one
  26121. * or more contributor license agreements. See the NOTICE file
  26122. * distributed with this work for additional information
  26123. * regarding copyright ownership. The ASF licenses this file
  26124. * to you under the Apache License, Version 2.0 (the
  26125. * "License"); you may not use this file except in compliance
  26126. * with the License. You may obtain a copy of the License at
  26127. *
  26128. * http://www.apache.org/licenses/LICENSE-2.0
  26129. *
  26130. * Unless required by applicable law or agreed to in writing,
  26131. * software distributed under the License is distributed on an
  26132. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26133. * KIND, either express or implied. See the License for the
  26134. * specific language governing permissions and limitations
  26135. * under the License.
  26136. */
  26137. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  26138. /**
  26139. * List for data storage
  26140. * @module echarts/data/List
  26141. */
  26142. var isObject$4 = isObject$1;
  26143. var UNDEFINED = 'undefined';
  26144. var INDEX_NOT_FOUND = -1;
  26145. // Use prefix to avoid index to be the same as otherIdList[idx],
  26146. // which will cause weird udpate animation.
  26147. var ID_PREFIX = 'e\0\0';
  26148. var dataCtors = {
  26149. 'float': typeof Float64Array === UNDEFINED
  26150. ? Array : Float64Array,
  26151. 'int': typeof Int32Array === UNDEFINED
  26152. ? Array : Int32Array,
  26153. // Ordinal data type can be string or int
  26154. 'ordinal': Array,
  26155. 'number': Array,
  26156. 'time': Array
  26157. };
  26158. // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  26159. // different from the Ctor of typed array.
  26160. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  26161. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  26162. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  26163. function getIndicesCtor(list) {
  26164. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  26165. return list._rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  26166. }
  26167. function cloneChunk(originalChunk) {
  26168. var Ctor = originalChunk.constructor;
  26169. // Only shallow clone is enough when Array.
  26170. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  26171. }
  26172. var TRANSFERABLE_PROPERTIES = [
  26173. 'hasItemOption', '_nameList', '_idList', '_invertedIndicesMap',
  26174. '_rawData', '_chunkSize', '_chunkCount', '_dimValueGetter',
  26175. '_count', '_rawCount', '_nameDimIdx', '_idDimIdx'
  26176. ];
  26177. var CLONE_PROPERTIES = [
  26178. '_extent', '_approximateExtent', '_rawExtent'
  26179. ];
  26180. function transferProperties(target, source) {
  26181. each$1(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  26182. if (source.hasOwnProperty(propName)) {
  26183. target[propName] = source[propName];
  26184. }
  26185. });
  26186. target.__wrappedMethods = source.__wrappedMethods;
  26187. each$1(CLONE_PROPERTIES, function (propName) {
  26188. target[propName] = clone(source[propName]);
  26189. });
  26190. target._calculationInfo = extend(source._calculationInfo);
  26191. }
  26192. /**
  26193. * @constructor
  26194. * @alias module:echarts/data/List
  26195. *
  26196. * @param {Array.<string|Object|module:data/DataDimensionInfo>} dimensions
  26197. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  26198. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  26199. * @param {module:echarts/model/Model} hostModel
  26200. */
  26201. var List = function (dimensions, hostModel) {
  26202. dimensions = dimensions || ['x', 'y'];
  26203. var dimensionInfos = {};
  26204. var dimensionNames = [];
  26205. var invertedIndicesMap = {};
  26206. for (var i = 0; i < dimensions.length; i++) {
  26207. // Use the original dimensions[i], where other flag props may exists.
  26208. var dimensionInfo = dimensions[i];
  26209. if (isString(dimensionInfo)) {
  26210. dimensionInfo = new DataDimensionInfo({name: dimensionInfo});
  26211. }
  26212. else if (!(dimensionInfo instanceof DataDimensionInfo)) {
  26213. dimensionInfo = new DataDimensionInfo(dimensionInfo);
  26214. }
  26215. var dimensionName = dimensionInfo.name;
  26216. dimensionInfo.type = dimensionInfo.type || 'float';
  26217. if (!dimensionInfo.coordDim) {
  26218. dimensionInfo.coordDim = dimensionName;
  26219. dimensionInfo.coordDimIndex = 0;
  26220. }
  26221. dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  26222. dimensionNames.push(dimensionName);
  26223. dimensionInfos[dimensionName] = dimensionInfo;
  26224. dimensionInfo.index = i;
  26225. if (dimensionInfo.createInvertedIndices) {
  26226. invertedIndicesMap[dimensionName] = [];
  26227. }
  26228. }
  26229. /**
  26230. * @readOnly
  26231. * @type {Array.<string>}
  26232. */
  26233. this.dimensions = dimensionNames;
  26234. /**
  26235. * Infomation of each data dimension, like data type.
  26236. * @type {Object}
  26237. */
  26238. this._dimensionInfos = dimensionInfos;
  26239. /**
  26240. * @type {module:echarts/model/Model}
  26241. */
  26242. this.hostModel = hostModel;
  26243. /**
  26244. * @type {module:echarts/model/Model}
  26245. */
  26246. this.dataType;
  26247. /**
  26248. * Indices stores the indices of data subset after filtered.
  26249. * This data subset will be used in chart.
  26250. * @type {Array.<number>}
  26251. * @readOnly
  26252. */
  26253. this._indices = null;
  26254. this._count = 0;
  26255. this._rawCount = 0;
  26256. /**
  26257. * Data storage
  26258. * @type {Object.<key, Array.<TypedArray|Array>>}
  26259. * @private
  26260. */
  26261. this._storage = {};
  26262. /**
  26263. * @type {Array.<string>}
  26264. */
  26265. this._nameList = [];
  26266. /**
  26267. * @type {Array.<string>}
  26268. */
  26269. this._idList = [];
  26270. /**
  26271. * Models of data option is stored sparse for optimizing memory cost
  26272. * @type {Array.<module:echarts/model/Model>}
  26273. * @private
  26274. */
  26275. this._optionModels = [];
  26276. /**
  26277. * Global visual properties after visual coding
  26278. * @type {Object}
  26279. * @private
  26280. */
  26281. this._visual = {};
  26282. /**
  26283. * Globel layout properties.
  26284. * @type {Object}
  26285. * @private
  26286. */
  26287. this._layout = {};
  26288. /**
  26289. * Item visual properties after visual coding
  26290. * @type {Array.<Object>}
  26291. * @private
  26292. */
  26293. this._itemVisuals = [];
  26294. /**
  26295. * Key: visual type, Value: boolean
  26296. * @type {Object}
  26297. * @readOnly
  26298. */
  26299. this.hasItemVisual = {};
  26300. /**
  26301. * Item layout properties after layout
  26302. * @type {Array.<Object>}
  26303. * @private
  26304. */
  26305. this._itemLayouts = [];
  26306. /**
  26307. * Graphic elemnents
  26308. * @type {Array.<module:zrender/Element>}
  26309. * @private
  26310. */
  26311. this._graphicEls = [];
  26312. /**
  26313. * Max size of each chunk.
  26314. * @type {number}
  26315. * @private
  26316. */
  26317. this._chunkSize = 1e5;
  26318. /**
  26319. * @type {number}
  26320. * @private
  26321. */
  26322. this._chunkCount = 0;
  26323. /**
  26324. * @type {Array.<Array|Object>}
  26325. * @private
  26326. */
  26327. this._rawData;
  26328. /**
  26329. * Raw extent will not be cloned, but only transfered.
  26330. * It will not be calculated util needed.
  26331. * key: dim,
  26332. * value: {end: number, extent: Array.<number>}
  26333. * @type {Object}
  26334. * @private
  26335. */
  26336. this._rawExtent = {};
  26337. /**
  26338. * @type {Object}
  26339. * @private
  26340. */
  26341. this._extent = {};
  26342. /**
  26343. * key: dim
  26344. * value: extent
  26345. * @type {Object}
  26346. * @private
  26347. */
  26348. this._approximateExtent = {};
  26349. /**
  26350. * Cache summary info for fast visit. See "dimensionHelper".
  26351. * @type {Object}
  26352. * @private
  26353. */
  26354. this._dimensionsSummary = summarizeDimensions(this);
  26355. /**
  26356. * @type {Object.<Array|TypedArray>}
  26357. * @private
  26358. */
  26359. this._invertedIndicesMap = invertedIndicesMap;
  26360. /**
  26361. * @type {Object}
  26362. * @private
  26363. */
  26364. this._calculationInfo = {};
  26365. /**
  26366. * User output info of this data.
  26367. * DO NOT use it in other places!
  26368. *
  26369. * When preparing user params for user callbacks, we have
  26370. * to clone these inner data structures to prevent users
  26371. * from modifying them to effect built-in logic. And for
  26372. * performance consideration we make this `userOutput` to
  26373. * avoid clone them too many times.
  26374. *
  26375. * @type {Object}
  26376. * @readOnly
  26377. */
  26378. this.userOutput = this._dimensionsSummary.userOutput;
  26379. };
  26380. var listProto = List.prototype;
  26381. listProto.type = 'list';
  26382. /**
  26383. * If each data item has it's own option
  26384. * @type {boolean}
  26385. */
  26386. listProto.hasItemOption = true;
  26387. /**
  26388. * The meanings of the input parameter `dim`:
  26389. *
  26390. * + If dim is a number (e.g., `1`), it means the index of the dimension.
  26391. * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.
  26392. * + If dim is a number-like string (e.g., `"1"`):
  26393. * + If there is the same concrete dim name defined in `this.dimensions`, it means that concrete name.
  26394. * + If not, it will be converted to a number, which means the index of the dimension.
  26395. * (why? because of the backward compatbility. We have been tolerating number-like string in
  26396. * dimension setting, although now it seems that it is not a good idea.)
  26397. * For example, `visualMap[i].dimension: "1"` is the same meaning as `visualMap[i].dimension: 1`,
  26398. * if no dimension name is defined as `"1"`.
  26399. * + If dim is a not-number-like string, it means the concrete dim name.
  26400. * For example, it can be be default name `"x"`, `"y"`, `"z"`, `"lng"`, `"lat"`, `"angle"`, `"radius"`,
  26401. * or customized in `dimensions` property of option like `"age"`.
  26402. *
  26403. * Get dimension name
  26404. * @param {string|number} dim See above.
  26405. * @return {string} Concrete dim name.
  26406. */
  26407. listProto.getDimension = function (dim) {
  26408. if (typeof dim === 'number'
  26409. // If being a number-like string but not being defined a dimension name.
  26410. || (!isNaN(dim) && !this._dimensionInfos.hasOwnProperty(dim))
  26411. ) {
  26412. dim = this.dimensions[dim];
  26413. }
  26414. return dim;
  26415. };
  26416. /**
  26417. * Get type and calculation info of particular dimension
  26418. * @param {string|number} dim
  26419. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  26420. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  26421. */
  26422. listProto.getDimensionInfo = function (dim) {
  26423. // Do not clone, because there may be categories in dimInfo.
  26424. return this._dimensionInfos[this.getDimension(dim)];
  26425. };
  26426. /**
  26427. * @return {Array.<string>} concrete dimension name list on coord.
  26428. */
  26429. listProto.getDimensionsOnCoord = function () {
  26430. return this._dimensionsSummary.dataDimsOnCoord.slice();
  26431. };
  26432. /**
  26433. * @param {string} coordDim
  26434. * @param {number} [idx] A coordDim may map to more than one data dim.
  26435. * If idx is `true`, return a array of all mapped dims.
  26436. * If idx is not specified, return the first dim not extra.
  26437. * @return {string|Array.<string>} concrete data dim.
  26438. * If idx is number, and not found, return null/undefined.
  26439. * If idx is `true`, and not found, return empty array (always return array).
  26440. */
  26441. listProto.mapDimension = function (coordDim, idx) {
  26442. var dimensionsSummary = this._dimensionsSummary;
  26443. if (idx == null) {
  26444. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  26445. }
  26446. var dims = dimensionsSummary.encode[coordDim];
  26447. return idx === true
  26448. // always return array if idx is `true`
  26449. ? (dims || []).slice()
  26450. : (dims && dims[idx]);
  26451. };
  26452. /**
  26453. * Initialize from data
  26454. * @param {Array.<Object|number|Array>} data source or data or data provider.
  26455. * @param {Array.<string>} [nameLIst] The name of a datum is used on data diff and
  26456. * default label/tooltip.
  26457. * A name can be specified in encode.itemName,
  26458. * or dataItem.name (only for series option data),
  26459. * or provided in nameList from outside.
  26460. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  26461. */
  26462. listProto.initData = function (data, nameList, dimValueGetter) {
  26463. var notProvider = Source.isInstance(data) || isArrayLike(data);
  26464. if (notProvider) {
  26465. data = new DefaultDataProvider(data, this.dimensions.length);
  26466. }
  26467. if (__DEV__) {
  26468. if (!notProvider && (typeof data.getItem !== 'function' || typeof data.count !== 'function')) {
  26469. throw new Error('Inavlid data provider.');
  26470. }
  26471. }
  26472. this._rawData = data;
  26473. // Clear
  26474. this._storage = {};
  26475. this._indices = null;
  26476. this._nameList = nameList || [];
  26477. this._idList = [];
  26478. this._nameRepeatCount = {};
  26479. if (!dimValueGetter) {
  26480. this.hasItemOption = false;
  26481. }
  26482. /**
  26483. * @readOnly
  26484. */
  26485. this.defaultDimValueGetter = defaultDimValueGetters[
  26486. this._rawData.getSource().sourceFormat
  26487. ];
  26488. // Default dim value getter
  26489. this._dimValueGetter = dimValueGetter = dimValueGetter
  26490. || this.defaultDimValueGetter;
  26491. this._dimValueGetterArrayRows = defaultDimValueGetters.arrayRows;
  26492. // Reset raw extent.
  26493. this._rawExtent = {};
  26494. this._initDataFromProvider(0, data.count());
  26495. // If data has no item option.
  26496. if (data.pure) {
  26497. this.hasItemOption = false;
  26498. }
  26499. };
  26500. listProto.getProvider = function () {
  26501. return this._rawData;
  26502. };
  26503. /**
  26504. * Caution: Can be only called on raw data (before `this._indices` created).
  26505. */
  26506. listProto.appendData = function (data) {
  26507. if (__DEV__) {
  26508. assert$1(!this._indices, 'appendData can only be called on raw data.');
  26509. }
  26510. var rawData = this._rawData;
  26511. var start = this.count();
  26512. rawData.appendData(data);
  26513. var end = rawData.count();
  26514. if (!rawData.persistent) {
  26515. end += start;
  26516. }
  26517. this._initDataFromProvider(start, end);
  26518. };
  26519. /**
  26520. * Caution: Can be only called on raw data (before `this._indices` created).
  26521. * This method does not modify `rawData` (`dataProvider`), but only
  26522. * add values to storage.
  26523. *
  26524. * The final count will be increased by `Math.max(values.length, names.length)`.
  26525. *
  26526. * @param {Array.<Array.<*>>} values That is the SourceType: 'arrayRows', like
  26527. * [
  26528. * [12, 33, 44],
  26529. * [NaN, 43, 1],
  26530. * ['-', 'asdf', 0]
  26531. * ]
  26532. * Each item is exaclty cooresponding to a dimension.
  26533. * @param {Array.<string>} [names]
  26534. */
  26535. listProto.appendValues = function (values, names) {
  26536. var chunkSize = this._chunkSize;
  26537. var storage = this._storage;
  26538. var dimensions = this.dimensions;
  26539. var dimLen = dimensions.length;
  26540. var rawExtent = this._rawExtent;
  26541. var start = this.count();
  26542. var end = start + Math.max(values.length, names ? names.length : 0);
  26543. var originalChunkCount = this._chunkCount;
  26544. for (var i = 0; i < dimLen; i++) {
  26545. var dim = dimensions[i];
  26546. if (!rawExtent[dim]) {
  26547. rawExtent[dim] = getInitialExtent();
  26548. }
  26549. if (!storage[dim]) {
  26550. storage[dim] = [];
  26551. }
  26552. prepareChunks(storage, this._dimensionInfos[dim], chunkSize, originalChunkCount, end);
  26553. this._chunkCount = storage[dim].length;
  26554. }
  26555. var emptyDataItem = new Array(dimLen);
  26556. for (var idx = start; idx < end; idx++) {
  26557. var sourceIdx = idx - start;
  26558. var chunkIndex = Math.floor(idx / chunkSize);
  26559. var chunkOffset = idx % chunkSize;
  26560. // Store the data by dimensions
  26561. for (var k = 0; k < dimLen; k++) {
  26562. var dim = dimensions[k];
  26563. var val = this._dimValueGetterArrayRows(
  26564. values[sourceIdx] || emptyDataItem, dim, sourceIdx, k
  26565. );
  26566. storage[dim][chunkIndex][chunkOffset] = val;
  26567. var dimRawExtent = rawExtent[dim];
  26568. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  26569. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  26570. }
  26571. if (names) {
  26572. this._nameList[idx] = names[sourceIdx];
  26573. }
  26574. }
  26575. this._rawCount = this._count = end;
  26576. // Reset data extent
  26577. this._extent = {};
  26578. prepareInvertedIndex(this);
  26579. };
  26580. listProto._initDataFromProvider = function (start, end) {
  26581. // Optimize.
  26582. if (start >= end) {
  26583. return;
  26584. }
  26585. var chunkSize = this._chunkSize;
  26586. var rawData = this._rawData;
  26587. var storage = this._storage;
  26588. var dimensions = this.dimensions;
  26589. var dimLen = dimensions.length;
  26590. var dimensionInfoMap = this._dimensionInfos;
  26591. var nameList = this._nameList;
  26592. var idList = this._idList;
  26593. var rawExtent = this._rawExtent;
  26594. var nameRepeatCount = this._nameRepeatCount = {};
  26595. var nameDimIdx;
  26596. var originalChunkCount = this._chunkCount;
  26597. for (var i = 0; i < dimLen; i++) {
  26598. var dim = dimensions[i];
  26599. if (!rawExtent[dim]) {
  26600. rawExtent[dim] = getInitialExtent();
  26601. }
  26602. var dimInfo = dimensionInfoMap[dim];
  26603. if (dimInfo.otherDims.itemName === 0) {
  26604. nameDimIdx = this._nameDimIdx = i;
  26605. }
  26606. if (dimInfo.otherDims.itemId === 0) {
  26607. this._idDimIdx = i;
  26608. }
  26609. if (!storage[dim]) {
  26610. storage[dim] = [];
  26611. }
  26612. prepareChunks(storage, dimInfo, chunkSize, originalChunkCount, end);
  26613. this._chunkCount = storage[dim].length;
  26614. }
  26615. var dataItem = new Array(dimLen);
  26616. for (var idx = start; idx < end; idx++) {
  26617. // NOTICE: Try not to write things into dataItem
  26618. dataItem = rawData.getItem(idx, dataItem);
  26619. // Each data item is value
  26620. // [1, 2]
  26621. // 2
  26622. // Bar chart, line chart which uses category axis
  26623. // only gives the 'y' value. 'x' value is the indices of category
  26624. // Use a tempValue to normalize the value to be a (x, y) value
  26625. var chunkIndex = Math.floor(idx / chunkSize);
  26626. var chunkOffset = idx % chunkSize;
  26627. // Store the data by dimensions
  26628. for (var k = 0; k < dimLen; k++) {
  26629. var dim = dimensions[k];
  26630. var dimStorage = storage[dim][chunkIndex];
  26631. // PENDING NULL is empty or zero
  26632. var val = this._dimValueGetter(dataItem, dim, idx, k);
  26633. dimStorage[chunkOffset] = val;
  26634. var dimRawExtent = rawExtent[dim];
  26635. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  26636. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  26637. }
  26638. // ??? FIXME not check by pure but sourceFormat?
  26639. // TODO refactor these logic.
  26640. if (!rawData.pure) {
  26641. var name = nameList[idx];
  26642. if (dataItem && name == null) {
  26643. // If dataItem is {name: ...}, it has highest priority.
  26644. // That is appropriate for many common cases.
  26645. if (dataItem.name != null) {
  26646. // There is no other place to persistent dataItem.name,
  26647. // so save it to nameList.
  26648. nameList[idx] = name = dataItem.name;
  26649. }
  26650. else if (nameDimIdx != null) {
  26651. var nameDim = dimensions[nameDimIdx];
  26652. var nameDimChunk = storage[nameDim][chunkIndex];
  26653. if (nameDimChunk) {
  26654. name = nameDimChunk[chunkOffset];
  26655. var ordinalMeta = dimensionInfoMap[nameDim].ordinalMeta;
  26656. if (ordinalMeta && ordinalMeta.categories.length) {
  26657. name = ordinalMeta.categories[name];
  26658. }
  26659. }
  26660. }
  26661. }
  26662. // Try using the id in option
  26663. // id or name is used on dynamical data, mapping old and new items.
  26664. var id = dataItem == null ? null : dataItem.id;
  26665. if (id == null && name != null) {
  26666. // Use name as id and add counter to avoid same name
  26667. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  26668. id = name;
  26669. if (nameRepeatCount[name] > 0) {
  26670. id += '__ec__' + nameRepeatCount[name];
  26671. }
  26672. nameRepeatCount[name]++;
  26673. }
  26674. id != null && (idList[idx] = id);
  26675. }
  26676. }
  26677. if (!rawData.persistent && rawData.clean) {
  26678. // Clean unused data if data source is typed array.
  26679. rawData.clean();
  26680. }
  26681. this._rawCount = this._count = end;
  26682. // Reset data extent
  26683. this._extent = {};
  26684. prepareInvertedIndex(this);
  26685. };
  26686. function prepareChunks(storage, dimInfo, chunkSize, chunkCount, end) {
  26687. var DataCtor = dataCtors[dimInfo.type];
  26688. var lastChunkIndex = chunkCount - 1;
  26689. var dim = dimInfo.name;
  26690. var resizeChunkArray = storage[dim][lastChunkIndex];
  26691. if (resizeChunkArray && resizeChunkArray.length < chunkSize) {
  26692. var newStore = new DataCtor(Math.min(end - lastChunkIndex * chunkSize, chunkSize));
  26693. // The cost of the copy is probably inconsiderable
  26694. // within the initial chunkSize.
  26695. for (var j = 0; j < resizeChunkArray.length; j++) {
  26696. newStore[j] = resizeChunkArray[j];
  26697. }
  26698. storage[dim][lastChunkIndex] = newStore;
  26699. }
  26700. // Create new chunks.
  26701. for (var k = chunkCount * chunkSize; k < end; k += chunkSize) {
  26702. storage[dim].push(new DataCtor(Math.min(end - k, chunkSize)));
  26703. }
  26704. }
  26705. function prepareInvertedIndex(list) {
  26706. var invertedIndicesMap = list._invertedIndicesMap;
  26707. each$1(invertedIndicesMap, function (invertedIndices, dim) {
  26708. var dimInfo = list._dimensionInfos[dim];
  26709. // Currently, only dimensions that has ordinalMeta can create inverted indices.
  26710. var ordinalMeta = dimInfo.ordinalMeta;
  26711. if (ordinalMeta) {
  26712. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array(
  26713. ordinalMeta.categories.length
  26714. );
  26715. // The default value of TypedArray is 0. To avoid miss
  26716. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  26717. for (var i = 0; i < invertedIndices.length; i++) {
  26718. invertedIndices[i] = INDEX_NOT_FOUND;
  26719. }
  26720. for (var i = 0; i < list._count; i++) {
  26721. // Only support the case that all values are distinct.
  26722. invertedIndices[list.get(dim, i)] = i;
  26723. }
  26724. }
  26725. });
  26726. }
  26727. function getRawValueFromStore(list, dimIndex, rawIndex) {
  26728. var val;
  26729. if (dimIndex != null) {
  26730. var chunkSize = list._chunkSize;
  26731. var chunkIndex = Math.floor(rawIndex / chunkSize);
  26732. var chunkOffset = rawIndex % chunkSize;
  26733. var dim = list.dimensions[dimIndex];
  26734. var chunk = list._storage[dim][chunkIndex];
  26735. if (chunk) {
  26736. val = chunk[chunkOffset];
  26737. var ordinalMeta = list._dimensionInfos[dim].ordinalMeta;
  26738. if (ordinalMeta && ordinalMeta.categories.length) {
  26739. val = ordinalMeta.categories[val];
  26740. }
  26741. }
  26742. }
  26743. return val;
  26744. }
  26745. /**
  26746. * @return {number}
  26747. */
  26748. listProto.count = function () {
  26749. return this._count;
  26750. };
  26751. listProto.getIndices = function () {
  26752. var newIndices;
  26753. var indices = this._indices;
  26754. if (indices) {
  26755. var Ctor = indices.constructor;
  26756. var thisCount = this._count;
  26757. // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  26758. if (Ctor === Array) {
  26759. newIndices = new Ctor(thisCount);
  26760. for (var i = 0; i < thisCount; i++) {
  26761. newIndices[i] = indices[i];
  26762. }
  26763. }
  26764. else {
  26765. newIndices = new Ctor(indices.buffer, 0, thisCount);
  26766. }
  26767. }
  26768. else {
  26769. var Ctor = getIndicesCtor(this);
  26770. var newIndices = new Ctor(this.count());
  26771. for (var i = 0; i < newIndices.length; i++) {
  26772. newIndices[i] = i;
  26773. }
  26774. }
  26775. return newIndices;
  26776. };
  26777. /**
  26778. * Get value. Return NaN if idx is out of range.
  26779. * @param {string} dim Dim must be concrete name.
  26780. * @param {number} idx
  26781. * @param {boolean} stack
  26782. * @return {number}
  26783. */
  26784. listProto.get = function (dim, idx /*, stack */) {
  26785. if (!(idx >= 0 && idx < this._count)) {
  26786. return NaN;
  26787. }
  26788. var storage = this._storage;
  26789. if (!storage[dim]) {
  26790. // TODO Warn ?
  26791. return NaN;
  26792. }
  26793. idx = this.getRawIndex(idx);
  26794. var chunkIndex = Math.floor(idx / this._chunkSize);
  26795. var chunkOffset = idx % this._chunkSize;
  26796. var chunkStore = storage[dim][chunkIndex];
  26797. var value = chunkStore[chunkOffset];
  26798. // FIXME ordinal data type is not stackable
  26799. // if (stack) {
  26800. // var dimensionInfo = this._dimensionInfos[dim];
  26801. // if (dimensionInfo && dimensionInfo.stackable) {
  26802. // var stackedOn = this.stackedOn;
  26803. // while (stackedOn) {
  26804. // // Get no stacked data of stacked on
  26805. // var stackedValue = stackedOn.get(dim, idx);
  26806. // // Considering positive stack, negative stack and empty data
  26807. // if ((value >= 0 && stackedValue > 0) // Positive stack
  26808. // || (value <= 0 && stackedValue < 0) // Negative stack
  26809. // ) {
  26810. // value += stackedValue;
  26811. // }
  26812. // stackedOn = stackedOn.stackedOn;
  26813. // }
  26814. // }
  26815. // }
  26816. return value;
  26817. };
  26818. /**
  26819. * @param {string} dim concrete dim
  26820. * @param {number} rawIndex
  26821. * @return {number|string}
  26822. */
  26823. listProto.getByRawIndex = function (dim, rawIdx) {
  26824. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  26825. return NaN;
  26826. }
  26827. var dimStore = this._storage[dim];
  26828. if (!dimStore) {
  26829. // TODO Warn ?
  26830. return NaN;
  26831. }
  26832. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  26833. var chunkOffset = rawIdx % this._chunkSize;
  26834. var chunkStore = dimStore[chunkIndex];
  26835. return chunkStore[chunkOffset];
  26836. };
  26837. /**
  26838. * FIXME Use `get` on chrome maybe slow(in filterSelf and selectRange).
  26839. * Hack a much simpler _getFast
  26840. * @private
  26841. */
  26842. listProto._getFast = function (dim, rawIdx) {
  26843. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  26844. var chunkOffset = rawIdx % this._chunkSize;
  26845. var chunkStore = this._storage[dim][chunkIndex];
  26846. return chunkStore[chunkOffset];
  26847. };
  26848. /**
  26849. * Get value for multi dimensions.
  26850. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  26851. * @param {number} idx
  26852. * @return {number}
  26853. */
  26854. listProto.getValues = function (dimensions, idx /*, stack */) {
  26855. var values = [];
  26856. if (!isArray(dimensions)) {
  26857. // stack = idx;
  26858. idx = dimensions;
  26859. dimensions = this.dimensions;
  26860. }
  26861. for (var i = 0, len = dimensions.length; i < len; i++) {
  26862. values.push(this.get(dimensions[i], idx /*, stack */));
  26863. }
  26864. return values;
  26865. };
  26866. /**
  26867. * If value is NaN. Inlcuding '-'
  26868. * Only check the coord dimensions.
  26869. * @param {string} dim
  26870. * @param {number} idx
  26871. * @return {number}
  26872. */
  26873. listProto.hasValue = function (idx) {
  26874. var dataDimsOnCoord = this._dimensionsSummary.dataDimsOnCoord;
  26875. for (var i = 0, len = dataDimsOnCoord.length; i < len; i++) {
  26876. // Ordinal type originally can be string or number.
  26877. // But when an ordinal type is used on coord, it can
  26878. // not be string but only number. So we can also use isNaN.
  26879. if (isNaN(this.get(dataDimsOnCoord[i], idx))) {
  26880. return false;
  26881. }
  26882. }
  26883. return true;
  26884. };
  26885. /**
  26886. * Get extent of data in one dimension
  26887. * @param {string} dim
  26888. * @param {boolean} stack
  26889. */
  26890. listProto.getDataExtent = function (dim /*, stack */) {
  26891. // Make sure use concrete dim as cache name.
  26892. dim = this.getDimension(dim);
  26893. var dimData = this._storage[dim];
  26894. var initialExtent = getInitialExtent();
  26895. // stack = !!((stack || false) && this.getCalculationInfo(dim));
  26896. if (!dimData) {
  26897. return initialExtent;
  26898. }
  26899. // Make more strict checkings to ensure hitting cache.
  26900. var currEnd = this.count();
  26901. // var cacheName = [dim, !!stack].join('_');
  26902. // var cacheName = dim;
  26903. // Consider the most cases when using data zoom, `getDataExtent`
  26904. // happened before filtering. We cache raw extent, which is not
  26905. // necessary to be cleared and recalculated when restore data.
  26906. var useRaw = !this._indices; // && !stack;
  26907. var dimExtent;
  26908. if (useRaw) {
  26909. return this._rawExtent[dim].slice();
  26910. }
  26911. dimExtent = this._extent[dim];
  26912. if (dimExtent) {
  26913. return dimExtent.slice();
  26914. }
  26915. dimExtent = initialExtent;
  26916. var min = dimExtent[0];
  26917. var max = dimExtent[1];
  26918. for (var i = 0; i < currEnd; i++) {
  26919. // var value = stack ? this.get(dim, i, true) : this._getFast(dim, this.getRawIndex(i));
  26920. var value = this._getFast(dim, this.getRawIndex(i));
  26921. value < min && (min = value);
  26922. value > max && (max = value);
  26923. }
  26924. dimExtent = [min, max];
  26925. this._extent[dim] = dimExtent;
  26926. return dimExtent;
  26927. };
  26928. /**
  26929. * Optimize for the scenario that data is filtered by a given extent.
  26930. * Consider that if data amount is more than hundreds of thousand,
  26931. * extent calculation will cost more than 10ms and the cache will
  26932. * be erased because of the filtering.
  26933. */
  26934. listProto.getApproximateExtent = function (dim /*, stack */) {
  26935. dim = this.getDimension(dim);
  26936. return this._approximateExtent[dim] || this.getDataExtent(dim /*, stack */);
  26937. };
  26938. listProto.setApproximateExtent = function (extent, dim /*, stack */) {
  26939. dim = this.getDimension(dim);
  26940. this._approximateExtent[dim] = extent.slice();
  26941. };
  26942. /**
  26943. * @param {string} key
  26944. * @return {*}
  26945. */
  26946. listProto.getCalculationInfo = function (key) {
  26947. return this._calculationInfo[key];
  26948. };
  26949. /**
  26950. * @param {string|Object} key or k-v object
  26951. * @param {*} [value]
  26952. */
  26953. listProto.setCalculationInfo = function (key, value) {
  26954. isObject$4(key)
  26955. ? extend(this._calculationInfo, key)
  26956. : (this._calculationInfo[key] = value);
  26957. };
  26958. /**
  26959. * Get sum of data in one dimension
  26960. * @param {string} dim
  26961. */
  26962. listProto.getSum = function (dim /*, stack */) {
  26963. var dimData = this._storage[dim];
  26964. var sum = 0;
  26965. if (dimData) {
  26966. for (var i = 0, len = this.count(); i < len; i++) {
  26967. var value = this.get(dim, i /*, stack */);
  26968. if (!isNaN(value)) {
  26969. sum += value;
  26970. }
  26971. }
  26972. }
  26973. return sum;
  26974. };
  26975. /**
  26976. * Get median of data in one dimension
  26977. * @param {string} dim
  26978. */
  26979. listProto.getMedian = function (dim /*, stack */) {
  26980. var dimDataArray = [];
  26981. // map all data of one dimension
  26982. this.each(dim, function (val, idx) {
  26983. if (!isNaN(val)) {
  26984. dimDataArray.push(val);
  26985. }
  26986. });
  26987. // TODO
  26988. // Use quick select?
  26989. // immutability & sort
  26990. var sortedDimDataArray = [].concat(dimDataArray).sort(function (a, b) {
  26991. return a - b;
  26992. });
  26993. var len = this.count();
  26994. // calculate median
  26995. return len === 0
  26996. ? 0
  26997. : len % 2 === 1
  26998. ? sortedDimDataArray[(len - 1) / 2]
  26999. : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  27000. };
  27001. // /**
  27002. // * Retreive the index with given value
  27003. // * @param {string} dim Concrete dimension.
  27004. // * @param {number} value
  27005. // * @return {number}
  27006. // */
  27007. // Currently incorrect: should return dataIndex but not rawIndex.
  27008. // Do not fix it until this method is to be used somewhere.
  27009. // FIXME Precision of float value
  27010. // listProto.indexOf = function (dim, value) {
  27011. // var storage = this._storage;
  27012. // var dimData = storage[dim];
  27013. // var chunkSize = this._chunkSize;
  27014. // if (dimData) {
  27015. // for (var i = 0, len = this.count(); i < len; i++) {
  27016. // var chunkIndex = Math.floor(i / chunkSize);
  27017. // var chunkOffset = i % chunkSize;
  27018. // if (dimData[chunkIndex][chunkOffset] === value) {
  27019. // return i;
  27020. // }
  27021. // }
  27022. // }
  27023. // return -1;
  27024. // };
  27025. /**
  27026. * Only support the dimension which inverted index created.
  27027. * Do not support other cases until required.
  27028. * @param {string} concrete dim
  27029. * @param {number|string} value
  27030. * @return {number} rawIndex
  27031. */
  27032. listProto.rawIndexOf = function (dim, value) {
  27033. var invertedIndices = dim && this._invertedIndicesMap[dim];
  27034. if (__DEV__) {
  27035. if (!invertedIndices) {
  27036. throw new Error('Do not supported yet');
  27037. }
  27038. }
  27039. var rawIndex = invertedIndices[value];
  27040. if (rawIndex == null || isNaN(rawIndex)) {
  27041. return INDEX_NOT_FOUND;
  27042. }
  27043. return rawIndex;
  27044. };
  27045. /**
  27046. * Retreive the index with given name
  27047. * @param {number} idx
  27048. * @param {number} name
  27049. * @return {number}
  27050. */
  27051. listProto.indexOfName = function (name) {
  27052. for (var i = 0, len = this.count(); i < len; i++) {
  27053. if (this.getName(i) === name) {
  27054. return i;
  27055. }
  27056. }
  27057. return -1;
  27058. };
  27059. /**
  27060. * Retreive the index with given raw data index
  27061. * @param {number} idx
  27062. * @param {number} name
  27063. * @return {number}
  27064. */
  27065. listProto.indexOfRawIndex = function (rawIndex) {
  27066. if (rawIndex >= this._rawCount || rawIndex < 0) {
  27067. return -1;
  27068. }
  27069. if (!this._indices) {
  27070. return rawIndex;
  27071. }
  27072. // Indices are ascending
  27073. var indices = this._indices;
  27074. // If rawIndex === dataIndex
  27075. var rawDataIndex = indices[rawIndex];
  27076. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  27077. return rawIndex;
  27078. }
  27079. var left = 0;
  27080. var right = this._count - 1;
  27081. while (left <= right) {
  27082. var mid = (left + right) / 2 | 0;
  27083. if (indices[mid] < rawIndex) {
  27084. left = mid + 1;
  27085. }
  27086. else if (indices[mid] > rawIndex) {
  27087. right = mid - 1;
  27088. }
  27089. else {
  27090. return mid;
  27091. }
  27092. }
  27093. return -1;
  27094. };
  27095. /**
  27096. * Retreive the index of nearest value
  27097. * @param {string} dim
  27098. * @param {number} value
  27099. * @param {number} [maxDistance=Infinity]
  27100. * @return {Array.<number>} If and only if multiple indices has
  27101. * the same value, they are put to the result.
  27102. */
  27103. listProto.indicesOfNearest = function (dim, value, maxDistance) {
  27104. var storage = this._storage;
  27105. var dimData = storage[dim];
  27106. var nearestIndices = [];
  27107. if (!dimData) {
  27108. return nearestIndices;
  27109. }
  27110. if (maxDistance == null) {
  27111. maxDistance = Infinity;
  27112. }
  27113. var minDist = Infinity;
  27114. var minDiff = -1;
  27115. var nearestIndicesLen = 0;
  27116. // Check the test case of `test/ut/spec/data/List.js`.
  27117. for (var i = 0, len = this.count(); i < len; i++) {
  27118. var diff = value - this.get(dim, i);
  27119. var dist = Math.abs(diff);
  27120. if (dist <= maxDistance) {
  27121. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  27122. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  27123. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  27124. // So we chose the one that `diff >= 0` in this csae.
  27125. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  27126. // should be push to `nearestIndices`.
  27127. if (dist < minDist
  27128. || (dist === minDist && diff >= 0 && minDiff < 0)
  27129. ) {
  27130. minDist = dist;
  27131. minDiff = diff;
  27132. nearestIndicesLen = 0;
  27133. }
  27134. if (diff === minDiff) {
  27135. nearestIndices[nearestIndicesLen++] = i;
  27136. }
  27137. }
  27138. }
  27139. nearestIndices.length = nearestIndicesLen;
  27140. return nearestIndices;
  27141. };
  27142. /**
  27143. * Get raw data index
  27144. * @param {number} idx
  27145. * @return {number}
  27146. */
  27147. listProto.getRawIndex = getRawIndexWithoutIndices;
  27148. function getRawIndexWithoutIndices(idx) {
  27149. return idx;
  27150. }
  27151. function getRawIndexWithIndices(idx) {
  27152. if (idx < this._count && idx >= 0) {
  27153. return this._indices[idx];
  27154. }
  27155. return -1;
  27156. }
  27157. /**
  27158. * Get raw data item
  27159. * @param {number} idx
  27160. * @return {number}
  27161. */
  27162. listProto.getRawDataItem = function (idx) {
  27163. if (!this._rawData.persistent) {
  27164. var val = [];
  27165. for (var i = 0; i < this.dimensions.length; i++) {
  27166. var dim = this.dimensions[i];
  27167. val.push(this.get(dim, idx));
  27168. }
  27169. return val;
  27170. }
  27171. else {
  27172. return this._rawData.getItem(this.getRawIndex(idx));
  27173. }
  27174. };
  27175. /**
  27176. * @param {number} idx
  27177. * @param {boolean} [notDefaultIdx=false]
  27178. * @return {string}
  27179. */
  27180. listProto.getName = function (idx) {
  27181. var rawIndex = this.getRawIndex(idx);
  27182. return this._nameList[rawIndex]
  27183. || getRawValueFromStore(this, this._nameDimIdx, rawIndex)
  27184. || '';
  27185. };
  27186. /**
  27187. * @param {number} idx
  27188. * @param {boolean} [notDefaultIdx=false]
  27189. * @return {string}
  27190. */
  27191. listProto.getId = function (idx) {
  27192. return getId(this, this.getRawIndex(idx));
  27193. };
  27194. function getId(list, rawIndex) {
  27195. var id = list._idList[rawIndex];
  27196. if (id == null) {
  27197. id = getRawValueFromStore(list, list._idDimIdx, rawIndex);
  27198. }
  27199. if (id == null) {
  27200. // FIXME Check the usage in graph, should not use prefix.
  27201. id = ID_PREFIX + rawIndex;
  27202. }
  27203. return id;
  27204. }
  27205. function normalizeDimensions(dimensions) {
  27206. if (!isArray(dimensions)) {
  27207. dimensions = [dimensions];
  27208. }
  27209. return dimensions;
  27210. }
  27211. function validateDimensions(list, dims) {
  27212. for (var i = 0; i < dims.length; i++) {
  27213. // stroage may be empty when no data, so use
  27214. // dimensionInfos to check.
  27215. if (!list._dimensionInfos[dims[i]]) {
  27216. console.error('Unkown dimension ' + dims[i]);
  27217. }
  27218. }
  27219. }
  27220. /**
  27221. * Data iteration
  27222. * @param {string|Array.<string>}
  27223. * @param {Function} cb
  27224. * @param {*} [context=this]
  27225. *
  27226. * @example
  27227. * list.each('x', function (x, idx) {});
  27228. * list.each(['x', 'y'], function (x, y, idx) {});
  27229. * list.each(function (idx) {})
  27230. */
  27231. listProto.each = function (dims, cb, context, contextCompat) {
  27232. 'use strict';
  27233. if (!this._count) {
  27234. return;
  27235. }
  27236. if (typeof dims === 'function') {
  27237. contextCompat = context;
  27238. context = cb;
  27239. cb = dims;
  27240. dims = [];
  27241. }
  27242. // contextCompat just for compat echarts3
  27243. context = context || contextCompat || this;
  27244. dims = map(normalizeDimensions(dims), this.getDimension, this);
  27245. if (__DEV__) {
  27246. validateDimensions(this, dims);
  27247. }
  27248. var dimSize = dims.length;
  27249. for (var i = 0; i < this.count(); i++) {
  27250. // Simple optimization
  27251. switch (dimSize) {
  27252. case 0:
  27253. cb.call(context, i);
  27254. break;
  27255. case 1:
  27256. cb.call(context, this.get(dims[0], i), i);
  27257. break;
  27258. case 2:
  27259. cb.call(context, this.get(dims[0], i), this.get(dims[1], i), i);
  27260. break;
  27261. default:
  27262. var k = 0;
  27263. var value = [];
  27264. for (; k < dimSize; k++) {
  27265. value[k] = this.get(dims[k], i);
  27266. }
  27267. // Index
  27268. value[k] = i;
  27269. cb.apply(context, value);
  27270. }
  27271. }
  27272. };
  27273. /**
  27274. * Data filter
  27275. * @param {string|Array.<string>}
  27276. * @param {Function} cb
  27277. * @param {*} [context=this]
  27278. */
  27279. listProto.filterSelf = function (dimensions, cb, context, contextCompat) {
  27280. 'use strict';
  27281. if (!this._count) {
  27282. return;
  27283. }
  27284. if (typeof dimensions === 'function') {
  27285. contextCompat = context;
  27286. context = cb;
  27287. cb = dimensions;
  27288. dimensions = [];
  27289. }
  27290. // contextCompat just for compat echarts3
  27291. context = context || contextCompat || this;
  27292. dimensions = map(
  27293. normalizeDimensions(dimensions), this.getDimension, this
  27294. );
  27295. if (__DEV__) {
  27296. validateDimensions(this, dimensions);
  27297. }
  27298. var count = this.count();
  27299. var Ctor = getIndicesCtor(this);
  27300. var newIndices = new Ctor(count);
  27301. var value = [];
  27302. var dimSize = dimensions.length;
  27303. var offset = 0;
  27304. var dim0 = dimensions[0];
  27305. for (var i = 0; i < count; i++) {
  27306. var keep;
  27307. var rawIdx = this.getRawIndex(i);
  27308. // Simple optimization
  27309. if (dimSize === 0) {
  27310. keep = cb.call(context, i);
  27311. }
  27312. else if (dimSize === 1) {
  27313. var val = this._getFast(dim0, rawIdx);
  27314. keep = cb.call(context, val, i);
  27315. }
  27316. else {
  27317. for (var k = 0; k < dimSize; k++) {
  27318. value[k] = this._getFast(dim0, rawIdx);
  27319. }
  27320. value[k] = i;
  27321. keep = cb.apply(context, value);
  27322. }
  27323. if (keep) {
  27324. newIndices[offset++] = rawIdx;
  27325. }
  27326. }
  27327. // Set indices after filtered.
  27328. if (offset < count) {
  27329. this._indices = newIndices;
  27330. }
  27331. this._count = offset;
  27332. // Reset data extent
  27333. this._extent = {};
  27334. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27335. return this;
  27336. };
  27337. /**
  27338. * Select data in range. (For optimization of filter)
  27339. * (Manually inline code, support 5 million data filtering in data zoom.)
  27340. */
  27341. listProto.selectRange = function (range) {
  27342. 'use strict';
  27343. if (!this._count) {
  27344. return;
  27345. }
  27346. var dimensions = [];
  27347. for (var dim in range) {
  27348. if (range.hasOwnProperty(dim)) {
  27349. dimensions.push(dim);
  27350. }
  27351. }
  27352. if (__DEV__) {
  27353. validateDimensions(this, dimensions);
  27354. }
  27355. var dimSize = dimensions.length;
  27356. if (!dimSize) {
  27357. return;
  27358. }
  27359. var originalCount = this.count();
  27360. var Ctor = getIndicesCtor(this);
  27361. var newIndices = new Ctor(originalCount);
  27362. var offset = 0;
  27363. var dim0 = dimensions[0];
  27364. var min = range[dim0][0];
  27365. var max = range[dim0][1];
  27366. var quickFinished = false;
  27367. if (!this._indices) {
  27368. // Extreme optimization for common case. About 2x faster in chrome.
  27369. var idx = 0;
  27370. if (dimSize === 1) {
  27371. var dimStorage = this._storage[dimensions[0]];
  27372. for (var k = 0; k < this._chunkCount; k++) {
  27373. var chunkStorage = dimStorage[k];
  27374. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  27375. for (var i = 0; i < len; i++) {
  27376. var val = chunkStorage[i];
  27377. // NaN will not be filtered. Consider the case, in line chart, empty
  27378. // value indicates the line should be broken. But for the case like
  27379. // scatter plot, a data item with empty value will not be rendered,
  27380. // but the axis extent may be effected if some other dim of the data
  27381. // item has value. Fortunately it is not a significant negative effect.
  27382. if (
  27383. (val >= min && val <= max) || isNaN(val)
  27384. ) {
  27385. newIndices[offset++] = idx;
  27386. }
  27387. idx++;
  27388. }
  27389. }
  27390. quickFinished = true;
  27391. }
  27392. else if (dimSize === 2) {
  27393. var dimStorage = this._storage[dim0];
  27394. var dimStorage2 = this._storage[dimensions[1]];
  27395. var min2 = range[dimensions[1]][0];
  27396. var max2 = range[dimensions[1]][1];
  27397. for (var k = 0; k < this._chunkCount; k++) {
  27398. var chunkStorage = dimStorage[k];
  27399. var chunkStorage2 = dimStorage2[k];
  27400. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  27401. for (var i = 0; i < len; i++) {
  27402. var val = chunkStorage[i];
  27403. var val2 = chunkStorage2[i];
  27404. // Do not filter NaN, see comment above.
  27405. if ((
  27406. (val >= min && val <= max) || isNaN(val)
  27407. )
  27408. && (
  27409. (val2 >= min2 && val2 <= max2) || isNaN(val2)
  27410. )
  27411. ) {
  27412. newIndices[offset++] = idx;
  27413. }
  27414. idx++;
  27415. }
  27416. }
  27417. quickFinished = true;
  27418. }
  27419. }
  27420. if (!quickFinished) {
  27421. if (dimSize === 1) {
  27422. for (var i = 0; i < originalCount; i++) {
  27423. var rawIndex = this.getRawIndex(i);
  27424. var val = this._getFast(dim0, rawIndex);
  27425. // Do not filter NaN, see comment above.
  27426. if (
  27427. (val >= min && val <= max) || isNaN(val)
  27428. ) {
  27429. newIndices[offset++] = rawIndex;
  27430. }
  27431. }
  27432. }
  27433. else {
  27434. for (var i = 0; i < originalCount; i++) {
  27435. var keep = true;
  27436. var rawIndex = this.getRawIndex(i);
  27437. for (var k = 0; k < dimSize; k++) {
  27438. var dimk = dimensions[k];
  27439. var val = this._getFast(dim, rawIndex);
  27440. // Do not filter NaN, see comment above.
  27441. if (val < range[dimk][0] || val > range[dimk][1]) {
  27442. keep = false;
  27443. }
  27444. }
  27445. if (keep) {
  27446. newIndices[offset++] = this.getRawIndex(i);
  27447. }
  27448. }
  27449. }
  27450. }
  27451. // Set indices after filtered.
  27452. if (offset < originalCount) {
  27453. this._indices = newIndices;
  27454. }
  27455. this._count = offset;
  27456. // Reset data extent
  27457. this._extent = {};
  27458. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27459. return this;
  27460. };
  27461. /**
  27462. * Data mapping to a plain array
  27463. * @param {string|Array.<string>} [dimensions]
  27464. * @param {Function} cb
  27465. * @param {*} [context=this]
  27466. * @return {Array}
  27467. */
  27468. listProto.mapArray = function (dimensions, cb, context, contextCompat) {
  27469. 'use strict';
  27470. if (typeof dimensions === 'function') {
  27471. contextCompat = context;
  27472. context = cb;
  27473. cb = dimensions;
  27474. dimensions = [];
  27475. }
  27476. // contextCompat just for compat echarts3
  27477. context = context || contextCompat || this;
  27478. var result = [];
  27479. this.each(dimensions, function () {
  27480. result.push(cb && cb.apply(this, arguments));
  27481. }, context);
  27482. return result;
  27483. };
  27484. // Data in excludeDimensions is copied, otherwise transfered.
  27485. function cloneListForMapAndSample(original, excludeDimensions) {
  27486. var allDimensions = original.dimensions;
  27487. var list = new List(
  27488. map(allDimensions, original.getDimensionInfo, original),
  27489. original.hostModel
  27490. );
  27491. // FIXME If needs stackedOn, value may already been stacked
  27492. transferProperties(list, original);
  27493. var storage = list._storage = {};
  27494. var originalStorage = original._storage;
  27495. // Init storage
  27496. for (var i = 0; i < allDimensions.length; i++) {
  27497. var dim = allDimensions[i];
  27498. if (originalStorage[dim]) {
  27499. // Notice that we do not reset invertedIndicesMap here, becuase
  27500. // there is no scenario of mapping or sampling ordinal dimension.
  27501. if (indexOf(excludeDimensions, dim) >= 0) {
  27502. storage[dim] = cloneDimStore(originalStorage[dim]);
  27503. list._rawExtent[dim] = getInitialExtent();
  27504. list._extent[dim] = null;
  27505. }
  27506. else {
  27507. // Direct reference for other dimensions
  27508. storage[dim] = originalStorage[dim];
  27509. }
  27510. }
  27511. }
  27512. return list;
  27513. }
  27514. function cloneDimStore(originalDimStore) {
  27515. var newDimStore = new Array(originalDimStore.length);
  27516. for (var j = 0; j < originalDimStore.length; j++) {
  27517. newDimStore[j] = cloneChunk(originalDimStore[j]);
  27518. }
  27519. return newDimStore;
  27520. }
  27521. function getInitialExtent() {
  27522. return [Infinity, -Infinity];
  27523. }
  27524. /**
  27525. * Data mapping to a new List with given dimensions
  27526. * @param {string|Array.<string>} dimensions
  27527. * @param {Function} cb
  27528. * @param {*} [context=this]
  27529. * @return {Array}
  27530. */
  27531. listProto.map = function (dimensions, cb, context, contextCompat) {
  27532. 'use strict';
  27533. // contextCompat just for compat echarts3
  27534. context = context || contextCompat || this;
  27535. dimensions = map(
  27536. normalizeDimensions(dimensions), this.getDimension, this
  27537. );
  27538. if (__DEV__) {
  27539. validateDimensions(this, dimensions);
  27540. }
  27541. var list = cloneListForMapAndSample(this, dimensions);
  27542. // Following properties are all immutable.
  27543. // So we can reference to the same value
  27544. list._indices = this._indices;
  27545. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27546. var storage = list._storage;
  27547. var tmpRetValue = [];
  27548. var chunkSize = this._chunkSize;
  27549. var dimSize = dimensions.length;
  27550. var dataCount = this.count();
  27551. var values = [];
  27552. var rawExtent = list._rawExtent;
  27553. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  27554. for (var dimIndex = 0; dimIndex < dimSize; dimIndex++) {
  27555. values[dimIndex] = this.get(dimensions[dimIndex], dataIndex /*, stack */);
  27556. }
  27557. values[dimSize] = dataIndex;
  27558. var retValue = cb && cb.apply(context, values);
  27559. if (retValue != null) {
  27560. // a number or string (in oridinal dimension)?
  27561. if (typeof retValue !== 'object') {
  27562. tmpRetValue[0] = retValue;
  27563. retValue = tmpRetValue;
  27564. }
  27565. var rawIndex = this.getRawIndex(dataIndex);
  27566. var chunkIndex = Math.floor(rawIndex / chunkSize);
  27567. var chunkOffset = rawIndex % chunkSize;
  27568. for (var i = 0; i < retValue.length; i++) {
  27569. var dim = dimensions[i];
  27570. var val = retValue[i];
  27571. var rawExtentOnDim = rawExtent[dim];
  27572. var dimStore = storage[dim];
  27573. if (dimStore) {
  27574. dimStore[chunkIndex][chunkOffset] = val;
  27575. }
  27576. if (val < rawExtentOnDim[0]) {
  27577. rawExtentOnDim[0] = val;
  27578. }
  27579. if (val > rawExtentOnDim[1]) {
  27580. rawExtentOnDim[1] = val;
  27581. }
  27582. }
  27583. }
  27584. }
  27585. return list;
  27586. };
  27587. /**
  27588. * Large data down sampling on given dimension
  27589. * @param {string} dimension
  27590. * @param {number} rate
  27591. * @param {Function} sampleValue
  27592. * @param {Function} sampleIndex Sample index for name and id
  27593. */
  27594. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  27595. var list = cloneListForMapAndSample(this, [dimension]);
  27596. var targetStorage = list._storage;
  27597. var frameValues = [];
  27598. var frameSize = Math.floor(1 / rate);
  27599. var dimStore = targetStorage[dimension];
  27600. var len = this.count();
  27601. var chunkSize = this._chunkSize;
  27602. var rawExtentOnDim = list._rawExtent[dimension];
  27603. var newIndices = new (getIndicesCtor(this))(len);
  27604. var offset = 0;
  27605. for (var i = 0; i < len; i += frameSize) {
  27606. // Last frame
  27607. if (frameSize > len - i) {
  27608. frameSize = len - i;
  27609. frameValues.length = frameSize;
  27610. }
  27611. for (var k = 0; k < frameSize; k++) {
  27612. var dataIdx = this.getRawIndex(i + k);
  27613. var originalChunkIndex = Math.floor(dataIdx / chunkSize);
  27614. var originalChunkOffset = dataIdx % chunkSize;
  27615. frameValues[k] = dimStore[originalChunkIndex][originalChunkOffset];
  27616. }
  27617. var value = sampleValue(frameValues);
  27618. var sampleFrameIdx = this.getRawIndex(
  27619. Math.min(i + sampleIndex(frameValues, value) || 0, len - 1)
  27620. );
  27621. var sampleChunkIndex = Math.floor(sampleFrameIdx / chunkSize);
  27622. var sampleChunkOffset = sampleFrameIdx % chunkSize;
  27623. // Only write value on the filtered data
  27624. dimStore[sampleChunkIndex][sampleChunkOffset] = value;
  27625. if (value < rawExtentOnDim[0]) {
  27626. rawExtentOnDim[0] = value;
  27627. }
  27628. if (value > rawExtentOnDim[1]) {
  27629. rawExtentOnDim[1] = value;
  27630. }
  27631. newIndices[offset++] = sampleFrameIdx;
  27632. }
  27633. list._count = offset;
  27634. list._indices = newIndices;
  27635. list.getRawIndex = getRawIndexWithIndices;
  27636. return list;
  27637. };
  27638. /**
  27639. * Get model of one data item.
  27640. *
  27641. * @param {number} idx
  27642. */
  27643. // FIXME Model proxy ?
  27644. listProto.getItemModel = function (idx) {
  27645. var hostModel = this.hostModel;
  27646. return new Model(this.getRawDataItem(idx), hostModel, hostModel && hostModel.ecModel);
  27647. };
  27648. /**
  27649. * Create a data differ
  27650. * @param {module:echarts/data/List} otherList
  27651. * @return {module:echarts/data/DataDiffer}
  27652. */
  27653. listProto.diff = function (otherList) {
  27654. var thisList = this;
  27655. return new DataDiffer(
  27656. otherList ? otherList.getIndices() : [],
  27657. this.getIndices(),
  27658. function (idx) {
  27659. return getId(otherList, idx);
  27660. },
  27661. function (idx) {
  27662. return getId(thisList, idx);
  27663. }
  27664. );
  27665. };
  27666. /**
  27667. * Get visual property.
  27668. * @param {string} key
  27669. */
  27670. listProto.getVisual = function (key) {
  27671. var visual = this._visual;
  27672. return visual && visual[key];
  27673. };
  27674. /**
  27675. * Set visual property
  27676. * @param {string|Object} key
  27677. * @param {*} [value]
  27678. *
  27679. * @example
  27680. * setVisual('color', color);
  27681. * setVisual({
  27682. * 'color': color
  27683. * });
  27684. */
  27685. listProto.setVisual = function (key, val) {
  27686. if (isObject$4(key)) {
  27687. for (var name in key) {
  27688. if (key.hasOwnProperty(name)) {
  27689. this.setVisual(name, key[name]);
  27690. }
  27691. }
  27692. return;
  27693. }
  27694. this._visual = this._visual || {};
  27695. this._visual[key] = val;
  27696. };
  27697. /**
  27698. * Set layout property.
  27699. * @param {string|Object} key
  27700. * @param {*} [val]
  27701. */
  27702. listProto.setLayout = function (key, val) {
  27703. if (isObject$4(key)) {
  27704. for (var name in key) {
  27705. if (key.hasOwnProperty(name)) {
  27706. this.setLayout(name, key[name]);
  27707. }
  27708. }
  27709. return;
  27710. }
  27711. this._layout[key] = val;
  27712. };
  27713. /**
  27714. * Get layout property.
  27715. * @param {string} key.
  27716. * @return {*}
  27717. */
  27718. listProto.getLayout = function (key) {
  27719. return this._layout[key];
  27720. };
  27721. /**
  27722. * Get layout of single data item
  27723. * @param {number} idx
  27724. */
  27725. listProto.getItemLayout = function (idx) {
  27726. return this._itemLayouts[idx];
  27727. };
  27728. /**
  27729. * Set layout of single data item
  27730. * @param {number} idx
  27731. * @param {Object} layout
  27732. * @param {boolean=} [merge=false]
  27733. */
  27734. listProto.setItemLayout = function (idx, layout, merge$$1) {
  27735. this._itemLayouts[idx] = merge$$1
  27736. ? extend(this._itemLayouts[idx] || {}, layout)
  27737. : layout;
  27738. };
  27739. /**
  27740. * Clear all layout of single data item
  27741. */
  27742. listProto.clearItemLayouts = function () {
  27743. this._itemLayouts.length = 0;
  27744. };
  27745. /**
  27746. * Get visual property of single data item
  27747. * @param {number} idx
  27748. * @param {string} key
  27749. * @param {boolean} [ignoreParent=false]
  27750. */
  27751. listProto.getItemVisual = function (idx, key, ignoreParent) {
  27752. var itemVisual = this._itemVisuals[idx];
  27753. var val = itemVisual && itemVisual[key];
  27754. if (val == null && !ignoreParent) {
  27755. // Use global visual property
  27756. return this.getVisual(key);
  27757. }
  27758. return val;
  27759. };
  27760. /**
  27761. * Set visual property of single data item
  27762. *
  27763. * @param {number} idx
  27764. * @param {string|Object} key
  27765. * @param {*} [value]
  27766. *
  27767. * @example
  27768. * setItemVisual(0, 'color', color);
  27769. * setItemVisual(0, {
  27770. * 'color': color
  27771. * });
  27772. */
  27773. listProto.setItemVisual = function (idx, key, value) {
  27774. var itemVisual = this._itemVisuals[idx] || {};
  27775. var hasItemVisual = this.hasItemVisual;
  27776. this._itemVisuals[idx] = itemVisual;
  27777. if (isObject$4(key)) {
  27778. for (var name in key) {
  27779. if (key.hasOwnProperty(name)) {
  27780. itemVisual[name] = key[name];
  27781. hasItemVisual[name] = true;
  27782. }
  27783. }
  27784. return;
  27785. }
  27786. itemVisual[key] = value;
  27787. hasItemVisual[key] = true;
  27788. };
  27789. /**
  27790. * Clear itemVisuals and list visual.
  27791. */
  27792. listProto.clearAllVisual = function () {
  27793. this._visual = {};
  27794. this._itemVisuals = [];
  27795. this.hasItemVisual = {};
  27796. };
  27797. var setItemDataAndSeriesIndex = function (child) {
  27798. child.seriesIndex = this.seriesIndex;
  27799. child.dataIndex = this.dataIndex;
  27800. child.dataType = this.dataType;
  27801. };
  27802. /**
  27803. * Set graphic element relative to data. It can be set as null
  27804. * @param {number} idx
  27805. * @param {module:zrender/Element} [el]
  27806. */
  27807. listProto.setItemGraphicEl = function (idx, el) {
  27808. var hostModel = this.hostModel;
  27809. if (el) {
  27810. // Add data index and series index for indexing the data by element
  27811. // Useful in tooltip
  27812. el.dataIndex = idx;
  27813. el.dataType = this.dataType;
  27814. el.seriesIndex = hostModel && hostModel.seriesIndex;
  27815. if (el.type === 'group') {
  27816. el.traverse(setItemDataAndSeriesIndex, el);
  27817. }
  27818. }
  27819. this._graphicEls[idx] = el;
  27820. };
  27821. /**
  27822. * @param {number} idx
  27823. * @return {module:zrender/Element}
  27824. */
  27825. listProto.getItemGraphicEl = function (idx) {
  27826. return this._graphicEls[idx];
  27827. };
  27828. /**
  27829. * @param {Function} cb
  27830. * @param {*} context
  27831. */
  27832. listProto.eachItemGraphicEl = function (cb, context) {
  27833. each$1(this._graphicEls, function (el, idx) {
  27834. if (el) {
  27835. cb && cb.call(context, el, idx);
  27836. }
  27837. });
  27838. };
  27839. /**
  27840. * Shallow clone a new list except visual and layout properties, and graph elements.
  27841. * New list only change the indices.
  27842. */
  27843. listProto.cloneShallow = function (list) {
  27844. if (!list) {
  27845. var dimensionInfoList = map(this.dimensions, this.getDimensionInfo, this);
  27846. list = new List(dimensionInfoList, this.hostModel);
  27847. }
  27848. // FIXME
  27849. list._storage = this._storage;
  27850. transferProperties(list, this);
  27851. // Clone will not change the data extent and indices
  27852. if (this._indices) {
  27853. var Ctor = this._indices.constructor;
  27854. list._indices = new Ctor(this._indices);
  27855. }
  27856. else {
  27857. list._indices = null;
  27858. }
  27859. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27860. return list;
  27861. };
  27862. /**
  27863. * Wrap some method to add more feature
  27864. * @param {string} methodName
  27865. * @param {Function} injectFunction
  27866. */
  27867. listProto.wrapMethod = function (methodName, injectFunction) {
  27868. var originalMethod = this[methodName];
  27869. if (typeof originalMethod !== 'function') {
  27870. return;
  27871. }
  27872. this.__wrappedMethods = this.__wrappedMethods || [];
  27873. this.__wrappedMethods.push(methodName);
  27874. this[methodName] = function () {
  27875. var res = originalMethod.apply(this, arguments);
  27876. return injectFunction.apply(this, [res].concat(slice(arguments)));
  27877. };
  27878. };
  27879. // Methods that create a new list based on this list should be listed here.
  27880. // Notice that those method should `RETURN` the new list.
  27881. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  27882. // Methods that change indices of this list should be listed here.
  27883. listProto.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  27884. /*
  27885. * Licensed to the Apache Software Foundation (ASF) under one
  27886. * or more contributor license agreements. See the NOTICE file
  27887. * distributed with this work for additional information
  27888. * regarding copyright ownership. The ASF licenses this file
  27889. * to you under the Apache License, Version 2.0 (the
  27890. * "License"); you may not use this file except in compliance
  27891. * with the License. You may obtain a copy of the License at
  27892. *
  27893. * http://www.apache.org/licenses/LICENSE-2.0
  27894. *
  27895. * Unless required by applicable law or agreed to in writing,
  27896. * software distributed under the License is distributed on an
  27897. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27898. * KIND, either express or implied. See the License for the
  27899. * specific language governing permissions and limitations
  27900. * under the License.
  27901. */
  27902. /**
  27903. * @deprecated
  27904. * Use `echarts/data/helper/createDimensions` instead.
  27905. */
  27906. /**
  27907. * @see {module:echarts/test/ut/spec/data/completeDimensions}
  27908. *
  27909. * This method builds the relationship between:
  27910. * + "what the coord sys or series requires (see `sysDims`)",
  27911. * + "what the user defines (in `encode` and `dimensions`, see `opt.dimsDef` and `opt.encodeDef`)"
  27912. * + "what the data source provids (see `source`)".
  27913. *
  27914. * Some guess strategy will be adapted if user does not define something.
  27915. * If no 'value' dimension specified, the first no-named dimension will be
  27916. * named as 'value'.
  27917. *
  27918. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  27919. * provides not only dim template, but also default order.
  27920. * properties: 'name', 'type', 'displayName'.
  27921. * `name` of each item provides default coord name.
  27922. * [{dimsDef: [string|Object, ...]}, ...] dimsDef of sysDim item provides default dim name, and
  27923. * provide dims count that the sysDim required.
  27924. * [{ordinalMeta}] can be specified.
  27925. * @param {module:echarts/data/Source|Array|Object} source or data (for compatibal with pervious)
  27926. * @param {Object} [opt]
  27927. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  27928. * For example: ['asdf', {name, type}, ...].
  27929. * @param {Object|HashMap} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  27930. * @param {Function} [opt.encodeDefaulter] Called if no `opt.encodeDef` exists.
  27931. * If not specified, auto find the next available data dim.
  27932. * param source {module:data/Source}
  27933. * param dimCount {number}
  27934. * return {Object} encode Never be `null/undefined`.
  27935. * @param {string} [opt.generateCoord] Generate coord dim with the given name.
  27936. * If not specified, extra dim names will be:
  27937. * 'value', 'value0', 'value1', ...
  27938. * @param {number} [opt.generateCoordCount] By default, the generated dim name is `generateCoord`.
  27939. * If `generateCoordCount` specified, the generated dim names will be:
  27940. * `generateCoord` + 0, `generateCoord` + 1, ...
  27941. * can be Infinity, indicate that use all of the remain columns.
  27942. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  27943. * @return {Array.<module:data/DataDimensionInfo>}
  27944. */
  27945. function completeDimensions(sysDims, source, opt) {
  27946. if (!Source.isInstance(source)) {
  27947. source = Source.seriesDataToSource(source);
  27948. }
  27949. opt = opt || {};
  27950. sysDims = (sysDims || []).slice();
  27951. var dimsDef = (opt.dimsDef || []).slice();
  27952. var dataDimNameMap = createHashMap();
  27953. var coordDimNameMap = createHashMap();
  27954. // var valueCandidate;
  27955. var result = [];
  27956. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimCount);
  27957. // Apply user defined dims (`name` and `type`) and init result.
  27958. for (var i = 0; i < dimCount; i++) {
  27959. var dimDefItem = dimsDef[i] = extend(
  27960. {}, isObject$1(dimsDef[i]) ? dimsDef[i] : {name: dimsDef[i]}
  27961. );
  27962. var userDimName = dimDefItem.name;
  27963. var resultItem = result[i] = new DataDimensionInfo();
  27964. // Name will be applied later for avoiding duplication.
  27965. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  27966. // Only if `series.dimensions` is defined in option
  27967. // displayName, will be set, and dimension will be diplayed vertically in
  27968. // tooltip by default.
  27969. resultItem.name = resultItem.displayName = userDimName;
  27970. dataDimNameMap.set(userDimName, i);
  27971. }
  27972. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  27973. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  27974. }
  27975. var encodeDef = opt.encodeDef;
  27976. if (!encodeDef && opt.encodeDefaulter) {
  27977. encodeDef = opt.encodeDefaulter(source, dimCount);
  27978. }
  27979. encodeDef = createHashMap(encodeDef);
  27980. // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  27981. encodeDef.each(function (dataDims, coordDim) {
  27982. dataDims = normalizeToArray(dataDims).slice();
  27983. // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  27984. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  27985. // this case.
  27986. if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
  27987. encodeDef.set(coordDim, false);
  27988. return;
  27989. }
  27990. var validDataDims = encodeDef.set(coordDim, []);
  27991. each$1(dataDims, function (resultDimIdx, idx) {
  27992. // The input resultDimIdx can be dim name or index.
  27993. isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  27994. if (resultDimIdx != null && resultDimIdx < dimCount) {
  27995. validDataDims[idx] = resultDimIdx;
  27996. applyDim(result[resultDimIdx], coordDim, idx);
  27997. }
  27998. });
  27999. });
  28000. // Apply templetes and default order from `sysDims`.
  28001. var availDimIdx = 0;
  28002. each$1(sysDims, function (sysDimItem, sysDimIndex) {
  28003. var coordDim;
  28004. var sysDimItem;
  28005. var sysDimItemDimsDef;
  28006. var sysDimItemOtherDims;
  28007. if (isString(sysDimItem)) {
  28008. coordDim = sysDimItem;
  28009. sysDimItem = {};
  28010. }
  28011. else {
  28012. coordDim = sysDimItem.name;
  28013. var ordinalMeta = sysDimItem.ordinalMeta;
  28014. sysDimItem.ordinalMeta = null;
  28015. sysDimItem = clone(sysDimItem);
  28016. sysDimItem.ordinalMeta = ordinalMeta;
  28017. // `coordDimIndex` should not be set directly.
  28018. sysDimItemDimsDef = sysDimItem.dimsDef;
  28019. sysDimItemOtherDims = sysDimItem.otherDims;
  28020. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex =
  28021. sysDimItem.dimsDef = sysDimItem.otherDims = null;
  28022. }
  28023. var dataDims = encodeDef.get(coordDim);
  28024. // negative resultDimIdx means no need to mapping.
  28025. if (dataDims === false) {
  28026. return;
  28027. }
  28028. var dataDims = normalizeToArray(dataDims);
  28029. // dimensions provides default dim sequences.
  28030. if (!dataDims.length) {
  28031. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  28032. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  28033. availDimIdx++;
  28034. }
  28035. availDimIdx < result.length && dataDims.push(availDimIdx++);
  28036. }
  28037. }
  28038. // Apply templates.
  28039. each$1(dataDims, function (resultDimIdx, coordDimIndex) {
  28040. var resultItem = result[resultDimIdx];
  28041. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  28042. if (resultItem.name == null && sysDimItemDimsDef) {
  28043. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  28044. !isObject$1(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {name: sysDimItemDimsDefItem});
  28045. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  28046. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  28047. }
  28048. // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  28049. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  28050. });
  28051. });
  28052. function applyDim(resultItem, coordDim, coordDimIndex) {
  28053. if (OTHER_DIMENSIONS.get(coordDim) != null) {
  28054. resultItem.otherDims[coordDim] = coordDimIndex;
  28055. }
  28056. else {
  28057. resultItem.coordDim = coordDim;
  28058. resultItem.coordDimIndex = coordDimIndex;
  28059. coordDimNameMap.set(coordDim, true);
  28060. }
  28061. }
  28062. // Make sure the first extra dim is 'value'.
  28063. var generateCoord = opt.generateCoord;
  28064. var generateCoordCount = opt.generateCoordCount;
  28065. var fromZero = generateCoordCount != null;
  28066. generateCoordCount = generateCoord ? (generateCoordCount || 1) : 0;
  28067. var extra = generateCoord || 'value';
  28068. // Set dim `name` and other `coordDim` and other props.
  28069. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  28070. var resultItem = result[resultDimIdx] = result[resultDimIdx] || new DataDimensionInfo();
  28071. var coordDim = resultItem.coordDim;
  28072. if (coordDim == null) {
  28073. resultItem.coordDim = genName(
  28074. extra, coordDimNameMap, fromZero
  28075. );
  28076. resultItem.coordDimIndex = 0;
  28077. if (!generateCoord || generateCoordCount <= 0) {
  28078. resultItem.isExtraCoord = true;
  28079. }
  28080. generateCoordCount--;
  28081. }
  28082. resultItem.name == null && (resultItem.name = genName(
  28083. resultItem.coordDim,
  28084. dataDimNameMap
  28085. ));
  28086. if (resultItem.type == null
  28087. && (
  28088. guessOrdinal(source, resultDimIdx, resultItem.name) === BE_ORDINAL.Must
  28089. // Consider the case:
  28090. // {
  28091. // dataset: {source: [
  28092. // ['2001', 123],
  28093. // ['2002', 456],
  28094. // ...
  28095. // ['The others', 987],
  28096. // ]},
  28097. // series: {type: 'pie'}
  28098. // }
  28099. // The first colum should better be treated as a "ordinal" although it
  28100. // might not able to be detected as an "ordinal" by `guessOrdinal`.
  28101. || (resultItem.isExtraCoord
  28102. && (resultItem.otherDims.itemName != null
  28103. || resultItem.otherDims.seriesName != null
  28104. )
  28105. )
  28106. )
  28107. ) {
  28108. resultItem.type = 'ordinal';
  28109. }
  28110. }
  28111. return result;
  28112. }
  28113. // ??? TODO
  28114. // Originally detect dimCount by data[0]. Should we
  28115. // optimize it to only by sysDims and dimensions and encode.
  28116. // So only necessary dims will be initialized.
  28117. // But
  28118. // (1) custom series should be considered. where other dims
  28119. // may be visited.
  28120. // (2) sometimes user need to calcualte bubble size or use visualMap
  28121. // on other dimensions besides coordSys needed.
  28122. // So, dims that is not used by system, should be shared in storage?
  28123. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  28124. // Note that the result dimCount should not small than columns count
  28125. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  28126. var dimCount = Math.max(
  28127. source.dimensionsDetectCount || 1,
  28128. sysDims.length,
  28129. dimsDef.length,
  28130. optDimCount || 0
  28131. );
  28132. each$1(sysDims, function (sysDimItem) {
  28133. var sysDimItemDimsDef = sysDimItem.dimsDef;
  28134. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  28135. });
  28136. return dimCount;
  28137. }
  28138. function genName(name, map$$1, fromZero) {
  28139. if (fromZero || map$$1.get(name) != null) {
  28140. var i = 0;
  28141. while (map$$1.get(name + i) != null) {
  28142. i++;
  28143. }
  28144. name += i;
  28145. }
  28146. map$$1.set(name, true);
  28147. return name;
  28148. }
  28149. /*
  28150. * Licensed to the Apache Software Foundation (ASF) under one
  28151. * or more contributor license agreements. See the NOTICE file
  28152. * distributed with this work for additional information
  28153. * regarding copyright ownership. The ASF licenses this file
  28154. * to you under the Apache License, Version 2.0 (the
  28155. * "License"); you may not use this file except in compliance
  28156. * with the License. You may obtain a copy of the License at
  28157. *
  28158. * http://www.apache.org/licenses/LICENSE-2.0
  28159. *
  28160. * Unless required by applicable law or agreed to in writing,
  28161. * software distributed under the License is distributed on an
  28162. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28163. * KIND, either express or implied. See the License for the
  28164. * specific language governing permissions and limitations
  28165. * under the License.
  28166. */
  28167. /**
  28168. * Substitute `completeDimensions`.
  28169. * `completeDimensions` is to be deprecated.
  28170. */
  28171. /**
  28172. * @param {module:echarts/data/Source|module:echarts/data/List} source or data.
  28173. * @param {Object|Array} [opt]
  28174. * @param {Array.<string|Object>} [opt.coordDimensions=[]]
  28175. * @param {number} [opt.dimensionsCount]
  28176. * @param {string} [opt.generateCoord]
  28177. * @param {string} [opt.generateCoordCount]
  28178. * @param {Array.<string|Object>} [opt.dimensionsDefine=source.dimensionsDefine] Overwrite source define.
  28179. * @param {Object|HashMap} [opt.encodeDefine=source.encodeDefine] Overwrite source define.
  28180. * @param {Function} [opt.encodeDefaulter] Make default encode if user not specified.
  28181. * @return {Array.<Object>} dimensionsInfo
  28182. */
  28183. var createDimensions = function (source, opt) {
  28184. opt = opt || {};
  28185. return completeDimensions(opt.coordDimensions || [], source, {
  28186. dimsDef: opt.dimensionsDefine || source.dimensionsDefine,
  28187. encodeDef: opt.encodeDefine || source.encodeDefine,
  28188. dimCount: opt.dimensionsCount,
  28189. encodeDefaulter: opt.encodeDefaulter,
  28190. generateCoord: opt.generateCoord,
  28191. generateCoordCount: opt.generateCoordCount
  28192. });
  28193. };
  28194. /*
  28195. * Licensed to the Apache Software Foundation (ASF) under one
  28196. * or more contributor license agreements. See the NOTICE file
  28197. * distributed with this work for additional information
  28198. * regarding copyright ownership. The ASF licenses this file
  28199. * to you under the Apache License, Version 2.0 (the
  28200. * "License"); you may not use this file except in compliance
  28201. * with the License. You may obtain a copy of the License at
  28202. *
  28203. * http://www.apache.org/licenses/LICENSE-2.0
  28204. *
  28205. * Unless required by applicable law or agreed to in writing,
  28206. * software distributed under the License is distributed on an
  28207. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28208. * KIND, either express or implied. See the License for the
  28209. * specific language governing permissions and limitations
  28210. * under the License.
  28211. */
  28212. /**
  28213. * Helper for model references.
  28214. * There are many manners to refer axis/coordSys.
  28215. */
  28216. // TODO
  28217. // merge relevant logic to this file?
  28218. // check: "modelHelper" of tooltip and "BrushTargetManager".
  28219. /**
  28220. * @class
  28221. * For example:
  28222. * {
  28223. * coordSysName: 'cartesian2d',
  28224. * coordSysDims: ['x', 'y', ...],
  28225. * axisMap: HashMap({
  28226. * x: xAxisModel,
  28227. * y: yAxisModel
  28228. * }),
  28229. * categoryAxisMap: HashMap({
  28230. * x: xAxisModel,
  28231. * y: undefined
  28232. * }),
  28233. * // The index of the first category axis in `coordSysDims`.
  28234. * // `null/undefined` means no category axis exists.
  28235. * firstCategoryDimIndex: 1,
  28236. * // To replace user specified encode.
  28237. * }
  28238. */
  28239. function CoordSysInfo(coordSysName) {
  28240. /**
  28241. * @type {string}
  28242. */
  28243. this.coordSysName = coordSysName;
  28244. /**
  28245. * @type {Array.<string>}
  28246. */
  28247. this.coordSysDims = [];
  28248. /**
  28249. * @type {module:zrender/core/util#HashMap}
  28250. */
  28251. this.axisMap = createHashMap();
  28252. /**
  28253. * @type {module:zrender/core/util#HashMap}
  28254. */
  28255. this.categoryAxisMap = createHashMap();
  28256. /**
  28257. * @type {number}
  28258. */
  28259. this.firstCategoryDimIndex = null;
  28260. }
  28261. /**
  28262. * @return {module:model/referHelper#CoordSysInfo}
  28263. */
  28264. function getCoordSysInfoBySeries(seriesModel) {
  28265. var coordSysName = seriesModel.get('coordinateSystem');
  28266. var result = new CoordSysInfo(coordSysName);
  28267. var fetch = fetchers[coordSysName];
  28268. if (fetch) {
  28269. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  28270. return result;
  28271. }
  28272. }
  28273. var fetchers = {
  28274. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  28275. var xAxisModel = seriesModel.getReferringComponents('xAxis')[0];
  28276. var yAxisModel = seriesModel.getReferringComponents('yAxis')[0];
  28277. if (__DEV__) {
  28278. if (!xAxisModel) {
  28279. throw new Error('xAxis "' + retrieve(
  28280. seriesModel.get('xAxisIndex'),
  28281. seriesModel.get('xAxisId'),
  28282. 0
  28283. ) + '" not found');
  28284. }
  28285. if (!yAxisModel) {
  28286. throw new Error('yAxis "' + retrieve(
  28287. seriesModel.get('xAxisIndex'),
  28288. seriesModel.get('yAxisId'),
  28289. 0
  28290. ) + '" not found');
  28291. }
  28292. }
  28293. result.coordSysDims = ['x', 'y'];
  28294. axisMap.set('x', xAxisModel);
  28295. axisMap.set('y', yAxisModel);
  28296. if (isCategory(xAxisModel)) {
  28297. categoryAxisMap.set('x', xAxisModel);
  28298. result.firstCategoryDimIndex = 0;
  28299. }
  28300. if (isCategory(yAxisModel)) {
  28301. categoryAxisMap.set('y', yAxisModel);
  28302. result.firstCategoryDimIndex == null & (result.firstCategoryDimIndex = 1);
  28303. }
  28304. },
  28305. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  28306. var singleAxisModel = seriesModel.getReferringComponents('singleAxis')[0];
  28307. if (__DEV__) {
  28308. if (!singleAxisModel) {
  28309. throw new Error('singleAxis should be specified.');
  28310. }
  28311. }
  28312. result.coordSysDims = ['single'];
  28313. axisMap.set('single', singleAxisModel);
  28314. if (isCategory(singleAxisModel)) {
  28315. categoryAxisMap.set('single', singleAxisModel);
  28316. result.firstCategoryDimIndex = 0;
  28317. }
  28318. },
  28319. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  28320. var polarModel = seriesModel.getReferringComponents('polar')[0];
  28321. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  28322. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  28323. if (__DEV__) {
  28324. if (!angleAxisModel) {
  28325. throw new Error('angleAxis option not found');
  28326. }
  28327. if (!radiusAxisModel) {
  28328. throw new Error('radiusAxis option not found');
  28329. }
  28330. }
  28331. result.coordSysDims = ['radius', 'angle'];
  28332. axisMap.set('radius', radiusAxisModel);
  28333. axisMap.set('angle', angleAxisModel);
  28334. if (isCategory(radiusAxisModel)) {
  28335. categoryAxisMap.set('radius', radiusAxisModel);
  28336. result.firstCategoryDimIndex = 0;
  28337. }
  28338. if (isCategory(angleAxisModel)) {
  28339. categoryAxisMap.set('angle', angleAxisModel);
  28340. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  28341. }
  28342. },
  28343. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  28344. result.coordSysDims = ['lng', 'lat'];
  28345. },
  28346. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  28347. var ecModel = seriesModel.ecModel;
  28348. var parallelModel = ecModel.getComponent(
  28349. 'parallel', seriesModel.get('parallelIndex')
  28350. );
  28351. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  28352. each$1(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  28353. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  28354. var axisDim = coordSysDims[index];
  28355. axisMap.set(axisDim, axisModel);
  28356. if (isCategory(axisModel) && result.firstCategoryDimIndex == null) {
  28357. categoryAxisMap.set(axisDim, axisModel);
  28358. result.firstCategoryDimIndex = index;
  28359. }
  28360. });
  28361. }
  28362. };
  28363. function isCategory(axisModel) {
  28364. return axisModel.get('type') === 'category';
  28365. }
  28366. /*
  28367. * Licensed to the Apache Software Foundation (ASF) under one
  28368. * or more contributor license agreements. See the NOTICE file
  28369. * distributed with this work for additional information
  28370. * regarding copyright ownership. The ASF licenses this file
  28371. * to you under the Apache License, Version 2.0 (the
  28372. * "License"); you may not use this file except in compliance
  28373. * with the License. You may obtain a copy of the License at
  28374. *
  28375. * http://www.apache.org/licenses/LICENSE-2.0
  28376. *
  28377. * Unless required by applicable law or agreed to in writing,
  28378. * software distributed under the License is distributed on an
  28379. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28380. * KIND, either express or implied. See the License for the
  28381. * specific language governing permissions and limitations
  28382. * under the License.
  28383. */
  28384. /**
  28385. * Note that it is too complicated to support 3d stack by value
  28386. * (have to create two-dimension inverted index), so in 3d case
  28387. * we just support that stacked by index.
  28388. *
  28389. * @param {module:echarts/model/Series} seriesModel
  28390. * @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
  28391. * The input dimensionInfoList will be modified.
  28392. * @param {Object} [opt]
  28393. * @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
  28394. * @param {boolean} [opt.byIndex=false]
  28395. * @return {Object} calculationInfo
  28396. * {
  28397. * stackedDimension: string
  28398. * stackedByDimension: string
  28399. * isStackedByIndex: boolean
  28400. * stackedOverDimension: string
  28401. * stackResultDimension: string
  28402. * }
  28403. */
  28404. function enableDataStack(seriesModel, dimensionInfoList, opt) {
  28405. opt = opt || {};
  28406. var byIndex = opt.byIndex;
  28407. var stackedCoordDimension = opt.stackedCoordDimension;
  28408. // Compatibal: when `stack` is set as '', do not stack.
  28409. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  28410. var stackedByDimInfo;
  28411. var stackedDimInfo;
  28412. var stackResultDimension;
  28413. var stackedOverDimension;
  28414. each$1(dimensionInfoList, function (dimensionInfo, index) {
  28415. if (isString(dimensionInfo)) {
  28416. dimensionInfoList[index] = dimensionInfo = {name: dimensionInfo};
  28417. }
  28418. if (mayStack && !dimensionInfo.isExtraCoord) {
  28419. // Find the first ordinal dimension as the stackedByDimInfo.
  28420. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  28421. stackedByDimInfo = dimensionInfo;
  28422. }
  28423. // Find the first stackable dimension as the stackedDimInfo.
  28424. if (!stackedDimInfo
  28425. && dimensionInfo.type !== 'ordinal'
  28426. && dimensionInfo.type !== 'time'
  28427. && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)
  28428. ) {
  28429. stackedDimInfo = dimensionInfo;
  28430. }
  28431. }
  28432. });
  28433. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  28434. // Compatible with previous design, value axis (time axis) only stack by index.
  28435. // It may make sense if the user provides elaborately constructed data.
  28436. byIndex = true;
  28437. }
  28438. // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  28439. // That put stack logic in List is for using conveniently in echarts extensions, but it
  28440. // might not be a good way.
  28441. if (stackedDimInfo) {
  28442. // Use a weird name that not duplicated with other names.
  28443. stackResultDimension = '__\0ecstackresult';
  28444. stackedOverDimension = '__\0ecstackedover';
  28445. // Create inverted index to fast query index by value.
  28446. if (stackedByDimInfo) {
  28447. stackedByDimInfo.createInvertedIndices = true;
  28448. }
  28449. var stackedDimCoordDim = stackedDimInfo.coordDim;
  28450. var stackedDimType = stackedDimInfo.type;
  28451. var stackedDimCoordIndex = 0;
  28452. each$1(dimensionInfoList, function (dimensionInfo) {
  28453. if (dimensionInfo.coordDim === stackedDimCoordDim) {
  28454. stackedDimCoordIndex++;
  28455. }
  28456. });
  28457. dimensionInfoList.push({
  28458. name: stackResultDimension,
  28459. coordDim: stackedDimCoordDim,
  28460. coordDimIndex: stackedDimCoordIndex,
  28461. type: stackedDimType,
  28462. isExtraCoord: true,
  28463. isCalculationCoord: true
  28464. });
  28465. stackedDimCoordIndex++;
  28466. dimensionInfoList.push({
  28467. name: stackedOverDimension,
  28468. // This dimension contains stack base (generally, 0), so do not set it as
  28469. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  28470. coordDim: stackedOverDimension,
  28471. coordDimIndex: stackedDimCoordIndex,
  28472. type: stackedDimType,
  28473. isExtraCoord: true,
  28474. isCalculationCoord: true
  28475. });
  28476. }
  28477. return {
  28478. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  28479. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  28480. isStackedByIndex: byIndex,
  28481. stackedOverDimension: stackedOverDimension,
  28482. stackResultDimension: stackResultDimension
  28483. };
  28484. }
  28485. /**
  28486. * @param {module:echarts/data/List} data
  28487. * @param {string} stackedDim
  28488. */
  28489. function isDimensionStacked(data, stackedDim /*, stackedByDim*/) {
  28490. // Each single series only maps to one pair of axis. So we do not need to
  28491. // check stackByDim, whatever stacked by a dimension or stacked by index.
  28492. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
  28493. // && (
  28494. // stackedByDim != null
  28495. // ? stackedByDim === data.getCalculationInfo('stackedByDimension')
  28496. // : data.getCalculationInfo('isStackedByIndex')
  28497. // );
  28498. }
  28499. /**
  28500. * @param {module:echarts/data/List} data
  28501. * @param {string} targetDim
  28502. * @param {string} [stackedByDim] If not input this parameter, check whether
  28503. * stacked by index.
  28504. * @return {string} dimension
  28505. */
  28506. function getStackedDimension(data, targetDim) {
  28507. return isDimensionStacked(data, targetDim)
  28508. ? data.getCalculationInfo('stackResultDimension')
  28509. : targetDim;
  28510. }
  28511. /*
  28512. * Licensed to the Apache Software Foundation (ASF) under one
  28513. * or more contributor license agreements. See the NOTICE file
  28514. * distributed with this work for additional information
  28515. * regarding copyright ownership. The ASF licenses this file
  28516. * to you under the Apache License, Version 2.0 (the
  28517. * "License"); you may not use this file except in compliance
  28518. * with the License. You may obtain a copy of the License at
  28519. *
  28520. * http://www.apache.org/licenses/LICENSE-2.0
  28521. *
  28522. * Unless required by applicable law or agreed to in writing,
  28523. * software distributed under the License is distributed on an
  28524. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28525. * KIND, either express or implied. See the License for the
  28526. * specific language governing permissions and limitations
  28527. * under the License.
  28528. */
  28529. /**
  28530. * @param {module:echarts/data/Source|Array} source Or raw data.
  28531. * @param {module:echarts/model/Series} seriesModel
  28532. * @param {Object} [opt]
  28533. * @param {string} [opt.generateCoord]
  28534. * @param {boolean} [opt.useEncodeDefaulter]
  28535. */
  28536. function createListFromArray(source, seriesModel, opt) {
  28537. opt = opt || {};
  28538. if (!Source.isInstance(source)) {
  28539. source = Source.seriesDataToSource(source);
  28540. }
  28541. var coordSysName = seriesModel.get('coordinateSystem');
  28542. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  28543. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  28544. var coordSysDimDefs;
  28545. if (coordSysInfo) {
  28546. coordSysDimDefs = map(coordSysInfo.coordSysDims, function (dim) {
  28547. var dimInfo = {name: dim};
  28548. var axisModel = coordSysInfo.axisMap.get(dim);
  28549. if (axisModel) {
  28550. var axisType = axisModel.get('type');
  28551. dimInfo.type = getDimensionTypeByAxis(axisType);
  28552. // dimInfo.stackable = isStackable(axisType);
  28553. }
  28554. return dimInfo;
  28555. });
  28556. }
  28557. if (!coordSysDimDefs) {
  28558. // Get dimensions from registered coordinate system
  28559. coordSysDimDefs = (registeredCoordSys && (
  28560. registeredCoordSys.getDimensionsInfo
  28561. ? registeredCoordSys.getDimensionsInfo()
  28562. : registeredCoordSys.dimensions.slice()
  28563. )) || ['x', 'y'];
  28564. }
  28565. var dimInfoList = createDimensions(source, {
  28566. coordDimensions: coordSysDimDefs,
  28567. generateCoord: opt.generateCoord,
  28568. encodeDefaulter: opt.useEncodeDefaulter
  28569. ? curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel)
  28570. : null
  28571. });
  28572. var firstCategoryDimIndex;
  28573. var hasNameEncode;
  28574. coordSysInfo && each$1(dimInfoList, function (dimInfo, dimIndex) {
  28575. var coordDim = dimInfo.coordDim;
  28576. var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
  28577. if (categoryAxisModel) {
  28578. if (firstCategoryDimIndex == null) {
  28579. firstCategoryDimIndex = dimIndex;
  28580. }
  28581. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  28582. }
  28583. if (dimInfo.otherDims.itemName != null) {
  28584. hasNameEncode = true;
  28585. }
  28586. });
  28587. if (!hasNameEncode && firstCategoryDimIndex != null) {
  28588. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  28589. }
  28590. var stackCalculationInfo = enableDataStack(seriesModel, dimInfoList);
  28591. var list = new List(dimInfoList, seriesModel);
  28592. list.setCalculationInfo(stackCalculationInfo);
  28593. var dimValueGetter = (firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source))
  28594. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  28595. // Use dataIndex as ordinal value in categoryAxis
  28596. return dimIndex === firstCategoryDimIndex
  28597. ? dataIndex
  28598. : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  28599. }
  28600. : null;
  28601. list.hasItemOption = false;
  28602. list.initData(source, null, dimValueGetter);
  28603. return list;
  28604. }
  28605. function isNeedCompleteOrdinalData(source) {
  28606. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  28607. var sampleItem = firstDataNotNull(source.data || []);
  28608. return sampleItem != null
  28609. && !isArray(getDataItemValue(sampleItem));
  28610. }
  28611. }
  28612. function firstDataNotNull(data) {
  28613. var i = 0;
  28614. while (i < data.length && data[i] == null) {
  28615. i++;
  28616. }
  28617. return data[i];
  28618. }
  28619. /*
  28620. * Licensed to the Apache Software Foundation (ASF) under one
  28621. * or more contributor license agreements. See the NOTICE file
  28622. * distributed with this work for additional information
  28623. * regarding copyright ownership. The ASF licenses this file
  28624. * to you under the Apache License, Version 2.0 (the
  28625. * "License"); you may not use this file except in compliance
  28626. * with the License. You may obtain a copy of the License at
  28627. *
  28628. * http://www.apache.org/licenses/LICENSE-2.0
  28629. *
  28630. * Unless required by applicable law or agreed to in writing,
  28631. * software distributed under the License is distributed on an
  28632. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28633. * KIND, either express or implied. See the License for the
  28634. * specific language governing permissions and limitations
  28635. * under the License.
  28636. */
  28637. SeriesModel.extend({
  28638. type: 'series.line',
  28639. dependencies: ['grid', 'polar'],
  28640. getInitialData: function (option, ecModel) {
  28641. if (__DEV__) {
  28642. var coordSys = option.coordinateSystem;
  28643. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  28644. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  28645. }
  28646. }
  28647. return createListFromArray(this.getSource(), this, {useEncodeDefaulter: true});
  28648. },
  28649. defaultOption: {
  28650. zlevel: 0,
  28651. z: 2,
  28652. coordinateSystem: 'cartesian2d',
  28653. legendHoverLink: true,
  28654. hoverAnimation: true,
  28655. // stack: null
  28656. // xAxisIndex: 0,
  28657. // yAxisIndex: 0,
  28658. // polarIndex: 0,
  28659. // If clip the overflow value
  28660. clip: true,
  28661. // cursor: null,
  28662. label: {
  28663. position: 'top'
  28664. },
  28665. // itemStyle: {
  28666. // },
  28667. lineStyle: {
  28668. width: 2,
  28669. type: 'solid'
  28670. },
  28671. // areaStyle: {
  28672. // origin of areaStyle. Valid values:
  28673. // `'auto'/null/undefined`: from axisLine to data
  28674. // `'start'`: from min to data
  28675. // `'end'`: from data to max
  28676. // origin: 'auto'
  28677. // },
  28678. // false, 'start', 'end', 'middle'
  28679. step: false,
  28680. // Disabled if step is true
  28681. smooth: false,
  28682. smoothMonotone: null,
  28683. symbol: 'emptyCircle',
  28684. symbolSize: 4,
  28685. symbolRotate: null,
  28686. showSymbol: true,
  28687. // `false`: follow the label interval strategy.
  28688. // `true`: show all symbols.
  28689. // `'auto'`: If possible, show all symbols, otherwise
  28690. // follow the label interval strategy.
  28691. showAllSymbol: 'auto',
  28692. // Whether to connect break point.
  28693. connectNulls: false,
  28694. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum'.
  28695. sampling: 'none',
  28696. animationEasing: 'linear',
  28697. // Disable progressive
  28698. progressive: 0,
  28699. hoverLayerThreshold: Infinity
  28700. }
  28701. });
  28702. /*
  28703. * Licensed to the Apache Software Foundation (ASF) under one
  28704. * or more contributor license agreements. See the NOTICE file
  28705. * distributed with this work for additional information
  28706. * regarding copyright ownership. The ASF licenses this file
  28707. * to you under the Apache License, Version 2.0 (the
  28708. * "License"); you may not use this file except in compliance
  28709. * with the License. You may obtain a copy of the License at
  28710. *
  28711. * http://www.apache.org/licenses/LICENSE-2.0
  28712. *
  28713. * Unless required by applicable law or agreed to in writing,
  28714. * software distributed under the License is distributed on an
  28715. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28716. * KIND, either express or implied. See the License for the
  28717. * specific language governing permissions and limitations
  28718. * under the License.
  28719. */
  28720. // Symbol factory
  28721. /**
  28722. * Triangle shape
  28723. * @inner
  28724. */
  28725. var Triangle = extendShape({
  28726. type: 'triangle',
  28727. shape: {
  28728. cx: 0,
  28729. cy: 0,
  28730. width: 0,
  28731. height: 0
  28732. },
  28733. buildPath: function (path, shape) {
  28734. var cx = shape.cx;
  28735. var cy = shape.cy;
  28736. var width = shape.width / 2;
  28737. var height = shape.height / 2;
  28738. path.moveTo(cx, cy - height);
  28739. path.lineTo(cx + width, cy + height);
  28740. path.lineTo(cx - width, cy + height);
  28741. path.closePath();
  28742. }
  28743. });
  28744. /**
  28745. * Diamond shape
  28746. * @inner
  28747. */
  28748. var Diamond = extendShape({
  28749. type: 'diamond',
  28750. shape: {
  28751. cx: 0,
  28752. cy: 0,
  28753. width: 0,
  28754. height: 0
  28755. },
  28756. buildPath: function (path, shape) {
  28757. var cx = shape.cx;
  28758. var cy = shape.cy;
  28759. var width = shape.width / 2;
  28760. var height = shape.height / 2;
  28761. path.moveTo(cx, cy - height);
  28762. path.lineTo(cx + width, cy);
  28763. path.lineTo(cx, cy + height);
  28764. path.lineTo(cx - width, cy);
  28765. path.closePath();
  28766. }
  28767. });
  28768. /**
  28769. * Pin shape
  28770. * @inner
  28771. */
  28772. var Pin = extendShape({
  28773. type: 'pin',
  28774. shape: {
  28775. // x, y on the cusp
  28776. x: 0,
  28777. y: 0,
  28778. width: 0,
  28779. height: 0
  28780. },
  28781. buildPath: function (path, shape) {
  28782. var x = shape.x;
  28783. var y = shape.y;
  28784. var w = shape.width / 5 * 3;
  28785. // Height must be larger than width
  28786. var h = Math.max(w, shape.height);
  28787. var r = w / 2;
  28788. // Dist on y with tangent point and circle center
  28789. var dy = r * r / (h - r);
  28790. var cy = y - h + r + dy;
  28791. var angle = Math.asin(dy / r);
  28792. // Dist on x with tangent point and circle center
  28793. var dx = Math.cos(angle) * r;
  28794. var tanX = Math.sin(angle);
  28795. var tanY = Math.cos(angle);
  28796. var cpLen = r * 0.6;
  28797. var cpLen2 = r * 0.7;
  28798. path.moveTo(x - dx, cy + dy);
  28799. path.arc(
  28800. x, cy, r,
  28801. Math.PI - angle,
  28802. Math.PI * 2 + angle
  28803. );
  28804. path.bezierCurveTo(
  28805. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  28806. x, y - cpLen2,
  28807. x, y
  28808. );
  28809. path.bezierCurveTo(
  28810. x, y - cpLen2,
  28811. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  28812. x - dx, cy + dy
  28813. );
  28814. path.closePath();
  28815. }
  28816. });
  28817. /**
  28818. * Arrow shape
  28819. * @inner
  28820. */
  28821. var Arrow = extendShape({
  28822. type: 'arrow',
  28823. shape: {
  28824. x: 0,
  28825. y: 0,
  28826. width: 0,
  28827. height: 0
  28828. },
  28829. buildPath: function (ctx, shape) {
  28830. var height = shape.height;
  28831. var width = shape.width;
  28832. var x = shape.x;
  28833. var y = shape.y;
  28834. var dx = width / 3 * 2;
  28835. ctx.moveTo(x, y);
  28836. ctx.lineTo(x + dx, y + height);
  28837. ctx.lineTo(x, y + height / 4 * 3);
  28838. ctx.lineTo(x - dx, y + height);
  28839. ctx.lineTo(x, y);
  28840. ctx.closePath();
  28841. }
  28842. });
  28843. /**
  28844. * Map of path contructors
  28845. * @type {Object.<string, module:zrender/graphic/Path>}
  28846. */
  28847. var symbolCtors = {
  28848. line: Line,
  28849. rect: Rect,
  28850. roundRect: Rect,
  28851. square: Rect,
  28852. circle: Circle,
  28853. diamond: Diamond,
  28854. pin: Pin,
  28855. arrow: Arrow,
  28856. triangle: Triangle
  28857. };
  28858. var symbolShapeMakers = {
  28859. line: function (x, y, w, h, shape) {
  28860. // FIXME
  28861. shape.x1 = x;
  28862. shape.y1 = y + h / 2;
  28863. shape.x2 = x + w;
  28864. shape.y2 = y + h / 2;
  28865. },
  28866. rect: function (x, y, w, h, shape) {
  28867. shape.x = x;
  28868. shape.y = y;
  28869. shape.width = w;
  28870. shape.height = h;
  28871. },
  28872. roundRect: function (x, y, w, h, shape) {
  28873. shape.x = x;
  28874. shape.y = y;
  28875. shape.width = w;
  28876. shape.height = h;
  28877. shape.r = Math.min(w, h) / 4;
  28878. },
  28879. square: function (x, y, w, h, shape) {
  28880. var size = Math.min(w, h);
  28881. shape.x = x;
  28882. shape.y = y;
  28883. shape.width = size;
  28884. shape.height = size;
  28885. },
  28886. circle: function (x, y, w, h, shape) {
  28887. // Put circle in the center of square
  28888. shape.cx = x + w / 2;
  28889. shape.cy = y + h / 2;
  28890. shape.r = Math.min(w, h) / 2;
  28891. },
  28892. diamond: function (x, y, w, h, shape) {
  28893. shape.cx = x + w / 2;
  28894. shape.cy = y + h / 2;
  28895. shape.width = w;
  28896. shape.height = h;
  28897. },
  28898. pin: function (x, y, w, h, shape) {
  28899. shape.x = x + w / 2;
  28900. shape.y = y + h / 2;
  28901. shape.width = w;
  28902. shape.height = h;
  28903. },
  28904. arrow: function (x, y, w, h, shape) {
  28905. shape.x = x + w / 2;
  28906. shape.y = y + h / 2;
  28907. shape.width = w;
  28908. shape.height = h;
  28909. },
  28910. triangle: function (x, y, w, h, shape) {
  28911. shape.cx = x + w / 2;
  28912. shape.cy = y + h / 2;
  28913. shape.width = w;
  28914. shape.height = h;
  28915. }
  28916. };
  28917. var symbolBuildProxies = {};
  28918. each$1(symbolCtors, function (Ctor, name) {
  28919. symbolBuildProxies[name] = new Ctor();
  28920. });
  28921. var SymbolClz$2 = extendShape({
  28922. type: 'symbol',
  28923. shape: {
  28924. symbolType: '',
  28925. x: 0,
  28926. y: 0,
  28927. width: 0,
  28928. height: 0
  28929. },
  28930. calculateTextPosition: function (out, style, rect) {
  28931. var res = calculateTextPosition(out, style, rect);
  28932. var shape = this.shape;
  28933. if (shape && shape.symbolType === 'pin' && style.textPosition === 'inside') {
  28934. res.y = rect.y + rect.height * 0.4;
  28935. }
  28936. return res;
  28937. },
  28938. buildPath: function (ctx, shape, inBundle) {
  28939. var symbolType = shape.symbolType;
  28940. if (symbolType !== 'none') {
  28941. var proxySymbol = symbolBuildProxies[symbolType];
  28942. if (!proxySymbol) {
  28943. // Default rect
  28944. symbolType = 'rect';
  28945. proxySymbol = symbolBuildProxies[symbolType];
  28946. }
  28947. symbolShapeMakers[symbolType](
  28948. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  28949. );
  28950. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  28951. }
  28952. }
  28953. });
  28954. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  28955. function symbolPathSetColor(color, innerColor) {
  28956. if (this.type !== 'image') {
  28957. var symbolStyle = this.style;
  28958. var symbolShape = this.shape;
  28959. if (symbolShape && symbolShape.symbolType === 'line') {
  28960. symbolStyle.stroke = color;
  28961. }
  28962. else if (this.__isEmptyBrush) {
  28963. symbolStyle.stroke = color;
  28964. symbolStyle.fill = innerColor || '#fff';
  28965. }
  28966. else {
  28967. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  28968. symbolStyle.fill && (symbolStyle.fill = color);
  28969. symbolStyle.stroke && (symbolStyle.stroke = color);
  28970. }
  28971. this.dirty(false);
  28972. }
  28973. }
  28974. /**
  28975. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  28976. * @param {string} symbolType
  28977. * @param {number} x
  28978. * @param {number} y
  28979. * @param {number} w
  28980. * @param {number} h
  28981. * @param {string} color
  28982. * @param {boolean} [keepAspect=false] whether to keep the ratio of w/h,
  28983. * for path and image only.
  28984. */
  28985. function createSymbol(symbolType, x, y, w, h, color, keepAspect) {
  28986. // TODO Support image object, DynamicImage.
  28987. var isEmpty = symbolType.indexOf('empty') === 0;
  28988. if (isEmpty) {
  28989. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  28990. }
  28991. var symbolPath;
  28992. if (symbolType.indexOf('image://') === 0) {
  28993. symbolPath = makeImage(
  28994. symbolType.slice(8),
  28995. new BoundingRect(x, y, w, h),
  28996. keepAspect ? 'center' : 'cover'
  28997. );
  28998. }
  28999. else if (symbolType.indexOf('path://') === 0) {
  29000. symbolPath = makePath(
  29001. symbolType.slice(7),
  29002. {},
  29003. new BoundingRect(x, y, w, h),
  29004. keepAspect ? 'center' : 'cover'
  29005. );
  29006. }
  29007. else {
  29008. symbolPath = new SymbolClz$2({
  29009. shape: {
  29010. symbolType: symbolType,
  29011. x: x,
  29012. y: y,
  29013. width: w,
  29014. height: h
  29015. }
  29016. });
  29017. }
  29018. symbolPath.__isEmptyBrush = isEmpty;
  29019. symbolPath.setColor = symbolPathSetColor;
  29020. symbolPath.setColor(color);
  29021. return symbolPath;
  29022. }
  29023. /*
  29024. * Licensed to the Apache Software Foundation (ASF) under one
  29025. * or more contributor license agreements. See the NOTICE file
  29026. * distributed with this work for additional information
  29027. * regarding copyright ownership. The ASF licenses this file
  29028. * to you under the Apache License, Version 2.0 (the
  29029. * "License"); you may not use this file except in compliance
  29030. * with the License. You may obtain a copy of the License at
  29031. *
  29032. * http://www.apache.org/licenses/LICENSE-2.0
  29033. *
  29034. * Unless required by applicable law or agreed to in writing,
  29035. * software distributed under the License is distributed on an
  29036. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29037. * KIND, either express or implied. See the License for the
  29038. * specific language governing permissions and limitations
  29039. * under the License.
  29040. */
  29041. /**
  29042. * @param {module:echarts/data/List} data
  29043. * @param {number} dataIndex
  29044. * @return {string} label string. Not null/undefined
  29045. */
  29046. function getDefaultLabel(data, dataIndex) {
  29047. var labelDims = data.mapDimension('defaultedLabel', true);
  29048. var len = labelDims.length;
  29049. // Simple optimization (in lots of cases, label dims length is 1)
  29050. if (len === 1) {
  29051. return retrieveRawValue(data, dataIndex, labelDims[0]);
  29052. }
  29053. else if (len) {
  29054. var vals = [];
  29055. for (var i = 0; i < labelDims.length; i++) {
  29056. var val = retrieveRawValue(data, dataIndex, labelDims[i]);
  29057. vals.push(val);
  29058. }
  29059. return vals.join(' ');
  29060. }
  29061. }
  29062. /*
  29063. * Licensed to the Apache Software Foundation (ASF) under one
  29064. * or more contributor license agreements. See the NOTICE file
  29065. * distributed with this work for additional information
  29066. * regarding copyright ownership. The ASF licenses this file
  29067. * to you under the Apache License, Version 2.0 (the
  29068. * "License"); you may not use this file except in compliance
  29069. * with the License. You may obtain a copy of the License at
  29070. *
  29071. * http://www.apache.org/licenses/LICENSE-2.0
  29072. *
  29073. * Unless required by applicable law or agreed to in writing,
  29074. * software distributed under the License is distributed on an
  29075. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29076. * KIND, either express or implied. See the License for the
  29077. * specific language governing permissions and limitations
  29078. * under the License.
  29079. */
  29080. /**
  29081. * @module echarts/chart/helper/Symbol
  29082. */
  29083. /**
  29084. * @constructor
  29085. * @alias {module:echarts/chart/helper/Symbol}
  29086. * @param {module:echarts/data/List} data
  29087. * @param {number} idx
  29088. * @extends {module:zrender/graphic/Group}
  29089. */
  29090. function SymbolClz(data, idx, seriesScope) {
  29091. Group.call(this);
  29092. this.updateData(data, idx, seriesScope);
  29093. }
  29094. var symbolProto = SymbolClz.prototype;
  29095. /**
  29096. * @public
  29097. * @static
  29098. * @param {module:echarts/data/List} data
  29099. * @param {number} dataIndex
  29100. * @return {Array.<number>} [width, height]
  29101. */
  29102. var getSymbolSize = SymbolClz.getSymbolSize = function (data, idx) {
  29103. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  29104. return symbolSize instanceof Array
  29105. ? symbolSize.slice()
  29106. : [+symbolSize, +symbolSize];
  29107. };
  29108. function getScale(symbolSize) {
  29109. return [symbolSize[0] / 2, symbolSize[1] / 2];
  29110. }
  29111. function driftSymbol(dx, dy) {
  29112. this.parent.drift(dx, dy);
  29113. }
  29114. symbolProto._createSymbol = function (
  29115. symbolType,
  29116. data,
  29117. idx,
  29118. symbolSize,
  29119. keepAspect
  29120. ) {
  29121. // Remove paths created before
  29122. this.removeAll();
  29123. var color = data.getItemVisual(idx, 'color');
  29124. // var symbolPath = createSymbol(
  29125. // symbolType, -0.5, -0.5, 1, 1, color
  29126. // );
  29127. // If width/height are set too small (e.g., set to 1) on ios10
  29128. // and macOS Sierra, a circle stroke become a rect, no matter what
  29129. // the scale is set. So we set width/height as 2. See #4150.
  29130. var symbolPath = createSymbol(
  29131. symbolType, -1, -1, 2, 2, color, keepAspect
  29132. );
  29133. symbolPath.attr({
  29134. z2: 100,
  29135. culling: true,
  29136. scale: getScale(symbolSize)
  29137. });
  29138. // Rewrite drift method
  29139. symbolPath.drift = driftSymbol;
  29140. this._symbolType = symbolType;
  29141. this.add(symbolPath);
  29142. };
  29143. /**
  29144. * Stop animation
  29145. * @param {boolean} toLastFrame
  29146. */
  29147. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  29148. this.childAt(0).stopAnimation(toLastFrame);
  29149. };
  29150. /**
  29151. * FIXME:
  29152. * Caution: This method breaks the encapsulation of this module,
  29153. * but it indeed brings convenience. So do not use the method
  29154. * unless you detailedly know all the implements of `Symbol`,
  29155. * especially animation.
  29156. *
  29157. * Get symbol path element.
  29158. */
  29159. symbolProto.getSymbolPath = function () {
  29160. return this.childAt(0);
  29161. };
  29162. /**
  29163. * Get scale(aka, current symbol size).
  29164. * Including the change caused by animation
  29165. */
  29166. symbolProto.getScale = function () {
  29167. return this.childAt(0).scale;
  29168. };
  29169. /**
  29170. * Highlight symbol
  29171. */
  29172. symbolProto.highlight = function () {
  29173. this.childAt(0).trigger('emphasis');
  29174. };
  29175. /**
  29176. * Downplay symbol
  29177. */
  29178. symbolProto.downplay = function () {
  29179. this.childAt(0).trigger('normal');
  29180. };
  29181. /**
  29182. * @param {number} zlevel
  29183. * @param {number} z
  29184. */
  29185. symbolProto.setZ = function (zlevel, z) {
  29186. var symbolPath = this.childAt(0);
  29187. symbolPath.zlevel = zlevel;
  29188. symbolPath.z = z;
  29189. };
  29190. symbolProto.setDraggable = function (draggable) {
  29191. var symbolPath = this.childAt(0);
  29192. symbolPath.draggable = draggable;
  29193. symbolPath.cursor = draggable ? 'move' : symbolPath.cursor;
  29194. };
  29195. /**
  29196. * Update symbol properties
  29197. * @param {module:echarts/data/List} data
  29198. * @param {number} idx
  29199. * @param {Object} [seriesScope]
  29200. * @param {Object} [seriesScope.itemStyle]
  29201. * @param {Object} [seriesScope.hoverItemStyle]
  29202. * @param {Object} [seriesScope.symbolRotate]
  29203. * @param {Object} [seriesScope.symbolOffset]
  29204. * @param {module:echarts/model/Model} [seriesScope.labelModel]
  29205. * @param {module:echarts/model/Model} [seriesScope.hoverLabelModel]
  29206. * @param {boolean} [seriesScope.hoverAnimation]
  29207. * @param {Object} [seriesScope.cursorStyle]
  29208. * @param {module:echarts/model/Model} [seriesScope.itemModel]
  29209. * @param {string} [seriesScope.symbolInnerColor]
  29210. * @param {Object} [seriesScope.fadeIn=false]
  29211. */
  29212. symbolProto.updateData = function (data, idx, seriesScope) {
  29213. this.silent = false;
  29214. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  29215. var seriesModel = data.hostModel;
  29216. var symbolSize = getSymbolSize(data, idx);
  29217. var isInit = symbolType !== this._symbolType;
  29218. if (isInit) {
  29219. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  29220. this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
  29221. }
  29222. else {
  29223. var symbolPath = this.childAt(0);
  29224. symbolPath.silent = false;
  29225. updateProps(symbolPath, {
  29226. scale: getScale(symbolSize)
  29227. }, seriesModel, idx);
  29228. }
  29229. this._updateCommon(data, idx, symbolSize, seriesScope);
  29230. if (isInit) {
  29231. var symbolPath = this.childAt(0);
  29232. var fadeIn = seriesScope && seriesScope.fadeIn;
  29233. var target = {scale: symbolPath.scale.slice()};
  29234. fadeIn && (target.style = {opacity: symbolPath.style.opacity});
  29235. symbolPath.scale = [0, 0];
  29236. fadeIn && (symbolPath.style.opacity = 0);
  29237. initProps(symbolPath, target, seriesModel, idx);
  29238. }
  29239. this._seriesModel = seriesModel;
  29240. };
  29241. // Update common properties
  29242. var normalStyleAccessPath = ['itemStyle'];
  29243. var emphasisStyleAccessPath = ['emphasis', 'itemStyle'];
  29244. var normalLabelAccessPath = ['label'];
  29245. var emphasisLabelAccessPath = ['emphasis', 'label'];
  29246. /**
  29247. * @param {module:echarts/data/List} data
  29248. * @param {number} idx
  29249. * @param {Array.<number>} symbolSize
  29250. * @param {Object} [seriesScope]
  29251. */
  29252. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  29253. var symbolPath = this.childAt(0);
  29254. var seriesModel = data.hostModel;
  29255. var color = data.getItemVisual(idx, 'color');
  29256. // Reset style
  29257. if (symbolPath.type !== 'image') {
  29258. symbolPath.useStyle({
  29259. strokeNoScale: true
  29260. });
  29261. }
  29262. else {
  29263. symbolPath.setStyle({
  29264. opacity: 1,
  29265. shadowBlur: null,
  29266. shadowOffsetX: null,
  29267. shadowOffsetY: null,
  29268. shadowColor: null
  29269. });
  29270. }
  29271. var itemStyle = seriesScope && seriesScope.itemStyle;
  29272. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  29273. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  29274. var labelModel = seriesScope && seriesScope.labelModel;
  29275. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  29276. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  29277. var cursorStyle = seriesScope && seriesScope.cursorStyle;
  29278. if (!seriesScope || data.hasItemOption) {
  29279. var itemModel = (seriesScope && seriesScope.itemModel)
  29280. ? seriesScope.itemModel : data.getItemModel(idx);
  29281. // Color must be excluded.
  29282. // Because symbol provide setColor individually to set fill and stroke
  29283. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  29284. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  29285. symbolOffset = itemModel.getShallow('symbolOffset');
  29286. labelModel = itemModel.getModel(normalLabelAccessPath);
  29287. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  29288. hoverAnimation = itemModel.getShallow('hoverAnimation');
  29289. cursorStyle = itemModel.getShallow('cursor');
  29290. }
  29291. else {
  29292. hoverItemStyle = extend({}, hoverItemStyle);
  29293. }
  29294. var elStyle = symbolPath.style;
  29295. var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
  29296. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  29297. if (symbolOffset) {
  29298. symbolPath.attr('position', [
  29299. parsePercent$1(symbolOffset[0], symbolSize[0]),
  29300. parsePercent$1(symbolOffset[1], symbolSize[1])
  29301. ]);
  29302. }
  29303. cursorStyle && symbolPath.attr('cursor', cursorStyle);
  29304. // PENDING setColor before setStyle!!!
  29305. symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
  29306. symbolPath.setStyle(itemStyle);
  29307. var opacity = data.getItemVisual(idx, 'opacity');
  29308. if (opacity != null) {
  29309. elStyle.opacity = opacity;
  29310. }
  29311. var liftZ = data.getItemVisual(idx, 'liftZ');
  29312. var z2Origin = symbolPath.__z2Origin;
  29313. if (liftZ != null) {
  29314. if (z2Origin == null) {
  29315. symbolPath.__z2Origin = symbolPath.z2;
  29316. symbolPath.z2 += liftZ;
  29317. }
  29318. }
  29319. else if (z2Origin != null) {
  29320. symbolPath.z2 = z2Origin;
  29321. symbolPath.__z2Origin = null;
  29322. }
  29323. var useNameLabel = seriesScope && seriesScope.useNameLabel;
  29324. setLabelStyle(
  29325. elStyle, hoverItemStyle, labelModel, hoverLabelModel,
  29326. {
  29327. labelFetcher: seriesModel,
  29328. labelDataIndex: idx,
  29329. defaultText: getLabelDefaultText,
  29330. isRectText: true,
  29331. autoColor: color
  29332. }
  29333. );
  29334. // Do not execute util needed.
  29335. function getLabelDefaultText(idx, opt) {
  29336. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  29337. }
  29338. symbolPath.__symbolOriginalScale = getScale(symbolSize);
  29339. symbolPath.hoverStyle = hoverItemStyle;
  29340. symbolPath.highDownOnUpdate = (
  29341. hoverAnimation && seriesModel.isAnimationEnabled()
  29342. ) ? highDownOnUpdate : null;
  29343. setHoverStyle(symbolPath);
  29344. };
  29345. function highDownOnUpdate(fromState, toState) {
  29346. // Do not support this hover animation util some scenario required.
  29347. // Animation can only be supported in hover layer when using `el.incremetal`.
  29348. if (this.incremental || this.useHoverLayer) {
  29349. return;
  29350. }
  29351. if (toState === 'emphasis') {
  29352. var scale = this.__symbolOriginalScale;
  29353. var ratio = scale[1] / scale[0];
  29354. var emphasisOpt = {
  29355. scale: [
  29356. Math.max(scale[0] * 1.1, scale[0] + 3),
  29357. Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)
  29358. ]
  29359. };
  29360. // FIXME
  29361. // modify it after support stop specified animation.
  29362. // toState === fromState
  29363. // ? (this.stopAnimation(), this.attr(emphasisOpt))
  29364. this.animateTo(emphasisOpt, 400, 'elasticOut');
  29365. }
  29366. else if (toState === 'normal') {
  29367. this.animateTo({
  29368. scale: this.__symbolOriginalScale
  29369. }, 400, 'elasticOut');
  29370. }
  29371. }
  29372. /**
  29373. * @param {Function} cb
  29374. * @param {Object} [opt]
  29375. * @param {Object} [opt.keepLabel=true]
  29376. */
  29377. symbolProto.fadeOut = function (cb, opt) {
  29378. var symbolPath = this.childAt(0);
  29379. // Avoid mistaken hover when fading out
  29380. this.silent = symbolPath.silent = true;
  29381. // Not show text when animating
  29382. !(opt && opt.keepLabel) && (symbolPath.style.text = null);
  29383. updateProps(
  29384. symbolPath,
  29385. {
  29386. style: {opacity: 0},
  29387. scale: [0, 0]
  29388. },
  29389. this._seriesModel,
  29390. this.dataIndex,
  29391. cb
  29392. );
  29393. };
  29394. inherits(SymbolClz, Group);
  29395. /*
  29396. * Licensed to the Apache Software Foundation (ASF) under one
  29397. * or more contributor license agreements. See the NOTICE file
  29398. * distributed with this work for additional information
  29399. * regarding copyright ownership. The ASF licenses this file
  29400. * to you under the Apache License, Version 2.0 (the
  29401. * "License"); you may not use this file except in compliance
  29402. * with the License. You may obtain a copy of the License at
  29403. *
  29404. * http://www.apache.org/licenses/LICENSE-2.0
  29405. *
  29406. * Unless required by applicable law or agreed to in writing,
  29407. * software distributed under the License is distributed on an
  29408. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29409. * KIND, either express or implied. See the License for the
  29410. * specific language governing permissions and limitations
  29411. * under the License.
  29412. */
  29413. /**
  29414. * @module echarts/chart/helper/SymbolDraw
  29415. */
  29416. /**
  29417. * @constructor
  29418. * @alias module:echarts/chart/helper/SymbolDraw
  29419. * @param {module:zrender/graphic/Group} [symbolCtor]
  29420. */
  29421. function SymbolDraw(symbolCtor) {
  29422. this.group = new Group();
  29423. this._symbolCtor = symbolCtor || SymbolClz;
  29424. }
  29425. var symbolDrawProto = SymbolDraw.prototype;
  29426. function symbolNeedsDraw(data, point, idx, opt) {
  29427. return point && !isNaN(point[0]) && !isNaN(point[1])
  29428. && !(opt.isIgnore && opt.isIgnore(idx))
  29429. // We do not set clipShape on group, because it will cut part of
  29430. // the symbol element shape. We use the same clip shape here as
  29431. // the line clip.
  29432. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1]))
  29433. && data.getItemVisual(idx, 'symbol') !== 'none';
  29434. }
  29435. /**
  29436. * Update symbols draw by new data
  29437. * @param {module:echarts/data/List} data
  29438. * @param {Object} [opt] Or isIgnore
  29439. * @param {Function} [opt.isIgnore]
  29440. * @param {Object} [opt.clipShape]
  29441. */
  29442. symbolDrawProto.updateData = function (data, opt) {
  29443. opt = normalizeUpdateOpt(opt);
  29444. var group = this.group;
  29445. var seriesModel = data.hostModel;
  29446. var oldData = this._data;
  29447. var SymbolCtor = this._symbolCtor;
  29448. var seriesScope = makeSeriesScope(data);
  29449. // There is no oldLineData only when first rendering or switching from
  29450. // stream mode to normal mode, where previous elements should be removed.
  29451. if (!oldData) {
  29452. group.removeAll();
  29453. }
  29454. data.diff(oldData)
  29455. .add(function (newIdx) {
  29456. var point = data.getItemLayout(newIdx);
  29457. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  29458. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  29459. symbolEl.attr('position', point);
  29460. data.setItemGraphicEl(newIdx, symbolEl);
  29461. group.add(symbolEl);
  29462. }
  29463. })
  29464. .update(function (newIdx, oldIdx) {
  29465. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  29466. var point = data.getItemLayout(newIdx);
  29467. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  29468. group.remove(symbolEl);
  29469. return;
  29470. }
  29471. if (!symbolEl) {
  29472. symbolEl = new SymbolCtor(data, newIdx);
  29473. symbolEl.attr('position', point);
  29474. }
  29475. else {
  29476. symbolEl.updateData(data, newIdx, seriesScope);
  29477. updateProps(symbolEl, {
  29478. position: point
  29479. }, seriesModel);
  29480. }
  29481. // Add back
  29482. group.add(symbolEl);
  29483. data.setItemGraphicEl(newIdx, symbolEl);
  29484. })
  29485. .remove(function (oldIdx) {
  29486. var el = oldData.getItemGraphicEl(oldIdx);
  29487. el && el.fadeOut(function () {
  29488. group.remove(el);
  29489. });
  29490. })
  29491. .execute();
  29492. this._data = data;
  29493. };
  29494. symbolDrawProto.isPersistent = function () {
  29495. return true;
  29496. };
  29497. symbolDrawProto.updateLayout = function () {
  29498. var data = this._data;
  29499. if (data) {
  29500. // Not use animation
  29501. data.eachItemGraphicEl(function (el, idx) {
  29502. var point = data.getItemLayout(idx);
  29503. el.attr('position', point);
  29504. });
  29505. }
  29506. };
  29507. symbolDrawProto.incrementalPrepareUpdate = function (data) {
  29508. this._seriesScope = makeSeriesScope(data);
  29509. this._data = null;
  29510. this.group.removeAll();
  29511. };
  29512. /**
  29513. * Update symbols draw by new data
  29514. * @param {module:echarts/data/List} data
  29515. * @param {Object} [opt] Or isIgnore
  29516. * @param {Function} [opt.isIgnore]
  29517. * @param {Object} [opt.clipShape]
  29518. */
  29519. symbolDrawProto.incrementalUpdate = function (taskParams, data, opt) {
  29520. opt = normalizeUpdateOpt(opt);
  29521. function updateIncrementalAndHover(el) {
  29522. if (!el.isGroup) {
  29523. el.incremental = el.useHoverLayer = true;
  29524. }
  29525. }
  29526. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  29527. var point = data.getItemLayout(idx);
  29528. if (symbolNeedsDraw(data, point, idx, opt)) {
  29529. var el = new this._symbolCtor(data, idx, this._seriesScope);
  29530. el.traverse(updateIncrementalAndHover);
  29531. el.attr('position', point);
  29532. this.group.add(el);
  29533. data.setItemGraphicEl(idx, el);
  29534. }
  29535. }
  29536. };
  29537. function normalizeUpdateOpt(opt) {
  29538. if (opt != null && !isObject$1(opt)) {
  29539. opt = {isIgnore: opt};
  29540. }
  29541. return opt || {};
  29542. }
  29543. symbolDrawProto.remove = function (enableAnimation) {
  29544. var group = this.group;
  29545. var data = this._data;
  29546. // Incremental model do not have this._data.
  29547. if (data && enableAnimation) {
  29548. data.eachItemGraphicEl(function (el) {
  29549. el.fadeOut(function () {
  29550. group.remove(el);
  29551. });
  29552. });
  29553. }
  29554. else {
  29555. group.removeAll();
  29556. }
  29557. };
  29558. function makeSeriesScope(data) {
  29559. var seriesModel = data.hostModel;
  29560. return {
  29561. itemStyle: seriesModel.getModel('itemStyle').getItemStyle(['color']),
  29562. hoverItemStyle: seriesModel.getModel('emphasis.itemStyle').getItemStyle(),
  29563. symbolRotate: seriesModel.get('symbolRotate'),
  29564. symbolOffset: seriesModel.get('symbolOffset'),
  29565. hoverAnimation: seriesModel.get('hoverAnimation'),
  29566. labelModel: seriesModel.getModel('label'),
  29567. hoverLabelModel: seriesModel.getModel('emphasis.label'),
  29568. cursorStyle: seriesModel.get('cursor')
  29569. };
  29570. }
  29571. /*
  29572. * Licensed to the Apache Software Foundation (ASF) under one
  29573. * or more contributor license agreements. See the NOTICE file
  29574. * distributed with this work for additional information
  29575. * regarding copyright ownership. The ASF licenses this file
  29576. * to you under the Apache License, Version 2.0 (the
  29577. * "License"); you may not use this file except in compliance
  29578. * with the License. You may obtain a copy of the License at
  29579. *
  29580. * http://www.apache.org/licenses/LICENSE-2.0
  29581. *
  29582. * Unless required by applicable law or agreed to in writing,
  29583. * software distributed under the License is distributed on an
  29584. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29585. * KIND, either express or implied. See the License for the
  29586. * specific language governing permissions and limitations
  29587. * under the License.
  29588. */
  29589. /**
  29590. * @param {Object} coordSys
  29591. * @param {module:echarts/data/List} data
  29592. * @param {string} valueOrigin lineSeries.option.areaStyle.origin
  29593. */
  29594. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  29595. var baseAxis = coordSys.getBaseAxis();
  29596. var valueAxis = coordSys.getOtherAxis(baseAxis);
  29597. var valueStart = getValueStart(valueAxis, valueOrigin);
  29598. var baseAxisDim = baseAxis.dim;
  29599. var valueAxisDim = valueAxis.dim;
  29600. var valueDim = data.mapDimension(valueAxisDim);
  29601. var baseDim = data.mapDimension(baseAxisDim);
  29602. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  29603. var dims = map(coordSys.dimensions, function (coordDim) {
  29604. return data.mapDimension(coordDim);
  29605. });
  29606. var stacked;
  29607. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  29608. if (stacked |= isDimensionStacked(data, dims[0] /*, dims[1]*/)) { // jshint ignore:line
  29609. dims[0] = stackResultDim;
  29610. }
  29611. if (stacked |= isDimensionStacked(data, dims[1] /*, dims[0]*/)) { // jshint ignore:line
  29612. dims[1] = stackResultDim;
  29613. }
  29614. return {
  29615. dataDimsForPoint: dims,
  29616. valueStart: valueStart,
  29617. valueAxisDim: valueAxisDim,
  29618. baseAxisDim: baseAxisDim,
  29619. stacked: !!stacked,
  29620. valueDim: valueDim,
  29621. baseDim: baseDim,
  29622. baseDataOffset: baseDataOffset,
  29623. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  29624. };
  29625. }
  29626. function getValueStart(valueAxis, valueOrigin) {
  29627. var valueStart = 0;
  29628. var extent = valueAxis.scale.getExtent();
  29629. if (valueOrigin === 'start') {
  29630. valueStart = extent[0];
  29631. }
  29632. else if (valueOrigin === 'end') {
  29633. valueStart = extent[1];
  29634. }
  29635. // auto
  29636. else {
  29637. // Both positive
  29638. if (extent[0] > 0) {
  29639. valueStart = extent[0];
  29640. }
  29641. // Both negative
  29642. else if (extent[1] < 0) {
  29643. valueStart = extent[1];
  29644. }
  29645. // If is one positive, and one negative, onZero shall be true
  29646. }
  29647. return valueStart;
  29648. }
  29649. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  29650. var value = NaN;
  29651. if (dataCoordInfo.stacked) {
  29652. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  29653. }
  29654. if (isNaN(value)) {
  29655. value = dataCoordInfo.valueStart;
  29656. }
  29657. var baseDataOffset = dataCoordInfo.baseDataOffset;
  29658. var stackedData = [];
  29659. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  29660. stackedData[1 - baseDataOffset] = value;
  29661. return coordSys.dataToPoint(stackedData);
  29662. }
  29663. /*
  29664. * Licensed to the Apache Software Foundation (ASF) under one
  29665. * or more contributor license agreements. See the NOTICE file
  29666. * distributed with this work for additional information
  29667. * regarding copyright ownership. The ASF licenses this file
  29668. * to you under the Apache License, Version 2.0 (the
  29669. * "License"); you may not use this file except in compliance
  29670. * with the License. You may obtain a copy of the License at
  29671. *
  29672. * http://www.apache.org/licenses/LICENSE-2.0
  29673. *
  29674. * Unless required by applicable law or agreed to in writing,
  29675. * software distributed under the License is distributed on an
  29676. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29677. * KIND, either express or implied. See the License for the
  29678. * specific language governing permissions and limitations
  29679. * under the License.
  29680. */
  29681. // var arrayDiff = require('zrender/src/core/arrayDiff');
  29682. // 'zrender/src/core/arrayDiff' has been used before, but it did
  29683. // not do well in performance when roam with fixed dataZoom window.
  29684. // function convertToIntId(newIdList, oldIdList) {
  29685. // // Generate int id instead of string id.
  29686. // // Compare string maybe slow in score function of arrDiff
  29687. // // Assume id in idList are all unique
  29688. // var idIndicesMap = {};
  29689. // var idx = 0;
  29690. // for (var i = 0; i < newIdList.length; i++) {
  29691. // idIndicesMap[newIdList[i]] = idx;
  29692. // newIdList[i] = idx++;
  29693. // }
  29694. // for (var i = 0; i < oldIdList.length; i++) {
  29695. // var oldId = oldIdList[i];
  29696. // // Same with newIdList
  29697. // if (idIndicesMap[oldId]) {
  29698. // oldIdList[i] = idIndicesMap[oldId];
  29699. // }
  29700. // else {
  29701. // oldIdList[i] = idx++;
  29702. // }
  29703. // }
  29704. // }
  29705. function diffData(oldData, newData) {
  29706. var diffResult = [];
  29707. newData.diff(oldData)
  29708. .add(function (idx) {
  29709. diffResult.push({cmd: '+', idx: idx});
  29710. })
  29711. .update(function (newIdx, oldIdx) {
  29712. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  29713. })
  29714. .remove(function (idx) {
  29715. diffResult.push({cmd: '-', idx: idx});
  29716. })
  29717. .execute();
  29718. return diffResult;
  29719. }
  29720. var lineAnimationDiff = function (
  29721. oldData, newData,
  29722. oldStackedOnPoints, newStackedOnPoints,
  29723. oldCoordSys, newCoordSys,
  29724. oldValueOrigin, newValueOrigin
  29725. ) {
  29726. var diff = diffData(oldData, newData);
  29727. // var newIdList = newData.mapArray(newData.getId);
  29728. // var oldIdList = oldData.mapArray(oldData.getId);
  29729. // convertToIntId(newIdList, oldIdList);
  29730. // // FIXME One data ?
  29731. // diff = arrayDiff(oldIdList, newIdList);
  29732. var currPoints = [];
  29733. var nextPoints = [];
  29734. // Points for stacking base line
  29735. var currStackedPoints = [];
  29736. var nextStackedPoints = [];
  29737. var status = [];
  29738. var sortedIndices = [];
  29739. var rawIndices = [];
  29740. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  29741. var oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  29742. for (var i = 0; i < diff.length; i++) {
  29743. var diffItem = diff[i];
  29744. var pointAdded = true;
  29745. // FIXME, animation is not so perfect when dataZoom window moves fast
  29746. // Which is in case remvoing or add more than one data in the tail or head
  29747. switch (diffItem.cmd) {
  29748. case '=':
  29749. var currentPt = oldData.getItemLayout(diffItem.idx);
  29750. var nextPt = newData.getItemLayout(diffItem.idx1);
  29751. // If previous data is NaN, use next point directly
  29752. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  29753. currentPt = nextPt.slice();
  29754. }
  29755. currPoints.push(currentPt);
  29756. nextPoints.push(nextPt);
  29757. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  29758. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  29759. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  29760. break;
  29761. case '+':
  29762. var idx = diffItem.idx;
  29763. currPoints.push(
  29764. oldCoordSys.dataToPoint([
  29765. newData.get(newDataOldCoordInfo.dataDimsForPoint[0], idx),
  29766. newData.get(newDataOldCoordInfo.dataDimsForPoint[1], idx)
  29767. ])
  29768. );
  29769. nextPoints.push(newData.getItemLayout(idx).slice());
  29770. currStackedPoints.push(
  29771. getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, idx)
  29772. );
  29773. nextStackedPoints.push(newStackedOnPoints[idx]);
  29774. rawIndices.push(newData.getRawIndex(idx));
  29775. break;
  29776. case '-':
  29777. var idx = diffItem.idx;
  29778. var rawIndex = oldData.getRawIndex(idx);
  29779. // Data is replaced. In the case of dynamic data queue
  29780. // FIXME FIXME FIXME
  29781. if (rawIndex !== idx) {
  29782. currPoints.push(oldData.getItemLayout(idx));
  29783. nextPoints.push(newCoordSys.dataToPoint([
  29784. oldData.get(oldDataNewCoordInfo.dataDimsForPoint[0], idx),
  29785. oldData.get(oldDataNewCoordInfo.dataDimsForPoint[1], idx)
  29786. ]));
  29787. currStackedPoints.push(oldStackedOnPoints[idx]);
  29788. nextStackedPoints.push(
  29789. getStackedOnPoint(oldDataNewCoordInfo, newCoordSys, oldData, idx)
  29790. );
  29791. rawIndices.push(rawIndex);
  29792. }
  29793. else {
  29794. pointAdded = false;
  29795. }
  29796. }
  29797. // Original indices
  29798. if (pointAdded) {
  29799. status.push(diffItem);
  29800. sortedIndices.push(sortedIndices.length);
  29801. }
  29802. }
  29803. // Diff result may be crossed if all items are changed
  29804. // Sort by data index
  29805. sortedIndices.sort(function (a, b) {
  29806. return rawIndices[a] - rawIndices[b];
  29807. });
  29808. var sortedCurrPoints = [];
  29809. var sortedNextPoints = [];
  29810. var sortedCurrStackedPoints = [];
  29811. var sortedNextStackedPoints = [];
  29812. var sortedStatus = [];
  29813. for (var i = 0; i < sortedIndices.length; i++) {
  29814. var idx = sortedIndices[i];
  29815. sortedCurrPoints[i] = currPoints[idx];
  29816. sortedNextPoints[i] = nextPoints[idx];
  29817. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  29818. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  29819. sortedStatus[i] = status[idx];
  29820. }
  29821. return {
  29822. current: sortedCurrPoints,
  29823. next: sortedNextPoints,
  29824. stackedOnCurrent: sortedCurrStackedPoints,
  29825. stackedOnNext: sortedNextStackedPoints,
  29826. status: sortedStatus
  29827. };
  29828. };
  29829. /*
  29830. * Licensed to the Apache Software Foundation (ASF) under one
  29831. * or more contributor license agreements. See the NOTICE file
  29832. * distributed with this work for additional information
  29833. * regarding copyright ownership. The ASF licenses this file
  29834. * to you under the Apache License, Version 2.0 (the
  29835. * "License"); you may not use this file except in compliance
  29836. * with the License. You may obtain a copy of the License at
  29837. *
  29838. * http://www.apache.org/licenses/LICENSE-2.0
  29839. *
  29840. * Unless required by applicable law or agreed to in writing,
  29841. * software distributed under the License is distributed on an
  29842. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29843. * KIND, either express or implied. See the License for the
  29844. * specific language governing permissions and limitations
  29845. * under the License.
  29846. */
  29847. // Poly path support NaN point
  29848. var vec2Min = min;
  29849. var vec2Max = max;
  29850. var scaleAndAdd$1 = scaleAndAdd;
  29851. var v2Copy = copy;
  29852. // Temporary variable
  29853. var v = [];
  29854. var cp0 = [];
  29855. var cp1 = [];
  29856. function isPointNull(p) {
  29857. return isNaN(p[0]) || isNaN(p[1]);
  29858. }
  29859. function drawSegment(
  29860. ctx, points, start, segLen, allLen,
  29861. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  29862. ) {
  29863. // if (smoothMonotone == null) {
  29864. // if (isMono(points, 'x')) {
  29865. // return drawMono(ctx, points, start, segLen, allLen,
  29866. // dir, smoothMin, smoothMax, smooth, 'x', connectNulls);
  29867. // }
  29868. // else if (isMono(points, 'y')) {
  29869. // return drawMono(ctx, points, start, segLen, allLen,
  29870. // dir, smoothMin, smoothMax, smooth, 'y', connectNulls);
  29871. // }
  29872. // else {
  29873. // return drawNonMono.apply(this, arguments);
  29874. // }
  29875. // }
  29876. // else if (smoothMonotone !== 'none' && isMono(points, smoothMonotone)) {
  29877. // return drawMono.apply(this, arguments);
  29878. // }
  29879. // else {
  29880. // return drawNonMono.apply(this, arguments);
  29881. // }
  29882. if (smoothMonotone === 'none' || !smoothMonotone) {
  29883. return drawNonMono.apply(this, arguments);
  29884. }
  29885. else {
  29886. return drawMono.apply(this, arguments);
  29887. }
  29888. }
  29889. /**
  29890. * Check if points is in monotone.
  29891. *
  29892. * @param {number[][]} points Array of points which is in [x, y] form
  29893. * @param {string} smoothMonotone 'x', 'y', or 'none', stating for which
  29894. * dimension that is checking.
  29895. * If is 'none', `drawNonMono` should be
  29896. * called.
  29897. * If is undefined, either being monotone
  29898. * in 'x' or 'y' will call `drawMono`.
  29899. */
  29900. // function isMono(points, smoothMonotone) {
  29901. // if (points.length <= 1) {
  29902. // return true;
  29903. // }
  29904. // var dim = smoothMonotone === 'x' ? 0 : 1;
  29905. // var last = points[0][dim];
  29906. // var lastDiff = 0;
  29907. // for (var i = 1; i < points.length; ++i) {
  29908. // var diff = points[i][dim] - last;
  29909. // if (!isNaN(diff) && !isNaN(lastDiff)
  29910. // && diff !== 0 && lastDiff !== 0
  29911. // && ((diff >= 0) !== (lastDiff >= 0))
  29912. // ) {
  29913. // return false;
  29914. // }
  29915. // if (!isNaN(diff) && diff !== 0) {
  29916. // lastDiff = diff;
  29917. // last = points[i][dim];
  29918. // }
  29919. // }
  29920. // return true;
  29921. // }
  29922. /**
  29923. * Draw smoothed line in monotone, in which only vertical or horizontal bezier
  29924. * control points will be used. This should be used when points are monotone
  29925. * either in x or y dimension.
  29926. */
  29927. function drawMono(
  29928. ctx, points, start, segLen, allLen,
  29929. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  29930. ) {
  29931. var prevIdx = 0;
  29932. var idx = start;
  29933. for (var k = 0; k < segLen; k++) {
  29934. var p = points[idx];
  29935. if (idx >= allLen || idx < 0) {
  29936. break;
  29937. }
  29938. if (isPointNull(p)) {
  29939. if (connectNulls) {
  29940. idx += dir;
  29941. continue;
  29942. }
  29943. break;
  29944. }
  29945. if (idx === start) {
  29946. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  29947. }
  29948. else {
  29949. if (smooth > 0) {
  29950. var prevP = points[prevIdx];
  29951. var dim = smoothMonotone === 'y' ? 1 : 0;
  29952. // Length of control point to p, either in x or y, but not both
  29953. var ctrlLen = (p[dim] - prevP[dim]) * smooth;
  29954. v2Copy(cp0, prevP);
  29955. cp0[dim] = prevP[dim] + ctrlLen;
  29956. v2Copy(cp1, p);
  29957. cp1[dim] = p[dim] - ctrlLen;
  29958. ctx.bezierCurveTo(
  29959. cp0[0], cp0[1],
  29960. cp1[0], cp1[1],
  29961. p[0], p[1]
  29962. );
  29963. }
  29964. else {
  29965. ctx.lineTo(p[0], p[1]);
  29966. }
  29967. }
  29968. prevIdx = idx;
  29969. idx += dir;
  29970. }
  29971. return k;
  29972. }
  29973. /**
  29974. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  29975. * situations. This should be used when points are non-monotone neither in x or
  29976. * y dimension.
  29977. */
  29978. function drawNonMono(
  29979. ctx, points, start, segLen, allLen,
  29980. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  29981. ) {
  29982. var prevIdx = 0;
  29983. var idx = start;
  29984. for (var k = 0; k < segLen; k++) {
  29985. var p = points[idx];
  29986. if (idx >= allLen || idx < 0) {
  29987. break;
  29988. }
  29989. if (isPointNull(p)) {
  29990. if (connectNulls) {
  29991. idx += dir;
  29992. continue;
  29993. }
  29994. break;
  29995. }
  29996. if (idx === start) {
  29997. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  29998. v2Copy(cp0, p);
  29999. }
  30000. else {
  30001. if (smooth > 0) {
  30002. var nextIdx = idx + dir;
  30003. var nextP = points[nextIdx];
  30004. if (connectNulls) {
  30005. // Find next point not null
  30006. while (nextP && isPointNull(points[nextIdx])) {
  30007. nextIdx += dir;
  30008. nextP = points[nextIdx];
  30009. }
  30010. }
  30011. var ratioNextSeg = 0.5;
  30012. var prevP = points[prevIdx];
  30013. var nextP = points[nextIdx];
  30014. // Last point
  30015. if (!nextP || isPointNull(nextP)) {
  30016. v2Copy(cp1, p);
  30017. }
  30018. else {
  30019. // If next data is null in not connect case
  30020. if (isPointNull(nextP) && !connectNulls) {
  30021. nextP = p;
  30022. }
  30023. sub(v, nextP, prevP);
  30024. var lenPrevSeg;
  30025. var lenNextSeg;
  30026. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  30027. var dim = smoothMonotone === 'x' ? 0 : 1;
  30028. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  30029. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  30030. }
  30031. else {
  30032. lenPrevSeg = dist(p, prevP);
  30033. lenNextSeg = dist(p, nextP);
  30034. }
  30035. // Use ratio of seg length
  30036. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  30037. scaleAndAdd$1(cp1, p, v, -smooth * (1 - ratioNextSeg));
  30038. }
  30039. // Smooth constraint
  30040. vec2Min(cp0, cp0, smoothMax);
  30041. vec2Max(cp0, cp0, smoothMin);
  30042. vec2Min(cp1, cp1, smoothMax);
  30043. vec2Max(cp1, cp1, smoothMin);
  30044. ctx.bezierCurveTo(
  30045. cp0[0], cp0[1],
  30046. cp1[0], cp1[1],
  30047. p[0], p[1]
  30048. );
  30049. // cp0 of next segment
  30050. scaleAndAdd$1(cp0, p, v, smooth * ratioNextSeg);
  30051. }
  30052. else {
  30053. ctx.lineTo(p[0], p[1]);
  30054. }
  30055. }
  30056. prevIdx = idx;
  30057. idx += dir;
  30058. }
  30059. return k;
  30060. }
  30061. function getBoundingBox(points, smoothConstraint) {
  30062. var ptMin = [Infinity, Infinity];
  30063. var ptMax = [-Infinity, -Infinity];
  30064. if (smoothConstraint) {
  30065. for (var i = 0; i < points.length; i++) {
  30066. var pt = points[i];
  30067. if (pt[0] < ptMin[0]) {
  30068. ptMin[0] = pt[0];
  30069. }
  30070. if (pt[1] < ptMin[1]) {
  30071. ptMin[1] = pt[1];
  30072. }
  30073. if (pt[0] > ptMax[0]) {
  30074. ptMax[0] = pt[0];
  30075. }
  30076. if (pt[1] > ptMax[1]) {
  30077. ptMax[1] = pt[1];
  30078. }
  30079. }
  30080. }
  30081. return {
  30082. min: smoothConstraint ? ptMin : ptMax,
  30083. max: smoothConstraint ? ptMax : ptMin
  30084. };
  30085. }
  30086. var Polyline$1 = Path.extend({
  30087. type: 'ec-polyline',
  30088. shape: {
  30089. points: [],
  30090. smooth: 0,
  30091. smoothConstraint: true,
  30092. smoothMonotone: null,
  30093. connectNulls: false
  30094. },
  30095. style: {
  30096. fill: null,
  30097. stroke: '#000'
  30098. },
  30099. brush: fixClipWithShadow(Path.prototype.brush),
  30100. buildPath: function (ctx, shape) {
  30101. var points = shape.points;
  30102. var i = 0;
  30103. var len$$1 = points.length;
  30104. var result = getBoundingBox(points, shape.smoothConstraint);
  30105. if (shape.connectNulls) {
  30106. // Must remove first and last null values avoid draw error in polygon
  30107. for (; len$$1 > 0; len$$1--) {
  30108. if (!isPointNull(points[len$$1 - 1])) {
  30109. break;
  30110. }
  30111. }
  30112. for (; i < len$$1; i++) {
  30113. if (!isPointNull(points[i])) {
  30114. break;
  30115. }
  30116. }
  30117. }
  30118. while (i < len$$1) {
  30119. i += drawSegment(
  30120. ctx, points, i, len$$1, len$$1,
  30121. 1, result.min, result.max, shape.smooth,
  30122. shape.smoothMonotone, shape.connectNulls
  30123. ) + 1;
  30124. }
  30125. }
  30126. });
  30127. var Polygon$1 = Path.extend({
  30128. type: 'ec-polygon',
  30129. shape: {
  30130. points: [],
  30131. // Offset between stacked base points and points
  30132. stackedOnPoints: [],
  30133. smooth: 0,
  30134. stackedOnSmooth: 0,
  30135. smoothConstraint: true,
  30136. smoothMonotone: null,
  30137. connectNulls: false
  30138. },
  30139. brush: fixClipWithShadow(Path.prototype.brush),
  30140. buildPath: function (ctx, shape) {
  30141. var points = shape.points;
  30142. var stackedOnPoints = shape.stackedOnPoints;
  30143. var i = 0;
  30144. var len$$1 = points.length;
  30145. var smoothMonotone = shape.smoothMonotone;
  30146. var bbox = getBoundingBox(points, shape.smoothConstraint);
  30147. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  30148. if (shape.connectNulls) {
  30149. // Must remove first and last null values avoid draw error in polygon
  30150. for (; len$$1 > 0; len$$1--) {
  30151. if (!isPointNull(points[len$$1 - 1])) {
  30152. break;
  30153. }
  30154. }
  30155. for (; i < len$$1; i++) {
  30156. if (!isPointNull(points[i])) {
  30157. break;
  30158. }
  30159. }
  30160. }
  30161. while (i < len$$1) {
  30162. var k = drawSegment(
  30163. ctx, points, i, len$$1, len$$1,
  30164. 1, bbox.min, bbox.max, shape.smooth,
  30165. smoothMonotone, shape.connectNulls
  30166. );
  30167. drawSegment(
  30168. ctx, stackedOnPoints, i + k - 1, k, len$$1,
  30169. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  30170. smoothMonotone, shape.connectNulls
  30171. );
  30172. i += k + 1;
  30173. ctx.closePath();
  30174. }
  30175. }
  30176. });
  30177. /*
  30178. * Licensed to the Apache Software Foundation (ASF) under one
  30179. * or more contributor license agreements. See the NOTICE file
  30180. * distributed with this work for additional information
  30181. * regarding copyright ownership. The ASF licenses this file
  30182. * to you under the Apache License, Version 2.0 (the
  30183. * "License"); you may not use this file except in compliance
  30184. * with the License. You may obtain a copy of the License at
  30185. *
  30186. * http://www.apache.org/licenses/LICENSE-2.0
  30187. *
  30188. * Unless required by applicable law or agreed to in writing,
  30189. * software distributed under the License is distributed on an
  30190. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30191. * KIND, either express or implied. See the License for the
  30192. * specific language governing permissions and limitations
  30193. * under the License.
  30194. */
  30195. function createGridClipPath(cartesian, hasAnimation, seriesModel) {
  30196. var rect = cartesian.getArea();
  30197. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  30198. var x = rect.x;
  30199. var y = rect.y;
  30200. var width = rect.width;
  30201. var height = rect.height;
  30202. var lineWidth = seriesModel.get('lineStyle.width') || 2;
  30203. // Expand the clip path a bit to avoid the border is clipped and looks thinner
  30204. x -= lineWidth / 2;
  30205. y -= lineWidth / 2;
  30206. width += lineWidth;
  30207. height += lineWidth;
  30208. // fix: https://github.com/apache/incubator-echarts/issues/11369
  30209. x = Math.floor(x);
  30210. width = Math.round(width);
  30211. var clipPath = new Rect({
  30212. shape: {
  30213. x: x,
  30214. y: y,
  30215. width: width,
  30216. height: height
  30217. }
  30218. });
  30219. if (hasAnimation) {
  30220. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  30221. initProps(clipPath, {
  30222. shape: {
  30223. width: width,
  30224. height: height
  30225. }
  30226. }, seriesModel);
  30227. }
  30228. return clipPath;
  30229. }
  30230. function createPolarClipPath(polar, hasAnimation, seriesModel) {
  30231. var sectorArea = polar.getArea();
  30232. // Avoid float number rounding error for symbol on the edge of axis extent.
  30233. var clipPath = new Sector({
  30234. shape: {
  30235. cx: round$1(polar.cx, 1),
  30236. cy: round$1(polar.cy, 1),
  30237. r0: round$1(sectorArea.r0, 1),
  30238. r: round$1(sectorArea.r, 1),
  30239. startAngle: sectorArea.startAngle,
  30240. endAngle: sectorArea.endAngle,
  30241. clockwise: sectorArea.clockwise
  30242. }
  30243. });
  30244. if (hasAnimation) {
  30245. clipPath.shape.endAngle = sectorArea.startAngle;
  30246. initProps(clipPath, {
  30247. shape: {
  30248. endAngle: sectorArea.endAngle
  30249. }
  30250. }, seriesModel);
  30251. }
  30252. return clipPath;
  30253. }
  30254. function createClipPath(coordSys, hasAnimation, seriesModel) {
  30255. if (!coordSys) {
  30256. return null;
  30257. }
  30258. else if (coordSys.type === 'polar') {
  30259. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  30260. }
  30261. else if (coordSys.type === 'cartesian2d') {
  30262. return createGridClipPath(coordSys, hasAnimation, seriesModel);
  30263. }
  30264. return null;
  30265. }
  30266. /*
  30267. * Licensed to the Apache Software Foundation (ASF) under one
  30268. * or more contributor license agreements. See the NOTICE file
  30269. * distributed with this work for additional information
  30270. * regarding copyright ownership. The ASF licenses this file
  30271. * to you under the Apache License, Version 2.0 (the
  30272. * "License"); you may not use this file except in compliance
  30273. * with the License. You may obtain a copy of the License at
  30274. *
  30275. * http://www.apache.org/licenses/LICENSE-2.0
  30276. *
  30277. * Unless required by applicable law or agreed to in writing,
  30278. * software distributed under the License is distributed on an
  30279. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30280. * KIND, either express or implied. See the License for the
  30281. * specific language governing permissions and limitations
  30282. * under the License.
  30283. */
  30284. // FIXME step not support polar
  30285. function isPointsSame(points1, points2) {
  30286. if (points1.length !== points2.length) {
  30287. return;
  30288. }
  30289. for (var i = 0; i < points1.length; i++) {
  30290. var p1 = points1[i];
  30291. var p2 = points2[i];
  30292. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  30293. return;
  30294. }
  30295. }
  30296. return true;
  30297. }
  30298. function getBoundingDiff(points1, points2) {
  30299. var min1 = [];
  30300. var max1 = [];
  30301. var min2 = [];
  30302. var max2 = [];
  30303. fromPoints(points1, min1, max1);
  30304. fromPoints(points2, min2, max2);
  30305. // Get a max value from each corner of two boundings.
  30306. return Math.max(
  30307. Math.abs(min1[0] - min2[0]),
  30308. Math.abs(min1[1] - min2[1]),
  30309. Math.abs(max1[0] - max2[0]),
  30310. Math.abs(max1[1] - max2[1])
  30311. );
  30312. }
  30313. function getSmooth(smooth) {
  30314. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.5 : 0);
  30315. }
  30316. /**
  30317. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  30318. * @param {module:echarts/data/List} data
  30319. * @param {Object} dataCoordInfo
  30320. * @param {Array.<Array.<number>>} points
  30321. */
  30322. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  30323. if (!dataCoordInfo.valueDim) {
  30324. return [];
  30325. }
  30326. var points = [];
  30327. for (var idx = 0, len = data.count(); idx < len; idx++) {
  30328. points.push(getStackedOnPoint(dataCoordInfo, coordSys, data, idx));
  30329. }
  30330. return points;
  30331. }
  30332. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  30333. var baseAxis = coordSys.getBaseAxis();
  30334. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  30335. var stepPoints = [];
  30336. for (var i = 0; i < points.length - 1; i++) {
  30337. var nextPt = points[i + 1];
  30338. var pt = points[i];
  30339. stepPoints.push(pt);
  30340. var stepPt = [];
  30341. switch (stepTurnAt) {
  30342. case 'end':
  30343. stepPt[baseIndex] = nextPt[baseIndex];
  30344. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  30345. // default is start
  30346. stepPoints.push(stepPt);
  30347. break;
  30348. case 'middle':
  30349. // default is start
  30350. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  30351. var stepPt2 = [];
  30352. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  30353. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  30354. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  30355. stepPoints.push(stepPt);
  30356. stepPoints.push(stepPt2);
  30357. break;
  30358. default:
  30359. stepPt[baseIndex] = pt[baseIndex];
  30360. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  30361. // default is start
  30362. stepPoints.push(stepPt);
  30363. }
  30364. }
  30365. // Last points
  30366. points[i] && stepPoints.push(points[i]);
  30367. return stepPoints;
  30368. }
  30369. function getVisualGradient(data, coordSys) {
  30370. var visualMetaList = data.getVisual('visualMeta');
  30371. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  30372. // When data.count() is 0, gradient range can not be calculated.
  30373. return;
  30374. }
  30375. if (coordSys.type !== 'cartesian2d') {
  30376. if (__DEV__) {
  30377. console.warn('Visual map on line style is only supported on cartesian2d.');
  30378. }
  30379. return;
  30380. }
  30381. var coordDim;
  30382. var visualMeta;
  30383. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  30384. var dimIndex = visualMetaList[i].dimension;
  30385. var dimName = data.dimensions[dimIndex];
  30386. var dimInfo = data.getDimensionInfo(dimName);
  30387. coordDim = dimInfo && dimInfo.coordDim;
  30388. // Can only be x or y
  30389. if (coordDim === 'x' || coordDim === 'y') {
  30390. visualMeta = visualMetaList[i];
  30391. break;
  30392. }
  30393. }
  30394. if (!visualMeta) {
  30395. if (__DEV__) {
  30396. console.warn('Visual map on line style only support x or y dimension.');
  30397. }
  30398. return;
  30399. }
  30400. // If the area to be rendered is bigger than area defined by LinearGradient,
  30401. // the canvas spec prescribes that the color of the first stop and the last
  30402. // stop should be used. But if two stops are added at offset 0, in effect
  30403. // browsers use the color of the second stop to render area outside
  30404. // LinearGradient. So we can only infinitesimally extend area defined in
  30405. // LinearGradient to render `outerColors`.
  30406. var axis = coordSys.getAxis(coordDim);
  30407. // dataToCoor mapping may not be linear, but must be monotonic.
  30408. var colorStops = map(visualMeta.stops, function (stop) {
  30409. return {
  30410. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  30411. color: stop.color
  30412. };
  30413. });
  30414. var stopLen = colorStops.length;
  30415. var outerColors = visualMeta.outerColors.slice();
  30416. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  30417. colorStops.reverse();
  30418. outerColors.reverse();
  30419. }
  30420. var tinyExtent = 10; // Arbitrary value: 10px
  30421. var minCoord = colorStops[0].coord - tinyExtent;
  30422. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  30423. var coordSpan = maxCoord - minCoord;
  30424. if (coordSpan < 1e-3) {
  30425. return 'transparent';
  30426. }
  30427. each$1(colorStops, function (stop) {
  30428. stop.offset = (stop.coord - minCoord) / coordSpan;
  30429. });
  30430. colorStops.push({
  30431. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  30432. color: outerColors[1] || 'transparent'
  30433. });
  30434. colorStops.unshift({ // notice colorStops.length have been changed.
  30435. offset: stopLen ? colorStops[0].offset : 0.5,
  30436. color: outerColors[0] || 'transparent'
  30437. });
  30438. // zrUtil.each(colorStops, function (colorStop) {
  30439. // // Make sure each offset has rounded px to avoid not sharp edge
  30440. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  30441. // });
  30442. var gradient = new LinearGradient(0, 0, 0, 0, colorStops, true);
  30443. gradient[coordDim] = minCoord;
  30444. gradient[coordDim + '2'] = maxCoord;
  30445. return gradient;
  30446. }
  30447. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  30448. var showAllSymbol = seriesModel.get('showAllSymbol');
  30449. var isAuto = showAllSymbol === 'auto';
  30450. if (showAllSymbol && !isAuto) {
  30451. return;
  30452. }
  30453. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  30454. if (!categoryAxis) {
  30455. return;
  30456. }
  30457. // Note that category label interval strategy might bring some weird effect
  30458. // in some scenario: users may wonder why some of the symbols are not
  30459. // displayed. So we show all symbols as possible as we can.
  30460. if (isAuto
  30461. // Simplify the logic, do not determine label overlap here.
  30462. && canShowAllSymbolForCategory(categoryAxis, data)
  30463. ) {
  30464. return;
  30465. }
  30466. // Otherwise follow the label interval strategy on category axis.
  30467. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  30468. var labelMap = {};
  30469. each$1(categoryAxis.getViewLabels(), function (labelItem) {
  30470. labelMap[labelItem.tickValue] = 1;
  30471. });
  30472. return function (dataIndex) {
  30473. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  30474. };
  30475. }
  30476. function canShowAllSymbolForCategory(categoryAxis, data) {
  30477. // In mose cases, line is monotonous on category axis, and the label size
  30478. // is close with each other. So we check the symbol size and some of the
  30479. // label size alone with the category axis to estimate whether all symbol
  30480. // can be shown without overlap.
  30481. var axisExtent = categoryAxis.getExtent();
  30482. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  30483. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  30484. // Sampling some points, max 5.
  30485. var dataLen = data.count();
  30486. var step = Math.max(1, Math.round(dataLen / 5));
  30487. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  30488. if (SymbolClz.getSymbolSize(
  30489. data, dataIndex
  30490. // Only for cartesian, where `isHorizontal` exists.
  30491. )[categoryAxis.isHorizontal() ? 1 : 0]
  30492. // Empirical number
  30493. * 1.5 > availSize
  30494. ) {
  30495. return false;
  30496. }
  30497. }
  30498. return true;
  30499. }
  30500. function createLineClipPath(coordSys, hasAnimation, seriesModel) {
  30501. if (coordSys.type === 'cartesian2d') {
  30502. var isHorizontal = coordSys.getBaseAxis().isHorizontal();
  30503. var clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel);
  30504. // Expand clip shape to avoid clipping when line value exceeds axis
  30505. if (!seriesModel.get('clip', true)) {
  30506. var rectShape = clipPath.shape;
  30507. var expandSize = Math.max(rectShape.width, rectShape.height);
  30508. if (isHorizontal) {
  30509. rectShape.y -= expandSize;
  30510. rectShape.height += expandSize * 2;
  30511. }
  30512. else {
  30513. rectShape.x -= expandSize;
  30514. rectShape.width += expandSize * 2;
  30515. }
  30516. }
  30517. return clipPath;
  30518. }
  30519. else {
  30520. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  30521. }
  30522. }
  30523. Chart.extend({
  30524. type: 'line',
  30525. init: function () {
  30526. var lineGroup = new Group();
  30527. var symbolDraw = new SymbolDraw();
  30528. this.group.add(symbolDraw.group);
  30529. this._symbolDraw = symbolDraw;
  30530. this._lineGroup = lineGroup;
  30531. },
  30532. render: function (seriesModel, ecModel, api) {
  30533. var coordSys = seriesModel.coordinateSystem;
  30534. var group = this.group;
  30535. var data = seriesModel.getData();
  30536. var lineStyleModel = seriesModel.getModel('lineStyle');
  30537. var areaStyleModel = seriesModel.getModel('areaStyle');
  30538. var points = data.mapArray(data.getItemLayout);
  30539. var isCoordSysPolar = coordSys.type === 'polar';
  30540. var prevCoordSys = this._coordSys;
  30541. var symbolDraw = this._symbolDraw;
  30542. var polyline = this._polyline;
  30543. var polygon = this._polygon;
  30544. var lineGroup = this._lineGroup;
  30545. var hasAnimation = seriesModel.get('animation');
  30546. var isAreaChart = !areaStyleModel.isEmpty();
  30547. var valueOrigin = areaStyleModel.get('origin');
  30548. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  30549. var stackedOnPoints = getStackedOnPoints(coordSys, data, dataCoordInfo);
  30550. var showSymbol = seriesModel.get('showSymbol');
  30551. var isIgnoreFunc = showSymbol && !isCoordSysPolar
  30552. && getIsIgnoreFunc(seriesModel, data, coordSys);
  30553. // Remove temporary symbols
  30554. var oldData = this._data;
  30555. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  30556. if (el.__temp) {
  30557. group.remove(el);
  30558. oldData.setItemGraphicEl(idx, null);
  30559. }
  30560. });
  30561. // Remove previous created symbols if showSymbol changed to false
  30562. if (!showSymbol) {
  30563. symbolDraw.remove();
  30564. }
  30565. group.add(lineGroup);
  30566. // FIXME step not support polar
  30567. var step = !isCoordSysPolar && seriesModel.get('step');
  30568. var clipShapeForSymbol;
  30569. if (coordSys && coordSys.getArea && seriesModel.get('clip', true)) {
  30570. clipShapeForSymbol = coordSys.getArea();
  30571. // Avoid float number rounding error for symbol on the edge of axis extent.
  30572. // See #7913 and `test/dataZoom-clip.html`.
  30573. if (clipShapeForSymbol.width != null) {
  30574. clipShapeForSymbol.x -= 0.1;
  30575. clipShapeForSymbol.y -= 0.1;
  30576. clipShapeForSymbol.width += 0.2;
  30577. clipShapeForSymbol.height += 0.2;
  30578. }
  30579. else if (clipShapeForSymbol.r0) {
  30580. clipShapeForSymbol.r0 -= 0.5;
  30581. clipShapeForSymbol.r1 += 0.5;
  30582. }
  30583. }
  30584. this._clipShapeForSymbol = clipShapeForSymbol;
  30585. // Initialization animation or coordinate system changed
  30586. if (
  30587. !(polyline && prevCoordSys.type === coordSys.type && step === this._step)
  30588. ) {
  30589. showSymbol && symbolDraw.updateData(data, {
  30590. isIgnore: isIgnoreFunc,
  30591. clipShape: clipShapeForSymbol
  30592. });
  30593. if (step) {
  30594. // TODO If stacked series is not step
  30595. points = turnPointsIntoStep(points, coordSys, step);
  30596. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  30597. }
  30598. polyline = this._newPolyline(points, coordSys, hasAnimation);
  30599. if (isAreaChart) {
  30600. polygon = this._newPolygon(
  30601. points, stackedOnPoints,
  30602. coordSys, hasAnimation
  30603. );
  30604. }
  30605. lineGroup.setClipPath(createLineClipPath(coordSys, true, seriesModel));
  30606. }
  30607. else {
  30608. if (isAreaChart && !polygon) {
  30609. // If areaStyle is added
  30610. polygon = this._newPolygon(
  30611. points, stackedOnPoints,
  30612. coordSys, hasAnimation
  30613. );
  30614. }
  30615. else if (polygon && !isAreaChart) {
  30616. // If areaStyle is removed
  30617. lineGroup.remove(polygon);
  30618. polygon = this._polygon = null;
  30619. }
  30620. // Update clipPath
  30621. lineGroup.setClipPath(createLineClipPath(coordSys, false, seriesModel));
  30622. // Always update, or it is wrong in the case turning on legend
  30623. // because points are not changed
  30624. showSymbol && symbolDraw.updateData(data, {
  30625. isIgnore: isIgnoreFunc,
  30626. clipShape: clipShapeForSymbol
  30627. });
  30628. // Stop symbol animation and sync with line points
  30629. // FIXME performance?
  30630. data.eachItemGraphicEl(function (el) {
  30631. el.stopAnimation(true);
  30632. });
  30633. // In the case data zoom triggerred refreshing frequently
  30634. // Data may not change if line has a category axis. So it should animate nothing
  30635. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  30636. || !isPointsSame(this._points, points)
  30637. ) {
  30638. if (hasAnimation) {
  30639. this._updateAnimation(
  30640. data, stackedOnPoints, coordSys, api, step, valueOrigin
  30641. );
  30642. }
  30643. else {
  30644. // Not do it in update with animation
  30645. if (step) {
  30646. // TODO If stacked series is not step
  30647. points = turnPointsIntoStep(points, coordSys, step);
  30648. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  30649. }
  30650. polyline.setShape({
  30651. points: points
  30652. });
  30653. polygon && polygon.setShape({
  30654. points: points,
  30655. stackedOnPoints: stackedOnPoints
  30656. });
  30657. }
  30658. }
  30659. }
  30660. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  30661. polyline.useStyle(defaults(
  30662. // Use color in lineStyle first
  30663. lineStyleModel.getLineStyle(),
  30664. {
  30665. fill: 'none',
  30666. stroke: visualColor,
  30667. lineJoin: 'bevel'
  30668. }
  30669. ));
  30670. var smooth = seriesModel.get('smooth');
  30671. smooth = getSmooth(seriesModel.get('smooth'));
  30672. polyline.setShape({
  30673. smooth: smooth,
  30674. smoothMonotone: seriesModel.get('smoothMonotone'),
  30675. connectNulls: seriesModel.get('connectNulls')
  30676. });
  30677. if (polygon) {
  30678. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  30679. var stackedOnSmooth = 0;
  30680. polygon.useStyle(defaults(
  30681. areaStyleModel.getAreaStyle(),
  30682. {
  30683. fill: visualColor,
  30684. opacity: 0.7,
  30685. lineJoin: 'bevel'
  30686. }
  30687. ));
  30688. if (stackedOnSeries) {
  30689. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  30690. }
  30691. polygon.setShape({
  30692. smooth: smooth,
  30693. stackedOnSmooth: stackedOnSmooth,
  30694. smoothMonotone: seriesModel.get('smoothMonotone'),
  30695. connectNulls: seriesModel.get('connectNulls')
  30696. });
  30697. }
  30698. this._data = data;
  30699. // Save the coordinate system for transition animation when data changed
  30700. this._coordSys = coordSys;
  30701. this._stackedOnPoints = stackedOnPoints;
  30702. this._points = points;
  30703. this._step = step;
  30704. this._valueOrigin = valueOrigin;
  30705. },
  30706. dispose: function () {},
  30707. highlight: function (seriesModel, ecModel, api, payload) {
  30708. var data = seriesModel.getData();
  30709. var dataIndex = queryDataIndex(data, payload);
  30710. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  30711. var symbol = data.getItemGraphicEl(dataIndex);
  30712. if (!symbol) {
  30713. // Create a temporary symbol if it is not exists
  30714. var pt = data.getItemLayout(dataIndex);
  30715. if (!pt) {
  30716. // Null data
  30717. return;
  30718. }
  30719. // fix #11360: should't draw symbol outside clipShapeForSymbol
  30720. if (this._clipShapeForSymbol && !this._clipShapeForSymbol.contain(pt[0], pt[1])) {
  30721. return;
  30722. }
  30723. symbol = new SymbolClz(data, dataIndex);
  30724. symbol.position = pt;
  30725. symbol.setZ(
  30726. seriesModel.get('zlevel'),
  30727. seriesModel.get('z')
  30728. );
  30729. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  30730. symbol.__temp = true;
  30731. data.setItemGraphicEl(dataIndex, symbol);
  30732. // Stop scale animation
  30733. symbol.stopSymbolAnimation(true);
  30734. this.group.add(symbol);
  30735. }
  30736. symbol.highlight();
  30737. }
  30738. else {
  30739. // Highlight whole series
  30740. Chart.prototype.highlight.call(
  30741. this, seriesModel, ecModel, api, payload
  30742. );
  30743. }
  30744. },
  30745. downplay: function (seriesModel, ecModel, api, payload) {
  30746. var data = seriesModel.getData();
  30747. var dataIndex = queryDataIndex(data, payload);
  30748. if (dataIndex != null && dataIndex >= 0) {
  30749. var symbol = data.getItemGraphicEl(dataIndex);
  30750. if (symbol) {
  30751. if (symbol.__temp) {
  30752. data.setItemGraphicEl(dataIndex, null);
  30753. this.group.remove(symbol);
  30754. }
  30755. else {
  30756. symbol.downplay();
  30757. }
  30758. }
  30759. }
  30760. else {
  30761. // FIXME
  30762. // can not downplay completely.
  30763. // Downplay whole series
  30764. Chart.prototype.downplay.call(
  30765. this, seriesModel, ecModel, api, payload
  30766. );
  30767. }
  30768. },
  30769. /**
  30770. * @param {module:zrender/container/Group} group
  30771. * @param {Array.<Array.<number>>} points
  30772. * @private
  30773. */
  30774. _newPolyline: function (points) {
  30775. var polyline = this._polyline;
  30776. // Remove previous created polyline
  30777. if (polyline) {
  30778. this._lineGroup.remove(polyline);
  30779. }
  30780. polyline = new Polyline$1({
  30781. shape: {
  30782. points: points
  30783. },
  30784. silent: true,
  30785. z2: 10
  30786. });
  30787. this._lineGroup.add(polyline);
  30788. this._polyline = polyline;
  30789. return polyline;
  30790. },
  30791. /**
  30792. * @param {module:zrender/container/Group} group
  30793. * @param {Array.<Array.<number>>} stackedOnPoints
  30794. * @param {Array.<Array.<number>>} points
  30795. * @private
  30796. */
  30797. _newPolygon: function (points, stackedOnPoints) {
  30798. var polygon = this._polygon;
  30799. // Remove previous created polygon
  30800. if (polygon) {
  30801. this._lineGroup.remove(polygon);
  30802. }
  30803. polygon = new Polygon$1({
  30804. shape: {
  30805. points: points,
  30806. stackedOnPoints: stackedOnPoints
  30807. },
  30808. silent: true
  30809. });
  30810. this._lineGroup.add(polygon);
  30811. this._polygon = polygon;
  30812. return polygon;
  30813. },
  30814. /**
  30815. * @private
  30816. */
  30817. // FIXME Two value axis
  30818. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step, valueOrigin) {
  30819. var polyline = this._polyline;
  30820. var polygon = this._polygon;
  30821. var seriesModel = data.hostModel;
  30822. var diff = lineAnimationDiff(
  30823. this._data, data,
  30824. this._stackedOnPoints, stackedOnPoints,
  30825. this._coordSys, coordSys,
  30826. this._valueOrigin, valueOrigin
  30827. );
  30828. var current = diff.current;
  30829. var stackedOnCurrent = diff.stackedOnCurrent;
  30830. var next = diff.next;
  30831. var stackedOnNext = diff.stackedOnNext;
  30832. if (step) {
  30833. // TODO If stacked series is not step
  30834. current = turnPointsIntoStep(diff.current, coordSys, step);
  30835. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  30836. next = turnPointsIntoStep(diff.next, coordSys, step);
  30837. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  30838. }
  30839. // Don't apply animation if diff is large.
  30840. // For better result and avoid memory explosion problems like
  30841. // https://github.com/apache/incubator-echarts/issues/12229
  30842. if (getBoundingDiff(current, next) > 3000
  30843. || (polygon && getBoundingDiff(stackedOnCurrent, stackedOnNext) > 3000)
  30844. ) {
  30845. polyline.setShape({
  30846. points: next
  30847. });
  30848. if (polygon) {
  30849. polygon.setShape({
  30850. points: next,
  30851. stackedOnPoints: stackedOnNext
  30852. });
  30853. }
  30854. return;
  30855. }
  30856. // `diff.current` is subset of `current` (which should be ensured by
  30857. // turnPointsIntoStep), so points in `__points` can be updated when
  30858. // points in `current` are update during animation.
  30859. polyline.shape.__points = diff.current;
  30860. polyline.shape.points = current;
  30861. updateProps(polyline, {
  30862. shape: {
  30863. points: next
  30864. }
  30865. }, seriesModel);
  30866. if (polygon) {
  30867. polygon.setShape({
  30868. points: current,
  30869. stackedOnPoints: stackedOnCurrent
  30870. });
  30871. updateProps(polygon, {
  30872. shape: {
  30873. points: next,
  30874. stackedOnPoints: stackedOnNext
  30875. }
  30876. }, seriesModel);
  30877. }
  30878. var updatedDataInfo = [];
  30879. var diffStatus = diff.status;
  30880. for (var i = 0; i < diffStatus.length; i++) {
  30881. var cmd = diffStatus[i].cmd;
  30882. if (cmd === '=') {
  30883. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  30884. if (el) {
  30885. updatedDataInfo.push({
  30886. el: el,
  30887. ptIdx: i // Index of points
  30888. });
  30889. }
  30890. }
  30891. }
  30892. if (polyline.animators && polyline.animators.length) {
  30893. polyline.animators[0].during(function () {
  30894. for (var i = 0; i < updatedDataInfo.length; i++) {
  30895. var el = updatedDataInfo[i].el;
  30896. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  30897. }
  30898. });
  30899. }
  30900. },
  30901. remove: function (ecModel) {
  30902. var group = this.group;
  30903. var oldData = this._data;
  30904. this._lineGroup.removeAll();
  30905. this._symbolDraw.remove(true);
  30906. // Remove temporary created elements when highlighting
  30907. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  30908. if (el.__temp) {
  30909. group.remove(el);
  30910. oldData.setItemGraphicEl(idx, null);
  30911. }
  30912. });
  30913. this._polyline =
  30914. this._polygon =
  30915. this._coordSys =
  30916. this._points =
  30917. this._stackedOnPoints =
  30918. this._data = null;
  30919. }
  30920. });
  30921. /*
  30922. * Licensed to the Apache Software Foundation (ASF) under one
  30923. * or more contributor license agreements. See the NOTICE file
  30924. * distributed with this work for additional information
  30925. * regarding copyright ownership. The ASF licenses this file
  30926. * to you under the Apache License, Version 2.0 (the
  30927. * "License"); you may not use this file except in compliance
  30928. * with the License. You may obtain a copy of the License at
  30929. *
  30930. * http://www.apache.org/licenses/LICENSE-2.0
  30931. *
  30932. * Unless required by applicable law or agreed to in writing,
  30933. * software distributed under the License is distributed on an
  30934. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30935. * KIND, either express or implied. See the License for the
  30936. * specific language governing permissions and limitations
  30937. * under the License.
  30938. */
  30939. var visualSymbol = function (seriesType, defaultSymbolType, legendSymbol) {
  30940. // Encoding visual for all series include which is filtered for legend drawing
  30941. return {
  30942. seriesType: seriesType,
  30943. // For legend.
  30944. performRawSeries: true,
  30945. reset: function (seriesModel, ecModel, api) {
  30946. var data = seriesModel.getData();
  30947. var symbolType = seriesModel.get('symbol');
  30948. var symbolSize = seriesModel.get('symbolSize');
  30949. var keepAspect = seriesModel.get('symbolKeepAspect');
  30950. var symbolRotate = seriesModel.get('symbolRotate');
  30951. var hasSymbolTypeCallback = isFunction$1(symbolType);
  30952. var hasSymbolSizeCallback = isFunction$1(symbolSize);
  30953. var hasSymbolRotateCallback = isFunction$1(symbolRotate);
  30954. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback || hasSymbolRotateCallback;
  30955. var seriesSymbol = (!hasSymbolTypeCallback && symbolType) ? symbolType : defaultSymbolType;
  30956. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  30957. data.setVisual({
  30958. legendSymbol: legendSymbol || seriesSymbol,
  30959. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  30960. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  30961. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  30962. // some cases but generally it is not recommanded.
  30963. symbol: seriesSymbol,
  30964. symbolSize: seriesSymbolSize,
  30965. symbolKeepAspect: keepAspect,
  30966. symbolRotate: symbolRotate
  30967. });
  30968. // Only visible series has each data be visual encoded
  30969. if (ecModel.isSeriesFiltered(seriesModel)) {
  30970. return;
  30971. }
  30972. function dataEach(data, idx) {
  30973. if (hasCallback) {
  30974. var rawValue = seriesModel.getRawValue(idx);
  30975. var params = seriesModel.getDataParams(idx);
  30976. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  30977. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  30978. hasSymbolRotateCallback && data.setItemVisual(idx, 'symbolRotate', symbolRotate(rawValue, params));
  30979. }
  30980. if (data.hasItemOption) {
  30981. var itemModel = data.getItemModel(idx);
  30982. var itemSymbolType = itemModel.getShallow('symbol', true);
  30983. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  30984. var itemSymbolRotate = itemModel.getShallow('symbolRotate', true);
  30985. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true);
  30986. // If has item symbol
  30987. if (itemSymbolType != null) {
  30988. data.setItemVisual(idx, 'symbol', itemSymbolType);
  30989. }
  30990. if (itemSymbolSize != null) {
  30991. // PENDING Transform symbolSize ?
  30992. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  30993. }
  30994. if (itemSymbolRotate != null) {
  30995. data.setItemVisual(idx, 'symbolRotate', itemSymbolRotate);
  30996. }
  30997. if (itemSymbolKeepAspect != null) {
  30998. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  30999. }
  31000. }
  31001. }
  31002. return { dataEach: (data.hasItemOption || hasCallback) ? dataEach : null };
  31003. }
  31004. };
  31005. };
  31006. /*
  31007. * Licensed to the Apache Software Foundation (ASF) under one
  31008. * or more contributor license agreements. See the NOTICE file
  31009. * distributed with this work for additional information
  31010. * regarding copyright ownership. The ASF licenses this file
  31011. * to you under the Apache License, Version 2.0 (the
  31012. * "License"); you may not use this file except in compliance
  31013. * with the License. You may obtain a copy of the License at
  31014. *
  31015. * http://www.apache.org/licenses/LICENSE-2.0
  31016. *
  31017. * Unless required by applicable law or agreed to in writing,
  31018. * software distributed under the License is distributed on an
  31019. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31020. * KIND, either express or implied. See the License for the
  31021. * specific language governing permissions and limitations
  31022. * under the License.
  31023. */
  31024. /* global Float32Array */
  31025. var layoutPoints = function (seriesType) {
  31026. return {
  31027. seriesType: seriesType,
  31028. plan: createRenderPlanner(),
  31029. reset: function (seriesModel) {
  31030. var data = seriesModel.getData();
  31031. var coordSys = seriesModel.coordinateSystem;
  31032. var pipelineContext = seriesModel.pipelineContext;
  31033. var isLargeRender = pipelineContext.large;
  31034. if (!coordSys) {
  31035. return;
  31036. }
  31037. var dims = map(coordSys.dimensions, function (dim) {
  31038. return data.mapDimension(dim);
  31039. }).slice(0, 2);
  31040. var dimLen = dims.length;
  31041. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  31042. if (isDimensionStacked(data, dims[0] /*, dims[1]*/)) {
  31043. dims[0] = stackResultDim;
  31044. }
  31045. if (isDimensionStacked(data, dims[1] /*, dims[0]*/)) {
  31046. dims[1] = stackResultDim;
  31047. }
  31048. function progress(params, data) {
  31049. var segCount = params.end - params.start;
  31050. var points = isLargeRender && new Float32Array(segCount * dimLen);
  31051. for (var i = params.start, offset = 0, tmpIn = [], tmpOut = []; i < params.end; i++) {
  31052. var point;
  31053. if (dimLen === 1) {
  31054. var x = data.get(dims[0], i);
  31055. point = !isNaN(x) && coordSys.dataToPoint(x, null, tmpOut);
  31056. }
  31057. else {
  31058. var x = tmpIn[0] = data.get(dims[0], i);
  31059. var y = tmpIn[1] = data.get(dims[1], i);
  31060. // Also {Array.<number>}, not undefined to avoid if...else... statement
  31061. point = !isNaN(x) && !isNaN(y) && coordSys.dataToPoint(tmpIn, null, tmpOut);
  31062. }
  31063. if (isLargeRender) {
  31064. points[offset++] = point ? point[0] : NaN;
  31065. points[offset++] = point ? point[1] : NaN;
  31066. }
  31067. else {
  31068. data.setItemLayout(i, (point && point.slice()) || [NaN, NaN]);
  31069. }
  31070. }
  31071. isLargeRender && data.setLayout('symbolPoints', points);
  31072. }
  31073. return dimLen && {progress: progress};
  31074. }
  31075. };
  31076. };
  31077. /*
  31078. * Licensed to the Apache Software Foundation (ASF) under one
  31079. * or more contributor license agreements. See the NOTICE file
  31080. * distributed with this work for additional information
  31081. * regarding copyright ownership. The ASF licenses this file
  31082. * to you under the Apache License, Version 2.0 (the
  31083. * "License"); you may not use this file except in compliance
  31084. * with the License. You may obtain a copy of the License at
  31085. *
  31086. * http://www.apache.org/licenses/LICENSE-2.0
  31087. *
  31088. * Unless required by applicable law or agreed to in writing,
  31089. * software distributed under the License is distributed on an
  31090. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31091. * KIND, either express or implied. See the License for the
  31092. * specific language governing permissions and limitations
  31093. * under the License.
  31094. */
  31095. var samplers = {
  31096. average: function (frame) {
  31097. var sum = 0;
  31098. var count = 0;
  31099. for (var i = 0; i < frame.length; i++) {
  31100. if (!isNaN(frame[i])) {
  31101. sum += frame[i];
  31102. count++;
  31103. }
  31104. }
  31105. // Return NaN if count is 0
  31106. return count === 0 ? NaN : sum / count;
  31107. },
  31108. sum: function (frame) {
  31109. var sum = 0;
  31110. for (var i = 0; i < frame.length; i++) {
  31111. // Ignore NaN
  31112. sum += frame[i] || 0;
  31113. }
  31114. return sum;
  31115. },
  31116. max: function (frame) {
  31117. var max = -Infinity;
  31118. for (var i = 0; i < frame.length; i++) {
  31119. frame[i] > max && (max = frame[i]);
  31120. }
  31121. // NaN will cause illegal axis extent.
  31122. return isFinite(max) ? max : NaN;
  31123. },
  31124. min: function (frame) {
  31125. var min = Infinity;
  31126. for (var i = 0; i < frame.length; i++) {
  31127. frame[i] < min && (min = frame[i]);
  31128. }
  31129. // NaN will cause illegal axis extent.
  31130. return isFinite(min) ? min : NaN;
  31131. },
  31132. // TODO
  31133. // Median
  31134. nearest: function (frame) {
  31135. return frame[0];
  31136. }
  31137. };
  31138. var indexSampler = function (frame, value) {
  31139. return Math.round(frame.length / 2);
  31140. };
  31141. var dataSample = function (seriesType) {
  31142. return {
  31143. seriesType: seriesType,
  31144. modifyOutputEnd: true,
  31145. reset: function (seriesModel, ecModel, api) {
  31146. var data = seriesModel.getData();
  31147. var sampling = seriesModel.get('sampling');
  31148. var coordSys = seriesModel.coordinateSystem;
  31149. // Only cartesian2d support down sampling
  31150. if (coordSys.type === 'cartesian2d' && sampling) {
  31151. var baseAxis = coordSys.getBaseAxis();
  31152. var valueAxis = coordSys.getOtherAxis(baseAxis);
  31153. var extent = baseAxis.getExtent();
  31154. // Coordinste system has been resized
  31155. var size = Math.abs(extent[1] - extent[0]);
  31156. var rate = Math.round(data.count() / size);
  31157. if (rate > 1) {
  31158. var sampler;
  31159. if (typeof sampling === 'string') {
  31160. sampler = samplers[sampling];
  31161. }
  31162. else if (typeof sampling === 'function') {
  31163. sampler = sampling;
  31164. }
  31165. if (sampler) {
  31166. // Only support sample the first dim mapped from value axis.
  31167. seriesModel.setData(data.downSample(
  31168. data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler
  31169. ));
  31170. }
  31171. }
  31172. }
  31173. }
  31174. };
  31175. };
  31176. /*
  31177. * Licensed to the Apache Software Foundation (ASF) under one
  31178. * or more contributor license agreements. See the NOTICE file
  31179. * distributed with this work for additional information
  31180. * regarding copyright ownership. The ASF licenses this file
  31181. * to you under the Apache License, Version 2.0 (the
  31182. * "License"); you may not use this file except in compliance
  31183. * with the License. You may obtain a copy of the License at
  31184. *
  31185. * http://www.apache.org/licenses/LICENSE-2.0
  31186. *
  31187. * Unless required by applicable law or agreed to in writing,
  31188. * software distributed under the License is distributed on an
  31189. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31190. * KIND, either express or implied. See the License for the
  31191. * specific language governing permissions and limitations
  31192. * under the License.
  31193. */
  31194. /**
  31195. * // Scale class management
  31196. * @module echarts/scale/Scale
  31197. */
  31198. /**
  31199. * @param {Object} [setting]
  31200. */
  31201. function Scale(setting) {
  31202. this._setting = setting || {};
  31203. /**
  31204. * Extent
  31205. * @type {Array.<number>}
  31206. * @protected
  31207. */
  31208. this._extent = [Infinity, -Infinity];
  31209. /**
  31210. * Step is calculated in adjustExtent
  31211. * @type {Array.<number>}
  31212. * @protected
  31213. */
  31214. this._interval = 0;
  31215. this.init && this.init.apply(this, arguments);
  31216. }
  31217. /**
  31218. * Parse input val to valid inner number.
  31219. * @param {*} val
  31220. * @return {number}
  31221. */
  31222. Scale.prototype.parse = function (val) {
  31223. // Notice: This would be a trap here, If the implementation
  31224. // of this method depends on extent, and this method is used
  31225. // before extent set (like in dataZoom), it would be wrong.
  31226. // Nevertheless, parse does not depend on extent generally.
  31227. return val;
  31228. };
  31229. Scale.prototype.getSetting = function (name) {
  31230. return this._setting[name];
  31231. };
  31232. Scale.prototype.contain = function (val) {
  31233. var extent = this._extent;
  31234. return val >= extent[0] && val <= extent[1];
  31235. };
  31236. /**
  31237. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  31238. * @param {number} val
  31239. * @return {number}
  31240. */
  31241. Scale.prototype.normalize = function (val) {
  31242. var extent = this._extent;
  31243. if (extent[1] === extent[0]) {
  31244. return 0.5;
  31245. }
  31246. return (val - extent[0]) / (extent[1] - extent[0]);
  31247. };
  31248. /**
  31249. * Scale normalized value
  31250. * @param {number} val
  31251. * @return {number}
  31252. */
  31253. Scale.prototype.scale = function (val) {
  31254. var extent = this._extent;
  31255. return val * (extent[1] - extent[0]) + extent[0];
  31256. };
  31257. /**
  31258. * Set extent from data
  31259. * @param {Array.<number>} other
  31260. */
  31261. Scale.prototype.unionExtent = function (other) {
  31262. var extent = this._extent;
  31263. other[0] < extent[0] && (extent[0] = other[0]);
  31264. other[1] > extent[1] && (extent[1] = other[1]);
  31265. // not setExtent because in log axis it may transformed to power
  31266. // this.setExtent(extent[0], extent[1]);
  31267. };
  31268. /**
  31269. * Set extent from data
  31270. * @param {module:echarts/data/List} data
  31271. * @param {string} dim
  31272. */
  31273. Scale.prototype.unionExtentFromData = function (data, dim) {
  31274. this.unionExtent(data.getApproximateExtent(dim));
  31275. };
  31276. /**
  31277. * Get extent
  31278. * @return {Array.<number>}
  31279. */
  31280. Scale.prototype.getExtent = function () {
  31281. return this._extent.slice();
  31282. };
  31283. /**
  31284. * Set extent
  31285. * @param {number} start
  31286. * @param {number} end
  31287. */
  31288. Scale.prototype.setExtent = function (start, end) {
  31289. var thisExtent = this._extent;
  31290. if (!isNaN(start)) {
  31291. thisExtent[0] = start;
  31292. }
  31293. if (!isNaN(end)) {
  31294. thisExtent[1] = end;
  31295. }
  31296. };
  31297. /**
  31298. * When axis extent depends on data and no data exists,
  31299. * axis ticks should not be drawn, which is named 'blank'.
  31300. */
  31301. Scale.prototype.isBlank = function () {
  31302. return this._isBlank;
  31303. },
  31304. /**
  31305. * When axis extent depends on data and no data exists,
  31306. * axis ticks should not be drawn, which is named 'blank'.
  31307. */
  31308. Scale.prototype.setBlank = function (isBlank) {
  31309. this._isBlank = isBlank;
  31310. };
  31311. /**
  31312. * @abstract
  31313. * @param {*} tick
  31314. * @return {string} label of the tick.
  31315. */
  31316. Scale.prototype.getLabel = null;
  31317. enableClassExtend(Scale);
  31318. enableClassManagement(Scale, {
  31319. registerWhenExtend: true
  31320. });
  31321. /*
  31322. * Licensed to the Apache Software Foundation (ASF) under one
  31323. * or more contributor license agreements. See the NOTICE file
  31324. * distributed with this work for additional information
  31325. * regarding copyright ownership. The ASF licenses this file
  31326. * to you under the Apache License, Version 2.0 (the
  31327. * "License"); you may not use this file except in compliance
  31328. * with the License. You may obtain a copy of the License at
  31329. *
  31330. * http://www.apache.org/licenses/LICENSE-2.0
  31331. *
  31332. * Unless required by applicable law or agreed to in writing,
  31333. * software distributed under the License is distributed on an
  31334. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31335. * KIND, either express or implied. See the License for the
  31336. * specific language governing permissions and limitations
  31337. * under the License.
  31338. */
  31339. /**
  31340. * @constructor
  31341. * @param {Object} [opt]
  31342. * @param {Object} [opt.categories=[]]
  31343. * @param {Object} [opt.needCollect=false]
  31344. * @param {Object} [opt.deduplication=false]
  31345. */
  31346. function OrdinalMeta(opt) {
  31347. /**
  31348. * @readOnly
  31349. * @type {Array.<string>}
  31350. */
  31351. this.categories = opt.categories || [];
  31352. /**
  31353. * @private
  31354. * @type {boolean}
  31355. */
  31356. this._needCollect = opt.needCollect;
  31357. /**
  31358. * @private
  31359. * @type {boolean}
  31360. */
  31361. this._deduplication = opt.deduplication;
  31362. /**
  31363. * @private
  31364. * @type {boolean}
  31365. */
  31366. this._map;
  31367. }
  31368. /**
  31369. * @param {module:echarts/model/Model} axisModel
  31370. * @return {module:echarts/data/OrdinalMeta}
  31371. */
  31372. OrdinalMeta.createByAxisModel = function (axisModel) {
  31373. var option = axisModel.option;
  31374. var data = option.data;
  31375. var categories = data && map(data, getName);
  31376. return new OrdinalMeta({
  31377. categories: categories,
  31378. needCollect: !categories,
  31379. // deduplication is default in axis.
  31380. deduplication: option.dedplication !== false
  31381. });
  31382. };
  31383. var proto$1 = OrdinalMeta.prototype;
  31384. /**
  31385. * @param {string} category
  31386. * @return {number} ordinal
  31387. */
  31388. proto$1.getOrdinal = function (category) {
  31389. return getOrCreateMap(this).get(category);
  31390. };
  31391. /**
  31392. * @param {*} category
  31393. * @return {number} The ordinal. If not found, return NaN.
  31394. */
  31395. proto$1.parseAndCollect = function (category) {
  31396. var index;
  31397. var needCollect = this._needCollect;
  31398. // The value of category dim can be the index of the given category set.
  31399. // This feature is only supported when !needCollect, because we should
  31400. // consider a common case: a value is 2017, which is a number but is
  31401. // expected to be tread as a category. This case usually happen in dataset,
  31402. // where it happent to be no need of the index feature.
  31403. if (typeof category !== 'string' && !needCollect) {
  31404. return category;
  31405. }
  31406. // Optimize for the scenario:
  31407. // category is ['2012-01-01', '2012-01-02', ...], where the input
  31408. // data has been ensured not duplicate and is large data.
  31409. // Notice, if a dataset dimension provide categroies, usually echarts
  31410. // should remove duplication except user tell echarts dont do that
  31411. // (set axis.deduplication = false), because echarts do not know whether
  31412. // the values in the category dimension has duplication (consider the
  31413. // parallel-aqi example)
  31414. if (needCollect && !this._deduplication) {
  31415. index = this.categories.length;
  31416. this.categories[index] = category;
  31417. return index;
  31418. }
  31419. var map$$1 = getOrCreateMap(this);
  31420. index = map$$1.get(category);
  31421. if (index == null) {
  31422. if (needCollect) {
  31423. index = this.categories.length;
  31424. this.categories[index] = category;
  31425. map$$1.set(category, index);
  31426. }
  31427. else {
  31428. index = NaN;
  31429. }
  31430. }
  31431. return index;
  31432. };
  31433. // Consider big data, do not create map until needed.
  31434. function getOrCreateMap(ordinalMeta) {
  31435. return ordinalMeta._map || (
  31436. ordinalMeta._map = createHashMap(ordinalMeta.categories)
  31437. );
  31438. }
  31439. function getName(obj) {
  31440. if (isObject$1(obj) && obj.value != null) {
  31441. return obj.value;
  31442. }
  31443. else {
  31444. return obj + '';
  31445. }
  31446. }
  31447. /*
  31448. * Licensed to the Apache Software Foundation (ASF) under one
  31449. * or more contributor license agreements. See the NOTICE file
  31450. * distributed with this work for additional information
  31451. * regarding copyright ownership. The ASF licenses this file
  31452. * to you under the Apache License, Version 2.0 (the
  31453. * "License"); you may not use this file except in compliance
  31454. * with the License. You may obtain a copy of the License at
  31455. *
  31456. * http://www.apache.org/licenses/LICENSE-2.0
  31457. *
  31458. * Unless required by applicable law or agreed to in writing,
  31459. * software distributed under the License is distributed on an
  31460. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31461. * KIND, either express or implied. See the License for the
  31462. * specific language governing permissions and limitations
  31463. * under the License.
  31464. */
  31465. /**
  31466. * Linear continuous scale
  31467. * @module echarts/coord/scale/Ordinal
  31468. *
  31469. * http://en.wikipedia.org/wiki/Level_of_measurement
  31470. */
  31471. // FIXME only one data
  31472. var scaleProto = Scale.prototype;
  31473. var OrdinalScale = Scale.extend({
  31474. type: 'ordinal',
  31475. /**
  31476. * @param {module:echarts/data/OrdianlMeta|Array.<string>} ordinalMeta
  31477. */
  31478. init: function (ordinalMeta, extent) {
  31479. // Caution: Should not use instanceof, consider ec-extensions using
  31480. // import approach to get OrdinalMeta class.
  31481. if (!ordinalMeta || isArray(ordinalMeta)) {
  31482. ordinalMeta = new OrdinalMeta({categories: ordinalMeta});
  31483. }
  31484. this._ordinalMeta = ordinalMeta;
  31485. this._extent = extent || [0, ordinalMeta.categories.length - 1];
  31486. },
  31487. parse: function (val) {
  31488. return typeof val === 'string'
  31489. ? this._ordinalMeta.getOrdinal(val)
  31490. // val might be float.
  31491. : Math.round(val);
  31492. },
  31493. contain: function (rank) {
  31494. rank = this.parse(rank);
  31495. return scaleProto.contain.call(this, rank)
  31496. && this._ordinalMeta.categories[rank] != null;
  31497. },
  31498. /**
  31499. * Normalize given rank or name to linear [0, 1]
  31500. * @param {number|string} [val]
  31501. * @return {number}
  31502. */
  31503. normalize: function (val) {
  31504. return scaleProto.normalize.call(this, this.parse(val));
  31505. },
  31506. scale: function (val) {
  31507. return Math.round(scaleProto.scale.call(this, val));
  31508. },
  31509. /**
  31510. * @return {Array}
  31511. */
  31512. getTicks: function () {
  31513. var ticks = [];
  31514. var extent = this._extent;
  31515. var rank = extent[0];
  31516. while (rank <= extent[1]) {
  31517. ticks.push(rank);
  31518. rank++;
  31519. }
  31520. return ticks;
  31521. },
  31522. /**
  31523. * Get item on rank n
  31524. * @param {number} n
  31525. * @return {string}
  31526. */
  31527. getLabel: function (n) {
  31528. if (!this.isBlank()) {
  31529. // Note that if no data, ordinalMeta.categories is an empty array.
  31530. return this._ordinalMeta.categories[n];
  31531. }
  31532. },
  31533. /**
  31534. * @return {number}
  31535. */
  31536. count: function () {
  31537. return this._extent[1] - this._extent[0] + 1;
  31538. },
  31539. /**
  31540. * @override
  31541. */
  31542. unionExtentFromData: function (data, dim) {
  31543. this.unionExtent(data.getApproximateExtent(dim));
  31544. },
  31545. getOrdinalMeta: function () {
  31546. return this._ordinalMeta;
  31547. },
  31548. niceTicks: noop,
  31549. niceExtent: noop
  31550. });
  31551. /**
  31552. * @return {module:echarts/scale/Time}
  31553. */
  31554. OrdinalScale.create = function () {
  31555. return new OrdinalScale();
  31556. };
  31557. /*
  31558. * Licensed to the Apache Software Foundation (ASF) under one
  31559. * or more contributor license agreements. See the NOTICE file
  31560. * distributed with this work for additional information
  31561. * regarding copyright ownership. The ASF licenses this file
  31562. * to you under the Apache License, Version 2.0 (the
  31563. * "License"); you may not use this file except in compliance
  31564. * with the License. You may obtain a copy of the License at
  31565. *
  31566. * http://www.apache.org/licenses/LICENSE-2.0
  31567. *
  31568. * Unless required by applicable law or agreed to in writing,
  31569. * software distributed under the License is distributed on an
  31570. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31571. * KIND, either express or implied. See the License for the
  31572. * specific language governing permissions and limitations
  31573. * under the License.
  31574. */
  31575. /**
  31576. * For testable.
  31577. */
  31578. var roundNumber$1 = round$1;
  31579. /**
  31580. * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
  31581. * Should be extent[0] < extent[1].
  31582. * @param {number} splitNumber splitNumber should be >= 1.
  31583. * @param {number} [minInterval]
  31584. * @param {number} [maxInterval]
  31585. * @return {Object} {interval, intervalPrecision, niceTickExtent}
  31586. */
  31587. function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
  31588. var result = {};
  31589. var span = extent[1] - extent[0];
  31590. var interval = result.interval = nice(span / splitNumber, true);
  31591. if (minInterval != null && interval < minInterval) {
  31592. interval = result.interval = minInterval;
  31593. }
  31594. if (maxInterval != null && interval > maxInterval) {
  31595. interval = result.interval = maxInterval;
  31596. }
  31597. // Tow more digital for tick.
  31598. var precision = result.intervalPrecision = getIntervalPrecision(interval);
  31599. // Niced extent inside original extent
  31600. var niceTickExtent = result.niceTickExtent = [
  31601. roundNumber$1(Math.ceil(extent[0] / interval) * interval, precision),
  31602. roundNumber$1(Math.floor(extent[1] / interval) * interval, precision)
  31603. ];
  31604. fixExtent(niceTickExtent, extent);
  31605. return result;
  31606. }
  31607. /**
  31608. * @param {number} interval
  31609. * @return {number} interval precision
  31610. */
  31611. function getIntervalPrecision(interval) {
  31612. // Tow more digital for tick.
  31613. return getPrecisionSafe(interval) + 2;
  31614. }
  31615. function clamp(niceTickExtent, idx, extent) {
  31616. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  31617. }
  31618. // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  31619. function fixExtent(niceTickExtent, extent) {
  31620. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  31621. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  31622. clamp(niceTickExtent, 0, extent);
  31623. clamp(niceTickExtent, 1, extent);
  31624. if (niceTickExtent[0] > niceTickExtent[1]) {
  31625. niceTickExtent[0] = niceTickExtent[1];
  31626. }
  31627. }
  31628. /*
  31629. * Licensed to the Apache Software Foundation (ASF) under one
  31630. * or more contributor license agreements. See the NOTICE file
  31631. * distributed with this work for additional information
  31632. * regarding copyright ownership. The ASF licenses this file
  31633. * to you under the Apache License, Version 2.0 (the
  31634. * "License"); you may not use this file except in compliance
  31635. * with the License. You may obtain a copy of the License at
  31636. *
  31637. * http://www.apache.org/licenses/LICENSE-2.0
  31638. *
  31639. * Unless required by applicable law or agreed to in writing,
  31640. * software distributed under the License is distributed on an
  31641. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31642. * KIND, either express or implied. See the License for the
  31643. * specific language governing permissions and limitations
  31644. * under the License.
  31645. */
  31646. /**
  31647. * Interval scale
  31648. * @module echarts/scale/Interval
  31649. */
  31650. var roundNumber = round$1;
  31651. /**
  31652. * @alias module:echarts/coord/scale/Interval
  31653. * @constructor
  31654. */
  31655. var IntervalScale = Scale.extend({
  31656. type: 'interval',
  31657. _interval: 0,
  31658. _intervalPrecision: 2,
  31659. setExtent: function (start, end) {
  31660. var thisExtent = this._extent;
  31661. //start,end may be a Number like '25',so...
  31662. if (!isNaN(start)) {
  31663. thisExtent[0] = parseFloat(start);
  31664. }
  31665. if (!isNaN(end)) {
  31666. thisExtent[1] = parseFloat(end);
  31667. }
  31668. },
  31669. unionExtent: function (other) {
  31670. var extent = this._extent;
  31671. other[0] < extent[0] && (extent[0] = other[0]);
  31672. other[1] > extent[1] && (extent[1] = other[1]);
  31673. // unionExtent may called by it's sub classes
  31674. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  31675. },
  31676. /**
  31677. * Get interval
  31678. */
  31679. getInterval: function () {
  31680. return this._interval;
  31681. },
  31682. /**
  31683. * Set interval
  31684. */
  31685. setInterval: function (interval) {
  31686. this._interval = interval;
  31687. // Dropped auto calculated niceExtent and use user setted extent
  31688. // We assume user wan't to set both interval, min, max to get a better result
  31689. this._niceExtent = this._extent.slice();
  31690. this._intervalPrecision = getIntervalPrecision(interval);
  31691. },
  31692. /**
  31693. * @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
  31694. * @return {Array.<number>}
  31695. */
  31696. getTicks: function (expandToNicedExtent) {
  31697. var interval = this._interval;
  31698. var extent = this._extent;
  31699. var niceTickExtent = this._niceExtent;
  31700. var intervalPrecision = this._intervalPrecision;
  31701. var ticks = [];
  31702. // If interval is 0, return [];
  31703. if (!interval) {
  31704. return ticks;
  31705. }
  31706. // Consider this case: using dataZoom toolbox, zoom and zoom.
  31707. var safeLimit = 10000;
  31708. if (extent[0] < niceTickExtent[0]) {
  31709. if (expandToNicedExtent) {
  31710. ticks.push(roundNumber(niceTickExtent[0] - interval, intervalPrecision));
  31711. }
  31712. else {
  31713. ticks.push(extent[0]);
  31714. }
  31715. }
  31716. var tick = niceTickExtent[0];
  31717. while (tick <= niceTickExtent[1]) {
  31718. ticks.push(tick);
  31719. // Avoid rounding error
  31720. tick = roundNumber(tick + interval, intervalPrecision);
  31721. if (tick === ticks[ticks.length - 1]) {
  31722. // Consider out of safe float point, e.g.,
  31723. // -3711126.9907707 + 2e-10 === -3711126.9907707
  31724. break;
  31725. }
  31726. if (ticks.length > safeLimit) {
  31727. return [];
  31728. }
  31729. }
  31730. // Consider this case: the last item of ticks is smaller
  31731. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  31732. var lastNiceTick = ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1];
  31733. if (extent[1] > lastNiceTick) {
  31734. if (expandToNicedExtent) {
  31735. ticks.push(roundNumber(lastNiceTick + interval, intervalPrecision));
  31736. }
  31737. else {
  31738. ticks.push(extent[1]);
  31739. }
  31740. }
  31741. return ticks;
  31742. },
  31743. /**
  31744. * @param {number} [splitNumber=5]
  31745. * @return {Array.<Array.<number>>}
  31746. */
  31747. getMinorTicks: function (splitNumber) {
  31748. var ticks = this.getTicks(true);
  31749. var minorTicks = [];
  31750. var extent = this.getExtent();
  31751. for (var i = 1; i < ticks.length; i++) {
  31752. var nextTick = ticks[i];
  31753. var prevTick = ticks[i - 1];
  31754. var count = 0;
  31755. var minorTicksGroup = [];
  31756. var interval = nextTick - prevTick;
  31757. var minorInterval = interval / splitNumber;
  31758. while (count < splitNumber - 1) {
  31759. var minorTick = round$1(prevTick + (count + 1) * minorInterval);
  31760. // For the first and last interval. The count may be less than splitNumber.
  31761. if (minorTick > extent[0] && minorTick < extent[1]) {
  31762. minorTicksGroup.push(minorTick);
  31763. }
  31764. count++;
  31765. }
  31766. minorTicks.push(minorTicksGroup);
  31767. }
  31768. return minorTicks;
  31769. },
  31770. /**
  31771. * @param {number} data
  31772. * @param {Object} [opt]
  31773. * @param {number|string} [opt.precision] If 'auto', use nice presision.
  31774. * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
  31775. * @return {string}
  31776. */
  31777. getLabel: function (data, opt) {
  31778. if (data == null) {
  31779. return '';
  31780. }
  31781. var precision = opt && opt.precision;
  31782. if (precision == null) {
  31783. precision = getPrecisionSafe(data) || 0;
  31784. }
  31785. else if (precision === 'auto') {
  31786. // Should be more precise then tick.
  31787. precision = this._intervalPrecision;
  31788. }
  31789. // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  31790. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  31791. data = roundNumber(data, precision, true);
  31792. return addCommas(data);
  31793. },
  31794. /**
  31795. * Update interval and extent of intervals for nice ticks
  31796. *
  31797. * @param {number} [splitNumber = 5] Desired number of ticks
  31798. * @param {number} [minInterval]
  31799. * @param {number} [maxInterval]
  31800. */
  31801. niceTicks: function (splitNumber, minInterval, maxInterval) {
  31802. splitNumber = splitNumber || 5;
  31803. var extent = this._extent;
  31804. var span = extent[1] - extent[0];
  31805. if (!isFinite(span)) {
  31806. return;
  31807. }
  31808. // User may set axis min 0 and data are all negative
  31809. // FIXME If it needs to reverse ?
  31810. if (span < 0) {
  31811. span = -span;
  31812. extent.reverse();
  31813. }
  31814. var result = intervalScaleNiceTicks(
  31815. extent, splitNumber, minInterval, maxInterval
  31816. );
  31817. this._intervalPrecision = result.intervalPrecision;
  31818. this._interval = result.interval;
  31819. this._niceExtent = result.niceTickExtent;
  31820. },
  31821. /**
  31822. * Nice extent.
  31823. * @param {Object} opt
  31824. * @param {number} [opt.splitNumber = 5] Given approx tick number
  31825. * @param {boolean} [opt.fixMin=false]
  31826. * @param {boolean} [opt.fixMax=false]
  31827. * @param {boolean} [opt.minInterval]
  31828. * @param {boolean} [opt.maxInterval]
  31829. */
  31830. niceExtent: function (opt) {
  31831. var extent = this._extent;
  31832. // If extent start and end are same, expand them
  31833. if (extent[0] === extent[1]) {
  31834. if (extent[0] !== 0) {
  31835. // Expand extent
  31836. var expandSize = extent[0];
  31837. // In the fowllowing case
  31838. // Axis has been fixed max 100
  31839. // Plus data are all 100 and axis extent are [100, 100].
  31840. // Extend to the both side will cause expanded max is larger than fixed max.
  31841. // So only expand to the smaller side.
  31842. if (!opt.fixMax) {
  31843. extent[1] += expandSize / 2;
  31844. extent[0] -= expandSize / 2;
  31845. }
  31846. else {
  31847. extent[0] -= expandSize / 2;
  31848. }
  31849. }
  31850. else {
  31851. extent[1] = 1;
  31852. }
  31853. }
  31854. var span = extent[1] - extent[0];
  31855. // If there are no data and extent are [Infinity, -Infinity]
  31856. if (!isFinite(span)) {
  31857. extent[0] = 0;
  31858. extent[1] = 1;
  31859. }
  31860. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  31861. // var extent = this._extent;
  31862. var interval = this._interval;
  31863. if (!opt.fixMin) {
  31864. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
  31865. }
  31866. if (!opt.fixMax) {
  31867. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
  31868. }
  31869. }
  31870. });
  31871. /**
  31872. * @return {module:echarts/scale/Time}
  31873. */
  31874. IntervalScale.create = function () {
  31875. return new IntervalScale();
  31876. };
  31877. /*
  31878. * Licensed to the Apache Software Foundation (ASF) under one
  31879. * or more contributor license agreements. See the NOTICE file
  31880. * distributed with this work for additional information
  31881. * regarding copyright ownership. The ASF licenses this file
  31882. * to you under the Apache License, Version 2.0 (the
  31883. * "License"); you may not use this file except in compliance
  31884. * with the License. You may obtain a copy of the License at
  31885. *
  31886. * http://www.apache.org/licenses/LICENSE-2.0
  31887. *
  31888. * Unless required by applicable law or agreed to in writing,
  31889. * software distributed under the License is distributed on an
  31890. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31891. * KIND, either express or implied. See the License for the
  31892. * specific language governing permissions and limitations
  31893. * under the License.
  31894. */
  31895. /* global Float32Array */
  31896. var STACK_PREFIX = '__ec_stack_';
  31897. var LARGE_BAR_MIN_WIDTH = 0.5;
  31898. var LargeArr = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  31899. function getSeriesStackId(seriesModel) {
  31900. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  31901. }
  31902. function getAxisKey(axis) {
  31903. return axis.dim + axis.index;
  31904. }
  31905. /**
  31906. * @param {Object} opt
  31907. * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
  31908. * @param {number} opt.count Positive interger.
  31909. * @param {number} [opt.barWidth]
  31910. * @param {number} [opt.barMaxWidth]
  31911. * @param {number} [opt.barMinWidth]
  31912. * @param {number} [opt.barGap]
  31913. * @param {number} [opt.barCategoryGap]
  31914. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  31915. */
  31916. function prepareLayoutBarSeries(seriesType, ecModel) {
  31917. var seriesModels = [];
  31918. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  31919. // Check series coordinate, do layout for cartesian2d only
  31920. if (isOnCartesian(seriesModel) && !isInLargeMode(seriesModel)) {
  31921. seriesModels.push(seriesModel);
  31922. }
  31923. });
  31924. return seriesModels;
  31925. }
  31926. /**
  31927. * Map from (baseAxis.dim + '_' + baseAxis.index) to min gap of two adjacent
  31928. * values.
  31929. * This works for time axes, value axes, and log axes.
  31930. * For a single time axis, return value is in the form like
  31931. * {'x_0': [1000000]}.
  31932. * The value of 1000000 is in milliseconds.
  31933. */
  31934. function getValueAxesMinGaps(barSeries) {
  31935. /**
  31936. * Map from axis.index to values.
  31937. * For a single time axis, axisValues is in the form like
  31938. * {'x_0': [1495555200000, 1495641600000, 1495728000000]}.
  31939. * Items in axisValues[x], e.g. 1495555200000, are time values of all
  31940. * series.
  31941. */
  31942. var axisValues = {};
  31943. each$1(barSeries, function (seriesModel) {
  31944. var cartesian = seriesModel.coordinateSystem;
  31945. var baseAxis = cartesian.getBaseAxis();
  31946. if (baseAxis.type !== 'time' && baseAxis.type !== 'value') {
  31947. return;
  31948. }
  31949. var data = seriesModel.getData();
  31950. var key = baseAxis.dim + '_' + baseAxis.index;
  31951. var dim = data.mapDimension(baseAxis.dim);
  31952. for (var i = 0, cnt = data.count(); i < cnt; ++i) {
  31953. var value = data.get(dim, i);
  31954. if (!axisValues[key]) {
  31955. // No previous data for the axis
  31956. axisValues[key] = [value];
  31957. }
  31958. else {
  31959. // No value in previous series
  31960. axisValues[key].push(value);
  31961. }
  31962. // Ignore duplicated time values in the same axis
  31963. }
  31964. });
  31965. var axisMinGaps = [];
  31966. for (var key in axisValues) {
  31967. if (axisValues.hasOwnProperty(key)) {
  31968. var valuesInAxis = axisValues[key];
  31969. if (valuesInAxis) {
  31970. // Sort axis values into ascending order to calculate gaps
  31971. valuesInAxis.sort(function (a, b) {
  31972. return a - b;
  31973. });
  31974. var min = null;
  31975. for (var j = 1; j < valuesInAxis.length; ++j) {
  31976. var delta = valuesInAxis[j] - valuesInAxis[j - 1];
  31977. if (delta > 0) {
  31978. // Ignore 0 delta because they are of the same axis value
  31979. min = min === null ? delta : Math.min(min, delta);
  31980. }
  31981. }
  31982. // Set to null if only have one data
  31983. axisMinGaps[key] = min;
  31984. }
  31985. }
  31986. }
  31987. return axisMinGaps;
  31988. }
  31989. function makeColumnLayout(barSeries) {
  31990. var axisMinGaps = getValueAxesMinGaps(barSeries);
  31991. var seriesInfoList = [];
  31992. each$1(barSeries, function (seriesModel) {
  31993. var cartesian = seriesModel.coordinateSystem;
  31994. var baseAxis = cartesian.getBaseAxis();
  31995. var axisExtent = baseAxis.getExtent();
  31996. var bandWidth;
  31997. if (baseAxis.type === 'category') {
  31998. bandWidth = baseAxis.getBandWidth();
  31999. }
  32000. else if (baseAxis.type === 'value' || baseAxis.type === 'time') {
  32001. var key = baseAxis.dim + '_' + baseAxis.index;
  32002. var minGap = axisMinGaps[key];
  32003. var extentSpan = Math.abs(axisExtent[1] - axisExtent[0]);
  32004. var scale = baseAxis.scale.getExtent();
  32005. var scaleSpan = Math.abs(scale[1] - scale[0]);
  32006. bandWidth = minGap
  32007. ? extentSpan / scaleSpan * minGap
  32008. : extentSpan; // When there is only one data value
  32009. }
  32010. else {
  32011. var data = seriesModel.getData();
  32012. bandWidth = Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
  32013. }
  32014. var barWidth = parsePercent$1(
  32015. seriesModel.get('barWidth'), bandWidth
  32016. );
  32017. var barMaxWidth = parsePercent$1(
  32018. seriesModel.get('barMaxWidth'), bandWidth
  32019. );
  32020. var barMinWidth = parsePercent$1(
  32021. // barMinWidth by default is 1 in cartesian. Because in value axis,
  32022. // the auto-calculated bar width might be less than 1.
  32023. seriesModel.get('barMinWidth') || 1, bandWidth
  32024. );
  32025. var barGap = seriesModel.get('barGap');
  32026. var barCategoryGap = seriesModel.get('barCategoryGap');
  32027. seriesInfoList.push({
  32028. bandWidth: bandWidth,
  32029. barWidth: barWidth,
  32030. barMaxWidth: barMaxWidth,
  32031. barMinWidth: barMinWidth,
  32032. barGap: barGap,
  32033. barCategoryGap: barCategoryGap,
  32034. axisKey: getAxisKey(baseAxis),
  32035. stackId: getSeriesStackId(seriesModel)
  32036. });
  32037. });
  32038. return doCalBarWidthAndOffset(seriesInfoList);
  32039. }
  32040. function doCalBarWidthAndOffset(seriesInfoList) {
  32041. // Columns info on each category axis. Key is cartesian name
  32042. var columnsMap = {};
  32043. each$1(seriesInfoList, function (seriesInfo, idx) {
  32044. var axisKey = seriesInfo.axisKey;
  32045. var bandWidth = seriesInfo.bandWidth;
  32046. var columnsOnAxis = columnsMap[axisKey] || {
  32047. bandWidth: bandWidth,
  32048. remainedWidth: bandWidth,
  32049. autoWidthCount: 0,
  32050. categoryGap: '20%',
  32051. gap: '30%',
  32052. stacks: {}
  32053. };
  32054. var stacks = columnsOnAxis.stacks;
  32055. columnsMap[axisKey] = columnsOnAxis;
  32056. var stackId = seriesInfo.stackId;
  32057. if (!stacks[stackId]) {
  32058. columnsOnAxis.autoWidthCount++;
  32059. }
  32060. stacks[stackId] = stacks[stackId] || {
  32061. width: 0,
  32062. maxWidth: 0
  32063. };
  32064. // Caution: In a single coordinate system, these barGrid attributes
  32065. // will be shared by series. Consider that they have default values,
  32066. // only the attributes set on the last series will work.
  32067. // Do not change this fact unless there will be a break change.
  32068. var barWidth = seriesInfo.barWidth;
  32069. if (barWidth && !stacks[stackId].width) {
  32070. // See #6312, do not restrict width.
  32071. stacks[stackId].width = barWidth;
  32072. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  32073. columnsOnAxis.remainedWidth -= barWidth;
  32074. }
  32075. var barMaxWidth = seriesInfo.barMaxWidth;
  32076. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  32077. var barMinWidth = seriesInfo.barMinWidth;
  32078. barMinWidth && (stacks[stackId].minWidth = barMinWidth);
  32079. var barGap = seriesInfo.barGap;
  32080. (barGap != null) && (columnsOnAxis.gap = barGap);
  32081. var barCategoryGap = seriesInfo.barCategoryGap;
  32082. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  32083. });
  32084. var result = {};
  32085. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  32086. result[coordSysName] = {};
  32087. var stacks = columnsOnAxis.stacks;
  32088. var bandWidth = columnsOnAxis.bandWidth;
  32089. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  32090. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  32091. var remainedWidth = columnsOnAxis.remainedWidth;
  32092. var autoWidthCount = columnsOnAxis.autoWidthCount;
  32093. var autoWidth = (remainedWidth - categoryGap)
  32094. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  32095. autoWidth = Math.max(autoWidth, 0);
  32096. // Find if any auto calculated bar exceeded maxBarWidth
  32097. each$1(stacks, function (column) {
  32098. var maxWidth = column.maxWidth;
  32099. var minWidth = column.minWidth;
  32100. if (!column.width) {
  32101. var finalWidth = autoWidth;
  32102. if (maxWidth && maxWidth < finalWidth) {
  32103. finalWidth = Math.min(maxWidth, remainedWidth);
  32104. }
  32105. // `minWidth` has higher priority. `minWidth` decide that wheter the
  32106. // bar is able to be visible. So `minWidth` should not be restricted
  32107. // by `maxWidth` or `remainedWidth` (which is from `bandWidth`). In
  32108. // the extreme cases for `value` axis, bars are allowed to overlap
  32109. // with each other if `minWidth` specified.
  32110. if (minWidth && minWidth > finalWidth) {
  32111. finalWidth = minWidth;
  32112. }
  32113. if (finalWidth !== autoWidth) {
  32114. column.width = finalWidth;
  32115. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  32116. autoWidthCount--;
  32117. }
  32118. }
  32119. else {
  32120. // `barMinWidth/barMaxWidth` has higher priority than `barWidth`, as
  32121. // CSS does. Becuase barWidth can be a percent value, where
  32122. // `barMaxWidth` can be used to restrict the final width.
  32123. var finalWidth = column.width;
  32124. if (maxWidth) {
  32125. finalWidth = Math.min(finalWidth, maxWidth);
  32126. }
  32127. // `minWidth` has higher priority, as described above
  32128. if (minWidth) {
  32129. finalWidth = Math.max(finalWidth, minWidth);
  32130. }
  32131. column.width = finalWidth;
  32132. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  32133. autoWidthCount--;
  32134. }
  32135. });
  32136. // Recalculate width again
  32137. autoWidth = (remainedWidth - categoryGap)
  32138. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  32139. autoWidth = Math.max(autoWidth, 0);
  32140. var widthSum = 0;
  32141. var lastColumn;
  32142. each$1(stacks, function (column, idx) {
  32143. if (!column.width) {
  32144. column.width = autoWidth;
  32145. }
  32146. lastColumn = column;
  32147. widthSum += column.width * (1 + barGapPercent);
  32148. });
  32149. if (lastColumn) {
  32150. widthSum -= lastColumn.width * barGapPercent;
  32151. }
  32152. var offset = -widthSum / 2;
  32153. each$1(stacks, function (column, stackId) {
  32154. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  32155. bandWidth: bandWidth,
  32156. offset: offset,
  32157. width: column.width
  32158. };
  32159. offset += column.width * (1 + barGapPercent);
  32160. });
  32161. });
  32162. return result;
  32163. }
  32164. /**
  32165. * @param {Object} barWidthAndOffset The result of makeColumnLayout
  32166. * @param {module:echarts/coord/Axis} axis
  32167. * @param {module:echarts/model/Series} [seriesModel] If not provided, return all.
  32168. * @return {Object} {stackId: {offset, width}} or {offset, width} if seriesModel provided.
  32169. */
  32170. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  32171. if (barWidthAndOffset && axis) {
  32172. var result = barWidthAndOffset[getAxisKey(axis)];
  32173. if (result != null && seriesModel != null) {
  32174. result = result[getSeriesStackId(seriesModel)];
  32175. }
  32176. return result;
  32177. }
  32178. }
  32179. /**
  32180. * @param {string} seriesType
  32181. * @param {module:echarts/model/Global} ecModel
  32182. */
  32183. function layout(seriesType, ecModel) {
  32184. var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
  32185. var barWidthAndOffset = makeColumnLayout(seriesModels);
  32186. var lastStackCoords = {};
  32187. each$1(seriesModels, function (seriesModel) {
  32188. var data = seriesModel.getData();
  32189. var cartesian = seriesModel.coordinateSystem;
  32190. var baseAxis = cartesian.getBaseAxis();
  32191. var stackId = getSeriesStackId(seriesModel);
  32192. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  32193. var columnOffset = columnLayoutInfo.offset;
  32194. var columnWidth = columnLayoutInfo.width;
  32195. var valueAxis = cartesian.getOtherAxis(baseAxis);
  32196. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  32197. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  32198. data.setLayout({
  32199. bandWidth: columnLayoutInfo.bandWidth,
  32200. offset: columnOffset,
  32201. size: columnWidth
  32202. });
  32203. var valueDim = data.mapDimension(valueAxis.dim);
  32204. var baseDim = data.mapDimension(baseAxis.dim);
  32205. var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
  32206. var isValueAxisH = valueAxis.isHorizontal();
  32207. var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked);
  32208. for (var idx = 0, len = data.count(); idx < len; idx++) {
  32209. var value = data.get(valueDim, idx);
  32210. var baseValue = data.get(baseDim, idx);
  32211. var sign = value >= 0 ? 'p' : 'n';
  32212. var baseCoord = valueAxisStart;
  32213. // Because of the barMinHeight, we can not use the value in
  32214. // stackResultDimension directly.
  32215. if (stacked) {
  32216. // Only ordinal axis can be stacked.
  32217. if (!lastStackCoords[stackId][baseValue]) {
  32218. lastStackCoords[stackId][baseValue] = {
  32219. p: valueAxisStart, // Positive stack
  32220. n: valueAxisStart // Negative stack
  32221. };
  32222. }
  32223. // Should also consider #4243
  32224. baseCoord = lastStackCoords[stackId][baseValue][sign];
  32225. }
  32226. var x;
  32227. var y;
  32228. var width;
  32229. var height;
  32230. if (isValueAxisH) {
  32231. var coord = cartesian.dataToPoint([value, baseValue]);
  32232. x = baseCoord;
  32233. y = coord[1] + columnOffset;
  32234. width = coord[0] - valueAxisStart;
  32235. height = columnWidth;
  32236. if (Math.abs(width) < barMinHeight) {
  32237. width = (width < 0 ? -1 : 1) * barMinHeight;
  32238. }
  32239. // Ignore stack from NaN value
  32240. if (!isNaN(width)) {
  32241. stacked && (lastStackCoords[stackId][baseValue][sign] += width);
  32242. }
  32243. }
  32244. else {
  32245. var coord = cartesian.dataToPoint([baseValue, value]);
  32246. x = coord[0] + columnOffset;
  32247. y = baseCoord;
  32248. width = columnWidth;
  32249. height = coord[1] - valueAxisStart;
  32250. if (Math.abs(height) < barMinHeight) {
  32251. // Include zero to has a positive bar
  32252. height = (height <= 0 ? -1 : 1) * barMinHeight;
  32253. }
  32254. // Ignore stack from NaN value
  32255. if (!isNaN(height)) {
  32256. stacked && (lastStackCoords[stackId][baseValue][sign] += height);
  32257. }
  32258. }
  32259. data.setItemLayout(idx, {
  32260. x: x,
  32261. y: y,
  32262. width: width,
  32263. height: height
  32264. });
  32265. }
  32266. }, this);
  32267. }
  32268. // TODO: Do not support stack in large mode yet.
  32269. var largeLayout = {
  32270. seriesType: 'bar',
  32271. plan: createRenderPlanner(),
  32272. reset: function (seriesModel) {
  32273. if (!isOnCartesian(seriesModel) || !isInLargeMode(seriesModel)) {
  32274. return;
  32275. }
  32276. var data = seriesModel.getData();
  32277. var cartesian = seriesModel.coordinateSystem;
  32278. var coordLayout = cartesian.grid.getRect();
  32279. var baseAxis = cartesian.getBaseAxis();
  32280. var valueAxis = cartesian.getOtherAxis(baseAxis);
  32281. var valueDim = data.mapDimension(valueAxis.dim);
  32282. var baseDim = data.mapDimension(baseAxis.dim);
  32283. var valueAxisHorizontal = valueAxis.isHorizontal();
  32284. var valueDimIdx = valueAxisHorizontal ? 0 : 1;
  32285. var barWidth = retrieveColumnLayout(
  32286. makeColumnLayout([seriesModel]), baseAxis, seriesModel
  32287. ).width;
  32288. if (!(barWidth > LARGE_BAR_MIN_WIDTH)) { // jshint ignore:line
  32289. barWidth = LARGE_BAR_MIN_WIDTH;
  32290. }
  32291. return {progress: progress};
  32292. function progress(params, data) {
  32293. var count = params.count;
  32294. var largePoints = new LargeArr(count * 2);
  32295. var largeBackgroundPoints = new LargeArr(count * 2);
  32296. var largeDataIndices = new LargeArr(count);
  32297. var dataIndex;
  32298. var coord = [];
  32299. var valuePair = [];
  32300. var pointsOffset = 0;
  32301. var idxOffset = 0;
  32302. while ((dataIndex = params.next()) != null) {
  32303. valuePair[valueDimIdx] = data.get(valueDim, dataIndex);
  32304. valuePair[1 - valueDimIdx] = data.get(baseDim, dataIndex);
  32305. coord = cartesian.dataToPoint(valuePair, null, coord);
  32306. // Data index might not be in order, depends on `progressiveChunkMode`.
  32307. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal
  32308. ? coordLayout.x + coordLayout.width : coord[0];
  32309. largePoints[pointsOffset++] = coord[0];
  32310. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal
  32311. ? coord[1] : coordLayout.y + coordLayout.height;
  32312. largePoints[pointsOffset++] = coord[1];
  32313. largeDataIndices[idxOffset++] = dataIndex;
  32314. }
  32315. data.setLayout({
  32316. largePoints: largePoints,
  32317. largeDataIndices: largeDataIndices,
  32318. largeBackgroundPoints: largeBackgroundPoints,
  32319. barWidth: barWidth,
  32320. valueAxisStart: getValueAxisStart(baseAxis, valueAxis, false),
  32321. backgroundStart: valueAxisHorizontal ? coordLayout.x : coordLayout.y,
  32322. valueAxisHorizontal: valueAxisHorizontal
  32323. });
  32324. }
  32325. }
  32326. };
  32327. function isOnCartesian(seriesModel) {
  32328. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  32329. }
  32330. function isInLargeMode(seriesModel) {
  32331. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  32332. }
  32333. // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  32334. function getValueAxisStart(baseAxis, valueAxis, stacked) {
  32335. return valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.type === 'log' ? 1 : 0));
  32336. }
  32337. /*
  32338. * Licensed to the Apache Software Foundation (ASF) under one
  32339. * or more contributor license agreements. See the NOTICE file
  32340. * distributed with this work for additional information
  32341. * regarding copyright ownership. The ASF licenses this file
  32342. * to you under the Apache License, Version 2.0 (the
  32343. * "License"); you may not use this file except in compliance
  32344. * with the License. You may obtain a copy of the License at
  32345. *
  32346. * http://www.apache.org/licenses/LICENSE-2.0
  32347. *
  32348. * Unless required by applicable law or agreed to in writing,
  32349. * software distributed under the License is distributed on an
  32350. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32351. * KIND, either express or implied. See the License for the
  32352. * specific language governing permissions and limitations
  32353. * under the License.
  32354. */
  32355. /*
  32356. * A third-party license is embeded for some of the code in this file:
  32357. * The "scaleLevels" was originally copied from "d3.js" with some
  32358. * modifications made for this project.
  32359. * (See more details in the comment on the definition of "scaleLevels" below.)
  32360. * The use of the source code of this file is also subject to the terms
  32361. * and consitions of the license of "d3.js" (BSD-3Clause, see
  32362. * </licenses/LICENSE-d3>).
  32363. */
  32364. // [About UTC and local time zone]:
  32365. // In most cases, `number.parseDate` will treat input data string as local time
  32366. // (except time zone is specified in time string). And `format.formateTime` returns
  32367. // local time by default. option.useUTC is false by default. This design have
  32368. // concidered these common case:
  32369. // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
  32370. // in local time by default.
  32371. // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
  32372. // as its original time, without any time difference.
  32373. var intervalScaleProto = IntervalScale.prototype;
  32374. var mathCeil = Math.ceil;
  32375. var mathFloor = Math.floor;
  32376. var ONE_SECOND = 1000;
  32377. var ONE_MINUTE = ONE_SECOND * 60;
  32378. var ONE_HOUR = ONE_MINUTE * 60;
  32379. var ONE_DAY = ONE_HOUR * 24;
  32380. // FIXME 公用?
  32381. var bisect = function (a, x, lo, hi) {
  32382. while (lo < hi) {
  32383. var mid = lo + hi >>> 1;
  32384. if (a[mid][1] < x) {
  32385. lo = mid + 1;
  32386. }
  32387. else {
  32388. hi = mid;
  32389. }
  32390. }
  32391. return lo;
  32392. };
  32393. /**
  32394. * @alias module:echarts/coord/scale/Time
  32395. * @constructor
  32396. */
  32397. var TimeScale = IntervalScale.extend({
  32398. type: 'time',
  32399. /**
  32400. * @override
  32401. */
  32402. getLabel: function (val) {
  32403. var stepLvl = this._stepLvl;
  32404. var date = new Date(val);
  32405. return formatTime(stepLvl[0], date, this.getSetting('useUTC'));
  32406. },
  32407. /**
  32408. * @override
  32409. */
  32410. niceExtent: function (opt) {
  32411. var extent = this._extent;
  32412. // If extent start and end are same, expand them
  32413. if (extent[0] === extent[1]) {
  32414. // Expand extent
  32415. extent[0] -= ONE_DAY;
  32416. extent[1] += ONE_DAY;
  32417. }
  32418. // If there are no data and extent are [Infinity, -Infinity]
  32419. if (extent[1] === -Infinity && extent[0] === Infinity) {
  32420. var d = new Date();
  32421. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  32422. extent[0] = extent[1] - ONE_DAY;
  32423. }
  32424. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  32425. // var extent = this._extent;
  32426. var interval = this._interval;
  32427. if (!opt.fixMin) {
  32428. extent[0] = round$1(mathFloor(extent[0] / interval) * interval);
  32429. }
  32430. if (!opt.fixMax) {
  32431. extent[1] = round$1(mathCeil(extent[1] / interval) * interval);
  32432. }
  32433. },
  32434. /**
  32435. * @override
  32436. */
  32437. niceTicks: function (approxTickNum, minInterval, maxInterval) {
  32438. approxTickNum = approxTickNum || 10;
  32439. var extent = this._extent;
  32440. var span = extent[1] - extent[0];
  32441. var approxInterval = span / approxTickNum;
  32442. if (minInterval != null && approxInterval < minInterval) {
  32443. approxInterval = minInterval;
  32444. }
  32445. if (maxInterval != null && approxInterval > maxInterval) {
  32446. approxInterval = maxInterval;
  32447. }
  32448. var scaleLevelsLen = scaleLevels.length;
  32449. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  32450. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  32451. var interval = level[1];
  32452. // Same with interval scale if span is much larger than 1 year
  32453. if (level[0] === 'year') {
  32454. var yearSpan = span / interval;
  32455. // From "Nice Numbers for Graph Labels" of Graphic Gems
  32456. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  32457. var yearStep = nice(yearSpan / approxTickNum, true);
  32458. interval *= yearStep;
  32459. }
  32460. var timezoneOffset = this.getSetting('useUTC')
  32461. ? 0 : (new Date(+extent[0] || +extent[1])).getTimezoneOffset() * 60 * 1000;
  32462. var niceExtent = [
  32463. Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset),
  32464. Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)
  32465. ];
  32466. fixExtent(niceExtent, extent);
  32467. this._stepLvl = level;
  32468. // Interval will be used in getTicks
  32469. this._interval = interval;
  32470. this._niceExtent = niceExtent;
  32471. },
  32472. parse: function (val) {
  32473. // val might be float.
  32474. return +parseDate(val);
  32475. }
  32476. });
  32477. each$1(['contain', 'normalize'], function (methodName) {
  32478. TimeScale.prototype[methodName] = function (val) {
  32479. return intervalScaleProto[methodName].call(this, this.parse(val));
  32480. };
  32481. });
  32482. /**
  32483. * This implementation was originally copied from "d3.js"
  32484. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  32485. * with some modifications made for this program.
  32486. * See the license statement at the head of this file.
  32487. */
  32488. var scaleLevels = [
  32489. // Format interval
  32490. ['hh:mm:ss', ONE_SECOND], // 1s
  32491. ['hh:mm:ss', ONE_SECOND * 5], // 5s
  32492. ['hh:mm:ss', ONE_SECOND * 10], // 10s
  32493. ['hh:mm:ss', ONE_SECOND * 15], // 15s
  32494. ['hh:mm:ss', ONE_SECOND * 30], // 30s
  32495. ['hh:mm\nMM-dd', ONE_MINUTE], // 1m
  32496. ['hh:mm\nMM-dd', ONE_MINUTE * 5], // 5m
  32497. ['hh:mm\nMM-dd', ONE_MINUTE * 10], // 10m
  32498. ['hh:mm\nMM-dd', ONE_MINUTE * 15], // 15m
  32499. ['hh:mm\nMM-dd', ONE_MINUTE * 30], // 30m
  32500. ['hh:mm\nMM-dd', ONE_HOUR], // 1h
  32501. ['hh:mm\nMM-dd', ONE_HOUR * 2], // 2h
  32502. ['hh:mm\nMM-dd', ONE_HOUR * 6], // 6h
  32503. ['hh:mm\nMM-dd', ONE_HOUR * 12], // 12h
  32504. ['MM-dd\nyyyy', ONE_DAY], // 1d
  32505. ['MM-dd\nyyyy', ONE_DAY * 2], // 2d
  32506. ['MM-dd\nyyyy', ONE_DAY * 3], // 3d
  32507. ['MM-dd\nyyyy', ONE_DAY * 4], // 4d
  32508. ['MM-dd\nyyyy', ONE_DAY * 5], // 5d
  32509. ['MM-dd\nyyyy', ONE_DAY * 6], // 6d
  32510. ['week', ONE_DAY * 7], // 7d
  32511. ['MM-dd\nyyyy', ONE_DAY * 10], // 10d
  32512. ['week', ONE_DAY * 14], // 2w
  32513. ['week', ONE_DAY * 21], // 3w
  32514. ['month', ONE_DAY * 31], // 1M
  32515. ['week', ONE_DAY * 42], // 6w
  32516. ['month', ONE_DAY * 62], // 2M
  32517. ['week', ONE_DAY * 70], // 10w
  32518. ['quarter', ONE_DAY * 95], // 3M
  32519. ['month', ONE_DAY * 31 * 4], // 4M
  32520. ['month', ONE_DAY * 31 * 5], // 5M
  32521. ['half-year', ONE_DAY * 380 / 2], // 6M
  32522. ['month', ONE_DAY * 31 * 8], // 8M
  32523. ['month', ONE_DAY * 31 * 10], // 10M
  32524. ['year', ONE_DAY * 380] // 1Y
  32525. ];
  32526. /**
  32527. * @param {module:echarts/model/Model}
  32528. * @return {module:echarts/scale/Time}
  32529. */
  32530. TimeScale.create = function (model) {
  32531. return new TimeScale({useUTC: model.ecModel.get('useUTC')});
  32532. };
  32533. /*
  32534. * Licensed to the Apache Software Foundation (ASF) under one
  32535. * or more contributor license agreements. See the NOTICE file
  32536. * distributed with this work for additional information
  32537. * regarding copyright ownership. The ASF licenses this file
  32538. * to you under the Apache License, Version 2.0 (the
  32539. * "License"); you may not use this file except in compliance
  32540. * with the License. You may obtain a copy of the License at
  32541. *
  32542. * http://www.apache.org/licenses/LICENSE-2.0
  32543. *
  32544. * Unless required by applicable law or agreed to in writing,
  32545. * software distributed under the License is distributed on an
  32546. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32547. * KIND, either express or implied. See the License for the
  32548. * specific language governing permissions and limitations
  32549. * under the License.
  32550. */
  32551. /**
  32552. * Log scale
  32553. * @module echarts/scale/Log
  32554. */
  32555. // Use some method of IntervalScale
  32556. var scaleProto$1 = Scale.prototype;
  32557. var intervalScaleProto$1 = IntervalScale.prototype;
  32558. var getPrecisionSafe$1 = getPrecisionSafe;
  32559. var roundingErrorFix = round$1;
  32560. var mathFloor$1 = Math.floor;
  32561. var mathCeil$1 = Math.ceil;
  32562. var mathPow$1 = Math.pow;
  32563. var mathLog = Math.log;
  32564. var LogScale = Scale.extend({
  32565. type: 'log',
  32566. base: 10,
  32567. $constructor: function () {
  32568. Scale.apply(this, arguments);
  32569. this._originalScale = new IntervalScale();
  32570. },
  32571. /**
  32572. * @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
  32573. * @return {Array.<number>}
  32574. */
  32575. getTicks: function (expandToNicedExtent) {
  32576. var originalScale = this._originalScale;
  32577. var extent = this._extent;
  32578. var originalExtent = originalScale.getExtent();
  32579. return map(intervalScaleProto$1.getTicks.call(this, expandToNicedExtent), function (val) {
  32580. var powVal = round$1(mathPow$1(this.base, val));
  32581. // Fix #4158
  32582. powVal = (val === extent[0] && originalScale.__fixMin)
  32583. ? fixRoundingError(powVal, originalExtent[0])
  32584. : powVal;
  32585. powVal = (val === extent[1] && originalScale.__fixMax)
  32586. ? fixRoundingError(powVal, originalExtent[1])
  32587. : powVal;
  32588. return powVal;
  32589. }, this);
  32590. },
  32591. /**
  32592. * @param {number} splitNumber
  32593. * @return {Array.<Array.<number>>}
  32594. */
  32595. getMinorTicks: intervalScaleProto$1.getMinorTicks,
  32596. /**
  32597. * @param {number} val
  32598. * @return {string}
  32599. */
  32600. getLabel: intervalScaleProto$1.getLabel,
  32601. /**
  32602. * @param {number} val
  32603. * @return {number}
  32604. */
  32605. scale: function (val) {
  32606. val = scaleProto$1.scale.call(this, val);
  32607. return mathPow$1(this.base, val);
  32608. },
  32609. /**
  32610. * @param {number} start
  32611. * @param {number} end
  32612. */
  32613. setExtent: function (start, end) {
  32614. var base = this.base;
  32615. start = mathLog(start) / mathLog(base);
  32616. end = mathLog(end) / mathLog(base);
  32617. intervalScaleProto$1.setExtent.call(this, start, end);
  32618. },
  32619. /**
  32620. * @return {number} end
  32621. */
  32622. getExtent: function () {
  32623. var base = this.base;
  32624. var extent = scaleProto$1.getExtent.call(this);
  32625. extent[0] = mathPow$1(base, extent[0]);
  32626. extent[1] = mathPow$1(base, extent[1]);
  32627. // Fix #4158
  32628. var originalScale = this._originalScale;
  32629. var originalExtent = originalScale.getExtent();
  32630. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  32631. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  32632. return extent;
  32633. },
  32634. /**
  32635. * @param {Array.<number>} extent
  32636. */
  32637. unionExtent: function (extent) {
  32638. this._originalScale.unionExtent(extent);
  32639. var base = this.base;
  32640. extent[0] = mathLog(extent[0]) / mathLog(base);
  32641. extent[1] = mathLog(extent[1]) / mathLog(base);
  32642. scaleProto$1.unionExtent.call(this, extent);
  32643. },
  32644. /**
  32645. * @override
  32646. */
  32647. unionExtentFromData: function (data, dim) {
  32648. // TODO
  32649. // filter value that <= 0
  32650. this.unionExtent(data.getApproximateExtent(dim));
  32651. },
  32652. /**
  32653. * Update interval and extent of intervals for nice ticks
  32654. * @param {number} [approxTickNum = 10] Given approx tick number
  32655. */
  32656. niceTicks: function (approxTickNum) {
  32657. approxTickNum = approxTickNum || 10;
  32658. var extent = this._extent;
  32659. var span = extent[1] - extent[0];
  32660. if (span === Infinity || span <= 0) {
  32661. return;
  32662. }
  32663. var interval = quantity(span);
  32664. var err = approxTickNum / span * interval;
  32665. // Filter ticks to get closer to the desired count.
  32666. if (err <= 0.5) {
  32667. interval *= 10;
  32668. }
  32669. // Interval should be integer
  32670. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  32671. interval *= 10;
  32672. }
  32673. var niceExtent = [
  32674. round$1(mathCeil$1(extent[0] / interval) * interval),
  32675. round$1(mathFloor$1(extent[1] / interval) * interval)
  32676. ];
  32677. this._interval = interval;
  32678. this._niceExtent = niceExtent;
  32679. },
  32680. /**
  32681. * Nice extent.
  32682. * @override
  32683. */
  32684. niceExtent: function (opt) {
  32685. intervalScaleProto$1.niceExtent.call(this, opt);
  32686. var originalScale = this._originalScale;
  32687. originalScale.__fixMin = opt.fixMin;
  32688. originalScale.__fixMax = opt.fixMax;
  32689. }
  32690. });
  32691. each$1(['contain', 'normalize'], function (methodName) {
  32692. LogScale.prototype[methodName] = function (val) {
  32693. val = mathLog(val) / mathLog(this.base);
  32694. return scaleProto$1[methodName].call(this, val);
  32695. };
  32696. });
  32697. LogScale.create = function () {
  32698. return new LogScale();
  32699. };
  32700. function fixRoundingError(val, originalVal) {
  32701. return roundingErrorFix(val, getPrecisionSafe$1(originalVal));
  32702. }
  32703. /*
  32704. * Licensed to the Apache Software Foundation (ASF) under one
  32705. * or more contributor license agreements. See the NOTICE file
  32706. * distributed with this work for additional information
  32707. * regarding copyright ownership. The ASF licenses this file
  32708. * to you under the Apache License, Version 2.0 (the
  32709. * "License"); you may not use this file except in compliance
  32710. * with the License. You may obtain a copy of the License at
  32711. *
  32712. * http://www.apache.org/licenses/LICENSE-2.0
  32713. *
  32714. * Unless required by applicable law or agreed to in writing,
  32715. * software distributed under the License is distributed on an
  32716. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32717. * KIND, either express or implied. See the License for the
  32718. * specific language governing permissions and limitations
  32719. * under the License.
  32720. */
  32721. /**
  32722. * Get axis scale extent before niced.
  32723. * Item of returned array can only be number (including Infinity and NaN).
  32724. */
  32725. function getScaleExtent(scale, model) {
  32726. var scaleType = scale.type;
  32727. var min = model.getMin();
  32728. var max = model.getMax();
  32729. var originalExtent = scale.getExtent();
  32730. var axisDataLen;
  32731. var boundaryGap;
  32732. var span;
  32733. if (scaleType === 'ordinal') {
  32734. axisDataLen = model.getCategories().length;
  32735. }
  32736. else {
  32737. boundaryGap = model.get('boundaryGap');
  32738. if (!isArray(boundaryGap)) {
  32739. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  32740. }
  32741. if (typeof boundaryGap[0] === 'boolean') {
  32742. if (__DEV__) {
  32743. console.warn('Boolean type for boundaryGap is only '
  32744. + 'allowed for ordinal axis. Please use string in '
  32745. + 'percentage instead, e.g., "20%". Currently, '
  32746. + 'boundaryGap is set to be 0.');
  32747. }
  32748. boundaryGap = [0, 0];
  32749. }
  32750. boundaryGap[0] = parsePercent$1(boundaryGap[0], 1);
  32751. boundaryGap[1] = parsePercent$1(boundaryGap[1], 1);
  32752. span = (originalExtent[1] - originalExtent[0])
  32753. || Math.abs(originalExtent[0]);
  32754. }
  32755. // Notice: When min/max is not set (that is, when there are null/undefined,
  32756. // which is the most common case), these cases should be ensured:
  32757. // (1) For 'ordinal', show all axis.data.
  32758. // (2) For others:
  32759. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  32760. // disabled).
  32761. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  32762. // be the result that originalExtent enlarged by boundaryGap.
  32763. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  32764. // FIXME
  32765. // (1) When min/max is 'dataMin' or 'dataMax', should boundaryGap be able to used?
  32766. // (2) When `needCrossZero` and all data is positive/negative, should it be ensured
  32767. // that the results processed by boundaryGap are positive/negative?
  32768. if (min === 'dataMin') {
  32769. min = originalExtent[0];
  32770. }
  32771. else if (typeof min === 'function') {
  32772. min = min({
  32773. min: originalExtent[0],
  32774. max: originalExtent[1]
  32775. });
  32776. }
  32777. if (max === 'dataMax') {
  32778. max = originalExtent[1];
  32779. }
  32780. else if (typeof max === 'function') {
  32781. max = max({
  32782. min: originalExtent[0],
  32783. max: originalExtent[1]
  32784. });
  32785. }
  32786. var fixMin = min != null;
  32787. var fixMax = max != null;
  32788. if (min == null) {
  32789. min = scaleType === 'ordinal'
  32790. ? (axisDataLen ? 0 : NaN)
  32791. : originalExtent[0] - boundaryGap[0] * span;
  32792. }
  32793. if (max == null) {
  32794. max = scaleType === 'ordinal'
  32795. ? (axisDataLen ? axisDataLen - 1 : NaN)
  32796. : originalExtent[1] + boundaryGap[1] * span;
  32797. }
  32798. (min == null || !isFinite(min)) && (min = NaN);
  32799. (max == null || !isFinite(max)) && (max = NaN);
  32800. scale.setBlank(
  32801. eqNaN(min)
  32802. || eqNaN(max)
  32803. || (scaleType === 'ordinal' && !scale.getOrdinalMeta().categories.length)
  32804. );
  32805. // Evaluate if axis needs cross zero
  32806. if (model.getNeedCrossZero()) {
  32807. // Axis is over zero and min is not set
  32808. if (min > 0 && max > 0 && !fixMin) {
  32809. min = 0;
  32810. }
  32811. // Axis is under zero and max is not set
  32812. if (min < 0 && max < 0 && !fixMax) {
  32813. max = 0;
  32814. }
  32815. }
  32816. // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  32817. // is base axis
  32818. // FIXME
  32819. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  32820. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  32821. // Should not depend on series type `bar`?
  32822. // (3) Fix that might overlap when using dataZoom.
  32823. // (4) Consider other chart types using `barGrid`?
  32824. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  32825. var ecModel = model.ecModel;
  32826. if (ecModel && (scaleType === 'time' /*|| scaleType === 'interval' */)) {
  32827. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  32828. var isBaseAxisAndHasBarSeries;
  32829. each$1(barSeriesModels, function (seriesModel) {
  32830. isBaseAxisAndHasBarSeries |= seriesModel.getBaseAxis() === model.axis;
  32831. });
  32832. if (isBaseAxisAndHasBarSeries) {
  32833. // Calculate placement of bars on axis
  32834. var barWidthAndOffset = makeColumnLayout(barSeriesModels);
  32835. // Adjust axis min and max to account for overflow
  32836. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  32837. min = adjustedScale.min;
  32838. max = adjustedScale.max;
  32839. }
  32840. }
  32841. return {
  32842. extent: [min, max],
  32843. // "fix" means "fixed", the value should not be
  32844. // changed in the subsequent steps.
  32845. fixMin: fixMin,
  32846. fixMax: fixMax
  32847. };
  32848. }
  32849. function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
  32850. // Get Axis Length
  32851. var axisExtent = model.axis.getExtent();
  32852. var axisLength = axisExtent[1] - axisExtent[0];
  32853. // Get bars on current base axis and calculate min and max overflow
  32854. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  32855. if (barsOnCurrentAxis === undefined) {
  32856. return {min: min, max: max};
  32857. }
  32858. var minOverflow = Infinity;
  32859. each$1(barsOnCurrentAxis, function (item) {
  32860. minOverflow = Math.min(item.offset, minOverflow);
  32861. });
  32862. var maxOverflow = -Infinity;
  32863. each$1(barsOnCurrentAxis, function (item) {
  32864. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  32865. });
  32866. minOverflow = Math.abs(minOverflow);
  32867. maxOverflow = Math.abs(maxOverflow);
  32868. var totalOverFlow = minOverflow + maxOverflow;
  32869. // Calulate required buffer based on old range and overflow
  32870. var oldRange = max - min;
  32871. var oldRangePercentOfNew = (1 - (minOverflow + maxOverflow) / axisLength);
  32872. var overflowBuffer = ((oldRange / oldRangePercentOfNew) - oldRange);
  32873. max += overflowBuffer * (maxOverflow / totalOverFlow);
  32874. min -= overflowBuffer * (minOverflow / totalOverFlow);
  32875. return {min: min, max: max};
  32876. }
  32877. function niceScaleExtent(scale, model) {
  32878. var extentInfo = getScaleExtent(scale, model);
  32879. var extent = extentInfo.extent;
  32880. var splitNumber = model.get('splitNumber');
  32881. if (scale.type === 'log') {
  32882. scale.base = model.get('logBase');
  32883. }
  32884. var scaleType = scale.type;
  32885. scale.setExtent(extent[0], extent[1]);
  32886. scale.niceExtent({
  32887. splitNumber: splitNumber,
  32888. fixMin: extentInfo.fixMin,
  32889. fixMax: extentInfo.fixMax,
  32890. minInterval: (scaleType === 'interval' || scaleType === 'time')
  32891. ? model.get('minInterval') : null,
  32892. maxInterval: (scaleType === 'interval' || scaleType === 'time')
  32893. ? model.get('maxInterval') : null
  32894. });
  32895. // If some one specified the min, max. And the default calculated interval
  32896. // is not good enough. He can specify the interval. It is often appeared
  32897. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  32898. // to be 60.
  32899. // FIXME
  32900. var interval = model.get('interval');
  32901. if (interval != null) {
  32902. scale.setInterval && scale.setInterval(interval);
  32903. }
  32904. }
  32905. /**
  32906. * @param {module:echarts/model/Model} model
  32907. * @param {string} [axisType] Default retrieve from model.type
  32908. * @return {module:echarts/scale/*}
  32909. */
  32910. function createScaleByModel(model, axisType) {
  32911. axisType = axisType || model.get('type');
  32912. if (axisType) {
  32913. switch (axisType) {
  32914. // Buildin scale
  32915. case 'category':
  32916. return new OrdinalScale(
  32917. model.getOrdinalMeta
  32918. ? model.getOrdinalMeta()
  32919. : model.getCategories(),
  32920. [Infinity, -Infinity]
  32921. );
  32922. case 'value':
  32923. return new IntervalScale();
  32924. // Extended scale, like time and log
  32925. default:
  32926. return (Scale.getClass(axisType) || IntervalScale).create(model);
  32927. }
  32928. }
  32929. }
  32930. /**
  32931. * Check if the axis corss 0
  32932. */
  32933. function ifAxisCrossZero(axis) {
  32934. var dataExtent = axis.scale.getExtent();
  32935. var min = dataExtent[0];
  32936. var max = dataExtent[1];
  32937. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  32938. }
  32939. /**
  32940. * @param {module:echarts/coord/Axis} axis
  32941. * @return {Function} Label formatter function.
  32942. * param: {number} tickValue,
  32943. * param: {number} idx, the index in all ticks.
  32944. * If category axis, this param is not requied.
  32945. * return: {string} label string.
  32946. */
  32947. function makeLabelFormatter(axis) {
  32948. var labelFormatter = axis.getLabelModel().get('formatter');
  32949. var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
  32950. if (typeof labelFormatter === 'string') {
  32951. labelFormatter = (function (tpl) {
  32952. return function (val) {
  32953. // For category axis, get raw value; for numeric axis,
  32954. // get foramtted label like '1,333,444'.
  32955. val = axis.scale.getLabel(val);
  32956. return tpl.replace('{value}', val != null ? val : '');
  32957. };
  32958. })(labelFormatter);
  32959. // Consider empty array
  32960. return labelFormatter;
  32961. }
  32962. else if (typeof labelFormatter === 'function') {
  32963. return function (tickValue, idx) {
  32964. // The original intention of `idx` is "the index of the tick in all ticks".
  32965. // But the previous implementation of category axis do not consider the
  32966. // `axisLabel.interval`, which cause that, for example, the `interval` is
  32967. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  32968. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  32969. // the definition here for back compatibility.
  32970. if (categoryTickStart != null) {
  32971. idx = tickValue - categoryTickStart;
  32972. }
  32973. return labelFormatter(getAxisRawValue(axis, tickValue), idx);
  32974. };
  32975. }
  32976. else {
  32977. return function (tick) {
  32978. return axis.scale.getLabel(tick);
  32979. };
  32980. }
  32981. }
  32982. function getAxisRawValue(axis, value) {
  32983. // In category axis with data zoom, tick is not the original
  32984. // index of axis.data. So tick should not be exposed to user
  32985. // in category axis.
  32986. return axis.type === 'category' ? axis.scale.getLabel(value) : value;
  32987. }
  32988. /**
  32989. * @param {module:echarts/coord/Axis} axis
  32990. * @return {module:zrender/core/BoundingRect} Be null/undefined if no labels.
  32991. */
  32992. function estimateLabelUnionRect(axis) {
  32993. var axisModel = axis.model;
  32994. var scale = axis.scale;
  32995. if (!axisModel.get('axisLabel.show') || scale.isBlank()) {
  32996. return;
  32997. }
  32998. var isCategory = axis.type === 'category';
  32999. var realNumberScaleTicks;
  33000. var tickCount;
  33001. var categoryScaleExtent = scale.getExtent();
  33002. // Optimize for large category data, avoid call `getTicks()`.
  33003. if (isCategory) {
  33004. tickCount = scale.count();
  33005. }
  33006. else {
  33007. realNumberScaleTicks = scale.getTicks();
  33008. tickCount = realNumberScaleTicks.length;
  33009. }
  33010. var axisLabelModel = axis.getLabelModel();
  33011. var labelFormatter = makeLabelFormatter(axis);
  33012. var rect;
  33013. var step = 1;
  33014. // Simple optimization for large amount of labels
  33015. if (tickCount > 40) {
  33016. step = Math.ceil(tickCount / 40);
  33017. }
  33018. for (var i = 0; i < tickCount; i += step) {
  33019. var tickValue = realNumberScaleTicks ? realNumberScaleTicks[i] : categoryScaleExtent[0] + i;
  33020. var label = labelFormatter(tickValue);
  33021. var unrotatedSingleRect = axisLabelModel.getTextRect(label);
  33022. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  33023. rect ? rect.union(singleRect) : (rect = singleRect);
  33024. }
  33025. return rect;
  33026. }
  33027. function rotateTextRect(textRect, rotate) {
  33028. var rotateRadians = rotate * Math.PI / 180;
  33029. var boundingBox = textRect.plain();
  33030. var beforeWidth = boundingBox.width;
  33031. var beforeHeight = boundingBox.height;
  33032. var afterWidth = beforeWidth * Math.abs(Math.cos(rotateRadians)) + Math.abs(beforeHeight * Math.sin(rotateRadians));
  33033. var afterHeight = beforeWidth * Math.abs(Math.sin(rotateRadians)) + Math.abs(beforeHeight * Math.cos(rotateRadians));
  33034. var rotatedRect = new BoundingRect(boundingBox.x, boundingBox.y, afterWidth, afterHeight);
  33035. return rotatedRect;
  33036. }
  33037. /**
  33038. * @param {module:echarts/src/model/Model} model axisLabelModel or axisTickModel
  33039. * @return {number|String} Can be null|'auto'|number|function
  33040. */
  33041. function getOptionCategoryInterval(model) {
  33042. var interval = model.get('interval');
  33043. return interval == null ? 'auto' : interval;
  33044. }
  33045. /**
  33046. * Set `categoryInterval` as 0 implicitly indicates that
  33047. * show all labels reguardless of overlap.
  33048. * @param {Object} axis axisModel.axis
  33049. * @return {boolean}
  33050. */
  33051. function shouldShowAllLabels(axis) {
  33052. return axis.type === 'category'
  33053. && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  33054. }
  33055. /*
  33056. * Licensed to the Apache Software Foundation (ASF) under one
  33057. * or more contributor license agreements. See the NOTICE file
  33058. * distributed with this work for additional information
  33059. * regarding copyright ownership. The ASF licenses this file
  33060. * to you under the Apache License, Version 2.0 (the
  33061. * "License"); you may not use this file except in compliance
  33062. * with the License. You may obtain a copy of the License at
  33063. *
  33064. * http://www.apache.org/licenses/LICENSE-2.0
  33065. *
  33066. * Unless required by applicable law or agreed to in writing,
  33067. * software distributed under the License is distributed on an
  33068. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33069. * KIND, either express or implied. See the License for the
  33070. * specific language governing permissions and limitations
  33071. * under the License.
  33072. */
  33073. /**
  33074. * Cartesian coordinate system
  33075. * @module echarts/coord/Cartesian
  33076. *
  33077. */
  33078. function dimAxisMapper(dim) {
  33079. return this._axes[dim];
  33080. }
  33081. /**
  33082. * @alias module:echarts/coord/Cartesian
  33083. * @constructor
  33084. */
  33085. var Cartesian = function (name) {
  33086. this._axes = {};
  33087. this._dimList = [];
  33088. /**
  33089. * @type {string}
  33090. */
  33091. this.name = name || '';
  33092. };
  33093. Cartesian.prototype = {
  33094. constructor: Cartesian,
  33095. type: 'cartesian',
  33096. /**
  33097. * Get axis
  33098. * @param {number|string} dim
  33099. * @return {module:echarts/coord/Cartesian~Axis}
  33100. */
  33101. getAxis: function (dim) {
  33102. return this._axes[dim];
  33103. },
  33104. /**
  33105. * Get axes list
  33106. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  33107. */
  33108. getAxes: function () {
  33109. return map(this._dimList, dimAxisMapper, this);
  33110. },
  33111. /**
  33112. * Get axes list by given scale type
  33113. */
  33114. getAxesByScale: function (scaleType) {
  33115. scaleType = scaleType.toLowerCase();
  33116. return filter(
  33117. this.getAxes(),
  33118. function (axis) {
  33119. return axis.scale.type === scaleType;
  33120. }
  33121. );
  33122. },
  33123. /**
  33124. * Add axis
  33125. * @param {module:echarts/coord/Cartesian.Axis}
  33126. */
  33127. addAxis: function (axis) {
  33128. var dim = axis.dim;
  33129. this._axes[dim] = axis;
  33130. this._dimList.push(dim);
  33131. },
  33132. /**
  33133. * Convert data to coord in nd space
  33134. * @param {Array.<number>|Object.<string, number>} val
  33135. * @return {Array.<number>|Object.<string, number>}
  33136. */
  33137. dataToCoord: function (val) {
  33138. return this._dataCoordConvert(val, 'dataToCoord');
  33139. },
  33140. /**
  33141. * Convert coord in nd space to data
  33142. * @param {Array.<number>|Object.<string, number>} val
  33143. * @return {Array.<number>|Object.<string, number>}
  33144. */
  33145. coordToData: function (val) {
  33146. return this._dataCoordConvert(val, 'coordToData');
  33147. },
  33148. _dataCoordConvert: function (input, method) {
  33149. var dimList = this._dimList;
  33150. var output = input instanceof Array ? [] : {};
  33151. for (var i = 0; i < dimList.length; i++) {
  33152. var dim = dimList[i];
  33153. var axis = this._axes[dim];
  33154. output[dim] = axis[method](input[dim]);
  33155. }
  33156. return output;
  33157. }
  33158. };
  33159. /*
  33160. * Licensed to the Apache Software Foundation (ASF) under one
  33161. * or more contributor license agreements. See the NOTICE file
  33162. * distributed with this work for additional information
  33163. * regarding copyright ownership. The ASF licenses this file
  33164. * to you under the Apache License, Version 2.0 (the
  33165. * "License"); you may not use this file except in compliance
  33166. * with the License. You may obtain a copy of the License at
  33167. *
  33168. * http://www.apache.org/licenses/LICENSE-2.0
  33169. *
  33170. * Unless required by applicable law or agreed to in writing,
  33171. * software distributed under the License is distributed on an
  33172. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33173. * KIND, either express or implied. See the License for the
  33174. * specific language governing permissions and limitations
  33175. * under the License.
  33176. */
  33177. function Cartesian2D(name) {
  33178. Cartesian.call(this, name);
  33179. }
  33180. Cartesian2D.prototype = {
  33181. constructor: Cartesian2D,
  33182. type: 'cartesian2d',
  33183. /**
  33184. * @type {Array.<string>}
  33185. * @readOnly
  33186. */
  33187. dimensions: ['x', 'y'],
  33188. /**
  33189. * Base axis will be used on stacking.
  33190. *
  33191. * @return {module:echarts/coord/cartesian/Axis2D}
  33192. */
  33193. getBaseAxis: function () {
  33194. return this.getAxesByScale('ordinal')[0]
  33195. || this.getAxesByScale('time')[0]
  33196. || this.getAxis('x');
  33197. },
  33198. /**
  33199. * If contain point
  33200. * @param {Array.<number>} point
  33201. * @return {boolean}
  33202. */
  33203. containPoint: function (point) {
  33204. var axisX = this.getAxis('x');
  33205. var axisY = this.getAxis('y');
  33206. return axisX.contain(axisX.toLocalCoord(point[0]))
  33207. && axisY.contain(axisY.toLocalCoord(point[1]));
  33208. },
  33209. /**
  33210. * If contain data
  33211. * @param {Array.<number>} data
  33212. * @return {boolean}
  33213. */
  33214. containData: function (data) {
  33215. return this.getAxis('x').containData(data[0])
  33216. && this.getAxis('y').containData(data[1]);
  33217. },
  33218. /**
  33219. * @param {Array.<number>} data
  33220. * @param {Array.<number>} out
  33221. * @return {Array.<number>}
  33222. */
  33223. dataToPoint: function (data, reserved, out) {
  33224. var xAxis = this.getAxis('x');
  33225. var yAxis = this.getAxis('y');
  33226. out = out || [];
  33227. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(data[0]));
  33228. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(data[1]));
  33229. return out;
  33230. },
  33231. /**
  33232. * @param {Array.<number>} data
  33233. * @param {Array.<number>} out
  33234. * @return {Array.<number>}
  33235. */
  33236. clampData: function (data, out) {
  33237. var xScale = this.getAxis('x').scale;
  33238. var yScale = this.getAxis('y').scale;
  33239. var xAxisExtent = xScale.getExtent();
  33240. var yAxisExtent = yScale.getExtent();
  33241. var x = xScale.parse(data[0]);
  33242. var y = yScale.parse(data[1]);
  33243. out = out || [];
  33244. out[0] = Math.min(
  33245. Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x),
  33246. Math.max(xAxisExtent[0], xAxisExtent[1])
  33247. );
  33248. out[1] = Math.min(
  33249. Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y),
  33250. Math.max(yAxisExtent[0], yAxisExtent[1])
  33251. );
  33252. return out;
  33253. },
  33254. /**
  33255. * @param {Array.<number>} point
  33256. * @param {Array.<number>} out
  33257. * @return {Array.<number>}
  33258. */
  33259. pointToData: function (point, out) {
  33260. var xAxis = this.getAxis('x');
  33261. var yAxis = this.getAxis('y');
  33262. out = out || [];
  33263. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]));
  33264. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]));
  33265. return out;
  33266. },
  33267. /**
  33268. * Get other axis
  33269. * @param {module:echarts/coord/cartesian/Axis2D} axis
  33270. */
  33271. getOtherAxis: function (axis) {
  33272. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  33273. },
  33274. /**
  33275. * Get rect area of cartesian.
  33276. * Area will have a contain function to determine if a point is in the coordinate system.
  33277. * @return {BoundingRect}
  33278. */
  33279. getArea: function () {
  33280. var xExtent = this.getAxis('x').getGlobalExtent();
  33281. var yExtent = this.getAxis('y').getGlobalExtent();
  33282. var x = Math.min(xExtent[0], xExtent[1]);
  33283. var y = Math.min(yExtent[0], yExtent[1]);
  33284. var width = Math.max(xExtent[0], xExtent[1]) - x;
  33285. var height = Math.max(yExtent[0], yExtent[1]) - y;
  33286. var rect = new BoundingRect(x, y, width, height);
  33287. return rect;
  33288. }
  33289. };
  33290. inherits(Cartesian2D, Cartesian);
  33291. /*
  33292. * Licensed to the Apache Software Foundation (ASF) under one
  33293. * or more contributor license agreements. See the NOTICE file
  33294. * distributed with this work for additional information
  33295. * regarding copyright ownership. The ASF licenses this file
  33296. * to you under the Apache License, Version 2.0 (the
  33297. * "License"); you may not use this file except in compliance
  33298. * with the License. You may obtain a copy of the License at
  33299. *
  33300. * http://www.apache.org/licenses/LICENSE-2.0
  33301. *
  33302. * Unless required by applicable law or agreed to in writing,
  33303. * software distributed under the License is distributed on an
  33304. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33305. * KIND, either express or implied. See the License for the
  33306. * specific language governing permissions and limitations
  33307. * under the License.
  33308. */
  33309. var inner$6 = makeInner();
  33310. /**
  33311. * @param {module:echats/coord/Axis} axis
  33312. * @return {Object} {
  33313. * labels: [{
  33314. * formattedLabel: string,
  33315. * rawLabel: string,
  33316. * tickValue: number
  33317. * }, ...],
  33318. * labelCategoryInterval: number
  33319. * }
  33320. */
  33321. function createAxisLabels(axis) {
  33322. // Only ordinal scale support tick interval
  33323. return axis.type === 'category'
  33324. ? makeCategoryLabels(axis)
  33325. : makeRealNumberLabels(axis);
  33326. }
  33327. /**
  33328. * @param {module:echats/coord/Axis} axis
  33329. * @param {module:echarts/model/Model} tickModel For example, can be axisTick, splitLine, splitArea.
  33330. * @return {Object} {
  33331. * ticks: Array.<number>
  33332. * tickCategoryInterval: number
  33333. * }
  33334. */
  33335. function createAxisTicks(axis, tickModel) {
  33336. // Only ordinal scale support tick interval
  33337. return axis.type === 'category'
  33338. ? makeCategoryTicks(axis, tickModel)
  33339. : {ticks: axis.scale.getTicks()};
  33340. }
  33341. function makeCategoryLabels(axis) {
  33342. var labelModel = axis.getLabelModel();
  33343. var result = makeCategoryLabelsActually(axis, labelModel);
  33344. return (!labelModel.get('show') || axis.scale.isBlank())
  33345. ? {labels: [], labelCategoryInterval: result.labelCategoryInterval}
  33346. : result;
  33347. }
  33348. function makeCategoryLabelsActually(axis, labelModel) {
  33349. var labelsCache = getListCache(axis, 'labels');
  33350. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  33351. var result = listCacheGet(labelsCache, optionLabelInterval);
  33352. if (result) {
  33353. return result;
  33354. }
  33355. var labels;
  33356. var numericLabelInterval;
  33357. if (isFunction$1(optionLabelInterval)) {
  33358. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  33359. }
  33360. else {
  33361. numericLabelInterval = optionLabelInterval === 'auto'
  33362. ? makeAutoCategoryInterval(axis) : optionLabelInterval;
  33363. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  33364. }
  33365. // Cache to avoid calling interval function repeatly.
  33366. return listCacheSet(labelsCache, optionLabelInterval, {
  33367. labels: labels, labelCategoryInterval: numericLabelInterval
  33368. });
  33369. }
  33370. function makeCategoryTicks(axis, tickModel) {
  33371. var ticksCache = getListCache(axis, 'ticks');
  33372. var optionTickInterval = getOptionCategoryInterval(tickModel);
  33373. var result = listCacheGet(ticksCache, optionTickInterval);
  33374. if (result) {
  33375. return result;
  33376. }
  33377. var ticks;
  33378. var tickCategoryInterval;
  33379. // Optimize for the case that large category data and no label displayed,
  33380. // we should not return all ticks.
  33381. if (!tickModel.get('show') || axis.scale.isBlank()) {
  33382. ticks = [];
  33383. }
  33384. if (isFunction$1(optionTickInterval)) {
  33385. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  33386. }
  33387. // Always use label interval by default despite label show. Consider this
  33388. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  33389. // labels. `splitLine` and `axisTick` should be consistent in this case.
  33390. else if (optionTickInterval === 'auto') {
  33391. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel());
  33392. tickCategoryInterval = labelsResult.labelCategoryInterval;
  33393. ticks = map(labelsResult.labels, function (labelItem) {
  33394. return labelItem.tickValue;
  33395. });
  33396. }
  33397. else {
  33398. tickCategoryInterval = optionTickInterval;
  33399. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  33400. }
  33401. // Cache to avoid calling interval function repeatly.
  33402. return listCacheSet(ticksCache, optionTickInterval, {
  33403. ticks: ticks, tickCategoryInterval: tickCategoryInterval
  33404. });
  33405. }
  33406. function makeRealNumberLabels(axis) {
  33407. var ticks = axis.scale.getTicks();
  33408. var labelFormatter = makeLabelFormatter(axis);
  33409. return {
  33410. labels: map(ticks, function (tickValue, idx) {
  33411. return {
  33412. formattedLabel: labelFormatter(tickValue, idx),
  33413. rawLabel: axis.scale.getLabel(tickValue),
  33414. tickValue: tickValue
  33415. };
  33416. })
  33417. };
  33418. }
  33419. // Large category data calculation is performence sensitive, and ticks and label
  33420. // probably be fetched by multiple times. So we cache the result.
  33421. // axis is created each time during a ec process, so we do not need to clear cache.
  33422. function getListCache(axis, prop) {
  33423. // Because key can be funciton, and cache size always be small, we use array cache.
  33424. return inner$6(axis)[prop] || (inner$6(axis)[prop] = []);
  33425. }
  33426. function listCacheGet(cache, key) {
  33427. for (var i = 0; i < cache.length; i++) {
  33428. if (cache[i].key === key) {
  33429. return cache[i].value;
  33430. }
  33431. }
  33432. }
  33433. function listCacheSet(cache, key, value) {
  33434. cache.push({key: key, value: value});
  33435. return value;
  33436. }
  33437. function makeAutoCategoryInterval(axis) {
  33438. var result = inner$6(axis).autoInterval;
  33439. return result != null
  33440. ? result
  33441. : (inner$6(axis).autoInterval = axis.calculateCategoryInterval());
  33442. }
  33443. /**
  33444. * Calculate interval for category axis ticks and labels.
  33445. * To get precise result, at least one of `getRotate` and `isHorizontal`
  33446. * should be implemented in axis.
  33447. */
  33448. function calculateCategoryInterval(axis) {
  33449. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  33450. var labelFormatter = makeLabelFormatter(axis);
  33451. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  33452. var ordinalScale = axis.scale;
  33453. var ordinalExtent = ordinalScale.getExtent();
  33454. // Providing this method is for optimization:
  33455. // avoid generating a long array by `getTicks`
  33456. // in large category data case.
  33457. var tickCount = ordinalScale.count();
  33458. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  33459. return 0;
  33460. }
  33461. var step = 1;
  33462. // Simple optimization. Empirical value: tick count should less than 40.
  33463. if (tickCount > 40) {
  33464. step = Math.max(1, Math.floor(tickCount / 40));
  33465. }
  33466. var tickValue = ordinalExtent[0];
  33467. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  33468. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  33469. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  33470. var maxW = 0;
  33471. var maxH = 0;
  33472. // Caution: Performance sensitive for large category data.
  33473. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  33474. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  33475. var width = 0;
  33476. var height = 0;
  33477. // Not precise, do not consider align and vertical align
  33478. // and each distance from axis line yet.
  33479. var rect = getBoundingRect(
  33480. labelFormatter(tickValue), params.font, 'center', 'top'
  33481. );
  33482. // Magic number
  33483. width = rect.width * 1.3;
  33484. height = rect.height * 1.3;
  33485. // Min size, void long loop.
  33486. maxW = Math.max(maxW, width, 7);
  33487. maxH = Math.max(maxH, height, 7);
  33488. }
  33489. var dw = maxW / unitW;
  33490. var dh = maxH / unitH;
  33491. // 0/0 is NaN, 1/0 is Infinity.
  33492. isNaN(dw) && (dw = Infinity);
  33493. isNaN(dh) && (dh = Infinity);
  33494. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  33495. var cache = inner$6(axis.model);
  33496. var axisExtent = axis.getExtent();
  33497. var lastAutoInterval = cache.lastAutoInterval;
  33498. var lastTickCount = cache.lastTickCount;
  33499. // Use cache to keep interval stable while moving zoom window,
  33500. // otherwise the calculated interval might jitter when the zoom
  33501. // window size is close to the interval-changing size.
  33502. // For example, if all of the axis labels are `a, b, c, d, e, f, g`.
  33503. // The jitter will cause that sometimes the displayed labels are
  33504. // `a, d, g` (interval: 2) sometimes `a, c, e`(interval: 1).
  33505. if (lastAutoInterval != null
  33506. && lastTickCount != null
  33507. && Math.abs(lastAutoInterval - interval) <= 1
  33508. && Math.abs(lastTickCount - tickCount) <= 1
  33509. // Always choose the bigger one, otherwise the critical
  33510. // point is not the same when zooming in or zooming out.
  33511. && lastAutoInterval > interval
  33512. // If the axis change is caused by chart resize, the cache should not
  33513. // be used. Otherwise some hiden labels might not be shown again.
  33514. && cache.axisExtend0 === axisExtent[0]
  33515. && cache.axisExtend1 === axisExtent[1]
  33516. ) {
  33517. interval = lastAutoInterval;
  33518. }
  33519. // Only update cache if cache not used, otherwise the
  33520. // changing of interval is too insensitive.
  33521. else {
  33522. cache.lastTickCount = tickCount;
  33523. cache.lastAutoInterval = interval;
  33524. cache.axisExtend0 = axisExtent[0];
  33525. cache.axisExtend1 = axisExtent[1];
  33526. }
  33527. return interval;
  33528. }
  33529. function fetchAutoCategoryIntervalCalculationParams(axis) {
  33530. var labelModel = axis.getLabelModel();
  33531. return {
  33532. axisRotate: axis.getRotate
  33533. ? axis.getRotate()
  33534. : (axis.isHorizontal && !axis.isHorizontal())
  33535. ? 90
  33536. : 0,
  33537. labelRotate: labelModel.get('rotate') || 0,
  33538. font: labelModel.getFont()
  33539. };
  33540. }
  33541. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  33542. var labelFormatter = makeLabelFormatter(axis);
  33543. var ordinalScale = axis.scale;
  33544. var ordinalExtent = ordinalScale.getExtent();
  33545. var labelModel = axis.getLabelModel();
  33546. var result = [];
  33547. // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  33548. var step = Math.max((categoryInterval || 0) + 1, 1);
  33549. var startTick = ordinalExtent[0];
  33550. var tickCount = ordinalScale.count();
  33551. // Calculate start tick based on zero if possible to keep label consistent
  33552. // while zooming and moving while interval > 0. Otherwise the selection
  33553. // of displayable ticks and symbols probably keep changing.
  33554. // 3 is empirical value.
  33555. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  33556. startTick = Math.round(Math.ceil(startTick / step) * step);
  33557. }
  33558. // (1) Only add min max label here but leave overlap checking
  33559. // to render stage, which also ensure the returned list
  33560. // suitable for splitLine and splitArea rendering.
  33561. // (2) Scales except category always contain min max label so
  33562. // do not need to perform this process.
  33563. var showAllLabel = shouldShowAllLabels(axis);
  33564. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  33565. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  33566. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  33567. addItem(ordinalExtent[0]);
  33568. }
  33569. // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  33570. var tickValue = startTick;
  33571. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  33572. addItem(tickValue);
  33573. }
  33574. if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
  33575. addItem(ordinalExtent[1]);
  33576. }
  33577. function addItem(tVal) {
  33578. result.push(onlyTick
  33579. ? tVal
  33580. : {
  33581. formattedLabel: labelFormatter(tVal),
  33582. rawLabel: ordinalScale.getLabel(tVal),
  33583. tickValue: tVal
  33584. }
  33585. );
  33586. }
  33587. return result;
  33588. }
  33589. // When interval is function, the result `false` means ignore the tick.
  33590. // It is time consuming for large category data.
  33591. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  33592. var ordinalScale = axis.scale;
  33593. var labelFormatter = makeLabelFormatter(axis);
  33594. var result = [];
  33595. each$1(ordinalScale.getTicks(), function (tickValue) {
  33596. var rawLabel = ordinalScale.getLabel(tickValue);
  33597. if (categoryInterval(tickValue, rawLabel)) {
  33598. result.push(onlyTick
  33599. ? tickValue
  33600. : {
  33601. formattedLabel: labelFormatter(tickValue),
  33602. rawLabel: rawLabel,
  33603. tickValue: tickValue
  33604. }
  33605. );
  33606. }
  33607. });
  33608. return result;
  33609. }
  33610. /*
  33611. * Licensed to the Apache Software Foundation (ASF) under one
  33612. * or more contributor license agreements. See the NOTICE file
  33613. * distributed with this work for additional information
  33614. * regarding copyright ownership. The ASF licenses this file
  33615. * to you under the Apache License, Version 2.0 (the
  33616. * "License"); you may not use this file except in compliance
  33617. * with the License. You may obtain a copy of the License at
  33618. *
  33619. * http://www.apache.org/licenses/LICENSE-2.0
  33620. *
  33621. * Unless required by applicable law or agreed to in writing,
  33622. * software distributed under the License is distributed on an
  33623. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33624. * KIND, either express or implied. See the License for the
  33625. * specific language governing permissions and limitations
  33626. * under the License.
  33627. */
  33628. var NORMALIZED_EXTENT = [0, 1];
  33629. /**
  33630. * Base class of Axis.
  33631. * @constructor
  33632. */
  33633. var Axis = function (dim, scale, extent) {
  33634. /**
  33635. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'.
  33636. * @type {string}
  33637. */
  33638. this.dim = dim;
  33639. /**
  33640. * Axis scale
  33641. * @type {module:echarts/coord/scale/*}
  33642. */
  33643. this.scale = scale;
  33644. /**
  33645. * @type {Array.<number>}
  33646. * @private
  33647. */
  33648. this._extent = extent || [0, 0];
  33649. /**
  33650. * @type {boolean}
  33651. */
  33652. this.inverse = false;
  33653. /**
  33654. * Usually true when axis has a ordinal scale
  33655. * @type {boolean}
  33656. */
  33657. this.onBand = false;
  33658. };
  33659. Axis.prototype = {
  33660. constructor: Axis,
  33661. /**
  33662. * If axis extent contain given coord
  33663. * @param {number} coord
  33664. * @return {boolean}
  33665. */
  33666. contain: function (coord) {
  33667. var extent = this._extent;
  33668. var min = Math.min(extent[0], extent[1]);
  33669. var max = Math.max(extent[0], extent[1]);
  33670. return coord >= min && coord <= max;
  33671. },
  33672. /**
  33673. * If axis extent contain given data
  33674. * @param {number} data
  33675. * @return {boolean}
  33676. */
  33677. containData: function (data) {
  33678. return this.scale.contain(data);
  33679. },
  33680. /**
  33681. * Get coord extent.
  33682. * @return {Array.<number>}
  33683. */
  33684. getExtent: function () {
  33685. return this._extent.slice();
  33686. },
  33687. /**
  33688. * Get precision used for formatting
  33689. * @param {Array.<number>} [dataExtent]
  33690. * @return {number}
  33691. */
  33692. getPixelPrecision: function (dataExtent) {
  33693. return getPixelPrecision(
  33694. dataExtent || this.scale.getExtent(),
  33695. this._extent
  33696. );
  33697. },
  33698. /**
  33699. * Set coord extent
  33700. * @param {number} start
  33701. * @param {number} end
  33702. */
  33703. setExtent: function (start, end) {
  33704. var extent = this._extent;
  33705. extent[0] = start;
  33706. extent[1] = end;
  33707. },
  33708. /**
  33709. * Convert data to coord. Data is the rank if it has an ordinal scale
  33710. * @param {number} data
  33711. * @param {boolean} clamp
  33712. * @return {number}
  33713. */
  33714. dataToCoord: function (data, clamp) {
  33715. var extent = this._extent;
  33716. var scale = this.scale;
  33717. data = scale.normalize(data);
  33718. if (this.onBand && scale.type === 'ordinal') {
  33719. extent = extent.slice();
  33720. fixExtentWithBands(extent, scale.count());
  33721. }
  33722. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  33723. },
  33724. /**
  33725. * Convert coord to data. Data is the rank if it has an ordinal scale
  33726. * @param {number} coord
  33727. * @param {boolean} clamp
  33728. * @return {number}
  33729. */
  33730. coordToData: function (coord, clamp) {
  33731. var extent = this._extent;
  33732. var scale = this.scale;
  33733. if (this.onBand && scale.type === 'ordinal') {
  33734. extent = extent.slice();
  33735. fixExtentWithBands(extent, scale.count());
  33736. }
  33737. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  33738. return this.scale.scale(t);
  33739. },
  33740. /**
  33741. * Convert pixel point to data in axis
  33742. * @param {Array.<number>} point
  33743. * @param {boolean} clamp
  33744. * @return {number} data
  33745. */
  33746. pointToData: function (point, clamp) {
  33747. // Should be implemented in derived class if necessary.
  33748. },
  33749. /**
  33750. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  33751. * `axis.getTicksCoords` considers `onBand`, which is used by
  33752. * `boundaryGap:true` of category axis and splitLine and splitArea.
  33753. * @param {Object} [opt]
  33754. * @param {Model} [opt.tickModel=axis.model.getModel('axisTick')]
  33755. * @param {boolean} [opt.clamp] If `true`, the first and the last
  33756. * tick must be at the axis end points. Otherwise, clip ticks
  33757. * that outside the axis extent.
  33758. * @return {Array.<Object>} [{
  33759. * coord: ...,
  33760. * tickValue: ...
  33761. * }, ...]
  33762. */
  33763. getTicksCoords: function (opt) {
  33764. opt = opt || {};
  33765. var tickModel = opt.tickModel || this.getTickModel();
  33766. var result = createAxisTicks(this, tickModel);
  33767. var ticks = result.ticks;
  33768. var ticksCoords = map(ticks, function (tickValue) {
  33769. return {
  33770. coord: this.dataToCoord(tickValue),
  33771. tickValue: tickValue
  33772. };
  33773. }, this);
  33774. var alignWithLabel = tickModel.get('alignWithLabel');
  33775. fixOnBandTicksCoords(
  33776. this, ticksCoords, alignWithLabel, opt.clamp
  33777. );
  33778. return ticksCoords;
  33779. },
  33780. /**
  33781. * @return {Array.<Array.<Object>>} [{ coord: ..., tickValue: ...}]
  33782. */
  33783. getMinorTicksCoords: function () {
  33784. if (this.scale.type === 'ordinal') {
  33785. // Category axis doesn't support minor ticks
  33786. return [];
  33787. }
  33788. var minorTickModel = this.model.getModel('minorTick');
  33789. var splitNumber = minorTickModel.get('splitNumber');
  33790. // Protection.
  33791. if (!(splitNumber > 0 && splitNumber < 100)) {
  33792. splitNumber = 5;
  33793. }
  33794. var minorTicks = this.scale.getMinorTicks(splitNumber);
  33795. var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
  33796. return map(minorTicksGroup, function (minorTick) {
  33797. return {
  33798. coord: this.dataToCoord(minorTick),
  33799. tickValue: minorTick
  33800. };
  33801. }, this);
  33802. }, this);
  33803. return minorTicksCoords;
  33804. },
  33805. /**
  33806. * @return {Array.<Object>} [{
  33807. * formattedLabel: string,
  33808. * rawLabel: axis.scale.getLabel(tickValue)
  33809. * tickValue: number
  33810. * }, ...]
  33811. */
  33812. getViewLabels: function () {
  33813. return createAxisLabels(this).labels;
  33814. },
  33815. /**
  33816. * @return {module:echarts/coord/model/Model}
  33817. */
  33818. getLabelModel: function () {
  33819. return this.model.getModel('axisLabel');
  33820. },
  33821. /**
  33822. * Notice here we only get the default tick model. For splitLine
  33823. * or splitArea, we should pass the splitLineModel or splitAreaModel
  33824. * manually when calling `getTicksCoords`.
  33825. * In GL, this method may be overrided to:
  33826. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  33827. * @return {module:echarts/coord/model/Model}
  33828. */
  33829. getTickModel: function () {
  33830. return this.model.getModel('axisTick');
  33831. },
  33832. /**
  33833. * Get width of band
  33834. * @return {number}
  33835. */
  33836. getBandWidth: function () {
  33837. var axisExtent = this._extent;
  33838. var dataExtent = this.scale.getExtent();
  33839. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  33840. // Fix #2728, avoid NaN when only one data.
  33841. len === 0 && (len = 1);
  33842. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  33843. return Math.abs(size) / len;
  33844. },
  33845. /**
  33846. * @abstract
  33847. * @return {boolean} Is horizontal
  33848. */
  33849. isHorizontal: null,
  33850. /**
  33851. * @abstract
  33852. * @return {number} Get axis rotate, by degree.
  33853. */
  33854. getRotate: null,
  33855. /**
  33856. * Only be called in category axis.
  33857. * Can be overrided, consider other axes like in 3D.
  33858. * @return {number} Auto interval for cateogry axis tick and label
  33859. */
  33860. calculateCategoryInterval: function () {
  33861. return calculateCategoryInterval(this);
  33862. }
  33863. };
  33864. function fixExtentWithBands(extent, nTick) {
  33865. var size = extent[1] - extent[0];
  33866. var len = nTick;
  33867. var margin = size / len / 2;
  33868. extent[0] += margin;
  33869. extent[1] -= margin;
  33870. }
  33871. // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  33872. // |---1---|---2---|---3---|---4---|.
  33873. // So the displayed ticks and splitLine/splitArea should between
  33874. // each data item, otherwise cause misleading (e.g., split tow bars
  33875. // of a single data item when there are two bar series).
  33876. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  33877. // splitLine/spliteArea should layout appropriately corresponding
  33878. // to displayed labels. (So we should not use `getBandWidth` in this
  33879. // case).
  33880. function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) {
  33881. var ticksLen = ticksCoords.length;
  33882. if (!axis.onBand || alignWithLabel || !ticksLen) {
  33883. return;
  33884. }
  33885. var axisExtent = axis.getExtent();
  33886. var last;
  33887. var diffSize;
  33888. if (ticksLen === 1) {
  33889. ticksCoords[0].coord = axisExtent[0];
  33890. last = ticksCoords[1] = {coord: axisExtent[0]};
  33891. }
  33892. else {
  33893. var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
  33894. var shift = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen;
  33895. each$1(ticksCoords, function (ticksItem) {
  33896. ticksItem.coord -= shift / 2;
  33897. });
  33898. var dataExtent = axis.scale.getExtent();
  33899. diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
  33900. last = {coord: ticksCoords[ticksLen - 1].coord + shift * diffSize};
  33901. ticksCoords.push(last);
  33902. }
  33903. var inverse = axisExtent[0] > axisExtent[1];
  33904. // Handling clamp.
  33905. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  33906. clamp ? (ticksCoords[0].coord = axisExtent[0]) : ticksCoords.shift();
  33907. }
  33908. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  33909. ticksCoords.unshift({coord: axisExtent[0]});
  33910. }
  33911. if (littleThan(axisExtent[1], last.coord)) {
  33912. clamp ? (last.coord = axisExtent[1]) : ticksCoords.pop();
  33913. }
  33914. if (clamp && littleThan(last.coord, axisExtent[1])) {
  33915. ticksCoords.push({coord: axisExtent[1]});
  33916. }
  33917. function littleThan(a, b) {
  33918. // Avoid rounding error cause calculated tick coord different with extent.
  33919. // It may cause an extra unecessary tick added.
  33920. a = round$1(a);
  33921. b = round$1(b);
  33922. return inverse ? a > b : a < b;
  33923. }
  33924. }
  33925. /*
  33926. * Licensed to the Apache Software Foundation (ASF) under one
  33927. * or more contributor license agreements. See the NOTICE file
  33928. * distributed with this work for additional information
  33929. * regarding copyright ownership. The ASF licenses this file
  33930. * to you under the Apache License, Version 2.0 (the
  33931. * "License"); you may not use this file except in compliance
  33932. * with the License. You may obtain a copy of the License at
  33933. *
  33934. * http://www.apache.org/licenses/LICENSE-2.0
  33935. *
  33936. * Unless required by applicable law or agreed to in writing,
  33937. * software distributed under the License is distributed on an
  33938. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33939. * KIND, either express or implied. See the License for the
  33940. * specific language governing permissions and limitations
  33941. * under the License.
  33942. */
  33943. /**
  33944. * Extend axis 2d
  33945. * @constructor module:echarts/coord/cartesian/Axis2D
  33946. * @extends {module:echarts/coord/cartesian/Axis}
  33947. * @param {string} dim
  33948. * @param {*} scale
  33949. * @param {Array.<number>} coordExtent
  33950. * @param {string} axisType
  33951. * @param {string} position
  33952. */
  33953. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  33954. Axis.call(this, dim, scale, coordExtent);
  33955. /**
  33956. * Axis type
  33957. * - 'category'
  33958. * - 'value'
  33959. * - 'time'
  33960. * - 'log'
  33961. * @type {string}
  33962. */
  33963. this.type = axisType || 'value';
  33964. /**
  33965. * Axis position
  33966. * - 'top'
  33967. * - 'bottom'
  33968. * - 'left'
  33969. * - 'right'
  33970. */
  33971. this.position = position || 'bottom';
  33972. };
  33973. Axis2D.prototype = {
  33974. constructor: Axis2D,
  33975. /**
  33976. * Index of axis, can be used as key
  33977. */
  33978. index: 0,
  33979. /**
  33980. * Implemented in <module:echarts/coord/cartesian/Grid>.
  33981. * @return {Array.<module:echarts/coord/cartesian/Axis2D>}
  33982. * If not on zero of other axis, return null/undefined.
  33983. * If no axes, return an empty array.
  33984. */
  33985. getAxesOnZeroOf: null,
  33986. /**
  33987. * Axis model
  33988. * @param {module:echarts/coord/cartesian/AxisModel}
  33989. */
  33990. model: null,
  33991. isHorizontal: function () {
  33992. var position = this.position;
  33993. return position === 'top' || position === 'bottom';
  33994. },
  33995. /**
  33996. * Each item cooresponds to this.getExtent(), which
  33997. * means globalExtent[0] may greater than globalExtent[1],
  33998. * unless `asc` is input.
  33999. *
  34000. * @param {boolean} [asc]
  34001. * @return {Array.<number>}
  34002. */
  34003. getGlobalExtent: function (asc) {
  34004. var ret = this.getExtent();
  34005. ret[0] = this.toGlobalCoord(ret[0]);
  34006. ret[1] = this.toGlobalCoord(ret[1]);
  34007. asc && ret[0] > ret[1] && ret.reverse();
  34008. return ret;
  34009. },
  34010. getOtherAxis: function () {
  34011. this.grid.getOtherAxis();
  34012. },
  34013. /**
  34014. * @override
  34015. */
  34016. pointToData: function (point, clamp) {
  34017. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  34018. },
  34019. /**
  34020. * Transform global coord to local coord,
  34021. * i.e. var localCoord = axis.toLocalCoord(80);
  34022. * designate by module:echarts/coord/cartesian/Grid.
  34023. * @type {Function}
  34024. */
  34025. toLocalCoord: null,
  34026. /**
  34027. * Transform global coord to local coord,
  34028. * i.e. var globalCoord = axis.toLocalCoord(40);
  34029. * designate by module:echarts/coord/cartesian/Grid.
  34030. * @type {Function}
  34031. */
  34032. toGlobalCoord: null
  34033. };
  34034. inherits(Axis2D, Axis);
  34035. /*
  34036. * Licensed to the Apache Software Foundation (ASF) under one
  34037. * or more contributor license agreements. See the NOTICE file
  34038. * distributed with this work for additional information
  34039. * regarding copyright ownership. The ASF licenses this file
  34040. * to you under the Apache License, Version 2.0 (the
  34041. * "License"); you may not use this file except in compliance
  34042. * with the License. You may obtain a copy of the License at
  34043. *
  34044. * http://www.apache.org/licenses/LICENSE-2.0
  34045. *
  34046. * Unless required by applicable law or agreed to in writing,
  34047. * software distributed under the License is distributed on an
  34048. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34049. * KIND, either express or implied. See the License for the
  34050. * specific language governing permissions and limitations
  34051. * under the License.
  34052. */
  34053. var defaultOption = {
  34054. show: true,
  34055. zlevel: 0,
  34056. z: 0,
  34057. // Inverse the axis.
  34058. inverse: false,
  34059. // Axis name displayed.
  34060. name: '',
  34061. // 'start' | 'middle' | 'end'
  34062. nameLocation: 'end',
  34063. // By degree. By default auto rotate by nameLocation.
  34064. nameRotate: null,
  34065. nameTruncate: {
  34066. maxWidth: null,
  34067. ellipsis: '...',
  34068. placeholder: '.'
  34069. },
  34070. // Use global text style by default.
  34071. nameTextStyle: {},
  34072. // The gap between axisName and axisLine.
  34073. nameGap: 15,
  34074. // Default `false` to support tooltip.
  34075. silent: false,
  34076. // Default `false` to avoid legacy user event listener fail.
  34077. triggerEvent: false,
  34078. tooltip: {
  34079. show: false
  34080. },
  34081. axisPointer: {},
  34082. axisLine: {
  34083. show: true,
  34084. onZero: true,
  34085. onZeroAxisIndex: null,
  34086. lineStyle: {
  34087. color: '#333',
  34088. width: 1,
  34089. type: 'solid'
  34090. },
  34091. // The arrow at both ends the the axis.
  34092. symbol: ['none', 'none'],
  34093. symbolSize: [10, 15]
  34094. },
  34095. axisTick: {
  34096. show: true,
  34097. // Whether axisTick is inside the grid or outside the grid.
  34098. inside: false,
  34099. // The length of axisTick.
  34100. length: 5,
  34101. lineStyle: {
  34102. width: 1
  34103. }
  34104. },
  34105. axisLabel: {
  34106. show: true,
  34107. // Whether axisLabel is inside the grid or outside the grid.
  34108. inside: false,
  34109. rotate: 0,
  34110. // true | false | null/undefined (auto)
  34111. showMinLabel: null,
  34112. // true | false | null/undefined (auto)
  34113. showMaxLabel: null,
  34114. margin: 8,
  34115. // formatter: null,
  34116. fontSize: 12
  34117. },
  34118. splitLine: {
  34119. show: true,
  34120. lineStyle: {
  34121. color: ['#ccc'],
  34122. width: 1,
  34123. type: 'solid'
  34124. }
  34125. },
  34126. splitArea: {
  34127. show: false,
  34128. areaStyle: {
  34129. color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
  34130. }
  34131. }
  34132. };
  34133. var axisDefault = {};
  34134. axisDefault.categoryAxis = merge({
  34135. // The gap at both ends of the axis. For categoryAxis, boolean.
  34136. boundaryGap: true,
  34137. // Set false to faster category collection.
  34138. // Only usefull in the case like: category is
  34139. // ['2012-01-01', '2012-01-02', ...], where the input
  34140. // data has been ensured not duplicate and is large data.
  34141. // null means "auto":
  34142. // if axis.data provided, do not deduplication,
  34143. // else do deduplication.
  34144. deduplication: null,
  34145. // splitArea: {
  34146. // show: false
  34147. // },
  34148. splitLine: {
  34149. show: false
  34150. },
  34151. axisTick: {
  34152. // If tick is align with label when boundaryGap is true
  34153. alignWithLabel: false,
  34154. interval: 'auto'
  34155. },
  34156. axisLabel: {
  34157. interval: 'auto'
  34158. }
  34159. }, defaultOption);
  34160. axisDefault.valueAxis = merge({
  34161. // The gap at both ends of the axis. For value axis, [GAP, GAP], where
  34162. // `GAP` can be an absolute pixel number (like `35`), or percent (like `'30%'`)
  34163. boundaryGap: [0, 0],
  34164. // TODO
  34165. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  34166. // Min value of the axis. can be:
  34167. // + a number
  34168. // + 'dataMin': use the min value in data.
  34169. // + null/undefined: auto decide min value (consider pretty look and boundaryGap).
  34170. // min: null,
  34171. // Max value of the axis. can be:
  34172. // + a number
  34173. // + 'dataMax': use the max value in data.
  34174. // + null/undefined: auto decide max value (consider pretty look and boundaryGap).
  34175. // max: null,
  34176. // Readonly prop, specifies start value of the range when using data zoom.
  34177. // rangeStart: null
  34178. // Readonly prop, specifies end value of the range when using data zoom.
  34179. // rangeEnd: null
  34180. // Optional value can be:
  34181. // + `false`: always include value 0.
  34182. // + `true`: the extent do not consider value 0.
  34183. // scale: false,
  34184. // AxisTick and axisLabel and splitLine are caculated based on splitNumber.
  34185. splitNumber: 5,
  34186. // Interval specifies the span of the ticks is mandatorily.
  34187. // interval: null
  34188. // Specify min interval when auto calculate tick interval.
  34189. // minInterval: null
  34190. // Specify max interval when auto calculate tick interval.
  34191. // maxInterval: null
  34192. minorTick: {
  34193. // Minor tick, not available for cateogry axis.
  34194. show: false,
  34195. // Split number of minor ticks. The value should be in range of (0, 100)
  34196. splitNumber: 5,
  34197. // Lenght of minor tick
  34198. length: 3,
  34199. // Same inside with axisTick
  34200. // Line style
  34201. lineStyle: {
  34202. // Default to be same with axisTick
  34203. }
  34204. },
  34205. minorSplitLine: {
  34206. show: false,
  34207. lineStyle: {
  34208. color: '#eee',
  34209. width: 1
  34210. }
  34211. }
  34212. }, defaultOption);
  34213. axisDefault.timeAxis = defaults({
  34214. scale: true,
  34215. min: 'dataMin',
  34216. max: 'dataMax'
  34217. }, axisDefault.valueAxis);
  34218. axisDefault.logAxis = defaults({
  34219. scale: true,
  34220. logBase: 10
  34221. }, axisDefault.valueAxis);
  34222. /*
  34223. * Licensed to the Apache Software Foundation (ASF) under one
  34224. * or more contributor license agreements. See the NOTICE file
  34225. * distributed with this work for additional information
  34226. * regarding copyright ownership. The ASF licenses this file
  34227. * to you under the Apache License, Version 2.0 (the
  34228. * "License"); you may not use this file except in compliance
  34229. * with the License. You may obtain a copy of the License at
  34230. *
  34231. * http://www.apache.org/licenses/LICENSE-2.0
  34232. *
  34233. * Unless required by applicable law or agreed to in writing,
  34234. * software distributed under the License is distributed on an
  34235. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34236. * KIND, either express or implied. See the License for the
  34237. * specific language governing permissions and limitations
  34238. * under the License.
  34239. */
  34240. // FIXME axisType is fixed ?
  34241. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  34242. /**
  34243. * Generate sub axis model class
  34244. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  34245. * @param {module:echarts/model/Component} BaseAxisModelClass
  34246. * @param {Function} axisTypeDefaulter
  34247. * @param {Object} [extraDefaultOption]
  34248. */
  34249. var axisModelCreator = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  34250. each$1(AXIS_TYPES, function (axisType) {
  34251. BaseAxisModelClass.extend({
  34252. /**
  34253. * @readOnly
  34254. */
  34255. type: axisName + 'Axis.' + axisType,
  34256. mergeDefaultAndTheme: function (option, ecModel) {
  34257. var layoutMode = this.layoutMode;
  34258. var inputPositionParams = layoutMode
  34259. ? getLayoutParams(option) : {};
  34260. var themeModel = ecModel.getTheme();
  34261. merge(option, themeModel.get(axisType + 'Axis'));
  34262. merge(option, this.getDefaultOption());
  34263. option.type = axisTypeDefaulter(axisName, option);
  34264. if (layoutMode) {
  34265. mergeLayoutParam(option, inputPositionParams, layoutMode);
  34266. }
  34267. },
  34268. /**
  34269. * @override
  34270. */
  34271. optionUpdated: function () {
  34272. var thisOption = this.option;
  34273. if (thisOption.type === 'category') {
  34274. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  34275. }
  34276. },
  34277. /**
  34278. * Should not be called before all of 'getInitailData' finished.
  34279. * Because categories are collected during initializing data.
  34280. */
  34281. getCategories: function (rawData) {
  34282. var option = this.option;
  34283. // FIXME
  34284. // warning if called before all of 'getInitailData' finished.
  34285. if (option.type === 'category') {
  34286. if (rawData) {
  34287. return option.data;
  34288. }
  34289. return this.__ordinalMeta.categories;
  34290. }
  34291. },
  34292. getOrdinalMeta: function () {
  34293. return this.__ordinalMeta;
  34294. },
  34295. defaultOption: mergeAll(
  34296. [
  34297. {},
  34298. axisDefault[axisType + 'Axis'],
  34299. extraDefaultOption
  34300. ],
  34301. true
  34302. )
  34303. });
  34304. });
  34305. ComponentModel.registerSubTypeDefaulter(
  34306. axisName + 'Axis',
  34307. curry(axisTypeDefaulter, axisName)
  34308. );
  34309. };
  34310. /*
  34311. * Licensed to the Apache Software Foundation (ASF) under one
  34312. * or more contributor license agreements. See the NOTICE file
  34313. * distributed with this work for additional information
  34314. * regarding copyright ownership. The ASF licenses this file
  34315. * to you under the Apache License, Version 2.0 (the
  34316. * "License"); you may not use this file except in compliance
  34317. * with the License. You may obtain a copy of the License at
  34318. *
  34319. * http://www.apache.org/licenses/LICENSE-2.0
  34320. *
  34321. * Unless required by applicable law or agreed to in writing,
  34322. * software distributed under the License is distributed on an
  34323. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34324. * KIND, either express or implied. See the License for the
  34325. * specific language governing permissions and limitations
  34326. * under the License.
  34327. */
  34328. // import * as axisHelper from './axisHelper';
  34329. var axisModelCommonMixin = {
  34330. /**
  34331. * @param {boolean} origin
  34332. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  34333. */
  34334. getMin: function (origin) {
  34335. var option = this.option;
  34336. var min = (!origin && option.rangeStart != null)
  34337. ? option.rangeStart : option.min;
  34338. if (this.axis
  34339. && min != null
  34340. && min !== 'dataMin'
  34341. && typeof min !== 'function'
  34342. && !eqNaN(min)
  34343. ) {
  34344. min = this.axis.scale.parse(min);
  34345. }
  34346. return min;
  34347. },
  34348. /**
  34349. * @param {boolean} origin
  34350. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  34351. */
  34352. getMax: function (origin) {
  34353. var option = this.option;
  34354. var max = (!origin && option.rangeEnd != null)
  34355. ? option.rangeEnd : option.max;
  34356. if (this.axis
  34357. && max != null
  34358. && max !== 'dataMax'
  34359. && typeof max !== 'function'
  34360. && !eqNaN(max)
  34361. ) {
  34362. max = this.axis.scale.parse(max);
  34363. }
  34364. return max;
  34365. },
  34366. /**
  34367. * @return {boolean}
  34368. */
  34369. getNeedCrossZero: function () {
  34370. var option = this.option;
  34371. return (option.rangeStart != null || option.rangeEnd != null)
  34372. ? false : !option.scale;
  34373. },
  34374. /**
  34375. * Should be implemented by each axis model if necessary.
  34376. * @return {module:echarts/model/Component} coordinate system model
  34377. */
  34378. getCoordSysModel: noop,
  34379. /**
  34380. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  34381. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  34382. */
  34383. setRange: function (rangeStart, rangeEnd) {
  34384. this.option.rangeStart = rangeStart;
  34385. this.option.rangeEnd = rangeEnd;
  34386. },
  34387. /**
  34388. * Reset range
  34389. */
  34390. resetRange: function () {
  34391. // rangeStart and rangeEnd is readonly.
  34392. this.option.rangeStart = this.option.rangeEnd = null;
  34393. }
  34394. };
  34395. /*
  34396. * Licensed to the Apache Software Foundation (ASF) under one
  34397. * or more contributor license agreements. See the NOTICE file
  34398. * distributed with this work for additional information
  34399. * regarding copyright ownership. The ASF licenses this file
  34400. * to you under the Apache License, Version 2.0 (the
  34401. * "License"); you may not use this file except in compliance
  34402. * with the License. You may obtain a copy of the License at
  34403. *
  34404. * http://www.apache.org/licenses/LICENSE-2.0
  34405. *
  34406. * Unless required by applicable law or agreed to in writing,
  34407. * software distributed under the License is distributed on an
  34408. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34409. * KIND, either express or implied. See the License for the
  34410. * specific language governing permissions and limitations
  34411. * under the License.
  34412. */
  34413. var AxisModel = ComponentModel.extend({
  34414. type: 'cartesian2dAxis',
  34415. /**
  34416. * @type {module:echarts/coord/cartesian/Axis2D}
  34417. */
  34418. axis: null,
  34419. /**
  34420. * @override
  34421. */
  34422. init: function () {
  34423. AxisModel.superApply(this, 'init', arguments);
  34424. this.resetRange();
  34425. },
  34426. /**
  34427. * @override
  34428. */
  34429. mergeOption: function () {
  34430. AxisModel.superApply(this, 'mergeOption', arguments);
  34431. this.resetRange();
  34432. },
  34433. /**
  34434. * @override
  34435. */
  34436. restoreData: function () {
  34437. AxisModel.superApply(this, 'restoreData', arguments);
  34438. this.resetRange();
  34439. },
  34440. /**
  34441. * @override
  34442. * @return {module:echarts/model/Component}
  34443. */
  34444. getCoordSysModel: function () {
  34445. return this.ecModel.queryComponents({
  34446. mainType: 'grid',
  34447. index: this.option.gridIndex,
  34448. id: this.option.gridId
  34449. })[0];
  34450. }
  34451. });
  34452. function getAxisType(axisDim, option) {
  34453. // Default axis with data is category axis
  34454. return option.type || (option.data ? 'category' : 'value');
  34455. }
  34456. merge(AxisModel.prototype, axisModelCommonMixin);
  34457. var extraOption = {
  34458. // gridIndex: 0,
  34459. // gridId: '',
  34460. // Offset is for multiple axis on the same position
  34461. offset: 0
  34462. };
  34463. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  34464. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  34465. /*
  34466. * Licensed to the Apache Software Foundation (ASF) under one
  34467. * or more contributor license agreements. See the NOTICE file
  34468. * distributed with this work for additional information
  34469. * regarding copyright ownership. The ASF licenses this file
  34470. * to you under the Apache License, Version 2.0 (the
  34471. * "License"); you may not use this file except in compliance
  34472. * with the License. You may obtain a copy of the License at
  34473. *
  34474. * http://www.apache.org/licenses/LICENSE-2.0
  34475. *
  34476. * Unless required by applicable law or agreed to in writing,
  34477. * software distributed under the License is distributed on an
  34478. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34479. * KIND, either express or implied. See the License for the
  34480. * specific language governing permissions and limitations
  34481. * under the License.
  34482. */
  34483. // Grid 是在有直角坐标系的时候必须要存在的
  34484. // 所以这里也要被 Cartesian2D 依赖
  34485. ComponentModel.extend({
  34486. type: 'grid',
  34487. dependencies: ['xAxis', 'yAxis'],
  34488. layoutMode: 'box',
  34489. /**
  34490. * @type {module:echarts/coord/cartesian/Grid}
  34491. */
  34492. coordinateSystem: null,
  34493. defaultOption: {
  34494. show: false,
  34495. zlevel: 0,
  34496. z: 0,
  34497. left: '10%',
  34498. top: 60,
  34499. right: '10%',
  34500. bottom: 60,
  34501. // If grid size contain label
  34502. containLabel: false,
  34503. // width: {totalWidth} - left - right,
  34504. // height: {totalHeight} - top - bottom,
  34505. backgroundColor: 'rgba(0,0,0,0)',
  34506. borderWidth: 1,
  34507. borderColor: '#ccc'
  34508. }
  34509. });
  34510. /*
  34511. * Licensed to the Apache Software Foundation (ASF) under one
  34512. * or more contributor license agreements. See the NOTICE file
  34513. * distributed with this work for additional information
  34514. * regarding copyright ownership. The ASF licenses this file
  34515. * to you under the Apache License, Version 2.0 (the
  34516. * "License"); you may not use this file except in compliance
  34517. * with the License. You may obtain a copy of the License at
  34518. *
  34519. * http://www.apache.org/licenses/LICENSE-2.0
  34520. *
  34521. * Unless required by applicable law or agreed to in writing,
  34522. * software distributed under the License is distributed on an
  34523. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34524. * KIND, either express or implied. See the License for the
  34525. * specific language governing permissions and limitations
  34526. * under the License.
  34527. */
  34528. /**
  34529. * Grid is a region which contains at most 4 cartesian systems
  34530. *
  34531. * TODO Default cartesian
  34532. */
  34533. // Depends on GridModel, AxisModel, which performs preprocess.
  34534. /**
  34535. * Check if the axis is used in the specified grid
  34536. * @inner
  34537. */
  34538. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  34539. return axisModel.getCoordSysModel() === gridModel;
  34540. }
  34541. function Grid(gridModel, ecModel, api) {
  34542. /**
  34543. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  34544. * @private
  34545. */
  34546. this._coordsMap = {};
  34547. /**
  34548. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  34549. * @private
  34550. */
  34551. this._coordsList = [];
  34552. /**
  34553. * @type {Object.<string, Array.<module:echarts/coord/cartesian/Axis2D>>}
  34554. * @private
  34555. */
  34556. this._axesMap = {};
  34557. /**
  34558. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  34559. * @private
  34560. */
  34561. this._axesList = [];
  34562. this._initCartesian(gridModel, ecModel, api);
  34563. this.model = gridModel;
  34564. }
  34565. var gridProto = Grid.prototype;
  34566. gridProto.type = 'grid';
  34567. gridProto.axisPointerEnabled = true;
  34568. gridProto.getRect = function () {
  34569. return this._rect;
  34570. };
  34571. gridProto.update = function (ecModel, api) {
  34572. var axesMap = this._axesMap;
  34573. this._updateScale(ecModel, this.model);
  34574. each$1(axesMap.x, function (xAxis) {
  34575. niceScaleExtent(xAxis.scale, xAxis.model);
  34576. });
  34577. each$1(axesMap.y, function (yAxis) {
  34578. niceScaleExtent(yAxis.scale, yAxis.model);
  34579. });
  34580. // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  34581. var onZeroRecords = {};
  34582. each$1(axesMap.x, function (xAxis) {
  34583. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  34584. });
  34585. each$1(axesMap.y, function (yAxis) {
  34586. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  34587. });
  34588. // Resize again if containLabel is enabled
  34589. // FIXME It may cause getting wrong grid size in data processing stage
  34590. this.resize(this.model, api);
  34591. };
  34592. function fixAxisOnZero(axesMap, otherAxisDim, axis, onZeroRecords) {
  34593. axis.getAxesOnZeroOf = function () {
  34594. // TODO: onZero of multiple axes.
  34595. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  34596. };
  34597. // onZero can not be enabled in these two situations:
  34598. // 1. When any other axis is a category axis.
  34599. // 2. When no axis is cross 0 point.
  34600. var otherAxes = axesMap[otherAxisDim];
  34601. var otherAxisOnZeroOf;
  34602. var axisModel = axis.model;
  34603. var onZero = axisModel.get('axisLine.onZero');
  34604. var onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex');
  34605. if (!onZero) {
  34606. return;
  34607. }
  34608. // If target axis is specified.
  34609. if (onZeroAxisIndex != null) {
  34610. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  34611. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  34612. }
  34613. }
  34614. else {
  34615. // Find the first available other axis.
  34616. for (var idx in otherAxes) {
  34617. if (otherAxes.hasOwnProperty(idx)
  34618. && canOnZeroToAxis(otherAxes[idx])
  34619. // Consider that two Y axes on one value axis,
  34620. // if both onZero, the two Y axes overlap.
  34621. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]
  34622. ) {
  34623. otherAxisOnZeroOf = otherAxes[idx];
  34624. break;
  34625. }
  34626. }
  34627. }
  34628. if (otherAxisOnZeroOf) {
  34629. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  34630. }
  34631. function getOnZeroRecordKey(axis) {
  34632. return axis.dim + '_' + axis.index;
  34633. }
  34634. }
  34635. function canOnZeroToAxis(axis) {
  34636. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  34637. }
  34638. /**
  34639. * Resize the grid
  34640. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  34641. * @param {module:echarts/ExtensionAPI} api
  34642. */
  34643. gridProto.resize = function (gridModel, api, ignoreContainLabel) {
  34644. var gridRect = getLayoutRect(
  34645. gridModel.getBoxLayoutParams(), {
  34646. width: api.getWidth(),
  34647. height: api.getHeight()
  34648. });
  34649. this._rect = gridRect;
  34650. var axesList = this._axesList;
  34651. adjustAxes();
  34652. // Minus label size
  34653. if (!ignoreContainLabel && gridModel.get('containLabel')) {
  34654. each$1(axesList, function (axis) {
  34655. if (!axis.model.get('axisLabel.inside')) {
  34656. var labelUnionRect = estimateLabelUnionRect(axis);
  34657. if (labelUnionRect) {
  34658. var dim = axis.isHorizontal() ? 'height' : 'width';
  34659. var margin = axis.model.get('axisLabel.margin');
  34660. gridRect[dim] -= labelUnionRect[dim] + margin;
  34661. if (axis.position === 'top') {
  34662. gridRect.y += labelUnionRect.height + margin;
  34663. }
  34664. else if (axis.position === 'left') {
  34665. gridRect.x += labelUnionRect.width + margin;
  34666. }
  34667. }
  34668. }
  34669. });
  34670. adjustAxes();
  34671. }
  34672. function adjustAxes() {
  34673. each$1(axesList, function (axis) {
  34674. var isHorizontal = axis.isHorizontal();
  34675. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  34676. var idx = axis.inverse ? 1 : 0;
  34677. axis.setExtent(extent[idx], extent[1 - idx]);
  34678. updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
  34679. });
  34680. }
  34681. };
  34682. /**
  34683. * @param {string} axisType
  34684. * @param {number} [axisIndex]
  34685. */
  34686. gridProto.getAxis = function (axisType, axisIndex) {
  34687. var axesMapOnDim = this._axesMap[axisType];
  34688. if (axesMapOnDim != null) {
  34689. if (axisIndex == null) {
  34690. // Find first axis
  34691. for (var name in axesMapOnDim) {
  34692. if (axesMapOnDim.hasOwnProperty(name)) {
  34693. return axesMapOnDim[name];
  34694. }
  34695. }
  34696. }
  34697. return axesMapOnDim[axisIndex];
  34698. }
  34699. };
  34700. /**
  34701. * @return {Array.<module:echarts/coord/Axis>}
  34702. */
  34703. gridProto.getAxes = function () {
  34704. return this._axesList.slice();
  34705. };
  34706. /**
  34707. * Usage:
  34708. * grid.getCartesian(xAxisIndex, yAxisIndex);
  34709. * grid.getCartesian(xAxisIndex);
  34710. * grid.getCartesian(null, yAxisIndex);
  34711. * grid.getCartesian({xAxisIndex: ..., yAxisIndex: ...});
  34712. *
  34713. * @param {number|Object} [xAxisIndex]
  34714. * @param {number} [yAxisIndex]
  34715. */
  34716. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  34717. if (xAxisIndex != null && yAxisIndex != null) {
  34718. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  34719. return this._coordsMap[key];
  34720. }
  34721. if (isObject$1(xAxisIndex)) {
  34722. yAxisIndex = xAxisIndex.yAxisIndex;
  34723. xAxisIndex = xAxisIndex.xAxisIndex;
  34724. }
  34725. // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  34726. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  34727. if (coordList[i].getAxis('x').index === xAxisIndex
  34728. || coordList[i].getAxis('y').index === yAxisIndex
  34729. ) {
  34730. return coordList[i];
  34731. }
  34732. }
  34733. };
  34734. gridProto.getCartesians = function () {
  34735. return this._coordsList.slice();
  34736. };
  34737. /**
  34738. * @implements
  34739. * see {module:echarts/CoodinateSystem}
  34740. */
  34741. gridProto.convertToPixel = function (ecModel, finder, value) {
  34742. var target = this._findConvertTarget(ecModel, finder);
  34743. return target.cartesian
  34744. ? target.cartesian.dataToPoint(value)
  34745. : target.axis
  34746. ? target.axis.toGlobalCoord(target.axis.dataToCoord(value))
  34747. : null;
  34748. };
  34749. /**
  34750. * @implements
  34751. * see {module:echarts/CoodinateSystem}
  34752. */
  34753. gridProto.convertFromPixel = function (ecModel, finder, value) {
  34754. var target = this._findConvertTarget(ecModel, finder);
  34755. return target.cartesian
  34756. ? target.cartesian.pointToData(value)
  34757. : target.axis
  34758. ? target.axis.coordToData(target.axis.toLocalCoord(value))
  34759. : null;
  34760. };
  34761. /**
  34762. * @inner
  34763. */
  34764. gridProto._findConvertTarget = function (ecModel, finder) {
  34765. var seriesModel = finder.seriesModel;
  34766. var xAxisModel = finder.xAxisModel
  34767. || (seriesModel && seriesModel.getReferringComponents('xAxis')[0]);
  34768. var yAxisModel = finder.yAxisModel
  34769. || (seriesModel && seriesModel.getReferringComponents('yAxis')[0]);
  34770. var gridModel = finder.gridModel;
  34771. var coordsList = this._coordsList;
  34772. var cartesian;
  34773. var axis;
  34774. if (seriesModel) {
  34775. cartesian = seriesModel.coordinateSystem;
  34776. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  34777. }
  34778. else if (xAxisModel && yAxisModel) {
  34779. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  34780. }
  34781. else if (xAxisModel) {
  34782. axis = this.getAxis('x', xAxisModel.componentIndex);
  34783. }
  34784. else if (yAxisModel) {
  34785. axis = this.getAxis('y', yAxisModel.componentIndex);
  34786. }
  34787. // Lowest priority.
  34788. else if (gridModel) {
  34789. var grid = gridModel.coordinateSystem;
  34790. if (grid === this) {
  34791. cartesian = this._coordsList[0];
  34792. }
  34793. }
  34794. return {cartesian: cartesian, axis: axis};
  34795. };
  34796. /**
  34797. * @implements
  34798. * see {module:echarts/CoodinateSystem}
  34799. */
  34800. gridProto.containPoint = function (point) {
  34801. var coord = this._coordsList[0];
  34802. if (coord) {
  34803. return coord.containPoint(point);
  34804. }
  34805. };
  34806. /**
  34807. * Initialize cartesian coordinate systems
  34808. * @private
  34809. */
  34810. gridProto._initCartesian = function (gridModel, ecModel, api) {
  34811. var axisPositionUsed = {
  34812. left: false,
  34813. right: false,
  34814. top: false,
  34815. bottom: false
  34816. };
  34817. var axesMap = {
  34818. x: {},
  34819. y: {}
  34820. };
  34821. var axesCount = {
  34822. x: 0,
  34823. y: 0
  34824. };
  34825. /// Create axis
  34826. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  34827. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  34828. if (!axesCount.x || !axesCount.y) {
  34829. // Roll back when there no either x or y axis
  34830. this._axesMap = {};
  34831. this._axesList = [];
  34832. return;
  34833. }
  34834. this._axesMap = axesMap;
  34835. /// Create cartesian2d
  34836. each$1(axesMap.x, function (xAxis, xAxisIndex) {
  34837. each$1(axesMap.y, function (yAxis, yAxisIndex) {
  34838. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  34839. var cartesian = new Cartesian2D(key);
  34840. cartesian.grid = this;
  34841. cartesian.model = gridModel;
  34842. this._coordsMap[key] = cartesian;
  34843. this._coordsList.push(cartesian);
  34844. cartesian.addAxis(xAxis);
  34845. cartesian.addAxis(yAxis);
  34846. }, this);
  34847. }, this);
  34848. function createAxisCreator(axisType) {
  34849. return function (axisModel, idx) {
  34850. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  34851. return;
  34852. }
  34853. var axisPosition = axisModel.get('position');
  34854. if (axisType === 'x') {
  34855. // Fix position
  34856. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  34857. // Default bottom of X
  34858. axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
  34859. }
  34860. }
  34861. else {
  34862. // Fix position
  34863. if (axisPosition !== 'left' && axisPosition !== 'right') {
  34864. // Default left of Y
  34865. axisPosition = axisPositionUsed.left ? 'right' : 'left';
  34866. }
  34867. }
  34868. axisPositionUsed[axisPosition] = true;
  34869. var axis = new Axis2D(
  34870. axisType, createScaleByModel(axisModel),
  34871. [0, 0],
  34872. axisModel.get('type'),
  34873. axisPosition
  34874. );
  34875. var isCategory = axis.type === 'category';
  34876. axis.onBand = isCategory && axisModel.get('boundaryGap');
  34877. axis.inverse = axisModel.get('inverse');
  34878. // Inject axis into axisModel
  34879. axisModel.axis = axis;
  34880. // Inject axisModel into axis
  34881. axis.model = axisModel;
  34882. // Inject grid info axis
  34883. axis.grid = this;
  34884. // Index of axis, can be used as key
  34885. axis.index = idx;
  34886. this._axesList.push(axis);
  34887. axesMap[axisType][idx] = axis;
  34888. axesCount[axisType]++;
  34889. };
  34890. }
  34891. };
  34892. /**
  34893. * Update cartesian properties from series
  34894. * @param {module:echarts/model/Option} option
  34895. * @private
  34896. */
  34897. gridProto._updateScale = function (ecModel, gridModel) {
  34898. // Reset scale
  34899. each$1(this._axesList, function (axis) {
  34900. axis.scale.setExtent(Infinity, -Infinity);
  34901. });
  34902. ecModel.eachSeries(function (seriesModel) {
  34903. if (isCartesian2D(seriesModel)) {
  34904. var axesModels = findAxesModels(seriesModel, ecModel);
  34905. var xAxisModel = axesModels[0];
  34906. var yAxisModel = axesModels[1];
  34907. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  34908. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  34909. ) {
  34910. return;
  34911. }
  34912. var cartesian = this.getCartesian(
  34913. xAxisModel.componentIndex, yAxisModel.componentIndex
  34914. );
  34915. var data = seriesModel.getData();
  34916. var xAxis = cartesian.getAxis('x');
  34917. var yAxis = cartesian.getAxis('y');
  34918. if (data.type === 'list') {
  34919. unionExtent(data, xAxis, seriesModel);
  34920. unionExtent(data, yAxis, seriesModel);
  34921. }
  34922. }
  34923. }, this);
  34924. function unionExtent(data, axis, seriesModel) {
  34925. each$1(data.mapDimension(axis.dim, true), function (dim) {
  34926. axis.scale.unionExtentFromData(
  34927. // For example, the extent of the orginal dimension
  34928. // is [0.1, 0.5], the extent of the `stackResultDimension`
  34929. // is [7, 9], the final extent should not include [0.1, 0.5].
  34930. data, getStackedDimension(data, dim)
  34931. );
  34932. });
  34933. }
  34934. };
  34935. /**
  34936. * @param {string} [dim] 'x' or 'y' or 'auto' or null/undefined
  34937. * @return {Object} {baseAxes: [], otherAxes: []}
  34938. */
  34939. gridProto.getTooltipAxes = function (dim) {
  34940. var baseAxes = [];
  34941. var otherAxes = [];
  34942. each$1(this.getCartesians(), function (cartesian) {
  34943. var baseAxis = (dim != null && dim !== 'auto')
  34944. ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  34945. var otherAxis = cartesian.getOtherAxis(baseAxis);
  34946. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  34947. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  34948. });
  34949. return {baseAxes: baseAxes, otherAxes: otherAxes};
  34950. };
  34951. /**
  34952. * @inner
  34953. */
  34954. function updateAxisTransform(axis, coordBase) {
  34955. var axisExtent = axis.getExtent();
  34956. var axisExtentSum = axisExtent[0] + axisExtent[1];
  34957. // Fast transform
  34958. axis.toGlobalCoord = axis.dim === 'x'
  34959. ? function (coord) {
  34960. return coord + coordBase;
  34961. }
  34962. : function (coord) {
  34963. return axisExtentSum - coord + coordBase;
  34964. };
  34965. axis.toLocalCoord = axis.dim === 'x'
  34966. ? function (coord) {
  34967. return coord - coordBase;
  34968. }
  34969. : function (coord) {
  34970. return axisExtentSum - coord + coordBase;
  34971. };
  34972. }
  34973. var axesTypes = ['xAxis', 'yAxis'];
  34974. /**
  34975. * @inner
  34976. */
  34977. function findAxesModels(seriesModel, ecModel) {
  34978. return map(axesTypes, function (axisType) {
  34979. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  34980. if (__DEV__) {
  34981. if (!axisModel) {
  34982. throw new Error(axisType + ' "' + retrieve(
  34983. seriesModel.get(axisType + 'Index'),
  34984. seriesModel.get(axisType + 'Id'),
  34985. 0
  34986. ) + '" not found');
  34987. }
  34988. }
  34989. return axisModel;
  34990. });
  34991. }
  34992. /**
  34993. * @inner
  34994. */
  34995. function isCartesian2D(seriesModel) {
  34996. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  34997. }
  34998. Grid.create = function (ecModel, api) {
  34999. var grids = [];
  35000. ecModel.eachComponent('grid', function (gridModel, idx) {
  35001. var grid = new Grid(gridModel, ecModel, api);
  35002. grid.name = 'grid_' + idx;
  35003. // dataSampling requires axis extent, so resize
  35004. // should be performed in create stage.
  35005. grid.resize(gridModel, api, true);
  35006. gridModel.coordinateSystem = grid;
  35007. grids.push(grid);
  35008. });
  35009. // Inject the coordinateSystems into seriesModel
  35010. ecModel.eachSeries(function (seriesModel) {
  35011. if (!isCartesian2D(seriesModel)) {
  35012. return;
  35013. }
  35014. var axesModels = findAxesModels(seriesModel, ecModel);
  35015. var xAxisModel = axesModels[0];
  35016. var yAxisModel = axesModels[1];
  35017. var gridModel = xAxisModel.getCoordSysModel();
  35018. if (__DEV__) {
  35019. if (!gridModel) {
  35020. throw new Error(
  35021. 'Grid "' + retrieve(
  35022. xAxisModel.get('gridIndex'),
  35023. xAxisModel.get('gridId'),
  35024. 0
  35025. ) + '" not found'
  35026. );
  35027. }
  35028. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  35029. throw new Error('xAxis and yAxis must use the same grid');
  35030. }
  35031. }
  35032. var grid = gridModel.coordinateSystem;
  35033. seriesModel.coordinateSystem = grid.getCartesian(
  35034. xAxisModel.componentIndex, yAxisModel.componentIndex
  35035. );
  35036. });
  35037. return grids;
  35038. };
  35039. // For deciding which dimensions to use when creating list data
  35040. Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
  35041. CoordinateSystemManager.register('cartesian2d', Grid);
  35042. /*
  35043. * Licensed to the Apache Software Foundation (ASF) under one
  35044. * or more contributor license agreements. See the NOTICE file
  35045. * distributed with this work for additional information
  35046. * regarding copyright ownership. The ASF licenses this file
  35047. * to you under the Apache License, Version 2.0 (the
  35048. * "License"); you may not use this file except in compliance
  35049. * with the License. You may obtain a copy of the License at
  35050. *
  35051. * http://www.apache.org/licenses/LICENSE-2.0
  35052. *
  35053. * Unless required by applicable law or agreed to in writing,
  35054. * software distributed under the License is distributed on an
  35055. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35056. * KIND, either express or implied. See the License for the
  35057. * specific language governing permissions and limitations
  35058. * under the License.
  35059. */
  35060. var PI$2 = Math.PI;
  35061. /**
  35062. * A final axis is translated and rotated from a "standard axis".
  35063. * So opt.position and opt.rotation is required.
  35064. *
  35065. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  35066. * for example: (0, 0) ------------> (0, 50)
  35067. *
  35068. * nameDirection or tickDirection or labelDirection is 1 means tick
  35069. * or label is below the standard axis, whereas is -1 means above
  35070. * the standard axis. labelOffset means offset between label and axis,
  35071. * which is useful when 'onZero', where axisLabel is in the grid and
  35072. * label in outside grid.
  35073. *
  35074. * Tips: like always,
  35075. * positive rotation represents anticlockwise, and negative rotation
  35076. * represents clockwise.
  35077. * The direction of position coordinate is the same as the direction
  35078. * of screen coordinate.
  35079. *
  35080. * Do not need to consider axis 'inverse', which is auto processed by
  35081. * axis extent.
  35082. *
  35083. * @param {module:zrender/container/Group} group
  35084. * @param {Object} axisModel
  35085. * @param {Object} opt Standard axis parameters.
  35086. * @param {Array.<number>} opt.position [x, y]
  35087. * @param {number} opt.rotation by radian
  35088. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle' or 'center'.
  35089. * @param {number} [opt.tickDirection=1] 1 or -1
  35090. * @param {number} [opt.labelDirection=1] 1 or -1
  35091. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  35092. * @param {string} [opt.axisLabelShow] default get from axisModel.
  35093. * @param {string} [opt.axisName] default get from axisModel.
  35094. * @param {number} [opt.axisNameAvailableWidth]
  35095. * @param {number} [opt.labelRotate] by degree, default get from axisModel.
  35096. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  35097. * @param {number} [opt.nameTruncateMaxWidth]
  35098. */
  35099. var AxisBuilder = function (axisModel, opt) {
  35100. /**
  35101. * @readOnly
  35102. */
  35103. this.opt = opt;
  35104. /**
  35105. * @readOnly
  35106. */
  35107. this.axisModel = axisModel;
  35108. // Default value
  35109. defaults(
  35110. opt,
  35111. {
  35112. labelOffset: 0,
  35113. nameDirection: 1,
  35114. tickDirection: 1,
  35115. labelDirection: 1,
  35116. silent: true
  35117. }
  35118. );
  35119. /**
  35120. * @readOnly
  35121. */
  35122. this.group = new Group();
  35123. // FIXME Not use a seperate text group?
  35124. var dumbGroup = new Group({
  35125. position: opt.position.slice(),
  35126. rotation: opt.rotation
  35127. });
  35128. // this.group.add(dumbGroup);
  35129. // this._dumbGroup = dumbGroup;
  35130. dumbGroup.updateTransform();
  35131. this._transform = dumbGroup.transform;
  35132. this._dumbGroup = dumbGroup;
  35133. };
  35134. AxisBuilder.prototype = {
  35135. constructor: AxisBuilder,
  35136. hasBuilder: function (name) {
  35137. return !!builders[name];
  35138. },
  35139. add: function (name) {
  35140. builders[name].call(this);
  35141. },
  35142. getGroup: function () {
  35143. return this.group;
  35144. }
  35145. };
  35146. var builders = {
  35147. /**
  35148. * @private
  35149. */
  35150. axisLine: function () {
  35151. var opt = this.opt;
  35152. var axisModel = this.axisModel;
  35153. if (!axisModel.get('axisLine.show')) {
  35154. return;
  35155. }
  35156. var extent = this.axisModel.axis.getExtent();
  35157. var matrix = this._transform;
  35158. var pt1 = [extent[0], 0];
  35159. var pt2 = [extent[1], 0];
  35160. if (matrix) {
  35161. applyTransform(pt1, pt1, matrix);
  35162. applyTransform(pt2, pt2, matrix);
  35163. }
  35164. var lineStyle = extend(
  35165. {
  35166. lineCap: 'round'
  35167. },
  35168. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  35169. );
  35170. this.group.add(new Line({
  35171. // Id for animation
  35172. anid: 'line',
  35173. subPixelOptimize: true,
  35174. shape: {
  35175. x1: pt1[0],
  35176. y1: pt1[1],
  35177. x2: pt2[0],
  35178. y2: pt2[1]
  35179. },
  35180. style: lineStyle,
  35181. strokeContainThreshold: opt.strokeContainThreshold || 5,
  35182. silent: true,
  35183. z2: 1
  35184. }));
  35185. var arrows = axisModel.get('axisLine.symbol');
  35186. var arrowSize = axisModel.get('axisLine.symbolSize');
  35187. var arrowOffset = axisModel.get('axisLine.symbolOffset') || 0;
  35188. if (typeof arrowOffset === 'number') {
  35189. arrowOffset = [arrowOffset, arrowOffset];
  35190. }
  35191. if (arrows != null) {
  35192. if (typeof arrows === 'string') {
  35193. // Use the same arrow for start and end point
  35194. arrows = [arrows, arrows];
  35195. }
  35196. if (typeof arrowSize === 'string'
  35197. || typeof arrowSize === 'number'
  35198. ) {
  35199. // Use the same size for width and height
  35200. arrowSize = [arrowSize, arrowSize];
  35201. }
  35202. var symbolWidth = arrowSize[0];
  35203. var symbolHeight = arrowSize[1];
  35204. each$1([{
  35205. rotate: opt.rotation + Math.PI / 2,
  35206. offset: arrowOffset[0],
  35207. r: 0
  35208. }, {
  35209. rotate: opt.rotation - Math.PI / 2,
  35210. offset: arrowOffset[1],
  35211. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0])
  35212. + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  35213. }], function (point, index) {
  35214. if (arrows[index] !== 'none' && arrows[index] != null) {
  35215. var symbol = createSymbol(
  35216. arrows[index],
  35217. -symbolWidth / 2,
  35218. -symbolHeight / 2,
  35219. symbolWidth,
  35220. symbolHeight,
  35221. lineStyle.stroke,
  35222. true
  35223. );
  35224. // Calculate arrow position with offset
  35225. var r = point.r + point.offset;
  35226. var pos = [
  35227. pt1[0] + r * Math.cos(opt.rotation),
  35228. pt1[1] - r * Math.sin(opt.rotation)
  35229. ];
  35230. symbol.attr({
  35231. rotation: point.rotate,
  35232. position: pos,
  35233. silent: true,
  35234. z2: 11
  35235. });
  35236. this.group.add(symbol);
  35237. }
  35238. }, this);
  35239. }
  35240. },
  35241. /**
  35242. * @private
  35243. */
  35244. axisTickLabel: function () {
  35245. var axisModel = this.axisModel;
  35246. var opt = this.opt;
  35247. var ticksEls = buildAxisMajorTicks(this, axisModel, opt);
  35248. var labelEls = buildAxisLabel(this, axisModel, opt);
  35249. fixMinMaxLabelShow(axisModel, labelEls, ticksEls);
  35250. buildAxisMinorTicks(this, axisModel, opt);
  35251. },
  35252. /**
  35253. * @private
  35254. */
  35255. axisName: function () {
  35256. var opt = this.opt;
  35257. var axisModel = this.axisModel;
  35258. var name = retrieve(opt.axisName, axisModel.get('name'));
  35259. if (!name) {
  35260. return;
  35261. }
  35262. var nameLocation = axisModel.get('nameLocation');
  35263. var nameDirection = opt.nameDirection;
  35264. var textStyleModel = axisModel.getModel('nameTextStyle');
  35265. var gap = axisModel.get('nameGap') || 0;
  35266. var extent = this.axisModel.axis.getExtent();
  35267. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  35268. var pos = [
  35269. nameLocation === 'start'
  35270. ? extent[0] - gapSignal * gap
  35271. : nameLocation === 'end'
  35272. ? extent[1] + gapSignal * gap
  35273. : (extent[0] + extent[1]) / 2, // 'middle'
  35274. // Reuse labelOffset.
  35275. isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0
  35276. ];
  35277. var labelLayout;
  35278. var nameRotation = axisModel.get('nameRotate');
  35279. if (nameRotation != null) {
  35280. nameRotation = nameRotation * PI$2 / 180; // To radian.
  35281. }
  35282. var axisNameAvailableWidth;
  35283. if (isNameLocationCenter(nameLocation)) {
  35284. labelLayout = innerTextLayout(
  35285. opt.rotation,
  35286. nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  35287. nameDirection
  35288. );
  35289. }
  35290. else {
  35291. labelLayout = endTextLayout(
  35292. opt, nameLocation, nameRotation || 0, extent
  35293. );
  35294. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  35295. if (axisNameAvailableWidth != null) {
  35296. axisNameAvailableWidth = Math.abs(
  35297. axisNameAvailableWidth / Math.sin(labelLayout.rotation)
  35298. );
  35299. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  35300. }
  35301. }
  35302. var textFont = textStyleModel.getFont();
  35303. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  35304. var ellipsis = truncateOpt.ellipsis;
  35305. var maxWidth = retrieve(
  35306. opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth
  35307. );
  35308. // FIXME
  35309. // truncate rich text? (consider performance)
  35310. var truncatedText = (ellipsis != null && maxWidth != null)
  35311. ? truncateText$1(
  35312. name, maxWidth, textFont, ellipsis,
  35313. {minChar: 2, placeholder: truncateOpt.placeholder}
  35314. )
  35315. : name;
  35316. var tooltipOpt = axisModel.get('tooltip', true);
  35317. var mainType = axisModel.mainType;
  35318. var formatterParams = {
  35319. componentType: mainType,
  35320. name: name,
  35321. $vars: ['name']
  35322. };
  35323. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  35324. var textEl = new Text({
  35325. // Id for animation
  35326. anid: 'name',
  35327. __fullText: name,
  35328. __truncatedText: truncatedText,
  35329. position: pos,
  35330. rotation: labelLayout.rotation,
  35331. silent: isLabelSilent(axisModel),
  35332. z2: 1,
  35333. tooltip: (tooltipOpt && tooltipOpt.show)
  35334. ? extend({
  35335. content: name,
  35336. formatter: function () {
  35337. return name;
  35338. },
  35339. formatterParams: formatterParams
  35340. }, tooltipOpt)
  35341. : null
  35342. });
  35343. setTextStyle(textEl.style, textStyleModel, {
  35344. text: truncatedText,
  35345. textFont: textFont,
  35346. textFill: textStyleModel.getTextColor()
  35347. || axisModel.get('axisLine.lineStyle.color'),
  35348. textAlign: textStyleModel.get('align')
  35349. || labelLayout.textAlign,
  35350. textVerticalAlign: textStyleModel.get('verticalAlign')
  35351. || labelLayout.textVerticalAlign
  35352. });
  35353. if (axisModel.get('triggerEvent')) {
  35354. textEl.eventData = makeAxisEventDataBase(axisModel);
  35355. textEl.eventData.targetType = 'axisName';
  35356. textEl.eventData.name = name;
  35357. }
  35358. // FIXME
  35359. this._dumbGroup.add(textEl);
  35360. textEl.updateTransform();
  35361. this.group.add(textEl);
  35362. textEl.decomposeTransform();
  35363. }
  35364. };
  35365. var makeAxisEventDataBase = AxisBuilder.makeAxisEventDataBase = function (axisModel) {
  35366. var eventData = {
  35367. componentType: axisModel.mainType,
  35368. componentIndex: axisModel.componentIndex
  35369. };
  35370. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  35371. return eventData;
  35372. };
  35373. /**
  35374. * @public
  35375. * @static
  35376. * @param {Object} opt
  35377. * @param {number} axisRotation in radian
  35378. * @param {number} textRotation in radian
  35379. * @param {number} direction
  35380. * @return {Object} {
  35381. * rotation, // according to axis
  35382. * textAlign,
  35383. * textVerticalAlign
  35384. * }
  35385. */
  35386. var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  35387. var rotationDiff = remRadian(textRotation - axisRotation);
  35388. var textAlign;
  35389. var textVerticalAlign;
  35390. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  35391. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  35392. textAlign = 'center';
  35393. }
  35394. else if (isRadianAroundZero(rotationDiff - PI$2)) { // Label is inverse parallel with axis line.
  35395. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  35396. textAlign = 'center';
  35397. }
  35398. else {
  35399. textVerticalAlign = 'middle';
  35400. if (rotationDiff > 0 && rotationDiff < PI$2) {
  35401. textAlign = direction > 0 ? 'right' : 'left';
  35402. }
  35403. else {
  35404. textAlign = direction > 0 ? 'left' : 'right';
  35405. }
  35406. }
  35407. return {
  35408. rotation: rotationDiff,
  35409. textAlign: textAlign,
  35410. textVerticalAlign: textVerticalAlign
  35411. };
  35412. };
  35413. function endTextLayout(opt, textPosition, textRotate, extent) {
  35414. var rotationDiff = remRadian(textRotate - opt.rotation);
  35415. var textAlign;
  35416. var textVerticalAlign;
  35417. var inverse = extent[0] > extent[1];
  35418. var onLeft = (textPosition === 'start' && !inverse)
  35419. || (textPosition !== 'start' && inverse);
  35420. if (isRadianAroundZero(rotationDiff - PI$2 / 2)) {
  35421. textVerticalAlign = onLeft ? 'bottom' : 'top';
  35422. textAlign = 'center';
  35423. }
  35424. else if (isRadianAroundZero(rotationDiff - PI$2 * 1.5)) {
  35425. textVerticalAlign = onLeft ? 'top' : 'bottom';
  35426. textAlign = 'center';
  35427. }
  35428. else {
  35429. textVerticalAlign = 'middle';
  35430. if (rotationDiff < PI$2 * 1.5 && rotationDiff > PI$2 / 2) {
  35431. textAlign = onLeft ? 'left' : 'right';
  35432. }
  35433. else {
  35434. textAlign = onLeft ? 'right' : 'left';
  35435. }
  35436. }
  35437. return {
  35438. rotation: rotationDiff,
  35439. textAlign: textAlign,
  35440. textVerticalAlign: textVerticalAlign
  35441. };
  35442. }
  35443. var isLabelSilent = AxisBuilder.isLabelSilent = function (axisModel) {
  35444. var tooltipOpt = axisModel.get('tooltip');
  35445. return axisModel.get('silent')
  35446. // Consider mouse cursor, add these restrictions.
  35447. || !(
  35448. axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
  35449. );
  35450. };
  35451. function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
  35452. if (shouldShowAllLabels(axisModel.axis)) {
  35453. return;
  35454. }
  35455. // If min or max are user set, we need to check
  35456. // If the tick on min(max) are overlap on their neighbour tick
  35457. // If they are overlapped, we need to hide the min(max) tick label
  35458. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  35459. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  35460. // FIXME
  35461. // Have not consider onBand yet, where tick els is more than label els.
  35462. labelEls = labelEls || [];
  35463. tickEls = tickEls || [];
  35464. var firstLabel = labelEls[0];
  35465. var nextLabel = labelEls[1];
  35466. var lastLabel = labelEls[labelEls.length - 1];
  35467. var prevLabel = labelEls[labelEls.length - 2];
  35468. var firstTick = tickEls[0];
  35469. var nextTick = tickEls[1];
  35470. var lastTick = tickEls[tickEls.length - 1];
  35471. var prevTick = tickEls[tickEls.length - 2];
  35472. if (showMinLabel === false) {
  35473. ignoreEl(firstLabel);
  35474. ignoreEl(firstTick);
  35475. }
  35476. else if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  35477. if (showMinLabel) {
  35478. ignoreEl(nextLabel);
  35479. ignoreEl(nextTick);
  35480. }
  35481. else {
  35482. ignoreEl(firstLabel);
  35483. ignoreEl(firstTick);
  35484. }
  35485. }
  35486. if (showMaxLabel === false) {
  35487. ignoreEl(lastLabel);
  35488. ignoreEl(lastTick);
  35489. }
  35490. else if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  35491. if (showMaxLabel) {
  35492. ignoreEl(prevLabel);
  35493. ignoreEl(prevTick);
  35494. }
  35495. else {
  35496. ignoreEl(lastLabel);
  35497. ignoreEl(lastTick);
  35498. }
  35499. }
  35500. }
  35501. function ignoreEl(el) {
  35502. el && (el.ignore = true);
  35503. }
  35504. function isTwoLabelOverlapped(current, next, labelLayout) {
  35505. // current and next has the same rotation.
  35506. var firstRect = current && current.getBoundingRect().clone();
  35507. var nextRect = next && next.getBoundingRect().clone();
  35508. if (!firstRect || !nextRect) {
  35509. return;
  35510. }
  35511. // When checking intersect of two rotated labels, we use mRotationBack
  35512. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  35513. var mRotationBack = identity([]);
  35514. rotate(mRotationBack, mRotationBack, -current.rotation);
  35515. firstRect.applyTransform(mul$1([], mRotationBack, current.getLocalTransform()));
  35516. nextRect.applyTransform(mul$1([], mRotationBack, next.getLocalTransform()));
  35517. return firstRect.intersect(nextRect);
  35518. }
  35519. function isNameLocationCenter(nameLocation) {
  35520. return nameLocation === 'middle' || nameLocation === 'center';
  35521. }
  35522. function createTicks(ticksCoords, tickTransform, tickEndCoord, tickLineStyle, aniid) {
  35523. var tickEls = [];
  35524. var pt1 = [];
  35525. var pt2 = [];
  35526. for (var i = 0; i < ticksCoords.length; i++) {
  35527. var tickCoord = ticksCoords[i].coord;
  35528. pt1[0] = tickCoord;
  35529. pt1[1] = 0;
  35530. pt2[0] = tickCoord;
  35531. pt2[1] = tickEndCoord;
  35532. if (tickTransform) {
  35533. applyTransform(pt1, pt1, tickTransform);
  35534. applyTransform(pt2, pt2, tickTransform);
  35535. }
  35536. // Tick line, Not use group transform to have better line draw
  35537. var tickEl = new Line({
  35538. // Id for animation
  35539. anid: aniid + '_' + ticksCoords[i].tickValue,
  35540. subPixelOptimize: true,
  35541. shape: {
  35542. x1: pt1[0],
  35543. y1: pt1[1],
  35544. x2: pt2[0],
  35545. y2: pt2[1]
  35546. },
  35547. style: tickLineStyle,
  35548. z2: 2,
  35549. silent: true
  35550. });
  35551. tickEls.push(tickEl);
  35552. }
  35553. return tickEls;
  35554. }
  35555. function buildAxisMajorTicks(axisBuilder, axisModel, opt) {
  35556. var axis = axisModel.axis;
  35557. var tickModel = axisModel.getModel('axisTick');
  35558. if (!tickModel.get('show') || axis.scale.isBlank()) {
  35559. return;
  35560. }
  35561. var lineStyleModel = tickModel.getModel('lineStyle');
  35562. var tickEndCoord = opt.tickDirection * tickModel.get('length');
  35563. var ticksCoords = axis.getTicksCoords();
  35564. var ticksEls = createTicks(ticksCoords, axisBuilder._transform, tickEndCoord, defaults(
  35565. lineStyleModel.getLineStyle(),
  35566. {
  35567. stroke: axisModel.get('axisLine.lineStyle.color')
  35568. }
  35569. ), 'ticks');
  35570. for (var i = 0; i < ticksEls.length; i++) {
  35571. axisBuilder.group.add(ticksEls[i]);
  35572. }
  35573. return ticksEls;
  35574. }
  35575. function buildAxisMinorTicks(axisBuilder, axisModel, opt) {
  35576. var axis = axisModel.axis;
  35577. var minorTickModel = axisModel.getModel('minorTick');
  35578. if (!minorTickModel.get('show') || axis.scale.isBlank()) {
  35579. return;
  35580. }
  35581. var minorTicksCoords = axis.getMinorTicksCoords();
  35582. if (!minorTicksCoords.length) {
  35583. return;
  35584. }
  35585. var lineStyleModel = minorTickModel.getModel('lineStyle');
  35586. var tickEndCoord = opt.tickDirection * minorTickModel.get('length');
  35587. var minorTickLineStyle = defaults(
  35588. lineStyleModel.getLineStyle(),
  35589. defaults(
  35590. axisModel.getModel('axisTick').getLineStyle(),
  35591. {
  35592. stroke: axisModel.get('axisLine.lineStyle.color')
  35593. }
  35594. )
  35595. );
  35596. for (var i = 0; i < minorTicksCoords.length; i++) {
  35597. var minorTicksEls = createTicks(
  35598. minorTicksCoords[i], axisBuilder._transform, tickEndCoord, minorTickLineStyle, 'minorticks_' + i
  35599. );
  35600. for (var k = 0; k < minorTicksEls.length; k++) {
  35601. axisBuilder.group.add(minorTicksEls[k]);
  35602. }
  35603. }
  35604. }
  35605. function buildAxisLabel(axisBuilder, axisModel, opt) {
  35606. var axis = axisModel.axis;
  35607. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  35608. if (!show || axis.scale.isBlank()) {
  35609. return;
  35610. }
  35611. var labelModel = axisModel.getModel('axisLabel');
  35612. var labelMargin = labelModel.get('margin');
  35613. var labels = axis.getViewLabels();
  35614. // Special label rotate.
  35615. var labelRotation = (
  35616. retrieve(opt.labelRotate, labelModel.get('rotate')) || 0
  35617. ) * PI$2 / 180;
  35618. var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  35619. var rawCategoryData = axisModel.getCategories && axisModel.getCategories(true);
  35620. var labelEls = [];
  35621. var silent = isLabelSilent(axisModel);
  35622. var triggerEvent = axisModel.get('triggerEvent');
  35623. each$1(labels, function (labelItem, index) {
  35624. var tickValue = labelItem.tickValue;
  35625. var formattedLabel = labelItem.formattedLabel;
  35626. var rawLabel = labelItem.rawLabel;
  35627. var itemLabelModel = labelModel;
  35628. if (rawCategoryData && rawCategoryData[tickValue] && rawCategoryData[tickValue].textStyle) {
  35629. itemLabelModel = new Model(
  35630. rawCategoryData[tickValue].textStyle, labelModel, axisModel.ecModel
  35631. );
  35632. }
  35633. var textColor = itemLabelModel.getTextColor()
  35634. || axisModel.get('axisLine.lineStyle.color');
  35635. var tickCoord = axis.dataToCoord(tickValue);
  35636. var pos = [
  35637. tickCoord,
  35638. opt.labelOffset + opt.labelDirection * labelMargin
  35639. ];
  35640. var textEl = new Text({
  35641. // Id for animation
  35642. anid: 'label_' + tickValue,
  35643. position: pos,
  35644. rotation: labelLayout.rotation,
  35645. silent: silent,
  35646. z2: 10
  35647. });
  35648. setTextStyle(textEl.style, itemLabelModel, {
  35649. text: formattedLabel,
  35650. textAlign: itemLabelModel.getShallow('align', true)
  35651. || labelLayout.textAlign,
  35652. textVerticalAlign: itemLabelModel.getShallow('verticalAlign', true)
  35653. || itemLabelModel.getShallow('baseline', true)
  35654. || labelLayout.textVerticalAlign,
  35655. textFill: typeof textColor === 'function'
  35656. ? textColor(
  35657. // (1) In category axis with data zoom, tick is not the original
  35658. // index of axis.data. So tick should not be exposed to user
  35659. // in category axis.
  35660. // (2) Compatible with previous version, which always use formatted label as
  35661. // input. But in interval scale the formatted label is like '223,445', which
  35662. // maked user repalce ','. So we modify it to return original val but remain
  35663. // it as 'string' to avoid error in replacing.
  35664. axis.type === 'category'
  35665. ? rawLabel
  35666. : axis.type === 'value'
  35667. ? tickValue + ''
  35668. : tickValue,
  35669. index
  35670. )
  35671. : textColor
  35672. });
  35673. // Pack data for mouse event
  35674. if (triggerEvent) {
  35675. textEl.eventData = makeAxisEventDataBase(axisModel);
  35676. textEl.eventData.targetType = 'axisLabel';
  35677. textEl.eventData.value = rawLabel;
  35678. }
  35679. // FIXME
  35680. axisBuilder._dumbGroup.add(textEl);
  35681. textEl.updateTransform();
  35682. labelEls.push(textEl);
  35683. axisBuilder.group.add(textEl);
  35684. textEl.decomposeTransform();
  35685. });
  35686. return labelEls;
  35687. }
  35688. /*
  35689. * Licensed to the Apache Software Foundation (ASF) under one
  35690. * or more contributor license agreements. See the NOTICE file
  35691. * distributed with this work for additional information
  35692. * regarding copyright ownership. The ASF licenses this file
  35693. * to you under the Apache License, Version 2.0 (the
  35694. * "License"); you may not use this file except in compliance
  35695. * with the License. You may obtain a copy of the License at
  35696. *
  35697. * http://www.apache.org/licenses/LICENSE-2.0
  35698. *
  35699. * Unless required by applicable law or agreed to in writing,
  35700. * software distributed under the License is distributed on an
  35701. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35702. * KIND, either express or implied. See the License for the
  35703. * specific language governing permissions and limitations
  35704. * under the License.
  35705. */
  35706. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  35707. // allAxesInfo should be updated when setOption performed.
  35708. function fixValue(axisModel) {
  35709. var axisInfo = getAxisInfo(axisModel);
  35710. if (!axisInfo) {
  35711. return;
  35712. }
  35713. var axisPointerModel = axisInfo.axisPointerModel;
  35714. var scale = axisInfo.axis.scale;
  35715. var option = axisPointerModel.option;
  35716. var status = axisPointerModel.get('status');
  35717. var value = axisPointerModel.get('value');
  35718. // Parse init value for category and time axis.
  35719. if (value != null) {
  35720. value = scale.parse(value);
  35721. }
  35722. var useHandle = isHandleTrigger(axisPointerModel);
  35723. // If `handle` used, `axisPointer` will always be displayed, so value
  35724. // and status should be initialized.
  35725. if (status == null) {
  35726. option.status = useHandle ? 'show' : 'hide';
  35727. }
  35728. var extent = scale.getExtent().slice();
  35729. extent[0] > extent[1] && extent.reverse();
  35730. if (// Pick a value on axis when initializing.
  35731. value == null
  35732. // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  35733. // where we should re-pick a value to keep `handle` displaying normally.
  35734. || value > extent[1]
  35735. ) {
  35736. // Make handle displayed on the end of the axis when init, which looks better.
  35737. value = extent[1];
  35738. }
  35739. if (value < extent[0]) {
  35740. value = extent[0];
  35741. }
  35742. option.value = value;
  35743. if (useHandle) {
  35744. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  35745. }
  35746. }
  35747. function getAxisInfo(axisModel) {
  35748. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  35749. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  35750. }
  35751. function getAxisPointerModel(axisModel) {
  35752. var axisInfo = getAxisInfo(axisModel);
  35753. return axisInfo && axisInfo.axisPointerModel;
  35754. }
  35755. function isHandleTrigger(axisPointerModel) {
  35756. return !!axisPointerModel.get('handle.show');
  35757. }
  35758. /**
  35759. * @param {module:echarts/model/Model} model
  35760. * @return {string} unique key
  35761. */
  35762. function makeKey(model) {
  35763. return model.type + '||' + model.id;
  35764. }
  35765. /*
  35766. * Licensed to the Apache Software Foundation (ASF) under one
  35767. * or more contributor license agreements. See the NOTICE file
  35768. * distributed with this work for additional information
  35769. * regarding copyright ownership. The ASF licenses this file
  35770. * to you under the Apache License, Version 2.0 (the
  35771. * "License"); you may not use this file except in compliance
  35772. * with the License. You may obtain a copy of the License at
  35773. *
  35774. * http://www.apache.org/licenses/LICENSE-2.0
  35775. *
  35776. * Unless required by applicable law or agreed to in writing,
  35777. * software distributed under the License is distributed on an
  35778. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35779. * KIND, either express or implied. See the License for the
  35780. * specific language governing permissions and limitations
  35781. * under the License.
  35782. */
  35783. /**
  35784. * Base class of AxisView.
  35785. */
  35786. var AxisView = extendComponentView({
  35787. type: 'axis',
  35788. /**
  35789. * @private
  35790. */
  35791. _axisPointer: null,
  35792. /**
  35793. * @protected
  35794. * @type {string}
  35795. */
  35796. axisPointerClass: null,
  35797. /**
  35798. * @override
  35799. */
  35800. render: function (axisModel, ecModel, api, payload) {
  35801. // FIXME
  35802. // This process should proformed after coordinate systems updated
  35803. // (axis scale updated), and should be performed each time update.
  35804. // So put it here temporarily, although it is not appropriate to
  35805. // put a model-writing procedure in `view`.
  35806. this.axisPointerClass && fixValue(axisModel);
  35807. AxisView.superApply(this, 'render', arguments);
  35808. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  35809. },
  35810. /**
  35811. * Action handler.
  35812. * @public
  35813. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  35814. * @param {module:echarts/model/Global} ecModel
  35815. * @param {module:echarts/ExtensionAPI} api
  35816. * @param {Object} payload
  35817. */
  35818. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  35819. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  35820. },
  35821. /**
  35822. * @override
  35823. */
  35824. remove: function (ecModel, api) {
  35825. var axisPointer = this._axisPointer;
  35826. axisPointer && axisPointer.remove(api);
  35827. AxisView.superApply(this, 'remove', arguments);
  35828. },
  35829. /**
  35830. * @override
  35831. */
  35832. dispose: function (ecModel, api) {
  35833. disposeAxisPointer(this, api);
  35834. AxisView.superApply(this, 'dispose', arguments);
  35835. }
  35836. });
  35837. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  35838. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  35839. if (!Clazz) {
  35840. return;
  35841. }
  35842. var axisPointerModel = getAxisPointerModel(axisModel);
  35843. axisPointerModel
  35844. ? (axisView._axisPointer || (axisView._axisPointer = new Clazz()))
  35845. .render(axisModel, axisPointerModel, api, forceRender)
  35846. : disposeAxisPointer(axisView, api);
  35847. }
  35848. function disposeAxisPointer(axisView, ecModel, api) {
  35849. var axisPointer = axisView._axisPointer;
  35850. axisPointer && axisPointer.dispose(ecModel, api);
  35851. axisView._axisPointer = null;
  35852. }
  35853. var axisPointerClazz = [];
  35854. AxisView.registerAxisPointerClass = function (type, clazz) {
  35855. if (__DEV__) {
  35856. if (axisPointerClazz[type]) {
  35857. throw new Error('axisPointer ' + type + ' exists');
  35858. }
  35859. }
  35860. axisPointerClazz[type] = clazz;
  35861. };
  35862. AxisView.getAxisPointerClass = function (type) {
  35863. return type && axisPointerClazz[type];
  35864. };
  35865. /*
  35866. * Licensed to the Apache Software Foundation (ASF) under one
  35867. * or more contributor license agreements. See the NOTICE file
  35868. * distributed with this work for additional information
  35869. * regarding copyright ownership. The ASF licenses this file
  35870. * to you under the Apache License, Version 2.0 (the
  35871. * "License"); you may not use this file except in compliance
  35872. * with the License. You may obtain a copy of the License at
  35873. *
  35874. * http://www.apache.org/licenses/LICENSE-2.0
  35875. *
  35876. * Unless required by applicable law or agreed to in writing,
  35877. * software distributed under the License is distributed on an
  35878. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35879. * KIND, either express or implied. See the License for the
  35880. * specific language governing permissions and limitations
  35881. * under the License.
  35882. */
  35883. /**
  35884. * Can only be called after coordinate system creation stage.
  35885. * (Can be called before coordinate system update stage).
  35886. *
  35887. * @param {Object} opt {labelInside}
  35888. * @return {Object} {
  35889. * position, rotation, labelDirection, labelOffset,
  35890. * tickDirection, labelRotate, z2
  35891. * }
  35892. */
  35893. function layout$1(gridModel, axisModel, opt) {
  35894. opt = opt || {};
  35895. var grid = gridModel.coordinateSystem;
  35896. var axis = axisModel.axis;
  35897. var layout = {};
  35898. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  35899. var rawAxisPosition = axis.position;
  35900. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  35901. var axisDim = axis.dim;
  35902. var rect = grid.getRect();
  35903. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  35904. var idx = {left: 0, right: 1, top: 0, bottom: 1, onZero: 2};
  35905. var axisOffset = axisModel.get('offset') || 0;
  35906. var posBound = axisDim === 'x'
  35907. ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset]
  35908. : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  35909. if (otherAxisOnZeroOf) {
  35910. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  35911. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  35912. }
  35913. // Axis position
  35914. layout.position = [
  35915. axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0],
  35916. axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]
  35917. ];
  35918. // Axis rotation
  35919. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  35920. // Tick and label direction, x y is axisDim
  35921. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  35922. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  35923. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  35924. if (axisModel.get('axisTick.inside')) {
  35925. layout.tickDirection = -layout.tickDirection;
  35926. }
  35927. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  35928. layout.labelDirection = -layout.labelDirection;
  35929. }
  35930. // Special label rotation
  35931. var labelRotate = axisModel.get('axisLabel.rotate');
  35932. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  35933. // Over splitLine and splitArea
  35934. layout.z2 = 1;
  35935. return layout;
  35936. }
  35937. /*
  35938. * Licensed to the Apache Software Foundation (ASF) under one
  35939. * or more contributor license agreements. See the NOTICE file
  35940. * distributed with this work for additional information
  35941. * regarding copyright ownership. The ASF licenses this file
  35942. * to you under the Apache License, Version 2.0 (the
  35943. * "License"); you may not use this file except in compliance
  35944. * with the License. You may obtain a copy of the License at
  35945. *
  35946. * http://www.apache.org/licenses/LICENSE-2.0
  35947. *
  35948. * Unless required by applicable law or agreed to in writing,
  35949. * software distributed under the License is distributed on an
  35950. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35951. * KIND, either express or implied. See the License for the
  35952. * specific language governing permissions and limitations
  35953. * under the License.
  35954. */
  35955. function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
  35956. var axis = axisModel.axis;
  35957. if (axis.scale.isBlank()) {
  35958. return;
  35959. }
  35960. var splitAreaModel = axisModel.getModel('splitArea');
  35961. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  35962. var areaColors = areaStyleModel.get('color');
  35963. var gridRect = gridModel.coordinateSystem.getRect();
  35964. var ticksCoords = axis.getTicksCoords({
  35965. tickModel: splitAreaModel,
  35966. clamp: true
  35967. });
  35968. if (!ticksCoords.length) {
  35969. return;
  35970. }
  35971. // For Making appropriate splitArea animation, the color and anid
  35972. // should be corresponding to previous one if possible.
  35973. var areaColorsLen = areaColors.length;
  35974. var lastSplitAreaColors = axisView.__splitAreaColors;
  35975. var newSplitAreaColors = createHashMap();
  35976. var colorIndex = 0;
  35977. if (lastSplitAreaColors) {
  35978. for (var i = 0; i < ticksCoords.length; i++) {
  35979. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  35980. if (cIndex != null) {
  35981. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  35982. break;
  35983. }
  35984. }
  35985. }
  35986. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  35987. var areaStyle = areaStyleModel.getAreaStyle();
  35988. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  35989. for (var i = 1; i < ticksCoords.length; i++) {
  35990. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  35991. var x;
  35992. var y;
  35993. var width;
  35994. var height;
  35995. if (axis.isHorizontal()) {
  35996. x = prev;
  35997. y = gridRect.y;
  35998. width = tickCoord - x;
  35999. height = gridRect.height;
  36000. prev = x + width;
  36001. }
  36002. else {
  36003. x = gridRect.x;
  36004. y = prev;
  36005. width = gridRect.width;
  36006. height = tickCoord - y;
  36007. prev = y + height;
  36008. }
  36009. var tickValue = ticksCoords[i - 1].tickValue;
  36010. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  36011. axisGroup.add(new Rect({
  36012. anid: tickValue != null ? 'area_' + tickValue : null,
  36013. shape: {
  36014. x: x,
  36015. y: y,
  36016. width: width,
  36017. height: height
  36018. },
  36019. style: defaults({
  36020. fill: areaColors[colorIndex]
  36021. }, areaStyle),
  36022. silent: true
  36023. }));
  36024. colorIndex = (colorIndex + 1) % areaColorsLen;
  36025. }
  36026. axisView.__splitAreaColors = newSplitAreaColors;
  36027. }
  36028. function rectCoordAxisHandleRemove(axisView) {
  36029. axisView.__splitAreaColors = null;
  36030. }
  36031. /*
  36032. * Licensed to the Apache Software Foundation (ASF) under one
  36033. * or more contributor license agreements. See the NOTICE file
  36034. * distributed with this work for additional information
  36035. * regarding copyright ownership. The ASF licenses this file
  36036. * to you under the Apache License, Version 2.0 (the
  36037. * "License"); you may not use this file except in compliance
  36038. * with the License. You may obtain a copy of the License at
  36039. *
  36040. * http://www.apache.org/licenses/LICENSE-2.0
  36041. *
  36042. * Unless required by applicable law or agreed to in writing,
  36043. * software distributed under the License is distributed on an
  36044. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36045. * KIND, either express or implied. See the License for the
  36046. * specific language governing permissions and limitations
  36047. * under the License.
  36048. */
  36049. var axisBuilderAttrs = [
  36050. 'axisLine', 'axisTickLabel', 'axisName'
  36051. ];
  36052. var selfBuilderAttrs = [
  36053. 'splitArea', 'splitLine', 'minorSplitLine'
  36054. ];
  36055. var CartesianAxisView = AxisView.extend({
  36056. type: 'cartesianAxis',
  36057. axisPointerClass: 'CartesianAxisPointer',
  36058. /**
  36059. * @override
  36060. */
  36061. render: function (axisModel, ecModel, api, payload) {
  36062. this.group.removeAll();
  36063. var oldAxisGroup = this._axisGroup;
  36064. this._axisGroup = new Group();
  36065. this.group.add(this._axisGroup);
  36066. if (!axisModel.get('show')) {
  36067. return;
  36068. }
  36069. var gridModel = axisModel.getCoordSysModel();
  36070. var layout = layout$1(gridModel, axisModel);
  36071. var axisBuilder = new AxisBuilder(axisModel, layout);
  36072. each$1(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  36073. this._axisGroup.add(axisBuilder.getGroup());
  36074. each$1(selfBuilderAttrs, function (name) {
  36075. if (axisModel.get(name + '.show')) {
  36076. this['_' + name](axisModel, gridModel);
  36077. }
  36078. }, this);
  36079. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  36080. CartesianAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  36081. },
  36082. remove: function () {
  36083. rectCoordAxisHandleRemove(this);
  36084. },
  36085. /**
  36086. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  36087. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  36088. * @private
  36089. */
  36090. _splitLine: function (axisModel, gridModel) {
  36091. var axis = axisModel.axis;
  36092. if (axis.scale.isBlank()) {
  36093. return;
  36094. }
  36095. var splitLineModel = axisModel.getModel('splitLine');
  36096. var lineStyleModel = splitLineModel.getModel('lineStyle');
  36097. var lineColors = lineStyleModel.get('color');
  36098. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  36099. var gridRect = gridModel.coordinateSystem.getRect();
  36100. var isHorizontal = axis.isHorizontal();
  36101. var lineCount = 0;
  36102. var ticksCoords = axis.getTicksCoords({
  36103. tickModel: splitLineModel
  36104. });
  36105. var p1 = [];
  36106. var p2 = [];
  36107. var lineStyle = lineStyleModel.getLineStyle();
  36108. for (var i = 0; i < ticksCoords.length; i++) {
  36109. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  36110. if (isHorizontal) {
  36111. p1[0] = tickCoord;
  36112. p1[1] = gridRect.y;
  36113. p2[0] = tickCoord;
  36114. p2[1] = gridRect.y + gridRect.height;
  36115. }
  36116. else {
  36117. p1[0] = gridRect.x;
  36118. p1[1] = tickCoord;
  36119. p2[0] = gridRect.x + gridRect.width;
  36120. p2[1] = tickCoord;
  36121. }
  36122. var colorIndex = (lineCount++) % lineColors.length;
  36123. var tickValue = ticksCoords[i].tickValue;
  36124. this._axisGroup.add(new Line({
  36125. anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
  36126. subPixelOptimize: true,
  36127. shape: {
  36128. x1: p1[0],
  36129. y1: p1[1],
  36130. x2: p2[0],
  36131. y2: p2[1]
  36132. },
  36133. style: defaults({
  36134. stroke: lineColors[colorIndex]
  36135. }, lineStyle),
  36136. silent: true
  36137. }));
  36138. }
  36139. },
  36140. /**
  36141. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  36142. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  36143. * @private
  36144. */
  36145. _minorSplitLine: function (axisModel, gridModel) {
  36146. var axis = axisModel.axis;
  36147. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  36148. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  36149. var gridRect = gridModel.coordinateSystem.getRect();
  36150. var isHorizontal = axis.isHorizontal();
  36151. var minorTicksCoords = axis.getMinorTicksCoords();
  36152. if (!minorTicksCoords.length) {
  36153. return;
  36154. }
  36155. var p1 = [];
  36156. var p2 = [];
  36157. var lineStyle = lineStyleModel.getLineStyle();
  36158. for (var i = 0; i < minorTicksCoords.length; i++) {
  36159. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  36160. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  36161. if (isHorizontal) {
  36162. p1[0] = tickCoord;
  36163. p1[1] = gridRect.y;
  36164. p2[0] = tickCoord;
  36165. p2[1] = gridRect.y + gridRect.height;
  36166. }
  36167. else {
  36168. p1[0] = gridRect.x;
  36169. p1[1] = tickCoord;
  36170. p2[0] = gridRect.x + gridRect.width;
  36171. p2[1] = tickCoord;
  36172. }
  36173. this._axisGroup.add(new Line({
  36174. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  36175. subPixelOptimize: true,
  36176. shape: {
  36177. x1: p1[0],
  36178. y1: p1[1],
  36179. x2: p2[0],
  36180. y2: p2[1]
  36181. },
  36182. style: lineStyle,
  36183. silent: true
  36184. }));
  36185. }
  36186. }
  36187. },
  36188. /**
  36189. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  36190. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  36191. * @private
  36192. */
  36193. _splitArea: function (axisModel, gridModel) {
  36194. rectCoordAxisBuildSplitArea(this, this._axisGroup, axisModel, gridModel);
  36195. }
  36196. });
  36197. CartesianAxisView.extend({
  36198. type: 'xAxis'
  36199. });
  36200. CartesianAxisView.extend({
  36201. type: 'yAxis'
  36202. });
  36203. /*
  36204. * Licensed to the Apache Software Foundation (ASF) under one
  36205. * or more contributor license agreements. See the NOTICE file
  36206. * distributed with this work for additional information
  36207. * regarding copyright ownership. The ASF licenses this file
  36208. * to you under the Apache License, Version 2.0 (the
  36209. * "License"); you may not use this file except in compliance
  36210. * with the License. You may obtain a copy of the License at
  36211. *
  36212. * http://www.apache.org/licenses/LICENSE-2.0
  36213. *
  36214. * Unless required by applicable law or agreed to in writing,
  36215. * software distributed under the License is distributed on an
  36216. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36217. * KIND, either express or implied. See the License for the
  36218. * specific language governing permissions and limitations
  36219. * under the License.
  36220. */
  36221. /*
  36222. * Licensed to the Apache Software Foundation (ASF) under one
  36223. * or more contributor license agreements. See the NOTICE file
  36224. * distributed with this work for additional information
  36225. * regarding copyright ownership. The ASF licenses this file
  36226. * to you under the Apache License, Version 2.0 (the
  36227. * "License"); you may not use this file except in compliance
  36228. * with the License. You may obtain a copy of the License at
  36229. *
  36230. * http://www.apache.org/licenses/LICENSE-2.0
  36231. *
  36232. * Unless required by applicable law or agreed to in writing,
  36233. * software distributed under the License is distributed on an
  36234. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36235. * KIND, either express or implied. See the License for the
  36236. * specific language governing permissions and limitations
  36237. * under the License.
  36238. */
  36239. // Grid view
  36240. extendComponentView({
  36241. type: 'grid',
  36242. render: function (gridModel, ecModel) {
  36243. this.group.removeAll();
  36244. if (gridModel.get('show')) {
  36245. this.group.add(new Rect({
  36246. shape: gridModel.coordinateSystem.getRect(),
  36247. style: defaults({
  36248. fill: gridModel.get('backgroundColor')
  36249. }, gridModel.getItemStyle()),
  36250. silent: true,
  36251. z2: -1
  36252. }));
  36253. }
  36254. }
  36255. });
  36256. registerPreprocessor(function (option) {
  36257. // Only create grid when need
  36258. if (option.xAxis && option.yAxis && !option.grid) {
  36259. option.grid = {};
  36260. }
  36261. });
  36262. /*
  36263. * Licensed to the Apache Software Foundation (ASF) under one
  36264. * or more contributor license agreements. See the NOTICE file
  36265. * distributed with this work for additional information
  36266. * regarding copyright ownership. The ASF licenses this file
  36267. * to you under the Apache License, Version 2.0 (the
  36268. * "License"); you may not use this file except in compliance
  36269. * with the License. You may obtain a copy of the License at
  36270. *
  36271. * http://www.apache.org/licenses/LICENSE-2.0
  36272. *
  36273. * Unless required by applicable law or agreed to in writing,
  36274. * software distributed under the License is distributed on an
  36275. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36276. * KIND, either express or implied. See the License for the
  36277. * specific language governing permissions and limitations
  36278. * under the License.
  36279. */
  36280. // In case developer forget to include grid component
  36281. registerVisual(visualSymbol('line', 'circle', 'line'));
  36282. registerLayout(layoutPoints('line'));
  36283. // Down sample after filter
  36284. registerProcessor(
  36285. PRIORITY.PROCESSOR.STATISTIC,
  36286. dataSample('line')
  36287. );
  36288. /*
  36289. * Licensed to the Apache Software Foundation (ASF) under one
  36290. * or more contributor license agreements. See the NOTICE file
  36291. * distributed with this work for additional information
  36292. * regarding copyright ownership. The ASF licenses this file
  36293. * to you under the Apache License, Version 2.0 (the
  36294. * "License"); you may not use this file except in compliance
  36295. * with the License. You may obtain a copy of the License at
  36296. *
  36297. * http://www.apache.org/licenses/LICENSE-2.0
  36298. *
  36299. * Unless required by applicable law or agreed to in writing,
  36300. * software distributed under the License is distributed on an
  36301. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36302. * KIND, either express or implied. See the License for the
  36303. * specific language governing permissions and limitations
  36304. * under the License.
  36305. */
  36306. var BaseBarSeries = SeriesModel.extend({
  36307. type: 'series.__base_bar__',
  36308. getInitialData: function (option, ecModel) {
  36309. return createListFromArray(this.getSource(), this, {useEncodeDefaulter: true});
  36310. },
  36311. getMarkerPosition: function (value) {
  36312. var coordSys = this.coordinateSystem;
  36313. if (coordSys) {
  36314. // PENDING if clamp ?
  36315. var pt = coordSys.dataToPoint(coordSys.clampData(value));
  36316. var data = this.getData();
  36317. var offset = data.getLayout('offset');
  36318. var size = data.getLayout('size');
  36319. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  36320. pt[offsetIndex] += offset + size / 2;
  36321. return pt;
  36322. }
  36323. return [NaN, NaN];
  36324. },
  36325. defaultOption: {
  36326. zlevel: 0, // 一级层叠
  36327. z: 2, // 二级层叠
  36328. coordinateSystem: 'cartesian2d',
  36329. legendHoverLink: true,
  36330. // stack: null
  36331. // Cartesian coordinate system
  36332. // xAxisIndex: 0,
  36333. // yAxisIndex: 0,
  36334. // 最小高度改为0
  36335. barMinHeight: 0,
  36336. // 最小角度为0,仅对极坐标系下的柱状图有效
  36337. barMinAngle: 0,
  36338. // cursor: null,
  36339. large: false,
  36340. largeThreshold: 400,
  36341. progressive: 3e3,
  36342. progressiveChunkMode: 'mod',
  36343. // barMaxWidth: null,
  36344. // In cartesian, the default value is 1. Otherwise null.
  36345. // barMinWidth: null,
  36346. // 默认自适应
  36347. // barWidth: null,
  36348. // 柱间距离,默认为柱形宽度的30%,可设固定值
  36349. // barGap: '30%',
  36350. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  36351. // barCategoryGap: '20%',
  36352. // label: {
  36353. // show: false
  36354. // },
  36355. itemStyle: {},
  36356. emphasis: {}
  36357. }
  36358. });
  36359. /*
  36360. * Licensed to the Apache Software Foundation (ASF) under one
  36361. * or more contributor license agreements. See the NOTICE file
  36362. * distributed with this work for additional information
  36363. * regarding copyright ownership. The ASF licenses this file
  36364. * to you under the Apache License, Version 2.0 (the
  36365. * "License"); you may not use this file except in compliance
  36366. * with the License. You may obtain a copy of the License at
  36367. *
  36368. * http://www.apache.org/licenses/LICENSE-2.0
  36369. *
  36370. * Unless required by applicable law or agreed to in writing,
  36371. * software distributed under the License is distributed on an
  36372. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36373. * KIND, either express or implied. See the License for the
  36374. * specific language governing permissions and limitations
  36375. * under the License.
  36376. */
  36377. BaseBarSeries.extend({
  36378. type: 'series.bar',
  36379. dependencies: ['grid', 'polar'],
  36380. brushSelector: 'rect',
  36381. /**
  36382. * @override
  36383. */
  36384. getProgressive: function () {
  36385. // Do not support progressive in normal mode.
  36386. return this.get('large')
  36387. ? this.get('progressive')
  36388. : false;
  36389. },
  36390. /**
  36391. * @override
  36392. */
  36393. getProgressiveThreshold: function () {
  36394. // Do not support progressive in normal mode.
  36395. var progressiveThreshold = this.get('progressiveThreshold');
  36396. var largeThreshold = this.get('largeThreshold');
  36397. if (largeThreshold > progressiveThreshold) {
  36398. progressiveThreshold = largeThreshold;
  36399. }
  36400. return progressiveThreshold;
  36401. },
  36402. defaultOption: {
  36403. // If clipped
  36404. // Only available on cartesian2d
  36405. clip: true,
  36406. // If use caps on two sides of bars
  36407. // Only available on tangential polar bar
  36408. roundCap: false,
  36409. showBackground: false,
  36410. backgroundStyle: {
  36411. color: 'rgba(180, 180, 180, 0.2)',
  36412. borderColor: null,
  36413. borderWidth: 0,
  36414. borderType: 'solid',
  36415. borderRadius: 0,
  36416. shadowBlur: 0,
  36417. shadowColor: null,
  36418. shadowOffsetX: 0,
  36419. shadowOffsetY: 0,
  36420. opacity: 1
  36421. }
  36422. }
  36423. });
  36424. /*
  36425. * Licensed to the Apache Software Foundation (ASF) under one
  36426. * or more contributor license agreements. See the NOTICE file
  36427. * distributed with this work for additional information
  36428. * regarding copyright ownership. The ASF licenses this file
  36429. * to you under the Apache License, Version 2.0 (the
  36430. * "License"); you may not use this file except in compliance
  36431. * with the License. You may obtain a copy of the License at
  36432. *
  36433. * http://www.apache.org/licenses/LICENSE-2.0
  36434. *
  36435. * Unless required by applicable law or agreed to in writing,
  36436. * software distributed under the License is distributed on an
  36437. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36438. * KIND, either express or implied. See the License for the
  36439. * specific language governing permissions and limitations
  36440. * under the License.
  36441. */
  36442. function setLabel(
  36443. normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside
  36444. ) {
  36445. var labelModel = itemModel.getModel('label');
  36446. var hoverLabelModel = itemModel.getModel('emphasis.label');
  36447. setLabelStyle(
  36448. normalStyle, hoverStyle, labelModel, hoverLabelModel,
  36449. {
  36450. labelFetcher: seriesModel,
  36451. labelDataIndex: dataIndex,
  36452. defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
  36453. isRectText: true,
  36454. autoColor: color
  36455. }
  36456. );
  36457. fixPosition(normalStyle);
  36458. fixPosition(hoverStyle);
  36459. }
  36460. function fixPosition(style, labelPositionOutside) {
  36461. if (style.textPosition === 'outside') {
  36462. style.textPosition = labelPositionOutside;
  36463. }
  36464. }
  36465. /*
  36466. * Licensed to the Apache Software Foundation (ASF) under one
  36467. * or more contributor license agreements. See the NOTICE file
  36468. * distributed with this work for additional information
  36469. * regarding copyright ownership. The ASF licenses this file
  36470. * to you under the Apache License, Version 2.0 (the
  36471. * "License"); you may not use this file except in compliance
  36472. * with the License. You may obtain a copy of the License at
  36473. *
  36474. * http://www.apache.org/licenses/LICENSE-2.0
  36475. *
  36476. * Unless required by applicable law or agreed to in writing,
  36477. * software distributed under the License is distributed on an
  36478. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36479. * KIND, either express or implied. See the License for the
  36480. * specific language governing permissions and limitations
  36481. * under the License.
  36482. */
  36483. var getBarItemStyle = makeStyleMapper(
  36484. [
  36485. ['fill', 'color'],
  36486. ['stroke', 'borderColor'],
  36487. ['lineWidth', 'borderWidth'],
  36488. // Compatitable with 2
  36489. ['stroke', 'barBorderColor'],
  36490. ['lineWidth', 'barBorderWidth'],
  36491. ['opacity'],
  36492. ['shadowBlur'],
  36493. ['shadowOffsetX'],
  36494. ['shadowOffsetY'],
  36495. ['shadowColor']
  36496. ]
  36497. );
  36498. var barItemStyle = {
  36499. getBarItemStyle: function (excludes) {
  36500. var style = getBarItemStyle(this, excludes);
  36501. if (this.getBorderLineDash) {
  36502. var lineDash = this.getBorderLineDash();
  36503. lineDash && (style.lineDash = lineDash);
  36504. }
  36505. return style;
  36506. }
  36507. };
  36508. /*
  36509. * Licensed to the Apache Software Foundation (ASF) under one
  36510. * or more contributor license agreements. See the NOTICE file
  36511. * distributed with this work for additional information
  36512. * regarding copyright ownership. The ASF licenses this file
  36513. * to you under the Apache License, Version 2.0 (the
  36514. * "License"); you may not use this file except in compliance
  36515. * with the License. You may obtain a copy of the License at
  36516. *
  36517. * http://www.apache.org/licenses/LICENSE-2.0
  36518. *
  36519. * Unless required by applicable law or agreed to in writing,
  36520. * software distributed under the License is distributed on an
  36521. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36522. * KIND, either express or implied. See the License for the
  36523. * specific language governing permissions and limitations
  36524. * under the License.
  36525. */
  36526. /**
  36527. * Sausage: similar to sector, but have half circle on both sides
  36528. * @public
  36529. */
  36530. var Sausage = extendShape({
  36531. type: 'sausage',
  36532. shape: {
  36533. cx: 0,
  36534. cy: 0,
  36535. r0: 0,
  36536. r: 0,
  36537. startAngle: 0,
  36538. endAngle: Math.PI * 2,
  36539. clockwise: true
  36540. },
  36541. buildPath: function (ctx, shape) {
  36542. var x = shape.cx;
  36543. var y = shape.cy;
  36544. var r0 = Math.max(shape.r0 || 0, 0);
  36545. var r = Math.max(shape.r, 0);
  36546. var dr = (r - r0) * 0.5;
  36547. var rCenter = r0 + dr;
  36548. var startAngle = shape.startAngle;
  36549. var endAngle = shape.endAngle;
  36550. var clockwise = shape.clockwise;
  36551. var unitStartX = Math.cos(startAngle);
  36552. var unitStartY = Math.sin(startAngle);
  36553. var unitEndX = Math.cos(endAngle);
  36554. var unitEndY = Math.sin(endAngle);
  36555. var lessThanCircle = clockwise
  36556. ? endAngle - startAngle < Math.PI * 2
  36557. : startAngle - endAngle < Math.PI * 2;
  36558. if (lessThanCircle) {
  36559. ctx.moveTo(unitStartX * r0 + x, unitStartY * r0 + y);
  36560. ctx.arc(
  36561. unitStartX * rCenter + x, unitStartY * rCenter + y, dr,
  36562. -Math.PI + startAngle, startAngle, !clockwise
  36563. );
  36564. }
  36565. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  36566. ctx.moveTo(unitEndX * r + x, unitEndY * r + y);
  36567. ctx.arc(
  36568. unitEndX * rCenter + x, unitEndY * rCenter + y, dr,
  36569. endAngle - Math.PI * 2, endAngle - Math.PI, !clockwise
  36570. );
  36571. if (r0 !== 0) {
  36572. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  36573. ctx.moveTo(unitStartX * r0 + x, unitEndY * r0 + y);
  36574. }
  36575. ctx.closePath();
  36576. }
  36577. });
  36578. /*
  36579. * Licensed to the Apache Software Foundation (ASF) under one
  36580. * or more contributor license agreements. See the NOTICE file
  36581. * distributed with this work for additional information
  36582. * regarding copyright ownership. The ASF licenses this file
  36583. * to you under the Apache License, Version 2.0 (the
  36584. * "License"); you may not use this file except in compliance
  36585. * with the License. You may obtain a copy of the License at
  36586. *
  36587. * http://www.apache.org/licenses/LICENSE-2.0
  36588. *
  36589. * Unless required by applicable law or agreed to in writing,
  36590. * software distributed under the License is distributed on an
  36591. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36592. * KIND, either express or implied. See the License for the
  36593. * specific language governing permissions and limitations
  36594. * under the License.
  36595. */
  36596. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'barBorderWidth'];
  36597. var _eventPos = [0, 0];
  36598. // FIXME
  36599. // Just for compatible with ec2.
  36600. extend(Model.prototype, barItemStyle);
  36601. function getClipArea(coord, data) {
  36602. var coordSysClipArea = coord.getArea && coord.getArea();
  36603. if (coord.type === 'cartesian2d') {
  36604. var baseAxis = coord.getBaseAxis();
  36605. // When boundaryGap is false or using time axis. bar may exceed the grid.
  36606. // We should not clip this part.
  36607. // See test/bar2.html
  36608. if (baseAxis.type !== 'category' || !baseAxis.onBand) {
  36609. var expandWidth = data.getLayout('bandWidth');
  36610. if (baseAxis.isHorizontal()) {
  36611. coordSysClipArea.x -= expandWidth;
  36612. coordSysClipArea.width += expandWidth * 2;
  36613. }
  36614. else {
  36615. coordSysClipArea.y -= expandWidth;
  36616. coordSysClipArea.height += expandWidth * 2;
  36617. }
  36618. }
  36619. }
  36620. return coordSysClipArea;
  36621. }
  36622. extendChartView({
  36623. type: 'bar',
  36624. render: function (seriesModel, ecModel, api) {
  36625. this._updateDrawMode(seriesModel);
  36626. var coordinateSystemType = seriesModel.get('coordinateSystem');
  36627. if (coordinateSystemType === 'cartesian2d'
  36628. || coordinateSystemType === 'polar'
  36629. ) {
  36630. this._isLargeDraw
  36631. ? this._renderLarge(seriesModel, ecModel, api)
  36632. : this._renderNormal(seriesModel, ecModel, api);
  36633. }
  36634. else if (__DEV__) {
  36635. console.warn('Only cartesian2d and polar supported for bar.');
  36636. }
  36637. return this.group;
  36638. },
  36639. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  36640. this._clear();
  36641. this._updateDrawMode(seriesModel);
  36642. },
  36643. incrementalRender: function (params, seriesModel, ecModel, api) {
  36644. // Do not support progressive in normal mode.
  36645. this._incrementalRenderLarge(params, seriesModel);
  36646. },
  36647. _updateDrawMode: function (seriesModel) {
  36648. var isLargeDraw = seriesModel.pipelineContext.large;
  36649. if (this._isLargeDraw == null || isLargeDraw ^ this._isLargeDraw) {
  36650. this._isLargeDraw = isLargeDraw;
  36651. this._clear();
  36652. }
  36653. },
  36654. _renderNormal: function (seriesModel, ecModel, api) {
  36655. var group = this.group;
  36656. var data = seriesModel.getData();
  36657. var oldData = this._data;
  36658. var coord = seriesModel.coordinateSystem;
  36659. var baseAxis = coord.getBaseAxis();
  36660. var isHorizontalOrRadial;
  36661. if (coord.type === 'cartesian2d') {
  36662. isHorizontalOrRadial = baseAxis.isHorizontal();
  36663. }
  36664. else if (coord.type === 'polar') {
  36665. isHorizontalOrRadial = baseAxis.dim === 'angle';
  36666. }
  36667. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  36668. var needsClip = seriesModel.get('clip', true);
  36669. var coordSysClipArea = getClipArea(coord, data);
  36670. // If there is clipPath created in large mode. Remove it.
  36671. group.removeClipPath();
  36672. // We don't use clipPath in normal mode because we needs a perfect animation
  36673. // And don't want the label are clipped.
  36674. var roundCap = seriesModel.get('roundCap', true);
  36675. var drawBackground = seriesModel.get('showBackground', true);
  36676. var backgroundModel = seriesModel.getModel('backgroundStyle');
  36677. var barBorderRadius = backgroundModel.get('barBorderRadius') || 0;
  36678. var bgEls = [];
  36679. var oldBgEls = this._backgroundEls || [];
  36680. var createBackground = function (dataIndex) {
  36681. var bgLayout = getLayout[coord.type](data, dataIndex);
  36682. var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
  36683. bgEl.useStyle(backgroundModel.getBarItemStyle());
  36684. // Only cartesian2d support borderRadius.
  36685. if (coord.type === 'cartesian2d') {
  36686. bgEl.setShape('r', barBorderRadius);
  36687. }
  36688. bgEls[dataIndex] = bgEl;
  36689. return bgEl;
  36690. };
  36691. data.diff(oldData)
  36692. .add(function (dataIndex) {
  36693. var itemModel = data.getItemModel(dataIndex);
  36694. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  36695. if (drawBackground) {
  36696. createBackground(dataIndex);
  36697. }
  36698. // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  36699. if (!data.hasValue(dataIndex)) {
  36700. return;
  36701. }
  36702. if (needsClip) {
  36703. // Clip will modify the layout params.
  36704. // And return a boolean to determine if the shape are fully clipped.
  36705. var isClipped = clip[coord.type](coordSysClipArea, layout);
  36706. if (isClipped) {
  36707. group.remove(el);
  36708. return;
  36709. }
  36710. }
  36711. var el = elementCreator[coord.type](
  36712. dataIndex, layout, isHorizontalOrRadial, animationModel, false, roundCap
  36713. );
  36714. data.setItemGraphicEl(dataIndex, el);
  36715. group.add(el);
  36716. updateStyle(
  36717. el, data, dataIndex, itemModel, layout,
  36718. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  36719. );
  36720. })
  36721. .update(function (newIndex, oldIndex) {
  36722. var itemModel = data.getItemModel(newIndex);
  36723. var layout = getLayout[coord.type](data, newIndex, itemModel);
  36724. if (drawBackground) {
  36725. var bgEl;
  36726. if (oldBgEls.length === 0) {
  36727. bgEl = createBackground(oldIndex);
  36728. }
  36729. else {
  36730. bgEl = oldBgEls[oldIndex];
  36731. bgEl.useStyle(backgroundModel.getBarItemStyle());
  36732. // Only cartesian2d support borderRadius.
  36733. if (coord.type === 'cartesian2d') {
  36734. bgEl.setShape('r', barBorderRadius);
  36735. }
  36736. bgEls[newIndex] = bgEl;
  36737. }
  36738. var bgLayout = getLayout[coord.type](data, newIndex);
  36739. var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
  36740. updateProps(bgEl, { shape: shape }, animationModel, newIndex);
  36741. }
  36742. var el = oldData.getItemGraphicEl(oldIndex);
  36743. if (!data.hasValue(newIndex)) {
  36744. group.remove(el);
  36745. return;
  36746. }
  36747. if (needsClip) {
  36748. var isClipped = clip[coord.type](coordSysClipArea, layout);
  36749. if (isClipped) {
  36750. group.remove(el);
  36751. return;
  36752. }
  36753. }
  36754. if (el) {
  36755. updateProps(el, {shape: layout}, animationModel, newIndex);
  36756. }
  36757. else {
  36758. el = elementCreator[coord.type](
  36759. newIndex, layout, isHorizontalOrRadial, animationModel, true, roundCap
  36760. );
  36761. }
  36762. data.setItemGraphicEl(newIndex, el);
  36763. // Add back
  36764. group.add(el);
  36765. updateStyle(
  36766. el, data, newIndex, itemModel, layout,
  36767. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  36768. );
  36769. })
  36770. .remove(function (dataIndex) {
  36771. var el = oldData.getItemGraphicEl(dataIndex);
  36772. if (coord.type === 'cartesian2d') {
  36773. el && removeRect(dataIndex, animationModel, el);
  36774. }
  36775. else {
  36776. el && removeSector(dataIndex, animationModel, el);
  36777. }
  36778. })
  36779. .execute();
  36780. var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
  36781. bgGroup.removeAll();
  36782. for (var i = 0; i < bgEls.length; ++i) {
  36783. bgGroup.add(bgEls[i]);
  36784. }
  36785. group.add(bgGroup);
  36786. this._backgroundEls = bgEls;
  36787. this._data = data;
  36788. },
  36789. _renderLarge: function (seriesModel, ecModel, api) {
  36790. this._clear();
  36791. createLarge(seriesModel, this.group);
  36792. // Use clipPath in large mode.
  36793. var clipPath = seriesModel.get('clip', true)
  36794. ? createClipPath(seriesModel.coordinateSystem, false, seriesModel)
  36795. : null;
  36796. if (clipPath) {
  36797. this.group.setClipPath(clipPath);
  36798. }
  36799. else {
  36800. this.group.removeClipPath();
  36801. }
  36802. },
  36803. _incrementalRenderLarge: function (params, seriesModel) {
  36804. this._removeBackground();
  36805. createLarge(seriesModel, this.group, true);
  36806. },
  36807. dispose: noop,
  36808. remove: function (ecModel) {
  36809. this._clear(ecModel);
  36810. },
  36811. _clear: function (ecModel) {
  36812. var group = this.group;
  36813. var data = this._data;
  36814. if (ecModel && ecModel.get('animation') && data && !this._isLargeDraw) {
  36815. this._removeBackground();
  36816. this._backgroundEls = [];
  36817. data.eachItemGraphicEl(function (el) {
  36818. if (el.type === 'sector') {
  36819. removeSector(el.dataIndex, ecModel, el);
  36820. }
  36821. else {
  36822. removeRect(el.dataIndex, ecModel, el);
  36823. }
  36824. });
  36825. }
  36826. else {
  36827. group.removeAll();
  36828. }
  36829. this._data = null;
  36830. },
  36831. _removeBackground: function () {
  36832. this.group.remove(this._backgroundGroup);
  36833. this._backgroundGroup = null;
  36834. }
  36835. });
  36836. var mathMax$4 = Math.max;
  36837. var mathMin$4 = Math.min;
  36838. var clip = {
  36839. cartesian2d: function (coordSysBoundingRect, layout) {
  36840. var signWidth = layout.width < 0 ? -1 : 1;
  36841. var signHeight = layout.height < 0 ? -1 : 1;
  36842. // Needs positive width and height
  36843. if (signWidth < 0) {
  36844. layout.x += layout.width;
  36845. layout.width = -layout.width;
  36846. }
  36847. if (signHeight < 0) {
  36848. layout.y += layout.height;
  36849. layout.height = -layout.height;
  36850. }
  36851. var x = mathMax$4(layout.x, coordSysBoundingRect.x);
  36852. var x2 = mathMin$4(layout.x + layout.width, coordSysBoundingRect.x + coordSysBoundingRect.width);
  36853. var y = mathMax$4(layout.y, coordSysBoundingRect.y);
  36854. var y2 = mathMin$4(layout.y + layout.height, coordSysBoundingRect.y + coordSysBoundingRect.height);
  36855. layout.x = x;
  36856. layout.y = y;
  36857. layout.width = x2 - x;
  36858. layout.height = y2 - y;
  36859. var clipped = layout.width < 0 || layout.height < 0;
  36860. // Reverse back
  36861. if (signWidth < 0) {
  36862. layout.x += layout.width;
  36863. layout.width = -layout.width;
  36864. }
  36865. if (signHeight < 0) {
  36866. layout.y += layout.height;
  36867. layout.height = -layout.height;
  36868. }
  36869. return clipped;
  36870. },
  36871. polar: function (coordSysClipArea, layout) {
  36872. var signR = layout.r0 <= layout.r ? 1 : -1;
  36873. // Make sure r is larger than r0
  36874. if (signR < 0) {
  36875. var r = layout.r;
  36876. layout.r = layout.r0;
  36877. layout.r0 = r;
  36878. }
  36879. var r = mathMin$4(layout.r, coordSysClipArea.r);
  36880. var r0 = mathMax$4(layout.r0, coordSysClipArea.r0);
  36881. layout.r = r;
  36882. layout.r0 = r0;
  36883. var clipped = r - r0 < 0;
  36884. // Reverse back
  36885. if (signR < 0) {
  36886. var r = layout.r;
  36887. layout.r = layout.r0;
  36888. layout.r0 = r;
  36889. }
  36890. return clipped;
  36891. }
  36892. };
  36893. var elementCreator = {
  36894. cartesian2d: function (
  36895. dataIndex, layout, isHorizontal,
  36896. animationModel, isUpdate
  36897. ) {
  36898. var rect = new Rect({
  36899. shape: extend({}, layout),
  36900. z2: 1
  36901. });
  36902. rect.name = 'item';
  36903. // Animation
  36904. if (animationModel) {
  36905. var rectShape = rect.shape;
  36906. var animateProperty = isHorizontal ? 'height' : 'width';
  36907. var animateTarget = {};
  36908. rectShape[animateProperty] = 0;
  36909. animateTarget[animateProperty] = layout[animateProperty];
  36910. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  36911. shape: animateTarget
  36912. }, animationModel, dataIndex);
  36913. }
  36914. return rect;
  36915. },
  36916. polar: function (
  36917. dataIndex, layout, isRadial,
  36918. animationModel, isUpdate, roundCap
  36919. ) {
  36920. // Keep the same logic with bar in catesion: use end value to control
  36921. // direction. Notice that if clockwise is true (by default), the sector
  36922. // will always draw clockwisely, no matter whether endAngle is greater
  36923. // or less than startAngle.
  36924. var clockwise = layout.startAngle < layout.endAngle;
  36925. var ShapeClass = (!isRadial && roundCap) ? Sausage : Sector;
  36926. var sector = new ShapeClass({
  36927. shape: defaults({clockwise: clockwise}, layout),
  36928. z2: 1
  36929. });
  36930. sector.name = 'item';
  36931. // Animation
  36932. if (animationModel) {
  36933. var sectorShape = sector.shape;
  36934. var animateProperty = isRadial ? 'r' : 'endAngle';
  36935. var animateTarget = {};
  36936. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  36937. animateTarget[animateProperty] = layout[animateProperty];
  36938. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  36939. shape: animateTarget
  36940. }, animationModel, dataIndex);
  36941. }
  36942. return sector;
  36943. }
  36944. };
  36945. function removeRect(dataIndex, animationModel, el) {
  36946. // Not show text when animating
  36947. el.style.text = null;
  36948. updateProps(el, {
  36949. shape: {
  36950. width: 0
  36951. }
  36952. }, animationModel, dataIndex, function () {
  36953. el.parent && el.parent.remove(el);
  36954. });
  36955. }
  36956. function removeSector(dataIndex, animationModel, el) {
  36957. // Not show text when animating
  36958. el.style.text = null;
  36959. updateProps(el, {
  36960. shape: {
  36961. r: el.shape.r0
  36962. }
  36963. }, animationModel, dataIndex, function () {
  36964. el.parent && el.parent.remove(el);
  36965. });
  36966. }
  36967. var getLayout = {
  36968. // itemModel is only used to get borderWidth, which is not needed
  36969. // when calculating bar background layout.
  36970. cartesian2d: function (data, dataIndex, itemModel) {
  36971. var layout = data.getItemLayout(dataIndex);
  36972. var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0;
  36973. // fix layout with lineWidth
  36974. var signX = layout.width > 0 ? 1 : -1;
  36975. var signY = layout.height > 0 ? 1 : -1;
  36976. return {
  36977. x: layout.x + signX * fixedLineWidth / 2,
  36978. y: layout.y + signY * fixedLineWidth / 2,
  36979. width: layout.width - signX * fixedLineWidth,
  36980. height: layout.height - signY * fixedLineWidth
  36981. };
  36982. },
  36983. polar: function (data, dataIndex, itemModel) {
  36984. var layout = data.getItemLayout(dataIndex);
  36985. return {
  36986. cx: layout.cx,
  36987. cy: layout.cy,
  36988. r0: layout.r0,
  36989. r: layout.r,
  36990. startAngle: layout.startAngle,
  36991. endAngle: layout.endAngle
  36992. };
  36993. }
  36994. };
  36995. function isZeroOnPolar(layout) {
  36996. return layout.startAngle != null
  36997. && layout.endAngle != null
  36998. && layout.startAngle === layout.endAngle;
  36999. }
  37000. function updateStyle(
  37001. el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar
  37002. ) {
  37003. var color = data.getItemVisual(dataIndex, 'color');
  37004. var opacity = data.getItemVisual(dataIndex, 'opacity');
  37005. var stroke = data.getVisual('borderColor');
  37006. var itemStyleModel = itemModel.getModel('itemStyle');
  37007. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getBarItemStyle();
  37008. if (!isPolar) {
  37009. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  37010. }
  37011. el.useStyle(defaults(
  37012. {
  37013. stroke: isZeroOnPolar(layout) ? 'none' : stroke,
  37014. fill: isZeroOnPolar(layout) ? 'none' : color,
  37015. opacity: opacity
  37016. },
  37017. itemStyleModel.getBarItemStyle()
  37018. ));
  37019. var cursorStyle = itemModel.getShallow('cursor');
  37020. cursorStyle && el.attr('cursor', cursorStyle);
  37021. var labelPositionOutside = isHorizontal
  37022. ? (layout.height > 0 ? 'bottom' : 'top')
  37023. : (layout.width > 0 ? 'left' : 'right');
  37024. if (!isPolar) {
  37025. setLabel(
  37026. el.style, hoverStyle, itemModel, color,
  37027. seriesModel, dataIndex, labelPositionOutside
  37028. );
  37029. }
  37030. if (isZeroOnPolar(layout)) {
  37031. hoverStyle.fill = hoverStyle.stroke = 'none';
  37032. }
  37033. setHoverStyle(el, hoverStyle);
  37034. }
  37035. // In case width or height are too small.
  37036. function getLineWidth(itemModel, rawLayout) {
  37037. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  37038. // width or height may be NaN for empty data
  37039. var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
  37040. var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
  37041. return Math.min(lineWidth, width, height);
  37042. }
  37043. var LargePath = Path.extend({
  37044. type: 'largeBar',
  37045. shape: {points: []},
  37046. buildPath: function (ctx, shape) {
  37047. // Drawing lines is more efficient than drawing
  37048. // a whole line or drawing rects.
  37049. var points = shape.points;
  37050. var startPoint = this.__startPoint;
  37051. var baseDimIdx = this.__baseDimIdx;
  37052. for (var i = 0; i < points.length; i += 2) {
  37053. startPoint[baseDimIdx] = points[i + baseDimIdx];
  37054. ctx.moveTo(startPoint[0], startPoint[1]);
  37055. ctx.lineTo(points[i], points[i + 1]);
  37056. }
  37057. }
  37058. });
  37059. function createLarge(seriesModel, group, incremental) {
  37060. // TODO support polar
  37061. var data = seriesModel.getData();
  37062. var startPoint = [];
  37063. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  37064. startPoint[1 - baseDimIdx] = data.getLayout('valueAxisStart');
  37065. var largeDataIndices = data.getLayout('largeDataIndices');
  37066. var barWidth = data.getLayout('barWidth');
  37067. var backgroundModel = seriesModel.getModel('backgroundStyle');
  37068. var drawBackground = seriesModel.get('showBackground', true);
  37069. if (drawBackground) {
  37070. var points = data.getLayout('largeBackgroundPoints');
  37071. var backgroundStartPoint = [];
  37072. backgroundStartPoint[1 - baseDimIdx] = data.getLayout('backgroundStart');
  37073. var bgEl = new LargePath({
  37074. shape: {points: points},
  37075. incremental: !!incremental,
  37076. __startPoint: backgroundStartPoint,
  37077. __baseDimIdx: baseDimIdx,
  37078. __largeDataIndices: largeDataIndices,
  37079. __barWidth: barWidth,
  37080. silent: true,
  37081. z2: 0
  37082. });
  37083. setLargeBackgroundStyle(bgEl, backgroundModel, data);
  37084. group.add(bgEl);
  37085. }
  37086. var el = new LargePath({
  37087. shape: {points: data.getLayout('largePoints')},
  37088. incremental: !!incremental,
  37089. __startPoint: startPoint,
  37090. __baseDimIdx: baseDimIdx,
  37091. __largeDataIndices: largeDataIndices,
  37092. __barWidth: barWidth
  37093. });
  37094. group.add(el);
  37095. setLargeStyle(el, seriesModel, data);
  37096. // Enable tooltip and user mouse/touch event handlers.
  37097. el.seriesIndex = seriesModel.seriesIndex;
  37098. if (!seriesModel.get('silent')) {
  37099. el.on('mousedown', largePathUpdateDataIndex);
  37100. el.on('mousemove', largePathUpdateDataIndex);
  37101. }
  37102. }
  37103. // Use throttle to avoid frequently traverse to find dataIndex.
  37104. var largePathUpdateDataIndex = throttle(function (event) {
  37105. var largePath = this;
  37106. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  37107. largePath.dataIndex = dataIndex >= 0 ? dataIndex : null;
  37108. }, 30, false);
  37109. function largePathFindDataIndex(largePath, x, y) {
  37110. var baseDimIdx = largePath.__baseDimIdx;
  37111. var valueDimIdx = 1 - baseDimIdx;
  37112. var points = largePath.shape.points;
  37113. var largeDataIndices = largePath.__largeDataIndices;
  37114. var barWidthHalf = Math.abs(largePath.__barWidth / 2);
  37115. var startValueVal = largePath.__startPoint[valueDimIdx];
  37116. _eventPos[0] = x;
  37117. _eventPos[1] = y;
  37118. var pointerBaseVal = _eventPos[baseDimIdx];
  37119. var pointerValueVal = _eventPos[1 - baseDimIdx];
  37120. var baseLowerBound = pointerBaseVal - barWidthHalf;
  37121. var baseUpperBound = pointerBaseVal + barWidthHalf;
  37122. for (var i = 0, len = points.length / 2; i < len; i++) {
  37123. var ii = i * 2;
  37124. var barBaseVal = points[ii + baseDimIdx];
  37125. var barValueVal = points[ii + valueDimIdx];
  37126. if (
  37127. barBaseVal >= baseLowerBound && barBaseVal <= baseUpperBound
  37128. && (
  37129. startValueVal <= barValueVal
  37130. ? (pointerValueVal >= startValueVal && pointerValueVal <= barValueVal)
  37131. : (pointerValueVal >= barValueVal && pointerValueVal <= startValueVal)
  37132. )
  37133. ) {
  37134. return largeDataIndices[i];
  37135. }
  37136. }
  37137. return -1;
  37138. }
  37139. function setLargeStyle(el, seriesModel, data) {
  37140. var borderColor = data.getVisual('borderColor') || data.getVisual('color');
  37141. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle(['color', 'borderColor']);
  37142. el.useStyle(itemStyle);
  37143. el.style.fill = null;
  37144. el.style.stroke = borderColor;
  37145. el.style.lineWidth = data.getLayout('barWidth');
  37146. }
  37147. function setLargeBackgroundStyle(el, backgroundModel, data) {
  37148. var borderColor = backgroundModel.get('borderColor') || backgroundModel.get('color');
  37149. var itemStyle = backgroundModel.getItemStyle(['color', 'borderColor']);
  37150. el.useStyle(itemStyle);
  37151. el.style.fill = null;
  37152. el.style.stroke = borderColor;
  37153. el.style.lineWidth = data.getLayout('barWidth');
  37154. }
  37155. function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
  37156. var coordLayout;
  37157. var isPolar = coord.type === 'polar';
  37158. if (isPolar) {
  37159. coordLayout = coord.getArea();
  37160. }
  37161. else {
  37162. coordLayout = coord.grid.getRect();
  37163. }
  37164. if (isPolar) {
  37165. return {
  37166. cx: coordLayout.cx,
  37167. cy: coordLayout.cy,
  37168. r0: isHorizontalOrRadial ? coordLayout.r0 : layout.r0,
  37169. r: isHorizontalOrRadial ? coordLayout.r : layout.r,
  37170. startAngle: isHorizontalOrRadial ? layout.startAngle : 0,
  37171. endAngle: isHorizontalOrRadial ? layout.endAngle : Math.PI * 2
  37172. };
  37173. }
  37174. else {
  37175. return {
  37176. x: isHorizontalOrRadial ? layout.x : coordLayout.x,
  37177. y: isHorizontalOrRadial ? coordLayout.y : layout.y,
  37178. width: isHorizontalOrRadial ? layout.width : coordLayout.width,
  37179. height: isHorizontalOrRadial ? coordLayout.height : layout.height
  37180. };
  37181. }
  37182. }
  37183. function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
  37184. var ElementClz = coord.type === 'polar' ? Sector : Rect;
  37185. return new ElementClz({
  37186. shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
  37187. silent: true,
  37188. z2: 0
  37189. });
  37190. }
  37191. /*
  37192. * Licensed to the Apache Software Foundation (ASF) under one
  37193. * or more contributor license agreements. See the NOTICE file
  37194. * distributed with this work for additional information
  37195. * regarding copyright ownership. The ASF licenses this file
  37196. * to you under the Apache License, Version 2.0 (the
  37197. * "License"); you may not use this file except in compliance
  37198. * with the License. You may obtain a copy of the License at
  37199. *
  37200. * http://www.apache.org/licenses/LICENSE-2.0
  37201. *
  37202. * Unless required by applicable law or agreed to in writing,
  37203. * software distributed under the License is distributed on an
  37204. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37205. * KIND, either express or implied. See the License for the
  37206. * specific language governing permissions and limitations
  37207. * under the License.
  37208. */
  37209. // In case developer forget to include grid component
  37210. registerLayout(PRIORITY.VISUAL.LAYOUT, curry(layout, 'bar'));
  37211. // Use higher prority to avoid to be blocked by other overall layout, which do not
  37212. // only exist in this module, but probably also exist in other modules, like `barPolar`.
  37213. registerLayout(PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, largeLayout);
  37214. registerVisual({
  37215. seriesType: 'bar',
  37216. reset: function (seriesModel) {
  37217. // Visual coding for legend
  37218. seriesModel.getData().setVisual('legendSymbol', 'roundRect');
  37219. }
  37220. });
  37221. /*
  37222. * Licensed to the Apache Software Foundation (ASF) under one
  37223. * or more contributor license agreements. See the NOTICE file
  37224. * distributed with this work for additional information
  37225. * regarding copyright ownership. The ASF licenses this file
  37226. * to you under the Apache License, Version 2.0 (the
  37227. * "License"); you may not use this file except in compliance
  37228. * with the License. You may obtain a copy of the License at
  37229. *
  37230. * http://www.apache.org/licenses/LICENSE-2.0
  37231. *
  37232. * Unless required by applicable law or agreed to in writing,
  37233. * software distributed under the License is distributed on an
  37234. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37235. * KIND, either express or implied. See the License for the
  37236. * specific language governing permissions and limitations
  37237. * under the License.
  37238. */
  37239. /**
  37240. * [Usage]:
  37241. * (1)
  37242. * createListSimply(seriesModel, ['value']);
  37243. * (2)
  37244. * createListSimply(seriesModel, {
  37245. * coordDimensions: ['value'],
  37246. * dimensionsCount: 5
  37247. * });
  37248. *
  37249. * @param {module:echarts/model/Series} seriesModel
  37250. * @param {Object|Array.<string|Object>} opt opt or coordDimensions
  37251. * The options in opt, see `echarts/data/helper/createDimensions`
  37252. * @param {Array.<string>} [nameList]
  37253. * @return {module:echarts/data/List}
  37254. */
  37255. var createListSimply = function (seriesModel, opt, nameList) {
  37256. opt = isArray(opt) && {coordDimensions: opt} || extend({}, opt);
  37257. var source = seriesModel.getSource();
  37258. var dimensionsInfo = createDimensions(source, opt);
  37259. var list = new List(dimensionsInfo, seriesModel);
  37260. list.initData(source, nameList);
  37261. return list;
  37262. };
  37263. /*
  37264. * Licensed to the Apache Software Foundation (ASF) under one
  37265. * or more contributor license agreements. See the NOTICE file
  37266. * distributed with this work for additional information
  37267. * regarding copyright ownership. The ASF licenses this file
  37268. * to you under the Apache License, Version 2.0 (the
  37269. * "License"); you may not use this file except in compliance
  37270. * with the License. You may obtain a copy of the License at
  37271. *
  37272. * http://www.apache.org/licenses/LICENSE-2.0
  37273. *
  37274. * Unless required by applicable law or agreed to in writing,
  37275. * software distributed under the License is distributed on an
  37276. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37277. * KIND, either express or implied. See the License for the
  37278. * specific language governing permissions and limitations
  37279. * under the License.
  37280. */
  37281. /**
  37282. * Data selectable mixin for chart series.
  37283. * To eanble data select, option of series must have `selectedMode`.
  37284. * And each data item will use `selected` to toggle itself selected status
  37285. */
  37286. var dataSelectableMixin = {
  37287. /**
  37288. * @param {Array.<Object>} targetList [{name, value, selected}, ...]
  37289. * If targetList is an array, it should like [{name: ..., value: ...}, ...].
  37290. * If targetList is a "List", it must have coordDim: 'value' dimension and name.
  37291. */
  37292. updateSelectedMap: function (targetList) {
  37293. this._targetList = isArray(targetList) ? targetList.slice() : [];
  37294. this._selectTargetMap = reduce(targetList || [], function (targetMap, target) {
  37295. targetMap.set(target.name, target);
  37296. return targetMap;
  37297. }, createHashMap());
  37298. },
  37299. /**
  37300. * Either name or id should be passed as input here.
  37301. * If both of them are defined, id is used.
  37302. *
  37303. * @param {string|undefined} name name of data
  37304. * @param {number|undefined} id dataIndex of data
  37305. */
  37306. // PENGING If selectedMode is null ?
  37307. select: function (name, id) {
  37308. var target = id != null
  37309. ? this._targetList[id]
  37310. : this._selectTargetMap.get(name);
  37311. var selectedMode = this.get('selectedMode');
  37312. if (selectedMode === 'single') {
  37313. this._selectTargetMap.each(function (target) {
  37314. target.selected = false;
  37315. });
  37316. }
  37317. target && (target.selected = true);
  37318. },
  37319. /**
  37320. * Either name or id should be passed as input here.
  37321. * If both of them are defined, id is used.
  37322. *
  37323. * @param {string|undefined} name name of data
  37324. * @param {number|undefined} id dataIndex of data
  37325. */
  37326. unSelect: function (name, id) {
  37327. var target = id != null
  37328. ? this._targetList[id]
  37329. : this._selectTargetMap.get(name);
  37330. // var selectedMode = this.get('selectedMode');
  37331. // selectedMode !== 'single' && target && (target.selected = false);
  37332. target && (target.selected = false);
  37333. },
  37334. /**
  37335. * Either name or id should be passed as input here.
  37336. * If both of them are defined, id is used.
  37337. *
  37338. * @param {string|undefined} name name of data
  37339. * @param {number|undefined} id dataIndex of data
  37340. */
  37341. toggleSelected: function (name, id) {
  37342. var target = id != null
  37343. ? this._targetList[id]
  37344. : this._selectTargetMap.get(name);
  37345. if (target != null) {
  37346. this[target.selected ? 'unSelect' : 'select'](name, id);
  37347. return target.selected;
  37348. }
  37349. },
  37350. /**
  37351. * Either name or id should be passed as input here.
  37352. * If both of them are defined, id is used.
  37353. *
  37354. * @param {string|undefined} name name of data
  37355. * @param {number|undefined} id dataIndex of data
  37356. */
  37357. isSelected: function (name, id) {
  37358. var target = id != null
  37359. ? this._targetList[id]
  37360. : this._selectTargetMap.get(name);
  37361. return target && target.selected;
  37362. }
  37363. };
  37364. /*
  37365. * Licensed to the Apache Software Foundation (ASF) under one
  37366. * or more contributor license agreements. See the NOTICE file
  37367. * distributed with this work for additional information
  37368. * regarding copyright ownership. The ASF licenses this file
  37369. * to you under the Apache License, Version 2.0 (the
  37370. * "License"); you may not use this file except in compliance
  37371. * with the License. You may obtain a copy of the License at
  37372. *
  37373. * http://www.apache.org/licenses/LICENSE-2.0
  37374. *
  37375. * Unless required by applicable law or agreed to in writing,
  37376. * software distributed under the License is distributed on an
  37377. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37378. * KIND, either express or implied. See the License for the
  37379. * specific language governing permissions and limitations
  37380. * under the License.
  37381. */
  37382. /**
  37383. * LegendVisualProvider is an bridge that pick encoded color from data and
  37384. * provide to the legend component.
  37385. * @param {Function} getDataWithEncodedVisual Function to get data after filtered. It stores all the encoding info
  37386. * @param {Function} getRawData Function to get raw data before filtered.
  37387. */
  37388. function LegendVisualProvider(getDataWithEncodedVisual, getRawData) {
  37389. this.getAllNames = function () {
  37390. var rawData = getRawData();
  37391. // We find the name from the raw data. In case it's filtered by the legend component.
  37392. // Normally, the name can be found in rawData, but can't be found in filtered data will display as gray.
  37393. return rawData.mapArray(rawData.getName);
  37394. };
  37395. this.containName = function (name) {
  37396. var rawData = getRawData();
  37397. return rawData.indexOfName(name) >= 0;
  37398. };
  37399. this.indexOfName = function (name) {
  37400. // Only get data when necessary.
  37401. // Because LegendVisualProvider constructor may be new in the stage that data is not prepared yet.
  37402. // Invoking Series#getData immediately will throw an error.
  37403. var dataWithEncodedVisual = getDataWithEncodedVisual();
  37404. return dataWithEncodedVisual.indexOfName(name);
  37405. };
  37406. this.getItemVisual = function (dataIndex, key) {
  37407. // Get encoded visual properties from final filtered data.
  37408. var dataWithEncodedVisual = getDataWithEncodedVisual();
  37409. return dataWithEncodedVisual.getItemVisual(dataIndex, key);
  37410. };
  37411. }
  37412. /*
  37413. * Licensed to the Apache Software Foundation (ASF) under one
  37414. * or more contributor license agreements. See the NOTICE file
  37415. * distributed with this work for additional information
  37416. * regarding copyright ownership. The ASF licenses this file
  37417. * to you under the Apache License, Version 2.0 (the
  37418. * "License"); you may not use this file except in compliance
  37419. * with the License. You may obtain a copy of the License at
  37420. *
  37421. * http://www.apache.org/licenses/LICENSE-2.0
  37422. *
  37423. * Unless required by applicable law or agreed to in writing,
  37424. * software distributed under the License is distributed on an
  37425. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37426. * KIND, either express or implied. See the License for the
  37427. * specific language governing permissions and limitations
  37428. * under the License.
  37429. */
  37430. var PieSeries = extendSeriesModel({
  37431. type: 'series.pie',
  37432. // Overwrite
  37433. init: function (option) {
  37434. PieSeries.superApply(this, 'init', arguments);
  37435. // Enable legend selection for each data item
  37436. // Use a function instead of direct access because data reference may changed
  37437. this.legendVisualProvider = new LegendVisualProvider(
  37438. bind(this.getData, this), bind(this.getRawData, this)
  37439. );
  37440. this.updateSelectedMap(this._createSelectableList());
  37441. this._defaultLabelLine(option);
  37442. },
  37443. // Overwrite
  37444. mergeOption: function (newOption) {
  37445. PieSeries.superCall(this, 'mergeOption', newOption);
  37446. this.updateSelectedMap(this._createSelectableList());
  37447. },
  37448. getInitialData: function (option, ecModel) {
  37449. return createListSimply(this, {
  37450. coordDimensions: ['value'],
  37451. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  37452. });
  37453. },
  37454. _createSelectableList: function () {
  37455. var data = this.getRawData();
  37456. var valueDim = data.mapDimension('value');
  37457. var targetList = [];
  37458. for (var i = 0, len = data.count(); i < len; i++) {
  37459. targetList.push({
  37460. name: data.getName(i),
  37461. value: data.get(valueDim, i),
  37462. selected: retrieveRawAttr(data, i, 'selected')
  37463. });
  37464. }
  37465. return targetList;
  37466. },
  37467. // Overwrite
  37468. getDataParams: function (dataIndex) {
  37469. var data = this.getData();
  37470. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  37471. // FIXME toFixed?
  37472. var valueList = [];
  37473. data.each(data.mapDimension('value'), function (value) {
  37474. valueList.push(value);
  37475. });
  37476. params.percent = getPercentWithPrecision(
  37477. valueList,
  37478. dataIndex,
  37479. data.hostModel.get('percentPrecision')
  37480. );
  37481. params.$vars.push('percent');
  37482. return params;
  37483. },
  37484. _defaultLabelLine: function (option) {
  37485. // Extend labelLine emphasis
  37486. defaultEmphasis(option, 'labelLine', ['show']);
  37487. var labelLineNormalOpt = option.labelLine;
  37488. var labelLineEmphasisOpt = option.emphasis.labelLine;
  37489. // Not show label line if `label.normal.show = false`
  37490. labelLineNormalOpt.show = labelLineNormalOpt.show
  37491. && option.label.show;
  37492. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  37493. && option.emphasis.label.show;
  37494. },
  37495. defaultOption: {
  37496. zlevel: 0,
  37497. z: 2,
  37498. legendHoverLink: true,
  37499. hoverAnimation: true,
  37500. // 默认全局居中
  37501. center: ['50%', '50%'],
  37502. radius: [0, '75%'],
  37503. // 默认顺时针
  37504. clockwise: true,
  37505. startAngle: 90,
  37506. // 最小角度改为0
  37507. minAngle: 0,
  37508. // If the angle of a sector less than `minShowLabelAngle`,
  37509. // the label will not be displayed.
  37510. minShowLabelAngle: 0,
  37511. // 选中时扇区偏移量
  37512. selectedOffset: 10,
  37513. // 高亮扇区偏移量
  37514. hoverOffset: 10,
  37515. // If use strategy to avoid label overlapping
  37516. avoidLabelOverlap: true,
  37517. // 选择模式,默认关闭,可选single,multiple
  37518. // selectedMode: false,
  37519. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  37520. // roseType: null,
  37521. percentPrecision: 2,
  37522. // If still show when all data zero.
  37523. stillShowZeroSum: true,
  37524. // cursor: null,
  37525. left: 0,
  37526. top: 0,
  37527. right: 0,
  37528. bottom: 0,
  37529. width: null,
  37530. height: null,
  37531. label: {
  37532. // If rotate around circle
  37533. rotate: false,
  37534. show: true,
  37535. // 'outer', 'inside', 'center'
  37536. position: 'outer',
  37537. // 'none', 'labelLine', 'edge'. Works only when position is 'outer'
  37538. alignTo: 'none',
  37539. // Closest distance between label and chart edge.
  37540. // Works only position is 'outer' and alignTo is 'edge'.
  37541. margin: '25%',
  37542. // Works only position is 'outer' and alignTo is not 'edge'.
  37543. bleedMargin: 10,
  37544. // Distance between text and label line.
  37545. distanceToLabelLine: 5
  37546. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  37547. // 默认使用全局文本样式,详见TEXTSTYLE
  37548. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  37549. },
  37550. // Enabled when label.normal.position is 'outer'
  37551. labelLine: {
  37552. show: true,
  37553. // 引导线两段中的第一段长度
  37554. length: 15,
  37555. // 引导线两段中的第二段长度
  37556. length2: 15,
  37557. smooth: false,
  37558. lineStyle: {
  37559. // color: 各异,
  37560. width: 1,
  37561. type: 'solid'
  37562. }
  37563. },
  37564. itemStyle: {
  37565. borderWidth: 1
  37566. },
  37567. // Animation type. Valid values: expansion, scale
  37568. animationType: 'expansion',
  37569. // Animation type when update. Valid values: transition, expansion
  37570. animationTypeUpdate: 'transition',
  37571. animationEasing: 'cubicOut'
  37572. }
  37573. });
  37574. mixin(PieSeries, dataSelectableMixin);
  37575. /*
  37576. * Licensed to the Apache Software Foundation (ASF) under one
  37577. * or more contributor license agreements. See the NOTICE file
  37578. * distributed with this work for additional information
  37579. * regarding copyright ownership. The ASF licenses this file
  37580. * to you under the Apache License, Version 2.0 (the
  37581. * "License"); you may not use this file except in compliance
  37582. * with the License. You may obtain a copy of the License at
  37583. *
  37584. * http://www.apache.org/licenses/LICENSE-2.0
  37585. *
  37586. * Unless required by applicable law or agreed to in writing,
  37587. * software distributed under the License is distributed on an
  37588. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37589. * KIND, either express or implied. See the License for the
  37590. * specific language governing permissions and limitations
  37591. * under the License.
  37592. */
  37593. /**
  37594. * @param {module:echarts/model/Series} seriesModel
  37595. * @param {boolean} hasAnimation
  37596. * @inner
  37597. */
  37598. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  37599. var data = seriesModel.getData();
  37600. var dataIndex = this.dataIndex;
  37601. var name = data.getName(dataIndex);
  37602. var selectedOffset = seriesModel.get('selectedOffset');
  37603. api.dispatchAction({
  37604. type: 'pieToggleSelect',
  37605. from: uid,
  37606. name: name,
  37607. seriesId: seriesModel.id
  37608. });
  37609. data.each(function (idx) {
  37610. toggleItemSelected(
  37611. data.getItemGraphicEl(idx),
  37612. data.getItemLayout(idx),
  37613. seriesModel.isSelected(data.getName(idx)),
  37614. selectedOffset,
  37615. hasAnimation
  37616. );
  37617. });
  37618. }
  37619. /**
  37620. * @param {module:zrender/graphic/Sector} el
  37621. * @param {Object} layout
  37622. * @param {boolean} isSelected
  37623. * @param {number} selectedOffset
  37624. * @param {boolean} hasAnimation
  37625. * @inner
  37626. */
  37627. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  37628. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  37629. var dx = Math.cos(midAngle);
  37630. var dy = Math.sin(midAngle);
  37631. var offset = isSelected ? selectedOffset : 0;
  37632. var position = [dx * offset, dy * offset];
  37633. hasAnimation
  37634. // animateTo will stop revious animation like update transition
  37635. ? el.animate()
  37636. .when(200, {
  37637. position: position
  37638. })
  37639. .start('bounceOut')
  37640. : el.attr('position', position);
  37641. }
  37642. /**
  37643. * Piece of pie including Sector, Label, LabelLine
  37644. * @constructor
  37645. * @extends {module:zrender/graphic/Group}
  37646. */
  37647. function PiePiece(data, idx) {
  37648. Group.call(this);
  37649. var sector = new Sector({
  37650. z2: 2
  37651. });
  37652. var polyline = new Polyline();
  37653. var text = new Text();
  37654. this.add(sector);
  37655. this.add(polyline);
  37656. this.add(text);
  37657. this.updateData(data, idx, true);
  37658. }
  37659. var piePieceProto = PiePiece.prototype;
  37660. piePieceProto.updateData = function (data, idx, firstCreate) {
  37661. var sector = this.childAt(0);
  37662. var labelLine = this.childAt(1);
  37663. var labelText = this.childAt(2);
  37664. var seriesModel = data.hostModel;
  37665. var itemModel = data.getItemModel(idx);
  37666. var layout = data.getItemLayout(idx);
  37667. var sectorShape = extend({}, layout);
  37668. sectorShape.label = null;
  37669. var animationTypeUpdate = seriesModel.getShallow('animationTypeUpdate');
  37670. if (firstCreate) {
  37671. sector.setShape(sectorShape);
  37672. var animationType = seriesModel.getShallow('animationType');
  37673. if (animationType === 'scale') {
  37674. sector.shape.r = layout.r0;
  37675. initProps(sector, {
  37676. shape: {
  37677. r: layout.r
  37678. }
  37679. }, seriesModel, idx);
  37680. }
  37681. // Expansion
  37682. else {
  37683. sector.shape.endAngle = layout.startAngle;
  37684. updateProps(sector, {
  37685. shape: {
  37686. endAngle: layout.endAngle
  37687. }
  37688. }, seriesModel, idx);
  37689. }
  37690. }
  37691. else {
  37692. if (animationTypeUpdate === 'expansion') {
  37693. // Sectors are set to be target shape and an overlaying clipPath is used for animation
  37694. sector.setShape(sectorShape);
  37695. }
  37696. else {
  37697. // Transition animation from the old shape
  37698. updateProps(sector, {
  37699. shape: sectorShape
  37700. }, seriesModel, idx);
  37701. }
  37702. }
  37703. // Update common style
  37704. var visualColor = data.getItemVisual(idx, 'color');
  37705. sector.useStyle(
  37706. defaults(
  37707. {
  37708. lineJoin: 'bevel',
  37709. fill: visualColor
  37710. },
  37711. itemModel.getModel('itemStyle').getItemStyle()
  37712. )
  37713. );
  37714. sector.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  37715. var cursorStyle = itemModel.getShallow('cursor');
  37716. cursorStyle && sector.attr('cursor', cursorStyle);
  37717. // Toggle selected
  37718. toggleItemSelected(
  37719. this,
  37720. data.getItemLayout(idx),
  37721. seriesModel.isSelected(data.getName(idx)),
  37722. seriesModel.get('selectedOffset'),
  37723. seriesModel.get('animation')
  37724. );
  37725. // Label and text animation should be applied only for transition type animation when update
  37726. var withAnimation = !firstCreate && animationTypeUpdate === 'transition';
  37727. this._updateLabel(data, idx, withAnimation);
  37728. this.highDownOnUpdate = !seriesModel.get('silent')
  37729. ? function (fromState, toState) {
  37730. var hasAnimation = seriesModel.isAnimationEnabled() && itemModel.get('hoverAnimation');
  37731. if (toState === 'emphasis') {
  37732. labelLine.ignore = labelLine.hoverIgnore;
  37733. labelText.ignore = labelText.hoverIgnore;
  37734. // Sector may has animation of updating data. Force to move to the last frame
  37735. // Or it may stopped on the wrong shape
  37736. if (hasAnimation) {
  37737. sector.stopAnimation(true);
  37738. sector.animateTo({
  37739. shape: {
  37740. r: layout.r + seriesModel.get('hoverOffset')
  37741. }
  37742. }, 300, 'elasticOut');
  37743. }
  37744. }
  37745. else {
  37746. labelLine.ignore = labelLine.normalIgnore;
  37747. labelText.ignore = labelText.normalIgnore;
  37748. if (hasAnimation) {
  37749. sector.stopAnimation(true);
  37750. sector.animateTo({
  37751. shape: {
  37752. r: layout.r
  37753. }
  37754. }, 300, 'elasticOut');
  37755. }
  37756. }
  37757. }
  37758. : null;
  37759. setHoverStyle(this);
  37760. };
  37761. piePieceProto._updateLabel = function (data, idx, withAnimation) {
  37762. var labelLine = this.childAt(1);
  37763. var labelText = this.childAt(2);
  37764. var seriesModel = data.hostModel;
  37765. var itemModel = data.getItemModel(idx);
  37766. var layout = data.getItemLayout(idx);
  37767. var labelLayout = layout.label;
  37768. var visualColor = data.getItemVisual(idx, 'color');
  37769. if (!labelLayout || isNaN(labelLayout.x) || isNaN(labelLayout.y)) {
  37770. labelText.ignore = labelText.normalIgnore = labelText.hoverIgnore =
  37771. labelLine.ignore = labelLine.normalIgnore = labelLine.hoverIgnore = true;
  37772. return;
  37773. }
  37774. var targetLineShape = {
  37775. points: labelLayout.linePoints || [
  37776. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  37777. ]
  37778. };
  37779. var targetTextStyle = {
  37780. x: labelLayout.x,
  37781. y: labelLayout.y
  37782. };
  37783. if (withAnimation) {
  37784. updateProps(labelLine, {
  37785. shape: targetLineShape
  37786. }, seriesModel, idx);
  37787. updateProps(labelText, {
  37788. style: targetTextStyle
  37789. }, seriesModel, idx);
  37790. }
  37791. else {
  37792. labelLine.attr({
  37793. shape: targetLineShape
  37794. });
  37795. labelText.attr({
  37796. style: targetTextStyle
  37797. });
  37798. }
  37799. labelText.attr({
  37800. rotation: labelLayout.rotation,
  37801. origin: [labelLayout.x, labelLayout.y],
  37802. z2: 10
  37803. });
  37804. var labelModel = itemModel.getModel('label');
  37805. var labelHoverModel = itemModel.getModel('emphasis.label');
  37806. var labelLineModel = itemModel.getModel('labelLine');
  37807. var labelLineHoverModel = itemModel.getModel('emphasis.labelLine');
  37808. var visualColor = data.getItemVisual(idx, 'color');
  37809. setLabelStyle(
  37810. labelText.style, labelText.hoverStyle = {}, labelModel, labelHoverModel,
  37811. {
  37812. labelFetcher: data.hostModel,
  37813. labelDataIndex: idx,
  37814. defaultText: labelLayout.text,
  37815. autoColor: visualColor,
  37816. useInsideStyle: !!labelLayout.inside
  37817. },
  37818. {
  37819. textAlign: labelLayout.textAlign,
  37820. textVerticalAlign: labelLayout.verticalAlign,
  37821. opacity: data.getItemVisual(idx, 'opacity')
  37822. }
  37823. );
  37824. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  37825. labelText.hoverIgnore = !labelHoverModel.get('show');
  37826. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  37827. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  37828. // Default use item visual color
  37829. labelLine.setStyle({
  37830. stroke: visualColor,
  37831. opacity: data.getItemVisual(idx, 'opacity')
  37832. });
  37833. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  37834. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  37835. var smooth = labelLineModel.get('smooth');
  37836. if (smooth && smooth === true) {
  37837. smooth = 0.4;
  37838. }
  37839. labelLine.setShape({
  37840. smooth: smooth
  37841. });
  37842. };
  37843. inherits(PiePiece, Group);
  37844. // Pie view
  37845. var PieView = Chart.extend({
  37846. type: 'pie',
  37847. init: function () {
  37848. var sectorGroup = new Group();
  37849. this._sectorGroup = sectorGroup;
  37850. },
  37851. render: function (seriesModel, ecModel, api, payload) {
  37852. if (payload && (payload.from === this.uid)) {
  37853. return;
  37854. }
  37855. var data = seriesModel.getData();
  37856. var oldData = this._data;
  37857. var group = this.group;
  37858. var hasAnimation = ecModel.get('animation');
  37859. var isFirstRender = !oldData;
  37860. var animationType = seriesModel.get('animationType');
  37861. var animationTypeUpdate = seriesModel.get('animationTypeUpdate');
  37862. var onSectorClick = curry(
  37863. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  37864. );
  37865. var selectedMode = seriesModel.get('selectedMode');
  37866. data.diff(oldData)
  37867. .add(function (idx) {
  37868. var piePiece = new PiePiece(data, idx);
  37869. // Default expansion animation
  37870. if (isFirstRender && animationType !== 'scale') {
  37871. piePiece.eachChild(function (child) {
  37872. child.stopAnimation(true);
  37873. });
  37874. }
  37875. selectedMode && piePiece.on('click', onSectorClick);
  37876. data.setItemGraphicEl(idx, piePiece);
  37877. group.add(piePiece);
  37878. })
  37879. .update(function (newIdx, oldIdx) {
  37880. var piePiece = oldData.getItemGraphicEl(oldIdx);
  37881. if (!isFirstRender && animationTypeUpdate !== 'transition') {
  37882. piePiece.eachChild(function (child) {
  37883. child.stopAnimation(true);
  37884. });
  37885. }
  37886. piePiece.updateData(data, newIdx);
  37887. piePiece.off('click');
  37888. selectedMode && piePiece.on('click', onSectorClick);
  37889. group.add(piePiece);
  37890. data.setItemGraphicEl(newIdx, piePiece);
  37891. })
  37892. .remove(function (idx) {
  37893. var piePiece = oldData.getItemGraphicEl(idx);
  37894. group.remove(piePiece);
  37895. })
  37896. .execute();
  37897. if (
  37898. hasAnimation && data.count() > 0
  37899. && (isFirstRender ? animationType !== 'scale' : animationTypeUpdate !== 'transition')
  37900. ) {
  37901. var shape = data.getItemLayout(0);
  37902. for (var s = 1; isNaN(shape.startAngle) && s < data.count(); ++s) {
  37903. shape = data.getItemLayout(s);
  37904. }
  37905. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  37906. var removeClipPath = bind(group.removeClipPath, group);
  37907. group.setClipPath(this._createClipPath(
  37908. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel, isFirstRender
  37909. ));
  37910. }
  37911. else {
  37912. // clipPath is used in first-time animation, so remove it when otherwise. See: #8994
  37913. group.removeClipPath();
  37914. }
  37915. this._data = data;
  37916. },
  37917. dispose: function () {},
  37918. _createClipPath: function (
  37919. cx, cy, r, startAngle, clockwise, cb, seriesModel, isFirstRender
  37920. ) {
  37921. var clipPath = new Sector({
  37922. shape: {
  37923. cx: cx,
  37924. cy: cy,
  37925. r0: 0,
  37926. r: r,
  37927. startAngle: startAngle,
  37928. endAngle: startAngle,
  37929. clockwise: clockwise
  37930. }
  37931. });
  37932. var initOrUpdate = isFirstRender ? initProps : updateProps;
  37933. initOrUpdate(clipPath, {
  37934. shape: {
  37935. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  37936. }
  37937. }, seriesModel, cb);
  37938. return clipPath;
  37939. },
  37940. /**
  37941. * @implement
  37942. */
  37943. containPoint: function (point, seriesModel) {
  37944. var data = seriesModel.getData();
  37945. var itemLayout = data.getItemLayout(0);
  37946. if (itemLayout) {
  37947. var dx = point[0] - itemLayout.cx;
  37948. var dy = point[1] - itemLayout.cy;
  37949. var radius = Math.sqrt(dx * dx + dy * dy);
  37950. return radius <= itemLayout.r && radius >= itemLayout.r0;
  37951. }
  37952. }
  37953. });
  37954. /*
  37955. * Licensed to the Apache Software Foundation (ASF) under one
  37956. * or more contributor license agreements. See the NOTICE file
  37957. * distributed with this work for additional information
  37958. * regarding copyright ownership. The ASF licenses this file
  37959. * to you under the Apache License, Version 2.0 (the
  37960. * "License"); you may not use this file except in compliance
  37961. * with the License. You may obtain a copy of the License at
  37962. *
  37963. * http://www.apache.org/licenses/LICENSE-2.0
  37964. *
  37965. * Unless required by applicable law or agreed to in writing,
  37966. * software distributed under the License is distributed on an
  37967. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37968. * KIND, either express or implied. See the License for the
  37969. * specific language governing permissions and limitations
  37970. * under the License.
  37971. */
  37972. var createDataSelectAction = function (seriesType, actionInfos) {
  37973. each$1(actionInfos, function (actionInfo) {
  37974. actionInfo.update = 'updateView';
  37975. /**
  37976. * @payload
  37977. * @property {string} seriesName
  37978. * @property {string} name
  37979. */
  37980. registerAction(actionInfo, function (payload, ecModel) {
  37981. var selected = {};
  37982. ecModel.eachComponent(
  37983. {mainType: 'series', subType: seriesType, query: payload},
  37984. function (seriesModel) {
  37985. if (seriesModel[actionInfo.method]) {
  37986. seriesModel[actionInfo.method](
  37987. payload.name,
  37988. payload.dataIndex
  37989. );
  37990. }
  37991. var data = seriesModel.getData();
  37992. // Create selected map
  37993. data.each(function (idx) {
  37994. var name = data.getName(idx);
  37995. selected[name] = seriesModel.isSelected(name)
  37996. || false;
  37997. });
  37998. }
  37999. );
  38000. return {
  38001. name: payload.name,
  38002. selected: selected,
  38003. seriesId: payload.seriesId
  38004. };
  38005. });
  38006. });
  38007. };
  38008. /*
  38009. * Licensed to the Apache Software Foundation (ASF) under one
  38010. * or more contributor license agreements. See the NOTICE file
  38011. * distributed with this work for additional information
  38012. * regarding copyright ownership. The ASF licenses this file
  38013. * to you under the Apache License, Version 2.0 (the
  38014. * "License"); you may not use this file except in compliance
  38015. * with the License. You may obtain a copy of the License at
  38016. *
  38017. * http://www.apache.org/licenses/LICENSE-2.0
  38018. *
  38019. * Unless required by applicable law or agreed to in writing,
  38020. * software distributed under the License is distributed on an
  38021. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38022. * KIND, either express or implied. See the License for the
  38023. * specific language governing permissions and limitations
  38024. * under the License.
  38025. */
  38026. // Pick color from palette for each data item.
  38027. // Applicable for charts that require applying color palette
  38028. // in data level (like pie, funnel, chord).
  38029. var dataColor = function (seriesType) {
  38030. return {
  38031. getTargetSeries: function (ecModel) {
  38032. // Pie and funnel may use diferrent scope
  38033. var paletteScope = {};
  38034. var seiresModelMap = createHashMap();
  38035. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  38036. seriesModel.__paletteScope = paletteScope;
  38037. seiresModelMap.set(seriesModel.uid, seriesModel);
  38038. });
  38039. return seiresModelMap;
  38040. },
  38041. reset: function (seriesModel, ecModel) {
  38042. var dataAll = seriesModel.getRawData();
  38043. var idxMap = {};
  38044. var data = seriesModel.getData();
  38045. data.each(function (idx) {
  38046. var rawIdx = data.getRawIndex(idx);
  38047. idxMap[rawIdx] = idx;
  38048. });
  38049. dataAll.each(function (rawIdx) {
  38050. var filteredIdx = idxMap[rawIdx];
  38051. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  38052. var singleDataColor = filteredIdx != null
  38053. && data.getItemVisual(filteredIdx, 'color', true);
  38054. var singleDataBorderColor = filteredIdx != null
  38055. && data.getItemVisual(filteredIdx, 'borderColor', true);
  38056. var itemModel;
  38057. if (!singleDataColor || !singleDataBorderColor) {
  38058. // FIXME Performance
  38059. itemModel = dataAll.getItemModel(rawIdx);
  38060. }
  38061. if (!singleDataColor) {
  38062. var color = itemModel.get('itemStyle.color')
  38063. || seriesModel.getColorFromPalette(
  38064. dataAll.getName(rawIdx) || (rawIdx + ''), seriesModel.__paletteScope,
  38065. dataAll.count()
  38066. );
  38067. // Data is not filtered
  38068. if (filteredIdx != null) {
  38069. data.setItemVisual(filteredIdx, 'color', color);
  38070. }
  38071. }
  38072. if (!singleDataBorderColor) {
  38073. var borderColor = itemModel.get('itemStyle.borderColor');
  38074. // Data is not filtered
  38075. if (filteredIdx != null) {
  38076. data.setItemVisual(filteredIdx, 'borderColor', borderColor);
  38077. }
  38078. }
  38079. });
  38080. }
  38081. };
  38082. };
  38083. /*
  38084. * Licensed to the Apache Software Foundation (ASF) under one
  38085. * or more contributor license agreements. See the NOTICE file
  38086. * distributed with this work for additional information
  38087. * regarding copyright ownership. The ASF licenses this file
  38088. * to you under the Apache License, Version 2.0 (the
  38089. * "License"); you may not use this file except in compliance
  38090. * with the License. You may obtain a copy of the License at
  38091. *
  38092. * http://www.apache.org/licenses/LICENSE-2.0
  38093. *
  38094. * Unless required by applicable law or agreed to in writing,
  38095. * software distributed under the License is distributed on an
  38096. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38097. * KIND, either express or implied. See the License for the
  38098. * specific language governing permissions and limitations
  38099. * under the License.
  38100. */
  38101. // FIXME emphasis label position is not same with normal label position
  38102. var RADIAN$1 = Math.PI / 180;
  38103. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight, viewLeft, viewTop, farthestX) {
  38104. list.sort(function (a, b) {
  38105. return a.y - b.y;
  38106. });
  38107. function shiftDown(start, end, delta, dir) {
  38108. for (var j = start; j < end; j++) {
  38109. if (list[j].y + delta > viewTop + viewHeight) {
  38110. break;
  38111. }
  38112. list[j].y += delta;
  38113. if (j > start
  38114. && j + 1 < end
  38115. && list[j + 1].y > list[j].y + list[j].height
  38116. ) {
  38117. shiftUp(j, delta / 2);
  38118. return;
  38119. }
  38120. }
  38121. shiftUp(end - 1, delta / 2);
  38122. }
  38123. function shiftUp(end, delta) {
  38124. for (var j = end; j >= 0; j--) {
  38125. if (list[j].y - delta < viewTop) {
  38126. break;
  38127. }
  38128. list[j].y -= delta;
  38129. if (j > 0
  38130. && list[j].y > list[j - 1].y + list[j - 1].height
  38131. ) {
  38132. break;
  38133. }
  38134. }
  38135. }
  38136. function changeX(list, isDownList, cx, cy, r, dir) {
  38137. var lastDeltaX = dir > 0
  38138. ? isDownList // right-side
  38139. ? Number.MAX_VALUE // down
  38140. : 0 // up
  38141. : isDownList // left-side
  38142. ? Number.MAX_VALUE // down
  38143. : 0; // up
  38144. for (var i = 0, l = list.length; i < l; i++) {
  38145. if (list[i].labelAlignTo !== 'none') {
  38146. continue;
  38147. }
  38148. var deltaY = Math.abs(list[i].y - cy);
  38149. var length = list[i].len;
  38150. var length2 = list[i].len2;
  38151. var deltaX = (deltaY < r + length)
  38152. ? Math.sqrt(
  38153. (r + length + length2) * (r + length + length2)
  38154. - deltaY * deltaY
  38155. )
  38156. : Math.abs(list[i].x - cx);
  38157. if (isDownList && deltaX >= lastDeltaX) {
  38158. // right-down, left-down
  38159. deltaX = lastDeltaX - 10;
  38160. }
  38161. if (!isDownList && deltaX <= lastDeltaX) {
  38162. // right-up, left-up
  38163. deltaX = lastDeltaX + 10;
  38164. }
  38165. list[i].x = cx + deltaX * dir;
  38166. lastDeltaX = deltaX;
  38167. }
  38168. }
  38169. var lastY = 0;
  38170. var delta;
  38171. var len = list.length;
  38172. var upList = [];
  38173. var downList = [];
  38174. for (var i = 0; i < len; i++) {
  38175. if (list[i].position === 'outer' && list[i].labelAlignTo === 'labelLine') {
  38176. var dx = list[i].x - farthestX;
  38177. list[i].linePoints[1][0] += dx;
  38178. list[i].x = farthestX;
  38179. }
  38180. delta = list[i].y - lastY;
  38181. if (delta < 0) {
  38182. shiftDown(i, len, -delta, dir);
  38183. }
  38184. lastY = list[i].y + list[i].height;
  38185. }
  38186. if (viewHeight - lastY < 0) {
  38187. shiftUp(len - 1, lastY - viewHeight);
  38188. }
  38189. for (var i = 0; i < len; i++) {
  38190. if (list[i].y >= cy) {
  38191. downList.push(list[i]);
  38192. }
  38193. else {
  38194. upList.push(list[i]);
  38195. }
  38196. }
  38197. changeX(upList, false, cx, cy, r, dir);
  38198. changeX(downList, true, cx, cy, r, dir);
  38199. }
  38200. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop) {
  38201. var leftList = [];
  38202. var rightList = [];
  38203. var leftmostX = Number.MAX_VALUE;
  38204. var rightmostX = -Number.MAX_VALUE;
  38205. for (var i = 0; i < labelLayoutList.length; i++) {
  38206. if (isPositionCenter(labelLayoutList[i])) {
  38207. continue;
  38208. }
  38209. if (labelLayoutList[i].x < cx) {
  38210. leftmostX = Math.min(leftmostX, labelLayoutList[i].x);
  38211. leftList.push(labelLayoutList[i]);
  38212. }
  38213. else {
  38214. rightmostX = Math.max(rightmostX, labelLayoutList[i].x);
  38215. rightList.push(labelLayoutList[i]);
  38216. }
  38217. }
  38218. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight, viewLeft, viewTop, rightmostX);
  38219. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight, viewLeft, viewTop, leftmostX);
  38220. for (var i = 0; i < labelLayoutList.length; i++) {
  38221. var layout = labelLayoutList[i];
  38222. if (isPositionCenter(layout)) {
  38223. continue;
  38224. }
  38225. var linePoints = layout.linePoints;
  38226. if (linePoints) {
  38227. var isAlignToEdge = layout.labelAlignTo === 'edge';
  38228. var realTextWidth = layout.textRect.width;
  38229. var targetTextWidth;
  38230. if (isAlignToEdge) {
  38231. if (layout.x < cx) {
  38232. targetTextWidth = linePoints[2][0] - layout.labelDistance
  38233. - viewLeft - layout.labelMargin;
  38234. }
  38235. else {
  38236. targetTextWidth = viewLeft + viewWidth - layout.labelMargin
  38237. - linePoints[2][0] - layout.labelDistance;
  38238. }
  38239. }
  38240. else {
  38241. if (layout.x < cx) {
  38242. targetTextWidth = layout.x - viewLeft - layout.bleedMargin;
  38243. }
  38244. else {
  38245. targetTextWidth = viewLeft + viewWidth - layout.x - layout.bleedMargin;
  38246. }
  38247. }
  38248. if (targetTextWidth < layout.textRect.width) {
  38249. layout.text = truncateText(layout.text, targetTextWidth, layout.font);
  38250. if (layout.labelAlignTo === 'edge') {
  38251. realTextWidth = getWidth(layout.text, layout.font);
  38252. }
  38253. }
  38254. var dist = linePoints[1][0] - linePoints[2][0];
  38255. if (isAlignToEdge) {
  38256. if (layout.x < cx) {
  38257. linePoints[2][0] = viewLeft + layout.labelMargin + realTextWidth + layout.labelDistance;
  38258. }
  38259. else {
  38260. linePoints[2][0] = viewLeft + viewWidth - layout.labelMargin
  38261. - realTextWidth - layout.labelDistance;
  38262. }
  38263. }
  38264. else {
  38265. if (layout.x < cx) {
  38266. linePoints[2][0] = layout.x + layout.labelDistance;
  38267. }
  38268. else {
  38269. linePoints[2][0] = layout.x - layout.labelDistance;
  38270. }
  38271. linePoints[1][0] = linePoints[2][0] + dist;
  38272. }
  38273. linePoints[1][1] = linePoints[2][1] = layout.y;
  38274. }
  38275. }
  38276. }
  38277. function isPositionCenter(layout) {
  38278. // Not change x for center label
  38279. return layout.position === 'center';
  38280. }
  38281. var labelLayout = function (seriesModel, r, viewWidth, viewHeight, viewLeft, viewTop) {
  38282. var data = seriesModel.getData();
  38283. var labelLayoutList = [];
  38284. var cx;
  38285. var cy;
  38286. var hasLabelRotate = false;
  38287. var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN$1;
  38288. data.each(function (idx) {
  38289. var layout = data.getItemLayout(idx);
  38290. var itemModel = data.getItemModel(idx);
  38291. var labelModel = itemModel.getModel('label');
  38292. // Use position in normal or emphasis
  38293. var labelPosition = labelModel.get('position') || itemModel.get('emphasis.label.position');
  38294. var labelDistance = labelModel.get('distanceToLabelLine');
  38295. var labelAlignTo = labelModel.get('alignTo');
  38296. var labelMargin = parsePercent$1(labelModel.get('margin'), viewWidth);
  38297. var bleedMargin = labelModel.get('bleedMargin');
  38298. var font = labelModel.getFont();
  38299. var labelLineModel = itemModel.getModel('labelLine');
  38300. var labelLineLen = labelLineModel.get('length');
  38301. labelLineLen = parsePercent$1(labelLineLen, viewWidth);
  38302. var labelLineLen2 = labelLineModel.get('length2');
  38303. labelLineLen2 = parsePercent$1(labelLineLen2, viewWidth);
  38304. if (layout.angle < minShowLabelRadian) {
  38305. return;
  38306. }
  38307. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  38308. var dx = Math.cos(midAngle);
  38309. var dy = Math.sin(midAngle);
  38310. var textX;
  38311. var textY;
  38312. var linePoints;
  38313. var textAlign;
  38314. cx = layout.cx;
  38315. cy = layout.cy;
  38316. var text = seriesModel.getFormattedLabel(idx, 'normal')
  38317. || data.getName(idx);
  38318. var textRect = getBoundingRect(
  38319. text, font, textAlign, 'top'
  38320. );
  38321. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  38322. if (labelPosition === 'center') {
  38323. textX = layout.cx;
  38324. textY = layout.cy;
  38325. textAlign = 'center';
  38326. }
  38327. else {
  38328. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  38329. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  38330. textX = x1 + dx * 3;
  38331. textY = y1 + dy * 3;
  38332. if (!isLabelInside) {
  38333. // For roseType
  38334. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  38335. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  38336. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  38337. var y3 = y2;
  38338. if (labelAlignTo === 'edge') {
  38339. // Adjust textX because text align of edge is opposite
  38340. textX = dx < 0
  38341. ? viewLeft + labelMargin
  38342. : viewLeft + viewWidth - labelMargin;
  38343. }
  38344. else {
  38345. textX = x3 + (dx < 0 ? -labelDistance : labelDistance);
  38346. }
  38347. textY = y3;
  38348. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  38349. }
  38350. textAlign = isLabelInside
  38351. ? 'center'
  38352. : (labelAlignTo === 'edge'
  38353. ? (dx > 0 ? 'right' : 'left')
  38354. : (dx > 0 ? 'left' : 'right'));
  38355. }
  38356. var labelRotate;
  38357. var rotate = labelModel.get('rotate');
  38358. if (typeof rotate === 'number') {
  38359. labelRotate = rotate * (Math.PI / 180);
  38360. }
  38361. else {
  38362. labelRotate = rotate
  38363. ? (dx < 0 ? -midAngle + Math.PI : -midAngle)
  38364. : 0;
  38365. }
  38366. hasLabelRotate = !!labelRotate;
  38367. layout.label = {
  38368. x: textX,
  38369. y: textY,
  38370. position: labelPosition,
  38371. height: textRect.height,
  38372. len: labelLineLen,
  38373. len2: labelLineLen2,
  38374. linePoints: linePoints,
  38375. textAlign: textAlign,
  38376. verticalAlign: 'middle',
  38377. rotation: labelRotate,
  38378. inside: isLabelInside,
  38379. labelDistance: labelDistance,
  38380. labelAlignTo: labelAlignTo,
  38381. labelMargin: labelMargin,
  38382. bleedMargin: bleedMargin,
  38383. textRect: textRect,
  38384. text: text,
  38385. font: font
  38386. };
  38387. // Not layout the inside label
  38388. if (!isLabelInside) {
  38389. labelLayoutList.push(layout.label);
  38390. }
  38391. });
  38392. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  38393. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop);
  38394. }
  38395. };
  38396. /*
  38397. * Licensed to the Apache Software Foundation (ASF) under one
  38398. * or more contributor license agreements. See the NOTICE file
  38399. * distributed with this work for additional information
  38400. * regarding copyright ownership. The ASF licenses this file
  38401. * to you under the Apache License, Version 2.0 (the
  38402. * "License"); you may not use this file except in compliance
  38403. * with the License. You may obtain a copy of the License at
  38404. *
  38405. * http://www.apache.org/licenses/LICENSE-2.0
  38406. *
  38407. * Unless required by applicable law or agreed to in writing,
  38408. * software distributed under the License is distributed on an
  38409. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38410. * KIND, either express or implied. See the License for the
  38411. * specific language governing permissions and limitations
  38412. * under the License.
  38413. */
  38414. var PI2$4 = Math.PI * 2;
  38415. var RADIAN = Math.PI / 180;
  38416. function getViewRect(seriesModel, api) {
  38417. return getLayoutRect(
  38418. seriesModel.getBoxLayoutParams(), {
  38419. width: api.getWidth(),
  38420. height: api.getHeight()
  38421. }
  38422. );
  38423. }
  38424. var pieLayout = function (seriesType, ecModel, api, payload) {
  38425. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  38426. var data = seriesModel.getData();
  38427. var valueDim = data.mapDimension('value');
  38428. var viewRect = getViewRect(seriesModel, api);
  38429. var center = seriesModel.get('center');
  38430. var radius = seriesModel.get('radius');
  38431. if (!isArray(radius)) {
  38432. radius = [0, radius];
  38433. }
  38434. if (!isArray(center)) {
  38435. center = [center, center];
  38436. }
  38437. var width = parsePercent$1(viewRect.width, api.getWidth());
  38438. var height = parsePercent$1(viewRect.height, api.getHeight());
  38439. var size = Math.min(width, height);
  38440. var cx = parsePercent$1(center[0], width) + viewRect.x;
  38441. var cy = parsePercent$1(center[1], height) + viewRect.y;
  38442. var r0 = parsePercent$1(radius[0], size / 2);
  38443. var r = parsePercent$1(radius[1], size / 2);
  38444. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  38445. var minAngle = seriesModel.get('minAngle') * RADIAN;
  38446. var validDataCount = 0;
  38447. data.each(valueDim, function (value) {
  38448. !isNaN(value) && validDataCount++;
  38449. });
  38450. var sum = data.getSum(valueDim);
  38451. // Sum may be 0
  38452. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  38453. var clockwise = seriesModel.get('clockwise');
  38454. var roseType = seriesModel.get('roseType');
  38455. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  38456. // [0...max]
  38457. var extent = data.getDataExtent(valueDim);
  38458. extent[0] = 0;
  38459. // In the case some sector angle is smaller than minAngle
  38460. var restAngle = PI2$4;
  38461. var valueSumLargerThanMinAngle = 0;
  38462. var currentAngle = startAngle;
  38463. var dir = clockwise ? 1 : -1;
  38464. data.each(valueDim, function (value, idx) {
  38465. var angle;
  38466. if (isNaN(value)) {
  38467. data.setItemLayout(idx, {
  38468. angle: NaN,
  38469. startAngle: NaN,
  38470. endAngle: NaN,
  38471. clockwise: clockwise,
  38472. cx: cx,
  38473. cy: cy,
  38474. r0: r0,
  38475. r: roseType
  38476. ? NaN
  38477. : r,
  38478. viewRect: viewRect
  38479. });
  38480. return;
  38481. }
  38482. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  38483. if (roseType !== 'area') {
  38484. angle = (sum === 0 && stillShowZeroSum)
  38485. ? unitRadian : (value * unitRadian);
  38486. }
  38487. else {
  38488. angle = PI2$4 / validDataCount;
  38489. }
  38490. if (angle < minAngle) {
  38491. angle = minAngle;
  38492. restAngle -= minAngle;
  38493. }
  38494. else {
  38495. valueSumLargerThanMinAngle += value;
  38496. }
  38497. var endAngle = currentAngle + dir * angle;
  38498. data.setItemLayout(idx, {
  38499. angle: angle,
  38500. startAngle: currentAngle,
  38501. endAngle: endAngle,
  38502. clockwise: clockwise,
  38503. cx: cx,
  38504. cy: cy,
  38505. r0: r0,
  38506. r: roseType
  38507. ? linearMap(value, extent, [r0, r])
  38508. : r,
  38509. viewRect: viewRect
  38510. });
  38511. currentAngle = endAngle;
  38512. });
  38513. // Some sector is constrained by minAngle
  38514. // Rest sectors needs recalculate angle
  38515. if (restAngle < PI2$4 && validDataCount) {
  38516. // Average the angle if rest angle is not enough after all angles is
  38517. // Constrained by minAngle
  38518. if (restAngle <= 1e-3) {
  38519. var angle = PI2$4 / validDataCount;
  38520. data.each(valueDim, function (value, idx) {
  38521. if (!isNaN(value)) {
  38522. var layout = data.getItemLayout(idx);
  38523. layout.angle = angle;
  38524. layout.startAngle = startAngle + dir * idx * angle;
  38525. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  38526. }
  38527. });
  38528. }
  38529. else {
  38530. unitRadian = restAngle / valueSumLargerThanMinAngle;
  38531. currentAngle = startAngle;
  38532. data.each(valueDim, function (value, idx) {
  38533. if (!isNaN(value)) {
  38534. var layout = data.getItemLayout(idx);
  38535. var angle = layout.angle === minAngle
  38536. ? minAngle : value * unitRadian;
  38537. layout.startAngle = currentAngle;
  38538. layout.endAngle = currentAngle + dir * angle;
  38539. currentAngle += dir * angle;
  38540. }
  38541. });
  38542. }
  38543. }
  38544. labelLayout(seriesModel, r, viewRect.width, viewRect.height, viewRect.x, viewRect.y);
  38545. });
  38546. };
  38547. /*
  38548. * Licensed to the Apache Software Foundation (ASF) under one
  38549. * or more contributor license agreements. See the NOTICE file
  38550. * distributed with this work for additional information
  38551. * regarding copyright ownership. The ASF licenses this file
  38552. * to you under the Apache License, Version 2.0 (the
  38553. * "License"); you may not use this file except in compliance
  38554. * with the License. You may obtain a copy of the License at
  38555. *
  38556. * http://www.apache.org/licenses/LICENSE-2.0
  38557. *
  38558. * Unless required by applicable law or agreed to in writing,
  38559. * software distributed under the License is distributed on an
  38560. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38561. * KIND, either express or implied. See the License for the
  38562. * specific language governing permissions and limitations
  38563. * under the License.
  38564. */
  38565. var dataFilter = function (seriesType) {
  38566. return {
  38567. seriesType: seriesType,
  38568. reset: function (seriesModel, ecModel) {
  38569. var legendModels = ecModel.findComponents({
  38570. mainType: 'legend'
  38571. });
  38572. if (!legendModels || !legendModels.length) {
  38573. return;
  38574. }
  38575. var data = seriesModel.getData();
  38576. data.filterSelf(function (idx) {
  38577. var name = data.getName(idx);
  38578. // If in any legend component the status is not selected.
  38579. for (var i = 0; i < legendModels.length; i++) {
  38580. if (!legendModels[i].isSelected(name)) {
  38581. return false;
  38582. }
  38583. }
  38584. return true;
  38585. });
  38586. }
  38587. };
  38588. };
  38589. /*
  38590. * Licensed to the Apache Software Foundation (ASF) under one
  38591. * or more contributor license agreements. See the NOTICE file
  38592. * distributed with this work for additional information
  38593. * regarding copyright ownership. The ASF licenses this file
  38594. * to you under the Apache License, Version 2.0 (the
  38595. * "License"); you may not use this file except in compliance
  38596. * with the License. You may obtain a copy of the License at
  38597. *
  38598. * http://www.apache.org/licenses/LICENSE-2.0
  38599. *
  38600. * Unless required by applicable law or agreed to in writing,
  38601. * software distributed under the License is distributed on an
  38602. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38603. * KIND, either express or implied. See the License for the
  38604. * specific language governing permissions and limitations
  38605. * under the License.
  38606. */
  38607. createDataSelectAction('pie', [{
  38608. type: 'pieToggleSelect',
  38609. event: 'pieselectchanged',
  38610. method: 'toggleSelected'
  38611. }, {
  38612. type: 'pieSelect',
  38613. event: 'pieselected',
  38614. method: 'select'
  38615. }, {
  38616. type: 'pieUnSelect',
  38617. event: 'pieunselected',
  38618. method: 'unSelect'
  38619. }]);
  38620. registerVisual(dataColor('pie'));
  38621. registerLayout(curry(pieLayout, 'pie'));
  38622. registerProcessor(dataFilter('pie'));
  38623. /*
  38624. * Licensed to the Apache Software Foundation (ASF) under one
  38625. * or more contributor license agreements. See the NOTICE file
  38626. * distributed with this work for additional information
  38627. * regarding copyright ownership. The ASF licenses this file
  38628. * to you under the Apache License, Version 2.0 (the
  38629. * "License"); you may not use this file except in compliance
  38630. * with the License. You may obtain a copy of the License at
  38631. *
  38632. * http://www.apache.org/licenses/LICENSE-2.0
  38633. *
  38634. * Unless required by applicable law or agreed to in writing,
  38635. * software distributed under the License is distributed on an
  38636. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38637. * KIND, either express or implied. See the License for the
  38638. * specific language governing permissions and limitations
  38639. * under the License.
  38640. */
  38641. exports.version = version;
  38642. exports.dependencies = dependencies;
  38643. exports.PRIORITY = PRIORITY;
  38644. exports.init = init;
  38645. exports.connect = connect;
  38646. exports.disConnect = disConnect;
  38647. exports.disconnect = disconnect;
  38648. exports.dispose = dispose;
  38649. exports.getInstanceByDom = getInstanceByDom;
  38650. exports.getInstanceById = getInstanceById;
  38651. exports.registerTheme = registerTheme;
  38652. exports.registerPreprocessor = registerPreprocessor;
  38653. exports.registerProcessor = registerProcessor;
  38654. exports.registerPostUpdate = registerPostUpdate;
  38655. exports.registerAction = registerAction;
  38656. exports.registerCoordinateSystem = registerCoordinateSystem;
  38657. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  38658. exports.registerLayout = registerLayout;
  38659. exports.registerVisual = registerVisual;
  38660. exports.registerLoading = registerLoading;
  38661. exports.extendComponentModel = extendComponentModel;
  38662. exports.extendComponentView = extendComponentView;
  38663. exports.extendSeriesModel = extendSeriesModel;
  38664. exports.extendChartView = extendChartView;
  38665. exports.setCanvasCreator = setCanvasCreator;
  38666. exports.registerMap = registerMap;
  38667. exports.getMap = getMap;
  38668. exports.dataTool = dataTool;
  38669. })));