echarts.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : factory(global.echarts = {});
  3. })(this, function (exports) {
  4. 'use strict';
  5. /*
  6. * Licensed to the Apache Software Foundation (ASF) under one
  7. * or more contributor license agreements. See the NOTICE file
  8. * distributed with this work for additional information
  9. * regarding copyright ownership. The ASF licenses this file
  10. * to you under the Apache License, Version 2.0 (the
  11. * "License"); you may not use this file except in compliance
  12. * with the License. You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing,
  17. * software distributed under the License is distributed on an
  18. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. * KIND, either express or implied. See the License for the
  20. * specific language governing permissions and limitations
  21. * under the License.
  22. */
  23. // (1) The code `if (__DEV__) ...` can be removed by build tool.
  24. // (2) If intend to use `__DEV__`, this module should be imported. Use a global
  25. // variable `__DEV__` may cause that miss the declaration (see #6535), or the
  26. // declaration is behind of the using position (for example in `Model.extent`,
  27. // And tools like rollup can not analysis the dependency if not import).
  28. var dev; // In browser
  29. if (typeof window !== 'undefined') {
  30. dev = window.__DEV__;
  31. } // In node
  32. else if (typeof global !== 'undefined') {
  33. dev = global.__DEV__;
  34. }
  35. if (typeof dev === 'undefined') {
  36. dev = true;
  37. }
  38. var __DEV__ = dev;
  39. /**
  40. * zrender: 生成唯一id
  41. *
  42. * @author errorrik (errorrik@gmail.com)
  43. */
  44. var idStart = 0x0907;
  45. var guid = function () {
  46. return idStart++;
  47. };
  48. /**
  49. * echarts设备环境识别
  50. *
  51. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  52. * @author firede[firede@firede.us]
  53. * @desc thanks zepto.
  54. */
  55. /* global wx */
  56. var env = {};
  57. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  58. // In Weixin Application
  59. env = {
  60. browser: {},
  61. os: {},
  62. node: false,
  63. wxa: true,
  64. // Weixin Application
  65. canvasSupported: true,
  66. svgSupported: false,
  67. touchEventsSupported: true,
  68. domSupported: false
  69. };
  70. } else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  71. // In worker
  72. env = {
  73. browser: {},
  74. os: {},
  75. node: false,
  76. worker: true,
  77. canvasSupported: true,
  78. domSupported: false
  79. };
  80. } else if (typeof navigator === 'undefined') {
  81. // In node
  82. env = {
  83. browser: {},
  84. os: {},
  85. node: true,
  86. worker: false,
  87. // Assume canvas is supported
  88. canvasSupported: true,
  89. svgSupported: true,
  90. domSupported: false
  91. };
  92. } else {
  93. env = detect(navigator.userAgent);
  94. }
  95. var env$1 = env; // Zepto.js
  96. // (c) 2010-2013 Thomas Fuchs
  97. // Zepto.js may be freely distributed under the MIT license.
  98. function detect(ua) {
  99. var os = {};
  100. var browser = {}; // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  101. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  102. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  103. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  104. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  105. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  106. // var touchpad = webos && ua.match(/TouchPad/);
  107. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  108. // var silk = ua.match(/Silk\/([\d._]+)/);
  109. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  110. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  111. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  112. // var playbook = ua.match(/PlayBook/);
  113. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  114. var firefox = ua.match(/Firefox\/([\d.]+)/); // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  115. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  116. var ie = ua.match(/MSIE\s([\d.]+)/) // IE 11 Trident/7.0; rv:11.0
  117. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  118. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  119. var weChat = /micromessenger/i.test(ua); // Todo: clean this up with a better OS/browser seperation:
  120. // - discern (more) between multiple browsers on android
  121. // - decide if kindle fire in silk mode is android or not
  122. // - Firefox on Android doesn't specify the Android version
  123. // - possibly devide in os, device and browser hashes
  124. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  125. // if (android) os.android = true, os.version = android[2];
  126. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  127. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  128. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  129. // if (webos) os.webos = true, os.version = webos[2];
  130. // if (touchpad) os.touchpad = true;
  131. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  132. // if (bb10) os.bb10 = true, os.version = bb10[2];
  133. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  134. // if (playbook) browser.playbook = true;
  135. // if (kindle) os.kindle = true, os.version = kindle[1];
  136. // if (silk) browser.silk = true, browser.version = silk[1];
  137. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  138. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  139. if (firefox) {
  140. browser.firefox = true;
  141. browser.version = firefox[1];
  142. } // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  143. // if (webview) browser.webview = true;
  144. if (ie) {
  145. browser.ie = true;
  146. browser.version = ie[1];
  147. }
  148. if (edge) {
  149. browser.edge = true;
  150. browser.version = edge[1];
  151. } // It is difficult to detect WeChat in Win Phone precisely, because ua can
  152. // not be set on win phone. So we do not consider Win Phone.
  153. if (weChat) {
  154. browser.weChat = true;
  155. } // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  156. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  157. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  158. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  159. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  160. return {
  161. browser: browser,
  162. os: os,
  163. node: false,
  164. // 原生canvas支持,改极端点了
  165. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  166. canvasSupported: !!document.createElement('canvas').getContext,
  167. svgSupported: typeof SVGRect !== 'undefined',
  168. // works on most browsers
  169. // IE10/11 does not support touch event, and MS Edge supports them but not by
  170. // default, so we dont check navigator.maxTouchPoints for them here.
  171. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  172. // <http://caniuse.com/#search=pointer%20event>.
  173. pointerEventsSupported: // (1) Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  174. // events currently. So we dont use that on other browsers unless tested sufficiently.
  175. // For example, in iOS 13 Mobile Chromium 78, if the touching behavior starts page
  176. // scroll, the `pointermove` event can not be fired any more. That will break some
  177. // features like "pan horizontally to move something and pan vertically to page scroll".
  178. // The horizontal pan probably be interrupted by the casually triggered page scroll.
  179. // (2) Although IE 10 supports pointer event, it use old style and is different from the
  180. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  181. 'onpointerdown' in window && (browser.edge || browser.ie && browser.version >= 11),
  182. // passiveSupported: detectPassiveSupport()
  183. domSupported: typeof document !== 'undefined'
  184. };
  185. } // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
  186. // function detectPassiveSupport() {
  187. // // Test via a getter in the options object to see if the passive property is accessed
  188. // var supportsPassive = false;
  189. // try {
  190. // var opts = Object.defineProperty({}, 'passive', {
  191. // get: function() {
  192. // supportsPassive = true;
  193. // }
  194. // });
  195. // window.addEventListener('testPassive', function() {}, opts);
  196. // } catch (e) {
  197. // }
  198. // return supportsPassive;
  199. // }
  200. /**
  201. * @module zrender/core/util
  202. */
  203. // 用于处理merge时无法遍历Date等对象的问题
  204. var BUILTIN_OBJECT = {
  205. '[object Function]': 1,
  206. '[object RegExp]': 1,
  207. '[object Date]': 1,
  208. '[object Error]': 1,
  209. '[object CanvasGradient]': 1,
  210. '[object CanvasPattern]': 1,
  211. // For node-canvas
  212. '[object Image]': 1,
  213. '[object Canvas]': 1
  214. };
  215. var TYPED_ARRAY = {
  216. '[object Int8Array]': 1,
  217. '[object Uint8Array]': 1,
  218. '[object Uint8ClampedArray]': 1,
  219. '[object Int16Array]': 1,
  220. '[object Uint16Array]': 1,
  221. '[object Int32Array]': 1,
  222. '[object Uint32Array]': 1,
  223. '[object Float32Array]': 1,
  224. '[object Float64Array]': 1
  225. };
  226. var objToString = Object.prototype.toString;
  227. var arrayProto = Array.prototype;
  228. var nativeForEach = arrayProto.forEach;
  229. var nativeFilter = arrayProto.filter;
  230. var nativeSlice = arrayProto.slice;
  231. var nativeMap = arrayProto.map;
  232. var nativeReduce = arrayProto.reduce; // Avoid assign to an exported variable, for transforming to cjs.
  233. var methods = {};
  234. function $override(name, fn) {
  235. // Clear ctx instance for different environment
  236. if (name === 'createCanvas') {
  237. _ctx = null;
  238. }
  239. methods[name] = fn;
  240. }
  241. /**
  242. * Those data types can be cloned:
  243. * Plain object, Array, TypedArray, number, string, null, undefined.
  244. * Those data types will be assgined using the orginal data:
  245. * BUILTIN_OBJECT
  246. * Instance of user defined class will be cloned to a plain object, without
  247. * properties in prototype.
  248. * Other data types is not supported (not sure what will happen).
  249. *
  250. * Caution: do not support clone Date, for performance consideration.
  251. * (There might be a large number of date in `series.data`).
  252. * So date should not be modified in and out of echarts.
  253. *
  254. * @param {*} source
  255. * @return {*} new
  256. */
  257. function clone(source) {
  258. if (source == null || typeof source !== 'object') {
  259. return source;
  260. }
  261. var result = source;
  262. var typeStr = objToString.call(source);
  263. if (typeStr === '[object Array]') {
  264. if (!isPrimitive(source)) {
  265. result = [];
  266. for (var i = 0, len = source.length; i < len; i++) {
  267. result[i] = clone(source[i]);
  268. }
  269. }
  270. } else if (TYPED_ARRAY[typeStr]) {
  271. if (!isPrimitive(source)) {
  272. var Ctor = source.constructor;
  273. if (source.constructor.from) {
  274. result = Ctor.from(source);
  275. } else {
  276. result = new Ctor(source.length);
  277. for (var i = 0, len = source.length; i < len; i++) {
  278. result[i] = clone(source[i]);
  279. }
  280. }
  281. }
  282. } else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  283. result = {};
  284. for (var key in source) {
  285. if (source.hasOwnProperty(key)) {
  286. result[key] = clone(source[key]);
  287. }
  288. }
  289. }
  290. return result;
  291. }
  292. /**
  293. * @memberOf module:zrender/core/util
  294. * @param {*} target
  295. * @param {*} source
  296. * @param {boolean} [overwrite=false]
  297. */
  298. function merge(target, source, overwrite) {
  299. // We should escapse that source is string
  300. // and enter for ... in ...
  301. if (!isObject$1(source) || !isObject$1(target)) {
  302. return overwrite ? clone(source) : target;
  303. }
  304. for (var key in source) {
  305. if (source.hasOwnProperty(key)) {
  306. var targetProp = target[key];
  307. var sourceProp = source[key];
  308. if (isObject$1(sourceProp) && isObject$1(targetProp) && !isArray(sourceProp) && !isArray(targetProp) && !isDom(sourceProp) && !isDom(targetProp) && !isBuiltInObject(sourceProp) && !isBuiltInObject(targetProp) && !isPrimitive(sourceProp) && !isPrimitive(targetProp)) {
  309. // 如果需要递归覆盖,就递归调用merge
  310. merge(targetProp, sourceProp, overwrite);
  311. } else if (overwrite || !(key in target)) {
  312. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  313. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  314. target[key] = clone(source[key], true);
  315. }
  316. }
  317. }
  318. return target;
  319. }
  320. /**
  321. * @param {Array} targetAndSources The first item is target, and the rests are source.
  322. * @param {boolean} [overwrite=false]
  323. * @return {*} target
  324. */
  325. function mergeAll(targetAndSources, overwrite) {
  326. var result = targetAndSources[0];
  327. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  328. result = merge(result, targetAndSources[i], overwrite);
  329. }
  330. return result;
  331. }
  332. /**
  333. * @param {*} target
  334. * @param {*} source
  335. * @memberOf module:zrender/core/util
  336. */
  337. function extend(target, source) {
  338. for (var key in source) {
  339. if (source.hasOwnProperty(key)) {
  340. target[key] = source[key];
  341. }
  342. }
  343. return target;
  344. }
  345. /**
  346. * @param {*} target
  347. * @param {*} source
  348. * @param {boolean} [overlay=false]
  349. * @memberOf module:zrender/core/util
  350. */
  351. function defaults(target, source, overlay) {
  352. for (var key in source) {
  353. if (source.hasOwnProperty(key) && (overlay ? source[key] != null : target[key] == null)) {
  354. target[key] = source[key];
  355. }
  356. }
  357. return target;
  358. }
  359. var createCanvas = function () {
  360. return methods.createCanvas();
  361. };
  362. methods.createCanvas = function () {
  363. return document.createElement('canvas');
  364. }; // FIXME
  365. var _ctx;
  366. function getContext() {
  367. if (!_ctx) {
  368. // Use util.createCanvas instead of createCanvas
  369. // because createCanvas may be overwritten in different environment
  370. _ctx = createCanvas().getContext('2d');
  371. }
  372. return _ctx;
  373. }
  374. /**
  375. * 查询数组中元素的index
  376. * @memberOf module:zrender/core/util
  377. */
  378. function indexOf(array, value) {
  379. if (array) {
  380. if (array.indexOf) {
  381. return array.indexOf(value);
  382. }
  383. for (var i = 0, len = array.length; i < len; i++) {
  384. if (array[i] === value) {
  385. return i;
  386. }
  387. }
  388. }
  389. return -1;
  390. }
  391. /**
  392. * 构造类继承关系
  393. *
  394. * @memberOf module:zrender/core/util
  395. * @param {Function} clazz 源类
  396. * @param {Function} baseClazz 基类
  397. */
  398. function inherits(clazz, baseClazz) {
  399. var clazzPrototype = clazz.prototype;
  400. function F() {}
  401. F.prototype = baseClazz.prototype;
  402. clazz.prototype = new F();
  403. for (var prop in clazzPrototype) {
  404. if (clazzPrototype.hasOwnProperty(prop)) {
  405. clazz.prototype[prop] = clazzPrototype[prop];
  406. }
  407. }
  408. clazz.prototype.constructor = clazz;
  409. clazz.superClass = baseClazz;
  410. }
  411. /**
  412. * @memberOf module:zrender/core/util
  413. * @param {Object|Function} target
  414. * @param {Object|Function} sorce
  415. * @param {boolean} overlay
  416. */
  417. function mixin(target, source, overlay) {
  418. target = 'prototype' in target ? target.prototype : target;
  419. source = 'prototype' in source ? source.prototype : source;
  420. defaults(target, source, overlay);
  421. }
  422. /**
  423. * Consider typed array.
  424. * @param {Array|TypedArray} data
  425. */
  426. function isArrayLike(data) {
  427. if (!data) {
  428. return;
  429. }
  430. if (typeof data === 'string') {
  431. return false;
  432. }
  433. return typeof data.length === 'number';
  434. }
  435. /**
  436. * 数组或对象遍历
  437. * @memberOf module:zrender/core/util
  438. * @param {Object|Array} obj
  439. * @param {Function} cb
  440. * @param {*} [context]
  441. */
  442. function each$1(obj, cb, context) {
  443. if (!(obj && cb)) {
  444. return;
  445. }
  446. if (obj.forEach && obj.forEach === nativeForEach) {
  447. obj.forEach(cb, context);
  448. } else if (obj.length === +obj.length) {
  449. for (var i = 0, len = obj.length; i < len; i++) {
  450. cb.call(context, obj[i], i, obj);
  451. }
  452. } else {
  453. for (var key in obj) {
  454. if (obj.hasOwnProperty(key)) {
  455. cb.call(context, obj[key], key, obj);
  456. }
  457. }
  458. }
  459. }
  460. /**
  461. * 数组映射
  462. * @memberOf module:zrender/core/util
  463. * @param {Array} obj
  464. * @param {Function} cb
  465. * @param {*} [context]
  466. * @return {Array}
  467. */
  468. function map(obj, cb, context) {
  469. if (!(obj && cb)) {
  470. return;
  471. }
  472. if (obj.map && obj.map === nativeMap) {
  473. return obj.map(cb, context);
  474. } else {
  475. var result = [];
  476. for (var i = 0, len = obj.length; i < len; i++) {
  477. result.push(cb.call(context, obj[i], i, obj));
  478. }
  479. return result;
  480. }
  481. }
  482. /**
  483. * @memberOf module:zrender/core/util
  484. * @param {Array} obj
  485. * @param {Function} cb
  486. * @param {Object} [memo]
  487. * @param {*} [context]
  488. * @return {Array}
  489. */
  490. function reduce(obj, cb, memo, context) {
  491. if (!(obj && cb)) {
  492. return;
  493. }
  494. if (obj.reduce && obj.reduce === nativeReduce) {
  495. return obj.reduce(cb, memo, context);
  496. } else {
  497. for (var i = 0, len = obj.length; i < len; i++) {
  498. memo = cb.call(context, memo, obj[i], i, obj);
  499. }
  500. return memo;
  501. }
  502. }
  503. /**
  504. * 数组过滤
  505. * @memberOf module:zrender/core/util
  506. * @param {Array} obj
  507. * @param {Function} cb
  508. * @param {*} [context]
  509. * @return {Array}
  510. */
  511. function filter(obj, cb, context) {
  512. if (!(obj && cb)) {
  513. return;
  514. }
  515. if (obj.filter && obj.filter === nativeFilter) {
  516. return obj.filter(cb, context);
  517. } else {
  518. var result = [];
  519. for (var i = 0, len = obj.length; i < len; i++) {
  520. if (cb.call(context, obj[i], i, obj)) {
  521. result.push(obj[i]);
  522. }
  523. }
  524. return result;
  525. }
  526. }
  527. /**
  528. * 数组项查找
  529. * @memberOf module:zrender/core/util
  530. * @param {Array} obj
  531. * @param {Function} cb
  532. * @param {*} [context]
  533. * @return {*}
  534. */
  535. function find(obj, cb, context) {
  536. if (!(obj && cb)) {
  537. return;
  538. }
  539. for (var i = 0, len = obj.length; i < len; i++) {
  540. if (cb.call(context, obj[i], i, obj)) {
  541. return obj[i];
  542. }
  543. }
  544. }
  545. /**
  546. * @memberOf module:zrender/core/util
  547. * @param {Function} func
  548. * @param {*} context
  549. * @return {Function}
  550. */
  551. function bind(func, context) {
  552. var args = nativeSlice.call(arguments, 2);
  553. return function () {
  554. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  555. };
  556. }
  557. /**
  558. * @memberOf module:zrender/core/util
  559. * @param {Function} func
  560. * @return {Function}
  561. */
  562. function curry(func) {
  563. var args = nativeSlice.call(arguments, 1);
  564. return function () {
  565. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  566. };
  567. }
  568. /**
  569. * @memberOf module:zrender/core/util
  570. * @param {*} value
  571. * @return {boolean}
  572. */
  573. function isArray(value) {
  574. return objToString.call(value) === '[object Array]';
  575. }
  576. /**
  577. * @memberOf module:zrender/core/util
  578. * @param {*} value
  579. * @return {boolean}
  580. */
  581. function isFunction$1(value) {
  582. return typeof value === 'function';
  583. }
  584. /**
  585. * @memberOf module:zrender/core/util
  586. * @param {*} value
  587. * @return {boolean}
  588. */
  589. function isString(value) {
  590. return objToString.call(value) === '[object String]';
  591. }
  592. /**
  593. * @memberOf module:zrender/core/util
  594. * @param {*} value
  595. * @return {boolean}
  596. */
  597. function isObject$1(value) {
  598. // Avoid a V8 JIT bug in Chrome 19-20.
  599. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  600. var type = typeof value;
  601. return type === 'function' || !!value && type === 'object';
  602. }
  603. /**
  604. * @memberOf module:zrender/core/util
  605. * @param {*} value
  606. * @return {boolean}
  607. */
  608. function isBuiltInObject(value) {
  609. return !!BUILTIN_OBJECT[objToString.call(value)];
  610. }
  611. /**
  612. * @memberOf module:zrender/core/util
  613. * @param {*} value
  614. * @return {boolean}
  615. */
  616. function isTypedArray(value) {
  617. return !!TYPED_ARRAY[objToString.call(value)];
  618. }
  619. /**
  620. * @memberOf module:zrender/core/util
  621. * @param {*} value
  622. * @return {boolean}
  623. */
  624. function isDom(value) {
  625. return typeof value === 'object' && typeof value.nodeType === 'number' && typeof value.ownerDocument === 'object';
  626. }
  627. /**
  628. * Whether is exactly NaN. Notice isNaN('a') returns true.
  629. * @param {*} value
  630. * @return {boolean}
  631. */
  632. function eqNaN(value) {
  633. /* eslint-disable-next-line no-self-compare */
  634. return value !== value;
  635. }
  636. /**
  637. * If value1 is not null, then return value1, otherwise judget rest of values.
  638. * Low performance.
  639. * @memberOf module:zrender/core/util
  640. * @return {*} Final value
  641. */
  642. function retrieve(values) {
  643. for (var i = 0, len = arguments.length; i < len; i++) {
  644. if (arguments[i] != null) {
  645. return arguments[i];
  646. }
  647. }
  648. }
  649. function retrieve2(value0, value1) {
  650. return value0 != null ? value0 : value1;
  651. }
  652. function retrieve3(value0, value1, value2) {
  653. return value0 != null ? value0 : value1 != null ? value1 : value2;
  654. }
  655. /**
  656. * @memberOf module:zrender/core/util
  657. * @param {Array} arr
  658. * @param {number} startIndex
  659. * @param {number} endIndex
  660. * @return {Array}
  661. */
  662. function slice() {
  663. return Function.call.apply(nativeSlice, arguments);
  664. }
  665. /**
  666. * Normalize css liked array configuration
  667. * e.g.
  668. * 3 => [3, 3, 3, 3]
  669. * [4, 2] => [4, 2, 4, 2]
  670. * [4, 3, 2] => [4, 3, 2, 3]
  671. * @param {number|Array.<number>} val
  672. * @return {Array.<number>}
  673. */
  674. function normalizeCssArray(val) {
  675. if (typeof val === 'number') {
  676. return [val, val, val, val];
  677. }
  678. var len = val.length;
  679. if (len === 2) {
  680. // vertical | horizontal
  681. return [val[0], val[1], val[0], val[1]];
  682. } else if (len === 3) {
  683. // top | horizontal | bottom
  684. return [val[0], val[1], val[2], val[1]];
  685. }
  686. return val;
  687. }
  688. /**
  689. * @memberOf module:zrender/core/util
  690. * @param {boolean} condition
  691. * @param {string} message
  692. */
  693. function assert$1(condition, message) {
  694. if (!condition) {
  695. throw new Error(message);
  696. }
  697. }
  698. /**
  699. * @memberOf module:zrender/core/util
  700. * @param {string} str string to be trimed
  701. * @return {string} trimed string
  702. */
  703. function trim(str) {
  704. if (str == null) {
  705. return null;
  706. } else if (typeof str.trim === 'function') {
  707. return str.trim();
  708. } else {
  709. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  710. }
  711. }
  712. var primitiveKey = '__ec_primitive__';
  713. /**
  714. * Set an object as primitive to be ignored traversing children in clone or merge
  715. */
  716. function setAsPrimitive(obj) {
  717. obj[primitiveKey] = true;
  718. }
  719. function isPrimitive(obj) {
  720. return obj[primitiveKey];
  721. }
  722. /**
  723. * @constructor
  724. * @param {Object} obj Only apply `ownProperty`.
  725. */
  726. function HashMap(obj) {
  727. var isArr = isArray(obj); // Key should not be set on this, otherwise
  728. // methods get/set/... may be overrided.
  729. this.data = {};
  730. var thisMap = this;
  731. obj instanceof HashMap ? obj.each(visit) : obj && each$1(obj, visit);
  732. function visit(value, key) {
  733. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  734. }
  735. }
  736. HashMap.prototype = {
  737. constructor: HashMap,
  738. // Do not provide `has` method to avoid defining what is `has`.
  739. // (We usually treat `null` and `undefined` as the same, different
  740. // from ES6 Map).
  741. get: function (key) {
  742. return this.data.hasOwnProperty(key) ? this.data[key] : null;
  743. },
  744. set: function (key, value) {
  745. // Comparing with invocation chaining, `return value` is more commonly
  746. // used in this case: `var someVal = map.set('a', genVal());`
  747. return this.data[key] = value;
  748. },
  749. // Although util.each can be performed on this hashMap directly, user
  750. // should not use the exposed keys, who are prefixed.
  751. each: function (cb, context) {
  752. context !== void 0 && (cb = bind(cb, context));
  753. /* eslint-disable guard-for-in */
  754. for (var key in this.data) {
  755. this.data.hasOwnProperty(key) && cb(this.data[key], key);
  756. }
  757. /* eslint-enable guard-for-in */
  758. },
  759. // Do not use this method if performance sensitive.
  760. removeKey: function (key) {
  761. delete this.data[key];
  762. }
  763. };
  764. function createHashMap(obj) {
  765. return new HashMap(obj);
  766. }
  767. function concatArray(a, b) {
  768. var newArray = new a.constructor(a.length + b.length);
  769. for (var i = 0; i < a.length; i++) {
  770. newArray[i] = a[i];
  771. }
  772. var offset = a.length;
  773. for (i = 0; i < b.length; i++) {
  774. newArray[i + offset] = b[i];
  775. }
  776. return newArray;
  777. }
  778. function noop() {}
  779. var zrUtil = (Object.freeze || Object)({
  780. $override: $override,
  781. clone: clone,
  782. merge: merge,
  783. mergeAll: mergeAll,
  784. extend: extend,
  785. defaults: defaults,
  786. createCanvas: createCanvas,
  787. getContext: getContext,
  788. indexOf: indexOf,
  789. inherits: inherits,
  790. mixin: mixin,
  791. isArrayLike: isArrayLike,
  792. each: each$1,
  793. map: map,
  794. reduce: reduce,
  795. filter: filter,
  796. find: find,
  797. bind: bind,
  798. curry: curry,
  799. isArray: isArray,
  800. isFunction: isFunction$1,
  801. isString: isString,
  802. isObject: isObject$1,
  803. isBuiltInObject: isBuiltInObject,
  804. isTypedArray: isTypedArray,
  805. isDom: isDom,
  806. eqNaN: eqNaN,
  807. retrieve: retrieve,
  808. retrieve2: retrieve2,
  809. retrieve3: retrieve3,
  810. slice: slice,
  811. normalizeCssArray: normalizeCssArray,
  812. assert: assert$1,
  813. trim: trim,
  814. setAsPrimitive: setAsPrimitive,
  815. isPrimitive: isPrimitive,
  816. createHashMap: createHashMap,
  817. concatArray: concatArray,
  818. noop: noop
  819. });
  820. /* global Float32Array */
  821. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  822. /**
  823. * 创建一个向量
  824. * @param {number} [x=0]
  825. * @param {number} [y=0]
  826. * @return {Vector2}
  827. */
  828. function create(x, y) {
  829. var out = new ArrayCtor(2);
  830. if (x == null) {
  831. x = 0;
  832. }
  833. if (y == null) {
  834. y = 0;
  835. }
  836. out[0] = x;
  837. out[1] = y;
  838. return out;
  839. }
  840. /**
  841. * 复制向量数据
  842. * @param {Vector2} out
  843. * @param {Vector2} v
  844. * @return {Vector2}
  845. */
  846. function copy(out, v) {
  847. out[0] = v[0];
  848. out[1] = v[1];
  849. return out;
  850. }
  851. /**
  852. * 克隆一个向量
  853. * @param {Vector2} v
  854. * @return {Vector2}
  855. */
  856. function clone$1(v) {
  857. var out = new ArrayCtor(2);
  858. out[0] = v[0];
  859. out[1] = v[1];
  860. return out;
  861. }
  862. /**
  863. * 设置向量的两个项
  864. * @param {Vector2} out
  865. * @param {number} a
  866. * @param {number} b
  867. * @return {Vector2} 结果
  868. */
  869. function set(out, a, b) {
  870. out[0] = a;
  871. out[1] = b;
  872. return out;
  873. }
  874. /**
  875. * 向量相加
  876. * @param {Vector2} out
  877. * @param {Vector2} v1
  878. * @param {Vector2} v2
  879. */
  880. function add(out, v1, v2) {
  881. out[0] = v1[0] + v2[0];
  882. out[1] = v1[1] + v2[1];
  883. return out;
  884. }
  885. /**
  886. * 向量缩放后相加
  887. * @param {Vector2} out
  888. * @param {Vector2} v1
  889. * @param {Vector2} v2
  890. * @param {number} a
  891. */
  892. function scaleAndAdd(out, v1, v2, a) {
  893. out[0] = v1[0] + v2[0] * a;
  894. out[1] = v1[1] + v2[1] * a;
  895. return out;
  896. }
  897. /**
  898. * 向量相减
  899. * @param {Vector2} out
  900. * @param {Vector2} v1
  901. * @param {Vector2} v2
  902. */
  903. function sub(out, v1, v2) {
  904. out[0] = v1[0] - v2[0];
  905. out[1] = v1[1] - v2[1];
  906. return out;
  907. }
  908. /**
  909. * 向量长度
  910. * @param {Vector2} v
  911. * @return {number}
  912. */
  913. function len(v) {
  914. return Math.sqrt(lenSquare(v));
  915. }
  916. var length = len; // jshint ignore:line
  917. /**
  918. * 向量长度平方
  919. * @param {Vector2} v
  920. * @return {number}
  921. */
  922. function lenSquare(v) {
  923. return v[0] * v[0] + v[1] * v[1];
  924. }
  925. var lengthSquare = lenSquare;
  926. /**
  927. * 向量乘法
  928. * @param {Vector2} out
  929. * @param {Vector2} v1
  930. * @param {Vector2} v2
  931. */
  932. function mul(out, v1, v2) {
  933. out[0] = v1[0] * v2[0];
  934. out[1] = v1[1] * v2[1];
  935. return out;
  936. }
  937. /**
  938. * 向量除法
  939. * @param {Vector2} out
  940. * @param {Vector2} v1
  941. * @param {Vector2} v2
  942. */
  943. function div(out, v1, v2) {
  944. out[0] = v1[0] / v2[0];
  945. out[1] = v1[1] / v2[1];
  946. return out;
  947. }
  948. /**
  949. * 向量点乘
  950. * @param {Vector2} v1
  951. * @param {Vector2} v2
  952. * @return {number}
  953. */
  954. function dot(v1, v2) {
  955. return v1[0] * v2[0] + v1[1] * v2[1];
  956. }
  957. /**
  958. * 向量缩放
  959. * @param {Vector2} out
  960. * @param {Vector2} v
  961. * @param {number} s
  962. */
  963. function scale(out, v, s) {
  964. out[0] = v[0] * s;
  965. out[1] = v[1] * s;
  966. return out;
  967. }
  968. /**
  969. * 向量归一化
  970. * @param {Vector2} out
  971. * @param {Vector2} v
  972. */
  973. function normalize(out, v) {
  974. var d = len(v);
  975. if (d === 0) {
  976. out[0] = 0;
  977. out[1] = 0;
  978. } else {
  979. out[0] = v[0] / d;
  980. out[1] = v[1] / d;
  981. }
  982. return out;
  983. }
  984. /**
  985. * 计算向量间距离
  986. * @param {Vector2} v1
  987. * @param {Vector2} v2
  988. * @return {number}
  989. */
  990. function distance(v1, v2) {
  991. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  992. }
  993. var dist = distance;
  994. /**
  995. * 向量距离平方
  996. * @param {Vector2} v1
  997. * @param {Vector2} v2
  998. * @return {number}
  999. */
  1000. function distanceSquare(v1, v2) {
  1001. return (v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  1002. }
  1003. var distSquare = distanceSquare;
  1004. /**
  1005. * 求负向量
  1006. * @param {Vector2} out
  1007. * @param {Vector2} v
  1008. */
  1009. function negate(out, v) {
  1010. out[0] = -v[0];
  1011. out[1] = -v[1];
  1012. return out;
  1013. }
  1014. /**
  1015. * 插值两个点
  1016. * @param {Vector2} out
  1017. * @param {Vector2} v1
  1018. * @param {Vector2} v2
  1019. * @param {number} t
  1020. */
  1021. function lerp(out, v1, v2, t) {
  1022. out[0] = v1[0] + t * (v2[0] - v1[0]);
  1023. out[1] = v1[1] + t * (v2[1] - v1[1]);
  1024. return out;
  1025. }
  1026. /**
  1027. * 矩阵左乘向量
  1028. * @param {Vector2} out
  1029. * @param {Vector2} v
  1030. * @param {Vector2} m
  1031. */
  1032. function applyTransform(out, v, m) {
  1033. var x = v[0];
  1034. var y = v[1];
  1035. out[0] = m[0] * x + m[2] * y + m[4];
  1036. out[1] = m[1] * x + m[3] * y + m[5];
  1037. return out;
  1038. }
  1039. /**
  1040. * 求两个向量最小值
  1041. * @param {Vector2} out
  1042. * @param {Vector2} v1
  1043. * @param {Vector2} v2
  1044. */
  1045. function min(out, v1, v2) {
  1046. out[0] = Math.min(v1[0], v2[0]);
  1047. out[1] = Math.min(v1[1], v2[1]);
  1048. return out;
  1049. }
  1050. /**
  1051. * 求两个向量最大值
  1052. * @param {Vector2} out
  1053. * @param {Vector2} v1
  1054. * @param {Vector2} v2
  1055. */
  1056. function max(out, v1, v2) {
  1057. out[0] = Math.max(v1[0], v2[0]);
  1058. out[1] = Math.max(v1[1], v2[1]);
  1059. return out;
  1060. }
  1061. var vector = (Object.freeze || Object)({
  1062. create: create,
  1063. copy: copy,
  1064. clone: clone$1,
  1065. set: set,
  1066. add: add,
  1067. scaleAndAdd: scaleAndAdd,
  1068. sub: sub,
  1069. len: len,
  1070. length: length,
  1071. lenSquare: lenSquare,
  1072. lengthSquare: lengthSquare,
  1073. mul: mul,
  1074. div: div,
  1075. dot: dot,
  1076. scale: scale,
  1077. normalize: normalize,
  1078. distance: distance,
  1079. dist: dist,
  1080. distanceSquare: distanceSquare,
  1081. distSquare: distSquare,
  1082. negate: negate,
  1083. lerp: lerp,
  1084. applyTransform: applyTransform,
  1085. min: min,
  1086. max: max
  1087. }); // TODO Draggable for group
  1088. // FIXME Draggable on element which has parent rotation or scale
  1089. function Draggable() {
  1090. this.on('mousedown', this._dragStart, this);
  1091. this.on('mousemove', this._drag, this);
  1092. this.on('mouseup', this._dragEnd, this); // `mosuemove` and `mouseup` can be continue to fire when dragging.
  1093. // See [Drag outside] in `Handler.js`. So we do not need to trigger
  1094. // `_dragEnd` when globalout. That would brings better user experience.
  1095. // this.on('globalout', this._dragEnd, this);
  1096. // this._dropTarget = null;
  1097. // this._draggingTarget = null;
  1098. // this._x = 0;
  1099. // this._y = 0;
  1100. }
  1101. Draggable.prototype = {
  1102. constructor: Draggable,
  1103. _dragStart: function (e) {
  1104. var draggingTarget = e.target; // Find if there is draggable in the ancestor
  1105. while (draggingTarget && !draggingTarget.draggable) {
  1106. draggingTarget = draggingTarget.parent;
  1107. }
  1108. if (draggingTarget) {
  1109. this._draggingTarget = draggingTarget;
  1110. draggingTarget.dragging = true;
  1111. this._x = e.offsetX;
  1112. this._y = e.offsetY;
  1113. this.dispatchToElement(param(draggingTarget, e), 'dragstart', e.event);
  1114. }
  1115. },
  1116. _drag: function (e) {
  1117. var draggingTarget = this._draggingTarget;
  1118. if (draggingTarget) {
  1119. var x = e.offsetX;
  1120. var y = e.offsetY;
  1121. var dx = x - this._x;
  1122. var dy = y - this._y;
  1123. this._x = x;
  1124. this._y = y;
  1125. draggingTarget.drift(dx, dy, e);
  1126. this.dispatchToElement(param(draggingTarget, e), 'drag', e.event);
  1127. var dropTarget = this.findHover(x, y, draggingTarget).target;
  1128. var lastDropTarget = this._dropTarget;
  1129. this._dropTarget = dropTarget;
  1130. if (draggingTarget !== dropTarget) {
  1131. if (lastDropTarget && dropTarget !== lastDropTarget) {
  1132. this.dispatchToElement(param(lastDropTarget, e), 'dragleave', e.event);
  1133. }
  1134. if (dropTarget && dropTarget !== lastDropTarget) {
  1135. this.dispatchToElement(param(dropTarget, e), 'dragenter', e.event);
  1136. }
  1137. }
  1138. }
  1139. },
  1140. _dragEnd: function (e) {
  1141. var draggingTarget = this._draggingTarget;
  1142. if (draggingTarget) {
  1143. draggingTarget.dragging = false;
  1144. }
  1145. this.dispatchToElement(param(draggingTarget, e), 'dragend', e.event);
  1146. if (this._dropTarget) {
  1147. this.dispatchToElement(param(this._dropTarget, e), 'drop', e.event);
  1148. }
  1149. this._draggingTarget = null;
  1150. this._dropTarget = null;
  1151. }
  1152. };
  1153. function param(target, e) {
  1154. return {
  1155. target: target,
  1156. topTarget: e && e.topTarget
  1157. };
  1158. }
  1159. /**
  1160. * Event Mixin
  1161. * @module zrender/mixin/Eventful
  1162. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  1163. * pissang (https://www.github.com/pissang)
  1164. */
  1165. var arrySlice = Array.prototype.slice;
  1166. /**
  1167. * Event dispatcher.
  1168. *
  1169. * @alias module:zrender/mixin/Eventful
  1170. * @constructor
  1171. * @param {Object} [eventProcessor] The object eventProcessor is the scope when
  1172. * `eventProcessor.xxx` called.
  1173. * @param {Function} [eventProcessor.normalizeQuery]
  1174. * param: {string|Object} Raw query.
  1175. * return: {string|Object} Normalized query.
  1176. * @param {Function} [eventProcessor.filter] Event will be dispatched only
  1177. * if it returns `true`.
  1178. * param: {string} eventType
  1179. * param: {string|Object} query
  1180. * return: {boolean}
  1181. * @param {Function} [eventProcessor.afterTrigger] Called after all handlers called.
  1182. * param: {string} eventType
  1183. */
  1184. var Eventful = function (eventProcessor) {
  1185. this._$handlers = {};
  1186. this._$eventProcessor = eventProcessor;
  1187. };
  1188. Eventful.prototype = {
  1189. constructor: Eventful,
  1190. /**
  1191. * The handler can only be triggered once, then removed.
  1192. *
  1193. * @param {string} event The event name.
  1194. * @param {string|Object} [query] Condition used on event filter.
  1195. * @param {Function} handler The event handler.
  1196. * @param {Object} context
  1197. */
  1198. one: function (event, query, handler, context) {
  1199. return on(this, event, query, handler, context, true);
  1200. },
  1201. /**
  1202. * Bind a handler.
  1203. *
  1204. * @param {string} event The event name.
  1205. * @param {string|Object} [query] Condition used on event filter.
  1206. * @param {Function} handler The event handler.
  1207. * @param {Object} [context]
  1208. */
  1209. on: function (event, query, handler, context) {
  1210. return on(this, event, query, handler, context, false);
  1211. },
  1212. /**
  1213. * Whether any handler has bound.
  1214. *
  1215. * @param {string} event
  1216. * @return {boolean}
  1217. */
  1218. isSilent: function (event) {
  1219. var _h = this._$handlers;
  1220. return !_h[event] || !_h[event].length;
  1221. },
  1222. /**
  1223. * Unbind a event.
  1224. *
  1225. * @param {string} [event] The event name.
  1226. * If no `event` input, "off" all listeners.
  1227. * @param {Function} [handler] The event handler.
  1228. * If no `handler` input, "off" all listeners of the `event`.
  1229. */
  1230. off: function (event, handler) {
  1231. var _h = this._$handlers;
  1232. if (!event) {
  1233. this._$handlers = {};
  1234. return this;
  1235. }
  1236. if (handler) {
  1237. if (_h[event]) {
  1238. var newList = [];
  1239. for (var i = 0, l = _h[event].length; i < l; i++) {
  1240. if (_h[event][i].h !== handler) {
  1241. newList.push(_h[event][i]);
  1242. }
  1243. }
  1244. _h[event] = newList;
  1245. }
  1246. if (_h[event] && _h[event].length === 0) {
  1247. delete _h[event];
  1248. }
  1249. } else {
  1250. delete _h[event];
  1251. }
  1252. return this;
  1253. },
  1254. /**
  1255. * Dispatch a event.
  1256. *
  1257. * @param {string} type The event name.
  1258. */
  1259. trigger: function (type) {
  1260. var _h = this._$handlers[type];
  1261. var eventProcessor = this._$eventProcessor;
  1262. if (_h) {
  1263. var args = arguments;
  1264. var argLen = args.length;
  1265. if (argLen > 3) {
  1266. args = arrySlice.call(args, 1);
  1267. }
  1268. var len = _h.length;
  1269. for (var i = 0; i < len;) {
  1270. var hItem = _h[i];
  1271. if (eventProcessor && eventProcessor.filter && hItem.query != null && !eventProcessor.filter(type, hItem.query)) {
  1272. i++;
  1273. continue;
  1274. } // Optimize advise from backbone
  1275. switch (argLen) {
  1276. case 1:
  1277. hItem.h.call(hItem.ctx);
  1278. break;
  1279. case 2:
  1280. hItem.h.call(hItem.ctx, args[1]);
  1281. break;
  1282. case 3:
  1283. hItem.h.call(hItem.ctx, args[1], args[2]);
  1284. break;
  1285. default:
  1286. // have more than 2 given arguments
  1287. hItem.h.apply(hItem.ctx, args);
  1288. break;
  1289. }
  1290. if (hItem.one) {
  1291. _h.splice(i, 1);
  1292. len--;
  1293. } else {
  1294. i++;
  1295. }
  1296. }
  1297. }
  1298. eventProcessor && eventProcessor.afterTrigger && eventProcessor.afterTrigger(type);
  1299. return this;
  1300. },
  1301. /**
  1302. * Dispatch a event with context, which is specified at the last parameter.
  1303. *
  1304. * @param {string} type The event name.
  1305. */
  1306. triggerWithContext: function (type) {
  1307. var _h = this._$handlers[type];
  1308. var eventProcessor = this._$eventProcessor;
  1309. if (_h) {
  1310. var args = arguments;
  1311. var argLen = args.length;
  1312. if (argLen > 4) {
  1313. args = arrySlice.call(args, 1, args.length - 1);
  1314. }
  1315. var ctx = args[args.length - 1];
  1316. var len = _h.length;
  1317. for (var i = 0; i < len;) {
  1318. var hItem = _h[i];
  1319. if (eventProcessor && eventProcessor.filter && hItem.query != null && !eventProcessor.filter(type, hItem.query)) {
  1320. i++;
  1321. continue;
  1322. } // Optimize advise from backbone
  1323. switch (argLen) {
  1324. case 1:
  1325. hItem.h.call(ctx);
  1326. break;
  1327. case 2:
  1328. hItem.h.call(ctx, args[1]);
  1329. break;
  1330. case 3:
  1331. hItem.h.call(ctx, args[1], args[2]);
  1332. break;
  1333. default:
  1334. // have more than 2 given arguments
  1335. hItem.h.apply(ctx, args);
  1336. break;
  1337. }
  1338. if (hItem.one) {
  1339. _h.splice(i, 1);
  1340. len--;
  1341. } else {
  1342. i++;
  1343. }
  1344. }
  1345. }
  1346. eventProcessor && eventProcessor.afterTrigger && eventProcessor.afterTrigger(type);
  1347. return this;
  1348. }
  1349. };
  1350. function normalizeQuery(host, query) {
  1351. var eventProcessor = host._$eventProcessor;
  1352. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  1353. query = eventProcessor.normalizeQuery(query);
  1354. }
  1355. return query;
  1356. }
  1357. function on(eventful, event, query, handler, context, isOnce) {
  1358. var _h = eventful._$handlers;
  1359. if (typeof query === 'function') {
  1360. context = handler;
  1361. handler = query;
  1362. query = null;
  1363. }
  1364. if (!handler || !event) {
  1365. return eventful;
  1366. }
  1367. query = normalizeQuery(eventful, query);
  1368. if (!_h[event]) {
  1369. _h[event] = [];
  1370. }
  1371. for (var i = 0; i < _h[event].length; i++) {
  1372. if (_h[event][i].h === handler) {
  1373. return eventful;
  1374. }
  1375. }
  1376. var wrap = {
  1377. h: handler,
  1378. one: isOnce,
  1379. query: query,
  1380. ctx: context || eventful,
  1381. // FIXME
  1382. // Do not publish this feature util it is proved that it makes sense.
  1383. callAtLast: handler.zrEventfulCallAtLast
  1384. };
  1385. var lastIndex = _h[event].length - 1;
  1386. var lastWrap = _h[event][lastIndex];
  1387. lastWrap && lastWrap.callAtLast ? _h[event].splice(lastIndex, 0, wrap) : _h[event].push(wrap);
  1388. return eventful;
  1389. }
  1390. /**
  1391. * The algoritm is learnt from
  1392. * https://franklinta.com/2014/09/08/computing-css-matrix3d-transforms/
  1393. * And we made some optimization for matrix inversion.
  1394. * Other similar approaches:
  1395. * "cv::getPerspectiveTransform", "Direct Linear Transformation".
  1396. */
  1397. var LN2 = Math.log(2);
  1398. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1399. var cacheKey = rowMask + '-' + colMask;
  1400. var fullRank = rows.length;
  1401. if (detCache.hasOwnProperty(cacheKey)) {
  1402. return detCache[cacheKey];
  1403. }
  1404. if (rank === 1) {
  1405. // In this case the colMask must be like: `11101111`. We can find the place of `0`.
  1406. var colStart = Math.round(Math.log((1 << fullRank) - 1 & ~colMask) / LN2);
  1407. return rows[rowStart][colStart];
  1408. }
  1409. var subRowMask = rowMask | 1 << rowStart;
  1410. var subRowStart = rowStart + 1;
  1411. while (rowMask & 1 << subRowStart) {
  1412. subRowStart++;
  1413. }
  1414. var sum = 0;
  1415. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1416. var colTag = 1 << j;
  1417. if (!(colTag & colMask)) {
  1418. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j] // det(subMatrix(0, j))
  1419. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1420. colLocalIdx++;
  1421. }
  1422. }
  1423. detCache[cacheKey] = sum;
  1424. return sum;
  1425. }
  1426. /**
  1427. * Usage:
  1428. * ```js
  1429. * var transformer = buildTransformer(
  1430. * [10, 44, 100, 44, 100, 300, 10, 300],
  1431. * [50, 54, 130, 14, 140, 330, 14, 220]
  1432. * );
  1433. * var out = [];
  1434. * transformer && transformer([11, 33], out);
  1435. * ```
  1436. *
  1437. * Notice: `buildTransformer` may take more than 10ms in some Android device.
  1438. *
  1439. * @param {Array.<number>} src source four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1440. * @param {Array.<number>} dest destination four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1441. * @return {Function} transformer If fail, return null/undefined.
  1442. */
  1443. function buildTransformer(src, dest) {
  1444. var mA = [[src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]], [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]], [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]], [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]], [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]], [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]], [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]], [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]];
  1445. var detCache = {};
  1446. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1447. if (det === 0) {
  1448. // can not make transformer when and only when
  1449. // any three of the markers are collinear.
  1450. return;
  1451. } // `invert(mA) * dest`, that is, `adj(mA) / det * dest`.
  1452. var vh = [];
  1453. for (var i = 0; i < 8; i++) {
  1454. for (var j = 0; j < 8; j++) {
  1455. vh[j] == null && (vh[j] = 0);
  1456. vh[j] += ((i + j) % 2 ? -1 : 1) * // det(subMatrix(i, j))
  1457. determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache) / det * dest[i];
  1458. }
  1459. }
  1460. return function (out, srcPointX, srcPointY) {
  1461. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1462. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1463. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1464. };
  1465. }
  1466. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1467. /**
  1468. * Transform "local coord" from `elFrom` to `elTarget`.
  1469. * "local coord": the coord based on the input `el`. The origin point is at
  1470. * the position of "left: 0; top: 0;" in the `el`.
  1471. *
  1472. * Support when CSS transform is used.
  1473. *
  1474. * Having the `out` (that is, `[outX, outY]`), we can create an DOM element
  1475. * and set the CSS style as "left: outX; top: outY;" and append it to `elTarge`
  1476. * to locate the element.
  1477. *
  1478. * For example, this code below positions a child of `document.body` on the event
  1479. * point, no matter whether `body` has `margin`/`paddin`/`transfrom`/... :
  1480. * ```js
  1481. * transformLocalCoord(out, container, document.body, event.offsetX, event.offsetY);
  1482. * if (!eqNaN(out[0])) {
  1483. * // Then locate the tip element on the event point.
  1484. * var tipEl = document.createElement('div');
  1485. * tipEl.style.cssText = 'position: absolute; left:' + out[0] + ';top:' + out[1] + ';';
  1486. * document.body.appendChild(tipEl);
  1487. * }
  1488. * ```
  1489. *
  1490. * Notice: In some env this method is not supported. If called, `out` will be `[NaN, NaN]`.
  1491. *
  1492. * @param {Array.<number>} out [inX: number, inY: number] The output..
  1493. * If can not transform, `out` will not be modified but return `false`.
  1494. * @param {HTMLElement} elFrom The `[inX, inY]` is based on elFrom.
  1495. * @param {HTMLElement} elTarget The `out` is based on elTarget.
  1496. * @param {number} inX
  1497. * @param {number} inY
  1498. * @return {boolean} Whether transform successfully.
  1499. */
  1500. /**
  1501. * Transform between a "viewport coord" and a "local coord".
  1502. * "viewport coord": the coord based on the left-top corner of the viewport
  1503. * of the browser.
  1504. * "local coord": the coord based on the input `el`. The origin point is at
  1505. * the position of "left: 0; top: 0;" in the `el`.
  1506. *
  1507. * Support the case when CSS transform is used on el.
  1508. *
  1509. * @param {Array.<number>} out [inX: number, inY: number] The output. If `inverse: false`,
  1510. * it represents "local coord", otherwise "vireport coord".
  1511. * If can not transform, `out` will not be modified but return `false`.
  1512. * @param {HTMLElement} el The "local coord" is based on the `el`, see comment above.
  1513. * @param {number} inX If `inverse: false`,
  1514. * it represents "vireport coord", otherwise "local coord".
  1515. * @param {number} inY If `inverse: false`,
  1516. * it represents "vireport coord", otherwise "local coord".
  1517. * @param {boolean} [inverse=false]
  1518. * `true`: from "viewport coord" to "local coord".
  1519. * `false`: from "local coord" to "viewport coord".
  1520. * @return {boolean} Whether transform successfully.
  1521. */
  1522. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1523. if (el.getBoundingClientRect && env$1.domSupported && !isCanvasEl(el)) {
  1524. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1525. var markers = prepareCoordMarkers(el, saved);
  1526. var transformer = preparePointerTransformer(markers, saved, inverse);
  1527. if (transformer) {
  1528. transformer(out, inX, inY);
  1529. return true;
  1530. }
  1531. }
  1532. return false;
  1533. }
  1534. function prepareCoordMarkers(el, saved) {
  1535. var markers = saved.markers;
  1536. if (markers) {
  1537. return markers;
  1538. }
  1539. markers = saved.markers = [];
  1540. var propLR = ['left', 'right'];
  1541. var propTB = ['top', 'bottom'];
  1542. for (var i = 0; i < 4; i++) {
  1543. var marker = document.createElement('div');
  1544. var stl = marker.style;
  1545. var idxLR = i % 2;
  1546. var idxTB = (i >> 1) % 2;
  1547. stl.cssText = ['position: absolute', 'visibility: hidden', 'padding: 0', 'margin: 0', 'border-width: 0', 'user-select: none', 'width:0', 'height:0', // 'width: 5px',
  1548. // 'height: 5px',
  1549. propLR[idxLR] + ':0', propTB[idxTB] + ':0', propLR[1 - idxLR] + ':auto', propTB[1 - idxTB] + ':auto', ''].join('!important;');
  1550. el.appendChild(marker);
  1551. markers.push(marker);
  1552. }
  1553. return markers;
  1554. }
  1555. function preparePointerTransformer(markers, saved, inverse) {
  1556. var transformerName = inverse ? 'invTrans' : 'trans';
  1557. var transformer = saved[transformerName];
  1558. var oldSrcCoords = saved.srcCoords;
  1559. var oldCoordTheSame = true;
  1560. var srcCoords = [];
  1561. var destCoords = [];
  1562. for (var i = 0; i < 4; i++) {
  1563. var rect = markers[i].getBoundingClientRect();
  1564. var ii = 2 * i;
  1565. var x = rect.left;
  1566. var y = rect.top;
  1567. srcCoords.push(x, y);
  1568. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1569. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1570. } // Cache to avoid time consuming of `buildTransformer`.
  1571. return oldCoordTheSame && transformer ? transformer : (saved.srcCoords = srcCoords, saved[transformerName] = inverse ? buildTransformer(destCoords, srcCoords) : buildTransformer(srcCoords, destCoords));
  1572. }
  1573. function isCanvasEl(el) {
  1574. return el.nodeName.toUpperCase() === 'CANVAS';
  1575. }
  1576. /**
  1577. * Utilities for mouse or touch events.
  1578. */
  1579. var isDomLevel2 = typeof window !== 'undefined' && !!window.addEventListener;
  1580. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1581. var _calcOut = [];
  1582. /**
  1583. * Get the `zrX` and `zrY`, which are relative to the top-left of
  1584. * the input `el`.
  1585. * CSS transform (2D & 3D) is supported.
  1586. *
  1587. * The strategy to fetch the coords:
  1588. * + If `calculate` is not set as `true`, users of this method should
  1589. * ensure that `el` is the same or the same size & location as `e.target`.
  1590. * Otherwise the result coords are probably not expected. Because we
  1591. * firstly try to get coords from e.offsetX/e.offsetY.
  1592. * + If `calculate` is set as `true`, the input `el` can be any element
  1593. * and we force to calculate the coords based on `el`.
  1594. * + The input `el` should be positionable (not position:static).
  1595. *
  1596. * The force `calculate` can be used in case like:
  1597. * When mousemove event triggered on ec tooltip, `e.target` is not `el`(zr painter.dom).
  1598. *
  1599. * @param {HTMLElement} el DOM element.
  1600. * @param {Event} e Mouse event or touch event.
  1601. * @param {Object} out Get `out.zrX` and `out.zrY` as the result.
  1602. * @param {boolean} [calculate=false] Whether to force calculate
  1603. * the coordinates but not use ones provided by browser.
  1604. */
  1605. function clientToLocal(el, e, out, calculate) {
  1606. out = out || {}; // According to the W3C Working Draft, offsetX and offsetY should be relative
  1607. // to the padding edge of the target element. The only browser using this convention
  1608. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  1609. // not support the properties.
  1610. // (see http://www.jacklmoore.com/notes/mouse-position/)
  1611. // In zr painter.dom, padding edge equals to border edge.
  1612. if (calculate || !env$1.canvasSupported) {
  1613. calculateZrXY(el, e, out);
  1614. } // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  1615. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  1616. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  1617. // zoom-factor, overflow / opacity layers, transforms ...)
  1618. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  1619. // <https://bugs.jquery.com/ticket/8523#comment:14>
  1620. // BTW3, In ff, offsetX/offsetY is always 0.
  1621. else if (env$1.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  1622. out.zrX = e.layerX;
  1623. out.zrY = e.layerY;
  1624. } // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  1625. else if (e.offsetX != null) {
  1626. out.zrX = e.offsetX;
  1627. out.zrY = e.offsetY;
  1628. } // For some other device, e.g., IOS safari.
  1629. else {
  1630. calculateZrXY(el, e, out);
  1631. }
  1632. return out;
  1633. }
  1634. function calculateZrXY(el, e, out) {
  1635. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect.
  1636. if (env$1.domSupported && el.getBoundingClientRect) {
  1637. var ex = e.clientX;
  1638. var ey = e.clientY;
  1639. if (isCanvasEl(el)) {
  1640. // Original approach, which do not support CSS transform.
  1641. // marker can not be locationed in a canvas container
  1642. // (getBoundingClientRect is always 0). We do not support
  1643. // that input a pre-created canvas to zr while using css
  1644. // transform in iOS.
  1645. var box = el.getBoundingClientRect();
  1646. out.zrX = ex - box.left;
  1647. out.zrY = ey - box.top;
  1648. return;
  1649. } else {
  1650. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1651. out.zrX = _calcOut[0];
  1652. out.zrY = _calcOut[1];
  1653. return;
  1654. }
  1655. }
  1656. }
  1657. out.zrX = out.zrY = 0;
  1658. }
  1659. /**
  1660. * Find native event compat for legency IE.
  1661. * Should be called at the begining of a native event listener.
  1662. *
  1663. * @param {Event} [e] Mouse event or touch event or pointer event.
  1664. * For lagency IE, we use `window.event` is used.
  1665. * @return {Event} The native event.
  1666. */
  1667. function getNativeEvent(e) {
  1668. return e || window.event;
  1669. }
  1670. /**
  1671. * Normalize the coordinates of the input event.
  1672. *
  1673. * Get the `e.zrX` and `e.zrY`, which are relative to the top-left of
  1674. * the input `el`.
  1675. * Get `e.zrDelta` if using mouse wheel.
  1676. * Get `e.which`, see the comment inside this function.
  1677. *
  1678. * Do not calculate repeatly if `zrX` and `zrY` already exist.
  1679. *
  1680. * Notice: see comments in `clientToLocal`. check the relationship
  1681. * between the result coords and the parameters `el` and `calculate`.
  1682. *
  1683. * @param {HTMLElement} el DOM element.
  1684. * @param {Event} [e] See `getNativeEvent`.
  1685. * @param {boolean} [calculate=false] Whether to force calculate
  1686. * the coordinates but not use ones provided by browser.
  1687. * @return {UIEvent} The normalized native UIEvent.
  1688. */
  1689. function normalizeEvent(el, e, calculate) {
  1690. e = getNativeEvent(e);
  1691. if (e.zrX != null) {
  1692. return e;
  1693. }
  1694. var eventType = e.type;
  1695. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1696. if (!isTouch) {
  1697. clientToLocal(el, e, e, calculate);
  1698. e.zrDelta = e.wheelDelta ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  1699. } else {
  1700. var touch = eventType !== 'touchend' ? e.targetTouches[0] : e.changedTouches[0];
  1701. touch && clientToLocal(el, touch, e, calculate);
  1702. } // Add which for click: 1 === left; 2 === middle; 3 === right; otherwise: 0;
  1703. // See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
  1704. // If e.which has been defined, it may be readonly,
  1705. // see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
  1706. var button = e.button;
  1707. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1708. e.which = button & 1 ? 1 : button & 2 ? 3 : button & 4 ? 2 : 0;
  1709. } // [Caution]: `e.which` from browser is not always reliable. For example,
  1710. // when press left button and `mousemove (pointermove)` in Edge, the `e.which`
  1711. // is 65536 and the `e.button` is -1. But the `mouseup (pointerup)` and
  1712. // `mousedown (pointerdown)` is the same as Chrome does.
  1713. return e;
  1714. }
  1715. /**
  1716. * @param {HTMLElement} el
  1717. * @param {string} name
  1718. * @param {Function} handler
  1719. * @param {Object|boolean} opt If boolean, means `opt.capture`
  1720. * @param {boolean} [opt.capture=false]
  1721. * @param {boolean} [opt.passive=false]
  1722. */
  1723. function addEventListener(el, name, handler, opt) {
  1724. if (isDomLevel2) {
  1725. // Reproduct the console warning:
  1726. // [Violation] Added non-passive event listener to a scroll-blocking <some> event.
  1727. // Consider marking event handler as 'passive' to make the page more responsive.
  1728. // Just set console log level: verbose in chrome dev tool.
  1729. // then the warning log will be printed when addEventListener called.
  1730. // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  1731. // We have not yet found a neat way to using passive. Because in zrender the dom event
  1732. // listener delegate all of the upper events of element. Some of those events need
  1733. // to prevent default. For example, the feature `preventDefaultMouseMove` of echarts.
  1734. // Before passive can be adopted, these issues should be considered:
  1735. // (1) Whether and how a zrender user specifies an event listener passive. And by default,
  1736. // passive or not.
  1737. // (2) How to tread that some zrender event listener is passive, and some is not. If
  1738. // we use other way but not preventDefault of mousewheel and touchmove, browser
  1739. // compatibility should be handled.
  1740. // var opts = (env.passiveSupported && name === 'mousewheel')
  1741. // ? {passive: true}
  1742. // // By default, the third param of el.addEventListener is `capture: false`.
  1743. // : void 0;
  1744. // el.addEventListener(name, handler /* , opts */);
  1745. el.addEventListener(name, handler, opt);
  1746. } else {
  1747. // For simplicity, do not implement `setCapture` for IE9-.
  1748. el.attachEvent('on' + name, handler);
  1749. }
  1750. }
  1751. /**
  1752. * Parameter are the same as `addEventListener`.
  1753. *
  1754. * Notice that if a listener is registered twice, one with capture and one without,
  1755. * remove each one separately. Removal of a capturing listener does not affect a
  1756. * non-capturing version of the same listener, and vice versa.
  1757. */
  1758. function removeEventListener(el, name, handler, opt) {
  1759. if (isDomLevel2) {
  1760. el.removeEventListener(name, handler, opt);
  1761. } else {
  1762. el.detachEvent('on' + name, handler);
  1763. }
  1764. }
  1765. /**
  1766. * preventDefault and stopPropagation.
  1767. * Notice: do not use this method in zrender. It can only be
  1768. * used by upper applications if necessary.
  1769. *
  1770. * @param {Event} e A mouse or touch event.
  1771. */
  1772. var stop = isDomLevel2 ? function (e) {
  1773. e.preventDefault();
  1774. e.stopPropagation();
  1775. e.cancelBubble = true;
  1776. } : function (e) {
  1777. e.returnValue = false;
  1778. e.cancelBubble = true;
  1779. };
  1780. /**
  1781. * This method only works for mouseup and mousedown. The functionality is restricted
  1782. * for fault tolerance, See the `e.which` compatibility above.
  1783. *
  1784. * @param {MouseEvent} e
  1785. * @return {boolean}
  1786. */
  1787. /**
  1788. * To be removed.
  1789. * @deprecated
  1790. */
  1791. /**
  1792. * Only implements needed gestures for mobile.
  1793. */
  1794. var GestureMgr = function () {
  1795. /**
  1796. * @private
  1797. * @type {Array.<Object>}
  1798. */
  1799. this._track = [];
  1800. };
  1801. GestureMgr.prototype = {
  1802. constructor: GestureMgr,
  1803. recognize: function (event, target, root) {
  1804. this._doTrack(event, target, root);
  1805. return this._recognize(event);
  1806. },
  1807. clear: function () {
  1808. this._track.length = 0;
  1809. return this;
  1810. },
  1811. _doTrack: function (event, target, root) {
  1812. var touches = event.touches;
  1813. if (!touches) {
  1814. return;
  1815. }
  1816. var trackItem = {
  1817. points: [],
  1818. touches: [],
  1819. target: target,
  1820. event: event
  1821. };
  1822. for (var i = 0, len = touches.length; i < len; i++) {
  1823. var touch = touches[i];
  1824. var pos = clientToLocal(root, touch, {});
  1825. trackItem.points.push([pos.zrX, pos.zrY]);
  1826. trackItem.touches.push(touch);
  1827. }
  1828. this._track.push(trackItem);
  1829. },
  1830. _recognize: function (event) {
  1831. for (var eventName in recognizers) {
  1832. if (recognizers.hasOwnProperty(eventName)) {
  1833. var gestureInfo = recognizers[eventName](this._track, event);
  1834. if (gestureInfo) {
  1835. return gestureInfo;
  1836. }
  1837. }
  1838. }
  1839. }
  1840. };
  1841. function dist$1(pointPair) {
  1842. var dx = pointPair[1][0] - pointPair[0][0];
  1843. var dy = pointPair[1][1] - pointPair[0][1];
  1844. return Math.sqrt(dx * dx + dy * dy);
  1845. }
  1846. function center(pointPair) {
  1847. return [(pointPair[0][0] + pointPair[1][0]) / 2, (pointPair[0][1] + pointPair[1][1]) / 2];
  1848. }
  1849. var recognizers = {
  1850. pinch: function (track, event) {
  1851. var trackLen = track.length;
  1852. if (!trackLen) {
  1853. return;
  1854. }
  1855. var pinchEnd = (track[trackLen - 1] || {}).points;
  1856. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  1857. if (pinchPre && pinchPre.length > 1 && pinchEnd && pinchEnd.length > 1) {
  1858. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1859. !isFinite(pinchScale) && (pinchScale = 1);
  1860. event.pinchScale = pinchScale;
  1861. var pinchCenter = center(pinchEnd);
  1862. event.pinchX = pinchCenter[0];
  1863. event.pinchY = pinchCenter[1];
  1864. return {
  1865. type: 'pinch',
  1866. target: track[0].target,
  1867. event: event
  1868. };
  1869. }
  1870. } // Only pinch currently.
  1871. };
  1872. /**
  1873. * [The interface between `Handler` and `HandlerProxy`]:
  1874. *
  1875. * The default `HandlerProxy` only support the common standard web environment
  1876. * (e.g., standalone browser, headless browser, embed browser in mobild APP, ...).
  1877. * But `HandlerProxy` can be replaced to support more non-standard environment
  1878. * (e.g., mini app), or to support more feature that the default `HandlerProxy`
  1879. * not provided (like echarts-gl did).
  1880. * So the interface between `Handler` and `HandlerProxy` should be stable. Do not
  1881. * make break changes util inevitable. The interface include the public methods
  1882. * of `Handler` and the events listed in `handlerNames` below, by which `HandlerProxy`
  1883. * drives `Handler`.
  1884. */
  1885. /**
  1886. * [Drag outside]:
  1887. *
  1888. * That is, triggering `mousemove` and `mouseup` event when the pointer is out of the
  1889. * zrender area when dragging. That is important for the improvement of the user experience
  1890. * when dragging something near the boundary without being terminated unexpectedly.
  1891. *
  1892. * We originally consider to introduce new events like `pagemovemove` and `pagemouseup`
  1893. * to resolve this issue. But some drawbacks of it is described in
  1894. * https://github.com/ecomfe/zrender/pull/536#issuecomment-560286899
  1895. *
  1896. * Instead, we referenced the specifications:
  1897. * https://www.w3.org/TR/touch-events/#the-touchmove-event
  1898. * https://www.w3.org/TR/2014/WD-DOM-Level-3-Events-20140925/#event-type-mousemove
  1899. * where the the mousemove/touchmove can be continue to fire if the user began a drag
  1900. * operation and the pointer has left the boundary. (for the mouse event, browsers
  1901. * only do it on `document` and when the pointer has left the boundary of the browser.)
  1902. *
  1903. * So the default `HandlerProxy` supports this feature similarly: if it is in the dragging
  1904. * state (see `pointerCapture` in `HandlerProxy`), the `mousemove` and `mouseup` continue
  1905. * to fire until release the pointer. That is implemented by listen to those event on
  1906. * `document`.
  1907. * If we implement some other `HandlerProxy` only for touch device, that would be easier.
  1908. * The touch event support this feature by default.
  1909. *
  1910. * Note:
  1911. * There might be some cases that the mouse event can not be
  1912. * received on `document`. For example,
  1913. * (A) `useCapture` is not supported and some user defined event listeners on the ancestor
  1914. * of zr dom throw Error .
  1915. * (B) `useCapture` is not supported Some user defined event listeners on the ancestor of
  1916. * zr dom call `stopPropagation`.
  1917. * In these cases, the `mousemove` event might be keep triggered event
  1918. * if the mouse is released. We try to reduce the side-effect in those cases.
  1919. * That is, do nothing (especially, `findHover`) in those cases. See `isOutsideBoundary`.
  1920. *
  1921. * Note:
  1922. * If `HandlerProxy` listens to `document` with `useCapture`, `HandlerProxy` needs to
  1923. * make sure `stopPropagation` and `preventDefault` doing nothing if and only if the event
  1924. * target is not zrender dom. Becuase it is dangerous to enable users to call them in
  1925. * `document` capture phase to prevent the propagation to any listener of the webpage.
  1926. * But they are needed to work when the pointer inside the zrender dom.
  1927. */
  1928. var SILENT = 'silent';
  1929. function makeEventPacket(eveType, targetInfo, event) {
  1930. return {
  1931. type: eveType,
  1932. event: event,
  1933. // target can only be an element that is not silent.
  1934. target: targetInfo.target,
  1935. // topTarget can be a silent element.
  1936. topTarget: targetInfo.topTarget,
  1937. cancelBubble: false,
  1938. offsetX: event.zrX,
  1939. offsetY: event.zrY,
  1940. gestureEvent: event.gestureEvent,
  1941. pinchX: event.pinchX,
  1942. pinchY: event.pinchY,
  1943. pinchScale: event.pinchScale,
  1944. wheelDelta: event.zrDelta,
  1945. zrByTouch: event.zrByTouch,
  1946. which: event.which,
  1947. stop: stopEvent
  1948. };
  1949. }
  1950. function stopEvent() {
  1951. stop(this.event);
  1952. }
  1953. function EmptyProxy() {}
  1954. EmptyProxy.prototype.dispose = function () {};
  1955. var handlerNames = ['click', 'dblclick', 'mousewheel', 'mouseout', 'mouseup', 'mousedown', 'mousemove', 'contextmenu'];
  1956. /**
  1957. * @alias module:zrender/Handler
  1958. * @constructor
  1959. * @extends module:zrender/mixin/Eventful
  1960. * @param {module:zrender/Storage} storage Storage instance.
  1961. * @param {module:zrender/Painter} painter Painter instance.
  1962. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  1963. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  1964. */
  1965. var Handler = function (storage, painter, proxy, painterRoot) {
  1966. Eventful.call(this);
  1967. this.storage = storage;
  1968. this.painter = painter;
  1969. this.painterRoot = painterRoot;
  1970. proxy = proxy || new EmptyProxy();
  1971. /**
  1972. * Proxy of event. can be Dom, WebGLSurface, etc.
  1973. */
  1974. this.proxy = null;
  1975. /**
  1976. * {target, topTarget, x, y}
  1977. * @private
  1978. * @type {Object}
  1979. */
  1980. this._hovered = {};
  1981. /**
  1982. * @private
  1983. * @type {Date}
  1984. */
  1985. this._lastTouchMoment;
  1986. /**
  1987. * @private
  1988. * @type {number}
  1989. */
  1990. this._lastX;
  1991. /**
  1992. * @private
  1993. * @type {number}
  1994. */
  1995. this._lastY;
  1996. /**
  1997. * @private
  1998. * @type {module:zrender/core/GestureMgr}
  1999. */
  2000. this._gestureMgr;
  2001. Draggable.call(this);
  2002. this.setHandlerProxy(proxy);
  2003. };
  2004. Handler.prototype = {
  2005. constructor: Handler,
  2006. setHandlerProxy: function (proxy) {
  2007. if (this.proxy) {
  2008. this.proxy.dispose();
  2009. }
  2010. if (proxy) {
  2011. each$1(handlerNames, function (name) {
  2012. proxy.on && proxy.on(name, this[name], this);
  2013. }, this); // Attach handler
  2014. proxy.handler = this;
  2015. }
  2016. this.proxy = proxy;
  2017. },
  2018. mousemove: function (event) {
  2019. var x = event.zrX;
  2020. var y = event.zrY;
  2021. var isOutside = isOutsideBoundary(this, x, y);
  2022. var lastHovered = this._hovered;
  2023. var lastHoveredTarget = lastHovered.target; // If lastHoveredTarget is removed from zr (detected by '__zr') by some API call
  2024. // (like 'setOption' or 'dispatchAction') in event handlers, we should find
  2025. // lastHovered again here. Otherwise 'mouseout' can not be triggered normally.
  2026. // See #6198.
  2027. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  2028. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  2029. lastHoveredTarget = lastHovered.target;
  2030. }
  2031. var hovered = this._hovered = isOutside ? {
  2032. x: x,
  2033. y: y
  2034. } : this.findHover(x, y);
  2035. var hoveredTarget = hovered.target;
  2036. var proxy = this.proxy;
  2037. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default'); // Mouse out on previous hovered element
  2038. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2039. this.dispatchToElement(lastHovered, 'mouseout', event);
  2040. } // Mouse moving on one element
  2041. this.dispatchToElement(hovered, 'mousemove', event); // Mouse over on a new element
  2042. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2043. this.dispatchToElement(hovered, 'mouseover', event);
  2044. }
  2045. },
  2046. mouseout: function (event) {
  2047. var eventControl = event.zrEventControl;
  2048. var zrIsToLocalDOM = event.zrIsToLocalDOM;
  2049. if (eventControl !== 'only_globalout') {
  2050. this.dispatchToElement(this._hovered, 'mouseout', event);
  2051. }
  2052. if (eventControl !== 'no_globalout') {
  2053. // FIXME: if the pointer moving from the extra doms to realy "outside",
  2054. // the `globalout` should have been triggered. But currently not.
  2055. !zrIsToLocalDOM && this.trigger('globalout', {
  2056. type: 'globalout',
  2057. event: event
  2058. });
  2059. }
  2060. },
  2061. /**
  2062. * Resize
  2063. */
  2064. resize: function (event) {
  2065. this._hovered = {};
  2066. },
  2067. /**
  2068. * Dispatch event
  2069. * @param {string} eventName
  2070. * @param {event=} eventArgs
  2071. */
  2072. dispatch: function (eventName, eventArgs) {
  2073. var handler = this[eventName];
  2074. handler && handler.call(this, eventArgs);
  2075. },
  2076. /**
  2077. * Dispose
  2078. */
  2079. dispose: function () {
  2080. this.proxy.dispose();
  2081. this.storage = this.proxy = this.painter = null;
  2082. },
  2083. /**
  2084. * 设置默认的cursor style
  2085. * @param {string} [cursorStyle='default'] 例如 crosshair
  2086. */
  2087. setCursorStyle: function (cursorStyle) {
  2088. var proxy = this.proxy;
  2089. proxy.setCursor && proxy.setCursor(cursorStyle);
  2090. },
  2091. /**
  2092. * 事件分发代理
  2093. *
  2094. * @private
  2095. * @param {Object} targetInfo {target, topTarget} 目标图形元素
  2096. * @param {string} eventName 事件名称
  2097. * @param {Object} event 事件对象
  2098. */
  2099. dispatchToElement: function (targetInfo, eventName, event) {
  2100. targetInfo = targetInfo || {};
  2101. var el = targetInfo.target;
  2102. if (el && el.silent) {
  2103. return;
  2104. }
  2105. var eventHandler = 'on' + eventName;
  2106. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2107. while (el) {
  2108. el[eventHandler] && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  2109. el.trigger(eventName, eventPacket);
  2110. el = el.parent;
  2111. if (eventPacket.cancelBubble) {
  2112. break;
  2113. }
  2114. }
  2115. if (!eventPacket.cancelBubble) {
  2116. // 冒泡到顶级 zrender 对象
  2117. this.trigger(eventName, eventPacket); // 分发事件到用户自定义层
  2118. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  2119. this.painter && this.painter.eachOtherLayer(function (layer) {
  2120. if (typeof layer[eventHandler] === 'function') {
  2121. layer[eventHandler].call(layer, eventPacket);
  2122. }
  2123. if (layer.trigger) {
  2124. layer.trigger(eventName, eventPacket);
  2125. }
  2126. });
  2127. }
  2128. },
  2129. /**
  2130. * @private
  2131. * @param {number} x
  2132. * @param {number} y
  2133. * @param {module:zrender/graphic/Displayable} exclude
  2134. * @return {model:zrender/Element}
  2135. * @method
  2136. */
  2137. findHover: function (x, y, exclude) {
  2138. var list = this.storage.getDisplayList();
  2139. var out = {
  2140. x: x,
  2141. y: y
  2142. };
  2143. for (var i = list.length - 1; i >= 0; i--) {
  2144. var hoverCheckResult;
  2145. if (list[i] !== exclude // getDisplayList may include ignored item in VML mode
  2146. && !list[i].ignore && (hoverCheckResult = isHover(list[i], x, y))) {
  2147. !out.topTarget && (out.topTarget = list[i]);
  2148. if (hoverCheckResult !== SILENT) {
  2149. out.target = list[i];
  2150. break;
  2151. }
  2152. }
  2153. }
  2154. return out;
  2155. },
  2156. processGesture: function (event, stage) {
  2157. if (!this._gestureMgr) {
  2158. this._gestureMgr = new GestureMgr();
  2159. }
  2160. var gestureMgr = this._gestureMgr;
  2161. stage === 'start' && gestureMgr.clear();
  2162. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2163. stage === 'end' && gestureMgr.clear(); // Do not do any preventDefault here. Upper application do that if necessary.
  2164. if (gestureInfo) {
  2165. var type = gestureInfo.type;
  2166. event.gestureEvent = type;
  2167. this.dispatchToElement({
  2168. target: gestureInfo.target
  2169. }, type, gestureInfo.event);
  2170. }
  2171. }
  2172. }; // Common handlers
  2173. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2174. Handler.prototype[name] = function (event) {
  2175. var x = event.zrX;
  2176. var y = event.zrY;
  2177. var isOutside = isOutsideBoundary(this, x, y);
  2178. var hovered;
  2179. var hoveredTarget;
  2180. if (name !== 'mouseup' || !isOutside) {
  2181. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  2182. hovered = this.findHover(x, y);
  2183. hoveredTarget = hovered.target;
  2184. }
  2185. if (name === 'mousedown') {
  2186. this._downEl = hoveredTarget;
  2187. this._downPoint = [event.zrX, event.zrY]; // In case click triggered before mouseup
  2188. this._upEl = hoveredTarget;
  2189. } else if (name === 'mouseup') {
  2190. this._upEl = hoveredTarget;
  2191. } else if (name === 'click') {
  2192. if (this._downEl !== this._upEl // Original click event is triggered on the whole canvas element,
  2193. // including the case that `mousedown` - `mousemove` - `mouseup`,
  2194. // which should be filtered, otherwise it will bring trouble to
  2195. // pan and zoom.
  2196. || !this._downPoint // Arbitrary value
  2197. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2198. return;
  2199. }
  2200. this._downPoint = null;
  2201. }
  2202. this.dispatchToElement(hovered, name, event);
  2203. };
  2204. });
  2205. function isHover(displayable, x, y) {
  2206. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2207. var el = displayable;
  2208. var isSilent;
  2209. while (el) {
  2210. // If clipped by ancestor.
  2211. // FIXME: If clipPath has neither stroke nor fill,
  2212. // el.clipPath.contain(x, y) will always return false.
  2213. if (el.clipPath && !el.clipPath.contain(x, y)) {
  2214. return false;
  2215. }
  2216. if (el.silent) {
  2217. isSilent = true;
  2218. }
  2219. el = el.parent;
  2220. }
  2221. return isSilent ? SILENT : true;
  2222. }
  2223. return false;
  2224. }
  2225. /**
  2226. * See [Drag outside].
  2227. */
  2228. function isOutsideBoundary(handlerInstance, x, y) {
  2229. var painter = handlerInstance.painter;
  2230. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2231. }
  2232. mixin(Handler, Eventful);
  2233. mixin(Handler, Draggable);
  2234. /**
  2235. * 3x2矩阵操作类
  2236. * @exports zrender/tool/matrix
  2237. */
  2238. /* global Float32Array */
  2239. var ArrayCtor$1 = typeof Float32Array === 'undefined' ? Array : Float32Array;
  2240. /**
  2241. * Create a identity matrix.
  2242. * @return {Float32Array|Array.<number>}
  2243. */
  2244. function create$1() {
  2245. var out = new ArrayCtor$1(6);
  2246. identity(out);
  2247. return out;
  2248. }
  2249. /**
  2250. * 设置矩阵为单位矩阵
  2251. * @param {Float32Array|Array.<number>} out
  2252. */
  2253. function identity(out) {
  2254. out[0] = 1;
  2255. out[1] = 0;
  2256. out[2] = 0;
  2257. out[3] = 1;
  2258. out[4] = 0;
  2259. out[5] = 0;
  2260. return out;
  2261. }
  2262. /**
  2263. * 复制矩阵
  2264. * @param {Float32Array|Array.<number>} out
  2265. * @param {Float32Array|Array.<number>} m
  2266. */
  2267. function copy$1(out, m) {
  2268. out[0] = m[0];
  2269. out[1] = m[1];
  2270. out[2] = m[2];
  2271. out[3] = m[3];
  2272. out[4] = m[4];
  2273. out[5] = m[5];
  2274. return out;
  2275. }
  2276. /**
  2277. * 矩阵相乘
  2278. * @param {Float32Array|Array.<number>} out
  2279. * @param {Float32Array|Array.<number>} m1
  2280. * @param {Float32Array|Array.<number>} m2
  2281. */
  2282. function mul$1(out, m1, m2) {
  2283. // Consider matrix.mul(m, m2, m);
  2284. // where out is the same as m2.
  2285. // So use temp variable to escape error.
  2286. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  2287. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  2288. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  2289. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  2290. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  2291. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  2292. out[0] = out0;
  2293. out[1] = out1;
  2294. out[2] = out2;
  2295. out[3] = out3;
  2296. out[4] = out4;
  2297. out[5] = out5;
  2298. return out;
  2299. }
  2300. /**
  2301. * 平移变换
  2302. * @param {Float32Array|Array.<number>} out
  2303. * @param {Float32Array|Array.<number>} a
  2304. * @param {Float32Array|Array.<number>} v
  2305. */
  2306. function translate(out, a, v) {
  2307. out[0] = a[0];
  2308. out[1] = a[1];
  2309. out[2] = a[2];
  2310. out[3] = a[3];
  2311. out[4] = a[4] + v[0];
  2312. out[5] = a[5] + v[1];
  2313. return out;
  2314. }
  2315. /**
  2316. * 旋转变换
  2317. * @param {Float32Array|Array.<number>} out
  2318. * @param {Float32Array|Array.<number>} a
  2319. * @param {number} rad
  2320. */
  2321. function rotate(out, a, rad) {
  2322. var aa = a[0];
  2323. var ac = a[2];
  2324. var atx = a[4];
  2325. var ab = a[1];
  2326. var ad = a[3];
  2327. var aty = a[5];
  2328. var st = Math.sin(rad);
  2329. var ct = Math.cos(rad);
  2330. out[0] = aa * ct + ab * st;
  2331. out[1] = -aa * st + ab * ct;
  2332. out[2] = ac * ct + ad * st;
  2333. out[3] = -ac * st + ct * ad;
  2334. out[4] = ct * atx + st * aty;
  2335. out[5] = ct * aty - st * atx;
  2336. return out;
  2337. }
  2338. /**
  2339. * 缩放变换
  2340. * @param {Float32Array|Array.<number>} out
  2341. * @param {Float32Array|Array.<number>} a
  2342. * @param {Float32Array|Array.<number>} v
  2343. */
  2344. function scale$1(out, a, v) {
  2345. var vx = v[0];
  2346. var vy = v[1];
  2347. out[0] = a[0] * vx;
  2348. out[1] = a[1] * vy;
  2349. out[2] = a[2] * vx;
  2350. out[3] = a[3] * vy;
  2351. out[4] = a[4] * vx;
  2352. out[5] = a[5] * vy;
  2353. return out;
  2354. }
  2355. /**
  2356. * 求逆矩阵
  2357. * @param {Float32Array|Array.<number>} out
  2358. * @param {Float32Array|Array.<number>} a
  2359. */
  2360. function invert(out, a) {
  2361. var aa = a[0];
  2362. var ac = a[2];
  2363. var atx = a[4];
  2364. var ab = a[1];
  2365. var ad = a[3];
  2366. var aty = a[5];
  2367. var det = aa * ad - ab * ac;
  2368. if (!det) {
  2369. return null;
  2370. }
  2371. det = 1.0 / det;
  2372. out[0] = ad * det;
  2373. out[1] = -ab * det;
  2374. out[2] = -ac * det;
  2375. out[3] = aa * det;
  2376. out[4] = (ac * aty - ad * atx) * det;
  2377. out[5] = (ab * atx - aa * aty) * det;
  2378. return out;
  2379. }
  2380. /**
  2381. * Clone a new matrix.
  2382. * @param {Float32Array|Array.<number>} a
  2383. */
  2384. function clone$2(a) {
  2385. var b = create$1();
  2386. copy$1(b, a);
  2387. return b;
  2388. }
  2389. var matrix = (Object.freeze || Object)({
  2390. create: create$1,
  2391. identity: identity,
  2392. copy: copy$1,
  2393. mul: mul$1,
  2394. translate: translate,
  2395. rotate: rotate,
  2396. scale: scale$1,
  2397. invert: invert,
  2398. clone: clone$2
  2399. });
  2400. /**
  2401. * 提供变换扩展
  2402. * @module zrender/mixin/Transformable
  2403. * @author pissang (https://www.github.com/pissang)
  2404. */
  2405. var mIdentity = identity;
  2406. var EPSILON = 5e-5;
  2407. function isNotAroundZero(val) {
  2408. return val > EPSILON || val < -EPSILON;
  2409. }
  2410. /**
  2411. * @alias module:zrender/mixin/Transformable
  2412. * @constructor
  2413. */
  2414. var Transformable = function (opts) {
  2415. opts = opts || {}; // If there are no given position, rotation, scale
  2416. if (!opts.position) {
  2417. /**
  2418. * 平移
  2419. * @type {Array.<number>}
  2420. * @default [0, 0]
  2421. */
  2422. this.position = [0, 0];
  2423. }
  2424. if (opts.rotation == null) {
  2425. /**
  2426. * 旋转
  2427. * @type {Array.<number>}
  2428. * @default 0
  2429. */
  2430. this.rotation = 0;
  2431. }
  2432. if (!opts.scale) {
  2433. /**
  2434. * 缩放
  2435. * @type {Array.<number>}
  2436. * @default [1, 1]
  2437. */
  2438. this.scale = [1, 1];
  2439. }
  2440. /**
  2441. * 旋转和缩放的原点
  2442. * @type {Array.<number>}
  2443. * @default null
  2444. */
  2445. this.origin = this.origin || null;
  2446. };
  2447. var transformableProto = Transformable.prototype;
  2448. transformableProto.transform = null;
  2449. /**
  2450. * 判断是否需要有坐标变换
  2451. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  2452. */
  2453. transformableProto.needLocalTransform = function () {
  2454. return isNotAroundZero(this.rotation) || isNotAroundZero(this.position[0]) || isNotAroundZero(this.position[1]) || isNotAroundZero(this.scale[0] - 1) || isNotAroundZero(this.scale[1] - 1);
  2455. };
  2456. var scaleTmp = [];
  2457. transformableProto.updateTransform = function () {
  2458. var parent = this.parent;
  2459. var parentHasTransform = parent && parent.transform;
  2460. var needLocalTransform = this.needLocalTransform();
  2461. var m = this.transform;
  2462. if (!(needLocalTransform || parentHasTransform)) {
  2463. m && mIdentity(m);
  2464. return;
  2465. }
  2466. m = m || create$1();
  2467. if (needLocalTransform) {
  2468. this.getLocalTransform(m);
  2469. } else {
  2470. mIdentity(m);
  2471. } // 应用父节点变换
  2472. if (parentHasTransform) {
  2473. if (needLocalTransform) {
  2474. mul$1(m, parent.transform, m);
  2475. } else {
  2476. copy$1(m, parent.transform);
  2477. }
  2478. } // 保存这个变换矩阵
  2479. this.transform = m;
  2480. var globalScaleRatio = this.globalScaleRatio;
  2481. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  2482. this.getGlobalScale(scaleTmp);
  2483. var relX = scaleTmp[0] < 0 ? -1 : 1;
  2484. var relY = scaleTmp[1] < 0 ? -1 : 1;
  2485. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  2486. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  2487. m[0] *= sx;
  2488. m[1] *= sx;
  2489. m[2] *= sy;
  2490. m[3] *= sy;
  2491. }
  2492. this.invTransform = this.invTransform || create$1();
  2493. invert(this.invTransform, m);
  2494. };
  2495. transformableProto.getLocalTransform = function (m) {
  2496. return Transformable.getLocalTransform(this, m);
  2497. };
  2498. /**
  2499. * 将自己的transform应用到context上
  2500. * @param {CanvasRenderingContext2D} ctx
  2501. */
  2502. transformableProto.setTransform = function (ctx) {
  2503. var m = this.transform;
  2504. var dpr = ctx.dpr || 1;
  2505. if (m) {
  2506. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  2507. } else {
  2508. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2509. }
  2510. };
  2511. transformableProto.restoreTransform = function (ctx) {
  2512. var dpr = ctx.dpr || 1;
  2513. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2514. };
  2515. var tmpTransform = [];
  2516. var originTransform = create$1();
  2517. transformableProto.setLocalTransform = function (m) {
  2518. if (!m) {
  2519. // TODO return or set identity?
  2520. return;
  2521. }
  2522. var sx = m[0] * m[0] + m[1] * m[1];
  2523. var sy = m[2] * m[2] + m[3] * m[3];
  2524. var position = this.position;
  2525. var scale$$1 = this.scale;
  2526. if (isNotAroundZero(sx - 1)) {
  2527. sx = Math.sqrt(sx);
  2528. }
  2529. if (isNotAroundZero(sy - 1)) {
  2530. sy = Math.sqrt(sy);
  2531. }
  2532. if (m[0] < 0) {
  2533. sx = -sx;
  2534. }
  2535. if (m[3] < 0) {
  2536. sy = -sy;
  2537. }
  2538. position[0] = m[4];
  2539. position[1] = m[5];
  2540. scale$$1[0] = sx;
  2541. scale$$1[1] = sy;
  2542. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  2543. };
  2544. /**
  2545. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  2546. */
  2547. transformableProto.decomposeTransform = function () {
  2548. if (!this.transform) {
  2549. return;
  2550. }
  2551. var parent = this.parent;
  2552. var m = this.transform;
  2553. if (parent && parent.transform) {
  2554. // Get local transform and decompose them to position, scale, rotation
  2555. mul$1(tmpTransform, parent.invTransform, m);
  2556. m = tmpTransform;
  2557. }
  2558. var origin = this.origin;
  2559. if (origin && (origin[0] || origin[1])) {
  2560. originTransform[4] = origin[0];
  2561. originTransform[5] = origin[1];
  2562. mul$1(tmpTransform, m, originTransform);
  2563. tmpTransform[4] -= origin[0];
  2564. tmpTransform[5] -= origin[1];
  2565. m = tmpTransform;
  2566. }
  2567. this.setLocalTransform(m);
  2568. };
  2569. /**
  2570. * Get global scale
  2571. * @return {Array.<number>}
  2572. */
  2573. transformableProto.getGlobalScale = function (out) {
  2574. var m = this.transform;
  2575. out = out || [];
  2576. if (!m) {
  2577. out[0] = 1;
  2578. out[1] = 1;
  2579. return out;
  2580. }
  2581. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  2582. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  2583. if (m[0] < 0) {
  2584. out[0] = -out[0];
  2585. }
  2586. if (m[3] < 0) {
  2587. out[1] = -out[1];
  2588. }
  2589. return out;
  2590. };
  2591. /**
  2592. * 变换坐标位置到 shape 的局部坐标空间
  2593. * @method
  2594. * @param {number} x
  2595. * @param {number} y
  2596. * @return {Array.<number>}
  2597. */
  2598. transformableProto.transformCoordToLocal = function (x, y) {
  2599. var v2 = [x, y];
  2600. var invTransform = this.invTransform;
  2601. if (invTransform) {
  2602. applyTransform(v2, v2, invTransform);
  2603. }
  2604. return v2;
  2605. };
  2606. /**
  2607. * 变换局部坐标位置到全局坐标空间
  2608. * @method
  2609. * @param {number} x
  2610. * @param {number} y
  2611. * @return {Array.<number>}
  2612. */
  2613. transformableProto.transformCoordToGlobal = function (x, y) {
  2614. var v2 = [x, y];
  2615. var transform = this.transform;
  2616. if (transform) {
  2617. applyTransform(v2, v2, transform);
  2618. }
  2619. return v2;
  2620. };
  2621. /**
  2622. * @static
  2623. * @param {Object} target
  2624. * @param {Array.<number>} target.origin
  2625. * @param {number} target.rotation
  2626. * @param {Array.<number>} target.position
  2627. * @param {Array.<number>} [m]
  2628. */
  2629. Transformable.getLocalTransform = function (target, m) {
  2630. m = m || [];
  2631. mIdentity(m);
  2632. var origin = target.origin;
  2633. var scale$$1 = target.scale || [1, 1];
  2634. var rotation = target.rotation || 0;
  2635. var position = target.position || [0, 0];
  2636. if (origin) {
  2637. // Translate to origin
  2638. m[4] -= origin[0];
  2639. m[5] -= origin[1];
  2640. }
  2641. scale$1(m, m, scale$$1);
  2642. if (rotation) {
  2643. rotate(m, m, rotation);
  2644. }
  2645. if (origin) {
  2646. // Translate back from origin
  2647. m[4] += origin[0];
  2648. m[5] += origin[1];
  2649. }
  2650. m[4] += position[0];
  2651. m[5] += position[1];
  2652. return m;
  2653. };
  2654. /**
  2655. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  2656. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  2657. * @exports zrender/animation/easing
  2658. */
  2659. var easing = {
  2660. /**
  2661. * @param {number} k
  2662. * @return {number}
  2663. */
  2664. linear: function (k) {
  2665. return k;
  2666. },
  2667. /**
  2668. * @param {number} k
  2669. * @return {number}
  2670. */
  2671. quadraticIn: function (k) {
  2672. return k * k;
  2673. },
  2674. /**
  2675. * @param {number} k
  2676. * @return {number}
  2677. */
  2678. quadraticOut: function (k) {
  2679. return k * (2 - k);
  2680. },
  2681. /**
  2682. * @param {number} k
  2683. * @return {number}
  2684. */
  2685. quadraticInOut: function (k) {
  2686. if ((k *= 2) < 1) {
  2687. return 0.5 * k * k;
  2688. }
  2689. return -0.5 * (--k * (k - 2) - 1);
  2690. },
  2691. // 三次方的缓动(t^3)
  2692. /**
  2693. * @param {number} k
  2694. * @return {number}
  2695. */
  2696. cubicIn: function (k) {
  2697. return k * k * k;
  2698. },
  2699. /**
  2700. * @param {number} k
  2701. * @return {number}
  2702. */
  2703. cubicOut: function (k) {
  2704. return --k * k * k + 1;
  2705. },
  2706. /**
  2707. * @param {number} k
  2708. * @return {number}
  2709. */
  2710. cubicInOut: function (k) {
  2711. if ((k *= 2) < 1) {
  2712. return 0.5 * k * k * k;
  2713. }
  2714. return 0.5 * ((k -= 2) * k * k + 2);
  2715. },
  2716. // 四次方的缓动(t^4)
  2717. /**
  2718. * @param {number} k
  2719. * @return {number}
  2720. */
  2721. quarticIn: function (k) {
  2722. return k * k * k * k;
  2723. },
  2724. /**
  2725. * @param {number} k
  2726. * @return {number}
  2727. */
  2728. quarticOut: function (k) {
  2729. return 1 - --k * k * k * k;
  2730. },
  2731. /**
  2732. * @param {number} k
  2733. * @return {number}
  2734. */
  2735. quarticInOut: function (k) {
  2736. if ((k *= 2) < 1) {
  2737. return 0.5 * k * k * k * k;
  2738. }
  2739. return -0.5 * ((k -= 2) * k * k * k - 2);
  2740. },
  2741. // 五次方的缓动(t^5)
  2742. /**
  2743. * @param {number} k
  2744. * @return {number}
  2745. */
  2746. quinticIn: function (k) {
  2747. return k * k * k * k * k;
  2748. },
  2749. /**
  2750. * @param {number} k
  2751. * @return {number}
  2752. */
  2753. quinticOut: function (k) {
  2754. return --k * k * k * k * k + 1;
  2755. },
  2756. /**
  2757. * @param {number} k
  2758. * @return {number}
  2759. */
  2760. quinticInOut: function (k) {
  2761. if ((k *= 2) < 1) {
  2762. return 0.5 * k * k * k * k * k;
  2763. }
  2764. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2765. },
  2766. // 正弦曲线的缓动(sin(t))
  2767. /**
  2768. * @param {number} k
  2769. * @return {number}
  2770. */
  2771. sinusoidalIn: function (k) {
  2772. return 1 - Math.cos(k * Math.PI / 2);
  2773. },
  2774. /**
  2775. * @param {number} k
  2776. * @return {number}
  2777. */
  2778. sinusoidalOut: function (k) {
  2779. return Math.sin(k * Math.PI / 2);
  2780. },
  2781. /**
  2782. * @param {number} k
  2783. * @return {number}
  2784. */
  2785. sinusoidalInOut: function (k) {
  2786. return 0.5 * (1 - Math.cos(Math.PI * k));
  2787. },
  2788. // 指数曲线的缓动(2^t)
  2789. /**
  2790. * @param {number} k
  2791. * @return {number}
  2792. */
  2793. exponentialIn: function (k) {
  2794. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2795. },
  2796. /**
  2797. * @param {number} k
  2798. * @return {number}
  2799. */
  2800. exponentialOut: function (k) {
  2801. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2802. },
  2803. /**
  2804. * @param {number} k
  2805. * @return {number}
  2806. */
  2807. exponentialInOut: function (k) {
  2808. if (k === 0) {
  2809. return 0;
  2810. }
  2811. if (k === 1) {
  2812. return 1;
  2813. }
  2814. if ((k *= 2) < 1) {
  2815. return 0.5 * Math.pow(1024, k - 1);
  2816. }
  2817. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2818. },
  2819. // 圆形曲线的缓动(sqrt(1-t^2))
  2820. /**
  2821. * @param {number} k
  2822. * @return {number}
  2823. */
  2824. circularIn: function (k) {
  2825. return 1 - Math.sqrt(1 - k * k);
  2826. },
  2827. /**
  2828. * @param {number} k
  2829. * @return {number}
  2830. */
  2831. circularOut: function (k) {
  2832. return Math.sqrt(1 - --k * k);
  2833. },
  2834. /**
  2835. * @param {number} k
  2836. * @return {number}
  2837. */
  2838. circularInOut: function (k) {
  2839. if ((k *= 2) < 1) {
  2840. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2841. }
  2842. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2843. },
  2844. // 创建类似于弹簧在停止前来回振荡的动画
  2845. /**
  2846. * @param {number} k
  2847. * @return {number}
  2848. */
  2849. elasticIn: function (k) {
  2850. var s;
  2851. var a = 0.1;
  2852. var p = 0.4;
  2853. if (k === 0) {
  2854. return 0;
  2855. }
  2856. if (k === 1) {
  2857. return 1;
  2858. }
  2859. if (!a || a < 1) {
  2860. a = 1;
  2861. s = p / 4;
  2862. } else {
  2863. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2864. }
  2865. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  2866. },
  2867. /**
  2868. * @param {number} k
  2869. * @return {number}
  2870. */
  2871. elasticOut: function (k) {
  2872. var s;
  2873. var a = 0.1;
  2874. var p = 0.4;
  2875. if (k === 0) {
  2876. return 0;
  2877. }
  2878. if (k === 1) {
  2879. return 1;
  2880. }
  2881. if (!a || a < 1) {
  2882. a = 1;
  2883. s = p / 4;
  2884. } else {
  2885. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2886. }
  2887. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  2888. },
  2889. /**
  2890. * @param {number} k
  2891. * @return {number}
  2892. */
  2893. elasticInOut: function (k) {
  2894. var s;
  2895. var a = 0.1;
  2896. var p = 0.4;
  2897. if (k === 0) {
  2898. return 0;
  2899. }
  2900. if (k === 1) {
  2901. return 1;
  2902. }
  2903. if (!a || a < 1) {
  2904. a = 1;
  2905. s = p / 4;
  2906. } else {
  2907. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2908. }
  2909. if ((k *= 2) < 1) {
  2910. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  2911. }
  2912. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  2913. },
  2914. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  2915. /**
  2916. * @param {number} k
  2917. * @return {number}
  2918. */
  2919. backIn: function (k) {
  2920. var s = 1.70158;
  2921. return k * k * ((s + 1) * k - s);
  2922. },
  2923. /**
  2924. * @param {number} k
  2925. * @return {number}
  2926. */
  2927. backOut: function (k) {
  2928. var s = 1.70158;
  2929. return --k * k * ((s + 1) * k + s) + 1;
  2930. },
  2931. /**
  2932. * @param {number} k
  2933. * @return {number}
  2934. */
  2935. backInOut: function (k) {
  2936. var s = 1.70158 * 1.525;
  2937. if ((k *= 2) < 1) {
  2938. return 0.5 * (k * k * ((s + 1) * k - s));
  2939. }
  2940. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2941. },
  2942. // 创建弹跳效果
  2943. /**
  2944. * @param {number} k
  2945. * @return {number}
  2946. */
  2947. bounceIn: function (k) {
  2948. return 1 - easing.bounceOut(1 - k);
  2949. },
  2950. /**
  2951. * @param {number} k
  2952. * @return {number}
  2953. */
  2954. bounceOut: function (k) {
  2955. if (k < 1 / 2.75) {
  2956. return 7.5625 * k * k;
  2957. } else if (k < 2 / 2.75) {
  2958. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  2959. } else if (k < 2.5 / 2.75) {
  2960. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  2961. } else {
  2962. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  2963. }
  2964. },
  2965. /**
  2966. * @param {number} k
  2967. * @return {number}
  2968. */
  2969. bounceInOut: function (k) {
  2970. if (k < 0.5) {
  2971. return easing.bounceIn(k * 2) * 0.5;
  2972. }
  2973. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  2974. }
  2975. };
  2976. /**
  2977. * 动画主控制器
  2978. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  2979. * @config life(1000) 动画时长
  2980. * @config delay(0) 动画延迟时间
  2981. * @config loop(true)
  2982. * @config gap(0) 循环的间隔时间
  2983. * @config onframe
  2984. * @config easing(optional)
  2985. * @config ondestroy(optional)
  2986. * @config onrestart(optional)
  2987. *
  2988. * TODO pause
  2989. */
  2990. function Clip(options) {
  2991. this._target = options.target; // 生命周期
  2992. this._life = options.life || 1000; // 延时
  2993. this._delay = options.delay || 0; // 开始时间
  2994. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  2995. this._initialized = false; // 是否循环
  2996. this.loop = options.loop == null ? false : options.loop;
  2997. this.gap = options.gap || 0;
  2998. this.easing = options.easing || 'Linear';
  2999. this.onframe = options.onframe;
  3000. this.ondestroy = options.ondestroy;
  3001. this.onrestart = options.onrestart;
  3002. this._pausedTime = 0;
  3003. this._paused = false;
  3004. }
  3005. Clip.prototype = {
  3006. constructor: Clip,
  3007. step: function (globalTime, deltaTime) {
  3008. // Set startTime on first step, or _startTime may has milleseconds different between clips
  3009. // PENDING
  3010. if (!this._initialized) {
  3011. this._startTime = globalTime + this._delay;
  3012. this._initialized = true;
  3013. }
  3014. if (this._paused) {
  3015. this._pausedTime += deltaTime;
  3016. return;
  3017. }
  3018. var percent = (globalTime - this._startTime - this._pausedTime) / this._life; // 还没开始
  3019. if (percent < 0) {
  3020. return;
  3021. }
  3022. percent = Math.min(percent, 1);
  3023. var easing$$1 = this.easing;
  3024. var easingFunc = typeof easing$$1 === 'string' ? easing[easing$$1] : easing$$1;
  3025. var schedule = typeof easingFunc === 'function' ? easingFunc(percent) : percent;
  3026. this.fire('frame', schedule); // 结束
  3027. if (percent === 1) {
  3028. if (this.loop) {
  3029. this.restart(globalTime); // 重新开始周期
  3030. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  3031. return 'restart';
  3032. } // 动画完成将这个控制器标识为待删除
  3033. // 在Animation.update中进行批量删除
  3034. this._needsRemove = true;
  3035. return 'destroy';
  3036. }
  3037. return null;
  3038. },
  3039. restart: function (globalTime) {
  3040. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  3041. this._startTime = globalTime - remainder + this.gap;
  3042. this._pausedTime = 0;
  3043. this._needsRemove = false;
  3044. },
  3045. fire: function (eventType, arg) {
  3046. eventType = 'on' + eventType;
  3047. if (this[eventType]) {
  3048. this[eventType](this._target, arg);
  3049. }
  3050. },
  3051. pause: function () {
  3052. this._paused = true;
  3053. },
  3054. resume: function () {
  3055. this._paused = false;
  3056. }
  3057. }; // Simple LRU cache use doubly linked list
  3058. // @module zrender/core/LRU
  3059. /**
  3060. * Simple double linked list. Compared with array, it has O(1) remove operation.
  3061. * @constructor
  3062. */
  3063. var LinkedList = function () {
  3064. /**
  3065. * @type {module:zrender/core/LRU~Entry}
  3066. */
  3067. this.head = null;
  3068. /**
  3069. * @type {module:zrender/core/LRU~Entry}
  3070. */
  3071. this.tail = null;
  3072. this._len = 0;
  3073. };
  3074. var linkedListProto = LinkedList.prototype;
  3075. /**
  3076. * Insert a new value at the tail
  3077. * @param {} val
  3078. * @return {module:zrender/core/LRU~Entry}
  3079. */
  3080. linkedListProto.insert = function (val) {
  3081. var entry = new Entry(val);
  3082. this.insertEntry(entry);
  3083. return entry;
  3084. };
  3085. /**
  3086. * Insert an entry at the tail
  3087. * @param {module:zrender/core/LRU~Entry} entry
  3088. */
  3089. linkedListProto.insertEntry = function (entry) {
  3090. if (!this.head) {
  3091. this.head = this.tail = entry;
  3092. } else {
  3093. this.tail.next = entry;
  3094. entry.prev = this.tail;
  3095. entry.next = null;
  3096. this.tail = entry;
  3097. }
  3098. this._len++;
  3099. };
  3100. /**
  3101. * Remove entry.
  3102. * @param {module:zrender/core/LRU~Entry} entry
  3103. */
  3104. linkedListProto.remove = function (entry) {
  3105. var prev = entry.prev;
  3106. var next = entry.next;
  3107. if (prev) {
  3108. prev.next = next;
  3109. } else {
  3110. // Is head
  3111. this.head = next;
  3112. }
  3113. if (next) {
  3114. next.prev = prev;
  3115. } else {
  3116. // Is tail
  3117. this.tail = prev;
  3118. }
  3119. entry.next = entry.prev = null;
  3120. this._len--;
  3121. };
  3122. /**
  3123. * @return {number}
  3124. */
  3125. linkedListProto.len = function () {
  3126. return this._len;
  3127. };
  3128. /**
  3129. * Clear list
  3130. */
  3131. linkedListProto.clear = function () {
  3132. this.head = this.tail = null;
  3133. this._len = 0;
  3134. };
  3135. /**
  3136. * @constructor
  3137. * @param {} val
  3138. */
  3139. var Entry = function (val) {
  3140. /**
  3141. * @type {}
  3142. */
  3143. this.value = val;
  3144. /**
  3145. * @type {module:zrender/core/LRU~Entry}
  3146. */
  3147. this.next;
  3148. /**
  3149. * @type {module:zrender/core/LRU~Entry}
  3150. */
  3151. this.prev;
  3152. };
  3153. /**
  3154. * LRU Cache
  3155. * @constructor
  3156. * @alias module:zrender/core/LRU
  3157. */
  3158. var LRU = function (maxSize) {
  3159. this._list = new LinkedList();
  3160. this._map = {};
  3161. this._maxSize = maxSize || 10;
  3162. this._lastRemovedEntry = null;
  3163. };
  3164. var LRUProto = LRU.prototype;
  3165. /**
  3166. * @param {string} key
  3167. * @param {} value
  3168. * @return {} Removed value
  3169. */
  3170. LRUProto.put = function (key, value) {
  3171. var list = this._list;
  3172. var map = this._map;
  3173. var removed = null;
  3174. if (map[key] == null) {
  3175. var len = list.len(); // Reuse last removed entry
  3176. var entry = this._lastRemovedEntry;
  3177. if (len >= this._maxSize && len > 0) {
  3178. // Remove the least recently used
  3179. var leastUsedEntry = list.head;
  3180. list.remove(leastUsedEntry);
  3181. delete map[leastUsedEntry.key];
  3182. removed = leastUsedEntry.value;
  3183. this._lastRemovedEntry = leastUsedEntry;
  3184. }
  3185. if (entry) {
  3186. entry.value = value;
  3187. } else {
  3188. entry = new Entry(value);
  3189. }
  3190. entry.key = key;
  3191. list.insertEntry(entry);
  3192. map[key] = entry;
  3193. }
  3194. return removed;
  3195. };
  3196. /**
  3197. * @param {string} key
  3198. * @return {}
  3199. */
  3200. LRUProto.get = function (key) {
  3201. var entry = this._map[key];
  3202. var list = this._list;
  3203. if (entry != null) {
  3204. // Put the latest used entry in the tail
  3205. if (entry !== list.tail) {
  3206. list.remove(entry);
  3207. list.insertEntry(entry);
  3208. }
  3209. return entry.value;
  3210. }
  3211. };
  3212. /**
  3213. * Clear the cache
  3214. */
  3215. LRUProto.clear = function () {
  3216. this._list.clear();
  3217. this._map = {};
  3218. };
  3219. var kCSSColorTable = {
  3220. 'transparent': [0, 0, 0, 0],
  3221. 'aliceblue': [240, 248, 255, 1],
  3222. 'antiquewhite': [250, 235, 215, 1],
  3223. 'aqua': [0, 255, 255, 1],
  3224. 'aquamarine': [127, 255, 212, 1],
  3225. 'azure': [240, 255, 255, 1],
  3226. 'beige': [245, 245, 220, 1],
  3227. 'bisque': [255, 228, 196, 1],
  3228. 'black': [0, 0, 0, 1],
  3229. 'blanchedalmond': [255, 235, 205, 1],
  3230. 'blue': [0, 0, 255, 1],
  3231. 'blueviolet': [138, 43, 226, 1],
  3232. 'brown': [165, 42, 42, 1],
  3233. 'burlywood': [222, 184, 135, 1],
  3234. 'cadetblue': [95, 158, 160, 1],
  3235. 'chartreuse': [127, 255, 0, 1],
  3236. 'chocolate': [210, 105, 30, 1],
  3237. 'coral': [255, 127, 80, 1],
  3238. 'cornflowerblue': [100, 149, 237, 1],
  3239. 'cornsilk': [255, 248, 220, 1],
  3240. 'crimson': [220, 20, 60, 1],
  3241. 'cyan': [0, 255, 255, 1],
  3242. 'darkblue': [0, 0, 139, 1],
  3243. 'darkcyan': [0, 139, 139, 1],
  3244. 'darkgoldenrod': [184, 134, 11, 1],
  3245. 'darkgray': [169, 169, 169, 1],
  3246. 'darkgreen': [0, 100, 0, 1],
  3247. 'darkgrey': [169, 169, 169, 1],
  3248. 'darkkhaki': [189, 183, 107, 1],
  3249. 'darkmagenta': [139, 0, 139, 1],
  3250. 'darkolivegreen': [85, 107, 47, 1],
  3251. 'darkorange': [255, 140, 0, 1],
  3252. 'darkorchid': [153, 50, 204, 1],
  3253. 'darkred': [139, 0, 0, 1],
  3254. 'darksalmon': [233, 150, 122, 1],
  3255. 'darkseagreen': [143, 188, 143, 1],
  3256. 'darkslateblue': [72, 61, 139, 1],
  3257. 'darkslategray': [47, 79, 79, 1],
  3258. 'darkslategrey': [47, 79, 79, 1],
  3259. 'darkturquoise': [0, 206, 209, 1],
  3260. 'darkviolet': [148, 0, 211, 1],
  3261. 'deeppink': [255, 20, 147, 1],
  3262. 'deepskyblue': [0, 191, 255, 1],
  3263. 'dimgray': [105, 105, 105, 1],
  3264. 'dimgrey': [105, 105, 105, 1],
  3265. 'dodgerblue': [30, 144, 255, 1],
  3266. 'firebrick': [178, 34, 34, 1],
  3267. 'floralwhite': [255, 250, 240, 1],
  3268. 'forestgreen': [34, 139, 34, 1],
  3269. 'fuchsia': [255, 0, 255, 1],
  3270. 'gainsboro': [220, 220, 220, 1],
  3271. 'ghostwhite': [248, 248, 255, 1],
  3272. 'gold': [255, 215, 0, 1],
  3273. 'goldenrod': [218, 165, 32, 1],
  3274. 'gray': [128, 128, 128, 1],
  3275. 'green': [0, 128, 0, 1],
  3276. 'greenyellow': [173, 255, 47, 1],
  3277. 'grey': [128, 128, 128, 1],
  3278. 'honeydew': [240, 255, 240, 1],
  3279. 'hotpink': [255, 105, 180, 1],
  3280. 'indianred': [205, 92, 92, 1],
  3281. 'indigo': [75, 0, 130, 1],
  3282. 'ivory': [255, 255, 240, 1],
  3283. 'khaki': [240, 230, 140, 1],
  3284. 'lavender': [230, 230, 250, 1],
  3285. 'lavenderblush': [255, 240, 245, 1],
  3286. 'lawngreen': [124, 252, 0, 1],
  3287. 'lemonchiffon': [255, 250, 205, 1],
  3288. 'lightblue': [173, 216, 230, 1],
  3289. 'lightcoral': [240, 128, 128, 1],
  3290. 'lightcyan': [224, 255, 255, 1],
  3291. 'lightgoldenrodyellow': [250, 250, 210, 1],
  3292. 'lightgray': [211, 211, 211, 1],
  3293. 'lightgreen': [144, 238, 144, 1],
  3294. 'lightgrey': [211, 211, 211, 1],
  3295. 'lightpink': [255, 182, 193, 1],
  3296. 'lightsalmon': [255, 160, 122, 1],
  3297. 'lightseagreen': [32, 178, 170, 1],
  3298. 'lightskyblue': [135, 206, 250, 1],
  3299. 'lightslategray': [119, 136, 153, 1],
  3300. 'lightslategrey': [119, 136, 153, 1],
  3301. 'lightsteelblue': [176, 196, 222, 1],
  3302. 'lightyellow': [255, 255, 224, 1],
  3303. 'lime': [0, 255, 0, 1],
  3304. 'limegreen': [50, 205, 50, 1],
  3305. 'linen': [250, 240, 230, 1],
  3306. 'magenta': [255, 0, 255, 1],
  3307. 'maroon': [128, 0, 0, 1],
  3308. 'mediumaquamarine': [102, 205, 170, 1],
  3309. 'mediumblue': [0, 0, 205, 1],
  3310. 'mediumorchid': [186, 85, 211, 1],
  3311. 'mediumpurple': [147, 112, 219, 1],
  3312. 'mediumseagreen': [60, 179, 113, 1],
  3313. 'mediumslateblue': [123, 104, 238, 1],
  3314. 'mediumspringgreen': [0, 250, 154, 1],
  3315. 'mediumturquoise': [72, 209, 204, 1],
  3316. 'mediumvioletred': [199, 21, 133, 1],
  3317. 'midnightblue': [25, 25, 112, 1],
  3318. 'mintcream': [245, 255, 250, 1],
  3319. 'mistyrose': [255, 228, 225, 1],
  3320. 'moccasin': [255, 228, 181, 1],
  3321. 'navajowhite': [255, 222, 173, 1],
  3322. 'navy': [0, 0, 128, 1],
  3323. 'oldlace': [253, 245, 230, 1],
  3324. 'olive': [128, 128, 0, 1],
  3325. 'olivedrab': [107, 142, 35, 1],
  3326. 'orange': [255, 165, 0, 1],
  3327. 'orangered': [255, 69, 0, 1],
  3328. 'orchid': [218, 112, 214, 1],
  3329. 'palegoldenrod': [238, 232, 170, 1],
  3330. 'palegreen': [152, 251, 152, 1],
  3331. 'paleturquoise': [175, 238, 238, 1],
  3332. 'palevioletred': [219, 112, 147, 1],
  3333. 'papayawhip': [255, 239, 213, 1],
  3334. 'peachpuff': [255, 218, 185, 1],
  3335. 'peru': [205, 133, 63, 1],
  3336. 'pink': [255, 192, 203, 1],
  3337. 'plum': [221, 160, 221, 1],
  3338. 'powderblue': [176, 224, 230, 1],
  3339. 'purple': [128, 0, 128, 1],
  3340. 'red': [255, 0, 0, 1],
  3341. 'rosybrown': [188, 143, 143, 1],
  3342. 'royalblue': [65, 105, 225, 1],
  3343. 'saddlebrown': [139, 69, 19, 1],
  3344. 'salmon': [250, 128, 114, 1],
  3345. 'sandybrown': [244, 164, 96, 1],
  3346. 'seagreen': [46, 139, 87, 1],
  3347. 'seashell': [255, 245, 238, 1],
  3348. 'sienna': [160, 82, 45, 1],
  3349. 'silver': [192, 192, 192, 1],
  3350. 'skyblue': [135, 206, 235, 1],
  3351. 'slateblue': [106, 90, 205, 1],
  3352. 'slategray': [112, 128, 144, 1],
  3353. 'slategrey': [112, 128, 144, 1],
  3354. 'snow': [255, 250, 250, 1],
  3355. 'springgreen': [0, 255, 127, 1],
  3356. 'steelblue': [70, 130, 180, 1],
  3357. 'tan': [210, 180, 140, 1],
  3358. 'teal': [0, 128, 128, 1],
  3359. 'thistle': [216, 191, 216, 1],
  3360. 'tomato': [255, 99, 71, 1],
  3361. 'turquoise': [64, 224, 208, 1],
  3362. 'violet': [238, 130, 238, 1],
  3363. 'wheat': [245, 222, 179, 1],
  3364. 'white': [255, 255, 255, 1],
  3365. 'whitesmoke': [245, 245, 245, 1],
  3366. 'yellow': [255, 255, 0, 1],
  3367. 'yellowgreen': [154, 205, 50, 1]
  3368. };
  3369. function clampCssByte(i) {
  3370. // Clamp to integer 0 .. 255.
  3371. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3372. return i < 0 ? 0 : i > 255 ? 255 : i;
  3373. }
  3374. function clampCssAngle(i) {
  3375. // Clamp to integer 0 .. 360.
  3376. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3377. return i < 0 ? 0 : i > 360 ? 360 : i;
  3378. }
  3379. function clampCssFloat(f) {
  3380. // Clamp to float 0.0 .. 1.0.
  3381. return f < 0 ? 0 : f > 1 ? 1 : f;
  3382. }
  3383. function parseCssInt(str) {
  3384. // int or percentage.
  3385. if (str.length && str.charAt(str.length - 1) === '%') {
  3386. return clampCssByte(parseFloat(str) / 100 * 255);
  3387. }
  3388. return clampCssByte(parseInt(str, 10));
  3389. }
  3390. function parseCssFloat(str) {
  3391. // float or percentage.
  3392. if (str.length && str.charAt(str.length - 1) === '%') {
  3393. return clampCssFloat(parseFloat(str) / 100);
  3394. }
  3395. return clampCssFloat(parseFloat(str));
  3396. }
  3397. function cssHueToRgb(m1, m2, h) {
  3398. if (h < 0) {
  3399. h += 1;
  3400. } else if (h > 1) {
  3401. h -= 1;
  3402. }
  3403. if (h * 6 < 1) {
  3404. return m1 + (m2 - m1) * h * 6;
  3405. }
  3406. if (h * 2 < 1) {
  3407. return m2;
  3408. }
  3409. if (h * 3 < 2) {
  3410. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3411. }
  3412. return m1;
  3413. }
  3414. function lerpNumber(a, b, p) {
  3415. return a + (b - a) * p;
  3416. }
  3417. function setRgba(out, r, g, b, a) {
  3418. out[0] = r;
  3419. out[1] = g;
  3420. out[2] = b;
  3421. out[3] = a;
  3422. return out;
  3423. }
  3424. function copyRgba(out, a) {
  3425. out[0] = a[0];
  3426. out[1] = a[1];
  3427. out[2] = a[2];
  3428. out[3] = a[3];
  3429. return out;
  3430. }
  3431. var colorCache = new LRU(20);
  3432. var lastRemovedArr = null;
  3433. function putToCache(colorStr, rgbaArr) {
  3434. // Reuse removed array
  3435. if (lastRemovedArr) {
  3436. copyRgba(lastRemovedArr, rgbaArr);
  3437. }
  3438. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || rgbaArr.slice());
  3439. }
  3440. /**
  3441. * @param {string} colorStr
  3442. * @param {Array.<number>} out
  3443. * @return {Array.<number>}
  3444. * @memberOf module:zrender/util/color
  3445. */
  3446. function parse(colorStr, rgbaArr) {
  3447. if (!colorStr) {
  3448. return;
  3449. }
  3450. rgbaArr = rgbaArr || [];
  3451. var cached = colorCache.get(colorStr);
  3452. if (cached) {
  3453. return copyRgba(rgbaArr, cached);
  3454. } // colorStr may be not string
  3455. colorStr = colorStr + ''; // Remove all whitespace, not compliant, but should just be more accepting.
  3456. var str = colorStr.replace(/ /g, '').toLowerCase(); // Color keywords (and transparent) lookup.
  3457. if (str in kCSSColorTable) {
  3458. copyRgba(rgbaArr, kCSSColorTable[str]);
  3459. putToCache(colorStr, rgbaArr);
  3460. return rgbaArr;
  3461. } // #abc and #abc123 syntax.
  3462. if (str.charAt(0) === '#') {
  3463. if (str.length === 4) {
  3464. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3465. if (!(iv >= 0 && iv <= 0xfff)) {
  3466. setRgba(rgbaArr, 0, 0, 0, 1);
  3467. return; // Covers NaN.
  3468. }
  3469. setRgba(rgbaArr, (iv & 0xf00) >> 4 | (iv & 0xf00) >> 8, iv & 0xf0 | (iv & 0xf0) >> 4, iv & 0xf | (iv & 0xf) << 4, 1);
  3470. putToCache(colorStr, rgbaArr);
  3471. return rgbaArr;
  3472. } else if (str.length === 7) {
  3473. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3474. if (!(iv >= 0 && iv <= 0xffffff)) {
  3475. setRgba(rgbaArr, 0, 0, 0, 1);
  3476. return; // Covers NaN.
  3477. }
  3478. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, 1);
  3479. putToCache(colorStr, rgbaArr);
  3480. return rgbaArr;
  3481. }
  3482. return;
  3483. }
  3484. var op = str.indexOf('(');
  3485. var ep = str.indexOf(')');
  3486. if (op !== -1 && ep + 1 === str.length) {
  3487. var fname = str.substr(0, op);
  3488. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3489. var alpha = 1; // To allow case fallthrough.
  3490. switch (fname) {
  3491. case 'rgba':
  3492. if (params.length !== 4) {
  3493. setRgba(rgbaArr, 0, 0, 0, 1);
  3494. return;
  3495. }
  3496. alpha = parseCssFloat(params.pop());
  3497. // jshint ignore:line
  3498. // Fall through.
  3499. case 'rgb':
  3500. if (params.length !== 3) {
  3501. setRgba(rgbaArr, 0, 0, 0, 1);
  3502. return;
  3503. }
  3504. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), alpha);
  3505. putToCache(colorStr, rgbaArr);
  3506. return rgbaArr;
  3507. case 'hsla':
  3508. if (params.length !== 4) {
  3509. setRgba(rgbaArr, 0, 0, 0, 1);
  3510. return;
  3511. }
  3512. params[3] = parseCssFloat(params[3]);
  3513. hsla2rgba(params, rgbaArr);
  3514. putToCache(colorStr, rgbaArr);
  3515. return rgbaArr;
  3516. case 'hsl':
  3517. if (params.length !== 3) {
  3518. setRgba(rgbaArr, 0, 0, 0, 1);
  3519. return;
  3520. }
  3521. hsla2rgba(params, rgbaArr);
  3522. putToCache(colorStr, rgbaArr);
  3523. return rgbaArr;
  3524. default:
  3525. return;
  3526. }
  3527. }
  3528. setRgba(rgbaArr, 0, 0, 0, 1);
  3529. return;
  3530. }
  3531. /**
  3532. * @param {Array.<number>} hsla
  3533. * @param {Array.<number>} rgba
  3534. * @return {Array.<number>} rgba
  3535. */
  3536. function hsla2rgba(hsla, rgba) {
  3537. var h = (parseFloat(hsla[0]) % 360 + 360) % 360 / 360; // 0 .. 1
  3538. // NOTE(deanm): According to the CSS spec s/l should only be
  3539. // percentages, but we don't bother and let float or percentage.
  3540. var s = parseCssFloat(hsla[1]);
  3541. var l = parseCssFloat(hsla[2]);
  3542. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3543. var m1 = l * 2 - m2;
  3544. rgba = rgba || [];
  3545. setRgba(rgba, clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255), clampCssByte(cssHueToRgb(m1, m2, h) * 255), clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255), 1);
  3546. if (hsla.length === 4) {
  3547. rgba[3] = hsla[3];
  3548. }
  3549. return rgba;
  3550. }
  3551. /**
  3552. * @param {Array.<number>} rgba
  3553. * @return {Array.<number>} hsla
  3554. */
  3555. function rgba2hsla(rgba) {
  3556. if (!rgba) {
  3557. return;
  3558. } // RGB from 0 to 255
  3559. var R = rgba[0] / 255;
  3560. var G = rgba[1] / 255;
  3561. var B = rgba[2] / 255;
  3562. var vMin = Math.min(R, G, B); // Min. value of RGB
  3563. var vMax = Math.max(R, G, B); // Max. value of RGB
  3564. var delta = vMax - vMin; // Delta RGB value
  3565. var L = (vMax + vMin) / 2;
  3566. var H;
  3567. var S; // HSL results from 0 to 1
  3568. if (delta === 0) {
  3569. H = 0;
  3570. S = 0;
  3571. } else {
  3572. if (L < 0.5) {
  3573. S = delta / (vMax + vMin);
  3574. } else {
  3575. S = delta / (2 - vMax - vMin);
  3576. }
  3577. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  3578. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  3579. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  3580. if (R === vMax) {
  3581. H = deltaB - deltaG;
  3582. } else if (G === vMax) {
  3583. H = 1 / 3 + deltaR - deltaB;
  3584. } else if (B === vMax) {
  3585. H = 2 / 3 + deltaG - deltaR;
  3586. }
  3587. if (H < 0) {
  3588. H += 1;
  3589. }
  3590. if (H > 1) {
  3591. H -= 1;
  3592. }
  3593. }
  3594. var hsla = [H * 360, S, L];
  3595. if (rgba[3] != null) {
  3596. hsla.push(rgba[3]);
  3597. }
  3598. return hsla;
  3599. }
  3600. /**
  3601. * @param {string} color
  3602. * @param {number} level
  3603. * @return {string}
  3604. * @memberOf module:zrender/util/color
  3605. */
  3606. function lift(color, level) {
  3607. var colorArr = parse(color);
  3608. if (colorArr) {
  3609. for (var i = 0; i < 3; i++) {
  3610. if (level < 0) {
  3611. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3612. } else {
  3613. colorArr[i] = (255 - colorArr[i]) * level + colorArr[i] | 0;
  3614. }
  3615. if (colorArr[i] > 255) {
  3616. colorArr[i] = 255;
  3617. } else if (color[i] < 0) {
  3618. colorArr[i] = 0;
  3619. }
  3620. }
  3621. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3622. }
  3623. }
  3624. /**
  3625. * @param {string} color
  3626. * @return {string}
  3627. * @memberOf module:zrender/util/color
  3628. */
  3629. function toHex(color) {
  3630. var colorArr = parse(color);
  3631. if (colorArr) {
  3632. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + +colorArr[2]).toString(16).slice(1);
  3633. }
  3634. }
  3635. /**
  3636. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  3637. * @param {number} normalizedValue A float between 0 and 1.
  3638. * @param {Array.<Array.<number>>} colors List of rgba color array
  3639. * @param {Array.<number>} [out] Mapped gba color array
  3640. * @return {Array.<number>} will be null/undefined if input illegal.
  3641. */
  3642. function fastLerp(normalizedValue, colors, out) {
  3643. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3644. return;
  3645. }
  3646. out = out || [];
  3647. var value = normalizedValue * (colors.length - 1);
  3648. var leftIndex = Math.floor(value);
  3649. var rightIndex = Math.ceil(value);
  3650. var leftColor = colors[leftIndex];
  3651. var rightColor = colors[rightIndex];
  3652. var dv = value - leftIndex;
  3653. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3654. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3655. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3656. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3657. return out;
  3658. }
  3659. /**
  3660. * @deprecated
  3661. */
  3662. var fastMapToColor = fastLerp;
  3663. /**
  3664. * @param {number} normalizedValue A float between 0 and 1.
  3665. * @param {Array.<string>} colors Color list.
  3666. * @param {boolean=} fullOutput Default false.
  3667. * @return {(string|Object)} Result color. If fullOutput,
  3668. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  3669. * @memberOf module:zrender/util/color
  3670. */
  3671. function lerp$1(normalizedValue, colors, fullOutput) {
  3672. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3673. return;
  3674. }
  3675. var value = normalizedValue * (colors.length - 1);
  3676. var leftIndex = Math.floor(value);
  3677. var rightIndex = Math.ceil(value);
  3678. var leftColor = parse(colors[leftIndex]);
  3679. var rightColor = parse(colors[rightIndex]);
  3680. var dv = value - leftIndex;
  3681. var color = stringify([clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)), clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)), clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)), clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))], 'rgba');
  3682. return fullOutput ? {
  3683. color: color,
  3684. leftIndex: leftIndex,
  3685. rightIndex: rightIndex,
  3686. value: value
  3687. } : color;
  3688. }
  3689. /**
  3690. * @deprecated
  3691. */
  3692. var mapToColor = lerp$1;
  3693. /**
  3694. * @param {string} color
  3695. * @param {number=} h 0 ~ 360, ignore when null.
  3696. * @param {number=} s 0 ~ 1, ignore when null.
  3697. * @param {number=} l 0 ~ 1, ignore when null.
  3698. * @return {string} Color string in rgba format.
  3699. * @memberOf module:zrender/util/color
  3700. */
  3701. function modifyHSL(color, h, s, l) {
  3702. color = parse(color);
  3703. if (color) {
  3704. color = rgba2hsla(color);
  3705. h != null && (color[0] = clampCssAngle(h));
  3706. s != null && (color[1] = parseCssFloat(s));
  3707. l != null && (color[2] = parseCssFloat(l));
  3708. return stringify(hsla2rgba(color), 'rgba');
  3709. }
  3710. }
  3711. /**
  3712. * @param {string} color
  3713. * @param {number=} alpha 0 ~ 1
  3714. * @return {string} Color string in rgba format.
  3715. * @memberOf module:zrender/util/color
  3716. */
  3717. function modifyAlpha(color, alpha) {
  3718. color = parse(color);
  3719. if (color && alpha != null) {
  3720. color[3] = clampCssFloat(alpha);
  3721. return stringify(color, 'rgba');
  3722. }
  3723. }
  3724. /**
  3725. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  3726. * @param {string} type 'rgba', 'hsva', ...
  3727. * @return {string} Result color. (If input illegal, return undefined).
  3728. */
  3729. function stringify(arrColor, type) {
  3730. if (!arrColor || !arrColor.length) {
  3731. return;
  3732. }
  3733. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3734. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3735. colorStr += ',' + arrColor[3];
  3736. }
  3737. return type + '(' + colorStr + ')';
  3738. }
  3739. var color = (Object.freeze || Object)({
  3740. parse: parse,
  3741. lift: lift,
  3742. toHex: toHex,
  3743. fastLerp: fastLerp,
  3744. fastMapToColor: fastMapToColor,
  3745. lerp: lerp$1,
  3746. mapToColor: mapToColor,
  3747. modifyHSL: modifyHSL,
  3748. modifyAlpha: modifyAlpha,
  3749. stringify: stringify
  3750. });
  3751. /**
  3752. * @module echarts/animation/Animator
  3753. */
  3754. var arraySlice = Array.prototype.slice;
  3755. function defaultGetter(target, key) {
  3756. return target[key];
  3757. }
  3758. function defaultSetter(target, key, value) {
  3759. target[key] = value;
  3760. }
  3761. /**
  3762. * @param {number} p0
  3763. * @param {number} p1
  3764. * @param {number} percent
  3765. * @return {number}
  3766. */
  3767. function interpolateNumber(p0, p1, percent) {
  3768. return (p1 - p0) * percent + p0;
  3769. }
  3770. /**
  3771. * @param {string} p0
  3772. * @param {string} p1
  3773. * @param {number} percent
  3774. * @return {string}
  3775. */
  3776. function interpolateString(p0, p1, percent) {
  3777. return percent > 0.5 ? p1 : p0;
  3778. }
  3779. /**
  3780. * @param {Array} p0
  3781. * @param {Array} p1
  3782. * @param {number} percent
  3783. * @param {Array} out
  3784. * @param {number} arrDim
  3785. */
  3786. function interpolateArray(p0, p1, percent, out, arrDim) {
  3787. var len = p0.length;
  3788. if (arrDim === 1) {
  3789. for (var i = 0; i < len; i++) {
  3790. out[i] = interpolateNumber(p0[i], p1[i], percent);
  3791. }
  3792. } else {
  3793. var len2 = len && p0[0].length;
  3794. for (var i = 0; i < len; i++) {
  3795. for (var j = 0; j < len2; j++) {
  3796. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  3797. }
  3798. }
  3799. }
  3800. } // arr0 is source array, arr1 is target array.
  3801. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  3802. function fillArr(arr0, arr1, arrDim) {
  3803. var arr0Len = arr0.length;
  3804. var arr1Len = arr1.length;
  3805. if (arr0Len !== arr1Len) {
  3806. // FIXME Not work for TypedArray
  3807. var isPreviousLarger = arr0Len > arr1Len;
  3808. if (isPreviousLarger) {
  3809. // Cut the previous
  3810. arr0.length = arr1Len;
  3811. } else {
  3812. // Fill the previous
  3813. for (var i = arr0Len; i < arr1Len; i++) {
  3814. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  3815. }
  3816. }
  3817. } // Handling NaN value
  3818. var len2 = arr0[0] && arr0[0].length;
  3819. for (var i = 0; i < arr0.length; i++) {
  3820. if (arrDim === 1) {
  3821. if (isNaN(arr0[i])) {
  3822. arr0[i] = arr1[i];
  3823. }
  3824. } else {
  3825. for (var j = 0; j < len2; j++) {
  3826. if (isNaN(arr0[i][j])) {
  3827. arr0[i][j] = arr1[i][j];
  3828. }
  3829. }
  3830. }
  3831. }
  3832. }
  3833. /**
  3834. * @param {Array} arr0
  3835. * @param {Array} arr1
  3836. * @param {number} arrDim
  3837. * @return {boolean}
  3838. */
  3839. function isArraySame(arr0, arr1, arrDim) {
  3840. if (arr0 === arr1) {
  3841. return true;
  3842. }
  3843. var len = arr0.length;
  3844. if (len !== arr1.length) {
  3845. return false;
  3846. }
  3847. if (arrDim === 1) {
  3848. for (var i = 0; i < len; i++) {
  3849. if (arr0[i] !== arr1[i]) {
  3850. return false;
  3851. }
  3852. }
  3853. } else {
  3854. var len2 = arr0[0].length;
  3855. for (var i = 0; i < len; i++) {
  3856. for (var j = 0; j < len2; j++) {
  3857. if (arr0[i][j] !== arr1[i][j]) {
  3858. return false;
  3859. }
  3860. }
  3861. }
  3862. }
  3863. return true;
  3864. }
  3865. /**
  3866. * Catmull Rom interpolate array
  3867. * @param {Array} p0
  3868. * @param {Array} p1
  3869. * @param {Array} p2
  3870. * @param {Array} p3
  3871. * @param {number} t
  3872. * @param {number} t2
  3873. * @param {number} t3
  3874. * @param {Array} out
  3875. * @param {number} arrDim
  3876. */
  3877. function catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim) {
  3878. var len = p0.length;
  3879. if (arrDim === 1) {
  3880. for (var i = 0; i < len; i++) {
  3881. out[i] = catmullRomInterpolate(p0[i], p1[i], p2[i], p3[i], t, t2, t3);
  3882. }
  3883. } else {
  3884. var len2 = p0[0].length;
  3885. for (var i = 0; i < len; i++) {
  3886. for (var j = 0; j < len2; j++) {
  3887. out[i][j] = catmullRomInterpolate(p0[i][j], p1[i][j], p2[i][j], p3[i][j], t, t2, t3);
  3888. }
  3889. }
  3890. }
  3891. }
  3892. /**
  3893. * Catmull Rom interpolate number
  3894. * @param {number} p0
  3895. * @param {number} p1
  3896. * @param {number} p2
  3897. * @param {number} p3
  3898. * @param {number} t
  3899. * @param {number} t2
  3900. * @param {number} t3
  3901. * @return {number}
  3902. */
  3903. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  3904. var v0 = (p2 - p0) * 0.5;
  3905. var v1 = (p3 - p1) * 0.5;
  3906. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  3907. }
  3908. function cloneValue(value) {
  3909. if (isArrayLike(value)) {
  3910. var len = value.length;
  3911. if (isArrayLike(value[0])) {
  3912. var ret = [];
  3913. for (var i = 0; i < len; i++) {
  3914. ret.push(arraySlice.call(value[i]));
  3915. }
  3916. return ret;
  3917. }
  3918. return arraySlice.call(value);
  3919. }
  3920. return value;
  3921. }
  3922. function rgba2String(rgba) {
  3923. rgba[0] = Math.floor(rgba[0]);
  3924. rgba[1] = Math.floor(rgba[1]);
  3925. rgba[2] = Math.floor(rgba[2]);
  3926. return 'rgba(' + rgba.join(',') + ')';
  3927. }
  3928. function getArrayDim(keyframes) {
  3929. var lastValue = keyframes[keyframes.length - 1].value;
  3930. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  3931. }
  3932. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  3933. var getter = animator._getter;
  3934. var setter = animator._setter;
  3935. var useSpline = easing === 'spline';
  3936. var trackLen = keyframes.length;
  3937. if (!trackLen) {
  3938. return;
  3939. } // Guess data type
  3940. var firstVal = keyframes[0].value;
  3941. var isValueArray = isArrayLike(firstVal);
  3942. var isValueColor = false;
  3943. var isValueString = false; // For vertices morphing
  3944. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  3945. var trackMaxTime; // Sort keyframe as ascending
  3946. keyframes.sort(function (a, b) {
  3947. return a.time - b.time;
  3948. });
  3949. trackMaxTime = keyframes[trackLen - 1].time; // Percents of each keyframe
  3950. var kfPercents = []; // Value of each keyframe
  3951. var kfValues = [];
  3952. var prevValue = keyframes[0].value;
  3953. var isAllValueEqual = true;
  3954. for (var i = 0; i < trackLen; i++) {
  3955. kfPercents.push(keyframes[i].time / trackMaxTime); // Assume value is a color when it is a string
  3956. var value = keyframes[i].value; // Check if value is equal, deep check if value is array
  3957. if (!(isValueArray && isArraySame(value, prevValue, arrDim) || !isValueArray && value === prevValue)) {
  3958. isAllValueEqual = false;
  3959. }
  3960. prevValue = value; // Try converting a string to a color array
  3961. if (typeof value === 'string') {
  3962. var colorArray = parse(value);
  3963. if (colorArray) {
  3964. value = colorArray;
  3965. isValueColor = true;
  3966. } else {
  3967. isValueString = true;
  3968. }
  3969. }
  3970. kfValues.push(value);
  3971. }
  3972. if (!forceAnimate && isAllValueEqual) {
  3973. return;
  3974. }
  3975. var lastValue = kfValues[trackLen - 1]; // Polyfill array and NaN value
  3976. for (var i = 0; i < trackLen - 1; i++) {
  3977. if (isValueArray) {
  3978. fillArr(kfValues[i], lastValue, arrDim);
  3979. } else {
  3980. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  3981. kfValues[i] = lastValue;
  3982. }
  3983. }
  3984. }
  3985. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim); // Cache the key of last frame to speed up when
  3986. // animation playback is sequency
  3987. var lastFrame = 0;
  3988. var lastFramePercent = 0;
  3989. var start;
  3990. var w;
  3991. var p0;
  3992. var p1;
  3993. var p2;
  3994. var p3;
  3995. if (isValueColor) {
  3996. var rgba = [0, 0, 0, 0];
  3997. }
  3998. var onframe = function (target, percent) {
  3999. // Find the range keyframes
  4000. // kf1-----kf2---------current--------kf3
  4001. // find kf2 and kf3 and do interpolation
  4002. var frame; // In the easing function like elasticOut, percent may less than 0
  4003. if (percent < 0) {
  4004. frame = 0;
  4005. } else if (percent < lastFramePercent) {
  4006. // Start from next key
  4007. // PENDING start from lastFrame ?
  4008. start = Math.min(lastFrame + 1, trackLen - 1);
  4009. for (frame = start; frame >= 0; frame--) {
  4010. if (kfPercents[frame] <= percent) {
  4011. break;
  4012. }
  4013. } // PENDING really need to do this ?
  4014. frame = Math.min(frame, trackLen - 2);
  4015. } else {
  4016. for (frame = lastFrame; frame < trackLen; frame++) {
  4017. if (kfPercents[frame] > percent) {
  4018. break;
  4019. }
  4020. }
  4021. frame = Math.min(frame - 1, trackLen - 2);
  4022. }
  4023. lastFrame = frame;
  4024. lastFramePercent = percent;
  4025. var range = kfPercents[frame + 1] - kfPercents[frame];
  4026. if (range === 0) {
  4027. return;
  4028. } else {
  4029. w = (percent - kfPercents[frame]) / range;
  4030. }
  4031. if (useSpline) {
  4032. p1 = kfValues[frame];
  4033. p0 = kfValues[frame === 0 ? frame : frame - 1];
  4034. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  4035. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  4036. if (isValueArray) {
  4037. catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, getter(target, propName), arrDim);
  4038. } else {
  4039. var value;
  4040. if (isValueColor) {
  4041. value = catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, rgba, 1);
  4042. value = rgba2String(rgba);
  4043. } else if (isValueString) {
  4044. // String is step(0.5)
  4045. return interpolateString(p1, p2, w);
  4046. } else {
  4047. value = catmullRomInterpolate(p0, p1, p2, p3, w, w * w, w * w * w);
  4048. }
  4049. setter(target, propName, value);
  4050. }
  4051. } else {
  4052. if (isValueArray) {
  4053. interpolateArray(kfValues[frame], kfValues[frame + 1], w, getter(target, propName), arrDim);
  4054. } else {
  4055. var value;
  4056. if (isValueColor) {
  4057. interpolateArray(kfValues[frame], kfValues[frame + 1], w, rgba, 1);
  4058. value = rgba2String(rgba);
  4059. } else if (isValueString) {
  4060. // String is step(0.5)
  4061. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  4062. } else {
  4063. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  4064. }
  4065. setter(target, propName, value);
  4066. }
  4067. }
  4068. };
  4069. var clip = new Clip({
  4070. target: animator._target,
  4071. life: trackMaxTime,
  4072. loop: animator._loop,
  4073. delay: animator._delay,
  4074. onframe: onframe,
  4075. ondestroy: oneTrackDone
  4076. });
  4077. if (easing && easing !== 'spline') {
  4078. clip.easing = easing;
  4079. }
  4080. return clip;
  4081. }
  4082. /**
  4083. * @alias module:zrender/animation/Animator
  4084. * @constructor
  4085. * @param {Object} target
  4086. * @param {boolean} loop
  4087. * @param {Function} getter
  4088. * @param {Function} setter
  4089. */
  4090. var Animator = function (target, loop, getter, setter) {
  4091. this._tracks = {};
  4092. this._target = target;
  4093. this._loop = loop || false;
  4094. this._getter = getter || defaultGetter;
  4095. this._setter = setter || defaultSetter;
  4096. this._clipCount = 0;
  4097. this._delay = 0;
  4098. this._doneList = [];
  4099. this._onframeList = [];
  4100. this._clipList = [];
  4101. };
  4102. Animator.prototype = {
  4103. /**
  4104. * Set Animation keyframe
  4105. * @param {number} time 关键帧时间,单位是ms
  4106. * @param {Object} props 关键帧的属性值,key-value表示
  4107. * @return {module:zrender/animation/Animator}
  4108. */
  4109. when: function (time
  4110. /* ms */
  4111. , props) {
  4112. var tracks = this._tracks;
  4113. for (var propName in props) {
  4114. if (!props.hasOwnProperty(propName)) {
  4115. continue;
  4116. }
  4117. if (!tracks[propName]) {
  4118. tracks[propName] = []; // Invalid value
  4119. var value = this._getter(this._target, propName);
  4120. if (value == null) {
  4121. // zrLog('Invalid property ' + propName);
  4122. continue;
  4123. } // If time is 0
  4124. // Then props is given initialize value
  4125. // Else
  4126. // Initialize value from current prop value
  4127. if (time !== 0) {
  4128. tracks[propName].push({
  4129. time: 0,
  4130. value: cloneValue(value)
  4131. });
  4132. }
  4133. }
  4134. tracks[propName].push({
  4135. time: time,
  4136. value: props[propName]
  4137. });
  4138. }
  4139. return this;
  4140. },
  4141. /**
  4142. * 添加动画每一帧的回调函数
  4143. * @param {Function} callback
  4144. * @return {module:zrender/animation/Animator}
  4145. */
  4146. during: function (callback) {
  4147. this._onframeList.push(callback);
  4148. return this;
  4149. },
  4150. pause: function () {
  4151. for (var i = 0; i < this._clipList.length; i++) {
  4152. this._clipList[i].pause();
  4153. }
  4154. this._paused = true;
  4155. },
  4156. resume: function () {
  4157. for (var i = 0; i < this._clipList.length; i++) {
  4158. this._clipList[i].resume();
  4159. }
  4160. this._paused = false;
  4161. },
  4162. isPaused: function () {
  4163. return !!this._paused;
  4164. },
  4165. _doneCallback: function () {
  4166. // Clear all tracks
  4167. this._tracks = {}; // Clear all clips
  4168. this._clipList.length = 0;
  4169. var doneList = this._doneList;
  4170. var len = doneList.length;
  4171. for (var i = 0; i < len; i++) {
  4172. doneList[i].call(this);
  4173. }
  4174. },
  4175. /**
  4176. * Start the animation
  4177. * @param {string|Function} [easing]
  4178. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  4179. * @param {boolean} forceAnimate
  4180. * @return {module:zrender/animation/Animator}
  4181. */
  4182. start: function (easing, forceAnimate) {
  4183. var self = this;
  4184. var clipCount = 0;
  4185. var oneTrackDone = function () {
  4186. clipCount--;
  4187. if (!clipCount) {
  4188. self._doneCallback();
  4189. }
  4190. };
  4191. var lastClip;
  4192. for (var propName in this._tracks) {
  4193. if (!this._tracks.hasOwnProperty(propName)) {
  4194. continue;
  4195. }
  4196. var clip = createTrackClip(this, easing, oneTrackDone, this._tracks[propName], propName, forceAnimate);
  4197. if (clip) {
  4198. this._clipList.push(clip);
  4199. clipCount++; // If start after added to animation
  4200. if (this.animation) {
  4201. this.animation.addClip(clip);
  4202. }
  4203. lastClip = clip;
  4204. }
  4205. } // Add during callback on the last clip
  4206. if (lastClip) {
  4207. var oldOnFrame = lastClip.onframe;
  4208. lastClip.onframe = function (target, percent) {
  4209. oldOnFrame(target, percent);
  4210. for (var i = 0; i < self._onframeList.length; i++) {
  4211. self._onframeList[i](target, percent);
  4212. }
  4213. };
  4214. } // This optimization will help the case that in the upper application
  4215. // the view may be refreshed frequently, where animation will be
  4216. // called repeatly but nothing changed.
  4217. if (!clipCount) {
  4218. this._doneCallback();
  4219. }
  4220. return this;
  4221. },
  4222. /**
  4223. * Stop animation
  4224. * @param {boolean} forwardToLast If move to last frame before stop
  4225. */
  4226. stop: function (forwardToLast) {
  4227. var clipList = this._clipList;
  4228. var animation = this.animation;
  4229. for (var i = 0; i < clipList.length; i++) {
  4230. var clip = clipList[i];
  4231. if (forwardToLast) {
  4232. // Move to last frame before stop
  4233. clip.onframe(this._target, 1);
  4234. }
  4235. animation && animation.removeClip(clip);
  4236. }
  4237. clipList.length = 0;
  4238. },
  4239. /**
  4240. * Set when animation delay starts
  4241. * @param {number} time 单位ms
  4242. * @return {module:zrender/animation/Animator}
  4243. */
  4244. delay: function (time) {
  4245. this._delay = time;
  4246. return this;
  4247. },
  4248. /**
  4249. * Add callback for animation end
  4250. * @param {Function} cb
  4251. * @return {module:zrender/animation/Animator}
  4252. */
  4253. done: function (cb) {
  4254. if (cb) {
  4255. this._doneList.push(cb);
  4256. }
  4257. return this;
  4258. },
  4259. /**
  4260. * @return {Array.<module:zrender/animation/Clip>}
  4261. */
  4262. getClips: function () {
  4263. return this._clipList;
  4264. }
  4265. };
  4266. var dpr = 1; // If in browser environment
  4267. if (typeof window !== 'undefined') {
  4268. dpr = Math.max(window.devicePixelRatio || 1, 1);
  4269. }
  4270. /**
  4271. * config默认配置项
  4272. * @exports zrender/config
  4273. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  4274. */
  4275. /**
  4276. * Debug log mode:
  4277. * 0: Do nothing, for release.
  4278. * 1: console.error, for debug.
  4279. */
  4280. var debugMode = 0; // retina 屏幕优化
  4281. var devicePixelRatio = dpr;
  4282. var logError = function () {};
  4283. if (debugMode === 1) {
  4284. logError = console.error;
  4285. }
  4286. var logError$1 = logError;
  4287. /**
  4288. * @alias module:zrender/mixin/Animatable
  4289. * @constructor
  4290. */
  4291. var Animatable = function () {
  4292. /**
  4293. * @type {Array.<module:zrender/animation/Animator>}
  4294. * @readOnly
  4295. */
  4296. this.animators = [];
  4297. };
  4298. Animatable.prototype = {
  4299. constructor: Animatable,
  4300. /**
  4301. * 动画
  4302. *
  4303. * @param {string} path The path to fetch value from object, like 'a.b.c'.
  4304. * @param {boolean} [loop] Whether to loop animation.
  4305. * @return {module:zrender/animation/Animator}
  4306. * @example:
  4307. * el.animate('style', false)
  4308. * .when(1000, {x: 10} )
  4309. * .done(function(){ // Animation done })
  4310. * .start()
  4311. */
  4312. animate: function (path, loop) {
  4313. var target;
  4314. var animatingShape = false;
  4315. var el = this;
  4316. var zr = this.__zr;
  4317. if (path) {
  4318. var pathSplitted = path.split('.');
  4319. var prop = el; // If animating shape
  4320. animatingShape = pathSplitted[0] === 'shape';
  4321. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  4322. if (!prop) {
  4323. continue;
  4324. }
  4325. prop = prop[pathSplitted[i]];
  4326. }
  4327. if (prop) {
  4328. target = prop;
  4329. }
  4330. } else {
  4331. target = el;
  4332. }
  4333. if (!target) {
  4334. logError$1('Property "' + path + '" is not existed in element ' + el.id);
  4335. return;
  4336. }
  4337. var animators = el.animators;
  4338. var animator = new Animator(target, loop);
  4339. animator.during(function (target) {
  4340. el.dirty(animatingShape);
  4341. }).done(function () {
  4342. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  4343. animators.splice(indexOf(animators, animator), 1);
  4344. });
  4345. animators.push(animator); // If animate after added to the zrender
  4346. if (zr) {
  4347. zr.animation.addAnimator(animator);
  4348. }
  4349. return animator;
  4350. },
  4351. /**
  4352. * 停止动画
  4353. * @param {boolean} forwardToLast If move to last frame before stop
  4354. */
  4355. stopAnimation: function (forwardToLast) {
  4356. var animators = this.animators;
  4357. var len = animators.length;
  4358. for (var i = 0; i < len; i++) {
  4359. animators[i].stop(forwardToLast);
  4360. }
  4361. animators.length = 0;
  4362. return this;
  4363. },
  4364. /**
  4365. * Caution: this method will stop previous animation.
  4366. * So do not use this method to one element twice before
  4367. * animation starts, unless you know what you are doing.
  4368. * @param {Object} target
  4369. * @param {number} [time=500] Time in ms
  4370. * @param {string} [easing='linear']
  4371. * @param {number} [delay=0]
  4372. * @param {Function} [callback]
  4373. * @param {Function} [forceAnimate] Prevent stop animation and callback
  4374. * immediently when target values are the same as current values.
  4375. *
  4376. * @example
  4377. * // Animate position
  4378. * el.animateTo({
  4379. * position: [10, 10]
  4380. * }, function () { // done })
  4381. *
  4382. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  4383. * el.animateTo({
  4384. * shape: {
  4385. * width: 500
  4386. * },
  4387. * style: {
  4388. * fill: 'red'
  4389. * }
  4390. * position: [10, 10]
  4391. * }, 100, 100, 'cubicOut', function () { // done })
  4392. */
  4393. // TODO Return animation key
  4394. animateTo: function (target, time, delay, easing, callback, forceAnimate) {
  4395. animateTo(this, target, time, delay, easing, callback, forceAnimate);
  4396. },
  4397. /**
  4398. * Animate from the target state to current state.
  4399. * The params and the return value are the same as `this.animateTo`.
  4400. */
  4401. animateFrom: function (target, time, delay, easing, callback, forceAnimate) {
  4402. animateTo(this, target, time, delay, easing, callback, forceAnimate, true);
  4403. }
  4404. };
  4405. function animateTo(animatable, target, time, delay, easing, callback, forceAnimate, reverse) {
  4406. // animateTo(target, time, easing, callback);
  4407. if (isString(delay)) {
  4408. callback = easing;
  4409. easing = delay;
  4410. delay = 0;
  4411. } // animateTo(target, time, delay, callback);
  4412. else if (isFunction$1(easing)) {
  4413. callback = easing;
  4414. easing = 'linear';
  4415. delay = 0;
  4416. } // animateTo(target, time, callback);
  4417. else if (isFunction$1(delay)) {
  4418. callback = delay;
  4419. delay = 0;
  4420. } // animateTo(target, callback)
  4421. else if (isFunction$1(time)) {
  4422. callback = time;
  4423. time = 500;
  4424. } // animateTo(target)
  4425. else if (!time) {
  4426. time = 500;
  4427. } // Stop all previous animations
  4428. animatable.stopAnimation();
  4429. animateToShallow(animatable, '', animatable, target, time, delay, reverse); // Animators may be removed immediately after start
  4430. // if there is nothing to animate
  4431. var animators = animatable.animators.slice();
  4432. var count = animators.length;
  4433. function done() {
  4434. count--;
  4435. if (!count) {
  4436. callback && callback();
  4437. }
  4438. } // No animators. This should be checked before animators[i].start(),
  4439. // because 'done' may be executed immediately if no need to animate.
  4440. if (!count) {
  4441. callback && callback();
  4442. } // Start after all animators created
  4443. // Incase any animator is done immediately when all animation properties are not changed
  4444. for (var i = 0; i < animators.length; i++) {
  4445. animators[i].done(done).start(easing, forceAnimate);
  4446. }
  4447. }
  4448. /**
  4449. * @param {string} path=''
  4450. * @param {Object} source=animatable
  4451. * @param {Object} target
  4452. * @param {number} [time=500]
  4453. * @param {number} [delay=0]
  4454. * @param {boolean} [reverse] If `true`, animate
  4455. * from the `target` to current state.
  4456. *
  4457. * @example
  4458. * // Animate position
  4459. * el._animateToShallow({
  4460. * position: [10, 10]
  4461. * })
  4462. *
  4463. * // Animate shape, style and position in 100ms, delayed 100ms
  4464. * el._animateToShallow({
  4465. * shape: {
  4466. * width: 500
  4467. * },
  4468. * style: {
  4469. * fill: 'red'
  4470. * }
  4471. * position: [10, 10]
  4472. * }, 100, 100)
  4473. */
  4474. function animateToShallow(animatable, path, source, target, time, delay, reverse) {
  4475. var objShallow = {};
  4476. var propertyCount = 0;
  4477. for (var name in target) {
  4478. if (!target.hasOwnProperty(name)) {
  4479. continue;
  4480. }
  4481. if (source[name] != null) {
  4482. if (isObject$1(target[name]) && !isArrayLike(target[name])) {
  4483. animateToShallow(animatable, path ? path + '.' + name : name, source[name], target[name], time, delay, reverse);
  4484. } else {
  4485. if (reverse) {
  4486. objShallow[name] = source[name];
  4487. setAttrByPath(animatable, path, name, target[name]);
  4488. } else {
  4489. objShallow[name] = target[name];
  4490. }
  4491. propertyCount++;
  4492. }
  4493. } else if (target[name] != null && !reverse) {
  4494. setAttrByPath(animatable, path, name, target[name]);
  4495. }
  4496. }
  4497. if (propertyCount > 0) {
  4498. animatable.animate(path, false).when(time == null ? 500 : time, objShallow).delay(delay || 0);
  4499. }
  4500. }
  4501. function setAttrByPath(el, path, name, value) {
  4502. // Attr directly if not has property
  4503. // FIXME, if some property not needed for element ?
  4504. if (!path) {
  4505. el.attr(name, value);
  4506. } else {
  4507. // Only support set shape or style
  4508. var props = {};
  4509. props[path] = {};
  4510. props[path][name] = value;
  4511. el.attr(props);
  4512. }
  4513. }
  4514. /**
  4515. * @alias module:zrender/Element
  4516. * @constructor
  4517. * @extends {module:zrender/mixin/Animatable}
  4518. * @extends {module:zrender/mixin/Transformable}
  4519. * @extends {module:zrender/mixin/Eventful}
  4520. */
  4521. var Element = function (opts) {
  4522. // jshint ignore:line
  4523. Transformable.call(this, opts);
  4524. Eventful.call(this, opts);
  4525. Animatable.call(this, opts);
  4526. /**
  4527. * 画布元素ID
  4528. * @type {string}
  4529. */
  4530. this.id = opts.id || guid();
  4531. };
  4532. Element.prototype = {
  4533. /**
  4534. * 元素类型
  4535. * Element type
  4536. * @type {string}
  4537. */
  4538. type: 'element',
  4539. /**
  4540. * 元素名字
  4541. * Element name
  4542. * @type {string}
  4543. */
  4544. name: '',
  4545. /**
  4546. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  4547. * ZRender instance will be assigned when element is associated with zrender
  4548. * @name module:/zrender/Element#__zr
  4549. * @type {module:zrender/ZRender}
  4550. */
  4551. __zr: null,
  4552. /**
  4553. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  4554. * If ignore drawing and events of the element object
  4555. * @name module:/zrender/Element#ignore
  4556. * @type {boolean}
  4557. * @default false
  4558. */
  4559. ignore: false,
  4560. /**
  4561. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  4562. * 该路径会继承被裁减对象的变换
  4563. * @type {module:zrender/graphic/Path}
  4564. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  4565. * @readOnly
  4566. */
  4567. clipPath: null,
  4568. /**
  4569. * 是否是 Group
  4570. * @type {boolean}
  4571. */
  4572. isGroup: false,
  4573. /**
  4574. * Drift element
  4575. * @param {number} dx dx on the global space
  4576. * @param {number} dy dy on the global space
  4577. */
  4578. drift: function (dx, dy) {
  4579. switch (this.draggable) {
  4580. case 'horizontal':
  4581. dy = 0;
  4582. break;
  4583. case 'vertical':
  4584. dx = 0;
  4585. break;
  4586. }
  4587. var m = this.transform;
  4588. if (!m) {
  4589. m = this.transform = [1, 0, 0, 1, 0, 0];
  4590. }
  4591. m[4] += dx;
  4592. m[5] += dy;
  4593. this.decomposeTransform();
  4594. this.dirty(false);
  4595. },
  4596. /**
  4597. * Hook before update
  4598. */
  4599. beforeUpdate: function () {},
  4600. /**
  4601. * Hook after update
  4602. */
  4603. afterUpdate: function () {},
  4604. /**
  4605. * Update each frame
  4606. */
  4607. update: function () {
  4608. this.updateTransform();
  4609. },
  4610. /**
  4611. * @param {Function} cb
  4612. * @param {} context
  4613. */
  4614. traverse: function (cb, context) {},
  4615. /**
  4616. * @protected
  4617. */
  4618. attrKV: function (key, value) {
  4619. if (key === 'position' || key === 'scale' || key === 'origin') {
  4620. // Copy the array
  4621. if (value) {
  4622. var target = this[key];
  4623. if (!target) {
  4624. target = this[key] = [];
  4625. }
  4626. target[0] = value[0];
  4627. target[1] = value[1];
  4628. }
  4629. } else {
  4630. this[key] = value;
  4631. }
  4632. },
  4633. /**
  4634. * Hide the element
  4635. */
  4636. hide: function () {
  4637. this.ignore = true;
  4638. this.__zr && this.__zr.refresh();
  4639. },
  4640. /**
  4641. * Show the element
  4642. */
  4643. show: function () {
  4644. this.ignore = false;
  4645. this.__zr && this.__zr.refresh();
  4646. },
  4647. /**
  4648. * @param {string|Object} key
  4649. * @param {*} value
  4650. */
  4651. attr: function (key, value) {
  4652. if (typeof key === 'string') {
  4653. this.attrKV(key, value);
  4654. } else if (isObject$1(key)) {
  4655. for (var name in key) {
  4656. if (key.hasOwnProperty(name)) {
  4657. this.attrKV(name, key[name]);
  4658. }
  4659. }
  4660. }
  4661. this.dirty(false);
  4662. return this;
  4663. },
  4664. /**
  4665. * @param {module:zrender/graphic/Path} clipPath
  4666. */
  4667. setClipPath: function (clipPath) {
  4668. var zr = this.__zr;
  4669. if (zr) {
  4670. clipPath.addSelfToZr(zr);
  4671. } // Remove previous clip path
  4672. if (this.clipPath && this.clipPath !== clipPath) {
  4673. this.removeClipPath();
  4674. }
  4675. this.clipPath = clipPath;
  4676. clipPath.__zr = zr;
  4677. clipPath.__clipTarget = this;
  4678. this.dirty(false);
  4679. },
  4680. /**
  4681. */
  4682. removeClipPath: function () {
  4683. var clipPath = this.clipPath;
  4684. if (clipPath) {
  4685. if (clipPath.__zr) {
  4686. clipPath.removeSelfFromZr(clipPath.__zr);
  4687. }
  4688. clipPath.__zr = null;
  4689. clipPath.__clipTarget = null;
  4690. this.clipPath = null;
  4691. this.dirty(false);
  4692. }
  4693. },
  4694. /**
  4695. * Add self from zrender instance.
  4696. * Not recursively because it will be invoked when element added to storage.
  4697. * @param {module:zrender/ZRender} zr
  4698. */
  4699. addSelfToZr: function (zr) {
  4700. this.__zr = zr; // 添加动画
  4701. var animators = this.animators;
  4702. if (animators) {
  4703. for (var i = 0; i < animators.length; i++) {
  4704. zr.animation.addAnimator(animators[i]);
  4705. }
  4706. }
  4707. if (this.clipPath) {
  4708. this.clipPath.addSelfToZr(zr);
  4709. }
  4710. },
  4711. /**
  4712. * Remove self from zrender instance.
  4713. * Not recursively because it will be invoked when element added to storage.
  4714. * @param {module:zrender/ZRender} zr
  4715. */
  4716. removeSelfFromZr: function (zr) {
  4717. this.__zr = null; // 移除动画
  4718. var animators = this.animators;
  4719. if (animators) {
  4720. for (var i = 0; i < animators.length; i++) {
  4721. zr.animation.removeAnimator(animators[i]);
  4722. }
  4723. }
  4724. if (this.clipPath) {
  4725. this.clipPath.removeSelfFromZr(zr);
  4726. }
  4727. }
  4728. };
  4729. mixin(Element, Animatable);
  4730. mixin(Element, Transformable);
  4731. mixin(Element, Eventful);
  4732. /**
  4733. * @module echarts/core/BoundingRect
  4734. */
  4735. var v2ApplyTransform = applyTransform;
  4736. var mathMin = Math.min;
  4737. var mathMax = Math.max;
  4738. /**
  4739. * @alias module:echarts/core/BoundingRect
  4740. */
  4741. function BoundingRect(x, y, width, height) {
  4742. if (width < 0) {
  4743. x = x + width;
  4744. width = -width;
  4745. }
  4746. if (height < 0) {
  4747. y = y + height;
  4748. height = -height;
  4749. }
  4750. /**
  4751. * @type {number}
  4752. */
  4753. this.x = x;
  4754. /**
  4755. * @type {number}
  4756. */
  4757. this.y = y;
  4758. /**
  4759. * @type {number}
  4760. */
  4761. this.width = width;
  4762. /**
  4763. * @type {number}
  4764. */
  4765. this.height = height;
  4766. }
  4767. BoundingRect.prototype = {
  4768. constructor: BoundingRect,
  4769. /**
  4770. * @param {module:echarts/core/BoundingRect} other
  4771. */
  4772. union: function (other) {
  4773. var x = mathMin(other.x, this.x);
  4774. var y = mathMin(other.y, this.y);
  4775. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  4776. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  4777. this.x = x;
  4778. this.y = y;
  4779. },
  4780. /**
  4781. * @param {Array.<number>} m
  4782. * @methods
  4783. */
  4784. applyTransform: function () {
  4785. var lt = [];
  4786. var rb = [];
  4787. var lb = [];
  4788. var rt = [];
  4789. return function (m) {
  4790. // In case usage like this
  4791. // el.getBoundingRect().applyTransform(el.transform)
  4792. // And element has no transform
  4793. if (!m) {
  4794. return;
  4795. }
  4796. lt[0] = lb[0] = this.x;
  4797. lt[1] = rt[1] = this.y;
  4798. rb[0] = rt[0] = this.x + this.width;
  4799. rb[1] = lb[1] = this.y + this.height;
  4800. v2ApplyTransform(lt, lt, m);
  4801. v2ApplyTransform(rb, rb, m);
  4802. v2ApplyTransform(lb, lb, m);
  4803. v2ApplyTransform(rt, rt, m);
  4804. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4805. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4806. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4807. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4808. this.width = maxX - this.x;
  4809. this.height = maxY - this.y;
  4810. };
  4811. }(),
  4812. /**
  4813. * Calculate matrix of transforming from self to target rect
  4814. * @param {module:zrender/core/BoundingRect} b
  4815. * @return {Array.<number>}
  4816. */
  4817. calculateTransform: function (b) {
  4818. var a = this;
  4819. var sx = b.width / a.width;
  4820. var sy = b.height / a.height;
  4821. var m = create$1(); // 矩阵右乘
  4822. translate(m, m, [-a.x, -a.y]);
  4823. scale$1(m, m, [sx, sy]);
  4824. translate(m, m, [b.x, b.y]);
  4825. return m;
  4826. },
  4827. /**
  4828. * @param {(module:echarts/core/BoundingRect|Object)} b
  4829. * @return {boolean}
  4830. */
  4831. intersect: function (b) {
  4832. if (!b) {
  4833. return false;
  4834. }
  4835. if (!(b instanceof BoundingRect)) {
  4836. // Normalize negative width/height.
  4837. b = BoundingRect.create(b);
  4838. }
  4839. var a = this;
  4840. var ax0 = a.x;
  4841. var ax1 = a.x + a.width;
  4842. var ay0 = a.y;
  4843. var ay1 = a.y + a.height;
  4844. var bx0 = b.x;
  4845. var bx1 = b.x + b.width;
  4846. var by0 = b.y;
  4847. var by1 = b.y + b.height;
  4848. return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4849. },
  4850. contain: function (x, y) {
  4851. var rect = this;
  4852. return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && 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 && nextSibling && nextSibling.parent === this) {
  4990. var children = this._children;
  4991. var idx = children.indexOf(nextSibling);
  4992. if (idx >= 0) {
  4993. children.splice(idx, 0, child);
  4994. this._doAdd(child);
  4995. }
  4996. }
  4997. return this;
  4998. },
  4999. _doAdd: function (child) {
  5000. if (child.parent) {
  5001. child.parent.remove(child);
  5002. }
  5003. child.parent = this;
  5004. var storage = this.__storage;
  5005. var zr = this.__zr;
  5006. if (storage && storage !== child.__storage) {
  5007. storage.addToStorage(child);
  5008. if (child instanceof Group) {
  5009. child.addChildrenToStorage(storage);
  5010. }
  5011. }
  5012. zr && zr.refresh();
  5013. },
  5014. /**
  5015. * 移除子节点
  5016. * @param {module:zrender/Element} child
  5017. */
  5018. remove: function (child) {
  5019. var zr = this.__zr;
  5020. var storage = this.__storage;
  5021. var children = this._children;
  5022. var idx = indexOf(children, child);
  5023. if (idx < 0) {
  5024. return this;
  5025. }
  5026. children.splice(idx, 1);
  5027. child.parent = null;
  5028. if (storage) {
  5029. storage.delFromStorage(child);
  5030. if (child instanceof Group) {
  5031. child.delChildrenFromStorage(storage);
  5032. }
  5033. }
  5034. zr && zr.refresh();
  5035. return this;
  5036. },
  5037. /**
  5038. * 移除所有子节点
  5039. */
  5040. removeAll: function () {
  5041. var children = this._children;
  5042. var storage = this.__storage;
  5043. var child;
  5044. var i;
  5045. for (i = 0; i < children.length; i++) {
  5046. child = children[i];
  5047. if (storage) {
  5048. storage.delFromStorage(child);
  5049. if (child instanceof Group) {
  5050. child.delChildrenFromStorage(storage);
  5051. }
  5052. }
  5053. child.parent = null;
  5054. }
  5055. children.length = 0;
  5056. return this;
  5057. },
  5058. /**
  5059. * 遍历所有子节点
  5060. * @param {Function} cb
  5061. * @param {} context
  5062. */
  5063. eachChild: function (cb, context) {
  5064. var children = this._children;
  5065. for (var i = 0; i < children.length; i++) {
  5066. var child = children[i];
  5067. cb.call(context, child, i);
  5068. }
  5069. return this;
  5070. },
  5071. /**
  5072. * 深度优先遍历所有子孙节点
  5073. * @param {Function} cb
  5074. * @param {} context
  5075. */
  5076. traverse: function (cb, context) {
  5077. for (var i = 0; i < this._children.length; i++) {
  5078. var child = this._children[i];
  5079. cb.call(context, child);
  5080. if (child.type === 'group') {
  5081. child.traverse(cb, context);
  5082. }
  5083. }
  5084. return this;
  5085. },
  5086. addChildrenToStorage: function (storage) {
  5087. for (var i = 0; i < this._children.length; i++) {
  5088. var child = this._children[i];
  5089. storage.addToStorage(child);
  5090. if (child instanceof Group) {
  5091. child.addChildrenToStorage(storage);
  5092. }
  5093. }
  5094. },
  5095. delChildrenFromStorage: function (storage) {
  5096. for (var i = 0; i < this._children.length; i++) {
  5097. var child = this._children[i];
  5098. storage.delFromStorage(child);
  5099. if (child instanceof Group) {
  5100. child.delChildrenFromStorage(storage);
  5101. }
  5102. }
  5103. },
  5104. dirty: function () {
  5105. this.__dirty = true;
  5106. this.__zr && this.__zr.refresh();
  5107. return this;
  5108. },
  5109. /**
  5110. * @return {module:zrender/core/BoundingRect}
  5111. */
  5112. getBoundingRect: function (includeChildren) {
  5113. // TODO Caching
  5114. var rect = null;
  5115. var tmpRect = new BoundingRect(0, 0, 0, 0);
  5116. var children = includeChildren || this._children;
  5117. var tmpMat = [];
  5118. for (var i = 0; i < children.length; i++) {
  5119. var child = children[i];
  5120. if (child.ignore || child.invisible) {
  5121. continue;
  5122. }
  5123. var childRect = child.getBoundingRect();
  5124. var transform = child.getLocalTransform(tmpMat); // TODO
  5125. // The boundingRect cacluated by transforming original
  5126. // rect may be bigger than the actual bundingRect when rotation
  5127. // is used. (Consider a circle rotated aginst its center, where
  5128. // the actual boundingRect should be the same as that not be
  5129. // rotated.) But we can not find better approach to calculate
  5130. // actual boundingRect yet, considering performance.
  5131. if (transform) {
  5132. tmpRect.copy(childRect);
  5133. tmpRect.applyTransform(transform);
  5134. rect = rect || tmpRect.clone();
  5135. rect.union(tmpRect);
  5136. } else {
  5137. rect = rect || childRect.clone();
  5138. rect.union(childRect);
  5139. }
  5140. }
  5141. return rect || tmpRect;
  5142. }
  5143. };
  5144. inherits(Group, Element); // https://github.com/mziccard/node-timsort
  5145. var DEFAULT_MIN_MERGE = 32;
  5146. var DEFAULT_MIN_GALLOPING = 7;
  5147. function minRunLength(n) {
  5148. var r = 0;
  5149. while (n >= DEFAULT_MIN_MERGE) {
  5150. r |= n & 1;
  5151. n >>= 1;
  5152. }
  5153. return n + r;
  5154. }
  5155. function makeAscendingRun(array, lo, hi, compare) {
  5156. var runHi = lo + 1;
  5157. if (runHi === hi) {
  5158. return 1;
  5159. }
  5160. if (compare(array[runHi++], array[lo]) < 0) {
  5161. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  5162. runHi++;
  5163. }
  5164. reverseRun(array, lo, runHi);
  5165. } else {
  5166. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  5167. runHi++;
  5168. }
  5169. }
  5170. return runHi - lo;
  5171. }
  5172. function reverseRun(array, lo, hi) {
  5173. hi--;
  5174. while (lo < hi) {
  5175. var t = array[lo];
  5176. array[lo++] = array[hi];
  5177. array[hi--] = t;
  5178. }
  5179. }
  5180. function binaryInsertionSort(array, lo, hi, start, compare) {
  5181. if (start === lo) {
  5182. start++;
  5183. }
  5184. for (; start < hi; start++) {
  5185. var pivot = array[start];
  5186. var left = lo;
  5187. var right = start;
  5188. var mid;
  5189. while (left < right) {
  5190. mid = left + right >>> 1;
  5191. if (compare(pivot, array[mid]) < 0) {
  5192. right = mid;
  5193. } else {
  5194. left = mid + 1;
  5195. }
  5196. }
  5197. var n = start - left;
  5198. switch (n) {
  5199. case 3:
  5200. array[left + 3] = array[left + 2];
  5201. case 2:
  5202. array[left + 2] = array[left + 1];
  5203. case 1:
  5204. array[left + 1] = array[left];
  5205. break;
  5206. default:
  5207. while (n > 0) {
  5208. array[left + n] = array[left + n - 1];
  5209. n--;
  5210. }
  5211. }
  5212. array[left] = pivot;
  5213. }
  5214. }
  5215. function gallopLeft(value, array, start, length, hint, compare) {
  5216. var lastOffset = 0;
  5217. var maxOffset = 0;
  5218. var offset = 1;
  5219. if (compare(value, array[start + hint]) > 0) {
  5220. maxOffset = length - hint;
  5221. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  5222. lastOffset = offset;
  5223. offset = (offset << 1) + 1;
  5224. if (offset <= 0) {
  5225. offset = maxOffset;
  5226. }
  5227. }
  5228. if (offset > maxOffset) {
  5229. offset = maxOffset;
  5230. }
  5231. lastOffset += hint;
  5232. offset += hint;
  5233. } else {
  5234. maxOffset = hint + 1;
  5235. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  5236. lastOffset = offset;
  5237. offset = (offset << 1) + 1;
  5238. if (offset <= 0) {
  5239. offset = maxOffset;
  5240. }
  5241. }
  5242. if (offset > maxOffset) {
  5243. offset = maxOffset;
  5244. }
  5245. var tmp = lastOffset;
  5246. lastOffset = hint - offset;
  5247. offset = hint - tmp;
  5248. }
  5249. lastOffset++;
  5250. while (lastOffset < offset) {
  5251. var m = lastOffset + (offset - lastOffset >>> 1);
  5252. if (compare(value, array[start + m]) > 0) {
  5253. lastOffset = m + 1;
  5254. } else {
  5255. offset = m;
  5256. }
  5257. }
  5258. return offset;
  5259. }
  5260. function gallopRight(value, array, start, length, hint, compare) {
  5261. var lastOffset = 0;
  5262. var maxOffset = 0;
  5263. var offset = 1;
  5264. if (compare(value, array[start + hint]) < 0) {
  5265. maxOffset = hint + 1;
  5266. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  5267. lastOffset = offset;
  5268. offset = (offset << 1) + 1;
  5269. if (offset <= 0) {
  5270. offset = maxOffset;
  5271. }
  5272. }
  5273. if (offset > maxOffset) {
  5274. offset = maxOffset;
  5275. }
  5276. var tmp = lastOffset;
  5277. lastOffset = hint - offset;
  5278. offset = hint - tmp;
  5279. } else {
  5280. maxOffset = length - hint;
  5281. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  5282. lastOffset = offset;
  5283. offset = (offset << 1) + 1;
  5284. if (offset <= 0) {
  5285. offset = maxOffset;
  5286. }
  5287. }
  5288. if (offset > maxOffset) {
  5289. offset = maxOffset;
  5290. }
  5291. lastOffset += hint;
  5292. offset += hint;
  5293. }
  5294. lastOffset++;
  5295. while (lastOffset < offset) {
  5296. var m = lastOffset + (offset - lastOffset >>> 1);
  5297. if (compare(value, array[start + m]) < 0) {
  5298. offset = m;
  5299. } else {
  5300. lastOffset = m + 1;
  5301. }
  5302. }
  5303. return offset;
  5304. }
  5305. function TimSort(array, compare) {
  5306. var minGallop = DEFAULT_MIN_GALLOPING;
  5307. var runStart;
  5308. var runLength;
  5309. var stackSize = 0;
  5310. var tmp = [];
  5311. runStart = [];
  5312. runLength = [];
  5313. function pushRun(_runStart, _runLength) {
  5314. runStart[stackSize] = _runStart;
  5315. runLength[stackSize] = _runLength;
  5316. stackSize += 1;
  5317. }
  5318. function mergeRuns() {
  5319. while (stackSize > 1) {
  5320. var n = stackSize - 2;
  5321. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  5322. if (runLength[n - 1] < runLength[n + 1]) {
  5323. n--;
  5324. }
  5325. } else if (runLength[n] > runLength[n + 1]) {
  5326. break;
  5327. }
  5328. mergeAt(n);
  5329. }
  5330. }
  5331. function forceMergeRuns() {
  5332. while (stackSize > 1) {
  5333. var n = stackSize - 2;
  5334. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  5335. n--;
  5336. }
  5337. mergeAt(n);
  5338. }
  5339. }
  5340. function mergeAt(i) {
  5341. var start1 = runStart[i];
  5342. var length1 = runLength[i];
  5343. var start2 = runStart[i + 1];
  5344. var length2 = runLength[i + 1];
  5345. runLength[i] = length1 + length2;
  5346. if (i === stackSize - 3) {
  5347. runStart[i + 1] = runStart[i + 2];
  5348. runLength[i + 1] = runLength[i + 2];
  5349. }
  5350. stackSize--;
  5351. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  5352. start1 += k;
  5353. length1 -= k;
  5354. if (length1 === 0) {
  5355. return;
  5356. }
  5357. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  5358. if (length2 === 0) {
  5359. return;
  5360. }
  5361. if (length1 <= length2) {
  5362. mergeLow(start1, length1, start2, length2);
  5363. } else {
  5364. mergeHigh(start1, length1, start2, length2);
  5365. }
  5366. }
  5367. function mergeLow(start1, length1, start2, length2) {
  5368. var i = 0;
  5369. for (i = 0; i < length1; i++) {
  5370. tmp[i] = array[start1 + i];
  5371. }
  5372. var cursor1 = 0;
  5373. var cursor2 = start2;
  5374. var dest = start1;
  5375. array[dest++] = array[cursor2++];
  5376. if (--length2 === 0) {
  5377. for (i = 0; i < length1; i++) {
  5378. array[dest + i] = tmp[cursor1 + i];
  5379. }
  5380. return;
  5381. }
  5382. if (length1 === 1) {
  5383. for (i = 0; i < length2; i++) {
  5384. array[dest + i] = array[cursor2 + i];
  5385. }
  5386. array[dest + length2] = tmp[cursor1];
  5387. return;
  5388. }
  5389. var _minGallop = minGallop;
  5390. var count1;
  5391. var count2;
  5392. var exit;
  5393. while (1) {
  5394. count1 = 0;
  5395. count2 = 0;
  5396. exit = false;
  5397. do {
  5398. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  5399. array[dest++] = array[cursor2++];
  5400. count2++;
  5401. count1 = 0;
  5402. if (--length2 === 0) {
  5403. exit = true;
  5404. break;
  5405. }
  5406. } else {
  5407. array[dest++] = tmp[cursor1++];
  5408. count1++;
  5409. count2 = 0;
  5410. if (--length1 === 1) {
  5411. exit = true;
  5412. break;
  5413. }
  5414. }
  5415. } while ((count1 | count2) < _minGallop);
  5416. if (exit) {
  5417. break;
  5418. }
  5419. do {
  5420. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  5421. if (count1 !== 0) {
  5422. for (i = 0; i < count1; i++) {
  5423. array[dest + i] = tmp[cursor1 + i];
  5424. }
  5425. dest += count1;
  5426. cursor1 += count1;
  5427. length1 -= count1;
  5428. if (length1 <= 1) {
  5429. exit = true;
  5430. break;
  5431. }
  5432. }
  5433. array[dest++] = array[cursor2++];
  5434. if (--length2 === 0) {
  5435. exit = true;
  5436. break;
  5437. }
  5438. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  5439. if (count2 !== 0) {
  5440. for (i = 0; i < count2; i++) {
  5441. array[dest + i] = array[cursor2 + i];
  5442. }
  5443. dest += count2;
  5444. cursor2 += count2;
  5445. length2 -= count2;
  5446. if (length2 === 0) {
  5447. exit = true;
  5448. break;
  5449. }
  5450. }
  5451. array[dest++] = tmp[cursor1++];
  5452. if (--length1 === 1) {
  5453. exit = true;
  5454. break;
  5455. }
  5456. _minGallop--;
  5457. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5458. if (exit) {
  5459. break;
  5460. }
  5461. if (_minGallop < 0) {
  5462. _minGallop = 0;
  5463. }
  5464. _minGallop += 2;
  5465. }
  5466. minGallop = _minGallop;
  5467. minGallop < 1 && (minGallop = 1);
  5468. if (length1 === 1) {
  5469. for (i = 0; i < length2; i++) {
  5470. array[dest + i] = array[cursor2 + i];
  5471. }
  5472. array[dest + length2] = tmp[cursor1];
  5473. } else if (length1 === 0) {
  5474. throw new Error(); // throw new Error('mergeLow preconditions were not respected');
  5475. } else {
  5476. for (i = 0; i < length1; i++) {
  5477. array[dest + i] = tmp[cursor1 + i];
  5478. }
  5479. }
  5480. }
  5481. function mergeHigh(start1, length1, start2, length2) {
  5482. var i = 0;
  5483. for (i = 0; i < length2; i++) {
  5484. tmp[i] = array[start2 + i];
  5485. }
  5486. var cursor1 = start1 + length1 - 1;
  5487. var cursor2 = length2 - 1;
  5488. var dest = start2 + length2 - 1;
  5489. var customCursor = 0;
  5490. var customDest = 0;
  5491. array[dest--] = array[cursor1--];
  5492. if (--length1 === 0) {
  5493. customCursor = dest - (length2 - 1);
  5494. for (i = 0; i < length2; i++) {
  5495. array[customCursor + i] = tmp[i];
  5496. }
  5497. return;
  5498. }
  5499. if (length2 === 1) {
  5500. dest -= length1;
  5501. cursor1 -= length1;
  5502. customDest = dest + 1;
  5503. customCursor = cursor1 + 1;
  5504. for (i = length1 - 1; i >= 0; i--) {
  5505. array[customDest + i] = array[customCursor + i];
  5506. }
  5507. array[dest] = tmp[cursor2];
  5508. return;
  5509. }
  5510. var _minGallop = minGallop;
  5511. while (true) {
  5512. var count1 = 0;
  5513. var count2 = 0;
  5514. var exit = false;
  5515. do {
  5516. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  5517. array[dest--] = array[cursor1--];
  5518. count1++;
  5519. count2 = 0;
  5520. if (--length1 === 0) {
  5521. exit = true;
  5522. break;
  5523. }
  5524. } else {
  5525. array[dest--] = tmp[cursor2--];
  5526. count2++;
  5527. count1 = 0;
  5528. if (--length2 === 1) {
  5529. exit = true;
  5530. break;
  5531. }
  5532. }
  5533. } while ((count1 | count2) < _minGallop);
  5534. if (exit) {
  5535. break;
  5536. }
  5537. do {
  5538. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  5539. if (count1 !== 0) {
  5540. dest -= count1;
  5541. cursor1 -= count1;
  5542. length1 -= count1;
  5543. customDest = dest + 1;
  5544. customCursor = cursor1 + 1;
  5545. for (i = count1 - 1; i >= 0; i--) {
  5546. array[customDest + i] = array[customCursor + i];
  5547. }
  5548. if (length1 === 0) {
  5549. exit = true;
  5550. break;
  5551. }
  5552. }
  5553. array[dest--] = tmp[cursor2--];
  5554. if (--length2 === 1) {
  5555. exit = true;
  5556. break;
  5557. }
  5558. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  5559. if (count2 !== 0) {
  5560. dest -= count2;
  5561. cursor2 -= count2;
  5562. length2 -= count2;
  5563. customDest = dest + 1;
  5564. customCursor = cursor2 + 1;
  5565. for (i = 0; i < count2; i++) {
  5566. array[customDest + i] = tmp[customCursor + i];
  5567. }
  5568. if (length2 <= 1) {
  5569. exit = true;
  5570. break;
  5571. }
  5572. }
  5573. array[dest--] = array[cursor1--];
  5574. if (--length1 === 0) {
  5575. exit = true;
  5576. break;
  5577. }
  5578. _minGallop--;
  5579. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5580. if (exit) {
  5581. break;
  5582. }
  5583. if (_minGallop < 0) {
  5584. _minGallop = 0;
  5585. }
  5586. _minGallop += 2;
  5587. }
  5588. minGallop = _minGallop;
  5589. if (minGallop < 1) {
  5590. minGallop = 1;
  5591. }
  5592. if (length2 === 1) {
  5593. dest -= length1;
  5594. cursor1 -= length1;
  5595. customDest = dest + 1;
  5596. customCursor = cursor1 + 1;
  5597. for (i = length1 - 1; i >= 0; i--) {
  5598. array[customDest + i] = array[customCursor + i];
  5599. }
  5600. array[dest] = tmp[cursor2];
  5601. } else if (length2 === 0) {
  5602. throw new Error(); // throw new Error('mergeHigh preconditions were not respected');
  5603. } else {
  5604. customCursor = dest - (length2 - 1);
  5605. for (i = 0; i < length2; i++) {
  5606. array[customCursor + i] = tmp[i];
  5607. }
  5608. }
  5609. }
  5610. this.mergeRuns = mergeRuns;
  5611. this.forceMergeRuns = forceMergeRuns;
  5612. this.pushRun = pushRun;
  5613. }
  5614. function sort(array, compare, lo, hi) {
  5615. if (!lo) {
  5616. lo = 0;
  5617. }
  5618. if (!hi) {
  5619. hi = array.length;
  5620. }
  5621. var remaining = hi - lo;
  5622. if (remaining < 2) {
  5623. return;
  5624. }
  5625. var runLength = 0;
  5626. if (remaining < DEFAULT_MIN_MERGE) {
  5627. runLength = makeAscendingRun(array, lo, hi, compare);
  5628. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  5629. return;
  5630. }
  5631. var ts = new TimSort(array, compare);
  5632. var minRun = minRunLength(remaining);
  5633. do {
  5634. runLength = makeAscendingRun(array, lo, hi, compare);
  5635. if (runLength < minRun) {
  5636. var force = remaining;
  5637. if (force > minRun) {
  5638. force = minRun;
  5639. }
  5640. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  5641. runLength = force;
  5642. }
  5643. ts.pushRun(lo, runLength);
  5644. ts.mergeRuns();
  5645. remaining -= runLength;
  5646. lo += runLength;
  5647. } while (remaining !== 0);
  5648. ts.forceMergeRuns();
  5649. } // Use timsort because in most case elements are partially sorted
  5650. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  5651. function shapeCompareFunc(a, b) {
  5652. if (a.zlevel === b.zlevel) {
  5653. if (a.z === b.z) {
  5654. // if (a.z2 === b.z2) {
  5655. // // FIXME Slow has renderidx compare
  5656. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  5657. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  5658. // return a.__renderidx - b.__renderidx;
  5659. // }
  5660. return a.z2 - b.z2;
  5661. }
  5662. return a.z - b.z;
  5663. }
  5664. return a.zlevel - b.zlevel;
  5665. }
  5666. /**
  5667. * 内容仓库 (M)
  5668. * @alias module:zrender/Storage
  5669. * @constructor
  5670. */
  5671. var Storage = function () {
  5672. // jshint ignore:line
  5673. this._roots = [];
  5674. this._displayList = [];
  5675. this._displayListLen = 0;
  5676. };
  5677. Storage.prototype = {
  5678. constructor: Storage,
  5679. /**
  5680. * @param {Function} cb
  5681. *
  5682. */
  5683. traverse: function (cb, context) {
  5684. for (var i = 0; i < this._roots.length; i++) {
  5685. this._roots[i].traverse(cb, context);
  5686. }
  5687. },
  5688. /**
  5689. * 返回所有图形的绘制队列
  5690. * @param {boolean} [update=false] 是否在返回前更新该数组
  5691. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  5692. *
  5693. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  5694. * @return {Array.<module:zrender/graphic/Displayable>}
  5695. */
  5696. getDisplayList: function (update, includeIgnore) {
  5697. includeIgnore = includeIgnore || false;
  5698. if (update) {
  5699. this.updateDisplayList(includeIgnore);
  5700. }
  5701. return this._displayList;
  5702. },
  5703. /**
  5704. * 更新图形的绘制队列。
  5705. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  5706. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  5707. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  5708. */
  5709. updateDisplayList: function (includeIgnore) {
  5710. this._displayListLen = 0;
  5711. var roots = this._roots;
  5712. var displayList = this._displayList;
  5713. for (var i = 0, len = roots.length; i < len; i++) {
  5714. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  5715. }
  5716. displayList.length = this._displayListLen;
  5717. env$1.canvasSupported && sort(displayList, shapeCompareFunc);
  5718. },
  5719. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  5720. if (el.ignore && !includeIgnore) {
  5721. return;
  5722. }
  5723. el.beforeUpdate();
  5724. if (el.__dirty) {
  5725. el.update();
  5726. }
  5727. el.afterUpdate();
  5728. var userSetClipPath = el.clipPath;
  5729. if (userSetClipPath) {
  5730. // FIXME 效率影响
  5731. if (clipPaths) {
  5732. clipPaths = clipPaths.slice();
  5733. } else {
  5734. clipPaths = [];
  5735. }
  5736. var currentClipPath = userSetClipPath;
  5737. var parentClipPath = el; // Recursively add clip path
  5738. while (currentClipPath) {
  5739. // clipPath 的变换是基于使用这个 clipPath 的元素
  5740. currentClipPath.parent = parentClipPath;
  5741. currentClipPath.updateTransform();
  5742. clipPaths.push(currentClipPath);
  5743. parentClipPath = currentClipPath;
  5744. currentClipPath = currentClipPath.clipPath;
  5745. }
  5746. }
  5747. if (el.isGroup) {
  5748. var children = el._children;
  5749. for (var i = 0; i < children.length; i++) {
  5750. var child = children[i]; // Force to mark as dirty if group is dirty
  5751. // FIXME __dirtyPath ?
  5752. if (el.__dirty) {
  5753. child.__dirty = true;
  5754. }
  5755. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  5756. } // Mark group clean here
  5757. el.__dirty = false;
  5758. } else {
  5759. el.__clipPaths = clipPaths;
  5760. this._displayList[this._displayListLen++] = el;
  5761. }
  5762. },
  5763. /**
  5764. * 添加图形(Shape)或者组(Group)到根节点
  5765. * @param {module:zrender/Element} el
  5766. */
  5767. addRoot: function (el) {
  5768. if (el.__storage === this) {
  5769. return;
  5770. }
  5771. if (el instanceof Group) {
  5772. el.addChildrenToStorage(this);
  5773. }
  5774. this.addToStorage(el);
  5775. this._roots.push(el);
  5776. },
  5777. /**
  5778. * 删除指定的图形(Shape)或者组(Group)
  5779. * @param {string|Array.<string>} [el] 如果为空清空整个Storage
  5780. */
  5781. delRoot: function (el) {
  5782. if (el == null) {
  5783. // 不指定el清空
  5784. for (var i = 0; i < this._roots.length; i++) {
  5785. var root = this._roots[i];
  5786. if (root instanceof Group) {
  5787. root.delChildrenFromStorage(this);
  5788. }
  5789. }
  5790. this._roots = [];
  5791. this._displayList = [];
  5792. this._displayListLen = 0;
  5793. return;
  5794. }
  5795. if (el instanceof Array) {
  5796. for (var i = 0, l = el.length; i < l; i++) {
  5797. this.delRoot(el[i]);
  5798. }
  5799. return;
  5800. }
  5801. var idx = indexOf(this._roots, el);
  5802. if (idx >= 0) {
  5803. this.delFromStorage(el);
  5804. this._roots.splice(idx, 1);
  5805. if (el instanceof Group) {
  5806. el.delChildrenFromStorage(this);
  5807. }
  5808. }
  5809. },
  5810. addToStorage: function (el) {
  5811. if (el) {
  5812. el.__storage = this;
  5813. el.dirty(false);
  5814. }
  5815. return this;
  5816. },
  5817. delFromStorage: function (el) {
  5818. if (el) {
  5819. el.__storage = null;
  5820. }
  5821. return this;
  5822. },
  5823. /**
  5824. * 清空并且释放Storage
  5825. */
  5826. dispose: function () {
  5827. this._renderList = this._roots = null;
  5828. },
  5829. displayableSortFunc: shapeCompareFunc
  5830. };
  5831. var SHADOW_PROPS = {
  5832. 'shadowBlur': 1,
  5833. 'shadowOffsetX': 1,
  5834. 'shadowOffsetY': 1,
  5835. 'textShadowBlur': 1,
  5836. 'textShadowOffsetX': 1,
  5837. 'textShadowOffsetY': 1,
  5838. 'textBoxShadowBlur': 1,
  5839. 'textBoxShadowOffsetX': 1,
  5840. 'textBoxShadowOffsetY': 1
  5841. };
  5842. var fixShadow = function (ctx, propName, value) {
  5843. if (SHADOW_PROPS.hasOwnProperty(propName)) {
  5844. return value *= ctx.dpr;
  5845. }
  5846. return value;
  5847. };
  5848. var ContextCachedBy = {
  5849. NONE: 0,
  5850. STYLE_BIND: 1,
  5851. PLAIN_TEXT: 2
  5852. }; // Avoid confused with 0/false.
  5853. var WILL_BE_RESTORED = 9;
  5854. var STYLE_COMMON_PROPS = [['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'], ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]]; // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  5855. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  5856. var Style = function (opts) {
  5857. this.extendFrom(opts, false);
  5858. };
  5859. function createLinearGradient(ctx, obj, rect) {
  5860. var x = obj.x == null ? 0 : obj.x;
  5861. var x2 = obj.x2 == null ? 1 : obj.x2;
  5862. var y = obj.y == null ? 0 : obj.y;
  5863. var y2 = obj.y2 == null ? 0 : obj.y2;
  5864. if (!obj.global) {
  5865. x = x * rect.width + rect.x;
  5866. x2 = x2 * rect.width + rect.x;
  5867. y = y * rect.height + rect.y;
  5868. y2 = y2 * rect.height + rect.y;
  5869. } // Fix NaN when rect is Infinity
  5870. x = isNaN(x) ? 0 : x;
  5871. x2 = isNaN(x2) ? 1 : x2;
  5872. y = isNaN(y) ? 0 : y;
  5873. y2 = isNaN(y2) ? 0 : y2;
  5874. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  5875. return canvasGradient;
  5876. }
  5877. function createRadialGradient(ctx, obj, rect) {
  5878. var width = rect.width;
  5879. var height = rect.height;
  5880. var min = Math.min(width, height);
  5881. var x = obj.x == null ? 0.5 : obj.x;
  5882. var y = obj.y == null ? 0.5 : obj.y;
  5883. var r = obj.r == null ? 0.5 : obj.r;
  5884. if (!obj.global) {
  5885. x = x * width + rect.x;
  5886. y = y * height + rect.y;
  5887. r = r * min;
  5888. }
  5889. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  5890. return canvasGradient;
  5891. }
  5892. Style.prototype = {
  5893. constructor: Style,
  5894. /**
  5895. * @type {string}
  5896. */
  5897. fill: '#000',
  5898. /**
  5899. * @type {string}
  5900. */
  5901. stroke: null,
  5902. /**
  5903. * @type {number}
  5904. */
  5905. opacity: 1,
  5906. /**
  5907. * @type {number}
  5908. */
  5909. fillOpacity: null,
  5910. /**
  5911. * @type {number}
  5912. */
  5913. strokeOpacity: null,
  5914. /**
  5915. * `true` is not supported.
  5916. * `false`/`null`/`undefined` are the same.
  5917. * `false` is used to remove lineDash in some
  5918. * case that `null`/`undefined` can not be set.
  5919. * (e.g., emphasis.lineStyle in echarts)
  5920. * @type {Array.<number>|boolean}
  5921. */
  5922. lineDash: null,
  5923. /**
  5924. * @type {number}
  5925. */
  5926. lineDashOffset: 0,
  5927. /**
  5928. * @type {number}
  5929. */
  5930. shadowBlur: 0,
  5931. /**
  5932. * @type {number}
  5933. */
  5934. shadowOffsetX: 0,
  5935. /**
  5936. * @type {number}
  5937. */
  5938. shadowOffsetY: 0,
  5939. /**
  5940. * @type {number}
  5941. */
  5942. lineWidth: 1,
  5943. /**
  5944. * If stroke ignore scale
  5945. * @type {Boolean}
  5946. */
  5947. strokeNoScale: false,
  5948. // Bounding rect text configuration
  5949. // Not affected by element transform
  5950. /**
  5951. * @type {string}
  5952. */
  5953. text: null,
  5954. /**
  5955. * If `fontSize` or `fontFamily` exists, `font` will be reset by
  5956. * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.
  5957. * So do not visit it directly in upper application (like echarts),
  5958. * but use `contain/text#makeFont` instead.
  5959. * @type {string}
  5960. */
  5961. font: null,
  5962. /**
  5963. * The same as font. Use font please.
  5964. * @deprecated
  5965. * @type {string}
  5966. */
  5967. textFont: null,
  5968. /**
  5969. * It helps merging respectively, rather than parsing an entire font string.
  5970. * @type {string}
  5971. */
  5972. fontStyle: null,
  5973. /**
  5974. * It helps merging respectively, rather than parsing an entire font string.
  5975. * @type {string}
  5976. */
  5977. fontWeight: null,
  5978. /**
  5979. * It helps merging respectively, rather than parsing an entire font string.
  5980. * Should be 12 but not '12px'.
  5981. * @type {number}
  5982. */
  5983. fontSize: null,
  5984. /**
  5985. * It helps merging respectively, rather than parsing an entire font string.
  5986. * @type {string}
  5987. */
  5988. fontFamily: null,
  5989. /**
  5990. * Reserved for special functinality, like 'hr'.
  5991. * @type {string}
  5992. */
  5993. textTag: null,
  5994. /**
  5995. * @type {string}
  5996. */
  5997. textFill: '#000',
  5998. /**
  5999. * @type {string}
  6000. */
  6001. textStroke: null,
  6002. /**
  6003. * @type {number}
  6004. */
  6005. textWidth: null,
  6006. /**
  6007. * Only for textBackground.
  6008. * @type {number}
  6009. */
  6010. textHeight: null,
  6011. /**
  6012. * textStroke may be set as some color as a default
  6013. * value in upper applicaion, where the default value
  6014. * of textStrokeWidth should be 0 to make sure that
  6015. * user can choose to do not use text stroke.
  6016. * @type {number}
  6017. */
  6018. textStrokeWidth: 0,
  6019. /**
  6020. * @type {number}
  6021. */
  6022. textLineHeight: null,
  6023. /**
  6024. * 'inside', 'left', 'right', 'top', 'bottom'
  6025. * [x, y]
  6026. * Based on x, y of rect.
  6027. * @type {string|Array.<number>}
  6028. * @default 'inside'
  6029. */
  6030. textPosition: 'inside',
  6031. /**
  6032. * If not specified, use the boundingRect of a `displayable`.
  6033. * @type {Object}
  6034. */
  6035. textRect: null,
  6036. /**
  6037. * [x, y]
  6038. * @type {Array.<number>}
  6039. */
  6040. textOffset: null,
  6041. /**
  6042. * @type {string}
  6043. */
  6044. textAlign: null,
  6045. /**
  6046. * @type {string}
  6047. */
  6048. textVerticalAlign: null,
  6049. /**
  6050. * @type {number}
  6051. */
  6052. textDistance: 5,
  6053. /**
  6054. * @type {string}
  6055. */
  6056. textShadowColor: 'transparent',
  6057. /**
  6058. * @type {number}
  6059. */
  6060. textShadowBlur: 0,
  6061. /**
  6062. * @type {number}
  6063. */
  6064. textShadowOffsetX: 0,
  6065. /**
  6066. * @type {number}
  6067. */
  6068. textShadowOffsetY: 0,
  6069. /**
  6070. * @type {string}
  6071. */
  6072. textBoxShadowColor: 'transparent',
  6073. /**
  6074. * @type {number}
  6075. */
  6076. textBoxShadowBlur: 0,
  6077. /**
  6078. * @type {number}
  6079. */
  6080. textBoxShadowOffsetX: 0,
  6081. /**
  6082. * @type {number}
  6083. */
  6084. textBoxShadowOffsetY: 0,
  6085. /**
  6086. * Whether transform text.
  6087. * Only available in Path and Image element,
  6088. * where the text is called as `RectText`.
  6089. * @type {boolean}
  6090. */
  6091. transformText: false,
  6092. /**
  6093. * Text rotate around position of Path or Image.
  6094. * The origin of the rotation can be specified by `textOrigin`.
  6095. * Only available in Path and Image element,
  6096. * where the text is called as `RectText`.
  6097. */
  6098. textRotation: 0,
  6099. /**
  6100. * Text origin of text rotation.
  6101. * Useful in the case like label rotation of circular symbol.
  6102. * Only available in Path and Image element, where the text is called
  6103. * as `RectText` and the element is called as "host element".
  6104. * The value can be:
  6105. * + If specified as a coordinate like `[10, 40]`, it is the `[x, y]`
  6106. * base on the left-top corner of the rect of its host element.
  6107. * + If specified as a string `center`, it is the center of the rect of
  6108. * its host element.
  6109. * + By default, this origin is the `textPosition`.
  6110. * @type {string|Array.<number>}
  6111. */
  6112. textOrigin: null,
  6113. /**
  6114. * @type {string}
  6115. */
  6116. textBackgroundColor: null,
  6117. /**
  6118. * @type {string}
  6119. */
  6120. textBorderColor: null,
  6121. /**
  6122. * @type {number}
  6123. */
  6124. textBorderWidth: 0,
  6125. /**
  6126. * @type {number}
  6127. */
  6128. textBorderRadius: 0,
  6129. /**
  6130. * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`
  6131. * @type {number|Array.<number>}
  6132. */
  6133. textPadding: null,
  6134. /**
  6135. * Text styles for rich text.
  6136. * @type {Object}
  6137. */
  6138. rich: null,
  6139. /**
  6140. * {outerWidth, outerHeight, ellipsis, placeholder}
  6141. * @type {Object}
  6142. */
  6143. truncate: null,
  6144. /**
  6145. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  6146. * @type {string}
  6147. */
  6148. blend: null,
  6149. /**
  6150. * @param {CanvasRenderingContext2D} ctx
  6151. */
  6152. bind: function (ctx, el, prevEl) {
  6153. var style = this;
  6154. var prevStyle = prevEl && prevEl.style; // If no prevStyle, it means first draw.
  6155. // Only apply cache if the last time cachced by this function.
  6156. var notCheckCache = !prevStyle || ctx.__attrCachedBy !== ContextCachedBy.STYLE_BIND;
  6157. ctx.__attrCachedBy = ContextCachedBy.STYLE_BIND;
  6158. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6159. var prop = STYLE_COMMON_PROPS[i];
  6160. var styleName = prop[0];
  6161. if (notCheckCache || style[styleName] !== prevStyle[styleName]) {
  6162. // FIXME Invalid property value will cause style leak from previous element.
  6163. ctx[styleName] = fixShadow(ctx, styleName, style[styleName] || prop[1]);
  6164. }
  6165. }
  6166. if (notCheckCache || style.fill !== prevStyle.fill) {
  6167. ctx.fillStyle = style.fill;
  6168. }
  6169. if (notCheckCache || style.stroke !== prevStyle.stroke) {
  6170. ctx.strokeStyle = style.stroke;
  6171. }
  6172. if (notCheckCache || style.opacity !== prevStyle.opacity) {
  6173. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  6174. }
  6175. if (notCheckCache || style.blend !== prevStyle.blend) {
  6176. ctx.globalCompositeOperation = style.blend || 'source-over';
  6177. }
  6178. if (this.hasStroke()) {
  6179. var lineWidth = style.lineWidth;
  6180. ctx.lineWidth = lineWidth / (this.strokeNoScale && el && el.getLineScale ? el.getLineScale() : 1);
  6181. }
  6182. },
  6183. hasFill: function () {
  6184. var fill = this.fill;
  6185. return fill != null && fill !== 'none';
  6186. },
  6187. hasStroke: function () {
  6188. var stroke = this.stroke;
  6189. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  6190. },
  6191. /**
  6192. * Extend from other style
  6193. * @param {zrender/graphic/Style} otherStyle
  6194. * @param {boolean} overwrite true: overwrirte any way.
  6195. * false: overwrite only when !target.hasOwnProperty
  6196. * others: overwrite when property is not null/undefined.
  6197. */
  6198. extendFrom: function (otherStyle, overwrite) {
  6199. if (otherStyle) {
  6200. for (var name in otherStyle) {
  6201. if (otherStyle.hasOwnProperty(name) && (overwrite === true || (overwrite === false ? !this.hasOwnProperty(name) : otherStyle[name] != null))) {
  6202. this[name] = otherStyle[name];
  6203. }
  6204. }
  6205. }
  6206. },
  6207. /**
  6208. * Batch setting style with a given object
  6209. * @param {Object|string} obj
  6210. * @param {*} [obj]
  6211. */
  6212. set: function (obj, value) {
  6213. if (typeof obj === 'string') {
  6214. this[obj] = value;
  6215. } else {
  6216. this.extendFrom(obj, true);
  6217. }
  6218. },
  6219. /**
  6220. * Clone
  6221. * @return {zrender/graphic/Style} [description]
  6222. */
  6223. clone: function () {
  6224. var newStyle = new this.constructor();
  6225. newStyle.extendFrom(this, true);
  6226. return newStyle;
  6227. },
  6228. getGradient: function (ctx, obj, rect) {
  6229. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  6230. var canvasGradient = method(ctx, obj, rect);
  6231. var colorStops = obj.colorStops;
  6232. for (var i = 0; i < colorStops.length; i++) {
  6233. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  6234. }
  6235. return canvasGradient;
  6236. }
  6237. };
  6238. var styleProto = Style.prototype;
  6239. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6240. var prop = STYLE_COMMON_PROPS[i];
  6241. if (!(prop[0] in styleProto)) {
  6242. styleProto[prop[0]] = prop[1];
  6243. }
  6244. } // Provide for others
  6245. Style.getGradient = styleProto.getGradient;
  6246. var Pattern = function (image, repeat) {
  6247. // Should do nothing more in this constructor. Because gradient can be
  6248. // declard by `color: {image: ...}`, where this constructor will not be called.
  6249. this.image = image;
  6250. this.repeat = repeat; // Can be cloned
  6251. this.type = 'pattern';
  6252. };
  6253. Pattern.prototype.getCanvasPattern = function (ctx) {
  6254. return ctx.createPattern(this.image, this.repeat || 'repeat');
  6255. };
  6256. /**
  6257. * @module zrender/Layer
  6258. * @author pissang(https://www.github.com/pissang)
  6259. */
  6260. function returnFalse() {
  6261. return false;
  6262. }
  6263. /**
  6264. * 创建dom
  6265. *
  6266. * @inner
  6267. * @param {string} id dom id 待用
  6268. * @param {Painter} painter painter instance
  6269. * @param {number} number
  6270. */
  6271. function createDom(id, painter, dpr) {
  6272. var newDom = createCanvas();
  6273. var width = painter.getWidth();
  6274. var height = painter.getHeight();
  6275. var newDomStyle = newDom.style;
  6276. if (newDomStyle) {
  6277. // In node or some other non-browser environment
  6278. newDomStyle.position = 'absolute';
  6279. newDomStyle.left = 0;
  6280. newDomStyle.top = 0;
  6281. newDomStyle.width = width + 'px';
  6282. newDomStyle.height = height + 'px';
  6283. newDom.setAttribute('data-zr-dom-id', id);
  6284. }
  6285. newDom.width = width * dpr;
  6286. newDom.height = height * dpr;
  6287. return newDom;
  6288. }
  6289. /**
  6290. * @alias module:zrender/Layer
  6291. * @constructor
  6292. * @extends module:zrender/mixin/Transformable
  6293. * @param {string} id
  6294. * @param {module:zrender/Painter} painter
  6295. * @param {number} [dpr]
  6296. */
  6297. var Layer = function (id, painter, dpr) {
  6298. var dom;
  6299. dpr = dpr || devicePixelRatio;
  6300. if (typeof id === 'string') {
  6301. dom = createDom(id, painter, dpr);
  6302. } // Not using isDom because in node it will return false
  6303. else if (isObject$1(id)) {
  6304. dom = id;
  6305. id = dom.id;
  6306. }
  6307. this.id = id;
  6308. this.dom = dom;
  6309. var domStyle = dom.style;
  6310. if (domStyle) {
  6311. // Not in node
  6312. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  6313. domStyle['-webkit-user-select'] = 'none';
  6314. domStyle['user-select'] = 'none';
  6315. domStyle['-webkit-touch-callout'] = 'none';
  6316. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  6317. domStyle['padding'] = 0; // eslint-disable-line dot-notation
  6318. domStyle['margin'] = 0; // eslint-disable-line dot-notation
  6319. domStyle['border-width'] = 0;
  6320. }
  6321. this.domBack = null;
  6322. this.ctxBack = null;
  6323. this.painter = painter;
  6324. this.config = null; // Configs
  6325. /**
  6326. * 每次清空画布的颜色
  6327. * @type {string}
  6328. * @default 0
  6329. */
  6330. this.clearColor = 0;
  6331. /**
  6332. * 是否开启动态模糊
  6333. * @type {boolean}
  6334. * @default false
  6335. */
  6336. this.motionBlur = false;
  6337. /**
  6338. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  6339. * @type {number}
  6340. * @default 0.7
  6341. */
  6342. this.lastFrameAlpha = 0.7;
  6343. /**
  6344. * Layer dpr
  6345. * @type {number}
  6346. */
  6347. this.dpr = dpr;
  6348. };
  6349. Layer.prototype = {
  6350. constructor: Layer,
  6351. __dirty: true,
  6352. __used: false,
  6353. __drawIndex: 0,
  6354. __startIndex: 0,
  6355. __endIndex: 0,
  6356. incremental: false,
  6357. getElementCount: function () {
  6358. return this.__endIndex - this.__startIndex;
  6359. },
  6360. initContext: function () {
  6361. this.ctx = this.dom.getContext('2d');
  6362. this.ctx.dpr = this.dpr;
  6363. },
  6364. createBackBuffer: function () {
  6365. var dpr = this.dpr;
  6366. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  6367. this.ctxBack = this.domBack.getContext('2d');
  6368. if (dpr !== 1) {
  6369. this.ctxBack.scale(dpr, dpr);
  6370. }
  6371. },
  6372. /**
  6373. * @param {number} width
  6374. * @param {number} height
  6375. */
  6376. resize: function (width, height) {
  6377. var dpr = this.dpr;
  6378. var dom = this.dom;
  6379. var domStyle = dom.style;
  6380. var domBack = this.domBack;
  6381. if (domStyle) {
  6382. domStyle.width = width + 'px';
  6383. domStyle.height = height + 'px';
  6384. }
  6385. dom.width = width * dpr;
  6386. dom.height = height * dpr;
  6387. if (domBack) {
  6388. domBack.width = width * dpr;
  6389. domBack.height = height * dpr;
  6390. if (dpr !== 1) {
  6391. this.ctxBack.scale(dpr, dpr);
  6392. }
  6393. }
  6394. },
  6395. /**
  6396. * 清空该层画布
  6397. * @param {boolean} [clearAll]=false Clear all with out motion blur
  6398. * @param {Color} [clearColor]
  6399. */
  6400. clear: function (clearAll, clearColor) {
  6401. var dom = this.dom;
  6402. var ctx = this.ctx;
  6403. var width = dom.width;
  6404. var height = dom.height;
  6405. var clearColor = clearColor || this.clearColor;
  6406. var haveMotionBLur = this.motionBlur && !clearAll;
  6407. var lastFrameAlpha = this.lastFrameAlpha;
  6408. var dpr = this.dpr;
  6409. if (haveMotionBLur) {
  6410. if (!this.domBack) {
  6411. this.createBackBuffer();
  6412. }
  6413. this.ctxBack.globalCompositeOperation = 'copy';
  6414. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  6415. }
  6416. ctx.clearRect(0, 0, width, height);
  6417. if (clearColor && clearColor !== 'transparent') {
  6418. var clearColorGradientOrPattern; // Gradient
  6419. if (clearColor.colorStops) {
  6420. // Cache canvas gradient
  6421. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  6422. x: 0,
  6423. y: 0,
  6424. width: width,
  6425. height: height
  6426. });
  6427. clearColor.__canvasGradient = clearColorGradientOrPattern;
  6428. } // Pattern
  6429. else if (clearColor.image) {
  6430. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  6431. }
  6432. ctx.save();
  6433. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  6434. ctx.fillRect(0, 0, width, height);
  6435. ctx.restore();
  6436. }
  6437. if (haveMotionBLur) {
  6438. var domBack = this.domBack;
  6439. ctx.save();
  6440. ctx.globalAlpha = lastFrameAlpha;
  6441. ctx.drawImage(domBack, 0, 0, width, height);
  6442. ctx.restore();
  6443. }
  6444. }
  6445. };
  6446. var requestAnimationFrame = typeof window !== 'undefined' && (window.requestAnimationFrame && window.requestAnimationFrame.bind(window) || // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  6447. window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window) || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame) || function (func) {
  6448. setTimeout(func, 16);
  6449. };
  6450. var globalImageCache = new LRU(50);
  6451. /**
  6452. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6453. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6454. */
  6455. function findExistImage(newImageOrSrc) {
  6456. if (typeof newImageOrSrc === 'string') {
  6457. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6458. return cachedImgObj && cachedImgObj.image;
  6459. } else {
  6460. return newImageOrSrc;
  6461. }
  6462. }
  6463. /**
  6464. * Caution: User should cache loaded images, but not just count on LRU.
  6465. * Consider if required images more than LRU size, will dead loop occur?
  6466. *
  6467. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6468. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  6469. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  6470. * @param {Function} [cb] params: (image, cbPayload)
  6471. * @param {Object} [cbPayload] Payload on cb calling.
  6472. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6473. */
  6474. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  6475. if (!newImageOrSrc) {
  6476. return image;
  6477. } else if (typeof newImageOrSrc === 'string') {
  6478. // Image should not be loaded repeatly.
  6479. if (image && image.__zrImageSrc === newImageOrSrc || !hostEl) {
  6480. return image;
  6481. } // Only when there is no existent image or existent image src
  6482. // is different, this method is responsible for load.
  6483. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6484. var pendingWrap = {
  6485. hostEl: hostEl,
  6486. cb: cb,
  6487. cbPayload: cbPayload
  6488. };
  6489. if (cachedImgObj) {
  6490. image = cachedImgObj.image;
  6491. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  6492. } else {
  6493. image = new Image();
  6494. image.onload = image.onerror = imageOnLoad;
  6495. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  6496. image: image,
  6497. pending: [pendingWrap]
  6498. });
  6499. image.src = image.__zrImageSrc = newImageOrSrc;
  6500. }
  6501. return image;
  6502. } // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  6503. else {
  6504. return newImageOrSrc;
  6505. }
  6506. }
  6507. function imageOnLoad() {
  6508. var cachedImgObj = this.__cachedImgObj;
  6509. this.onload = this.onerror = this.__cachedImgObj = null;
  6510. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  6511. var pendingWrap = cachedImgObj.pending[i];
  6512. var cb = pendingWrap.cb;
  6513. cb && cb(this, pendingWrap.cbPayload);
  6514. pendingWrap.hostEl.dirty();
  6515. }
  6516. cachedImgObj.pending.length = 0;
  6517. }
  6518. function isImageReady(image) {
  6519. return image && image.width && image.height;
  6520. }
  6521. var textWidthCache = {};
  6522. var textWidthCacheCounter = 0;
  6523. var TEXT_CACHE_MAX = 5000;
  6524. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  6525. var DEFAULT_FONT$1 = '12px sans-serif'; // Avoid assign to an exported variable, for transforming to cjs.
  6526. var methods$1 = {};
  6527. /**
  6528. * @public
  6529. * @param {string} text
  6530. * @param {string} font
  6531. * @return {number} width
  6532. */
  6533. function getWidth(text, font) {
  6534. font = font || DEFAULT_FONT$1;
  6535. var key = text + ':' + font;
  6536. if (textWidthCache[key]) {
  6537. return textWidthCache[key];
  6538. }
  6539. var textLines = (text + '').split('\n');
  6540. var width = 0;
  6541. for (var i = 0, l = textLines.length; i < l; i++) {
  6542. // textContain.measureText may be overrided in SVG or VML
  6543. width = Math.max(measureText(textLines[i], font).width, width);
  6544. }
  6545. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  6546. textWidthCacheCounter = 0;
  6547. textWidthCache = {};
  6548. }
  6549. textWidthCacheCounter++;
  6550. textWidthCache[key] = width;
  6551. return width;
  6552. }
  6553. /**
  6554. * @public
  6555. * @param {string} text
  6556. * @param {string} font
  6557. * @param {string} [textAlign='left']
  6558. * @param {string} [textVerticalAlign='top']
  6559. * @param {Array.<number>} [textPadding]
  6560. * @param {Object} [rich]
  6561. * @param {Object} [truncate]
  6562. * @return {Object} {x, y, width, height, lineHeight}
  6563. */
  6564. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6565. return rich ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate);
  6566. }
  6567. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate) {
  6568. var contentBlock = parsePlainText(text, font, textPadding, textLineHeight, truncate);
  6569. var outerWidth = getWidth(text, font);
  6570. if (textPadding) {
  6571. outerWidth += textPadding[1] + textPadding[3];
  6572. }
  6573. var outerHeight = contentBlock.outerHeight;
  6574. var x = adjustTextX(0, outerWidth, textAlign);
  6575. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6576. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  6577. rect.lineHeight = contentBlock.lineHeight;
  6578. return rect;
  6579. }
  6580. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6581. var contentBlock = parseRichText(text, {
  6582. rich: rich,
  6583. truncate: truncate,
  6584. font: font,
  6585. textAlign: textAlign,
  6586. textPadding: textPadding,
  6587. textLineHeight: textLineHeight
  6588. });
  6589. var outerWidth = contentBlock.outerWidth;
  6590. var outerHeight = contentBlock.outerHeight;
  6591. var x = adjustTextX(0, outerWidth, textAlign);
  6592. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6593. return new BoundingRect(x, y, outerWidth, outerHeight);
  6594. }
  6595. /**
  6596. * @public
  6597. * @param {number} x
  6598. * @param {number} width
  6599. * @param {string} [textAlign='left']
  6600. * @return {number} Adjusted x.
  6601. */
  6602. function adjustTextX(x, width, textAlign) {
  6603. // FIXME Right to left language
  6604. if (textAlign === 'right') {
  6605. x -= width;
  6606. } else if (textAlign === 'center') {
  6607. x -= width / 2;
  6608. }
  6609. return x;
  6610. }
  6611. /**
  6612. * @public
  6613. * @param {number} y
  6614. * @param {number} height
  6615. * @param {string} [textVerticalAlign='top']
  6616. * @return {number} Adjusted y.
  6617. */
  6618. function adjustTextY(y, height, textVerticalAlign) {
  6619. if (textVerticalAlign === 'middle') {
  6620. y -= height / 2;
  6621. } else if (textVerticalAlign === 'bottom') {
  6622. y -= height;
  6623. }
  6624. return y;
  6625. }
  6626. /**
  6627. * Follow same interface to `Displayable.prototype.calculateTextPosition`.
  6628. * @public
  6629. * @param {Obejct} [out] Prepared out object. If not input, auto created in the method.
  6630. * @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited.
  6631. * @param {Object} rect {x, y, width, height} Rect of the host elment, according to which the text positioned.
  6632. * @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign}
  6633. */
  6634. function calculateTextPosition(out, style, rect) {
  6635. var textPosition = style.textPosition;
  6636. var distance = style.textDistance;
  6637. var x = rect.x;
  6638. var y = rect.y;
  6639. distance = distance || 0;
  6640. var height = rect.height;
  6641. var width = rect.width;
  6642. var halfHeight = height / 2;
  6643. var textAlign = 'left';
  6644. var textVerticalAlign = 'top';
  6645. switch (textPosition) {
  6646. case 'left':
  6647. x -= distance;
  6648. y += halfHeight;
  6649. textAlign = 'right';
  6650. textVerticalAlign = 'middle';
  6651. break;
  6652. case 'right':
  6653. x += distance + width;
  6654. y += halfHeight;
  6655. textVerticalAlign = 'middle';
  6656. break;
  6657. case 'top':
  6658. x += width / 2;
  6659. y -= distance;
  6660. textAlign = 'center';
  6661. textVerticalAlign = 'bottom';
  6662. break;
  6663. case 'bottom':
  6664. x += width / 2;
  6665. y += height + distance;
  6666. textAlign = 'center';
  6667. break;
  6668. case 'inside':
  6669. x += width / 2;
  6670. y += halfHeight;
  6671. textAlign = 'center';
  6672. textVerticalAlign = 'middle';
  6673. break;
  6674. case 'insideLeft':
  6675. x += distance;
  6676. y += halfHeight;
  6677. textVerticalAlign = 'middle';
  6678. break;
  6679. case 'insideRight':
  6680. x += width - distance;
  6681. y += halfHeight;
  6682. textAlign = 'right';
  6683. textVerticalAlign = 'middle';
  6684. break;
  6685. case 'insideTop':
  6686. x += width / 2;
  6687. y += distance;
  6688. textAlign = 'center';
  6689. break;
  6690. case 'insideBottom':
  6691. x += width / 2;
  6692. y += height - distance;
  6693. textAlign = 'center';
  6694. textVerticalAlign = 'bottom';
  6695. break;
  6696. case 'insideTopLeft':
  6697. x += distance;
  6698. y += distance;
  6699. break;
  6700. case 'insideTopRight':
  6701. x += width - distance;
  6702. y += distance;
  6703. textAlign = 'right';
  6704. break;
  6705. case 'insideBottomLeft':
  6706. x += distance;
  6707. y += height - distance;
  6708. textVerticalAlign = 'bottom';
  6709. break;
  6710. case 'insideBottomRight':
  6711. x += width - distance;
  6712. y += height - distance;
  6713. textAlign = 'right';
  6714. textVerticalAlign = 'bottom';
  6715. break;
  6716. }
  6717. out = out || {};
  6718. out.x = x;
  6719. out.y = y;
  6720. out.textAlign = textAlign;
  6721. out.textVerticalAlign = textVerticalAlign;
  6722. return out;
  6723. }
  6724. /**
  6725. * To be removed. But still do not remove in case that some one has imported it.
  6726. * @deprecated
  6727. * @public
  6728. * @param {stirng} textPosition
  6729. * @param {Object} rect {x, y, width, height}
  6730. * @param {number} distance
  6731. * @return {Object} {x, y, textAlign, textVerticalAlign}
  6732. */
  6733. /**
  6734. * Show ellipsis if overflow.
  6735. *
  6736. * @public
  6737. * @param {string} text
  6738. * @param {string} containerWidth
  6739. * @param {string} font
  6740. * @param {number} [ellipsis='...']
  6741. * @param {Object} [options]
  6742. * @param {number} [options.maxIterations=3]
  6743. * @param {number} [options.minChar=0] If truncate result are less
  6744. * then minChar, ellipsis will not show, which is
  6745. * better for user hint in some cases.
  6746. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  6747. * @return {string}
  6748. */
  6749. function truncateText(text, containerWidth, font, ellipsis, options) {
  6750. if (!containerWidth) {
  6751. return '';
  6752. }
  6753. var textLines = (text + '').split('\n');
  6754. options = prepareTruncateOptions(containerWidth, font, ellipsis, options); // FIXME
  6755. // It is not appropriate that every line has '...' when truncate multiple lines.
  6756. for (var i = 0, len = textLines.length; i < len; i++) {
  6757. textLines[i] = truncateSingleLine(textLines[i], options);
  6758. }
  6759. return textLines.join('\n');
  6760. }
  6761. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  6762. options = extend({}, options);
  6763. options.font = font;
  6764. var ellipsis = retrieve2(ellipsis, '...');
  6765. options.maxIterations = retrieve2(options.maxIterations, 2);
  6766. var minChar = options.minChar = retrieve2(options.minChar, 0); // FIXME
  6767. // Other languages?
  6768. options.cnCharWidth = getWidth('国', font); // FIXME
  6769. // Consider proportional font?
  6770. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  6771. options.placeholder = retrieve2(options.placeholder, ''); // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  6772. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  6773. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  6774. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  6775. contentWidth -= ascCharWidth;
  6776. }
  6777. var ellipsisWidth = getWidth(ellipsis, font);
  6778. if (ellipsisWidth > contentWidth) {
  6779. ellipsis = '';
  6780. ellipsisWidth = 0;
  6781. }
  6782. contentWidth = containerWidth - ellipsisWidth;
  6783. options.ellipsis = ellipsis;
  6784. options.ellipsisWidth = ellipsisWidth;
  6785. options.contentWidth = contentWidth;
  6786. options.containerWidth = containerWidth;
  6787. return options;
  6788. }
  6789. function truncateSingleLine(textLine, options) {
  6790. var containerWidth = options.containerWidth;
  6791. var font = options.font;
  6792. var contentWidth = options.contentWidth;
  6793. if (!containerWidth) {
  6794. return '';
  6795. }
  6796. var lineWidth = getWidth(textLine, font);
  6797. if (lineWidth <= containerWidth) {
  6798. return textLine;
  6799. }
  6800. for (var j = 0;; j++) {
  6801. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  6802. textLine += options.ellipsis;
  6803. break;
  6804. }
  6805. var subLength = j === 0 ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth) : lineWidth > 0 ? Math.floor(textLine.length * contentWidth / lineWidth) : 0;
  6806. textLine = textLine.substr(0, subLength);
  6807. lineWidth = getWidth(textLine, font);
  6808. }
  6809. if (textLine === '') {
  6810. textLine = options.placeholder;
  6811. }
  6812. return textLine;
  6813. }
  6814. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  6815. var width = 0;
  6816. var i = 0;
  6817. for (var len = text.length; i < len && width < contentWidth; i++) {
  6818. var charCode = text.charCodeAt(i);
  6819. width += 0 <= charCode && charCode <= 127 ? ascCharWidth : cnCharWidth;
  6820. }
  6821. return i;
  6822. }
  6823. /**
  6824. * @public
  6825. * @param {string} font
  6826. * @return {number} line height
  6827. */
  6828. function getLineHeight(font) {
  6829. // FIXME A rough approach.
  6830. return getWidth('国', font);
  6831. }
  6832. /**
  6833. * @public
  6834. * @param {string} text
  6835. * @param {string} font
  6836. * @return {Object} width
  6837. */
  6838. function measureText(text, font) {
  6839. return methods$1.measureText(text, font);
  6840. } // Avoid assign to an exported variable, for transforming to cjs.
  6841. methods$1.measureText = function (text, font) {
  6842. var ctx = getContext();
  6843. ctx.font = font || DEFAULT_FONT$1;
  6844. return ctx.measureText(text);
  6845. };
  6846. /**
  6847. * @public
  6848. * @param {string} text
  6849. * @param {string} font
  6850. * @param {Object} [truncate]
  6851. * @return {Object} block: {lineHeight, lines, height, outerHeight, canCacheByTextString}
  6852. * Notice: for performance, do not calculate outerWidth util needed.
  6853. * `canCacheByTextString` means the result `lines` is only determined by the input `text`.
  6854. * Thus we can simply comparing the `input` text to determin whether the result changed,
  6855. * without travel the result `lines`.
  6856. */
  6857. function parsePlainText(text, font, padding, textLineHeight, truncate) {
  6858. text != null && (text += '');
  6859. var lineHeight = retrieve2(textLineHeight, getLineHeight(font));
  6860. var lines = text ? text.split('\n') : [];
  6861. var height = lines.length * lineHeight;
  6862. var outerHeight = height;
  6863. var canCacheByTextString = true;
  6864. if (padding) {
  6865. outerHeight += padding[0] + padding[2];
  6866. }
  6867. if (text && truncate) {
  6868. canCacheByTextString = false;
  6869. var truncOuterHeight = truncate.outerHeight;
  6870. var truncOuterWidth = truncate.outerWidth;
  6871. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  6872. text = '';
  6873. lines = [];
  6874. } else if (truncOuterWidth != null) {
  6875. var options = prepareTruncateOptions(truncOuterWidth - (padding ? padding[1] + padding[3] : 0), font, truncate.ellipsis, {
  6876. minChar: truncate.minChar,
  6877. placeholder: truncate.placeholder
  6878. }); // FIXME
  6879. // It is not appropriate that every line has '...' when truncate multiple lines.
  6880. for (var i = 0, len = lines.length; i < len; i++) {
  6881. lines[i] = truncateSingleLine(lines[i], options);
  6882. }
  6883. }
  6884. }
  6885. return {
  6886. lines: lines,
  6887. height: height,
  6888. outerHeight: outerHeight,
  6889. lineHeight: lineHeight,
  6890. canCacheByTextString: canCacheByTextString
  6891. };
  6892. }
  6893. /**
  6894. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  6895. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  6896. *
  6897. * @public
  6898. * @param {string} text
  6899. * @param {Object} style
  6900. * @return {Object} block
  6901. * {
  6902. * width,
  6903. * height,
  6904. * lines: [{
  6905. * lineHeight,
  6906. * width,
  6907. * tokens: [[{
  6908. * styleName,
  6909. * text,
  6910. * width, // include textPadding
  6911. * height, // include textPadding
  6912. * textWidth, // pure text width
  6913. * textHeight, // pure text height
  6914. * lineHeihgt,
  6915. * font,
  6916. * textAlign,
  6917. * textVerticalAlign
  6918. * }], [...], ...]
  6919. * }, ...]
  6920. * }
  6921. * If styleName is undefined, it is plain text.
  6922. */
  6923. function parseRichText(text, style) {
  6924. var contentBlock = {
  6925. lines: [],
  6926. width: 0,
  6927. height: 0
  6928. };
  6929. text != null && (text += '');
  6930. if (!text) {
  6931. return contentBlock;
  6932. }
  6933. var lastIndex = STYLE_REG.lastIndex = 0;
  6934. var result;
  6935. while ((result = STYLE_REG.exec(text)) != null) {
  6936. var matchedIndex = result.index;
  6937. if (matchedIndex > lastIndex) {
  6938. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  6939. }
  6940. pushTokens(contentBlock, result[2], result[1]);
  6941. lastIndex = STYLE_REG.lastIndex;
  6942. }
  6943. if (lastIndex < text.length) {
  6944. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  6945. }
  6946. var lines = contentBlock.lines;
  6947. var contentHeight = 0;
  6948. var contentWidth = 0; // For `textWidth: 100%`
  6949. var pendingList = [];
  6950. var stlPadding = style.textPadding;
  6951. var truncate = style.truncate;
  6952. var truncateWidth = truncate && truncate.outerWidth;
  6953. var truncateHeight = truncate && truncate.outerHeight;
  6954. if (stlPadding) {
  6955. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  6956. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  6957. } // Calculate layout info of tokens.
  6958. for (var i = 0; i < lines.length; i++) {
  6959. var line = lines[i];
  6960. var lineHeight = 0;
  6961. var lineWidth = 0;
  6962. for (var j = 0; j < line.tokens.length; j++) {
  6963. var token = line.tokens[j];
  6964. var tokenStyle = token.styleName && style.rich[token.styleName] || {}; // textPadding should not inherit from style.
  6965. var textPadding = token.textPadding = tokenStyle.textPadding; // textFont has been asigned to font by `normalizeStyle`.
  6966. var font = token.font = tokenStyle.font || style.font; // textHeight can be used when textVerticalAlign is specified in token.
  6967. var tokenHeight = token.textHeight = retrieve2( // textHeight should not be inherited, consider it can be specified
  6968. // as box height of the block.
  6969. tokenStyle.textHeight, getLineHeight(font));
  6970. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  6971. token.height = tokenHeight;
  6972. token.lineHeight = retrieve3(tokenStyle.textLineHeight, style.textLineHeight, tokenHeight);
  6973. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  6974. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  6975. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  6976. return {
  6977. lines: [],
  6978. width: 0,
  6979. height: 0
  6980. };
  6981. }
  6982. token.textWidth = getWidth(token.text, font);
  6983. var tokenWidth = tokenStyle.textWidth;
  6984. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto'; // Percent width, can be `100%`, can be used in drawing separate
  6985. // line when box width is needed to be auto.
  6986. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  6987. token.percentWidth = tokenWidth;
  6988. pendingList.push(token);
  6989. tokenWidth = 0; // Do not truncate in this case, because there is no user case
  6990. // and it is too complicated.
  6991. } else {
  6992. if (tokenWidthNotSpecified) {
  6993. tokenWidth = token.textWidth; // FIXME: If image is not loaded and textWidth is not specified, calling
  6994. // `getBoundingRect()` will not get correct result.
  6995. var textBackgroundColor = tokenStyle.textBackgroundColor;
  6996. var bgImg = textBackgroundColor && textBackgroundColor.image; // Use cases:
  6997. // (1) If image is not loaded, it will be loaded at render phase and call
  6998. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  6999. // image, and then the right size will be calculated here at the next tick.
  7000. // See `graphic/helper/text.js`.
  7001. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  7002. // use `imageHelper.findExistImage` to find cached image.
  7003. // `imageHelper.findExistImage` will always be called here before
  7004. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  7005. // which ensures that image will not be rendered before correct size calcualted.
  7006. if (bgImg) {
  7007. bgImg = findExistImage(bgImg);
  7008. if (isImageReady(bgImg)) {
  7009. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  7010. }
  7011. }
  7012. }
  7013. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  7014. tokenWidth += paddingW;
  7015. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  7016. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  7017. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  7018. token.text = '';
  7019. token.textWidth = tokenWidth = 0;
  7020. } else {
  7021. token.text = truncateText(token.text, remianTruncWidth - paddingW, font, truncate.ellipsis, {
  7022. minChar: truncate.minChar
  7023. });
  7024. token.textWidth = getWidth(token.text, font);
  7025. tokenWidth = token.textWidth + paddingW;
  7026. }
  7027. }
  7028. }
  7029. lineWidth += token.width = tokenWidth;
  7030. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  7031. }
  7032. line.width = lineWidth;
  7033. line.lineHeight = lineHeight;
  7034. contentHeight += lineHeight;
  7035. contentWidth = Math.max(contentWidth, lineWidth);
  7036. }
  7037. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  7038. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  7039. if (stlPadding) {
  7040. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  7041. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  7042. }
  7043. for (var i = 0; i < pendingList.length; i++) {
  7044. var token = pendingList[i];
  7045. var percentWidth = token.percentWidth; // Should not base on outerWidth, because token can not be placed out of padding.
  7046. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  7047. }
  7048. return contentBlock;
  7049. }
  7050. function pushTokens(block, str, styleName) {
  7051. var isEmptyStr = str === '';
  7052. var strs = str.split('\n');
  7053. var lines = block.lines;
  7054. for (var i = 0; i < strs.length; i++) {
  7055. var text = strs[i];
  7056. var token = {
  7057. styleName: styleName,
  7058. text: text,
  7059. isLineHolder: !text && !isEmptyStr
  7060. }; // The first token should be appended to the last line.
  7061. if (!i) {
  7062. var tokens = (lines[lines.length - 1] || (lines[0] = {
  7063. tokens: []
  7064. })).tokens; // Consider cases:
  7065. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  7066. // (which is a placeholder) should be replaced by new token.
  7067. // (2) A image backage, where token likes {a|}.
  7068. // (3) A redundant '' will affect textAlign in line.
  7069. // (4) tokens with the same tplName should not be merged, because
  7070. // they should be displayed in different box (with border and padding).
  7071. var tokensLen = tokens.length;
  7072. tokensLen === 1 && tokens[0].isLineHolder ? tokens[0] = token : // Consider text is '', only insert when it is the "lineHolder" or
  7073. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  7074. (text || !tokensLen || isEmptyStr) && tokens.push(token);
  7075. } // Other tokens always start a new line.
  7076. else {
  7077. // If there is '', insert it as a placeholder.
  7078. lines.push({
  7079. tokens: [token]
  7080. });
  7081. }
  7082. }
  7083. }
  7084. function makeFont(style) {
  7085. // FIXME in node-canvas fontWeight is before fontStyle
  7086. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  7087. var font = (style.fontSize || style.fontFamily) && [style.fontStyle, style.fontWeight, (style.fontSize || 12) + 'px', // If font properties are defined, `fontFamily` should not be ignored.
  7088. style.fontFamily || 'sans-serif'].join(' ');
  7089. return font && trim(font) || style.textFont || style.font;
  7090. }
  7091. /**
  7092. * @param {Object} ctx
  7093. * @param {Object} shape
  7094. * @param {number} shape.x
  7095. * @param {number} shape.y
  7096. * @param {number} shape.width
  7097. * @param {number} shape.height
  7098. * @param {number} shape.r
  7099. */
  7100. function buildPath(ctx, shape) {
  7101. var x = shape.x;
  7102. var y = shape.y;
  7103. var width = shape.width;
  7104. var height = shape.height;
  7105. var r = shape.r;
  7106. var r1;
  7107. var r2;
  7108. var r3;
  7109. var r4; // Convert width and height to positive for better borderRadius
  7110. if (width < 0) {
  7111. x = x + width;
  7112. width = -width;
  7113. }
  7114. if (height < 0) {
  7115. y = y + height;
  7116. height = -height;
  7117. }
  7118. if (typeof r === 'number') {
  7119. r1 = r2 = r3 = r4 = r;
  7120. } else if (r instanceof Array) {
  7121. if (r.length === 1) {
  7122. r1 = r2 = r3 = r4 = r[0];
  7123. } else if (r.length === 2) {
  7124. r1 = r3 = r[0];
  7125. r2 = r4 = r[1];
  7126. } else if (r.length === 3) {
  7127. r1 = r[0];
  7128. r2 = r4 = r[1];
  7129. r3 = r[2];
  7130. } else {
  7131. r1 = r[0];
  7132. r2 = r[1];
  7133. r3 = r[2];
  7134. r4 = r[3];
  7135. }
  7136. } else {
  7137. r1 = r2 = r3 = r4 = 0;
  7138. }
  7139. var total;
  7140. if (r1 + r2 > width) {
  7141. total = r1 + r2;
  7142. r1 *= width / total;
  7143. r2 *= width / total;
  7144. }
  7145. if (r3 + r4 > width) {
  7146. total = r3 + r4;
  7147. r3 *= width / total;
  7148. r4 *= width / total;
  7149. }
  7150. if (r2 + r3 > height) {
  7151. total = r2 + r3;
  7152. r2 *= height / total;
  7153. r3 *= height / total;
  7154. }
  7155. if (r1 + r4 > height) {
  7156. total = r1 + r4;
  7157. r1 *= height / total;
  7158. r4 *= height / total;
  7159. }
  7160. ctx.moveTo(x + r1, y);
  7161. ctx.lineTo(x + width - r2, y);
  7162. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  7163. ctx.lineTo(x + width, y + height - r3);
  7164. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  7165. ctx.lineTo(x + r4, y + height);
  7166. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  7167. ctx.lineTo(x, y + r1);
  7168. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  7169. }
  7170. var DEFAULT_FONT = DEFAULT_FONT$1; // TODO: Have not support 'start', 'end' yet.
  7171. var VALID_TEXT_ALIGN = {
  7172. left: 1,
  7173. right: 1,
  7174. center: 1
  7175. };
  7176. var VALID_TEXT_VERTICAL_ALIGN = {
  7177. top: 1,
  7178. bottom: 1,
  7179. middle: 1
  7180. }; // Different from `STYLE_COMMON_PROPS` of `graphic/Style`,
  7181. // the default value of shadowColor is `'transparent'`.
  7182. var SHADOW_STYLE_COMMON_PROPS = [['textShadowBlur', 'shadowBlur', 0], ['textShadowOffsetX', 'shadowOffsetX', 0], ['textShadowOffsetY', 'shadowOffsetY', 0], ['textShadowColor', 'shadowColor', 'transparent']];
  7183. var _tmpTextPositionResult = {};
  7184. var _tmpBoxPositionResult = {};
  7185. /**
  7186. * @param {module:zrender/graphic/Style} style
  7187. * @return {module:zrender/graphic/Style} The input style.
  7188. */
  7189. function normalizeTextStyle(style) {
  7190. normalizeStyle(style);
  7191. each$1(style.rich, normalizeStyle);
  7192. return style;
  7193. }
  7194. function normalizeStyle(style) {
  7195. if (style) {
  7196. style.font = makeFont(style);
  7197. var textAlign = style.textAlign;
  7198. textAlign === 'middle' && (textAlign = 'center');
  7199. style.textAlign = textAlign == null || VALID_TEXT_ALIGN[textAlign] ? textAlign : 'left'; // Compatible with textBaseline.
  7200. var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
  7201. textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
  7202. style.textVerticalAlign = textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign] ? textVerticalAlign : 'top';
  7203. var textPadding = style.textPadding;
  7204. if (textPadding) {
  7205. style.textPadding = normalizeCssArray(style.textPadding);
  7206. }
  7207. }
  7208. }
  7209. /**
  7210. * @param {CanvasRenderingContext2D} ctx
  7211. * @param {string} text
  7212. * @param {module:zrender/graphic/Style} style
  7213. * @param {Object|boolean} [rect] {x, y, width, height}
  7214. * If set false, rect text is not used.
  7215. * @param {Element|module:zrender/graphic/helper/constant.WILL_BE_RESTORED} [prevEl] For ctx prop cache.
  7216. */
  7217. function renderText(hostEl, ctx, text, style, rect, prevEl) {
  7218. style.rich ? renderRichText(hostEl, ctx, text, style, rect, prevEl) : renderPlainText(hostEl, ctx, text, style, rect, prevEl);
  7219. } // Avoid setting to ctx according to prevEl if possible for
  7220. // performance in scenarios of large amount text.
  7221. function renderPlainText(hostEl, ctx, text, style, rect, prevEl) {
  7222. 'use strict';
  7223. var needDrawBg = needDrawBackground(style);
  7224. var prevStyle;
  7225. var checkCache = false;
  7226. var cachedByMe = ctx.__attrCachedBy === ContextCachedBy.PLAIN_TEXT; // Only take and check cache for `Text` el, but not RectText.
  7227. if (prevEl !== WILL_BE_RESTORED) {
  7228. if (prevEl) {
  7229. prevStyle = prevEl.style;
  7230. checkCache = !needDrawBg && cachedByMe && prevStyle;
  7231. } // Prevent from using cache in `Style::bind`, because of the case:
  7232. // ctx property is modified by other properties than `Style::bind`
  7233. // used, and Style::bind is called next.
  7234. ctx.__attrCachedBy = needDrawBg ? ContextCachedBy.NONE : ContextCachedBy.PLAIN_TEXT;
  7235. } // Since this will be restored, prevent from using these props to check cache in the next
  7236. // entering of this method. But do not need to clear other cache like `Style::bind`.
  7237. else if (cachedByMe) {
  7238. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7239. }
  7240. var styleFont = style.font || DEFAULT_FONT; // PENDING
  7241. // Only `Text` el set `font` and keep it (`RectText` will restore). So theoretically
  7242. // we can make font cache on ctx, which can cache for text el that are discontinuous.
  7243. // But layer save/restore needed to be considered.
  7244. // if (styleFont !== ctx.__fontCache) {
  7245. // ctx.font = styleFont;
  7246. // if (prevEl !== WILL_BE_RESTORED) {
  7247. // ctx.__fontCache = styleFont;
  7248. // }
  7249. // }
  7250. if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) {
  7251. ctx.font = styleFont;
  7252. } // Use the final font from context-2d, because the final
  7253. // font might not be the style.font when it is illegal.
  7254. // But get `ctx.font` might be time consuming.
  7255. var computedFont = hostEl.__computedFont;
  7256. if (hostEl.__styleFont !== styleFont) {
  7257. hostEl.__styleFont = styleFont;
  7258. computedFont = hostEl.__computedFont = ctx.font;
  7259. }
  7260. var textPadding = style.textPadding;
  7261. var textLineHeight = style.textLineHeight;
  7262. var contentBlock = hostEl.__textCotentBlock;
  7263. if (!contentBlock || hostEl.__dirtyText) {
  7264. contentBlock = hostEl.__textCotentBlock = parsePlainText(text, computedFont, textPadding, textLineHeight, style.truncate);
  7265. }
  7266. var outerHeight = contentBlock.outerHeight;
  7267. var textLines = contentBlock.lines;
  7268. var lineHeight = contentBlock.lineHeight;
  7269. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7270. var baseX = boxPos.baseX;
  7271. var baseY = boxPos.baseY;
  7272. var textAlign = boxPos.textAlign || 'left';
  7273. var textVerticalAlign = boxPos.textVerticalAlign; // Origin of textRotation should be the base point of text drawing.
  7274. applyTextRotation(ctx, style, rect, baseX, baseY);
  7275. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7276. var textX = baseX;
  7277. var textY = boxY;
  7278. if (needDrawBg || textPadding) {
  7279. // Consider performance, do not call getTextWidth util necessary.
  7280. var textWidth = getWidth(text, computedFont);
  7281. var outerWidth = textWidth;
  7282. textPadding && (outerWidth += textPadding[1] + textPadding[3]);
  7283. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7284. needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  7285. if (textPadding) {
  7286. textX = getTextXForPadding(baseX, textAlign, textPadding);
  7287. textY += textPadding[0];
  7288. }
  7289. } // Always set textAlign and textBase line, because it is difficute to calculate
  7290. // textAlign from prevEl, and we dont sure whether textAlign will be reset if
  7291. // font set happened.
  7292. ctx.textAlign = textAlign; // Force baseline to be "middle". Otherwise, if using "top", the
  7293. // text will offset downward a little bit in font "Microsoft YaHei".
  7294. ctx.textBaseline = 'middle'; // Set text opacity
  7295. ctx.globalAlpha = style.opacity || 1; // Always set shadowBlur and shadowOffset to avoid leak from displayable.
  7296. for (var i = 0; i < SHADOW_STYLE_COMMON_PROPS.length; i++) {
  7297. var propItem = SHADOW_STYLE_COMMON_PROPS[i];
  7298. var styleProp = propItem[0];
  7299. var ctxProp = propItem[1];
  7300. var val = style[styleProp];
  7301. if (!checkCache || val !== prevStyle[styleProp]) {
  7302. ctx[ctxProp] = fixShadow(ctx, ctxProp, val || propItem[2]);
  7303. }
  7304. } // `textBaseline` is set as 'middle'.
  7305. textY += lineHeight / 2;
  7306. var textStrokeWidth = style.textStrokeWidth;
  7307. var textStrokeWidthPrev = checkCache ? prevStyle.textStrokeWidth : null;
  7308. var strokeWidthChanged = !checkCache || textStrokeWidth !== textStrokeWidthPrev;
  7309. var strokeChanged = !checkCache || strokeWidthChanged || style.textStroke !== prevStyle.textStroke;
  7310. var textStroke = getStroke(style.textStroke, textStrokeWidth);
  7311. var textFill = getFill(style.textFill);
  7312. if (textStroke) {
  7313. if (strokeWidthChanged) {
  7314. ctx.lineWidth = textStrokeWidth;
  7315. }
  7316. if (strokeChanged) {
  7317. ctx.strokeStyle = textStroke;
  7318. }
  7319. }
  7320. if (textFill) {
  7321. if (!checkCache || style.textFill !== prevStyle.textFill) {
  7322. ctx.fillStyle = textFill;
  7323. }
  7324. } // Optimize simply, in most cases only one line exists.
  7325. if (textLines.length === 1) {
  7326. // Fill after stroke so the outline will not cover the main part.
  7327. textStroke && ctx.strokeText(textLines[0], textX, textY);
  7328. textFill && ctx.fillText(textLines[0], textX, textY);
  7329. } else {
  7330. for (var i = 0; i < textLines.length; i++) {
  7331. // Fill after stroke so the outline will not cover the main part.
  7332. textStroke && ctx.strokeText(textLines[i], textX, textY);
  7333. textFill && ctx.fillText(textLines[i], textX, textY);
  7334. textY += lineHeight;
  7335. }
  7336. }
  7337. }
  7338. function renderRichText(hostEl, ctx, text, style, rect, prevEl) {
  7339. // Do not do cache for rich text because of the complexity.
  7340. // But `RectText` this will be restored, do not need to clear other cache like `Style::bind`.
  7341. if (prevEl !== WILL_BE_RESTORED) {
  7342. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7343. }
  7344. var contentBlock = hostEl.__textCotentBlock;
  7345. if (!contentBlock || hostEl.__dirtyText) {
  7346. contentBlock = hostEl.__textCotentBlock = parseRichText(text, style);
  7347. }
  7348. drawRichText(hostEl, ctx, contentBlock, style, rect);
  7349. }
  7350. function drawRichText(hostEl, ctx, contentBlock, style, rect) {
  7351. var contentWidth = contentBlock.width;
  7352. var outerWidth = contentBlock.outerWidth;
  7353. var outerHeight = contentBlock.outerHeight;
  7354. var textPadding = style.textPadding;
  7355. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7356. var baseX = boxPos.baseX;
  7357. var baseY = boxPos.baseY;
  7358. var textAlign = boxPos.textAlign;
  7359. var textVerticalAlign = boxPos.textVerticalAlign; // Origin of textRotation should be the base point of text drawing.
  7360. applyTextRotation(ctx, style, rect, baseX, baseY);
  7361. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7362. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7363. var xLeft = boxX;
  7364. var lineTop = boxY;
  7365. if (textPadding) {
  7366. xLeft += textPadding[3];
  7367. lineTop += textPadding[0];
  7368. }
  7369. var xRight = xLeft + contentWidth;
  7370. needDrawBackground(style) && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  7371. for (var i = 0; i < contentBlock.lines.length; i++) {
  7372. var line = contentBlock.lines[i];
  7373. var tokens = line.tokens;
  7374. var tokenCount = tokens.length;
  7375. var lineHeight = line.lineHeight;
  7376. var usedWidth = line.width;
  7377. var leftIndex = 0;
  7378. var lineXLeft = xLeft;
  7379. var lineXRight = xRight;
  7380. var rightIndex = tokenCount - 1;
  7381. var token;
  7382. while (leftIndex < tokenCount && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')) {
  7383. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
  7384. usedWidth -= token.width;
  7385. lineXLeft += token.width;
  7386. leftIndex++;
  7387. }
  7388. while (rightIndex >= 0 && (token = tokens[rightIndex], token.textAlign === 'right')) {
  7389. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
  7390. usedWidth -= token.width;
  7391. lineXRight -= token.width;
  7392. rightIndex--;
  7393. } // The other tokens are placed as textAlign 'center' if there is enough space.
  7394. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
  7395. while (leftIndex <= rightIndex) {
  7396. token = tokens[leftIndex]; // Consider width specified by user, use 'center' rather than 'left'.
  7397. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
  7398. lineXLeft += token.width;
  7399. leftIndex++;
  7400. }
  7401. lineTop += lineHeight;
  7402. }
  7403. }
  7404. function applyTextRotation(ctx, style, rect, x, y) {
  7405. // textRotation only apply in RectText.
  7406. if (rect && style.textRotation) {
  7407. var origin = style.textOrigin;
  7408. if (origin === 'center') {
  7409. x = rect.width / 2 + rect.x;
  7410. y = rect.height / 2 + rect.y;
  7411. } else if (origin) {
  7412. x = origin[0] + rect.x;
  7413. y = origin[1] + rect.y;
  7414. }
  7415. ctx.translate(x, y); // Positive: anticlockwise
  7416. ctx.rotate(-style.textRotation);
  7417. ctx.translate(-x, -y);
  7418. }
  7419. }
  7420. function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
  7421. var tokenStyle = style.rich[token.styleName] || {};
  7422. tokenStyle.text = token.text; // 'ctx.textBaseline' is always set as 'middle', for sake of
  7423. // the bias of "Microsoft YaHei".
  7424. var textVerticalAlign = token.textVerticalAlign;
  7425. var y = lineTop + lineHeight / 2;
  7426. if (textVerticalAlign === 'top') {
  7427. y = lineTop + token.height / 2;
  7428. } else if (textVerticalAlign === 'bottom') {
  7429. y = lineTop + lineHeight - token.height / 2;
  7430. }
  7431. !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(hostEl, ctx, tokenStyle, textAlign === 'right' ? x - token.width : textAlign === 'center' ? x - token.width / 2 : x, y - token.height / 2, token.width, token.height);
  7432. var textPadding = token.textPadding;
  7433. if (textPadding) {
  7434. x = getTextXForPadding(x, textAlign, textPadding);
  7435. y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
  7436. }
  7437. setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
  7438. setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
  7439. setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
  7440. setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
  7441. setCtx(ctx, 'textAlign', textAlign); // Force baseline to be "middle". Otherwise, if using "top", the
  7442. // text will offset downward a little bit in font "Microsoft YaHei".
  7443. setCtx(ctx, 'textBaseline', 'middle');
  7444. setCtx(ctx, 'font', token.font || DEFAULT_FONT);
  7445. var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
  7446. var textFill = getFill(tokenStyle.textFill || style.textFill);
  7447. var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth); // Fill after stroke so the outline will not cover the main part.
  7448. if (textStroke) {
  7449. setCtx(ctx, 'lineWidth', textStrokeWidth);
  7450. setCtx(ctx, 'strokeStyle', textStroke);
  7451. ctx.strokeText(token.text, x, y);
  7452. }
  7453. if (textFill) {
  7454. setCtx(ctx, 'fillStyle', textFill);
  7455. ctx.fillText(token.text, x, y);
  7456. }
  7457. }
  7458. function needDrawBackground(style) {
  7459. return !!(style.textBackgroundColor || style.textBorderWidth && style.textBorderColor);
  7460. } // style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius, text}
  7461. // shape: {x, y, width, height}
  7462. function drawBackground(hostEl, ctx, style, x, y, width, height) {
  7463. var textBackgroundColor = style.textBackgroundColor;
  7464. var textBorderWidth = style.textBorderWidth;
  7465. var textBorderColor = style.textBorderColor;
  7466. var isPlainBg = isString(textBackgroundColor);
  7467. setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
  7468. setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
  7469. setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
  7470. setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
  7471. if (isPlainBg || textBorderWidth && textBorderColor) {
  7472. ctx.beginPath();
  7473. var textBorderRadius = style.textBorderRadius;
  7474. if (!textBorderRadius) {
  7475. ctx.rect(x, y, width, height);
  7476. } else {
  7477. buildPath(ctx, {
  7478. x: x,
  7479. y: y,
  7480. width: width,
  7481. height: height,
  7482. r: textBorderRadius
  7483. });
  7484. }
  7485. ctx.closePath();
  7486. }
  7487. if (isPlainBg) {
  7488. setCtx(ctx, 'fillStyle', textBackgroundColor);
  7489. if (style.fillOpacity != null) {
  7490. var originalGlobalAlpha = ctx.globalAlpha;
  7491. ctx.globalAlpha = style.fillOpacity * style.opacity;
  7492. ctx.fill();
  7493. ctx.globalAlpha = originalGlobalAlpha;
  7494. } else {
  7495. ctx.fill();
  7496. }
  7497. } else if (isObject$1(textBackgroundColor)) {
  7498. var image = textBackgroundColor.image;
  7499. image = createOrUpdateImage(image, null, hostEl, onBgImageLoaded, textBackgroundColor);
  7500. if (image && isImageReady(image)) {
  7501. ctx.drawImage(image, x, y, width, height);
  7502. }
  7503. }
  7504. if (textBorderWidth && textBorderColor) {
  7505. setCtx(ctx, 'lineWidth', textBorderWidth);
  7506. setCtx(ctx, 'strokeStyle', textBorderColor);
  7507. if (style.strokeOpacity != null) {
  7508. var originalGlobalAlpha = ctx.globalAlpha;
  7509. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  7510. ctx.stroke();
  7511. ctx.globalAlpha = originalGlobalAlpha;
  7512. } else {
  7513. ctx.stroke();
  7514. }
  7515. }
  7516. }
  7517. function onBgImageLoaded(image, textBackgroundColor) {
  7518. // Replace image, so that `contain/text.js#parseRichText`
  7519. // will get correct result in next tick.
  7520. textBackgroundColor.image = image;
  7521. }
  7522. function getBoxPosition(out, hostEl, style, rect) {
  7523. var baseX = style.x || 0;
  7524. var baseY = style.y || 0;
  7525. var textAlign = style.textAlign;
  7526. var textVerticalAlign = style.textVerticalAlign; // Text position represented by coord
  7527. if (rect) {
  7528. var textPosition = style.textPosition;
  7529. if (textPosition instanceof Array) {
  7530. // Percent
  7531. baseX = rect.x + parsePercent(textPosition[0], rect.width);
  7532. baseY = rect.y + parsePercent(textPosition[1], rect.height);
  7533. } else {
  7534. var res = hostEl && hostEl.calculateTextPosition ? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect) : calculateTextPosition(_tmpTextPositionResult, style, rect);
  7535. baseX = res.x;
  7536. baseY = res.y; // Default align and baseline when has textPosition
  7537. textAlign = textAlign || res.textAlign;
  7538. textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
  7539. } // textOffset is only support in RectText, otherwise
  7540. // we have to adjust boundingRect for textOffset.
  7541. var textOffset = style.textOffset;
  7542. if (textOffset) {
  7543. baseX += textOffset[0];
  7544. baseY += textOffset[1];
  7545. }
  7546. }
  7547. out = out || {};
  7548. out.baseX = baseX;
  7549. out.baseY = baseY;
  7550. out.textAlign = textAlign;
  7551. out.textVerticalAlign = textVerticalAlign;
  7552. return out;
  7553. }
  7554. function setCtx(ctx, prop, value) {
  7555. ctx[prop] = fixShadow(ctx, prop, value);
  7556. return ctx[prop];
  7557. }
  7558. /**
  7559. * @param {string} [stroke] If specified, do not check style.textStroke.
  7560. * @param {string} [lineWidth] If specified, do not check style.textStroke.
  7561. * @param {number} style
  7562. */
  7563. function getStroke(stroke, lineWidth) {
  7564. return stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none' ? null // TODO pattern and gradient?
  7565. : stroke.image || stroke.colorStops ? '#000' : stroke;
  7566. }
  7567. function getFill(fill) {
  7568. return fill == null || fill === 'none' ? null // TODO pattern and gradient?
  7569. : fill.image || fill.colorStops ? '#000' : fill;
  7570. }
  7571. function parsePercent(value, maxValue) {
  7572. if (typeof value === 'string') {
  7573. if (value.lastIndexOf('%') >= 0) {
  7574. return parseFloat(value) / 100 * maxValue;
  7575. }
  7576. return parseFloat(value);
  7577. }
  7578. return value;
  7579. }
  7580. function getTextXForPadding(x, textAlign, textPadding) {
  7581. return textAlign === 'right' ? x - textPadding[1] : textAlign === 'center' ? x + textPadding[3] / 2 - textPadding[1] / 2 : x + textPadding[3];
  7582. }
  7583. /**
  7584. * @param {string} text
  7585. * @param {module:zrender/Style} style
  7586. * @return {boolean}
  7587. */
  7588. function needDrawText(text, style) {
  7589. return text != null && (text || style.textBackgroundColor || style.textBorderWidth && style.textBorderColor || style.textPadding);
  7590. }
  7591. /**
  7592. * Mixin for drawing text in a element bounding rect
  7593. * @module zrender/mixin/RectText
  7594. */
  7595. var tmpRect$1 = new BoundingRect();
  7596. var RectText = function () {};
  7597. RectText.prototype = {
  7598. constructor: RectText,
  7599. /**
  7600. * Draw text in a rect with specified position.
  7601. * @param {CanvasRenderingContext2D} ctx
  7602. * @param {Object} rect Displayable rect
  7603. */
  7604. drawRectText: function (ctx, rect) {
  7605. var style = this.style;
  7606. rect = style.textRect || rect; // Optimize, avoid normalize every time.
  7607. this.__dirty && normalizeTextStyle(style, true);
  7608. var text = style.text; // Convert to string
  7609. text != null && (text += '');
  7610. if (!needDrawText(text, style)) {
  7611. return;
  7612. } // FIXME
  7613. // Do not provide prevEl to `textHelper.renderText` for ctx prop cache,
  7614. // but use `ctx.save()` and `ctx.restore()`. Because the cache for rect
  7615. // text propably break the cache for its host elements.
  7616. ctx.save(); // Transform rect to view space
  7617. var transform = this.transform;
  7618. if (!style.transformText) {
  7619. if (transform) {
  7620. tmpRect$1.copy(rect);
  7621. tmpRect$1.applyTransform(transform);
  7622. rect = tmpRect$1;
  7623. }
  7624. } else {
  7625. this.setTransform(ctx);
  7626. } // transformText and textRotation can not be used at the same time.
  7627. renderText(this, ctx, text, style, rect, WILL_BE_RESTORED);
  7628. ctx.restore();
  7629. }
  7630. };
  7631. /**
  7632. * Base class of all displayable graphic objects
  7633. * @module zrender/graphic/Displayable
  7634. */
  7635. /**
  7636. * @alias module:zrender/graphic/Displayable
  7637. * @extends module:zrender/Element
  7638. * @extends module:zrender/graphic/mixin/RectText
  7639. */
  7640. function Displayable(opts) {
  7641. opts = opts || {};
  7642. Element.call(this, opts); // Extend properties
  7643. for (var name in opts) {
  7644. if (opts.hasOwnProperty(name) && name !== 'style') {
  7645. this[name] = opts[name];
  7646. }
  7647. }
  7648. /**
  7649. * @type {module:zrender/graphic/Style}
  7650. */
  7651. this.style = new Style(opts.style, this);
  7652. this._rect = null; // Shapes for cascade clipping.
  7653. // Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.
  7654. // because it is easy to only using null to check whether clipPaths changed.
  7655. this.__clipPaths = null; // FIXME Stateful must be mixined after style is setted
  7656. // Stateful.call(this, opts);
  7657. }
  7658. Displayable.prototype = {
  7659. constructor: Displayable,
  7660. type: 'displayable',
  7661. /**
  7662. * Dirty flag. From which painter will determine if this displayable object needs brush.
  7663. * @name module:zrender/graphic/Displayable#__dirty
  7664. * @type {boolean}
  7665. */
  7666. __dirty: true,
  7667. /**
  7668. * Whether the displayable object is visible. when it is true, the displayable object
  7669. * is not drawn, but the mouse event can still trigger the object.
  7670. * @name module:/zrender/graphic/Displayable#invisible
  7671. * @type {boolean}
  7672. * @default false
  7673. */
  7674. invisible: false,
  7675. /**
  7676. * @name module:/zrender/graphic/Displayable#z
  7677. * @type {number}
  7678. * @default 0
  7679. */
  7680. z: 0,
  7681. /**
  7682. * @name module:/zrender/graphic/Displayable#z
  7683. * @type {number}
  7684. * @default 0
  7685. */
  7686. z2: 0,
  7687. /**
  7688. * The z level determines the displayable object can be drawn in which layer canvas.
  7689. * @name module:/zrender/graphic/Displayable#zlevel
  7690. * @type {number}
  7691. * @default 0
  7692. */
  7693. zlevel: 0,
  7694. /**
  7695. * Whether it can be dragged.
  7696. * @name module:/zrender/graphic/Displayable#draggable
  7697. * @type {boolean}
  7698. * @default false
  7699. */
  7700. draggable: false,
  7701. /**
  7702. * Whether is it dragging.
  7703. * @name module:/zrender/graphic/Displayable#draggable
  7704. * @type {boolean}
  7705. * @default false
  7706. */
  7707. dragging: false,
  7708. /**
  7709. * Whether to respond to mouse events.
  7710. * @name module:/zrender/graphic/Displayable#silent
  7711. * @type {boolean}
  7712. * @default false
  7713. */
  7714. silent: false,
  7715. /**
  7716. * If enable culling
  7717. * @type {boolean}
  7718. * @default false
  7719. */
  7720. culling: false,
  7721. /**
  7722. * Mouse cursor when hovered
  7723. * @name module:/zrender/graphic/Displayable#cursor
  7724. * @type {string}
  7725. */
  7726. cursor: 'pointer',
  7727. /**
  7728. * If hover area is bounding rect
  7729. * @name module:/zrender/graphic/Displayable#rectHover
  7730. * @type {string}
  7731. */
  7732. rectHover: false,
  7733. /**
  7734. * Render the element progressively when the value >= 0,
  7735. * usefull for large data.
  7736. * @type {boolean}
  7737. */
  7738. progressive: false,
  7739. /**
  7740. * @type {boolean}
  7741. */
  7742. incremental: false,
  7743. /**
  7744. * Scale ratio for global scale.
  7745. * @type {boolean}
  7746. */
  7747. globalScaleRatio: 1,
  7748. beforeBrush: function (ctx) {},
  7749. afterBrush: function (ctx) {},
  7750. /**
  7751. * Graphic drawing method.
  7752. * @param {CanvasRenderingContext2D} ctx
  7753. */
  7754. // Interface
  7755. brush: function (ctx, prevEl) {},
  7756. /**
  7757. * Get the minimum bounding box.
  7758. * @return {module:zrender/core/BoundingRect}
  7759. */
  7760. // Interface
  7761. getBoundingRect: function () {},
  7762. /**
  7763. * If displayable element contain coord x, y
  7764. * @param {number} x
  7765. * @param {number} y
  7766. * @return {boolean}
  7767. */
  7768. contain: function (x, y) {
  7769. return this.rectContain(x, y);
  7770. },
  7771. /**
  7772. * @param {Function} cb
  7773. * @param {} context
  7774. */
  7775. traverse: function (cb, context) {
  7776. cb.call(context, this);
  7777. },
  7778. /**
  7779. * If bounding rect of element contain coord x, y
  7780. * @param {number} x
  7781. * @param {number} y
  7782. * @return {boolean}
  7783. */
  7784. rectContain: function (x, y) {
  7785. var coord = this.transformCoordToLocal(x, y);
  7786. var rect = this.getBoundingRect();
  7787. return rect.contain(coord[0], coord[1]);
  7788. },
  7789. /**
  7790. * Mark displayable element dirty and refresh next frame
  7791. */
  7792. dirty: function () {
  7793. this.__dirty = this.__dirtyText = true;
  7794. this._rect = null;
  7795. this.__zr && this.__zr.refresh();
  7796. },
  7797. /**
  7798. * If displayable object binded any event
  7799. * @return {boolean}
  7800. */
  7801. // TODO, events bound by bind
  7802. // isSilent: function () {
  7803. // return !(
  7804. // this.hoverable || this.draggable
  7805. // || this.onmousemove || this.onmouseover || this.onmouseout
  7806. // || this.onmousedown || this.onmouseup || this.onclick
  7807. // || this.ondragenter || this.ondragover || this.ondragleave
  7808. // || this.ondrop
  7809. // );
  7810. // },
  7811. /**
  7812. * Alias for animate('style')
  7813. * @param {boolean} loop
  7814. */
  7815. animateStyle: function (loop) {
  7816. return this.animate('style', loop);
  7817. },
  7818. attrKV: function (key, value) {
  7819. if (key !== 'style') {
  7820. Element.prototype.attrKV.call(this, key, value);
  7821. } else {
  7822. this.style.set(value);
  7823. }
  7824. },
  7825. /**
  7826. * @param {Object|string} key
  7827. * @param {*} value
  7828. */
  7829. setStyle: function (key, value) {
  7830. this.style.set(key, value);
  7831. this.dirty(false);
  7832. return this;
  7833. },
  7834. /**
  7835. * Use given style object
  7836. * @param {Object} obj
  7837. */
  7838. useStyle: function (obj) {
  7839. this.style = new Style(obj, this);
  7840. this.dirty(false);
  7841. return this;
  7842. },
  7843. /**
  7844. * The string value of `textPosition` needs to be calculated to a real postion.
  7845. * For example, `'inside'` is calculated to `[rect.width/2, rect.height/2]`
  7846. * by default. See `contain/text.js#calculateTextPosition` for more details.
  7847. * But some coutom shapes like "pin", "flag" have center that is not exactly
  7848. * `[width/2, height/2]`. So we provide this hook to customize the calculation
  7849. * for those shapes. It will be called if the `style.textPosition` is a string.
  7850. * @param {Obejct} [out] Prepared out object. If not provided, this method should
  7851. * be responsible for creating one.
  7852. * @param {module:zrender/graphic/Style} style
  7853. * @param {Object} rect {x, y, width, height}
  7854. * @return {Obejct} out The same as the input out.
  7855. * {
  7856. * x: number. mandatory.
  7857. * y: number. mandatory.
  7858. * textAlign: string. optional. use style.textAlign by default.
  7859. * textVerticalAlign: string. optional. use style.textVerticalAlign by default.
  7860. * }
  7861. */
  7862. calculateTextPosition: null
  7863. };
  7864. inherits(Displayable, Element);
  7865. mixin(Displayable, RectText);
  7866. /**
  7867. * @alias zrender/graphic/Image
  7868. * @extends module:zrender/graphic/Displayable
  7869. * @constructor
  7870. * @param {Object} opts
  7871. */
  7872. function ZImage(opts) {
  7873. Displayable.call(this, opts);
  7874. }
  7875. ZImage.prototype = {
  7876. constructor: ZImage,
  7877. type: 'image',
  7878. brush: function (ctx, prevEl) {
  7879. var style = this.style;
  7880. var src = style.image; // Must bind each time
  7881. style.bind(ctx, this, prevEl);
  7882. var image = this._image = createOrUpdateImage(src, this._image, this, this.onload);
  7883. if (!image || !isImageReady(image)) {
  7884. return;
  7885. } // 图片已经加载完成
  7886. // if (image.nodeName.toUpperCase() == 'IMG') {
  7887. // if (!image.complete) {
  7888. // return;
  7889. // }
  7890. // }
  7891. // Else is canvas
  7892. var x = style.x || 0;
  7893. var y = style.y || 0;
  7894. var width = style.width;
  7895. var height = style.height;
  7896. var aspect = image.width / image.height;
  7897. if (width == null && height != null) {
  7898. // Keep image/height ratio
  7899. width = height * aspect;
  7900. } else if (height == null && width != null) {
  7901. height = width / aspect;
  7902. } else if (width == null && height == null) {
  7903. width = image.width;
  7904. height = image.height;
  7905. } // 设置transform
  7906. this.setTransform(ctx);
  7907. if (style.sWidth && style.sHeight) {
  7908. var sx = style.sx || 0;
  7909. var sy = style.sy || 0;
  7910. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  7911. } else if (style.sx && style.sy) {
  7912. var sx = style.sx;
  7913. var sy = style.sy;
  7914. var sWidth = width - sx;
  7915. var sHeight = height - sy;
  7916. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  7917. } else {
  7918. ctx.drawImage(image, x, y, width, height);
  7919. } // Draw rect text
  7920. if (style.text != null) {
  7921. // Only restore transform when needs draw text.
  7922. this.restoreTransform(ctx);
  7923. this.drawRectText(ctx, this.getBoundingRect());
  7924. }
  7925. },
  7926. getBoundingRect: function () {
  7927. var style = this.style;
  7928. if (!this._rect) {
  7929. this._rect = new BoundingRect(style.x || 0, style.y || 0, style.width || 0, style.height || 0);
  7930. }
  7931. return this._rect;
  7932. }
  7933. };
  7934. inherits(ZImage, Displayable);
  7935. var HOVER_LAYER_ZLEVEL = 1e5;
  7936. var CANVAS_ZLEVEL = 314159;
  7937. var EL_AFTER_INCREMENTAL_INC = 0.01;
  7938. var INCREMENTAL_INC = 0.001;
  7939. function parseInt10(val) {
  7940. return parseInt(val, 10);
  7941. }
  7942. function isLayerValid(layer) {
  7943. if (!layer) {
  7944. return false;
  7945. }
  7946. if (layer.__builtin__) {
  7947. return true;
  7948. }
  7949. if (typeof layer.resize !== 'function' || typeof layer.refresh !== 'function') {
  7950. return false;
  7951. }
  7952. return true;
  7953. }
  7954. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7955. var viewRect = new BoundingRect(0, 0, 0, 0);
  7956. function isDisplayableCulled(el, width, height) {
  7957. tmpRect.copy(el.getBoundingRect());
  7958. if (el.transform) {
  7959. tmpRect.applyTransform(el.transform);
  7960. }
  7961. viewRect.width = width;
  7962. viewRect.height = height;
  7963. return !tmpRect.intersect(viewRect);
  7964. }
  7965. function isClipPathChanged(clipPaths, prevClipPaths) {
  7966. // displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
  7967. if (clipPaths === prevClipPaths) {
  7968. return false;
  7969. }
  7970. if (!clipPaths || !prevClipPaths || clipPaths.length !== prevClipPaths.length) {
  7971. return true;
  7972. }
  7973. for (var i = 0; i < clipPaths.length; i++) {
  7974. if (clipPaths[i] !== prevClipPaths[i]) {
  7975. return true;
  7976. }
  7977. }
  7978. return false;
  7979. }
  7980. function doClip(clipPaths, ctx) {
  7981. for (var i = 0; i < clipPaths.length; i++) {
  7982. var clipPath = clipPaths[i];
  7983. clipPath.setTransform(ctx);
  7984. ctx.beginPath();
  7985. clipPath.buildPath(ctx, clipPath.shape);
  7986. ctx.clip(); // Transform back
  7987. clipPath.restoreTransform(ctx);
  7988. }
  7989. }
  7990. function createRoot(width, height) {
  7991. var domRoot = document.createElement('div'); // domRoot.onselectstart = returnFalse; // Avoid page selected
  7992. domRoot.style.cssText = ['position:relative', // IOS13 safari probably has a compositing bug (z order of the canvas and the consequent
  7993. // dom does not act as expected) when some of the parent dom has
  7994. // `-webkit-overflow-scrolling: touch;` and the webpage is longer than one screen and
  7995. // the canvas is not at the top part of the page.
  7996. // Check `https://bugs.webkit.org/show_bug.cgi?id=203681` for more details. We remove
  7997. // this `overflow:hidden` to avoid the bug.
  7998. // 'overflow:hidden',
  7999. 'width:' + width + 'px', 'height:' + height + 'px', 'padding:0', 'margin:0', 'border-width:0'].join(';') + ';';
  8000. return domRoot;
  8001. }
  8002. /**
  8003. * @alias module:zrender/Painter
  8004. * @constructor
  8005. * @param {HTMLElement} root 绘图容器
  8006. * @param {module:zrender/Storage} storage
  8007. * @param {Object} opts
  8008. */
  8009. var Painter = function (root, storage, opts) {
  8010. this.type = 'canvas'; // In node environment using node-canvas
  8011. var singleCanvas = !root.nodeName // In node ?
  8012. || root.nodeName.toUpperCase() === 'CANVAS';
  8013. this._opts = opts = extend({}, opts || {});
  8014. /**
  8015. * @type {number}
  8016. */
  8017. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  8018. /**
  8019. * @type {boolean}
  8020. * @private
  8021. */
  8022. this._singleCanvas = singleCanvas;
  8023. /**
  8024. * 绘图容器
  8025. * @type {HTMLElement}
  8026. */
  8027. this.root = root;
  8028. var rootStyle = root.style;
  8029. if (rootStyle) {
  8030. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  8031. rootStyle['-webkit-user-select'] = rootStyle['user-select'] = rootStyle['-webkit-touch-callout'] = 'none';
  8032. root.innerHTML = '';
  8033. }
  8034. /**
  8035. * @type {module:zrender/Storage}
  8036. */
  8037. this.storage = storage;
  8038. /**
  8039. * @type {Array.<number>}
  8040. * @private
  8041. */
  8042. var zlevelList = this._zlevelList = [];
  8043. /**
  8044. * @type {Object.<string, module:zrender/Layer>}
  8045. * @private
  8046. */
  8047. var layers = this._layers = {};
  8048. /**
  8049. * @type {Object.<string, Object>}
  8050. * @private
  8051. */
  8052. this._layerConfig = {};
  8053. /**
  8054. * zrender will do compositing when root is a canvas and have multiple zlevels.
  8055. */
  8056. this._needsManuallyCompositing = false;
  8057. if (!singleCanvas) {
  8058. this._width = this._getSize(0);
  8059. this._height = this._getSize(1);
  8060. var domRoot = this._domRoot = createRoot(this._width, this._height);
  8061. root.appendChild(domRoot);
  8062. } else {
  8063. var width = root.width;
  8064. var height = root.height;
  8065. if (opts.width != null) {
  8066. width = opts.width;
  8067. }
  8068. if (opts.height != null) {
  8069. height = opts.height;
  8070. }
  8071. this.dpr = opts.devicePixelRatio || 1; // Use canvas width and height directly
  8072. root.width = width * this.dpr;
  8073. root.height = height * this.dpr;
  8074. this._width = width;
  8075. this._height = height; // Create layer if only one given canvas
  8076. // Device can be specified to create a high dpi image.
  8077. var mainLayer = new Layer(root, this, this.dpr);
  8078. mainLayer.__builtin__ = true;
  8079. mainLayer.initContext(); // FIXME Use canvas width and height
  8080. // mainLayer.resize(width, height);
  8081. layers[CANVAS_ZLEVEL] = mainLayer;
  8082. mainLayer.zlevel = CANVAS_ZLEVEL; // Not use common zlevel.
  8083. zlevelList.push(CANVAS_ZLEVEL);
  8084. this._domRoot = root;
  8085. }
  8086. /**
  8087. * @type {module:zrender/Layer}
  8088. * @private
  8089. */
  8090. this._hoverlayer = null;
  8091. this._hoverElements = [];
  8092. };
  8093. Painter.prototype = {
  8094. constructor: Painter,
  8095. getType: function () {
  8096. return 'canvas';
  8097. },
  8098. /**
  8099. * If painter use a single canvas
  8100. * @return {boolean}
  8101. */
  8102. isSingleCanvas: function () {
  8103. return this._singleCanvas;
  8104. },
  8105. /**
  8106. * @return {HTMLDivElement}
  8107. */
  8108. getViewportRoot: function () {
  8109. return this._domRoot;
  8110. },
  8111. getViewportRootOffset: function () {
  8112. var viewportRoot = this.getViewportRoot();
  8113. if (viewportRoot) {
  8114. return {
  8115. offsetLeft: viewportRoot.offsetLeft || 0,
  8116. offsetTop: viewportRoot.offsetTop || 0
  8117. };
  8118. }
  8119. },
  8120. /**
  8121. * 刷新
  8122. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  8123. */
  8124. refresh: function (paintAll) {
  8125. var list = this.storage.getDisplayList(true);
  8126. var zlevelList = this._zlevelList;
  8127. this._redrawId = Math.random();
  8128. this._paintList(list, paintAll, this._redrawId); // Paint custum layers
  8129. for (var i = 0; i < zlevelList.length; i++) {
  8130. var z = zlevelList[i];
  8131. var layer = this._layers[z];
  8132. if (!layer.__builtin__ && layer.refresh) {
  8133. var clearColor = i === 0 ? this._backgroundColor : null;
  8134. layer.refresh(clearColor);
  8135. }
  8136. }
  8137. this.refreshHover();
  8138. return this;
  8139. },
  8140. addHover: function (el, hoverStyle) {
  8141. if (el.__hoverMir) {
  8142. return;
  8143. }
  8144. var elMirror = new el.constructor({
  8145. style: el.style,
  8146. shape: el.shape,
  8147. z: el.z,
  8148. z2: el.z2,
  8149. silent: el.silent
  8150. });
  8151. elMirror.__from = el;
  8152. el.__hoverMir = elMirror;
  8153. hoverStyle && elMirror.setStyle(hoverStyle);
  8154. this._hoverElements.push(elMirror);
  8155. return elMirror;
  8156. },
  8157. removeHover: function (el) {
  8158. var elMirror = el.__hoverMir;
  8159. var hoverElements = this._hoverElements;
  8160. var idx = indexOf(hoverElements, elMirror);
  8161. if (idx >= 0) {
  8162. hoverElements.splice(idx, 1);
  8163. }
  8164. el.__hoverMir = null;
  8165. },
  8166. clearHover: function (el) {
  8167. var hoverElements = this._hoverElements;
  8168. for (var i = 0; i < hoverElements.length; i++) {
  8169. var from = hoverElements[i].__from;
  8170. if (from) {
  8171. from.__hoverMir = null;
  8172. }
  8173. }
  8174. hoverElements.length = 0;
  8175. },
  8176. refreshHover: function () {
  8177. var hoverElements = this._hoverElements;
  8178. var len = hoverElements.length;
  8179. var hoverLayer = this._hoverlayer;
  8180. hoverLayer && hoverLayer.clear();
  8181. if (!len) {
  8182. return;
  8183. }
  8184. sort(hoverElements, this.storage.displayableSortFunc); // Use a extream large zlevel
  8185. // FIXME?
  8186. if (!hoverLayer) {
  8187. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  8188. }
  8189. var scope = {};
  8190. hoverLayer.ctx.save();
  8191. for (var i = 0; i < len;) {
  8192. var el = hoverElements[i];
  8193. var originalEl = el.__from; // Original el is removed
  8194. // PENDING
  8195. if (!(originalEl && originalEl.__zr)) {
  8196. hoverElements.splice(i, 1);
  8197. originalEl.__hoverMir = null;
  8198. len--;
  8199. continue;
  8200. }
  8201. i++; // Use transform
  8202. // FIXME style and shape ?
  8203. if (!originalEl.invisible) {
  8204. el.transform = originalEl.transform;
  8205. el.invTransform = originalEl.invTransform;
  8206. el.__clipPaths = originalEl.__clipPaths; // el.
  8207. this._doPaintEl(el, hoverLayer, true, scope);
  8208. }
  8209. }
  8210. hoverLayer.ctx.restore();
  8211. },
  8212. getHoverLayer: function () {
  8213. return this.getLayer(HOVER_LAYER_ZLEVEL);
  8214. },
  8215. _paintList: function (list, paintAll, redrawId) {
  8216. if (this._redrawId !== redrawId) {
  8217. return;
  8218. }
  8219. paintAll = paintAll || false;
  8220. this._updateLayerStatus(list);
  8221. var finished = this._doPaintList(list, paintAll);
  8222. if (this._needsManuallyCompositing) {
  8223. this._compositeManually();
  8224. }
  8225. if (!finished) {
  8226. var self = this;
  8227. requestAnimationFrame(function () {
  8228. self._paintList(list, paintAll, redrawId);
  8229. });
  8230. }
  8231. },
  8232. _compositeManually: function () {
  8233. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  8234. var width = this._domRoot.width;
  8235. var height = this._domRoot.height;
  8236. ctx.clearRect(0, 0, width, height); // PENDING, If only builtin layer?
  8237. this.eachBuiltinLayer(function (layer) {
  8238. if (layer.virtual) {
  8239. ctx.drawImage(layer.dom, 0, 0, width, height);
  8240. }
  8241. });
  8242. },
  8243. _doPaintList: function (list, paintAll) {
  8244. var layerList = [];
  8245. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  8246. var zlevel = this._zlevelList[zi];
  8247. var layer = this._layers[zlevel];
  8248. if (layer.__builtin__ && layer !== this._hoverlayer && (layer.__dirty || paintAll)) {
  8249. layerList.push(layer);
  8250. }
  8251. }
  8252. var finished = true;
  8253. for (var k = 0; k < layerList.length; k++) {
  8254. var layer = layerList[k];
  8255. var ctx = layer.ctx;
  8256. var scope = {};
  8257. ctx.save();
  8258. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  8259. var useTimer = !paintAll && layer.incremental && Date.now;
  8260. var startTime = useTimer && Date.now();
  8261. var clearColor = layer.zlevel === this._zlevelList[0] ? this._backgroundColor : null; // All elements in this layer are cleared.
  8262. if (layer.__startIndex === layer.__endIndex) {
  8263. layer.clear(false, clearColor);
  8264. } else if (start === layer.__startIndex) {
  8265. var firstEl = list[start];
  8266. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  8267. layer.clear(false, clearColor);
  8268. }
  8269. }
  8270. if (start === -1) {
  8271. console.error('For some unknown reason. drawIndex is -1');
  8272. start = layer.__startIndex;
  8273. }
  8274. for (var i = start; i < layer.__endIndex; i++) {
  8275. var el = list[i];
  8276. this._doPaintEl(el, layer, paintAll, scope);
  8277. el.__dirty = el.__dirtyText = false;
  8278. if (useTimer) {
  8279. // Date.now can be executed in 13,025,305 ops/second.
  8280. var dTime = Date.now() - startTime; // Give 15 millisecond to draw.
  8281. // The rest elements will be drawn in the next frame.
  8282. if (dTime > 15) {
  8283. break;
  8284. }
  8285. }
  8286. }
  8287. layer.__drawIndex = i;
  8288. if (layer.__drawIndex < layer.__endIndex) {
  8289. finished = false;
  8290. }
  8291. if (scope.prevElClipPaths) {
  8292. // Needs restore the state. If last drawn element is in the clipping area.
  8293. ctx.restore();
  8294. }
  8295. ctx.restore();
  8296. }
  8297. if (env$1.wxa) {
  8298. // Flush for weixin application
  8299. each$1(this._layers, function (layer) {
  8300. if (layer && layer.ctx && layer.ctx.draw) {
  8301. layer.ctx.draw();
  8302. }
  8303. });
  8304. }
  8305. return finished;
  8306. },
  8307. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  8308. var ctx = currentLayer.ctx;
  8309. var m = el.transform;
  8310. if ((currentLayer.__dirty || forcePaint) && // Ignore invisible element
  8311. !el.invisible // Ignore transparent element
  8312. && el.style.opacity !== 0 // Ignore scale 0 element, in some environment like node-canvas
  8313. // Draw a scale 0 element can cause all following draw wrong
  8314. // And setTransform with scale 0 will cause set back transform failed.
  8315. && !(m && !m[0] && !m[3]) // Ignore culled element
  8316. && !(el.culling && isDisplayableCulled(el, this._width, this._height))) {
  8317. var clipPaths = el.__clipPaths;
  8318. var prevElClipPaths = scope.prevElClipPaths; // Optimize when clipping on group with several elements
  8319. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  8320. // If has previous clipping state, restore from it
  8321. if (prevElClipPaths) {
  8322. ctx.restore();
  8323. scope.prevElClipPaths = null; // Reset prevEl since context has been restored
  8324. scope.prevEl = null;
  8325. } // New clipping state
  8326. if (clipPaths) {
  8327. ctx.save();
  8328. doClip(clipPaths, ctx);
  8329. scope.prevElClipPaths = clipPaths;
  8330. }
  8331. }
  8332. el.beforeBrush && el.beforeBrush(ctx);
  8333. el.brush(ctx, scope.prevEl || null);
  8334. scope.prevEl = el;
  8335. el.afterBrush && el.afterBrush(ctx);
  8336. }
  8337. },
  8338. /**
  8339. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  8340. * @param {number} zlevel
  8341. * @param {boolean} virtual Virtual layer will not be inserted into dom.
  8342. * @return {module:zrender/Layer}
  8343. */
  8344. getLayer: function (zlevel, virtual) {
  8345. if (this._singleCanvas && !this._needsManuallyCompositing) {
  8346. zlevel = CANVAS_ZLEVEL;
  8347. }
  8348. var layer = this._layers[zlevel];
  8349. if (!layer) {
  8350. // Create a new layer
  8351. layer = new Layer('zr_' + zlevel, this, this.dpr);
  8352. layer.zlevel = zlevel;
  8353. layer.__builtin__ = true;
  8354. if (this._layerConfig[zlevel]) {
  8355. merge(layer, this._layerConfig[zlevel], true);
  8356. } // TODO Remove EL_AFTER_INCREMENTAL_INC magic number
  8357. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  8358. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  8359. }
  8360. if (virtual) {
  8361. layer.virtual = virtual;
  8362. }
  8363. this.insertLayer(zlevel, layer); // Context is created after dom inserted to document
  8364. // Or excanvas will get 0px clientWidth and clientHeight
  8365. layer.initContext();
  8366. }
  8367. return layer;
  8368. },
  8369. insertLayer: function (zlevel, layer) {
  8370. var layersMap = this._layers;
  8371. var zlevelList = this._zlevelList;
  8372. var len = zlevelList.length;
  8373. var prevLayer = null;
  8374. var i = -1;
  8375. var domRoot = this._domRoot;
  8376. if (layersMap[zlevel]) {
  8377. logError$1('ZLevel ' + zlevel + ' has been used already');
  8378. return;
  8379. } // Check if is a valid layer
  8380. if (!isLayerValid(layer)) {
  8381. logError$1('Layer of zlevel ' + zlevel + ' is not valid');
  8382. return;
  8383. }
  8384. if (len > 0 && zlevel > zlevelList[0]) {
  8385. for (i = 0; i < len - 1; i++) {
  8386. if (zlevelList[i] < zlevel && zlevelList[i + 1] > zlevel) {
  8387. break;
  8388. }
  8389. }
  8390. prevLayer = layersMap[zlevelList[i]];
  8391. }
  8392. zlevelList.splice(i + 1, 0, zlevel);
  8393. layersMap[zlevel] = layer; // Vitual layer will not directly show on the screen.
  8394. // (It can be a WebGL layer and assigned to a ZImage element)
  8395. // But it still under management of zrender.
  8396. if (!layer.virtual) {
  8397. if (prevLayer) {
  8398. var prevDom = prevLayer.dom;
  8399. if (prevDom.nextSibling) {
  8400. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  8401. } else {
  8402. domRoot.appendChild(layer.dom);
  8403. }
  8404. } else {
  8405. if (domRoot.firstChild) {
  8406. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  8407. } else {
  8408. domRoot.appendChild(layer.dom);
  8409. }
  8410. }
  8411. }
  8412. },
  8413. // Iterate each layer
  8414. eachLayer: function (cb, context) {
  8415. var zlevelList = this._zlevelList;
  8416. var z;
  8417. var i;
  8418. for (i = 0; i < zlevelList.length; i++) {
  8419. z = zlevelList[i];
  8420. cb.call(context, this._layers[z], z);
  8421. }
  8422. },
  8423. // Iterate each buildin layer
  8424. eachBuiltinLayer: function (cb, context) {
  8425. var zlevelList = this._zlevelList;
  8426. var layer;
  8427. var z;
  8428. var i;
  8429. for (i = 0; i < zlevelList.length; i++) {
  8430. z = zlevelList[i];
  8431. layer = this._layers[z];
  8432. if (layer.__builtin__) {
  8433. cb.call(context, layer, z);
  8434. }
  8435. }
  8436. },
  8437. // Iterate each other layer except buildin layer
  8438. eachOtherLayer: function (cb, context) {
  8439. var zlevelList = this._zlevelList;
  8440. var layer;
  8441. var z;
  8442. var i;
  8443. for (i = 0; i < zlevelList.length; i++) {
  8444. z = zlevelList[i];
  8445. layer = this._layers[z];
  8446. if (!layer.__builtin__) {
  8447. cb.call(context, layer, z);
  8448. }
  8449. }
  8450. },
  8451. /**
  8452. * 获取所有已创建的层
  8453. * @param {Array.<module:zrender/Layer>} [prevLayer]
  8454. */
  8455. getLayers: function () {
  8456. return this._layers;
  8457. },
  8458. _updateLayerStatus: function (list) {
  8459. this.eachBuiltinLayer(function (layer, z) {
  8460. layer.__dirty = layer.__used = false;
  8461. });
  8462. function updatePrevLayer(idx) {
  8463. if (prevLayer) {
  8464. if (prevLayer.__endIndex !== idx) {
  8465. prevLayer.__dirty = true;
  8466. }
  8467. prevLayer.__endIndex = idx;
  8468. }
  8469. }
  8470. if (this._singleCanvas) {
  8471. for (var i = 1; i < list.length; i++) {
  8472. var el = list[i];
  8473. if (el.zlevel !== list[i - 1].zlevel || el.incremental) {
  8474. this._needsManuallyCompositing = true;
  8475. break;
  8476. }
  8477. }
  8478. }
  8479. var prevLayer = null;
  8480. var incrementalLayerCount = 0;
  8481. var prevZlevel;
  8482. for (var i = 0; i < list.length; i++) {
  8483. var el = list[i];
  8484. var zlevel = el.zlevel;
  8485. var layer;
  8486. if (prevZlevel !== zlevel) {
  8487. prevZlevel = zlevel;
  8488. incrementalLayerCount = 0;
  8489. } // TODO Not use magic number on zlevel.
  8490. // Each layer with increment element can be separated to 3 layers.
  8491. // (Other Element drawn after incremental element)
  8492. // -----------------zlevel + EL_AFTER_INCREMENTAL_INC--------------------
  8493. // (Incremental element)
  8494. // ----------------------zlevel + INCREMENTAL_INC------------------------
  8495. // (Element drawn before incremental element)
  8496. // --------------------------------zlevel--------------------------------
  8497. if (el.incremental) {
  8498. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  8499. layer.incremental = true;
  8500. incrementalLayerCount = 1;
  8501. } else {
  8502. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  8503. }
  8504. if (!layer.__builtin__) {
  8505. logError$1('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  8506. }
  8507. if (layer !== prevLayer) {
  8508. layer.__used = true;
  8509. if (layer.__startIndex !== i) {
  8510. layer.__dirty = true;
  8511. }
  8512. layer.__startIndex = i;
  8513. if (!layer.incremental) {
  8514. layer.__drawIndex = i;
  8515. } else {
  8516. // Mark layer draw index needs to update.
  8517. layer.__drawIndex = -1;
  8518. }
  8519. updatePrevLayer(i);
  8520. prevLayer = layer;
  8521. }
  8522. if (el.__dirty) {
  8523. layer.__dirty = true;
  8524. if (layer.incremental && layer.__drawIndex < 0) {
  8525. // Start draw from the first dirty element.
  8526. layer.__drawIndex = i;
  8527. }
  8528. }
  8529. }
  8530. updatePrevLayer(i);
  8531. this.eachBuiltinLayer(function (layer, z) {
  8532. // Used in last frame but not in this frame. Needs clear
  8533. if (!layer.__used && layer.getElementCount() > 0) {
  8534. layer.__dirty = true;
  8535. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  8536. } // For incremental layer. In case start index changed and no elements are dirty.
  8537. if (layer.__dirty && layer.__drawIndex < 0) {
  8538. layer.__drawIndex = layer.__startIndex;
  8539. }
  8540. });
  8541. },
  8542. /**
  8543. * 清除hover层外所有内容
  8544. */
  8545. clear: function () {
  8546. this.eachBuiltinLayer(this._clearLayer);
  8547. return this;
  8548. },
  8549. _clearLayer: function (layer) {
  8550. layer.clear();
  8551. },
  8552. setBackgroundColor: function (backgroundColor) {
  8553. this._backgroundColor = backgroundColor;
  8554. },
  8555. /**
  8556. * 修改指定zlevel的绘制参数
  8557. *
  8558. * @param {string} zlevel
  8559. * @param {Object} config 配置对象
  8560. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  8561. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  8562. * @param {number} [config.lastFrameAlpha=0.7]
  8563. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  8564. */
  8565. configLayer: function (zlevel, config) {
  8566. if (config) {
  8567. var layerConfig = this._layerConfig;
  8568. if (!layerConfig[zlevel]) {
  8569. layerConfig[zlevel] = config;
  8570. } else {
  8571. merge(layerConfig[zlevel], config, true);
  8572. }
  8573. for (var i = 0; i < this._zlevelList.length; i++) {
  8574. var _zlevel = this._zlevelList[i]; // TODO Remove EL_AFTER_INCREMENTAL_INC magic number
  8575. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  8576. var layer = this._layers[_zlevel];
  8577. merge(layer, layerConfig[zlevel], true);
  8578. }
  8579. }
  8580. }
  8581. },
  8582. /**
  8583. * 删除指定层
  8584. * @param {number} zlevel 层所在的zlevel
  8585. */
  8586. delLayer: function (zlevel) {
  8587. var layers = this._layers;
  8588. var zlevelList = this._zlevelList;
  8589. var layer = layers[zlevel];
  8590. if (!layer) {
  8591. return;
  8592. }
  8593. layer.dom.parentNode.removeChild(layer.dom);
  8594. delete layers[zlevel];
  8595. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  8596. },
  8597. /**
  8598. * 区域大小变化后重绘
  8599. */
  8600. resize: function (width, height) {
  8601. if (!this._domRoot.style) {
  8602. // Maybe in node or worker
  8603. if (width == null || height == null) {
  8604. return;
  8605. }
  8606. this._width = width;
  8607. this._height = height;
  8608. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  8609. } else {
  8610. var domRoot = this._domRoot; // FIXME Why ?
  8611. domRoot.style.display = 'none'; // Save input w/h
  8612. var opts = this._opts;
  8613. width != null && (opts.width = width);
  8614. height != null && (opts.height = height);
  8615. width = this._getSize(0);
  8616. height = this._getSize(1);
  8617. domRoot.style.display = ''; // 优化没有实际改变的resize
  8618. if (this._width !== width || height !== this._height) {
  8619. domRoot.style.width = width + 'px';
  8620. domRoot.style.height = height + 'px';
  8621. for (var id in this._layers) {
  8622. if (this._layers.hasOwnProperty(id)) {
  8623. this._layers[id].resize(width, height);
  8624. }
  8625. }
  8626. each$1(this._progressiveLayers, function (layer) {
  8627. layer.resize(width, height);
  8628. });
  8629. this.refresh(true);
  8630. }
  8631. this._width = width;
  8632. this._height = height;
  8633. }
  8634. return this;
  8635. },
  8636. /**
  8637. * 清除单独的一个层
  8638. * @param {number} zlevel
  8639. */
  8640. clearLayer: function (zlevel) {
  8641. var layer = this._layers[zlevel];
  8642. if (layer) {
  8643. layer.clear();
  8644. }
  8645. },
  8646. /**
  8647. * 释放
  8648. */
  8649. dispose: function () {
  8650. this.root.innerHTML = '';
  8651. this.root = this.storage = this._domRoot = this._layers = null;
  8652. },
  8653. /**
  8654. * Get canvas which has all thing rendered
  8655. * @param {Object} opts
  8656. * @param {string} [opts.backgroundColor]
  8657. * @param {number} [opts.pixelRatio]
  8658. */
  8659. getRenderedCanvas: function (opts) {
  8660. opts = opts || {};
  8661. if (this._singleCanvas && !this._compositeManually) {
  8662. return this._layers[CANVAS_ZLEVEL].dom;
  8663. }
  8664. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  8665. imageLayer.initContext();
  8666. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  8667. if (opts.pixelRatio <= this.dpr) {
  8668. this.refresh();
  8669. var width = imageLayer.dom.width;
  8670. var height = imageLayer.dom.height;
  8671. var ctx = imageLayer.ctx;
  8672. this.eachLayer(function (layer) {
  8673. if (layer.__builtin__) {
  8674. ctx.drawImage(layer.dom, 0, 0, width, height);
  8675. } else if (layer.renderToCanvas) {
  8676. imageLayer.ctx.save();
  8677. layer.renderToCanvas(imageLayer.ctx);
  8678. imageLayer.ctx.restore();
  8679. }
  8680. });
  8681. } else {
  8682. // PENDING, echarts-gl and incremental rendering.
  8683. var scope = {};
  8684. var displayList = this.storage.getDisplayList(true);
  8685. for (var i = 0; i < displayList.length; i++) {
  8686. var el = displayList[i];
  8687. this._doPaintEl(el, imageLayer, true, scope);
  8688. }
  8689. }
  8690. return imageLayer.dom;
  8691. },
  8692. /**
  8693. * 获取绘图区域宽度
  8694. */
  8695. getWidth: function () {
  8696. return this._width;
  8697. },
  8698. /**
  8699. * 获取绘图区域高度
  8700. */
  8701. getHeight: function () {
  8702. return this._height;
  8703. },
  8704. _getSize: function (whIdx) {
  8705. var opts = this._opts;
  8706. var wh = ['width', 'height'][whIdx];
  8707. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  8708. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  8709. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  8710. if (opts[wh] != null && opts[wh] !== 'auto') {
  8711. return parseFloat(opts[wh]);
  8712. }
  8713. var root = this.root; // IE8 does not support getComputedStyle, but it use VML.
  8714. var stl = document.defaultView.getComputedStyle(root);
  8715. return (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh])) - (parseInt10(stl[plt]) || 0) - (parseInt10(stl[prb]) || 0) | 0;
  8716. },
  8717. pathToImage: function (path, dpr) {
  8718. dpr = dpr || this.dpr;
  8719. var canvas = document.createElement('canvas');
  8720. var ctx = canvas.getContext('2d');
  8721. var rect = path.getBoundingRect();
  8722. var style = path.style;
  8723. var shadowBlurSize = style.shadowBlur * dpr;
  8724. var shadowOffsetX = style.shadowOffsetX * dpr;
  8725. var shadowOffsetY = style.shadowOffsetY * dpr;
  8726. var lineWidth = style.hasStroke() ? style.lineWidth : 0;
  8727. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  8728. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  8729. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  8730. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  8731. var width = rect.width + leftMargin + rightMargin;
  8732. var height = rect.height + topMargin + bottomMargin;
  8733. canvas.width = width * dpr;
  8734. canvas.height = height * dpr;
  8735. ctx.scale(dpr, dpr);
  8736. ctx.clearRect(0, 0, width, height);
  8737. ctx.dpr = dpr;
  8738. var pathTransform = {
  8739. position: path.position,
  8740. rotation: path.rotation,
  8741. scale: path.scale
  8742. };
  8743. path.position = [leftMargin - rect.x, topMargin - rect.y];
  8744. path.rotation = 0;
  8745. path.scale = [1, 1];
  8746. path.updateTransform();
  8747. if (path) {
  8748. path.brush(ctx);
  8749. }
  8750. var ImageShape = ZImage;
  8751. var imgShape = new ImageShape({
  8752. style: {
  8753. x: 0,
  8754. y: 0,
  8755. image: canvas
  8756. }
  8757. });
  8758. if (pathTransform.position != null) {
  8759. imgShape.position = path.position = pathTransform.position;
  8760. }
  8761. if (pathTransform.rotation != null) {
  8762. imgShape.rotation = path.rotation = pathTransform.rotation;
  8763. }
  8764. if (pathTransform.scale != null) {
  8765. imgShape.scale = path.scale = pathTransform.scale;
  8766. }
  8767. return imgShape;
  8768. }
  8769. };
  8770. /**
  8771. * Animation main class, dispatch and manage all animation controllers
  8772. *
  8773. * @module zrender/animation/Animation
  8774. * @author pissang(https://github.com/pissang)
  8775. */
  8776. // TODO Additive animation
  8777. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  8778. // https://developer.apple.com/videos/wwdc2014/#236
  8779. /**
  8780. * @typedef {Object} IZRenderStage
  8781. * @property {Function} update
  8782. */
  8783. /**
  8784. * @alias module:zrender/animation/Animation
  8785. * @constructor
  8786. * @param {Object} [options]
  8787. * @param {Function} [options.onframe]
  8788. * @param {IZRenderStage} [options.stage]
  8789. * @example
  8790. * var animation = new Animation();
  8791. * var obj = {
  8792. * x: 100,
  8793. * y: 100
  8794. * };
  8795. * animation.animate(node.position)
  8796. * .when(1000, {
  8797. * x: 500,
  8798. * y: 500
  8799. * })
  8800. * .when(2000, {
  8801. * x: 100,
  8802. * y: 100
  8803. * })
  8804. * .start('spline');
  8805. */
  8806. var Animation = function (options) {
  8807. options = options || {};
  8808. this.stage = options.stage || {};
  8809. this.onframe = options.onframe || function () {}; // private properties
  8810. this._clips = [];
  8811. this._running = false;
  8812. this._time;
  8813. this._pausedTime;
  8814. this._pauseStart;
  8815. this._paused = false;
  8816. Eventful.call(this);
  8817. };
  8818. Animation.prototype = {
  8819. constructor: Animation,
  8820. /**
  8821. * Add clip
  8822. * @param {module:zrender/animation/Clip} clip
  8823. */
  8824. addClip: function (clip) {
  8825. this._clips.push(clip);
  8826. },
  8827. /**
  8828. * Add animator
  8829. * @param {module:zrender/animation/Animator} animator
  8830. */
  8831. addAnimator: function (animator) {
  8832. animator.animation = this;
  8833. var clips = animator.getClips();
  8834. for (var i = 0; i < clips.length; i++) {
  8835. this.addClip(clips[i]);
  8836. }
  8837. },
  8838. /**
  8839. * Delete animation clip
  8840. * @param {module:zrender/animation/Clip} clip
  8841. */
  8842. removeClip: function (clip) {
  8843. var idx = indexOf(this._clips, clip);
  8844. if (idx >= 0) {
  8845. this._clips.splice(idx, 1);
  8846. }
  8847. },
  8848. /**
  8849. * Delete animation clip
  8850. * @param {module:zrender/animation/Animator} animator
  8851. */
  8852. removeAnimator: function (animator) {
  8853. var clips = animator.getClips();
  8854. for (var i = 0; i < clips.length; i++) {
  8855. this.removeClip(clips[i]);
  8856. }
  8857. animator.animation = null;
  8858. },
  8859. _update: function () {
  8860. var time = new Date().getTime() - this._pausedTime;
  8861. var delta = time - this._time;
  8862. var clips = this._clips;
  8863. var len = clips.length;
  8864. var deferredEvents = [];
  8865. var deferredClips = [];
  8866. for (var i = 0; i < len; i++) {
  8867. var clip = clips[i];
  8868. var e = clip.step(time, delta); // Throw out the events need to be called after
  8869. // stage.update, like destroy
  8870. if (e) {
  8871. deferredEvents.push(e);
  8872. deferredClips.push(clip);
  8873. }
  8874. } // Remove the finished clip
  8875. for (var i = 0; i < len;) {
  8876. if (clips[i]._needsRemove) {
  8877. clips[i] = clips[len - 1];
  8878. clips.pop();
  8879. len--;
  8880. } else {
  8881. i++;
  8882. }
  8883. }
  8884. len = deferredEvents.length;
  8885. for (var i = 0; i < len; i++) {
  8886. deferredClips[i].fire(deferredEvents[i]);
  8887. }
  8888. this._time = time;
  8889. this.onframe(delta); // 'frame' should be triggered before stage, because upper application
  8890. // depends on the sequence (e.g., echarts-stream and finish
  8891. // event judge)
  8892. this.trigger('frame', delta);
  8893. if (this.stage.update) {
  8894. this.stage.update();
  8895. }
  8896. },
  8897. _startLoop: function () {
  8898. var self = this;
  8899. this._running = true;
  8900. function step() {
  8901. if (self._running) {
  8902. requestAnimationFrame(step);
  8903. !self._paused && self._update();
  8904. }
  8905. }
  8906. requestAnimationFrame(step);
  8907. },
  8908. /**
  8909. * Start animation.
  8910. */
  8911. start: function () {
  8912. this._time = new Date().getTime();
  8913. this._pausedTime = 0;
  8914. this._startLoop();
  8915. },
  8916. /**
  8917. * Stop animation.
  8918. */
  8919. stop: function () {
  8920. this._running = false;
  8921. },
  8922. /**
  8923. * Pause animation.
  8924. */
  8925. pause: function () {
  8926. if (!this._paused) {
  8927. this._pauseStart = new Date().getTime();
  8928. this._paused = true;
  8929. }
  8930. },
  8931. /**
  8932. * Resume animation.
  8933. */
  8934. resume: function () {
  8935. if (this._paused) {
  8936. this._pausedTime += new Date().getTime() - this._pauseStart;
  8937. this._paused = false;
  8938. }
  8939. },
  8940. /**
  8941. * Clear animation.
  8942. */
  8943. clear: function () {
  8944. this._clips = [];
  8945. },
  8946. /**
  8947. * Whether animation finished.
  8948. */
  8949. isFinished: function () {
  8950. return !this._clips.length;
  8951. },
  8952. /**
  8953. * Creat animator for a target, whose props can be animated.
  8954. *
  8955. * @param {Object} target
  8956. * @param {Object} options
  8957. * @param {boolean} [options.loop=false] Whether loop animation.
  8958. * @param {Function} [options.getter=null] Get value from target.
  8959. * @param {Function} [options.setter=null] Set value to target.
  8960. * @return {module:zrender/animation/Animation~Animator}
  8961. */
  8962. // TODO Gap
  8963. animate: function (target, options) {
  8964. options = options || {};
  8965. var animator = new Animator(target, options.loop, options.getter, options.setter);
  8966. this.addAnimator(animator);
  8967. return animator;
  8968. }
  8969. };
  8970. mixin(Animation, Eventful);
  8971. /* global document */
  8972. var TOUCH_CLICK_DELAY = 300;
  8973. var globalEventSupported = env$1.domSupported;
  8974. var localNativeListenerNames = function () {
  8975. var mouseHandlerNames = ['click', 'dblclick', 'mousewheel', 'mouseout', 'mouseup', 'mousedown', 'mousemove', 'contextmenu'];
  8976. var touchHandlerNames = ['touchstart', 'touchend', 'touchmove'];
  8977. var pointerEventNameMap = {
  8978. pointerdown: 1,
  8979. pointerup: 1,
  8980. pointermove: 1,
  8981. pointerout: 1
  8982. };
  8983. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  8984. var nm = name.replace('mouse', 'pointer');
  8985. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  8986. });
  8987. return {
  8988. mouse: mouseHandlerNames,
  8989. touch: touchHandlerNames,
  8990. pointer: pointerHandlerNames
  8991. };
  8992. }();
  8993. var globalNativeListenerNames = {
  8994. mouse: ['mousemove', 'mouseup'],
  8995. pointer: ['pointermove', 'pointerup']
  8996. };
  8997. function eventNameFix(name) {
  8998. return name === 'mousewheel' && env$1.browser.firefox ? 'DOMMouseScroll' : name;
  8999. }
  9000. function isPointerFromTouch(event) {
  9001. var pointerType = event.pointerType;
  9002. return pointerType === 'pen' || pointerType === 'touch';
  9003. } // function useMSGuesture(handlerProxy, event) {
  9004. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  9005. // }
  9006. // function onMSGestureChange(proxy, event) {
  9007. // if (event.translationX || event.translationY) {
  9008. // // mousemove is carried by MSGesture to reduce the sensitivity.
  9009. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  9010. // }
  9011. // if (event.scale !== 1) {
  9012. // event.pinchX = event.offsetX;
  9013. // event.pinchY = event.offsetY;
  9014. // event.pinchScale = event.scale;
  9015. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  9016. // }
  9017. // }
  9018. /**
  9019. * Prevent mouse event from being dispatched after Touch Events action
  9020. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  9021. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  9022. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  9023. * Result: Blocking Mouse Events for 700ms.
  9024. *
  9025. * @param {DOMHandlerScope} scope
  9026. */
  9027. function setTouchTimer(scope) {
  9028. scope.touching = true;
  9029. if (scope.touchTimer != null) {
  9030. clearTimeout(scope.touchTimer);
  9031. scope.touchTimer = null;
  9032. }
  9033. scope.touchTimer = setTimeout(function () {
  9034. scope.touching = false;
  9035. scope.touchTimer = null;
  9036. }, 700);
  9037. } // Mark touch, which is useful in distinguish touch and
  9038. // mouse event in upper applicatoin.
  9039. function markTouch(event) {
  9040. event && (event.zrByTouch = true);
  9041. } // function markTriggeredFromLocal(event) {
  9042. // event && (event.__zrIsFromLocal = true);
  9043. // }
  9044. // function isTriggeredFromLocal(instance, event) {
  9045. // return !!(event && event.__zrIsFromLocal);
  9046. // }
  9047. function normalizeGlobalEvent(instance, event) {
  9048. // offsetX, offsetY still need to be calculated. They are necessary in the event
  9049. // handlers of the upper applications. Set `true` to force calculate them.
  9050. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  9051. }
  9052. /**
  9053. * Detect whether the given el is in `painterRoot`.
  9054. */
  9055. function isLocalEl(instance, el) {
  9056. var elTmp = el;
  9057. var isLocal = false;
  9058. while (elTmp && elTmp.nodeType !== 9 && !(isLocal = elTmp.domBelongToZr || elTmp !== el && elTmp === instance.painterRoot)) {
  9059. elTmp = elTmp.parentNode;
  9060. }
  9061. return isLocal;
  9062. }
  9063. /**
  9064. * Make a fake event but not change the original event,
  9065. * becuase the global event probably be used by other
  9066. * listeners not belonging to zrender.
  9067. * @class
  9068. */
  9069. function FakeGlobalEvent(instance, event) {
  9070. this.type = event.type;
  9071. this.target = this.currentTarget = instance.dom;
  9072. this.pointerType = event.pointerType; // Necessray for the force calculation of zrX, zrY
  9073. this.clientX = event.clientX;
  9074. this.clientY = event.clientY; // Because we do not mount global listeners to touch events,
  9075. // we do not copy `targetTouches` and `changedTouches` here.
  9076. }
  9077. var fakeGlobalEventProto = FakeGlobalEvent.prototype; // we make the default methods on the event do nothing,
  9078. // otherwise it is dangerous. See more details in
  9079. // [Drag outside] in `Handler.js`.
  9080. fakeGlobalEventProto.stopPropagation = fakeGlobalEventProto.stopImmediatePropagation = fakeGlobalEventProto.preventDefault = noop;
  9081. /**
  9082. * Local DOM Handlers
  9083. * @this {HandlerProxy}
  9084. */
  9085. var localDOMHandlers = {
  9086. mousedown: function (event) {
  9087. event = normalizeEvent(this.dom, event);
  9088. this._mayPointerCapture = [event.zrX, event.zrY];
  9089. this.trigger('mousedown', event);
  9090. },
  9091. mousemove: function (event) {
  9092. event = normalizeEvent(this.dom, event);
  9093. var downPoint = this._mayPointerCapture;
  9094. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  9095. togglePointerCapture(this, true);
  9096. }
  9097. this.trigger('mousemove', event);
  9098. },
  9099. mouseup: function (event) {
  9100. event = normalizeEvent(this.dom, event);
  9101. togglePointerCapture(this, false);
  9102. this.trigger('mouseup', event);
  9103. },
  9104. mouseout: function (event) {
  9105. event = normalizeEvent(this.dom, event); // Similarly to the browser did on `document` and touch event,
  9106. // `globalout` will be delayed to final pointer cature release.
  9107. if (this._pointerCapturing) {
  9108. event.zrEventControl = 'no_globalout';
  9109. } // There might be some doms created by upper layer application
  9110. // at the same level of painter.getViewportRoot() (e.g., tooltip
  9111. // dom created by echarts), where 'globalout' event should not
  9112. // be triggered when mouse enters these doms. (But 'mouseout'
  9113. // should be triggered at the original hovered element as usual).
  9114. var element = event.toElement || event.relatedTarget;
  9115. event.zrIsToLocalDOM = isLocalEl(this, element);
  9116. this.trigger('mouseout', event);
  9117. },
  9118. touchstart: function (event) {
  9119. // Default mouse behaviour should not be disabled here.
  9120. // For example, page may needs to be slided.
  9121. event = normalizeEvent(this.dom, event);
  9122. markTouch(event);
  9123. this._lastTouchMoment = new Date();
  9124. this.handler.processGesture(event, 'start'); // For consistent event listener for both touch device and mouse device,
  9125. // we simulate "mouseover-->mousedown" in touch device. So we trigger
  9126. // `mousemove` here (to trigger `mouseover` inside), and then trigger
  9127. // `mousedown`.
  9128. localDOMHandlers.mousemove.call(this, event);
  9129. localDOMHandlers.mousedown.call(this, event);
  9130. },
  9131. touchmove: function (event) {
  9132. event = normalizeEvent(this.dom, event);
  9133. markTouch(event);
  9134. this.handler.processGesture(event, 'change'); // Mouse move should always be triggered no matter whether
  9135. // there is gestrue event, because mouse move and pinch may
  9136. // be used at the same time.
  9137. localDOMHandlers.mousemove.call(this, event);
  9138. },
  9139. touchend: function (event) {
  9140. event = normalizeEvent(this.dom, event);
  9141. markTouch(event);
  9142. this.handler.processGesture(event, 'end');
  9143. localDOMHandlers.mouseup.call(this, event); // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  9144. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  9145. // we can conveniently implement "hover style" in both PC and touch device just
  9146. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  9147. // to remove "hover style" on an element, without any additional code for
  9148. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  9149. // style" will remain for user view)
  9150. // click event should always be triggered no matter whether
  9151. // there is gestrue event. System click can not be prevented.
  9152. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  9153. localDOMHandlers.click.call(this, event);
  9154. }
  9155. },
  9156. pointerdown: function (event) {
  9157. localDOMHandlers.mousedown.call(this, event); // if (useMSGuesture(this, event)) {
  9158. // this._msGesture.addPointer(event.pointerId);
  9159. // }
  9160. },
  9161. pointermove: function (event) {
  9162. // FIXME
  9163. // pointermove is so sensitive that it always triggered when
  9164. // tap(click) on touch screen, which affect some judgement in
  9165. // upper application. So, we dont support mousemove on MS touch
  9166. // device yet.
  9167. if (!isPointerFromTouch(event)) {
  9168. localDOMHandlers.mousemove.call(this, event);
  9169. }
  9170. },
  9171. pointerup: function (event) {
  9172. localDOMHandlers.mouseup.call(this, event);
  9173. },
  9174. pointerout: function (event) {
  9175. // pointerout will be triggered when tap on touch screen
  9176. // (IE11+/Edge on MS Surface) after click event triggered,
  9177. // which is inconsistent with the mousout behavior we defined
  9178. // in touchend. So we unify them.
  9179. // (check localDOMHandlers.touchend for detailed explanation)
  9180. if (!isPointerFromTouch(event)) {
  9181. localDOMHandlers.mouseout.call(this, event);
  9182. }
  9183. }
  9184. };
  9185. /**
  9186. * Othere DOM UI Event handlers for zr dom.
  9187. * @this {HandlerProxy}
  9188. */
  9189. each$1(['click', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  9190. localDOMHandlers[name] = function (event) {
  9191. event = normalizeEvent(this.dom, event);
  9192. this.trigger(name, event);
  9193. };
  9194. });
  9195. /**
  9196. * DOM UI Event handlers for global page.
  9197. *
  9198. * [Caution]:
  9199. * those handlers should both support in capture phase and bubble phase!
  9200. *
  9201. * @this {HandlerProxy}
  9202. */
  9203. var globalDOMHandlers = {
  9204. pointermove: function (event) {
  9205. // FIXME
  9206. // pointermove is so sensitive that it always triggered when
  9207. // tap(click) on touch screen, which affect some judgement in
  9208. // upper application. So, we dont support mousemove on MS touch
  9209. // device yet.
  9210. if (!isPointerFromTouch(event)) {
  9211. globalDOMHandlers.mousemove.call(this, event);
  9212. }
  9213. },
  9214. pointerup: function (event) {
  9215. globalDOMHandlers.mouseup.call(this, event);
  9216. },
  9217. mousemove: function (event) {
  9218. this.trigger('mousemove', event);
  9219. },
  9220. mouseup: function (event) {
  9221. var pointerCaptureReleasing = this._pointerCapturing;
  9222. togglePointerCapture(this, false);
  9223. this.trigger('mouseup', event);
  9224. if (pointerCaptureReleasing) {
  9225. event.zrEventControl = 'only_globalout';
  9226. this.trigger('mouseout', event);
  9227. }
  9228. }
  9229. };
  9230. /**
  9231. * @param {HandlerProxy} instance
  9232. * @param {DOMHandlerScope} scope
  9233. */
  9234. function mountLocalDOMEventListeners(instance, scope) {
  9235. var domHandlers = scope.domHandlers;
  9236. if (env$1.pointerEventsSupported) {
  9237. // Only IE11+/Edge
  9238. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  9239. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  9240. // at the same time.
  9241. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  9242. // screen, which do not occurs in pointer event.
  9243. // So we use pointer event to both detect touch gesture and mouse behavior.
  9244. each$1(localNativeListenerNames.pointer, function (nativeEventName) {
  9245. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9246. // markTriggeredFromLocal(event);
  9247. domHandlers[nativeEventName].call(instance, event);
  9248. });
  9249. }); // FIXME
  9250. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  9251. // which does not prevent defuault behavior occasionally (which may cause view port
  9252. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  9253. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  9254. // touch screen. And we only support click behavior on MS touch screen now.
  9255. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  9256. // We dont support touch on IE on win7.
  9257. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  9258. // if (typeof MSGesture === 'function') {
  9259. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  9260. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  9261. // }
  9262. } else {
  9263. if (env$1.touchEventsSupported) {
  9264. each$1(localNativeListenerNames.touch, function (nativeEventName) {
  9265. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9266. // markTriggeredFromLocal(event);
  9267. domHandlers[nativeEventName].call(instance, event);
  9268. setTouchTimer(scope);
  9269. });
  9270. }); // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  9271. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  9272. } // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  9273. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  9274. // mouse event can not be handle in those devices.
  9275. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  9276. // mouseevent after touch event triggered, see `setTouchTimer`.
  9277. each$1(localNativeListenerNames.mouse, function (nativeEventName) {
  9278. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9279. event = getNativeEvent(event);
  9280. if (!scope.touching) {
  9281. // markTriggeredFromLocal(event);
  9282. domHandlers[nativeEventName].call(instance, event);
  9283. }
  9284. });
  9285. });
  9286. }
  9287. }
  9288. /**
  9289. * @param {HandlerProxy} instance
  9290. * @param {DOMHandlerScope} scope
  9291. */
  9292. function mountGlobalDOMEventListeners(instance, scope) {
  9293. // Only IE11+/Edge. See the comment in `mountLocalDOMEventListeners`.
  9294. if (env$1.pointerEventsSupported) {
  9295. each$1(globalNativeListenerNames.pointer, mount);
  9296. } // Touch event has implemented "drag outside" so we do not mount global listener for touch event.
  9297. // (see https://www.w3.org/TR/touch-events/#the-touchmove-event)
  9298. // We do not consider "both-support-touch-and-mouse device" for this feature (see the comment of
  9299. // `mountLocalDOMEventListeners`) to avoid bugs util some requirements come.
  9300. else if (!env$1.touchEventsSupported) {
  9301. each$1(globalNativeListenerNames.mouse, mount);
  9302. }
  9303. function mount(nativeEventName) {
  9304. function nativeEventListener(event) {
  9305. event = getNativeEvent(event); // See the reason in [Drag outside] in `Handler.js`
  9306. // This checking supports both `useCapture` or not.
  9307. // PENDING: if there is performance issue in some devices,
  9308. // we probably can not use `useCapture` and change a easier
  9309. // to judes whether local (mark).
  9310. if (!isLocalEl(instance, event.target)) {
  9311. event = normalizeGlobalEvent(instance, event);
  9312. scope.domHandlers[nativeEventName].call(instance, event);
  9313. }
  9314. }
  9315. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, {
  9316. capture: true
  9317. } // See [Drag Outside] in `Handler.js`
  9318. );
  9319. }
  9320. }
  9321. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  9322. scope.mounted[nativeEventName] = listener;
  9323. scope.listenerOpts[nativeEventName] = opt;
  9324. addEventListener(scope.domTarget, eventNameFix(nativeEventName), listener, opt);
  9325. }
  9326. function unmountDOMEventListeners(scope) {
  9327. var mounted = scope.mounted;
  9328. for (var nativeEventName in mounted) {
  9329. if (mounted.hasOwnProperty(nativeEventName)) {
  9330. removeEventListener(scope.domTarget, eventNameFix(nativeEventName), mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  9331. }
  9332. }
  9333. scope.mounted = {};
  9334. }
  9335. /**
  9336. * See [Drag Outside] in `Handler.js`.
  9337. * @implement
  9338. * @param {boolean} isPointerCapturing Should never be `null`/`undefined`.
  9339. * `true`: start to capture pointer if it is not capturing.
  9340. * `false`: end the capture if it is capturing.
  9341. */
  9342. function togglePointerCapture(instance, isPointerCapturing) {
  9343. instance._mayPointerCapture = null;
  9344. if (globalEventSupported && instance._pointerCapturing ^ isPointerCapturing) {
  9345. instance._pointerCapturing = isPointerCapturing;
  9346. var globalHandlerScope = instance._globalHandlerScope;
  9347. isPointerCapturing ? mountGlobalDOMEventListeners(instance, globalHandlerScope) : unmountDOMEventListeners(globalHandlerScope);
  9348. }
  9349. }
  9350. /**
  9351. * @inner
  9352. * @class
  9353. */
  9354. function DOMHandlerScope(domTarget, domHandlers) {
  9355. this.domTarget = domTarget;
  9356. this.domHandlers = domHandlers; // Key: eventName, value: mounted handler funcitons.
  9357. // Used for unmount.
  9358. this.mounted = {};
  9359. this.listenerOpts = {};
  9360. this.touchTimer = null;
  9361. this.touching = false;
  9362. }
  9363. /**
  9364. * @public
  9365. * @class
  9366. */
  9367. function HandlerDomProxy(dom, painterRoot) {
  9368. Eventful.call(this);
  9369. this.dom = dom;
  9370. this.painterRoot = painterRoot;
  9371. this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  9372. if (globalEventSupported) {
  9373. this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  9374. }
  9375. /**
  9376. * @type {boolean}
  9377. */
  9378. this._pointerCapturing = false;
  9379. /**
  9380. * @type {Array.<number>} [x, y] or null.
  9381. */
  9382. this._mayPointerCapture = null;
  9383. mountLocalDOMEventListeners(this, this._localHandlerScope);
  9384. }
  9385. var handlerDomProxyProto = HandlerDomProxy.prototype;
  9386. handlerDomProxyProto.dispose = function () {
  9387. unmountDOMEventListeners(this._localHandlerScope);
  9388. if (globalEventSupported) {
  9389. unmountDOMEventListeners(this._globalHandlerScope);
  9390. }
  9391. };
  9392. handlerDomProxyProto.setCursor = function (cursorStyle) {
  9393. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  9394. };
  9395. mixin(HandlerDomProxy, Eventful);
  9396. /*!
  9397. * ZRender, a high performance 2d drawing library.
  9398. *
  9399. * Copyright (c) 2013, Baidu Inc.
  9400. * All rights reserved.
  9401. *
  9402. * LICENSE
  9403. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  9404. */
  9405. var useVML = !env$1.canvasSupported;
  9406. var painterCtors = {
  9407. canvas: Painter
  9408. };
  9409. var instances$1 = {}; // ZRender实例map索引
  9410. /**
  9411. * @type {string}
  9412. */
  9413. var version$1 = '4.3.2';
  9414. /**
  9415. * Initializing a zrender instance
  9416. * @param {HTMLElement} dom
  9417. * @param {Object} [opts]
  9418. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9419. * @param {number} [opts.devicePixelRatio]
  9420. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9421. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9422. * @return {module:zrender/ZRender}
  9423. */
  9424. function init$1(dom, opts) {
  9425. var zr = new ZRender(guid(), dom, opts);
  9426. instances$1[zr.id] = zr;
  9427. return zr;
  9428. }
  9429. /**
  9430. * Dispose zrender instance
  9431. * @param {module:zrender/ZRender} zr
  9432. */
  9433. function dispose$1(zr) {
  9434. if (zr) {
  9435. zr.dispose();
  9436. } else {
  9437. for (var key in instances$1) {
  9438. if (instances$1.hasOwnProperty(key)) {
  9439. instances$1[key].dispose();
  9440. }
  9441. }
  9442. instances$1 = {};
  9443. }
  9444. return this;
  9445. }
  9446. /**
  9447. * Get zrender instance by id
  9448. * @param {string} id zrender instance id
  9449. * @return {module:zrender/ZRender}
  9450. */
  9451. function getInstance(id) {
  9452. return instances$1[id];
  9453. }
  9454. function registerPainter(name, Ctor) {
  9455. painterCtors[name] = Ctor;
  9456. }
  9457. function delInstance(id) {
  9458. delete instances$1[id];
  9459. }
  9460. /**
  9461. * @module zrender/ZRender
  9462. */
  9463. /**
  9464. * @constructor
  9465. * @alias module:zrender/ZRender
  9466. * @param {string} id
  9467. * @param {HTMLElement} dom
  9468. * @param {Object} opts
  9469. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9470. * @param {number} [opts.devicePixelRatio]
  9471. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  9472. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  9473. */
  9474. var ZRender = function (id, dom, opts) {
  9475. opts = opts || {};
  9476. /**
  9477. * @type {HTMLDomElement}
  9478. */
  9479. this.dom = dom;
  9480. /**
  9481. * @type {string}
  9482. */
  9483. this.id = id;
  9484. var self = this;
  9485. var storage = new Storage();
  9486. var rendererType = opts.renderer; // TODO WebGL
  9487. if (useVML) {
  9488. if (!painterCtors.vml) {
  9489. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  9490. }
  9491. rendererType = 'vml';
  9492. } else if (!rendererType || !painterCtors[rendererType]) {
  9493. rendererType = 'canvas';
  9494. }
  9495. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  9496. this.storage = storage;
  9497. this.painter = painter;
  9498. var handerProxy = !env$1.node && !env$1.worker ? new HandlerDomProxy(painter.getViewportRoot(), painter.root) : null;
  9499. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  9500. /**
  9501. * @type {module:zrender/animation/Animation}
  9502. */
  9503. this.animation = new Animation({
  9504. stage: {
  9505. update: bind(this.flush, this)
  9506. }
  9507. });
  9508. this.animation.start();
  9509. /**
  9510. * @type {boolean}
  9511. * @private
  9512. */
  9513. this._needsRefresh; // 修改 storage.delFromStorage, 每次删除元素之前删除动画
  9514. // FIXME 有点ugly
  9515. var oldDelFromStorage = storage.delFromStorage;
  9516. var oldAddToStorage = storage.addToStorage;
  9517. storage.delFromStorage = function (el) {
  9518. oldDelFromStorage.call(storage, el);
  9519. el && el.removeSelfFromZr(self);
  9520. };
  9521. storage.addToStorage = function (el) {
  9522. oldAddToStorage.call(storage, el);
  9523. el.addSelfToZr(self);
  9524. };
  9525. };
  9526. ZRender.prototype = {
  9527. constructor: ZRender,
  9528. /**
  9529. * 获取实例唯一标识
  9530. * @return {string}
  9531. */
  9532. getId: function () {
  9533. return this.id;
  9534. },
  9535. /**
  9536. * 添加元素
  9537. * @param {module:zrender/Element} el
  9538. */
  9539. add: function (el) {
  9540. this.storage.addRoot(el);
  9541. this._needsRefresh = true;
  9542. },
  9543. /**
  9544. * 删除元素
  9545. * @param {module:zrender/Element} el
  9546. */
  9547. remove: function (el) {
  9548. this.storage.delRoot(el);
  9549. this._needsRefresh = true;
  9550. },
  9551. /**
  9552. * Change configuration of layer
  9553. * @param {string} zLevel
  9554. * @param {Object} config
  9555. * @param {string} [config.clearColor=0] Clear color
  9556. * @param {string} [config.motionBlur=false] If enable motion blur
  9557. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  9558. */
  9559. configLayer: function (zLevel, config) {
  9560. if (this.painter.configLayer) {
  9561. this.painter.configLayer(zLevel, config);
  9562. }
  9563. this._needsRefresh = true;
  9564. },
  9565. /**
  9566. * Set background color
  9567. * @param {string} backgroundColor
  9568. */
  9569. setBackgroundColor: function (backgroundColor) {
  9570. if (this.painter.setBackgroundColor) {
  9571. this.painter.setBackgroundColor(backgroundColor);
  9572. }
  9573. this._needsRefresh = true;
  9574. },
  9575. /**
  9576. * Repaint the canvas immediately
  9577. */
  9578. refreshImmediately: function () {
  9579. // var start = new Date();
  9580. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  9581. // Or it will cause zrender refreshes again and again.
  9582. this._needsRefresh = this._needsRefreshHover = false;
  9583. this.painter.refresh(); // Avoid trigger zr.refresh in Element#beforeUpdate hook
  9584. this._needsRefresh = this._needsRefreshHover = false; // var end = new Date();
  9585. // var log = document.getElementById('log');
  9586. // if (log) {
  9587. // log.innerHTML = log.innerHTML + '<br>' + (end - start);
  9588. // }
  9589. },
  9590. /**
  9591. * Mark and repaint the canvas in the next frame of browser
  9592. */
  9593. refresh: function () {
  9594. this._needsRefresh = true;
  9595. },
  9596. /**
  9597. * Perform all refresh
  9598. */
  9599. flush: function () {
  9600. var triggerRendered;
  9601. if (this._needsRefresh) {
  9602. triggerRendered = true;
  9603. this.refreshImmediately();
  9604. }
  9605. if (this._needsRefreshHover) {
  9606. triggerRendered = true;
  9607. this.refreshHoverImmediately();
  9608. }
  9609. triggerRendered && this.trigger('rendered');
  9610. },
  9611. /**
  9612. * Add element to hover layer
  9613. * @param {module:zrender/Element} el
  9614. * @param {Object} style
  9615. */
  9616. addHover: function (el, style) {
  9617. if (this.painter.addHover) {
  9618. var elMirror = this.painter.addHover(el, style);
  9619. this.refreshHover();
  9620. return elMirror;
  9621. }
  9622. },
  9623. /**
  9624. * Add element from hover layer
  9625. * @param {module:zrender/Element} el
  9626. */
  9627. removeHover: function (el) {
  9628. if (this.painter.removeHover) {
  9629. this.painter.removeHover(el);
  9630. this.refreshHover();
  9631. }
  9632. },
  9633. /**
  9634. * Clear all hover elements in hover layer
  9635. * @param {module:zrender/Element} el
  9636. */
  9637. clearHover: function () {
  9638. if (this.painter.clearHover) {
  9639. this.painter.clearHover();
  9640. this.refreshHover();
  9641. }
  9642. },
  9643. /**
  9644. * Refresh hover in next frame
  9645. */
  9646. refreshHover: function () {
  9647. this._needsRefreshHover = true;
  9648. },
  9649. /**
  9650. * Refresh hover immediately
  9651. */
  9652. refreshHoverImmediately: function () {
  9653. this._needsRefreshHover = false;
  9654. this.painter.refreshHover && this.painter.refreshHover();
  9655. },
  9656. /**
  9657. * Resize the canvas.
  9658. * Should be invoked when container size is changed
  9659. * @param {Object} [opts]
  9660. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9661. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9662. */
  9663. resize: function (opts) {
  9664. opts = opts || {};
  9665. this.painter.resize(opts.width, opts.height);
  9666. this.handler.resize();
  9667. },
  9668. /**
  9669. * Stop and clear all animation immediately
  9670. */
  9671. clearAnimation: function () {
  9672. this.animation.clear();
  9673. },
  9674. /**
  9675. * Get container width
  9676. */
  9677. getWidth: function () {
  9678. return this.painter.getWidth();
  9679. },
  9680. /**
  9681. * Get container height
  9682. */
  9683. getHeight: function () {
  9684. return this.painter.getHeight();
  9685. },
  9686. /**
  9687. * Export the canvas as Base64 URL
  9688. * @param {string} type
  9689. * @param {string} [backgroundColor='#fff']
  9690. * @return {string} Base64 URL
  9691. */
  9692. // toDataURL: function(type, backgroundColor) {
  9693. // return this.painter.getRenderedCanvas({
  9694. // backgroundColor: backgroundColor
  9695. // }).toDataURL(type);
  9696. // },
  9697. /**
  9698. * Converting a path to image.
  9699. * It has much better performance of drawing image rather than drawing a vector path.
  9700. * @param {module:zrender/graphic/Path} e
  9701. * @param {number} width
  9702. * @param {number} height
  9703. */
  9704. pathToImage: function (e, dpr) {
  9705. return this.painter.pathToImage(e, dpr);
  9706. },
  9707. /**
  9708. * Set default cursor
  9709. * @param {string} [cursorStyle='default'] 例如 crosshair
  9710. */
  9711. setCursorStyle: function (cursorStyle) {
  9712. this.handler.setCursorStyle(cursorStyle);
  9713. },
  9714. /**
  9715. * Find hovered element
  9716. * @param {number} x
  9717. * @param {number} y
  9718. * @return {Object} {target, topTarget}
  9719. */
  9720. findHover: function (x, y) {
  9721. return this.handler.findHover(x, y);
  9722. },
  9723. /**
  9724. * Bind event
  9725. *
  9726. * @param {string} eventName Event name
  9727. * @param {Function} eventHandler Handler function
  9728. * @param {Object} [context] Context object
  9729. */
  9730. on: function (eventName, eventHandler, context) {
  9731. this.handler.on(eventName, eventHandler, context);
  9732. },
  9733. /**
  9734. * Unbind event
  9735. * @param {string} eventName Event name
  9736. * @param {Function} [eventHandler] Handler function
  9737. */
  9738. off: function (eventName, eventHandler) {
  9739. this.handler.off(eventName, eventHandler);
  9740. },
  9741. /**
  9742. * Trigger event manually
  9743. *
  9744. * @param {string} eventName Event name
  9745. * @param {event=} event Event object
  9746. */
  9747. trigger: function (eventName, event) {
  9748. this.handler.trigger(eventName, event);
  9749. },
  9750. /**
  9751. * Clear all objects and the canvas.
  9752. */
  9753. clear: function () {
  9754. this.storage.delRoot();
  9755. this.painter.clear();
  9756. },
  9757. /**
  9758. * Dispose self.
  9759. */
  9760. dispose: function () {
  9761. this.animation.stop();
  9762. this.clear();
  9763. this.storage.dispose();
  9764. this.painter.dispose();
  9765. this.handler.dispose();
  9766. this.animation = this.storage = this.painter = this.handler = null;
  9767. delInstance(this.id);
  9768. }
  9769. };
  9770. var zrender = (Object.freeze || Object)({
  9771. version: version$1,
  9772. init: init$1,
  9773. dispose: dispose$1,
  9774. getInstance: getInstance,
  9775. registerPainter: registerPainter
  9776. });
  9777. /*
  9778. * Licensed to the Apache Software Foundation (ASF) under one
  9779. * or more contributor license agreements. See the NOTICE file
  9780. * distributed with this work for additional information
  9781. * regarding copyright ownership. The ASF licenses this file
  9782. * to you under the Apache License, Version 2.0 (the
  9783. * "License"); you may not use this file except in compliance
  9784. * with the License. You may obtain a copy of the License at
  9785. *
  9786. * http://www.apache.org/licenses/LICENSE-2.0
  9787. *
  9788. * Unless required by applicable law or agreed to in writing,
  9789. * software distributed under the License is distributed on an
  9790. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  9791. * KIND, either express or implied. See the License for the
  9792. * specific language governing permissions and limitations
  9793. * under the License.
  9794. */
  9795. var each$2 = each$1;
  9796. var isObject$2 = isObject$1;
  9797. var isArray$1 = isArray;
  9798. /**
  9799. * Make the name displayable. But we should
  9800. * make sure it is not duplicated with user
  9801. * specified name, so use '\0';
  9802. */
  9803. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  9804. /**
  9805. * If value is not array, then translate it to array.
  9806. * @param {*} value
  9807. * @return {Array} [value] or value
  9808. */
  9809. function normalizeToArray(value) {
  9810. return value instanceof Array ? value : value == null ? [] : [value];
  9811. }
  9812. /**
  9813. * Sync default option between normal and emphasis like `position` and `show`
  9814. * In case some one will write code like
  9815. * label: {
  9816. * show: false,
  9817. * position: 'outside',
  9818. * fontSize: 18
  9819. * },
  9820. * emphasis: {
  9821. * label: { show: true }
  9822. * }
  9823. * @param {Object} opt
  9824. * @param {string} key
  9825. * @param {Array.<string>} subOpts
  9826. */
  9827. function defaultEmphasis(opt, key, subOpts) {
  9828. // Caution: performance sensitive.
  9829. if (opt) {
  9830. opt[key] = opt[key] || {};
  9831. opt.emphasis = opt.emphasis || {};
  9832. opt.emphasis[key] = opt.emphasis[key] || {}; // Default emphasis option from normal
  9833. for (var i = 0, len = subOpts.length; i < len; i++) {
  9834. var subOptName = subOpts[i];
  9835. if (!opt.emphasis[key].hasOwnProperty(subOptName) && opt[key].hasOwnProperty(subOptName)) {
  9836. opt.emphasis[key][subOptName] = opt[key][subOptName];
  9837. }
  9838. }
  9839. }
  9840. }
  9841. var TEXT_STYLE_OPTIONS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth', 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY', 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding']; // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  9842. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  9843. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  9844. // // FIXME: deprecated, check and remove it.
  9845. // 'textStyle'
  9846. // ]);
  9847. /**
  9848. * The method do not ensure performance.
  9849. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  9850. * This helper method retieves value from data.
  9851. * @param {string|number|Date|Array|Object} dataItem
  9852. * @return {number|string|Date|Array.<number|string|Date>}
  9853. */
  9854. function getDataItemValue(dataItem) {
  9855. return isObject$2(dataItem) && !isArray$1(dataItem) && !(dataItem instanceof Date) ? dataItem.value : dataItem;
  9856. }
  9857. /**
  9858. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  9859. * This helper method determine if dataItem has extra option besides value
  9860. * @param {string|number|Date|Array|Object} dataItem
  9861. */
  9862. function isDataItemOption(dataItem) {
  9863. return isObject$2(dataItem) && !(dataItem instanceof Array); // // markLine data can be array
  9864. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  9865. }
  9866. /**
  9867. * Mapping to exists for merge.
  9868. *
  9869. * @public
  9870. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  9871. * @param {Object|Array.<Object>} newCptOptions
  9872. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  9873. * index of which is the same as exists.
  9874. */
  9875. function mappingToExists(exists, newCptOptions) {
  9876. // Mapping by the order by original option (but not order of
  9877. // new option) in merge mode. Because we should ensure
  9878. // some specified index (like xAxisIndex) is consistent with
  9879. // original option, which is easy to understand, espatially in
  9880. // media query. And in most case, merge option is used to
  9881. // update partial option but not be expected to change order.
  9882. newCptOptions = (newCptOptions || []).slice();
  9883. var result = map(exists || [], function (obj, index) {
  9884. return {
  9885. exist: obj
  9886. };
  9887. }); // Mapping by id or name if specified.
  9888. each$2(newCptOptions, function (cptOption, index) {
  9889. if (!isObject$2(cptOption)) {
  9890. return;
  9891. } // id has highest priority.
  9892. for (var i = 0; i < result.length; i++) {
  9893. if (!result[i].option // Consider name: two map to one.
  9894. && cptOption.id != null && result[i].exist.id === cptOption.id + '') {
  9895. result[i].option = cptOption;
  9896. newCptOptions[index] = null;
  9897. return;
  9898. }
  9899. }
  9900. for (var i = 0; i < result.length; i++) {
  9901. var exist = result[i].exist;
  9902. if (!result[i].option // Consider name: two map to one.
  9903. // Can not match when both ids exist but different.
  9904. && (exist.id == null || cptOption.id == null) && cptOption.name != null && !isIdInner(cptOption) && !isIdInner(exist) && exist.name === cptOption.name + '') {
  9905. result[i].option = cptOption;
  9906. newCptOptions[index] = null;
  9907. return;
  9908. }
  9909. }
  9910. }); // Otherwise mapping by index.
  9911. each$2(newCptOptions, function (cptOption, index) {
  9912. if (!isObject$2(cptOption)) {
  9913. return;
  9914. }
  9915. var i = 0;
  9916. for (; i < result.length; i++) {
  9917. var exist = result[i].exist;
  9918. if (!result[i].option // Existing model that already has id should be able to
  9919. // mapped to (because after mapping performed model may
  9920. // be assigned with a id, whish should not affect next
  9921. // mapping), except those has inner id.
  9922. && !isIdInner(exist) // Caution:
  9923. // Do not overwrite id. But name can be overwritten,
  9924. // because axis use name as 'show label text'.
  9925. // 'exist' always has id and name and we dont
  9926. // need to check it.
  9927. && cptOption.id == null) {
  9928. result[i].option = cptOption;
  9929. break;
  9930. }
  9931. }
  9932. if (i >= result.length) {
  9933. result.push({
  9934. option: cptOption
  9935. });
  9936. }
  9937. });
  9938. return result;
  9939. }
  9940. /**
  9941. * Make id and name for mapping result (result of mappingToExists)
  9942. * into `keyInfo` field.
  9943. *
  9944. * @public
  9945. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  9946. * which order is the same as exists.
  9947. * @return {Array.<Object>} The input.
  9948. */
  9949. function makeIdAndName(mapResult) {
  9950. // We use this id to hash component models and view instances
  9951. // in echarts. id can be specified by user, or auto generated.
  9952. // The id generation rule ensures new view instance are able
  9953. // to mapped to old instance when setOption are called in
  9954. // no-merge mode. So we generate model id by name and plus
  9955. // type in view id.
  9956. // name can be duplicated among components, which is convenient
  9957. // to specify multi components (like series) by one name.
  9958. // Ensure that each id is distinct.
  9959. var idMap = createHashMap();
  9960. each$2(mapResult, function (item, index) {
  9961. var existCpt = item.exist;
  9962. existCpt && idMap.set(existCpt.id, item);
  9963. });
  9964. each$2(mapResult, function (item, index) {
  9965. var opt = item.option;
  9966. assert$1(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
  9967. opt && opt.id != null && idMap.set(opt.id, item);
  9968. !item.keyInfo && (item.keyInfo = {});
  9969. }); // Make name and id.
  9970. each$2(mapResult, function (item, index) {
  9971. var existCpt = item.exist;
  9972. var opt = item.option;
  9973. var keyInfo = item.keyInfo;
  9974. if (!isObject$2(opt)) {
  9975. return;
  9976. } // name can be overwitten. Consider case: axis.name = '20km'.
  9977. // But id generated by name will not be changed, which affect
  9978. // only in that case: setOption with 'not merge mode' and view
  9979. // instance will be recreated, which can be accepted.
  9980. keyInfo.name = opt.name != null ? opt.name + '' : existCpt ? existCpt.name // Avoid diffferent series has the same name,
  9981. // because name may be used like in color pallet.
  9982. : DUMMY_COMPONENT_NAME_PREFIX + index;
  9983. if (existCpt) {
  9984. keyInfo.id = existCpt.id;
  9985. } else if (opt.id != null) {
  9986. keyInfo.id = opt.id + '';
  9987. } else {
  9988. // Consider this situatoin:
  9989. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  9990. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  9991. // Series with the same name between optionA and optionB
  9992. // should be mapped.
  9993. var idNum = 0;
  9994. do {
  9995. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  9996. } while (idMap.get(keyInfo.id));
  9997. }
  9998. idMap.set(keyInfo.id, item);
  9999. });
  10000. }
  10001. function isNameSpecified(componentModel) {
  10002. var name = componentModel.name; // Is specified when `indexOf` get -1 or > 0.
  10003. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  10004. }
  10005. /**
  10006. * @public
  10007. * @param {Object} cptOption
  10008. * @return {boolean}
  10009. */
  10010. function isIdInner(cptOption) {
  10011. return isObject$2(cptOption) && cptOption.id && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  10012. }
  10013. /**
  10014. * A helper for removing duplicate items between batchA and batchB,
  10015. * and in themselves, and categorize by series.
  10016. *
  10017. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10018. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10019. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  10020. */
  10021. /**
  10022. * @param {module:echarts/data/List} data
  10023. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  10024. * each of which can be Array or primary type.
  10025. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  10026. */
  10027. function queryDataIndex(data, payload) {
  10028. if (payload.dataIndexInside != null) {
  10029. return payload.dataIndexInside;
  10030. } else if (payload.dataIndex != null) {
  10031. return isArray(payload.dataIndex) ? map(payload.dataIndex, function (value) {
  10032. return data.indexOfRawIndex(value);
  10033. }) : data.indexOfRawIndex(payload.dataIndex);
  10034. } else if (payload.name != null) {
  10035. return isArray(payload.name) ? map(payload.name, function (value) {
  10036. return data.indexOfName(value);
  10037. }) : data.indexOfName(payload.name);
  10038. }
  10039. }
  10040. /**
  10041. * Enable property storage to any host object.
  10042. * Notice: Serialization is not supported.
  10043. *
  10044. * For example:
  10045. * var inner = zrUitl.makeInner();
  10046. *
  10047. * function some1(hostObj) {
  10048. * inner(hostObj).someProperty = 1212;
  10049. * ...
  10050. * }
  10051. * function some2() {
  10052. * var fields = inner(this);
  10053. * fields.someProperty1 = 1212;
  10054. * fields.someProperty2 = 'xx';
  10055. * ...
  10056. * }
  10057. *
  10058. * @return {Function}
  10059. */
  10060. function makeInner() {
  10061. // Consider different scope by es module import.
  10062. var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
  10063. return function (hostObj) {
  10064. return hostObj[key] || (hostObj[key] = {});
  10065. };
  10066. }
  10067. var innerUniqueIndex = 0;
  10068. /**
  10069. * @param {module:echarts/model/Global} ecModel
  10070. * @param {string|Object} finder
  10071. * If string, e.g., 'geo', means {geoIndex: 0}.
  10072. * If Object, could contain some of these properties below:
  10073. * {
  10074. * seriesIndex, seriesId, seriesName,
  10075. * geoIndex, geoId, geoName,
  10076. * bmapIndex, bmapId, bmapName,
  10077. * xAxisIndex, xAxisId, xAxisName,
  10078. * yAxisIndex, yAxisId, yAxisName,
  10079. * gridIndex, gridId, gridName,
  10080. * ... (can be extended)
  10081. * }
  10082. * Each properties can be number|string|Array.<number>|Array.<string>
  10083. * For example, a finder could be
  10084. * {
  10085. * seriesIndex: 3,
  10086. * geoId: ['aa', 'cc'],
  10087. * gridName: ['xx', 'rr']
  10088. * }
  10089. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  10090. * If nothing or null/undefined specified, return nothing.
  10091. * @param {Object} [opt]
  10092. * @param {string} [opt.defaultMainType]
  10093. * @param {Array.<string>} [opt.includeMainTypes]
  10094. * @return {Object} result like:
  10095. * {
  10096. * seriesModels: [seriesModel1, seriesModel2],
  10097. * seriesModel: seriesModel1, // The first model
  10098. * geoModels: [geoModel1, geoModel2],
  10099. * geoModel: geoModel1, // The first model
  10100. * ...
  10101. * }
  10102. */
  10103. function parseFinder(ecModel, finder, opt) {
  10104. if (isString(finder)) {
  10105. var obj = {};
  10106. obj[finder + 'Index'] = 0;
  10107. finder = obj;
  10108. }
  10109. var defaultMainType = opt && opt.defaultMainType;
  10110. if (defaultMainType && !has(finder, defaultMainType + 'Index') && !has(finder, defaultMainType + 'Id') && !has(finder, defaultMainType + 'Name')) {
  10111. finder[defaultMainType + 'Index'] = 0;
  10112. }
  10113. var result = {};
  10114. each$2(finder, function (value, key) {
  10115. var value = finder[key]; // Exclude 'dataIndex' and other illgal keys.
  10116. if (key === 'dataIndex' || key === 'dataIndexInside') {
  10117. result[key] = value;
  10118. return;
  10119. }
  10120. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  10121. var mainType = parsedKey[1];
  10122. var queryType = (parsedKey[2] || '').toLowerCase();
  10123. if (!mainType || !queryType || value == null || queryType === 'index' && value === 'none' || opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0) {
  10124. return;
  10125. }
  10126. var queryParam = {
  10127. mainType: mainType
  10128. };
  10129. if (queryType !== 'index' || value !== 'all') {
  10130. queryParam[queryType] = value;
  10131. }
  10132. var models = ecModel.queryComponents(queryParam);
  10133. result[mainType + 'Models'] = models;
  10134. result[mainType + 'Model'] = models[0];
  10135. });
  10136. return result;
  10137. }
  10138. function has(obj, prop) {
  10139. return obj && obj.hasOwnProperty(prop);
  10140. }
  10141. function setAttribute(dom, key, value) {
  10142. dom.setAttribute ? dom.setAttribute(key, value) : dom[key] = value;
  10143. }
  10144. function getAttribute(dom, key) {
  10145. return dom.getAttribute ? dom.getAttribute(key) : dom[key];
  10146. }
  10147. function getTooltipRenderMode(renderModeOption) {
  10148. if (renderModeOption === 'auto') {
  10149. // Using html when `document` exists, use richText otherwise
  10150. return env$1.domSupported ? 'html' : 'richText';
  10151. } else {
  10152. return renderModeOption || 'html';
  10153. }
  10154. }
  10155. /**
  10156. * Group a list by key.
  10157. *
  10158. * @param {Array} array
  10159. * @param {Function} getKey
  10160. * param {*} Array item
  10161. * return {string} key
  10162. * @return {Object} Result
  10163. * {Array}: keys,
  10164. * {module:zrender/core/util/HashMap} buckets: {key -> Array}
  10165. */
  10166. /*
  10167. * Licensed to the Apache Software Foundation (ASF) under one
  10168. * or more contributor license agreements. See the NOTICE file
  10169. * distributed with this work for additional information
  10170. * regarding copyright ownership. The ASF licenses this file
  10171. * to you under the Apache License, Version 2.0 (the
  10172. * "License"); you may not use this file except in compliance
  10173. * with the License. You may obtain a copy of the License at
  10174. *
  10175. * http://www.apache.org/licenses/LICENSE-2.0
  10176. *
  10177. * Unless required by applicable law or agreed to in writing,
  10178. * software distributed under the License is distributed on an
  10179. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10180. * KIND, either express or implied. See the License for the
  10181. * specific language governing permissions and limitations
  10182. * under the License.
  10183. */
  10184. var TYPE_DELIMITER = '.';
  10185. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  10186. /**
  10187. * Notice, parseClassType('') should returns {main: '', sub: ''}
  10188. * @public
  10189. */
  10190. function parseClassType$1(componentType) {
  10191. var ret = {
  10192. main: '',
  10193. sub: ''
  10194. };
  10195. if (componentType) {
  10196. componentType = componentType.split(TYPE_DELIMITER);
  10197. ret.main = componentType[0] || '';
  10198. ret.sub = componentType[1] || '';
  10199. }
  10200. return ret;
  10201. }
  10202. /**
  10203. * @public
  10204. */
  10205. function checkClassType(componentType) {
  10206. assert$1(/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType), 'componentType "' + componentType + '" illegal');
  10207. }
  10208. /**
  10209. * @public
  10210. */
  10211. function enableClassExtend(RootClass, mandatoryMethods) {
  10212. RootClass.$constructor = RootClass;
  10213. RootClass.extend = function (proto) {
  10214. if (__DEV__) {
  10215. each$1(mandatoryMethods, function (method) {
  10216. if (!proto[method]) {
  10217. console.warn('Method `' + method + '` should be implemented' + (proto.type ? ' in ' + proto.type : '') + '.');
  10218. }
  10219. });
  10220. }
  10221. var superClass = this;
  10222. var ExtendedClass = function () {
  10223. if (!proto.$constructor) {
  10224. superClass.apply(this, arguments);
  10225. } else {
  10226. proto.$constructor.apply(this, arguments);
  10227. }
  10228. };
  10229. extend(ExtendedClass.prototype, proto);
  10230. ExtendedClass.extend = this.extend;
  10231. ExtendedClass.superCall = superCall;
  10232. ExtendedClass.superApply = superApply;
  10233. inherits(ExtendedClass, this);
  10234. ExtendedClass.superClass = superClass;
  10235. return ExtendedClass;
  10236. };
  10237. }
  10238. var classBase = 0;
  10239. /**
  10240. * Can not use instanceof, consider different scope by
  10241. * cross domain or es module import in ec extensions.
  10242. * Mount a method "isInstance()" to Clz.
  10243. */
  10244. function enableClassCheck(Clz) {
  10245. var classAttr = ['__\0is_clz', classBase++, Math.random().toFixed(3)].join('_');
  10246. Clz.prototype[classAttr] = true;
  10247. if (__DEV__) {
  10248. assert$1(!Clz.isInstance, 'The method "is" can not be defined.');
  10249. }
  10250. Clz.isInstance = function (obj) {
  10251. return !!(obj && obj[classAttr]);
  10252. };
  10253. } // superCall should have class info, which can not be fetch from 'this'.
  10254. // Consider this case:
  10255. // class A has method f,
  10256. // class B inherits class A, overrides method f, f call superApply('f'),
  10257. // class C inherits class B, do not overrides method f,
  10258. // then when method of class C is called, dead loop occured.
  10259. function superCall(context, methodName) {
  10260. var args = slice(arguments, 2);
  10261. return this.superClass.prototype[methodName].apply(context, args);
  10262. }
  10263. function superApply(context, methodName, args) {
  10264. return this.superClass.prototype[methodName].apply(context, args);
  10265. }
  10266. /**
  10267. * @param {Object} entity
  10268. * @param {Object} options
  10269. * @param {boolean} [options.registerWhenExtend]
  10270. * @public
  10271. */
  10272. function enableClassManagement(entity, options) {
  10273. options = options || {};
  10274. /**
  10275. * Component model classes
  10276. * key: componentType,
  10277. * value:
  10278. * componentClass, when componentType is 'xxx'
  10279. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  10280. * @type {Object}
  10281. */
  10282. var storage = {};
  10283. entity.registerClass = function (Clazz, componentType) {
  10284. if (componentType) {
  10285. checkClassType(componentType);
  10286. componentType = parseClassType$1(componentType);
  10287. if (!componentType.sub) {
  10288. if (__DEV__) {
  10289. if (storage[componentType.main]) {
  10290. console.warn(componentType.main + ' exists.');
  10291. }
  10292. }
  10293. storage[componentType.main] = Clazz;
  10294. } else if (componentType.sub !== IS_CONTAINER) {
  10295. var container = makeContainer(componentType);
  10296. container[componentType.sub] = Clazz;
  10297. }
  10298. }
  10299. return Clazz;
  10300. };
  10301. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  10302. var Clazz = storage[componentMainType];
  10303. if (Clazz && Clazz[IS_CONTAINER]) {
  10304. Clazz = subType ? Clazz[subType] : null;
  10305. }
  10306. if (throwWhenNotFound && !Clazz) {
  10307. throw new Error(!subType ? componentMainType + '.' + 'type should be specified.' : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.');
  10308. }
  10309. return Clazz;
  10310. };
  10311. entity.getClassesByMainType = function (componentType) {
  10312. componentType = parseClassType$1(componentType);
  10313. var result = [];
  10314. var obj = storage[componentType.main];
  10315. if (obj && obj[IS_CONTAINER]) {
  10316. each$1(obj, function (o, type) {
  10317. type !== IS_CONTAINER && result.push(o);
  10318. });
  10319. } else {
  10320. result.push(obj);
  10321. }
  10322. return result;
  10323. };
  10324. entity.hasClass = function (componentType) {
  10325. // Just consider componentType.main.
  10326. componentType = parseClassType$1(componentType);
  10327. return !!storage[componentType.main];
  10328. };
  10329. /**
  10330. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  10331. */
  10332. entity.getAllClassMainTypes = function () {
  10333. var types = [];
  10334. each$1(storage, function (obj, type) {
  10335. types.push(type);
  10336. });
  10337. return types;
  10338. };
  10339. /**
  10340. * If a main type is container and has sub types
  10341. * @param {string} mainType
  10342. * @return {boolean}
  10343. */
  10344. entity.hasSubTypes = function (componentType) {
  10345. componentType = parseClassType$1(componentType);
  10346. var obj = storage[componentType.main];
  10347. return obj && obj[IS_CONTAINER];
  10348. };
  10349. entity.parseClassType = parseClassType$1;
  10350. function makeContainer(componentType) {
  10351. var container = storage[componentType.main];
  10352. if (!container || !container[IS_CONTAINER]) {
  10353. container = storage[componentType.main] = {};
  10354. container[IS_CONTAINER] = true;
  10355. }
  10356. return container;
  10357. }
  10358. if (options.registerWhenExtend) {
  10359. var originalExtend = entity.extend;
  10360. if (originalExtend) {
  10361. entity.extend = function (proto) {
  10362. var ExtendedClass = originalExtend.call(this, proto);
  10363. return entity.registerClass(ExtendedClass, proto.type);
  10364. };
  10365. }
  10366. }
  10367. return entity;
  10368. }
  10369. /**
  10370. * @param {string|Array.<string>} properties
  10371. */
  10372. /*
  10373. * Licensed to the Apache Software Foundation (ASF) under one
  10374. * or more contributor license agreements. See the NOTICE file
  10375. * distributed with this work for additional information
  10376. * regarding copyright ownership. The ASF licenses this file
  10377. * to you under the Apache License, Version 2.0 (the
  10378. * "License"); you may not use this file except in compliance
  10379. * with the License. You may obtain a copy of the License at
  10380. *
  10381. * http://www.apache.org/licenses/LICENSE-2.0
  10382. *
  10383. * Unless required by applicable law or agreed to in writing,
  10384. * software distributed under the License is distributed on an
  10385. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10386. * KIND, either express or implied. See the License for the
  10387. * specific language governing permissions and limitations
  10388. * under the License.
  10389. */
  10390. // TODO Parse shadow style
  10391. // TODO Only shallow path support
  10392. var makeStyleMapper = function (properties) {
  10393. // Normalize
  10394. for (var i = 0; i < properties.length; i++) {
  10395. if (!properties[i][1]) {
  10396. properties[i][1] = properties[i][0];
  10397. }
  10398. }
  10399. return function (model, excludes, includes) {
  10400. var style = {};
  10401. for (var i = 0; i < properties.length; i++) {
  10402. var propName = properties[i][1];
  10403. if (excludes && indexOf(excludes, propName) >= 0 || includes && indexOf(includes, propName) < 0) {
  10404. continue;
  10405. }
  10406. var val = model.getShallow(propName);
  10407. if (val != null) {
  10408. style[properties[i][0]] = val;
  10409. }
  10410. }
  10411. return style;
  10412. };
  10413. };
  10414. /*
  10415. * Licensed to the Apache Software Foundation (ASF) under one
  10416. * or more contributor license agreements. See the NOTICE file
  10417. * distributed with this work for additional information
  10418. * regarding copyright ownership. The ASF licenses this file
  10419. * to you under the Apache License, Version 2.0 (the
  10420. * "License"); you may not use this file except in compliance
  10421. * with the License. You may obtain a copy of the License at
  10422. *
  10423. * http://www.apache.org/licenses/LICENSE-2.0
  10424. *
  10425. * Unless required by applicable law or agreed to in writing,
  10426. * software distributed under the License is distributed on an
  10427. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10428. * KIND, either express or implied. See the License for the
  10429. * specific language governing permissions and limitations
  10430. * under the License.
  10431. */
  10432. var getLineStyle = makeStyleMapper([['lineWidth', 'width'], ['stroke', 'color'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor']]);
  10433. var lineStyleMixin = {
  10434. getLineStyle: function (excludes) {
  10435. var style = getLineStyle(this, excludes); // Always set lineDash whether dashed, otherwise we can not
  10436. // erase the previous style when assigning to el.style.
  10437. style.lineDash = this.getLineDash(style.lineWidth);
  10438. return style;
  10439. },
  10440. getLineDash: function (lineWidth) {
  10441. if (lineWidth == null) {
  10442. lineWidth = 1;
  10443. }
  10444. var lineType = this.get('type');
  10445. var dotSize = Math.max(lineWidth, 2);
  10446. var dashSize = lineWidth * 4;
  10447. return lineType === 'solid' || lineType == null ? // Use `false` but not `null` for the solid line here, because `null` might be
  10448. // ignored when assigning to `el.style`. e.g., when setting `lineStyle.type` as
  10449. // `'dashed'` and `emphasis.lineStyle.type` as `'solid'` in graph series, the
  10450. // `lineDash` gotten form the latter one is not able to erase that from the former
  10451. // one if using `null` here according to the emhpsis strategy in `util/graphic.js`.
  10452. false : lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize];
  10453. }
  10454. };
  10455. /*
  10456. * Licensed to the Apache Software Foundation (ASF) under one
  10457. * or more contributor license agreements. See the NOTICE file
  10458. * distributed with this work for additional information
  10459. * regarding copyright ownership. The ASF licenses this file
  10460. * to you under the Apache License, Version 2.0 (the
  10461. * "License"); you may not use this file except in compliance
  10462. * with the License. You may obtain a copy of the License at
  10463. *
  10464. * http://www.apache.org/licenses/LICENSE-2.0
  10465. *
  10466. * Unless required by applicable law or agreed to in writing,
  10467. * software distributed under the License is distributed on an
  10468. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10469. * KIND, either express or implied. See the License for the
  10470. * specific language governing permissions and limitations
  10471. * under the License.
  10472. */
  10473. var getAreaStyle = makeStyleMapper([['fill', 'color'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['opacity'], ['shadowColor']]);
  10474. var areaStyleMixin = {
  10475. getAreaStyle: function (excludes, includes) {
  10476. return getAreaStyle(this, excludes, includes);
  10477. }
  10478. };
  10479. /**
  10480. * 曲线辅助模块
  10481. * @module zrender/core/curve
  10482. * @author pissang(https://www.github.com/pissang)
  10483. */
  10484. var mathPow = Math.pow;
  10485. var mathSqrt$2 = Math.sqrt;
  10486. var EPSILON$1 = 1e-8;
  10487. var EPSILON_NUMERIC = 1e-4;
  10488. var THREE_SQRT = mathSqrt$2(3);
  10489. var ONE_THIRD = 1 / 3; // 临时变量
  10490. var _v0 = create();
  10491. var _v1 = create();
  10492. var _v2 = create();
  10493. function isAroundZero(val) {
  10494. return val > -EPSILON$1 && val < EPSILON$1;
  10495. }
  10496. function isNotAroundZero$1(val) {
  10497. return val > EPSILON$1 || val < -EPSILON$1;
  10498. }
  10499. /**
  10500. * 计算三次贝塞尔值
  10501. * @memberOf module:zrender/core/curve
  10502. * @param {number} p0
  10503. * @param {number} p1
  10504. * @param {number} p2
  10505. * @param {number} p3
  10506. * @param {number} t
  10507. * @return {number}
  10508. */
  10509. function cubicAt(p0, p1, p2, p3, t) {
  10510. var onet = 1 - t;
  10511. return onet * onet * (onet * p0 + 3 * t * p1) + t * t * (t * p3 + 3 * onet * p2);
  10512. }
  10513. /**
  10514. * 计算三次贝塞尔导数值
  10515. * @memberOf module:zrender/core/curve
  10516. * @param {number} p0
  10517. * @param {number} p1
  10518. * @param {number} p2
  10519. * @param {number} p3
  10520. * @param {number} t
  10521. * @return {number}
  10522. */
  10523. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10524. var onet = 1 - t;
  10525. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet + (p3 - p2) * t * t);
  10526. }
  10527. /**
  10528. * 计算三次贝塞尔方程根,使用盛金公式
  10529. * @memberOf module:zrender/core/curve
  10530. * @param {number} p0
  10531. * @param {number} p1
  10532. * @param {number} p2
  10533. * @param {number} p3
  10534. * @param {number} val
  10535. * @param {Array.<number>} roots
  10536. * @return {number} 有效根数目
  10537. */
  10538. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10539. // Evaluate roots of cubic functions
  10540. var a = p3 + 3 * (p1 - p2) - p0;
  10541. var b = 3 * (p2 - p1 * 2 + p0);
  10542. var c = 3 * (p1 - p0);
  10543. var d = p0 - val;
  10544. var A = b * b - 3 * a * c;
  10545. var B = b * c - 9 * a * d;
  10546. var C = c * c - 3 * b * d;
  10547. var n = 0;
  10548. if (isAroundZero(A) && isAroundZero(B)) {
  10549. if (isAroundZero(b)) {
  10550. roots[0] = 0;
  10551. } else {
  10552. var t1 = -c / b; //t1, t2, t3, b is not zero
  10553. if (t1 >= 0 && t1 <= 1) {
  10554. roots[n++] = t1;
  10555. }
  10556. }
  10557. } else {
  10558. var disc = B * B - 4 * A * C;
  10559. if (isAroundZero(disc)) {
  10560. var K = B / A;
  10561. var t1 = -b / a + K; // t1, a is not zero
  10562. var t2 = -K / 2; // t2, t3
  10563. if (t1 >= 0 && t1 <= 1) {
  10564. roots[n++] = t1;
  10565. }
  10566. if (t2 >= 0 && t2 <= 1) {
  10567. roots[n++] = t2;
  10568. }
  10569. } else if (disc > 0) {
  10570. var discSqrt = mathSqrt$2(disc);
  10571. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10572. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  10573. if (Y1 < 0) {
  10574. Y1 = -mathPow(-Y1, ONE_THIRD);
  10575. } else {
  10576. Y1 = mathPow(Y1, ONE_THIRD);
  10577. }
  10578. if (Y2 < 0) {
  10579. Y2 = -mathPow(-Y2, ONE_THIRD);
  10580. } else {
  10581. Y2 = mathPow(Y2, ONE_THIRD);
  10582. }
  10583. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  10584. if (t1 >= 0 && t1 <= 1) {
  10585. roots[n++] = t1;
  10586. }
  10587. } else {
  10588. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt$2(A * A * A));
  10589. var theta = Math.acos(T) / 3;
  10590. var ASqrt = mathSqrt$2(A);
  10591. var tmp = Math.cos(theta);
  10592. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  10593. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  10594. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  10595. if (t1 >= 0 && t1 <= 1) {
  10596. roots[n++] = t1;
  10597. }
  10598. if (t2 >= 0 && t2 <= 1) {
  10599. roots[n++] = t2;
  10600. }
  10601. if (t3 >= 0 && t3 <= 1) {
  10602. roots[n++] = t3;
  10603. }
  10604. }
  10605. }
  10606. return n;
  10607. }
  10608. /**
  10609. * 计算三次贝塞尔方程极限值的位置
  10610. * @memberOf module:zrender/core/curve
  10611. * @param {number} p0
  10612. * @param {number} p1
  10613. * @param {number} p2
  10614. * @param {number} p3
  10615. * @param {Array.<number>} extrema
  10616. * @return {number} 有效数目
  10617. */
  10618. function cubicExtrema(p0, p1, p2, p3, extrema) {
  10619. var b = 6 * p2 - 12 * p1 + 6 * p0;
  10620. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  10621. var c = 3 * p1 - 3 * p0;
  10622. var n = 0;
  10623. if (isAroundZero(a)) {
  10624. if (isNotAroundZero$1(b)) {
  10625. var t1 = -c / b;
  10626. if (t1 >= 0 && t1 <= 1) {
  10627. extrema[n++] = t1;
  10628. }
  10629. }
  10630. } else {
  10631. var disc = b * b - 4 * a * c;
  10632. if (isAroundZero(disc)) {
  10633. extrema[0] = -b / (2 * a);
  10634. } else if (disc > 0) {
  10635. var discSqrt = mathSqrt$2(disc);
  10636. var t1 = (-b + discSqrt) / (2 * a);
  10637. var t2 = (-b - discSqrt) / (2 * a);
  10638. if (t1 >= 0 && t1 <= 1) {
  10639. extrema[n++] = t1;
  10640. }
  10641. if (t2 >= 0 && t2 <= 1) {
  10642. extrema[n++] = t2;
  10643. }
  10644. }
  10645. }
  10646. return n;
  10647. }
  10648. /**
  10649. * 细分三次贝塞尔曲线
  10650. * @memberOf module:zrender/core/curve
  10651. * @param {number} p0
  10652. * @param {number} p1
  10653. * @param {number} p2
  10654. * @param {number} p3
  10655. * @param {number} t
  10656. * @param {Array.<number>} out
  10657. */
  10658. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  10659. var p01 = (p1 - p0) * t + p0;
  10660. var p12 = (p2 - p1) * t + p1;
  10661. var p23 = (p3 - p2) * t + p2;
  10662. var p012 = (p12 - p01) * t + p01;
  10663. var p123 = (p23 - p12) * t + p12;
  10664. var p0123 = (p123 - p012) * t + p012; // Seg0
  10665. out[0] = p0;
  10666. out[1] = p01;
  10667. out[2] = p012;
  10668. out[3] = p0123; // Seg1
  10669. out[4] = p0123;
  10670. out[5] = p123;
  10671. out[6] = p23;
  10672. out[7] = p3;
  10673. }
  10674. /**
  10675. * 投射点到三次贝塞尔曲线上,返回投射距离。
  10676. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10677. * @param {number} x0
  10678. * @param {number} y0
  10679. * @param {number} x1
  10680. * @param {number} y1
  10681. * @param {number} x2
  10682. * @param {number} y2
  10683. * @param {number} x3
  10684. * @param {number} y3
  10685. * @param {number} x
  10686. * @param {number} y
  10687. * @param {Array.<number>} [out] 投射点
  10688. * @return {number}
  10689. */
  10690. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  10691. // http://pomax.github.io/bezierinfo/#projections
  10692. var t;
  10693. var interval = 0.005;
  10694. var d = Infinity;
  10695. var prev;
  10696. var next;
  10697. var d1;
  10698. var d2;
  10699. _v0[0] = x;
  10700. _v0[1] = y; // 先粗略估计一下可能的最小距离的 t 值
  10701. // PENDING
  10702. for (var _t = 0; _t < 1; _t += 0.05) {
  10703. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  10704. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  10705. d1 = distSquare(_v0, _v1);
  10706. if (d1 < d) {
  10707. t = _t;
  10708. d = d1;
  10709. }
  10710. }
  10711. d = Infinity; // At most 32 iteration
  10712. for (var i = 0; i < 32; i++) {
  10713. if (interval < EPSILON_NUMERIC) {
  10714. break;
  10715. }
  10716. prev = t - interval;
  10717. next = t + interval; // t - interval
  10718. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  10719. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  10720. d1 = distSquare(_v1, _v0);
  10721. if (prev >= 0 && d1 < d) {
  10722. t = prev;
  10723. d = d1;
  10724. } else {
  10725. // t + interval
  10726. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  10727. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  10728. d2 = distSquare(_v2, _v0);
  10729. if (next <= 1 && d2 < d) {
  10730. t = next;
  10731. d = d2;
  10732. } else {
  10733. interval *= 0.5;
  10734. }
  10735. }
  10736. } // t
  10737. if (out) {
  10738. out[0] = cubicAt(x0, x1, x2, x3, t);
  10739. out[1] = cubicAt(y0, y1, y2, y3, t);
  10740. } // console.log(interval, i);
  10741. return mathSqrt$2(d);
  10742. }
  10743. /**
  10744. * 计算二次方贝塞尔值
  10745. * @param {number} p0
  10746. * @param {number} p1
  10747. * @param {number} p2
  10748. * @param {number} t
  10749. * @return {number}
  10750. */
  10751. function quadraticAt(p0, p1, p2, t) {
  10752. var onet = 1 - t;
  10753. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  10754. }
  10755. /**
  10756. * 计算二次方贝塞尔导数值
  10757. * @param {number} p0
  10758. * @param {number} p1
  10759. * @param {number} p2
  10760. * @param {number} t
  10761. * @return {number}
  10762. */
  10763. function quadraticDerivativeAt(p0, p1, p2, t) {
  10764. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  10765. }
  10766. /**
  10767. * 计算二次方贝塞尔方程根
  10768. * @param {number} p0
  10769. * @param {number} p1
  10770. * @param {number} p2
  10771. * @param {number} t
  10772. * @param {Array.<number>} roots
  10773. * @return {number} 有效根数目
  10774. */
  10775. function quadraticRootAt(p0, p1, p2, val, roots) {
  10776. var a = p0 - 2 * p1 + p2;
  10777. var b = 2 * (p1 - p0);
  10778. var c = p0 - val;
  10779. var n = 0;
  10780. if (isAroundZero(a)) {
  10781. if (isNotAroundZero$1(b)) {
  10782. var t1 = -c / b;
  10783. if (t1 >= 0 && t1 <= 1) {
  10784. roots[n++] = t1;
  10785. }
  10786. }
  10787. } else {
  10788. var disc = b * b - 4 * a * c;
  10789. if (isAroundZero(disc)) {
  10790. var t1 = -b / (2 * a);
  10791. if (t1 >= 0 && t1 <= 1) {
  10792. roots[n++] = t1;
  10793. }
  10794. } else if (disc > 0) {
  10795. var discSqrt = mathSqrt$2(disc);
  10796. var t1 = (-b + discSqrt) / (2 * a);
  10797. var t2 = (-b - discSqrt) / (2 * a);
  10798. if (t1 >= 0 && t1 <= 1) {
  10799. roots[n++] = t1;
  10800. }
  10801. if (t2 >= 0 && t2 <= 1) {
  10802. roots[n++] = t2;
  10803. }
  10804. }
  10805. }
  10806. return n;
  10807. }
  10808. /**
  10809. * 计算二次贝塞尔方程极限值
  10810. * @memberOf module:zrender/core/curve
  10811. * @param {number} p0
  10812. * @param {number} p1
  10813. * @param {number} p2
  10814. * @return {number}
  10815. */
  10816. function quadraticExtremum(p0, p1, p2) {
  10817. var divider = p0 + p2 - 2 * p1;
  10818. if (divider === 0) {
  10819. // p1 is center of p0 and p2
  10820. return 0.5;
  10821. } else {
  10822. return (p0 - p1) / divider;
  10823. }
  10824. }
  10825. /**
  10826. * 细分二次贝塞尔曲线
  10827. * @memberOf module:zrender/core/curve
  10828. * @param {number} p0
  10829. * @param {number} p1
  10830. * @param {number} p2
  10831. * @param {number} t
  10832. * @param {Array.<number>} out
  10833. */
  10834. function quadraticSubdivide(p0, p1, p2, t, out) {
  10835. var p01 = (p1 - p0) * t + p0;
  10836. var p12 = (p2 - p1) * t + p1;
  10837. var p012 = (p12 - p01) * t + p01; // Seg0
  10838. out[0] = p0;
  10839. out[1] = p01;
  10840. out[2] = p012; // Seg1
  10841. out[3] = p012;
  10842. out[4] = p12;
  10843. out[5] = p2;
  10844. }
  10845. /**
  10846. * 投射点到二次贝塞尔曲线上,返回投射距离。
  10847. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10848. * @param {number} x0
  10849. * @param {number} y0
  10850. * @param {number} x1
  10851. * @param {number} y1
  10852. * @param {number} x2
  10853. * @param {number} y2
  10854. * @param {number} x
  10855. * @param {number} y
  10856. * @param {Array.<number>} out 投射点
  10857. * @return {number}
  10858. */
  10859. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  10860. // http://pomax.github.io/bezierinfo/#projections
  10861. var t;
  10862. var interval = 0.005;
  10863. var d = Infinity;
  10864. _v0[0] = x;
  10865. _v0[1] = y; // 先粗略估计一下可能的最小距离的 t 值
  10866. // PENDING
  10867. for (var _t = 0; _t < 1; _t += 0.05) {
  10868. _v1[0] = quadraticAt(x0, x1, x2, _t);
  10869. _v1[1] = quadraticAt(y0, y1, y2, _t);
  10870. var d1 = distSquare(_v0, _v1);
  10871. if (d1 < d) {
  10872. t = _t;
  10873. d = d1;
  10874. }
  10875. }
  10876. d = Infinity; // At most 32 iteration
  10877. for (var i = 0; i < 32; i++) {
  10878. if (interval < EPSILON_NUMERIC) {
  10879. break;
  10880. }
  10881. var prev = t - interval;
  10882. var next = t + interval; // t - interval
  10883. _v1[0] = quadraticAt(x0, x1, x2, prev);
  10884. _v1[1] = quadraticAt(y0, y1, y2, prev);
  10885. var d1 = distSquare(_v1, _v0);
  10886. if (prev >= 0 && d1 < d) {
  10887. t = prev;
  10888. d = d1;
  10889. } else {
  10890. // t + interval
  10891. _v2[0] = quadraticAt(x0, x1, x2, next);
  10892. _v2[1] = quadraticAt(y0, y1, y2, next);
  10893. var d2 = distSquare(_v2, _v0);
  10894. if (next <= 1 && d2 < d) {
  10895. t = next;
  10896. d = d2;
  10897. } else {
  10898. interval *= 0.5;
  10899. }
  10900. }
  10901. } // t
  10902. if (out) {
  10903. out[0] = quadraticAt(x0, x1, x2, t);
  10904. out[1] = quadraticAt(y0, y1, y2, t);
  10905. } // console.log(interval, i);
  10906. return mathSqrt$2(d);
  10907. }
  10908. /**
  10909. * @author Yi Shen(https://github.com/pissang)
  10910. */
  10911. var mathMin$3 = Math.min;
  10912. var mathMax$3 = Math.max;
  10913. var mathSin$2 = Math.sin;
  10914. var mathCos$2 = Math.cos;
  10915. var PI2 = Math.PI * 2;
  10916. var start = create();
  10917. var end = create();
  10918. var extremity = create();
  10919. /**
  10920. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  10921. * @module zrender/core/bbox
  10922. * @param {Array<Object>} points 顶点数组
  10923. * @param {number} min
  10924. * @param {number} max
  10925. */
  10926. function fromPoints(points, min$$1, max$$1) {
  10927. if (points.length === 0) {
  10928. return;
  10929. }
  10930. var p = points[0];
  10931. var left = p[0];
  10932. var right = p[0];
  10933. var top = p[1];
  10934. var bottom = p[1];
  10935. var i;
  10936. for (i = 1; i < points.length; i++) {
  10937. p = points[i];
  10938. left = mathMin$3(left, p[0]);
  10939. right = mathMax$3(right, p[0]);
  10940. top = mathMin$3(top, p[1]);
  10941. bottom = mathMax$3(bottom, p[1]);
  10942. }
  10943. min$$1[0] = left;
  10944. min$$1[1] = top;
  10945. max$$1[0] = right;
  10946. max$$1[1] = bottom;
  10947. }
  10948. /**
  10949. * @memberOf module:zrender/core/bbox
  10950. * @param {number} x0
  10951. * @param {number} y0
  10952. * @param {number} x1
  10953. * @param {number} y1
  10954. * @param {Array.<number>} min
  10955. * @param {Array.<number>} max
  10956. */
  10957. function fromLine(x0, y0, x1, y1, min$$1, max$$1) {
  10958. min$$1[0] = mathMin$3(x0, x1);
  10959. min$$1[1] = mathMin$3(y0, y1);
  10960. max$$1[0] = mathMax$3(x0, x1);
  10961. max$$1[1] = mathMax$3(y0, y1);
  10962. }
  10963. var xDim = [];
  10964. var yDim = [];
  10965. /**
  10966. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  10967. * @memberOf module:zrender/core/bbox
  10968. * @param {number} x0
  10969. * @param {number} y0
  10970. * @param {number} x1
  10971. * @param {number} y1
  10972. * @param {number} x2
  10973. * @param {number} y2
  10974. * @param {number} x3
  10975. * @param {number} y3
  10976. * @param {Array.<number>} min
  10977. * @param {Array.<number>} max
  10978. */
  10979. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min$$1, max$$1) {
  10980. var cubicExtrema$$1 = cubicExtrema;
  10981. var cubicAt$$1 = cubicAt;
  10982. var i;
  10983. var n = cubicExtrema$$1(x0, x1, x2, x3, xDim);
  10984. min$$1[0] = Infinity;
  10985. min$$1[1] = Infinity;
  10986. max$$1[0] = -Infinity;
  10987. max$$1[1] = -Infinity;
  10988. for (i = 0; i < n; i++) {
  10989. var x = cubicAt$$1(x0, x1, x2, x3, xDim[i]);
  10990. min$$1[0] = mathMin$3(x, min$$1[0]);
  10991. max$$1[0] = mathMax$3(x, max$$1[0]);
  10992. }
  10993. n = cubicExtrema$$1(y0, y1, y2, y3, yDim);
  10994. for (i = 0; i < n; i++) {
  10995. var y = cubicAt$$1(y0, y1, y2, y3, yDim[i]);
  10996. min$$1[1] = mathMin$3(y, min$$1[1]);
  10997. max$$1[1] = mathMax$3(y, max$$1[1]);
  10998. }
  10999. min$$1[0] = mathMin$3(x0, min$$1[0]);
  11000. max$$1[0] = mathMax$3(x0, max$$1[0]);
  11001. min$$1[0] = mathMin$3(x3, min$$1[0]);
  11002. max$$1[0] = mathMax$3(x3, max$$1[0]);
  11003. min$$1[1] = mathMin$3(y0, min$$1[1]);
  11004. max$$1[1] = mathMax$3(y0, max$$1[1]);
  11005. min$$1[1] = mathMin$3(y3, min$$1[1]);
  11006. max$$1[1] = mathMax$3(y3, max$$1[1]);
  11007. }
  11008. /**
  11009. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  11010. * @memberOf module:zrender/core/bbox
  11011. * @param {number} x0
  11012. * @param {number} y0
  11013. * @param {number} x1
  11014. * @param {number} y1
  11015. * @param {number} x2
  11016. * @param {number} y2
  11017. * @param {Array.<number>} min
  11018. * @param {Array.<number>} max
  11019. */
  11020. function fromQuadratic(x0, y0, x1, y1, x2, y2, min$$1, max$$1) {
  11021. var quadraticExtremum$$1 = quadraticExtremum;
  11022. var quadraticAt$$1 = quadraticAt; // Find extremities, where derivative in x dim or y dim is zero
  11023. var tx = mathMax$3(mathMin$3(quadraticExtremum$$1(x0, x1, x2), 1), 0);
  11024. var ty = mathMax$3(mathMin$3(quadraticExtremum$$1(y0, y1, y2), 1), 0);
  11025. var x = quadraticAt$$1(x0, x1, x2, tx);
  11026. var y = quadraticAt$$1(y0, y1, y2, ty);
  11027. min$$1[0] = mathMin$3(x0, x2, x);
  11028. min$$1[1] = mathMin$3(y0, y2, y);
  11029. max$$1[0] = mathMax$3(x0, x2, x);
  11030. max$$1[1] = mathMax$3(y0, y2, y);
  11031. }
  11032. /**
  11033. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  11034. * @method
  11035. * @memberOf module:zrender/core/bbox
  11036. * @param {number} x
  11037. * @param {number} y
  11038. * @param {number} rx
  11039. * @param {number} ry
  11040. * @param {number} startAngle
  11041. * @param {number} endAngle
  11042. * @param {number} anticlockwise
  11043. * @param {Array.<number>} min
  11044. * @param {Array.<number>} max
  11045. */
  11046. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$$1, max$$1) {
  11047. var vec2Min = min;
  11048. var vec2Max = max;
  11049. var diff = Math.abs(startAngle - endAngle);
  11050. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  11051. // Is a circle
  11052. min$$1[0] = x - rx;
  11053. min$$1[1] = y - ry;
  11054. max$$1[0] = x + rx;
  11055. max$$1[1] = y + ry;
  11056. return;
  11057. }
  11058. start[0] = mathCos$2(startAngle) * rx + x;
  11059. start[1] = mathSin$2(startAngle) * ry + y;
  11060. end[0] = mathCos$2(endAngle) * rx + x;
  11061. end[1] = mathSin$2(endAngle) * ry + y;
  11062. vec2Min(min$$1, start, end);
  11063. vec2Max(max$$1, start, end); // Thresh to [0, Math.PI * 2]
  11064. startAngle = startAngle % PI2;
  11065. if (startAngle < 0) {
  11066. startAngle = startAngle + PI2;
  11067. }
  11068. endAngle = endAngle % PI2;
  11069. if (endAngle < 0) {
  11070. endAngle = endAngle + PI2;
  11071. }
  11072. if (startAngle > endAngle && !anticlockwise) {
  11073. endAngle += PI2;
  11074. } else if (startAngle < endAngle && anticlockwise) {
  11075. startAngle += PI2;
  11076. }
  11077. if (anticlockwise) {
  11078. var tmp = endAngle;
  11079. endAngle = startAngle;
  11080. startAngle = tmp;
  11081. } // var number = 0;
  11082. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  11083. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  11084. if (angle > startAngle) {
  11085. extremity[0] = mathCos$2(angle) * rx + x;
  11086. extremity[1] = mathSin$2(angle) * ry + y;
  11087. vec2Min(min$$1, extremity, min$$1);
  11088. vec2Max(max$$1, extremity, max$$1);
  11089. }
  11090. }
  11091. }
  11092. /**
  11093. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  11094. * 可以用于 isInsidePath 判断以及获取boundingRect
  11095. *
  11096. * @module zrender/core/PathProxy
  11097. * @author Yi Shen (http://www.github.com/pissang)
  11098. */
  11099. // TODO getTotalLength, getPointAtLength
  11100. /* global Float32Array */
  11101. var CMD = {
  11102. M: 1,
  11103. L: 2,
  11104. C: 3,
  11105. Q: 4,
  11106. A: 5,
  11107. Z: 6,
  11108. // Rect
  11109. R: 7
  11110. }; // var CMD_MEM_SIZE = {
  11111. // M: 3,
  11112. // L: 3,
  11113. // C: 7,
  11114. // Q: 5,
  11115. // A: 9,
  11116. // R: 5,
  11117. // Z: 1
  11118. // };
  11119. var min$1 = [];
  11120. var max$1 = [];
  11121. var min2 = [];
  11122. var max2 = [];
  11123. var mathMin$2 = Math.min;
  11124. var mathMax$2 = Math.max;
  11125. var mathCos$1 = Math.cos;
  11126. var mathSin$1 = Math.sin;
  11127. var mathSqrt$1 = Math.sqrt;
  11128. var mathAbs = Math.abs;
  11129. var hasTypedArray = typeof Float32Array !== 'undefined';
  11130. /**
  11131. * @alias module:zrender/core/PathProxy
  11132. * @constructor
  11133. */
  11134. var PathProxy = function (notSaveData) {
  11135. this._saveData = !(notSaveData || false);
  11136. if (this._saveData) {
  11137. /**
  11138. * Path data. Stored as flat array
  11139. * @type {Array.<Object>}
  11140. */
  11141. this.data = [];
  11142. }
  11143. this._ctx = null;
  11144. };
  11145. /**
  11146. * 快速计算Path包围盒(并不是最小包围盒)
  11147. * @return {Object}
  11148. */
  11149. PathProxy.prototype = {
  11150. constructor: PathProxy,
  11151. _xi: 0,
  11152. _yi: 0,
  11153. _x0: 0,
  11154. _y0: 0,
  11155. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  11156. _ux: 0,
  11157. _uy: 0,
  11158. _len: 0,
  11159. _lineDash: null,
  11160. _dashOffset: 0,
  11161. _dashIdx: 0,
  11162. _dashSum: 0,
  11163. /**
  11164. * @readOnly
  11165. */
  11166. setScale: function (sx, sy, segmentIgnoreThreshold) {
  11167. // Compat. Previously there is no segmentIgnoreThreshold.
  11168. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  11169. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  11170. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  11171. },
  11172. getContext: function () {
  11173. return this._ctx;
  11174. },
  11175. /**
  11176. * @param {CanvasRenderingContext2D} ctx
  11177. * @return {module:zrender/core/PathProxy}
  11178. */
  11179. beginPath: function (ctx) {
  11180. this._ctx = ctx;
  11181. ctx && ctx.beginPath();
  11182. ctx && (this.dpr = ctx.dpr); // Reset
  11183. if (this._saveData) {
  11184. this._len = 0;
  11185. }
  11186. if (this._lineDash) {
  11187. this._lineDash = null;
  11188. this._dashOffset = 0;
  11189. }
  11190. return this;
  11191. },
  11192. /**
  11193. * @param {number} x
  11194. * @param {number} y
  11195. * @return {module:zrender/core/PathProxy}
  11196. */
  11197. moveTo: function (x, y) {
  11198. this.addData(CMD.M, x, y);
  11199. this._ctx && this._ctx.moveTo(x, y); // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11200. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11201. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11202. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11203. this._x0 = x;
  11204. this._y0 = y;
  11205. this._xi = x;
  11206. this._yi = y;
  11207. return this;
  11208. },
  11209. /**
  11210. * @param {number} x
  11211. * @param {number} y
  11212. * @return {module:zrender/core/PathProxy}
  11213. */
  11214. lineTo: function (x, y) {
  11215. var exceedUnit = mathAbs(x - this._xi) > this._ux || mathAbs(y - this._yi) > this._uy // Force draw the first segment
  11216. || this._len < 5;
  11217. this.addData(CMD.L, x, y);
  11218. if (this._ctx && exceedUnit) {
  11219. this._needsDash() ? this._dashedLineTo(x, y) : this._ctx.lineTo(x, y);
  11220. }
  11221. if (exceedUnit) {
  11222. this._xi = x;
  11223. this._yi = y;
  11224. }
  11225. return this;
  11226. },
  11227. /**
  11228. * @param {number} x1
  11229. * @param {number} y1
  11230. * @param {number} x2
  11231. * @param {number} y2
  11232. * @param {number} x3
  11233. * @param {number} y3
  11234. * @return {module:zrender/core/PathProxy}
  11235. */
  11236. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11237. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11238. if (this._ctx) {
  11239. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3) : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11240. }
  11241. this._xi = x3;
  11242. this._yi = y3;
  11243. return this;
  11244. },
  11245. /**
  11246. * @param {number} x1
  11247. * @param {number} y1
  11248. * @param {number} x2
  11249. * @param {number} y2
  11250. * @return {module:zrender/core/PathProxy}
  11251. */
  11252. quadraticCurveTo: function (x1, y1, x2, y2) {
  11253. this.addData(CMD.Q, x1, y1, x2, y2);
  11254. if (this._ctx) {
  11255. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2) : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11256. }
  11257. this._xi = x2;
  11258. this._yi = y2;
  11259. return this;
  11260. },
  11261. /**
  11262. * @param {number} cx
  11263. * @param {number} cy
  11264. * @param {number} r
  11265. * @param {number} startAngle
  11266. * @param {number} endAngle
  11267. * @param {boolean} anticlockwise
  11268. * @return {module:zrender/core/PathProxy}
  11269. */
  11270. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11271. this.addData(CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1);
  11272. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11273. this._xi = mathCos$1(endAngle) * r + cx;
  11274. this._yi = mathSin$1(endAngle) * r + cy;
  11275. return this;
  11276. },
  11277. // TODO
  11278. arcTo: function (x1, y1, x2, y2, radius) {
  11279. if (this._ctx) {
  11280. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11281. }
  11282. return this;
  11283. },
  11284. // TODO
  11285. rect: function (x, y, w, h) {
  11286. this._ctx && this._ctx.rect(x, y, w, h);
  11287. this.addData(CMD.R, x, y, w, h);
  11288. return this;
  11289. },
  11290. /**
  11291. * @return {module:zrender/core/PathProxy}
  11292. */
  11293. closePath: function () {
  11294. this.addData(CMD.Z);
  11295. var ctx = this._ctx;
  11296. var x0 = this._x0;
  11297. var y0 = this._y0;
  11298. if (ctx) {
  11299. this._needsDash() && this._dashedLineTo(x0, y0);
  11300. ctx.closePath();
  11301. }
  11302. this._xi = x0;
  11303. this._yi = y0;
  11304. return this;
  11305. },
  11306. /**
  11307. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11308. * stroke 同样
  11309. * @param {CanvasRenderingContext2D} ctx
  11310. * @return {module:zrender/core/PathProxy}
  11311. */
  11312. fill: function (ctx) {
  11313. ctx && ctx.fill();
  11314. this.toStatic();
  11315. },
  11316. /**
  11317. * @param {CanvasRenderingContext2D} ctx
  11318. * @return {module:zrender/core/PathProxy}
  11319. */
  11320. stroke: function (ctx) {
  11321. ctx && ctx.stroke();
  11322. this.toStatic();
  11323. },
  11324. /**
  11325. * 必须在其它绘制命令前调用
  11326. * Must be invoked before all other path drawing methods
  11327. * @return {module:zrender/core/PathProxy}
  11328. */
  11329. setLineDash: function (lineDash) {
  11330. if (lineDash instanceof Array) {
  11331. this._lineDash = lineDash;
  11332. this._dashIdx = 0;
  11333. var lineDashSum = 0;
  11334. for (var i = 0; i < lineDash.length; i++) {
  11335. lineDashSum += lineDash[i];
  11336. }
  11337. this._dashSum = lineDashSum;
  11338. }
  11339. return this;
  11340. },
  11341. /**
  11342. * 必须在其它绘制命令前调用
  11343. * Must be invoked before all other path drawing methods
  11344. * @return {module:zrender/core/PathProxy}
  11345. */
  11346. setLineDashOffset: function (offset) {
  11347. this._dashOffset = offset;
  11348. return this;
  11349. },
  11350. /**
  11351. *
  11352. * @return {boolean}
  11353. */
  11354. len: function () {
  11355. return this._len;
  11356. },
  11357. /**
  11358. * 直接设置 Path 数据
  11359. */
  11360. setData: function (data) {
  11361. var len$$1 = data.length;
  11362. if (!(this.data && this.data.length === len$$1) && hasTypedArray) {
  11363. this.data = new Float32Array(len$$1);
  11364. }
  11365. for (var i = 0; i < len$$1; i++) {
  11366. this.data[i] = data[i];
  11367. }
  11368. this._len = len$$1;
  11369. },
  11370. /**
  11371. * 添加子路径
  11372. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11373. */
  11374. appendPath: function (path) {
  11375. if (!(path instanceof Array)) {
  11376. path = [path];
  11377. }
  11378. var len$$1 = path.length;
  11379. var appendSize = 0;
  11380. var offset = this._len;
  11381. for (var i = 0; i < len$$1; i++) {
  11382. appendSize += path[i].len();
  11383. }
  11384. if (hasTypedArray && this.data instanceof Float32Array) {
  11385. this.data = new Float32Array(offset + appendSize);
  11386. }
  11387. for (var i = 0; i < len$$1; i++) {
  11388. var appendPathData = path[i].data;
  11389. for (var k = 0; k < appendPathData.length; k++) {
  11390. this.data[offset++] = appendPathData[k];
  11391. }
  11392. }
  11393. this._len = offset;
  11394. },
  11395. /**
  11396. * 填充 Path 数据。
  11397. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11398. */
  11399. addData: function (cmd) {
  11400. if (!this._saveData) {
  11401. return;
  11402. }
  11403. var data = this.data;
  11404. if (this._len + arguments.length > data.length) {
  11405. // 因为之前的数组已经转换成静态的 Float32Array
  11406. // 所以不够用时需要扩展一个新的动态数组
  11407. this._expandData();
  11408. data = this.data;
  11409. }
  11410. for (var i = 0; i < arguments.length; i++) {
  11411. data[this._len++] = arguments[i];
  11412. }
  11413. this._prevCmd = cmd;
  11414. },
  11415. _expandData: function () {
  11416. // Only if data is Float32Array
  11417. if (!(this.data instanceof Array)) {
  11418. var newData = [];
  11419. for (var i = 0; i < this._len; i++) {
  11420. newData[i] = this.data[i];
  11421. }
  11422. this.data = newData;
  11423. }
  11424. },
  11425. /**
  11426. * If needs js implemented dashed line
  11427. * @return {boolean}
  11428. * @private
  11429. */
  11430. _needsDash: function () {
  11431. return this._lineDash;
  11432. },
  11433. _dashedLineTo: function (x1, y1) {
  11434. var dashSum = this._dashSum;
  11435. var offset = this._dashOffset;
  11436. var lineDash = this._lineDash;
  11437. var ctx = this._ctx;
  11438. var x0 = this._xi;
  11439. var y0 = this._yi;
  11440. var dx = x1 - x0;
  11441. var dy = y1 - y0;
  11442. var dist$$1 = mathSqrt$1(dx * dx + dy * dy);
  11443. var x = x0;
  11444. var y = y0;
  11445. var dash;
  11446. var nDash = lineDash.length;
  11447. var idx;
  11448. dx /= dist$$1;
  11449. dy /= dist$$1;
  11450. if (offset < 0) {
  11451. // Convert to positive offset
  11452. offset = dashSum + offset;
  11453. }
  11454. offset %= dashSum;
  11455. x -= offset * dx;
  11456. y -= offset * dy;
  11457. while (dx > 0 && x <= x1 || dx < 0 && x >= x1 || dx === 0 && (dy > 0 && y <= y1 || dy < 0 && y >= y1)) {
  11458. idx = this._dashIdx;
  11459. dash = lineDash[idx];
  11460. x += dx * dash;
  11461. y += dy * dash;
  11462. this._dashIdx = (idx + 1) % nDash; // Skip positive offset
  11463. if (dx > 0 && x < x0 || dx < 0 && x > x0 || dy > 0 && y < y0 || dy < 0 && y > y0) {
  11464. continue;
  11465. }
  11466. ctx[idx % 2 ? 'moveTo' : 'lineTo'](dx >= 0 ? mathMin$2(x, x1) : mathMax$2(x, x1), dy >= 0 ? mathMin$2(y, y1) : mathMax$2(y, y1));
  11467. } // Offset for next lineTo
  11468. dx = x - x1;
  11469. dy = y - y1;
  11470. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11471. },
  11472. // Not accurate dashed line to
  11473. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11474. var dashSum = this._dashSum;
  11475. var offset = this._dashOffset;
  11476. var lineDash = this._lineDash;
  11477. var ctx = this._ctx;
  11478. var x0 = this._xi;
  11479. var y0 = this._yi;
  11480. var t;
  11481. var dx;
  11482. var dy;
  11483. var cubicAt$$1 = cubicAt;
  11484. var bezierLen = 0;
  11485. var idx = this._dashIdx;
  11486. var nDash = lineDash.length;
  11487. var x;
  11488. var y;
  11489. var tmpLen = 0;
  11490. if (offset < 0) {
  11491. // Convert to positive offset
  11492. offset = dashSum + offset;
  11493. }
  11494. offset %= dashSum; // Bezier approx length
  11495. for (t = 0; t < 1; t += 0.1) {
  11496. dx = cubicAt$$1(x0, x1, x2, x3, t + 0.1) - cubicAt$$1(x0, x1, x2, x3, t);
  11497. dy = cubicAt$$1(y0, y1, y2, y3, t + 0.1) - cubicAt$$1(y0, y1, y2, y3, t);
  11498. bezierLen += mathSqrt$1(dx * dx + dy * dy);
  11499. } // Find idx after add offset
  11500. for (; idx < nDash; idx++) {
  11501. tmpLen += lineDash[idx];
  11502. if (tmpLen > offset) {
  11503. break;
  11504. }
  11505. }
  11506. t = (tmpLen - offset) / bezierLen;
  11507. while (t <= 1) {
  11508. x = cubicAt$$1(x0, x1, x2, x3, t);
  11509. y = cubicAt$$1(y0, y1, y2, y3, t); // Use line to approximate dashed bezier
  11510. // Bad result if dash is long
  11511. idx % 2 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
  11512. t += lineDash[idx] / bezierLen;
  11513. idx = (idx + 1) % nDash;
  11514. } // Finish the last segment and calculate the new offset
  11515. idx % 2 !== 0 && ctx.lineTo(x3, y3);
  11516. dx = x3 - x;
  11517. dy = y3 - y;
  11518. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11519. },
  11520. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  11521. // Convert quadratic to cubic using degree elevation
  11522. var x3 = x2;
  11523. var y3 = y2;
  11524. x2 = (x2 + 2 * x1) / 3;
  11525. y2 = (y2 + 2 * y1) / 3;
  11526. x1 = (this._xi + 2 * x1) / 3;
  11527. y1 = (this._yi + 2 * y1) / 3;
  11528. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  11529. },
  11530. /**
  11531. * 转成静态的 Float32Array 减少堆内存占用
  11532. * Convert dynamic array to static Float32Array
  11533. */
  11534. toStatic: function () {
  11535. var data = this.data;
  11536. if (data instanceof Array) {
  11537. data.length = this._len;
  11538. if (hasTypedArray) {
  11539. this.data = new Float32Array(data);
  11540. }
  11541. }
  11542. },
  11543. /**
  11544. * @return {module:zrender/core/BoundingRect}
  11545. */
  11546. getBoundingRect: function () {
  11547. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  11548. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  11549. var data = this.data;
  11550. var xi = 0;
  11551. var yi = 0;
  11552. var x0 = 0;
  11553. var y0 = 0;
  11554. for (var i = 0; i < data.length;) {
  11555. var cmd = data[i++];
  11556. if (i === 1) {
  11557. // 如果第一个命令是 L, C, Q
  11558. // 则 previous point 同绘制命令的第一个 point
  11559. //
  11560. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11561. xi = data[i];
  11562. yi = data[i + 1];
  11563. x0 = xi;
  11564. y0 = yi;
  11565. }
  11566. switch (cmd) {
  11567. case CMD.M:
  11568. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11569. // 在 closePath 的时候使用
  11570. x0 = data[i++];
  11571. y0 = data[i++];
  11572. xi = x0;
  11573. yi = y0;
  11574. min2[0] = x0;
  11575. min2[1] = y0;
  11576. max2[0] = x0;
  11577. max2[1] = y0;
  11578. break;
  11579. case CMD.L:
  11580. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  11581. xi = data[i++];
  11582. yi = data[i++];
  11583. break;
  11584. case CMD.C:
  11585. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  11586. xi = data[i++];
  11587. yi = data[i++];
  11588. break;
  11589. case CMD.Q:
  11590. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  11591. xi = data[i++];
  11592. yi = data[i++];
  11593. break;
  11594. case CMD.A:
  11595. // TODO Arc 判断的开销比较大
  11596. var cx = data[i++];
  11597. var cy = data[i++];
  11598. var rx = data[i++];
  11599. var ry = data[i++];
  11600. var startAngle = data[i++];
  11601. var endAngle = data[i++] + startAngle; // TODO Arc 旋转
  11602. i += 1;
  11603. var anticlockwise = 1 - data[i++];
  11604. if (i === 1) {
  11605. // 直接使用 arc 命令
  11606. // 第一个命令起点还未定义
  11607. x0 = mathCos$1(startAngle) * rx + cx;
  11608. y0 = mathSin$1(startAngle) * ry + cy;
  11609. }
  11610. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  11611. xi = mathCos$1(endAngle) * rx + cx;
  11612. yi = mathSin$1(endAngle) * ry + cy;
  11613. break;
  11614. case CMD.R:
  11615. x0 = xi = data[i++];
  11616. y0 = yi = data[i++];
  11617. var width = data[i++];
  11618. var height = data[i++]; // Use fromLine
  11619. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  11620. break;
  11621. case CMD.Z:
  11622. xi = x0;
  11623. yi = y0;
  11624. break;
  11625. } // Union
  11626. min(min$1, min$1, min2);
  11627. max(max$1, max$1, max2);
  11628. } // No data
  11629. if (i === 0) {
  11630. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  11631. }
  11632. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  11633. },
  11634. /**
  11635. * Rebuild path from current data
  11636. * Rebuild path will not consider javascript implemented line dash.
  11637. * @param {CanvasRenderingContext2D} ctx
  11638. */
  11639. rebuildPath: function (ctx) {
  11640. var d = this.data;
  11641. var x0;
  11642. var y0;
  11643. var xi;
  11644. var yi;
  11645. var x;
  11646. var y;
  11647. var ux = this._ux;
  11648. var uy = this._uy;
  11649. var len$$1 = this._len;
  11650. for (var i = 0; i < len$$1;) {
  11651. var cmd = d[i++];
  11652. if (i === 1) {
  11653. // 如果第一个命令是 L, C, Q
  11654. // 则 previous point 同绘制命令的第一个 point
  11655. //
  11656. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11657. xi = d[i];
  11658. yi = d[i + 1];
  11659. x0 = xi;
  11660. y0 = yi;
  11661. }
  11662. switch (cmd) {
  11663. case CMD.M:
  11664. x0 = xi = d[i++];
  11665. y0 = yi = d[i++];
  11666. ctx.moveTo(xi, yi);
  11667. break;
  11668. case CMD.L:
  11669. x = d[i++];
  11670. y = d[i++]; // Not draw too small seg between
  11671. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len$$1 - 1) {
  11672. ctx.lineTo(x, y);
  11673. xi = x;
  11674. yi = y;
  11675. }
  11676. break;
  11677. case CMD.C:
  11678. ctx.bezierCurveTo(d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]);
  11679. xi = d[i - 2];
  11680. yi = d[i - 1];
  11681. break;
  11682. case CMD.Q:
  11683. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  11684. xi = d[i - 2];
  11685. yi = d[i - 1];
  11686. break;
  11687. case CMD.A:
  11688. var cx = d[i++];
  11689. var cy = d[i++];
  11690. var rx = d[i++];
  11691. var ry = d[i++];
  11692. var theta = d[i++];
  11693. var dTheta = d[i++];
  11694. var psi = d[i++];
  11695. var fs = d[i++];
  11696. var r = rx > ry ? rx : ry;
  11697. var scaleX = rx > ry ? 1 : rx / ry;
  11698. var scaleY = rx > ry ? ry / rx : 1;
  11699. var isEllipse = Math.abs(rx - ry) > 1e-3;
  11700. var endAngle = theta + dTheta;
  11701. if (isEllipse) {
  11702. ctx.translate(cx, cy);
  11703. ctx.rotate(psi);
  11704. ctx.scale(scaleX, scaleY);
  11705. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  11706. ctx.scale(1 / scaleX, 1 / scaleY);
  11707. ctx.rotate(-psi);
  11708. ctx.translate(-cx, -cy);
  11709. } else {
  11710. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  11711. }
  11712. if (i === 1) {
  11713. // 直接使用 arc 命令
  11714. // 第一个命令起点还未定义
  11715. x0 = mathCos$1(theta) * rx + cx;
  11716. y0 = mathSin$1(theta) * ry + cy;
  11717. }
  11718. xi = mathCos$1(endAngle) * rx + cx;
  11719. yi = mathSin$1(endAngle) * ry + cy;
  11720. break;
  11721. case CMD.R:
  11722. x0 = xi = d[i];
  11723. y0 = yi = d[i + 1];
  11724. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  11725. break;
  11726. case CMD.Z:
  11727. ctx.closePath();
  11728. xi = x0;
  11729. yi = y0;
  11730. }
  11731. }
  11732. }
  11733. };
  11734. PathProxy.CMD = CMD;
  11735. /**
  11736. * 线段包含判断
  11737. * @param {number} x0
  11738. * @param {number} y0
  11739. * @param {number} x1
  11740. * @param {number} y1
  11741. * @param {number} lineWidth
  11742. * @param {number} x
  11743. * @param {number} y
  11744. * @return {boolean}
  11745. */
  11746. function containStroke$1(x0, y0, x1, y1, lineWidth, x, y) {
  11747. if (lineWidth === 0) {
  11748. return false;
  11749. }
  11750. var _l = lineWidth;
  11751. var _a = 0;
  11752. var _b = x0; // Quick reject
  11753. if (y > y0 + _l && y > y1 + _l || y < y0 - _l && y < y1 - _l || x > x0 + _l && x > x1 + _l || x < x0 - _l && x < x1 - _l) {
  11754. return false;
  11755. }
  11756. if (x0 !== x1) {
  11757. _a = (y0 - y1) / (x0 - x1);
  11758. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  11759. } else {
  11760. return Math.abs(x - x0) <= _l / 2;
  11761. }
  11762. var tmp = _a * x - y + _b;
  11763. var _s = tmp * tmp / (_a * _a + 1);
  11764. return _s <= _l / 2 * _l / 2;
  11765. }
  11766. /**
  11767. * 三次贝塞尔曲线描边包含判断
  11768. * @param {number} x0
  11769. * @param {number} y0
  11770. * @param {number} x1
  11771. * @param {number} y1
  11772. * @param {number} x2
  11773. * @param {number} y2
  11774. * @param {number} x3
  11775. * @param {number} y3
  11776. * @param {number} lineWidth
  11777. * @param {number} x
  11778. * @param {number} y
  11779. * @return {boolean}
  11780. */
  11781. function containStroke$2(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  11782. if (lineWidth === 0) {
  11783. return false;
  11784. }
  11785. var _l = lineWidth; // Quick reject
  11786. if (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l || y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l || x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l || x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l) {
  11787. return false;
  11788. }
  11789. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  11790. return d <= _l / 2;
  11791. }
  11792. /**
  11793. * 二次贝塞尔曲线描边包含判断
  11794. * @param {number} x0
  11795. * @param {number} y0
  11796. * @param {number} x1
  11797. * @param {number} y1
  11798. * @param {number} x2
  11799. * @param {number} y2
  11800. * @param {number} lineWidth
  11801. * @param {number} x
  11802. * @param {number} y
  11803. * @return {boolean}
  11804. */
  11805. function containStroke$3(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  11806. if (lineWidth === 0) {
  11807. return false;
  11808. }
  11809. var _l = lineWidth; // Quick reject
  11810. if (y > y0 + _l && y > y1 + _l && y > y2 + _l || y < y0 - _l && y < y1 - _l && y < y2 - _l || x > x0 + _l && x > x1 + _l && x > x2 + _l || x < x0 - _l && x < x1 - _l && x < x2 - _l) {
  11811. return false;
  11812. }
  11813. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  11814. return d <= _l / 2;
  11815. }
  11816. var PI2$3 = Math.PI * 2;
  11817. function normalizeRadian(angle) {
  11818. angle %= PI2$3;
  11819. if (angle < 0) {
  11820. angle += PI2$3;
  11821. }
  11822. return angle;
  11823. }
  11824. var PI2$2 = Math.PI * 2;
  11825. /**
  11826. * 圆弧描边包含判断
  11827. * @param {number} cx
  11828. * @param {number} cy
  11829. * @param {number} r
  11830. * @param {number} startAngle
  11831. * @param {number} endAngle
  11832. * @param {boolean} anticlockwise
  11833. * @param {number} lineWidth
  11834. * @param {number} x
  11835. * @param {number} y
  11836. * @return {Boolean}
  11837. */
  11838. function containStroke$4(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  11839. if (lineWidth === 0) {
  11840. return false;
  11841. }
  11842. var _l = lineWidth;
  11843. x -= cx;
  11844. y -= cy;
  11845. var d = Math.sqrt(x * x + y * y);
  11846. if (d - _l > r || d + _l < r) {
  11847. return false;
  11848. }
  11849. if (Math.abs(startAngle - endAngle) % PI2$2 < 1e-4) {
  11850. // Is a circle
  11851. return true;
  11852. }
  11853. if (anticlockwise) {
  11854. var tmp = startAngle;
  11855. startAngle = normalizeRadian(endAngle);
  11856. endAngle = normalizeRadian(tmp);
  11857. } else {
  11858. startAngle = normalizeRadian(startAngle);
  11859. endAngle = normalizeRadian(endAngle);
  11860. }
  11861. if (startAngle > endAngle) {
  11862. endAngle += PI2$2;
  11863. }
  11864. var angle = Math.atan2(y, x);
  11865. if (angle < 0) {
  11866. angle += PI2$2;
  11867. }
  11868. return angle >= startAngle && angle <= endAngle || angle + PI2$2 >= startAngle && angle + PI2$2 <= endAngle;
  11869. }
  11870. function windingLine(x0, y0, x1, y1, x, y) {
  11871. if (y > y0 && y > y1 || y < y0 && y < y1) {
  11872. return 0;
  11873. } // Ignore horizontal line
  11874. if (y1 === y0) {
  11875. return 0;
  11876. }
  11877. var dir = y1 < y0 ? 1 : -1;
  11878. var t = (y - y0) / (y1 - y0); // Avoid winding error when intersection point is the connect point of two line of polygon
  11879. if (t === 1 || t === 0) {
  11880. dir = y1 < y0 ? 0.5 : -0.5;
  11881. }
  11882. var x_ = t * (x1 - x0) + x0; // If (x, y) on the line, considered as "contain".
  11883. return x_ === x ? Infinity : x_ > x ? dir : 0;
  11884. }
  11885. var CMD$1 = PathProxy.CMD;
  11886. var PI2$1 = Math.PI * 2;
  11887. var EPSILON$2 = 1e-4;
  11888. function isAroundEqual(a, b) {
  11889. return Math.abs(a - b) < EPSILON$2;
  11890. } // 临时数组
  11891. var roots = [-1, -1, -1];
  11892. var extrema = [-1, -1];
  11893. function swapExtrema() {
  11894. var tmp = extrema[0];
  11895. extrema[0] = extrema[1];
  11896. extrema[1] = tmp;
  11897. }
  11898. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  11899. // Quick reject
  11900. if (y > y0 && y > y1 && y > y2 && y > y3 || y < y0 && y < y1 && y < y2 && y < y3) {
  11901. return 0;
  11902. }
  11903. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  11904. if (nRoots === 0) {
  11905. return 0;
  11906. } else {
  11907. var w = 0;
  11908. var nExtrema = -1;
  11909. var y0_;
  11910. var y1_;
  11911. for (var i = 0; i < nRoots; i++) {
  11912. var t = roots[i]; // Avoid winding error when intersection point is the connect point of two line of polygon
  11913. var unit = t === 0 || t === 1 ? 0.5 : 1;
  11914. var x_ = cubicAt(x0, x1, x2, x3, t);
  11915. if (x_ < x) {
  11916. // Quick reject
  11917. continue;
  11918. }
  11919. if (nExtrema < 0) {
  11920. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  11921. if (extrema[1] < extrema[0] && nExtrema > 1) {
  11922. swapExtrema();
  11923. }
  11924. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  11925. if (nExtrema > 1) {
  11926. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  11927. }
  11928. }
  11929. if (nExtrema === 2) {
  11930. // 分成三段单调函数
  11931. if (t < extrema[0]) {
  11932. w += y0_ < y0 ? unit : -unit;
  11933. } else if (t < extrema[1]) {
  11934. w += y1_ < y0_ ? unit : -unit;
  11935. } else {
  11936. w += y3 < y1_ ? unit : -unit;
  11937. }
  11938. } else {
  11939. // 分成两段单调函数
  11940. if (t < extrema[0]) {
  11941. w += y0_ < y0 ? unit : -unit;
  11942. } else {
  11943. w += y3 < y0_ ? unit : -unit;
  11944. }
  11945. }
  11946. }
  11947. return w;
  11948. }
  11949. }
  11950. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  11951. // Quick reject
  11952. if (y > y0 && y > y1 && y > y2 || y < y0 && y < y1 && y < y2) {
  11953. return 0;
  11954. }
  11955. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  11956. if (nRoots === 0) {
  11957. return 0;
  11958. } else {
  11959. var t = quadraticExtremum(y0, y1, y2);
  11960. if (t >= 0 && t <= 1) {
  11961. var w = 0;
  11962. var y_ = quadraticAt(y0, y1, y2, t);
  11963. for (var i = 0; i < nRoots; i++) {
  11964. // Remove one endpoint.
  11965. var unit = roots[i] === 0 || roots[i] === 1 ? 0.5 : 1;
  11966. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  11967. if (x_ < x) {
  11968. // Quick reject
  11969. continue;
  11970. }
  11971. if (roots[i] < t) {
  11972. w += y_ < y0 ? unit : -unit;
  11973. } else {
  11974. w += y2 < y_ ? unit : -unit;
  11975. }
  11976. }
  11977. return w;
  11978. } else {
  11979. // Remove one endpoint.
  11980. var unit = roots[0] === 0 || roots[0] === 1 ? 0.5 : 1;
  11981. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  11982. if (x_ < x) {
  11983. // Quick reject
  11984. return 0;
  11985. }
  11986. return y2 < y0 ? unit : -unit;
  11987. }
  11988. }
  11989. } // TODO
  11990. // Arc 旋转
  11991. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  11992. y -= cy;
  11993. if (y > r || y < -r) {
  11994. return 0;
  11995. }
  11996. var tmp = Math.sqrt(r * r - y * y);
  11997. roots[0] = -tmp;
  11998. roots[1] = tmp;
  11999. var diff = Math.abs(startAngle - endAngle);
  12000. if (diff < 1e-4) {
  12001. return 0;
  12002. }
  12003. if (diff % PI2$1 < 1e-4) {
  12004. // Is a circle
  12005. startAngle = 0;
  12006. endAngle = PI2$1;
  12007. var dir = anticlockwise ? 1 : -1;
  12008. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  12009. return dir;
  12010. } else {
  12011. return 0;
  12012. }
  12013. }
  12014. if (anticlockwise) {
  12015. var tmp = startAngle;
  12016. startAngle = normalizeRadian(endAngle);
  12017. endAngle = normalizeRadian(tmp);
  12018. } else {
  12019. startAngle = normalizeRadian(startAngle);
  12020. endAngle = normalizeRadian(endAngle);
  12021. }
  12022. if (startAngle > endAngle) {
  12023. endAngle += PI2$1;
  12024. }
  12025. var w = 0;
  12026. for (var i = 0; i < 2; i++) {
  12027. var x_ = roots[i];
  12028. if (x_ + cx > x) {
  12029. var angle = Math.atan2(y, x_);
  12030. var dir = anticlockwise ? 1 : -1;
  12031. if (angle < 0) {
  12032. angle = PI2$1 + angle;
  12033. }
  12034. if (angle >= startAngle && angle <= endAngle || angle + PI2$1 >= startAngle && angle + PI2$1 <= endAngle) {
  12035. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  12036. dir = -dir;
  12037. }
  12038. w += dir;
  12039. }
  12040. }
  12041. }
  12042. return w;
  12043. }
  12044. function containPath(data, lineWidth, isStroke, x, y) {
  12045. var w = 0;
  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++]; // Begin a new subpath
  12052. if (cmd === CMD$1.M && i > 1) {
  12053. // Close previous subpath
  12054. if (!isStroke) {
  12055. w += windingLine(xi, yi, x0, y0, x, y);
  12056. } // 如果被任何一个 subpath 包含
  12057. // if (w !== 0) {
  12058. // return true;
  12059. // }
  12060. }
  12061. if (i === 1) {
  12062. // 如果第一个命令是 L, C, Q
  12063. // 则 previous point 同绘制命令的第一个 point
  12064. //
  12065. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12066. xi = data[i];
  12067. yi = data[i + 1];
  12068. x0 = xi;
  12069. y0 = yi;
  12070. }
  12071. switch (cmd) {
  12072. case CMD$1.M:
  12073. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  12074. // 在 closePath 的时候使用
  12075. x0 = data[i++];
  12076. y0 = data[i++];
  12077. xi = x0;
  12078. yi = y0;
  12079. break;
  12080. case CMD$1.L:
  12081. if (isStroke) {
  12082. if (containStroke$1(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  12083. return true;
  12084. }
  12085. } else {
  12086. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  12087. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  12088. }
  12089. xi = data[i++];
  12090. yi = data[i++];
  12091. break;
  12092. case CMD$1.C:
  12093. if (isStroke) {
  12094. if (containStroke$2(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  12095. return true;
  12096. }
  12097. } else {
  12098. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  12099. }
  12100. xi = data[i++];
  12101. yi = data[i++];
  12102. break;
  12103. case CMD$1.Q:
  12104. if (isStroke) {
  12105. if (containStroke$3(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  12106. return true;
  12107. }
  12108. } else {
  12109. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  12110. }
  12111. xi = data[i++];
  12112. yi = data[i++];
  12113. break;
  12114. case CMD$1.A:
  12115. // TODO Arc 判断的开销比较大
  12116. var cx = data[i++];
  12117. var cy = data[i++];
  12118. var rx = data[i++];
  12119. var ry = data[i++];
  12120. var theta = data[i++];
  12121. var dTheta = data[i++]; // TODO Arc 旋转
  12122. i += 1;
  12123. var anticlockwise = 1 - data[i++];
  12124. var x1 = Math.cos(theta) * rx + cx;
  12125. var y1 = Math.sin(theta) * ry + cy; // 不是直接使用 arc 命令
  12126. if (i > 1) {
  12127. w += windingLine(xi, yi, x1, y1, x, y);
  12128. } else {
  12129. // 第一个命令起点还未定义
  12130. x0 = x1;
  12131. y0 = y1;
  12132. } // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  12133. var _x = (x - cx) * ry / rx + cx;
  12134. if (isStroke) {
  12135. if (containStroke$4(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  12136. return true;
  12137. }
  12138. } else {
  12139. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  12140. }
  12141. xi = Math.cos(theta + dTheta) * rx + cx;
  12142. yi = Math.sin(theta + dTheta) * ry + cy;
  12143. break;
  12144. case CMD$1.R:
  12145. x0 = xi = data[i++];
  12146. y0 = yi = data[i++];
  12147. var width = data[i++];
  12148. var height = data[i++];
  12149. var x1 = x0 + width;
  12150. var y1 = y0 + height;
  12151. if (isStroke) {
  12152. if (containStroke$1(x0, y0, x1, y0, lineWidth, x, y) || containStroke$1(x1, y0, x1, y1, lineWidth, x, y) || containStroke$1(x1, y1, x0, y1, lineWidth, x, y) || containStroke$1(x0, y1, x0, y0, lineWidth, x, y)) {
  12153. return true;
  12154. }
  12155. } else {
  12156. // FIXME Clockwise ?
  12157. w += windingLine(x1, y0, x1, y1, x, y);
  12158. w += windingLine(x0, y1, x0, y0, x, y);
  12159. }
  12160. break;
  12161. case CMD$1.Z:
  12162. if (isStroke) {
  12163. if (containStroke$1(xi, yi, x0, y0, lineWidth, x, y)) {
  12164. return true;
  12165. }
  12166. } else {
  12167. // Close a subpath
  12168. w += windingLine(xi, yi, x0, y0, x, y); // 如果被任何一个 subpath 包含
  12169. // FIXME subpaths may overlap
  12170. // if (w !== 0) {
  12171. // return true;
  12172. // }
  12173. }
  12174. xi = x0;
  12175. yi = y0;
  12176. break;
  12177. }
  12178. }
  12179. if (!isStroke && !isAroundEqual(yi, y0)) {
  12180. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  12181. }
  12182. return w !== 0;
  12183. }
  12184. function contain(pathData, x, y) {
  12185. return containPath(pathData, 0, false, x, y);
  12186. }
  12187. function containStroke(pathData, lineWidth, x, y) {
  12188. return containPath(pathData, lineWidth, true, x, y);
  12189. }
  12190. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  12191. var abs = Math.abs;
  12192. var pathProxyForDraw = new PathProxy(true);
  12193. /**
  12194. * @alias module:zrender/graphic/Path
  12195. * @extends module:zrender/graphic/Displayable
  12196. * @constructor
  12197. * @param {Object} opts
  12198. */
  12199. function Path(opts) {
  12200. Displayable.call(this, opts);
  12201. /**
  12202. * @type {module:zrender/core/PathProxy}
  12203. * @readOnly
  12204. */
  12205. this.path = null;
  12206. }
  12207. Path.prototype = {
  12208. constructor: Path,
  12209. type: 'path',
  12210. __dirtyPath: true,
  12211. strokeContainThreshold: 5,
  12212. // This item default to be false. But in map series in echarts,
  12213. // in order to improve performance, it should be set to true,
  12214. // so the shorty segment won't draw.
  12215. segmentIgnoreThreshold: 0,
  12216. /**
  12217. * See `module:zrender/src/graphic/helper/subPixelOptimize`.
  12218. * @type {boolean}
  12219. */
  12220. subPixelOptimize: false,
  12221. brush: function (ctx, prevEl) {
  12222. var style = this.style;
  12223. var path = this.path || pathProxyForDraw;
  12224. var hasStroke = style.hasStroke();
  12225. var hasFill = style.hasFill();
  12226. var fill = style.fill;
  12227. var stroke = style.stroke;
  12228. var hasFillGradient = hasFill && !!fill.colorStops;
  12229. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  12230. var hasFillPattern = hasFill && !!fill.image;
  12231. var hasStrokePattern = hasStroke && !!stroke.image;
  12232. style.bind(ctx, this, prevEl);
  12233. this.setTransform(ctx);
  12234. if (this.__dirty) {
  12235. var rect; // Update gradient because bounding rect may changed
  12236. if (hasFillGradient) {
  12237. rect = rect || this.getBoundingRect();
  12238. this._fillGradient = style.getGradient(ctx, fill, rect);
  12239. }
  12240. if (hasStrokeGradient) {
  12241. rect = rect || this.getBoundingRect();
  12242. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  12243. }
  12244. } // Use the gradient or pattern
  12245. if (hasFillGradient) {
  12246. // PENDING If may have affect the state
  12247. ctx.fillStyle = this._fillGradient;
  12248. } else if (hasFillPattern) {
  12249. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  12250. }
  12251. if (hasStrokeGradient) {
  12252. ctx.strokeStyle = this._strokeGradient;
  12253. } else if (hasStrokePattern) {
  12254. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  12255. }
  12256. var lineDash = style.lineDash;
  12257. var lineDashOffset = style.lineDashOffset;
  12258. var ctxLineDash = !!ctx.setLineDash; // Update path sx, sy
  12259. var scale = this.getGlobalScale();
  12260. path.setScale(scale[0], scale[1], this.segmentIgnoreThreshold); // Proxy context
  12261. // Rebuild path in following 2 cases
  12262. // 1. Path is dirty
  12263. // 2. Path needs javascript implemented lineDash stroking.
  12264. // In this case, lineDash information will not be saved in PathProxy
  12265. if (this.__dirtyPath || lineDash && !ctxLineDash && hasStroke) {
  12266. path.beginPath(ctx); // Setting line dash before build path
  12267. if (lineDash && !ctxLineDash) {
  12268. path.setLineDash(lineDash);
  12269. path.setLineDashOffset(lineDashOffset);
  12270. }
  12271. this.buildPath(path, this.shape, false); // Clear path dirty flag
  12272. if (this.path) {
  12273. this.__dirtyPath = false;
  12274. }
  12275. } else {
  12276. // Replay path building
  12277. ctx.beginPath();
  12278. this.path.rebuildPath(ctx);
  12279. }
  12280. if (hasFill) {
  12281. if (style.fillOpacity != null) {
  12282. var originalGlobalAlpha = ctx.globalAlpha;
  12283. ctx.globalAlpha = style.fillOpacity * style.opacity;
  12284. path.fill(ctx);
  12285. ctx.globalAlpha = originalGlobalAlpha;
  12286. } else {
  12287. path.fill(ctx);
  12288. }
  12289. }
  12290. if (lineDash && ctxLineDash) {
  12291. ctx.setLineDash(lineDash);
  12292. ctx.lineDashOffset = lineDashOffset;
  12293. }
  12294. if (hasStroke) {
  12295. if (style.strokeOpacity != null) {
  12296. var originalGlobalAlpha = ctx.globalAlpha;
  12297. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  12298. path.stroke(ctx);
  12299. ctx.globalAlpha = originalGlobalAlpha;
  12300. } else {
  12301. path.stroke(ctx);
  12302. }
  12303. }
  12304. if (lineDash && ctxLineDash) {
  12305. // PENDING
  12306. // Remove lineDash
  12307. ctx.setLineDash([]);
  12308. } // Draw rect text
  12309. if (style.text != null) {
  12310. // Only restore transform when needs draw text.
  12311. this.restoreTransform(ctx);
  12312. this.drawRectText(ctx, this.getBoundingRect());
  12313. }
  12314. },
  12315. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  12316. // Like in circle
  12317. buildPath: function (ctx, shapeCfg, inBundle) {},
  12318. createPathProxy: function () {
  12319. this.path = new PathProxy();
  12320. },
  12321. getBoundingRect: function () {
  12322. var rect = this._rect;
  12323. var style = this.style;
  12324. var needsUpdateRect = !rect;
  12325. if (needsUpdateRect) {
  12326. var path = this.path;
  12327. if (!path) {
  12328. // Create path on demand.
  12329. path = this.path = new PathProxy();
  12330. }
  12331. if (this.__dirtyPath) {
  12332. path.beginPath();
  12333. this.buildPath(path, this.shape, false);
  12334. }
  12335. rect = path.getBoundingRect();
  12336. }
  12337. this._rect = rect;
  12338. if (style.hasStroke()) {
  12339. // Needs update rect with stroke lineWidth when
  12340. // 1. Element changes scale or lineWidth
  12341. // 2. Shape is changed
  12342. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  12343. if (this.__dirty || needsUpdateRect) {
  12344. rectWithStroke.copy(rect); // FIXME Must after updateTransform
  12345. var w = style.lineWidth; // PENDING, Min line width is needed when line is horizontal or vertical
  12346. var lineScale = style.strokeNoScale ? this.getLineScale() : 1; // Only add extra hover lineWidth when there are no fill
  12347. if (!style.hasFill()) {
  12348. w = Math.max(w, this.strokeContainThreshold || 4);
  12349. } // Consider line width
  12350. // Line scale can't be 0;
  12351. if (lineScale > 1e-10) {
  12352. rectWithStroke.width += w / lineScale;
  12353. rectWithStroke.height += w / lineScale;
  12354. rectWithStroke.x -= w / lineScale / 2;
  12355. rectWithStroke.y -= w / lineScale / 2;
  12356. }
  12357. } // Return rect with stroke
  12358. return rectWithStroke;
  12359. }
  12360. return rect;
  12361. },
  12362. contain: function (x, y) {
  12363. var localPos = this.transformCoordToLocal(x, y);
  12364. var rect = this.getBoundingRect();
  12365. var style = this.style;
  12366. x = localPos[0];
  12367. y = localPos[1];
  12368. if (rect.contain(x, y)) {
  12369. var pathData = this.path.data;
  12370. if (style.hasStroke()) {
  12371. var lineWidth = style.lineWidth;
  12372. var lineScale = style.strokeNoScale ? this.getLineScale() : 1; // Line scale can't be 0;
  12373. if (lineScale > 1e-10) {
  12374. // Only add extra hover lineWidth when there are no fill
  12375. if (!style.hasFill()) {
  12376. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  12377. }
  12378. if (containStroke(pathData, lineWidth / lineScale, x, y)) {
  12379. return true;
  12380. }
  12381. }
  12382. }
  12383. if (style.hasFill()) {
  12384. return contain(pathData, x, y);
  12385. }
  12386. }
  12387. return false;
  12388. },
  12389. /**
  12390. * @param {boolean} dirtyPath
  12391. */
  12392. dirty: function (dirtyPath) {
  12393. if (dirtyPath == null) {
  12394. dirtyPath = true;
  12395. } // Only mark dirty, not mark clean
  12396. if (dirtyPath) {
  12397. this.__dirtyPath = dirtyPath;
  12398. this._rect = null;
  12399. }
  12400. this.__dirty = this.__dirtyText = true;
  12401. this.__zr && this.__zr.refresh(); // Used as a clipping path
  12402. if (this.__clipTarget) {
  12403. this.__clipTarget.dirty();
  12404. }
  12405. },
  12406. /**
  12407. * Alias for animate('shape')
  12408. * @param {boolean} loop
  12409. */
  12410. animateShape: function (loop) {
  12411. return this.animate('shape', loop);
  12412. },
  12413. // Overwrite attrKV
  12414. attrKV: function (key, value) {
  12415. // FIXME
  12416. if (key === 'shape') {
  12417. this.setShape(value);
  12418. this.__dirtyPath = true;
  12419. this._rect = null;
  12420. } else {
  12421. Displayable.prototype.attrKV.call(this, key, value);
  12422. }
  12423. },
  12424. /**
  12425. * @param {Object|string} key
  12426. * @param {*} value
  12427. */
  12428. setShape: function (key, value) {
  12429. var shape = this.shape; // Path from string may not have shape
  12430. if (shape) {
  12431. if (isObject$1(key)) {
  12432. for (var name in key) {
  12433. if (key.hasOwnProperty(name)) {
  12434. shape[name] = key[name];
  12435. }
  12436. }
  12437. } else {
  12438. shape[key] = value;
  12439. }
  12440. this.dirty(true);
  12441. }
  12442. return this;
  12443. },
  12444. getLineScale: function () {
  12445. var m = this.transform; // Get the line scale.
  12446. // Determinant of `m` means how much the area is enlarged by the
  12447. // transformation. So its square root can be used as a scale factor
  12448. // for width.
  12449. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10 ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1])) : 1;
  12450. }
  12451. };
  12452. /**
  12453. * 扩展一个 Path element, 比如星形,圆等。
  12454. * Extend a path element
  12455. * @param {Object} props
  12456. * @param {string} props.type Path type
  12457. * @param {Function} props.init Initialize
  12458. * @param {Function} props.buildPath Overwrite buildPath method
  12459. * @param {Object} [props.style] Extended default style config
  12460. * @param {Object} [props.shape] Extended default shape config
  12461. */
  12462. Path.extend = function (defaults$$1) {
  12463. var Sub = function (opts) {
  12464. Path.call(this, opts);
  12465. if (defaults$$1.style) {
  12466. // Extend default style
  12467. this.style.extendFrom(defaults$$1.style, false);
  12468. } // Extend default shape
  12469. var defaultShape = defaults$$1.shape;
  12470. if (defaultShape) {
  12471. this.shape = this.shape || {};
  12472. var thisShape = this.shape;
  12473. for (var name in defaultShape) {
  12474. if (!thisShape.hasOwnProperty(name) && defaultShape.hasOwnProperty(name)) {
  12475. thisShape[name] = defaultShape[name];
  12476. }
  12477. }
  12478. }
  12479. defaults$$1.init && defaults$$1.init.call(this, opts);
  12480. };
  12481. inherits(Sub, Path); // FIXME 不能 extend position, rotation 等引用对象
  12482. for (var name in defaults$$1) {
  12483. // Extending prototype values and methods
  12484. if (name !== 'style' && name !== 'shape') {
  12485. Sub.prototype[name] = defaults$$1[name];
  12486. }
  12487. }
  12488. return Sub;
  12489. };
  12490. inherits(Path, Displayable);
  12491. var CMD$2 = PathProxy.CMD;
  12492. var points = [[], [], []];
  12493. var mathSqrt$3 = Math.sqrt;
  12494. var mathAtan2 = Math.atan2;
  12495. var transformPath = function (path, m) {
  12496. var data = path.data;
  12497. var cmd;
  12498. var nPoint;
  12499. var i;
  12500. var j;
  12501. var k;
  12502. var p;
  12503. var M = CMD$2.M;
  12504. var C = CMD$2.C;
  12505. var L = CMD$2.L;
  12506. var R = CMD$2.R;
  12507. var A = CMD$2.A;
  12508. var Q = CMD$2.Q;
  12509. for (i = 0, j = 0; i < data.length;) {
  12510. cmd = data[i++];
  12511. j = i;
  12512. nPoint = 0;
  12513. switch (cmd) {
  12514. case M:
  12515. nPoint = 1;
  12516. break;
  12517. case L:
  12518. nPoint = 1;
  12519. break;
  12520. case C:
  12521. nPoint = 3;
  12522. break;
  12523. case Q:
  12524. nPoint = 2;
  12525. break;
  12526. case A:
  12527. var x = m[4];
  12528. var y = m[5];
  12529. var sx = mathSqrt$3(m[0] * m[0] + m[1] * m[1]);
  12530. var sy = mathSqrt$3(m[2] * m[2] + m[3] * m[3]);
  12531. var angle = mathAtan2(-m[1] / sy, m[0] / sx); // cx
  12532. data[i] *= sx;
  12533. data[i++] += x; // cy
  12534. data[i] *= sy;
  12535. data[i++] += y; // Scale rx and ry
  12536. // FIXME Assume psi is 0 here
  12537. data[i++] *= sx;
  12538. data[i++] *= sy; // Start angle
  12539. data[i++] += angle; // end angle
  12540. data[i++] += angle; // FIXME psi
  12541. i += 2;
  12542. j = i;
  12543. break;
  12544. case R:
  12545. // x0, y0
  12546. p[0] = data[i++];
  12547. p[1] = data[i++];
  12548. applyTransform(p, p, m);
  12549. data[j++] = p[0];
  12550. data[j++] = p[1]; // x1, y1
  12551. p[0] += data[i++];
  12552. p[1] += data[i++];
  12553. applyTransform(p, p, m);
  12554. data[j++] = p[0];
  12555. data[j++] = p[1];
  12556. }
  12557. for (k = 0; k < nPoint; k++) {
  12558. var p = points[k];
  12559. p[0] = data[i++];
  12560. p[1] = data[i++];
  12561. applyTransform(p, p, m); // Write back
  12562. data[j++] = p[0];
  12563. data[j++] = p[1];
  12564. }
  12565. }
  12566. }; // command chars
  12567. // var cc = [
  12568. // 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  12569. // 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  12570. // ];
  12571. var mathSqrt = Math.sqrt;
  12572. var mathSin = Math.sin;
  12573. var mathCos = Math.cos;
  12574. var PI = Math.PI;
  12575. var vMag = function (v) {
  12576. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  12577. };
  12578. var vRatio = function (u, v) {
  12579. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  12580. };
  12581. var vAngle = function (u, v) {
  12582. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
  12583. };
  12584. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  12585. var psi = psiDeg * (PI / 180.0);
  12586. var xp = mathCos(psi) * (x1 - x2) / 2.0 + mathSin(psi) * (y1 - y2) / 2.0;
  12587. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0 + mathCos(psi) * (y1 - y2) / 2.0;
  12588. var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
  12589. if (lambda > 1) {
  12590. rx *= mathSqrt(lambda);
  12591. ry *= mathSqrt(lambda);
  12592. }
  12593. var f = (fa === fs ? -1 : 1) * mathSqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) / (rx * rx * (yp * yp) + ry * ry * (xp * xp))) || 0;
  12594. var cxp = f * rx * yp / ry;
  12595. var cyp = f * -ry * xp / rx;
  12596. var cx = (x1 + x2) / 2.0 + mathCos(psi) * cxp - mathSin(psi) * cyp;
  12597. var cy = (y1 + y2) / 2.0 + mathSin(psi) * cxp + mathCos(psi) * cyp;
  12598. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  12599. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  12600. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  12601. var dTheta = vAngle(u, v);
  12602. if (vRatio(u, v) <= -1) {
  12603. dTheta = PI;
  12604. }
  12605. if (vRatio(u, v) >= 1) {
  12606. dTheta = 0;
  12607. }
  12608. if (fs === 0 && dTheta > 0) {
  12609. dTheta = dTheta - 2 * PI;
  12610. }
  12611. if (fs === 1 && dTheta < 0) {
  12612. dTheta = dTheta + 2 * PI;
  12613. }
  12614. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  12615. }
  12616. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig; // Consider case:
  12617. // (1) delimiter can be comma or space, where continuous commas
  12618. // or spaces should be seen as one comma.
  12619. // (2) value can be like:
  12620. // '2e-4', 'l.5.9' (ignore 0), 'M-10-10', 'l-2.43e-1,34.9983',
  12621. // 'l-.5E1,54', '121-23-44-11' (no delimiter)
  12622. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g; // var valueSplitReg = /[\s,]+/;
  12623. function createPathProxyFromString(data) {
  12624. if (!data) {
  12625. return new PathProxy();
  12626. } // var data = data.replace(/-/g, ' -')
  12627. // .replace(/ /g, ' ')
  12628. // .replace(/ /g, ',')
  12629. // .replace(/,,/g, ',');
  12630. // var n;
  12631. // create pipes so that we can split the data
  12632. // for (n = 0; n < cc.length; n++) {
  12633. // cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  12634. // }
  12635. // data = data.replace(/-/g, ',-');
  12636. // create array
  12637. // var arr = cs.split('|');
  12638. // init context point
  12639. var cpx = 0;
  12640. var cpy = 0;
  12641. var subpathX = cpx;
  12642. var subpathY = cpy;
  12643. var prevCmd;
  12644. var path = new PathProxy();
  12645. var CMD = PathProxy.CMD; // commandReg.lastIndex = 0;
  12646. // var cmdResult;
  12647. // while ((cmdResult = commandReg.exec(data)) != null) {
  12648. // var cmdStr = cmdResult[1];
  12649. // var cmdContent = cmdResult[2];
  12650. var cmdList = data.match(commandReg);
  12651. for (var l = 0; l < cmdList.length; l++) {
  12652. var cmdText = cmdList[l];
  12653. var cmdStr = cmdText.charAt(0);
  12654. var cmd; // String#split is faster a little bit than String#replace or RegExp#exec.
  12655. // var p = cmdContent.split(valueSplitReg);
  12656. // var pLen = 0;
  12657. // for (var i = 0; i < p.length; i++) {
  12658. // // '' and other invalid str => NaN
  12659. // var val = parseFloat(p[i]);
  12660. // !isNaN(val) && (p[pLen++] = val);
  12661. // }
  12662. var p = cmdText.match(numberReg) || [];
  12663. var pLen = p.length;
  12664. for (var i = 0; i < pLen; i++) {
  12665. p[i] = parseFloat(p[i]);
  12666. }
  12667. var off = 0;
  12668. while (off < pLen) {
  12669. var ctlPtx;
  12670. var ctlPty;
  12671. var rx;
  12672. var ry;
  12673. var psi;
  12674. var fa;
  12675. var fs;
  12676. var x1 = cpx;
  12677. var y1 = cpy; // convert l, H, h, V, and v to L
  12678. switch (cmdStr) {
  12679. case 'l':
  12680. cpx += p[off++];
  12681. cpy += p[off++];
  12682. cmd = CMD.L;
  12683. path.addData(cmd, cpx, cpy);
  12684. break;
  12685. case 'L':
  12686. cpx = p[off++];
  12687. cpy = p[off++];
  12688. cmd = CMD.L;
  12689. path.addData(cmd, cpx, cpy);
  12690. break;
  12691. case 'm':
  12692. cpx += p[off++];
  12693. cpy += p[off++];
  12694. cmd = CMD.M;
  12695. path.addData(cmd, cpx, cpy);
  12696. subpathX = cpx;
  12697. subpathY = cpy;
  12698. cmdStr = 'l';
  12699. break;
  12700. case 'M':
  12701. cpx = p[off++];
  12702. cpy = p[off++];
  12703. cmd = CMD.M;
  12704. path.addData(cmd, cpx, cpy);
  12705. subpathX = cpx;
  12706. subpathY = cpy;
  12707. cmdStr = 'L';
  12708. break;
  12709. case 'h':
  12710. cpx += p[off++];
  12711. cmd = CMD.L;
  12712. path.addData(cmd, cpx, cpy);
  12713. break;
  12714. case 'H':
  12715. cpx = p[off++];
  12716. cmd = CMD.L;
  12717. path.addData(cmd, cpx, cpy);
  12718. break;
  12719. case 'v':
  12720. cpy += p[off++];
  12721. cmd = CMD.L;
  12722. path.addData(cmd, cpx, cpy);
  12723. break;
  12724. case 'V':
  12725. cpy = p[off++];
  12726. cmd = CMD.L;
  12727. path.addData(cmd, cpx, cpy);
  12728. break;
  12729. case 'C':
  12730. cmd = CMD.C;
  12731. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  12732. cpx = p[off - 2];
  12733. cpy = p[off - 1];
  12734. break;
  12735. case 'c':
  12736. cmd = CMD.C;
  12737. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  12738. cpx += p[off - 2];
  12739. cpy += p[off - 1];
  12740. break;
  12741. case 'S':
  12742. ctlPtx = cpx;
  12743. ctlPty = cpy;
  12744. var len = path.len();
  12745. var pathData = path.data;
  12746. if (prevCmd === CMD.C) {
  12747. ctlPtx += cpx - pathData[len - 4];
  12748. ctlPty += cpy - pathData[len - 3];
  12749. }
  12750. cmd = CMD.C;
  12751. x1 = p[off++];
  12752. y1 = p[off++];
  12753. cpx = p[off++];
  12754. cpy = p[off++];
  12755. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12756. break;
  12757. case 's':
  12758. ctlPtx = cpx;
  12759. ctlPty = cpy;
  12760. var len = path.len();
  12761. var pathData = path.data;
  12762. if (prevCmd === CMD.C) {
  12763. ctlPtx += cpx - pathData[len - 4];
  12764. ctlPty += cpy - pathData[len - 3];
  12765. }
  12766. cmd = CMD.C;
  12767. x1 = cpx + p[off++];
  12768. y1 = cpy + p[off++];
  12769. cpx += p[off++];
  12770. cpy += p[off++];
  12771. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12772. break;
  12773. case 'Q':
  12774. x1 = p[off++];
  12775. y1 = p[off++];
  12776. cpx = p[off++];
  12777. cpy = p[off++];
  12778. cmd = CMD.Q;
  12779. path.addData(cmd, x1, y1, cpx, cpy);
  12780. break;
  12781. case 'q':
  12782. x1 = p[off++] + cpx;
  12783. y1 = p[off++] + cpy;
  12784. cpx += p[off++];
  12785. cpy += p[off++];
  12786. cmd = CMD.Q;
  12787. path.addData(cmd, x1, y1, cpx, cpy);
  12788. break;
  12789. case 'T':
  12790. ctlPtx = cpx;
  12791. ctlPty = cpy;
  12792. var len = path.len();
  12793. var pathData = path.data;
  12794. if (prevCmd === CMD.Q) {
  12795. ctlPtx += cpx - pathData[len - 4];
  12796. ctlPty += cpy - pathData[len - 3];
  12797. }
  12798. cpx = p[off++];
  12799. cpy = p[off++];
  12800. cmd = CMD.Q;
  12801. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12802. break;
  12803. case 't':
  12804. ctlPtx = cpx;
  12805. ctlPty = cpy;
  12806. var len = path.len();
  12807. var pathData = path.data;
  12808. if (prevCmd === CMD.Q) {
  12809. ctlPtx += cpx - pathData[len - 4];
  12810. ctlPty += cpy - pathData[len - 3];
  12811. }
  12812. cpx += p[off++];
  12813. cpy += p[off++];
  12814. cmd = CMD.Q;
  12815. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12816. break;
  12817. case 'A':
  12818. rx = p[off++];
  12819. ry = p[off++];
  12820. psi = p[off++];
  12821. fa = p[off++];
  12822. fs = p[off++];
  12823. x1 = cpx, y1 = cpy;
  12824. cpx = p[off++];
  12825. cpy = p[off++];
  12826. cmd = CMD.A;
  12827. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  12828. break;
  12829. case 'a':
  12830. rx = p[off++];
  12831. ry = p[off++];
  12832. psi = p[off++];
  12833. fa = p[off++];
  12834. fs = p[off++];
  12835. x1 = cpx, y1 = cpy;
  12836. cpx += p[off++];
  12837. cpy += p[off++];
  12838. cmd = CMD.A;
  12839. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  12840. break;
  12841. }
  12842. }
  12843. if (cmdStr === 'z' || cmdStr === 'Z') {
  12844. cmd = CMD.Z;
  12845. path.addData(cmd); // z may be in the middle of the path.
  12846. cpx = subpathX;
  12847. cpy = subpathY;
  12848. }
  12849. prevCmd = cmd;
  12850. }
  12851. path.toStatic();
  12852. return path;
  12853. } // TODO Optimize double memory cost problem
  12854. function createPathOptions(str, opts) {
  12855. var pathProxy = createPathProxyFromString(str);
  12856. opts = opts || {};
  12857. opts.buildPath = function (path) {
  12858. if (path.setData) {
  12859. path.setData(pathProxy.data); // Svg and vml renderer don't have context
  12860. var ctx = path.getContext();
  12861. if (ctx) {
  12862. path.rebuildPath(ctx);
  12863. }
  12864. } else {
  12865. var ctx = path;
  12866. pathProxy.rebuildPath(ctx);
  12867. }
  12868. };
  12869. opts.applyTransform = function (m) {
  12870. transformPath(pathProxy, m);
  12871. this.dirty(true);
  12872. };
  12873. return opts;
  12874. }
  12875. /**
  12876. * Create a Path object from path string data
  12877. * http://www.w3.org/TR/SVG/paths.html#PathData
  12878. * @param {Object} opts Other options
  12879. */
  12880. function createFromString(str, opts) {
  12881. return new Path(createPathOptions(str, opts));
  12882. }
  12883. /**
  12884. * Create a Path class from path string data
  12885. * @param {string} str
  12886. * @param {Object} opts Other options
  12887. */
  12888. function extendFromString(str, opts) {
  12889. return Path.extend(createPathOptions(str, opts));
  12890. }
  12891. /**
  12892. * Merge multiple paths
  12893. */
  12894. // TODO Apply transform
  12895. // TODO stroke dash
  12896. // TODO Optimize double memory cost problem
  12897. function mergePath$1(pathEls, opts) {
  12898. var pathList = [];
  12899. var len = pathEls.length;
  12900. for (var i = 0; i < len; i++) {
  12901. var pathEl = pathEls[i];
  12902. if (!pathEl.path) {
  12903. pathEl.createPathProxy();
  12904. }
  12905. if (pathEl.__dirtyPath) {
  12906. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  12907. }
  12908. pathList.push(pathEl.path);
  12909. }
  12910. var pathBundle = new Path(opts); // Need path proxy.
  12911. pathBundle.createPathProxy();
  12912. pathBundle.buildPath = function (path) {
  12913. path.appendPath(pathList); // Svg and vml renderer don't have context
  12914. var ctx = path.getContext();
  12915. if (ctx) {
  12916. path.rebuildPath(ctx);
  12917. }
  12918. };
  12919. return pathBundle;
  12920. }
  12921. /**
  12922. * @alias zrender/graphic/Text
  12923. * @extends module:zrender/graphic/Displayable
  12924. * @constructor
  12925. * @param {Object} opts
  12926. */
  12927. var Text = function (opts) {
  12928. // jshint ignore:line
  12929. Displayable.call(this, opts);
  12930. };
  12931. Text.prototype = {
  12932. constructor: Text,
  12933. type: 'text',
  12934. brush: function (ctx, prevEl) {
  12935. var style = this.style; // Optimize, avoid normalize every time.
  12936. this.__dirty && normalizeTextStyle(style, true); // Use props with prefix 'text'.
  12937. style.fill = style.stroke = style.shadowBlur = style.shadowColor = style.shadowOffsetX = style.shadowOffsetY = null;
  12938. var text = style.text; // Convert to string
  12939. text != null && (text += ''); // Do not apply style.bind in Text node. Because the real bind job
  12940. // is in textHelper.renderText, and performance of text render should
  12941. // be considered.
  12942. // style.bind(ctx, this, prevEl);
  12943. if (!needDrawText(text, style)) {
  12944. // The current el.style is not applied
  12945. // and should not be used as cache.
  12946. ctx.__attrCachedBy = ContextCachedBy.NONE;
  12947. return;
  12948. }
  12949. this.setTransform(ctx);
  12950. renderText(this, ctx, text, style, null, prevEl);
  12951. this.restoreTransform(ctx);
  12952. },
  12953. getBoundingRect: function () {
  12954. var style = this.style; // Optimize, avoid normalize every time.
  12955. this.__dirty && normalizeTextStyle(style, true);
  12956. if (!this._rect) {
  12957. var text = style.text;
  12958. text != null ? text += '' : text = '';
  12959. var rect = getBoundingRect(style.text + '', style.font, style.textAlign, style.textVerticalAlign, style.textPadding, style.textLineHeight, style.rich);
  12960. rect.x += style.x || 0;
  12961. rect.y += style.y || 0;
  12962. if (getStroke(style.textStroke, style.textStrokeWidth)) {
  12963. var w = style.textStrokeWidth;
  12964. rect.x -= w / 2;
  12965. rect.y -= w / 2;
  12966. rect.width += w;
  12967. rect.height += w;
  12968. }
  12969. this._rect = rect;
  12970. }
  12971. return this._rect;
  12972. }
  12973. };
  12974. inherits(Text, Displayable);
  12975. /**
  12976. * 圆形
  12977. * @module zrender/shape/Circle
  12978. */
  12979. var Circle = Path.extend({
  12980. type: 'circle',
  12981. shape: {
  12982. cx: 0,
  12983. cy: 0,
  12984. r: 0
  12985. },
  12986. buildPath: function (ctx, shape, inBundle) {
  12987. // Better stroking in ShapeBundle
  12988. // Always do it may have performence issue ( fill may be 2x more cost)
  12989. if (inBundle) {
  12990. ctx.moveTo(shape.cx + shape.r, shape.cy);
  12991. } // else {
  12992. // if (ctx.allocate && !ctx.data.length) {
  12993. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  12994. // }
  12995. // }
  12996. // Better stroking in ShapeBundle
  12997. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  12998. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  12999. }
  13000. }); // Fix weird bug in some version of IE11 (like 11.0.9600.178**),
  13001. // where exception "unexpected call to method or property access"
  13002. // might be thrown when calling ctx.fill or ctx.stroke after a path
  13003. // whose area size is zero is drawn and ctx.clip() is called and
  13004. // shadowBlur is set. See #4572, #3112, #5777.
  13005. // (e.g.,
  13006. // ctx.moveTo(10, 10);
  13007. // ctx.lineTo(20, 10);
  13008. // ctx.closePath();
  13009. // ctx.clip();
  13010. // ctx.shadowBlur = 10;
  13011. // ...
  13012. // ctx.fill();
  13013. // )
  13014. var shadowTemp = [['shadowBlur', 0], ['shadowColor', '#000'], ['shadowOffsetX', 0], ['shadowOffsetY', 0]];
  13015. var fixClipWithShadow = function (orignalBrush) {
  13016. // version string can be: '11.0'
  13017. return env$1.browser.ie && env$1.browser.version >= 11 ? function () {
  13018. var clipPaths = this.__clipPaths;
  13019. var style = this.style;
  13020. var modified;
  13021. if (clipPaths) {
  13022. for (var i = 0; i < clipPaths.length; i++) {
  13023. var clipPath = clipPaths[i];
  13024. var shape = clipPath && clipPath.shape;
  13025. var type = clipPath && clipPath.type;
  13026. if (shape && (type === 'sector' && shape.startAngle === shape.endAngle || type === 'rect' && (!shape.width || !shape.height))) {
  13027. for (var j = 0; j < shadowTemp.length; j++) {
  13028. // It is save to put shadowTemp static, because shadowTemp
  13029. // will be all modified each item brush called.
  13030. shadowTemp[j][2] = style[shadowTemp[j][0]];
  13031. style[shadowTemp[j][0]] = shadowTemp[j][1];
  13032. }
  13033. modified = true;
  13034. break;
  13035. }
  13036. }
  13037. }
  13038. orignalBrush.apply(this, arguments);
  13039. if (modified) {
  13040. for (var j = 0; j < shadowTemp.length; j++) {
  13041. style[shadowTemp[j][0]] = shadowTemp[j][2];
  13042. }
  13043. }
  13044. } : orignalBrush;
  13045. };
  13046. /**
  13047. * 扇形
  13048. * @module zrender/graphic/shape/Sector
  13049. */
  13050. var Sector = Path.extend({
  13051. type: 'sector',
  13052. shape: {
  13053. cx: 0,
  13054. cy: 0,
  13055. r0: 0,
  13056. r: 0,
  13057. startAngle: 0,
  13058. endAngle: Math.PI * 2,
  13059. clockwise: true
  13060. },
  13061. brush: fixClipWithShadow(Path.prototype.brush),
  13062. buildPath: function (ctx, shape) {
  13063. var x = shape.cx;
  13064. var y = shape.cy;
  13065. var r0 = Math.max(shape.r0 || 0, 0);
  13066. var r = Math.max(shape.r, 0);
  13067. var startAngle = shape.startAngle;
  13068. var endAngle = shape.endAngle;
  13069. var clockwise = shape.clockwise;
  13070. var unitX = Math.cos(startAngle);
  13071. var unitY = Math.sin(startAngle);
  13072. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  13073. ctx.lineTo(unitX * r + x, unitY * r + y);
  13074. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13075. ctx.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  13076. if (r0 !== 0) {
  13077. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  13078. }
  13079. ctx.closePath();
  13080. }
  13081. });
  13082. /**
  13083. * 圆环
  13084. * @module zrender/graphic/shape/Ring
  13085. */
  13086. var Ring = Path.extend({
  13087. type: 'ring',
  13088. shape: {
  13089. cx: 0,
  13090. cy: 0,
  13091. r: 0,
  13092. r0: 0
  13093. },
  13094. buildPath: function (ctx, shape) {
  13095. var x = shape.cx;
  13096. var y = shape.cy;
  13097. var PI2 = Math.PI * 2;
  13098. ctx.moveTo(x + shape.r, y);
  13099. ctx.arc(x, y, shape.r, 0, PI2, false);
  13100. ctx.moveTo(x + shape.r0, y);
  13101. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13102. }
  13103. });
  13104. /**
  13105. * Catmull-Rom spline 插值折线
  13106. * @module zrender/shape/util/smoothSpline
  13107. * @author pissang (https://www.github.com/pissang)
  13108. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13109. * errorrik (errorrik@gmail.com)
  13110. */
  13111. /**
  13112. * @inner
  13113. */
  13114. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  13115. var v0 = (p2 - p0) * 0.5;
  13116. var v1 = (p3 - p1) * 0.5;
  13117. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  13118. }
  13119. /**
  13120. * @alias module:zrender/shape/util/smoothSpline
  13121. * @param {Array} points 线段顶点数组
  13122. * @param {boolean} isLoop
  13123. * @return {Array}
  13124. */
  13125. var smoothSpline = function (points, isLoop) {
  13126. var len$$1 = points.length;
  13127. var ret = [];
  13128. var distance$$1 = 0;
  13129. for (var i = 1; i < len$$1; i++) {
  13130. distance$$1 += distance(points[i - 1], points[i]);
  13131. }
  13132. var segs = distance$$1 / 2;
  13133. segs = segs < len$$1 ? len$$1 : segs;
  13134. for (var i = 0; i < segs; i++) {
  13135. var pos = i / (segs - 1) * (isLoop ? len$$1 : len$$1 - 1);
  13136. var idx = Math.floor(pos);
  13137. var w = pos - idx;
  13138. var p0;
  13139. var p1 = points[idx % len$$1];
  13140. var p2;
  13141. var p3;
  13142. if (!isLoop) {
  13143. p0 = points[idx === 0 ? idx : idx - 1];
  13144. p2 = points[idx > len$$1 - 2 ? len$$1 - 1 : idx + 1];
  13145. p3 = points[idx > len$$1 - 3 ? len$$1 - 1 : idx + 2];
  13146. } else {
  13147. p0 = points[(idx - 1 + len$$1) % len$$1];
  13148. p2 = points[(idx + 1) % len$$1];
  13149. p3 = points[(idx + 2) % len$$1];
  13150. }
  13151. var w2 = w * w;
  13152. var w3 = w * w2;
  13153. ret.push([interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3), interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)]);
  13154. }
  13155. return ret;
  13156. };
  13157. /**
  13158. * 贝塞尔平滑曲线
  13159. * @module zrender/shape/util/smoothBezier
  13160. * @author pissang (https://www.github.com/pissang)
  13161. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13162. * errorrik (errorrik@gmail.com)
  13163. */
  13164. /**
  13165. * 贝塞尔平滑曲线
  13166. * @alias module:zrender/shape/util/smoothBezier
  13167. * @param {Array} points 线段顶点数组
  13168. * @param {number} smooth 平滑等级, 0-1
  13169. * @param {boolean} isLoop
  13170. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  13171. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  13172. * 整个折线的包围盒做一个并集用来约束控制点。
  13173. * @param {Array} 计算出来的控制点数组
  13174. */
  13175. var smoothBezier = function (points, smooth, isLoop, constraint) {
  13176. var cps = [];
  13177. var v = [];
  13178. var v1 = [];
  13179. var v2 = [];
  13180. var prevPoint;
  13181. var nextPoint;
  13182. var min$$1;
  13183. var max$$1;
  13184. if (constraint) {
  13185. min$$1 = [Infinity, Infinity];
  13186. max$$1 = [-Infinity, -Infinity];
  13187. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13188. min(min$$1, min$$1, points[i]);
  13189. max(max$$1, max$$1, points[i]);
  13190. } // 与指定的包围盒做并集
  13191. min(min$$1, min$$1, constraint[0]);
  13192. max(max$$1, max$$1, constraint[1]);
  13193. }
  13194. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13195. var point = points[i];
  13196. if (isLoop) {
  13197. prevPoint = points[i ? i - 1 : len$$1 - 1];
  13198. nextPoint = points[(i + 1) % len$$1];
  13199. } else {
  13200. if (i === 0 || i === len$$1 - 1) {
  13201. cps.push(clone$1(points[i]));
  13202. continue;
  13203. } else {
  13204. prevPoint = points[i - 1];
  13205. nextPoint = points[i + 1];
  13206. }
  13207. }
  13208. sub(v, nextPoint, prevPoint); // use degree to scale the handle length
  13209. scale(v, v, smooth);
  13210. var d0 = distance(point, prevPoint);
  13211. var d1 = distance(point, nextPoint);
  13212. var sum = d0 + d1;
  13213. if (sum !== 0) {
  13214. d0 /= sum;
  13215. d1 /= sum;
  13216. }
  13217. scale(v1, v, -d0);
  13218. scale(v2, v, d1);
  13219. var cp0 = add([], point, v1);
  13220. var cp1 = add([], point, v2);
  13221. if (constraint) {
  13222. max(cp0, cp0, min$$1);
  13223. min(cp0, cp0, max$$1);
  13224. max(cp1, cp1, min$$1);
  13225. min(cp1, cp1, max$$1);
  13226. }
  13227. cps.push(cp0);
  13228. cps.push(cp1);
  13229. }
  13230. if (isLoop) {
  13231. cps.push(cps.shift());
  13232. }
  13233. return cps;
  13234. };
  13235. function buildPath$1(ctx, shape, closePath) {
  13236. var points = shape.points;
  13237. var smooth = shape.smooth;
  13238. if (points && points.length >= 2) {
  13239. if (smooth && smooth !== 'spline') {
  13240. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  13241. ctx.moveTo(points[0][0], points[0][1]);
  13242. var len = points.length;
  13243. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13244. var cp1 = controlPoints[i * 2];
  13245. var cp2 = controlPoints[i * 2 + 1];
  13246. var p = points[(i + 1) % len];
  13247. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  13248. }
  13249. } else {
  13250. if (smooth === 'spline') {
  13251. points = smoothSpline(points, closePath);
  13252. }
  13253. ctx.moveTo(points[0][0], points[0][1]);
  13254. for (var i = 1, l = points.length; i < l; i++) {
  13255. ctx.lineTo(points[i][0], points[i][1]);
  13256. }
  13257. }
  13258. closePath && ctx.closePath();
  13259. }
  13260. }
  13261. /**
  13262. * 多边形
  13263. * @module zrender/shape/Polygon
  13264. */
  13265. var Polygon = Path.extend({
  13266. type: 'polygon',
  13267. shape: {
  13268. points: null,
  13269. smooth: false,
  13270. smoothConstraint: null
  13271. },
  13272. buildPath: function (ctx, shape) {
  13273. buildPath$1(ctx, shape, true);
  13274. }
  13275. });
  13276. /**
  13277. * @module zrender/graphic/shape/Polyline
  13278. */
  13279. var Polyline = Path.extend({
  13280. type: 'polyline',
  13281. shape: {
  13282. points: null,
  13283. smooth: false,
  13284. smoothConstraint: null
  13285. },
  13286. style: {
  13287. stroke: '#000',
  13288. fill: null
  13289. },
  13290. buildPath: function (ctx, shape) {
  13291. buildPath$1(ctx, shape, false);
  13292. }
  13293. });
  13294. /**
  13295. * Sub-pixel optimize for canvas rendering, prevent from blur
  13296. * when rendering a thin vertical/horizontal line.
  13297. */
  13298. var round = Math.round;
  13299. /**
  13300. * Sub pixel optimize line for canvas
  13301. *
  13302. * @param {Object} outputShape The modification will be performed on `outputShape`.
  13303. * `outputShape` and `inputShape` can be the same object.
  13304. * `outputShape` object can be used repeatly, because all of
  13305. * the `x1`, `x2`, `y1`, `y2` will be assigned in this method.
  13306. * @param {Object} [inputShape]
  13307. * @param {number} [inputShape.x1]
  13308. * @param {number} [inputShape.y1]
  13309. * @param {number} [inputShape.x2]
  13310. * @param {number} [inputShape.y2]
  13311. * @param {Object} [style]
  13312. * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.
  13313. */
  13314. function subPixelOptimizeLine$1(outputShape, inputShape, style) {
  13315. if (!inputShape) {
  13316. return;
  13317. }
  13318. var x1 = inputShape.x1;
  13319. var x2 = inputShape.x2;
  13320. var y1 = inputShape.y1;
  13321. var y2 = inputShape.y2;
  13322. outputShape.x1 = x1;
  13323. outputShape.x2 = x2;
  13324. outputShape.y1 = y1;
  13325. outputShape.y2 = y2;
  13326. var lineWidth = style && style.lineWidth;
  13327. if (!lineWidth) {
  13328. return;
  13329. }
  13330. if (round(x1 * 2) === round(x2 * 2)) {
  13331. outputShape.x1 = outputShape.x2 = subPixelOptimize$1(x1, lineWidth, true);
  13332. }
  13333. if (round(y1 * 2) === round(y2 * 2)) {
  13334. outputShape.y1 = outputShape.y2 = subPixelOptimize$1(y1, lineWidth, true);
  13335. }
  13336. }
  13337. /**
  13338. * Sub pixel optimize rect for canvas
  13339. *
  13340. * @param {Object} outputShape The modification will be performed on `outputShape`.
  13341. * `outputShape` and `inputShape` can be the same object.
  13342. * `outputShape` object can be used repeatly, because all of
  13343. * the `x`, `y`, `width`, `height` will be assigned in this method.
  13344. * @param {Object} [inputShape]
  13345. * @param {number} [inputShape.x]
  13346. * @param {number} [inputShape.y]
  13347. * @param {number} [inputShape.width]
  13348. * @param {number} [inputShape.height]
  13349. * @param {Object} [style]
  13350. * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.
  13351. */
  13352. function subPixelOptimizeRect$1(outputShape, inputShape, style) {
  13353. if (!inputShape) {
  13354. return;
  13355. }
  13356. var originX = inputShape.x;
  13357. var originY = inputShape.y;
  13358. var originWidth = inputShape.width;
  13359. var originHeight = inputShape.height;
  13360. outputShape.x = originX;
  13361. outputShape.y = originY;
  13362. outputShape.width = originWidth;
  13363. outputShape.height = originHeight;
  13364. var lineWidth = style && style.lineWidth;
  13365. if (!lineWidth) {
  13366. return;
  13367. }
  13368. outputShape.x = subPixelOptimize$1(originX, lineWidth, true);
  13369. outputShape.y = subPixelOptimize$1(originY, lineWidth, true);
  13370. outputShape.width = Math.max(subPixelOptimize$1(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  13371. outputShape.height = Math.max(subPixelOptimize$1(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  13372. }
  13373. /**
  13374. * Sub pixel optimize for canvas
  13375. *
  13376. * @param {number} position Coordinate, such as x, y
  13377. * @param {number} lineWidth If `null`/`undefined`/`0`, do not optimize.
  13378. * @param {boolean=} positiveOrNegative Default false (negative).
  13379. * @return {number} Optimized position.
  13380. */
  13381. function subPixelOptimize$1(position, lineWidth, positiveOrNegative) {
  13382. if (!lineWidth) {
  13383. return position;
  13384. } // Assure that (position + lineWidth / 2) is near integer edge,
  13385. // otherwise line will be fuzzy in canvas.
  13386. var doubledPosition = round(position * 2);
  13387. return (doubledPosition + round(lineWidth)) % 2 === 0 ? doubledPosition / 2 : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  13388. }
  13389. /**
  13390. * 矩形
  13391. * @module zrender/graphic/shape/Rect
  13392. */
  13393. // Avoid create repeatly.
  13394. var subPixelOptimizeOutputShape = {};
  13395. var Rect = Path.extend({
  13396. type: 'rect',
  13397. shape: {
  13398. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  13399. // r缩写为1 相当于 [1, 1, 1, 1]
  13400. // r缩写为[1] 相当于 [1, 1, 1, 1]
  13401. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  13402. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  13403. r: 0,
  13404. x: 0,
  13405. y: 0,
  13406. width: 0,
  13407. height: 0
  13408. },
  13409. buildPath: function (ctx, shape) {
  13410. var x;
  13411. var y;
  13412. var width;
  13413. var height;
  13414. if (this.subPixelOptimize) {
  13415. subPixelOptimizeRect$1(subPixelOptimizeOutputShape, shape, this.style);
  13416. x = subPixelOptimizeOutputShape.x;
  13417. y = subPixelOptimizeOutputShape.y;
  13418. width = subPixelOptimizeOutputShape.width;
  13419. height = subPixelOptimizeOutputShape.height;
  13420. subPixelOptimizeOutputShape.r = shape.r;
  13421. shape = subPixelOptimizeOutputShape;
  13422. } else {
  13423. x = shape.x;
  13424. y = shape.y;
  13425. width = shape.width;
  13426. height = shape.height;
  13427. }
  13428. if (!shape.r) {
  13429. ctx.rect(x, y, width, height);
  13430. } else {
  13431. buildPath(ctx, shape);
  13432. }
  13433. ctx.closePath();
  13434. return;
  13435. }
  13436. });
  13437. /**
  13438. * 直线
  13439. * @module zrender/graphic/shape/Line
  13440. */
  13441. // Avoid create repeatly.
  13442. var subPixelOptimizeOutputShape$1 = {};
  13443. var Line = Path.extend({
  13444. type: 'line',
  13445. shape: {
  13446. // Start point
  13447. x1: 0,
  13448. y1: 0,
  13449. // End point
  13450. x2: 0,
  13451. y2: 0,
  13452. percent: 1
  13453. },
  13454. style: {
  13455. stroke: '#000',
  13456. fill: null
  13457. },
  13458. buildPath: function (ctx, shape) {
  13459. var x1;
  13460. var y1;
  13461. var x2;
  13462. var y2;
  13463. if (this.subPixelOptimize) {
  13464. subPixelOptimizeLine$1(subPixelOptimizeOutputShape$1, shape, this.style);
  13465. x1 = subPixelOptimizeOutputShape$1.x1;
  13466. y1 = subPixelOptimizeOutputShape$1.y1;
  13467. x2 = subPixelOptimizeOutputShape$1.x2;
  13468. y2 = subPixelOptimizeOutputShape$1.y2;
  13469. } else {
  13470. x1 = shape.x1;
  13471. y1 = shape.y1;
  13472. x2 = shape.x2;
  13473. y2 = shape.y2;
  13474. }
  13475. var percent = shape.percent;
  13476. if (percent === 0) {
  13477. return;
  13478. }
  13479. ctx.moveTo(x1, y1);
  13480. if (percent < 1) {
  13481. x2 = x1 * (1 - percent) + x2 * percent;
  13482. y2 = y1 * (1 - percent) + y2 * percent;
  13483. }
  13484. ctx.lineTo(x2, y2);
  13485. },
  13486. /**
  13487. * Get point at percent
  13488. * @param {number} percent
  13489. * @return {Array.<number>}
  13490. */
  13491. pointAt: function (p) {
  13492. var shape = this.shape;
  13493. return [shape.x1 * (1 - p) + shape.x2 * p, shape.y1 * (1 - p) + shape.y2 * p];
  13494. }
  13495. });
  13496. /**
  13497. * 贝塞尔曲线
  13498. * @module zrender/shape/BezierCurve
  13499. */
  13500. var out = [];
  13501. function someVectorAt(shape, t, isTangent) {
  13502. var cpx2 = shape.cpx2;
  13503. var cpy2 = shape.cpy2;
  13504. if (cpx2 === null || cpy2 === null) {
  13505. return [(isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t), (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)];
  13506. } else {
  13507. return [(isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t), (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)];
  13508. }
  13509. }
  13510. var BezierCurve = Path.extend({
  13511. type: 'bezier-curve',
  13512. shape: {
  13513. x1: 0,
  13514. y1: 0,
  13515. x2: 0,
  13516. y2: 0,
  13517. cpx1: 0,
  13518. cpy1: 0,
  13519. // cpx2: 0,
  13520. // cpy2: 0
  13521. // Curve show percent, for animating
  13522. percent: 1
  13523. },
  13524. style: {
  13525. stroke: '#000',
  13526. fill: null
  13527. },
  13528. buildPath: function (ctx, shape) {
  13529. var x1 = shape.x1;
  13530. var y1 = shape.y1;
  13531. var x2 = shape.x2;
  13532. var y2 = shape.y2;
  13533. var cpx1 = shape.cpx1;
  13534. var cpy1 = shape.cpy1;
  13535. var cpx2 = shape.cpx2;
  13536. var cpy2 = shape.cpy2;
  13537. var percent = shape.percent;
  13538. if (percent === 0) {
  13539. return;
  13540. }
  13541. ctx.moveTo(x1, y1);
  13542. if (cpx2 == null || cpy2 == null) {
  13543. if (percent < 1) {
  13544. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13545. cpx1 = out[1];
  13546. x2 = out[2];
  13547. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13548. cpy1 = out[1];
  13549. y2 = out[2];
  13550. }
  13551. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13552. } else {
  13553. if (percent < 1) {
  13554. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13555. cpx1 = out[1];
  13556. cpx2 = out[2];
  13557. x2 = out[3];
  13558. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13559. cpy1 = out[1];
  13560. cpy2 = out[2];
  13561. y2 = out[3];
  13562. }
  13563. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13564. }
  13565. },
  13566. /**
  13567. * Get point at percent
  13568. * @param {number} t
  13569. * @return {Array.<number>}
  13570. */
  13571. pointAt: function (t) {
  13572. return someVectorAt(this.shape, t, false);
  13573. },
  13574. /**
  13575. * Get tangent at percent
  13576. * @param {number} t
  13577. * @return {Array.<number>}
  13578. */
  13579. tangentAt: function (t) {
  13580. var p = someVectorAt(this.shape, t, true);
  13581. return normalize(p, p);
  13582. }
  13583. });
  13584. /**
  13585. * 圆弧
  13586. * @module zrender/graphic/shape/Arc
  13587. */
  13588. var Arc = Path.extend({
  13589. type: 'arc',
  13590. shape: {
  13591. cx: 0,
  13592. cy: 0,
  13593. r: 0,
  13594. startAngle: 0,
  13595. endAngle: Math.PI * 2,
  13596. clockwise: true
  13597. },
  13598. style: {
  13599. stroke: '#000',
  13600. fill: null
  13601. },
  13602. buildPath: function (ctx, shape) {
  13603. var x = shape.cx;
  13604. var y = shape.cy;
  13605. var r = Math.max(shape.r, 0);
  13606. var startAngle = shape.startAngle;
  13607. var endAngle = shape.endAngle;
  13608. var clockwise = shape.clockwise;
  13609. var unitX = Math.cos(startAngle);
  13610. var unitY = Math.sin(startAngle);
  13611. ctx.moveTo(unitX * r + x, unitY * r + y);
  13612. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13613. }
  13614. }); // CompoundPath to improve performance
  13615. var CompoundPath = Path.extend({
  13616. type: 'compound',
  13617. shape: {
  13618. paths: null
  13619. },
  13620. _updatePathDirty: function () {
  13621. var dirtyPath = this.__dirtyPath;
  13622. var paths = this.shape.paths;
  13623. for (var i = 0; i < paths.length; i++) {
  13624. // Mark as dirty if any subpath is dirty
  13625. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  13626. }
  13627. this.__dirtyPath = dirtyPath;
  13628. this.__dirty = this.__dirty || dirtyPath;
  13629. },
  13630. beforeBrush: function () {
  13631. this._updatePathDirty();
  13632. var paths = this.shape.paths || [];
  13633. var scale = this.getGlobalScale(); // Update path scale
  13634. for (var i = 0; i < paths.length; i++) {
  13635. if (!paths[i].path) {
  13636. paths[i].createPathProxy();
  13637. }
  13638. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  13639. }
  13640. },
  13641. buildPath: function (ctx, shape) {
  13642. var paths = shape.paths || [];
  13643. for (var i = 0; i < paths.length; i++) {
  13644. paths[i].buildPath(ctx, paths[i].shape, true);
  13645. }
  13646. },
  13647. afterBrush: function () {
  13648. var paths = this.shape.paths || [];
  13649. for (var i = 0; i < paths.length; i++) {
  13650. paths[i].__dirtyPath = false;
  13651. }
  13652. },
  13653. getBoundingRect: function () {
  13654. this._updatePathDirty();
  13655. return Path.prototype.getBoundingRect.call(this);
  13656. }
  13657. });
  13658. /**
  13659. * @param {Array.<Object>} colorStops
  13660. */
  13661. var Gradient = function (colorStops) {
  13662. this.colorStops = colorStops || [];
  13663. };
  13664. Gradient.prototype = {
  13665. constructor: Gradient,
  13666. addColorStop: function (offset, color) {
  13667. this.colorStops.push({
  13668. offset: offset,
  13669. color: color
  13670. });
  13671. }
  13672. };
  13673. /**
  13674. * x, y, x2, y2 are all percent from 0 to 1
  13675. * @param {number} [x=0]
  13676. * @param {number} [y=0]
  13677. * @param {number} [x2=1]
  13678. * @param {number} [y2=0]
  13679. * @param {Array.<Object>} colorStops
  13680. * @param {boolean} [globalCoord=false]
  13681. */
  13682. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  13683. // Should do nothing more in this constructor. Because gradient can be
  13684. // declard by `color: {type: 'linear', colorStops: ...}`, where
  13685. // this constructor will not be called.
  13686. this.x = x == null ? 0 : x;
  13687. this.y = y == null ? 0 : y;
  13688. this.x2 = x2 == null ? 1 : x2;
  13689. this.y2 = y2 == null ? 0 : y2; // Can be cloned
  13690. this.type = 'linear'; // If use global coord
  13691. this.global = globalCoord || false;
  13692. Gradient.call(this, colorStops);
  13693. };
  13694. LinearGradient.prototype = {
  13695. constructor: LinearGradient
  13696. };
  13697. inherits(LinearGradient, Gradient);
  13698. /**
  13699. * x, y, r are all percent from 0 to 1
  13700. * @param {number} [x=0.5]
  13701. * @param {number} [y=0.5]
  13702. * @param {number} [r=0.5]
  13703. * @param {Array.<Object>} [colorStops]
  13704. * @param {boolean} [globalCoord=false]
  13705. */
  13706. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  13707. // Should do nothing more in this constructor. Because gradient can be
  13708. // declard by `color: {type: 'radial', colorStops: ...}`, where
  13709. // this constructor will not be called.
  13710. this.x = x == null ? 0.5 : x;
  13711. this.y = y == null ? 0.5 : y;
  13712. this.r = r == null ? 0.5 : r; // Can be cloned
  13713. this.type = 'radial'; // If use global coord
  13714. this.global = globalCoord || false;
  13715. Gradient.call(this, colorStops);
  13716. };
  13717. RadialGradient.prototype = {
  13718. constructor: RadialGradient
  13719. };
  13720. inherits(RadialGradient, Gradient);
  13721. /**
  13722. * Displayable for incremental rendering. It will be rendered in a separate layer
  13723. * IncrementalDisplay have two main methods. `clearDisplayables` and `addDisplayables`
  13724. * addDisplayables will render the added displayables incremetally.
  13725. *
  13726. * It use a not clearFlag to tell the painter don't clear the layer if it's the first element.
  13727. */
  13728. // TODO Style override ?
  13729. function IncrementalDisplayble(opts) {
  13730. Displayable.call(this, opts);
  13731. this._displayables = [];
  13732. this._temporaryDisplayables = [];
  13733. this._cursor = 0;
  13734. this.notClear = true;
  13735. }
  13736. IncrementalDisplayble.prototype.incremental = true;
  13737. IncrementalDisplayble.prototype.clearDisplaybles = function () {
  13738. this._displayables = [];
  13739. this._temporaryDisplayables = [];
  13740. this._cursor = 0;
  13741. this.dirty();
  13742. this.notClear = false;
  13743. };
  13744. IncrementalDisplayble.prototype.addDisplayable = function (displayable, notPersistent) {
  13745. if (notPersistent) {
  13746. this._temporaryDisplayables.push(displayable);
  13747. } else {
  13748. this._displayables.push(displayable);
  13749. }
  13750. this.dirty();
  13751. };
  13752. IncrementalDisplayble.prototype.addDisplayables = function (displayables, notPersistent) {
  13753. notPersistent = notPersistent || false;
  13754. for (var i = 0; i < displayables.length; i++) {
  13755. this.addDisplayable(displayables[i], notPersistent);
  13756. }
  13757. };
  13758. IncrementalDisplayble.prototype.eachPendingDisplayable = function (cb) {
  13759. for (var i = this._cursor; i < this._displayables.length; i++) {
  13760. cb && cb(this._displayables[i]);
  13761. }
  13762. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13763. cb && cb(this._temporaryDisplayables[i]);
  13764. }
  13765. };
  13766. IncrementalDisplayble.prototype.update = function () {
  13767. this.updateTransform();
  13768. for (var i = this._cursor; i < this._displayables.length; i++) {
  13769. var displayable = this._displayables[i]; // PENDING
  13770. displayable.parent = this;
  13771. displayable.update();
  13772. displayable.parent = null;
  13773. }
  13774. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13775. var displayable = this._temporaryDisplayables[i]; // PENDING
  13776. displayable.parent = this;
  13777. displayable.update();
  13778. displayable.parent = null;
  13779. }
  13780. };
  13781. IncrementalDisplayble.prototype.brush = function (ctx, prevEl) {
  13782. // Render persistant displayables.
  13783. for (var i = this._cursor; i < this._displayables.length; i++) {
  13784. var displayable = this._displayables[i];
  13785. displayable.beforeBrush && displayable.beforeBrush(ctx);
  13786. displayable.brush(ctx, i === this._cursor ? null : this._displayables[i - 1]);
  13787. displayable.afterBrush && displayable.afterBrush(ctx);
  13788. }
  13789. this._cursor = i; // Render temporary displayables.
  13790. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13791. var displayable = this._temporaryDisplayables[i];
  13792. displayable.beforeBrush && displayable.beforeBrush(ctx);
  13793. displayable.brush(ctx, i === 0 ? null : this._temporaryDisplayables[i - 1]);
  13794. displayable.afterBrush && displayable.afterBrush(ctx);
  13795. }
  13796. this._temporaryDisplayables = [];
  13797. this.notClear = true;
  13798. };
  13799. var m = [];
  13800. IncrementalDisplayble.prototype.getBoundingRect = function () {
  13801. if (!this._rect) {
  13802. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  13803. for (var i = 0; i < this._displayables.length; i++) {
  13804. var displayable = this._displayables[i];
  13805. var childRect = displayable.getBoundingRect().clone();
  13806. if (displayable.needLocalTransform()) {
  13807. childRect.applyTransform(displayable.getLocalTransform(m));
  13808. }
  13809. rect.union(childRect);
  13810. }
  13811. this._rect = rect;
  13812. }
  13813. return this._rect;
  13814. };
  13815. IncrementalDisplayble.prototype.contain = function (x, y) {
  13816. var localPos = this.transformCoordToLocal(x, y);
  13817. var rect = this.getBoundingRect();
  13818. if (rect.contain(localPos[0], localPos[1])) {
  13819. for (var i = 0; i < this._displayables.length; i++) {
  13820. var displayable = this._displayables[i];
  13821. if (displayable.contain(x, y)) {
  13822. return true;
  13823. }
  13824. }
  13825. }
  13826. return false;
  13827. };
  13828. inherits(IncrementalDisplayble, Displayable);
  13829. /*
  13830. * Licensed to the Apache Software Foundation (ASF) under one
  13831. * or more contributor license agreements. See the NOTICE file
  13832. * distributed with this work for additional information
  13833. * regarding copyright ownership. The ASF licenses this file
  13834. * to you under the Apache License, Version 2.0 (the
  13835. * "License"); you may not use this file except in compliance
  13836. * with the License. You may obtain a copy of the License at
  13837. *
  13838. * http://www.apache.org/licenses/LICENSE-2.0
  13839. *
  13840. * Unless required by applicable law or agreed to in writing,
  13841. * software distributed under the License is distributed on an
  13842. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13843. * KIND, either express or implied. See the License for the
  13844. * specific language governing permissions and limitations
  13845. * under the License.
  13846. */
  13847. var mathMax$1 = Math.max;
  13848. var mathMin$1 = Math.min;
  13849. var EMPTY_OBJ = {};
  13850. var Z2_EMPHASIS_LIFT = 1; // key: label model property nane, value: style property name.
  13851. var CACHED_LABEL_STYLE_PROPERTIES = {
  13852. color: 'textFill',
  13853. textBorderColor: 'textStroke',
  13854. textBorderWidth: 'textStrokeWidth'
  13855. };
  13856. var EMPHASIS = 'emphasis';
  13857. var NORMAL = 'normal'; // Reserve 0 as default.
  13858. var _highlightNextDigit = 1;
  13859. var _highlightKeyMap = {};
  13860. var _customShapeMap = {};
  13861. /**
  13862. * Extend shape with parameters
  13863. */
  13864. function extendShape(opts) {
  13865. return Path.extend(opts);
  13866. }
  13867. /**
  13868. * Extend path
  13869. */
  13870. function extendPath(pathData, opts) {
  13871. return extendFromString(pathData, opts);
  13872. }
  13873. /**
  13874. * Register a user defined shape.
  13875. * The shape class can be fetched by `getShapeClass`
  13876. * This method will overwrite the registered shapes, including
  13877. * the registered built-in shapes, if using the same `name`.
  13878. * The shape can be used in `custom series` and
  13879. * `graphic component` by declaring `{type: name}`.
  13880. *
  13881. * @param {string} name
  13882. * @param {Object} ShapeClass Can be generated by `extendShape`.
  13883. */
  13884. function registerShape(name, ShapeClass) {
  13885. _customShapeMap[name] = ShapeClass;
  13886. }
  13887. /**
  13888. * Find shape class registered by `registerShape`. Usually used in
  13889. * fetching user defined shape.
  13890. *
  13891. * [Caution]:
  13892. * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared
  13893. * to use user registered shapes.
  13894. * Because the built-in shape (see `getBuiltInShape`) will be registered by
  13895. * `registerShape` by default. That enables users to get both built-in
  13896. * shapes as well as the shapes belonging to themsleves. But users can overwrite
  13897. * the built-in shapes by using names like 'circle', 'rect' via calling
  13898. * `registerShape`. So the echarts inner featrues should not fetch shapes from here
  13899. * in case that it is overwritten by users, except that some features, like
  13900. * `custom series`, `graphic component`, do it deliberately.
  13901. *
  13902. * (2) In the features like `custom series`, `graphic component`, the user input
  13903. * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic
  13904. * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names
  13905. * are reserved names, that is, if some user register a shape named `'image'`,
  13906. * the shape will not be used. If we intending to add some more reserved names
  13907. * in feature, that might bring break changes (disable some existing user shape
  13908. * names). But that case probably rearly happen. So we dont make more mechanism
  13909. * to resolve this issue here.
  13910. *
  13911. * @param {string} name
  13912. * @return {Object} The shape class. If not found, return nothing.
  13913. */
  13914. function getShapeClass(name) {
  13915. if (_customShapeMap.hasOwnProperty(name)) {
  13916. return _customShapeMap[name];
  13917. }
  13918. }
  13919. /**
  13920. * Create a path element from path data string
  13921. * @param {string} pathData
  13922. * @param {Object} opts
  13923. * @param {module:zrender/core/BoundingRect} rect
  13924. * @param {string} [layout=cover] 'center' or 'cover'
  13925. */
  13926. function makePath(pathData, opts, rect, layout) {
  13927. var path = createFromString(pathData, opts);
  13928. if (rect) {
  13929. if (layout === 'center') {
  13930. rect = centerGraphic(rect, path.getBoundingRect());
  13931. }
  13932. resizePath(path, rect);
  13933. }
  13934. return path;
  13935. }
  13936. /**
  13937. * Create a image element from image url
  13938. * @param {string} imageUrl image url
  13939. * @param {Object} opts options
  13940. * @param {module:zrender/core/BoundingRect} rect constrain rect
  13941. * @param {string} [layout=cover] 'center' or 'cover'
  13942. */
  13943. function makeImage(imageUrl, rect, layout) {
  13944. var path = new ZImage({
  13945. style: {
  13946. image: imageUrl,
  13947. x: rect.x,
  13948. y: rect.y,
  13949. width: rect.width,
  13950. height: rect.height
  13951. },
  13952. onload: function (img) {
  13953. if (layout === 'center') {
  13954. var boundingRect = {
  13955. width: img.width,
  13956. height: img.height
  13957. };
  13958. path.setStyle(centerGraphic(rect, boundingRect));
  13959. }
  13960. }
  13961. });
  13962. return path;
  13963. }
  13964. /**
  13965. * Get position of centered element in bounding box.
  13966. *
  13967. * @param {Object} rect element local bounding box
  13968. * @param {Object} boundingRect constraint bounding box
  13969. * @return {Object} element position containing x, y, width, and height
  13970. */
  13971. function centerGraphic(rect, boundingRect) {
  13972. // Set rect to center, keep width / height ratio.
  13973. var aspect = boundingRect.width / boundingRect.height;
  13974. var width = rect.height * aspect;
  13975. var height;
  13976. if (width <= rect.width) {
  13977. height = rect.height;
  13978. } else {
  13979. width = rect.width;
  13980. height = width / aspect;
  13981. }
  13982. var cx = rect.x + rect.width / 2;
  13983. var cy = rect.y + rect.height / 2;
  13984. return {
  13985. x: cx - width / 2,
  13986. y: cy - height / 2,
  13987. width: width,
  13988. height: height
  13989. };
  13990. }
  13991. var mergePath = mergePath$1;
  13992. /**
  13993. * Resize a path to fit the rect
  13994. * @param {module:zrender/graphic/Path} path
  13995. * @param {Object} rect
  13996. */
  13997. function resizePath(path, rect) {
  13998. if (!path.applyTransform) {
  13999. return;
  14000. }
  14001. var pathRect = path.getBoundingRect();
  14002. var m = pathRect.calculateTransform(rect);
  14003. path.applyTransform(m);
  14004. }
  14005. /**
  14006. * Sub pixel optimize line for canvas
  14007. *
  14008. * @param {Object} param
  14009. * @param {Object} [param.shape]
  14010. * @param {number} [param.shape.x1]
  14011. * @param {number} [param.shape.y1]
  14012. * @param {number} [param.shape.x2]
  14013. * @param {number} [param.shape.y2]
  14014. * @param {Object} [param.style]
  14015. * @param {number} [param.style.lineWidth]
  14016. * @return {Object} Modified param
  14017. */
  14018. function subPixelOptimizeLine(param) {
  14019. subPixelOptimizeLine$1(param.shape, param.shape, param.style);
  14020. return param;
  14021. }
  14022. /**
  14023. * Sub pixel optimize rect for canvas
  14024. *
  14025. * @param {Object} param
  14026. * @param {Object} [param.shape]
  14027. * @param {number} [param.shape.x]
  14028. * @param {number} [param.shape.y]
  14029. * @param {number} [param.shape.width]
  14030. * @param {number} [param.shape.height]
  14031. * @param {Object} [param.style]
  14032. * @param {number} [param.style.lineWidth]
  14033. * @return {Object} Modified param
  14034. */
  14035. function subPixelOptimizeRect(param) {
  14036. subPixelOptimizeRect$1(param.shape, param.shape, param.style);
  14037. return param;
  14038. }
  14039. /**
  14040. * Sub pixel optimize for canvas
  14041. *
  14042. * @param {number} position Coordinate, such as x, y
  14043. * @param {number} lineWidth Should be nonnegative integer.
  14044. * @param {boolean=} positiveOrNegative Default false (negative).
  14045. * @return {number} Optimized position.
  14046. */
  14047. var subPixelOptimize = subPixelOptimize$1;
  14048. function hasFillOrStroke(fillOrStroke) {
  14049. return fillOrStroke != null && fillOrStroke !== 'none';
  14050. } // Most lifted color are duplicated.
  14051. var liftedColorMap = createHashMap();
  14052. var liftedColorCount = 0;
  14053. function liftColor(color) {
  14054. if (typeof color !== 'string') {
  14055. return color;
  14056. }
  14057. var liftedColor = liftedColorMap.get(color);
  14058. if (!liftedColor) {
  14059. liftedColor = lift(color, -0.1);
  14060. if (liftedColorCount < 10000) {
  14061. liftedColorMap.set(color, liftedColor);
  14062. liftedColorCount++;
  14063. }
  14064. }
  14065. return liftedColor;
  14066. }
  14067. function cacheElementStl(el) {
  14068. if (!el.__hoverStlDirty) {
  14069. return;
  14070. }
  14071. el.__hoverStlDirty = false;
  14072. var hoverStyle = el.__hoverStl;
  14073. if (!hoverStyle) {
  14074. el.__cachedNormalStl = el.__cachedNormalZ2 = null;
  14075. return;
  14076. }
  14077. var normalStyle = el.__cachedNormalStl = {};
  14078. el.__cachedNormalZ2 = el.z2;
  14079. var elStyle = el.style;
  14080. for (var name in hoverStyle) {
  14081. // See comment in `singleEnterEmphasis`.
  14082. if (hoverStyle[name] != null) {
  14083. normalStyle[name] = elStyle[name];
  14084. }
  14085. } // Always cache fill and stroke to normalStyle for lifting color.
  14086. normalStyle.fill = elStyle.fill;
  14087. normalStyle.stroke = elStyle.stroke;
  14088. }
  14089. function singleEnterEmphasis(el) {
  14090. var hoverStl = el.__hoverStl;
  14091. if (!hoverStl || el.__highlighted) {
  14092. return;
  14093. }
  14094. var zr = el.__zr;
  14095. var useHoverLayer = el.useHoverLayer && zr && zr.painter.type === 'canvas';
  14096. el.__highlighted = useHoverLayer ? 'layer' : 'plain';
  14097. if (el.isGroup || !zr && el.useHoverLayer) {
  14098. return;
  14099. }
  14100. var elTarget = el;
  14101. var targetStyle = el.style;
  14102. if (useHoverLayer) {
  14103. elTarget = zr.addHover(el);
  14104. targetStyle = elTarget.style;
  14105. }
  14106. rollbackDefaultTextStyle(targetStyle);
  14107. if (!useHoverLayer) {
  14108. cacheElementStl(elTarget);
  14109. } // styles can be:
  14110. // {
  14111. // label: {
  14112. // show: false,
  14113. // position: 'outside',
  14114. // fontSize: 18
  14115. // },
  14116. // emphasis: {
  14117. // label: {
  14118. // show: true
  14119. // }
  14120. // }
  14121. // },
  14122. // where properties of `emphasis` may not appear in `normal`. We previously use
  14123. // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.
  14124. // But consider rich text and setOption in merge mode, it is impossible to cover
  14125. // all properties in merge. So we use merge mode when setting style here.
  14126. // But we choose the merge strategy that only properties that is not `null/undefined`.
  14127. // Because when making a textStyle (espacially rich text), it is not easy to distinguish
  14128. // `hasOwnProperty` and `null/undefined` in code, so we trade them as the same for simplicity.
  14129. // But this strategy brings a trouble that `null/undefined` can not be used to remove
  14130. // style any more in `emphasis`. Users can both set properties directly on normal and
  14131. // emphasis to avoid this issue, or we might support `'none'` for this case if required.
  14132. targetStyle.extendFrom(hoverStl);
  14133. setDefaultHoverFillStroke(targetStyle, hoverStl, 'fill');
  14134. setDefaultHoverFillStroke(targetStyle, hoverStl, 'stroke');
  14135. applyDefaultTextStyle(targetStyle);
  14136. if (!useHoverLayer) {
  14137. el.dirty(false);
  14138. el.z2 += Z2_EMPHASIS_LIFT;
  14139. }
  14140. }
  14141. function setDefaultHoverFillStroke(targetStyle, hoverStyle, prop) {
  14142. if (!hasFillOrStroke(hoverStyle[prop]) && hasFillOrStroke(targetStyle[prop])) {
  14143. targetStyle[prop] = liftColor(targetStyle[prop]);
  14144. }
  14145. }
  14146. function singleEnterNormal(el) {
  14147. var highlighted = el.__highlighted;
  14148. if (!highlighted) {
  14149. return;
  14150. }
  14151. el.__highlighted = false;
  14152. if (el.isGroup) {
  14153. return;
  14154. }
  14155. if (highlighted === 'layer') {
  14156. el.__zr && el.__zr.removeHover(el);
  14157. } else {
  14158. var style = el.style;
  14159. var normalStl = el.__cachedNormalStl;
  14160. if (normalStl) {
  14161. rollbackDefaultTextStyle(style);
  14162. el.setStyle(normalStl);
  14163. applyDefaultTextStyle(style);
  14164. } // `__cachedNormalZ2` will not be reset if calling `setElementHoverStyle`
  14165. // when `el` is on emphasis state. So here by comparing with 1, we try
  14166. // hard to make the bug case rare.
  14167. var normalZ2 = el.__cachedNormalZ2;
  14168. if (normalZ2 != null && el.z2 - normalZ2 === Z2_EMPHASIS_LIFT) {
  14169. el.z2 = normalZ2;
  14170. }
  14171. }
  14172. }
  14173. function traverseUpdate(el, updater, commonParam) {
  14174. // If root is group, also enter updater for `highDownOnUpdate`.
  14175. var fromState = NORMAL;
  14176. var toState = NORMAL;
  14177. var trigger; // See the rule of `highDownOnUpdate` on `graphic.setAsHighDownDispatcher`.
  14178. el.__highlighted && (fromState = EMPHASIS, trigger = true);
  14179. updater(el, commonParam);
  14180. el.__highlighted && (toState = EMPHASIS, trigger = true);
  14181. el.isGroup && el.traverse(function (child) {
  14182. !child.isGroup && updater(child, commonParam);
  14183. });
  14184. trigger && el.__highDownOnUpdate && el.__highDownOnUpdate(fromState, toState);
  14185. }
  14186. /**
  14187. * Set hover style (namely "emphasis style") of element, based on the current
  14188. * style of the given `el`.
  14189. * This method should be called after all of the normal styles have been adopted
  14190. * to the `el`. See the reason on `setHoverStyle`.
  14191. *
  14192. * @param {module:zrender/Element} el Should not be `zrender/container/Group`.
  14193. * @param {Object} [el.hoverStyle] Can be set on el or its descendants,
  14194. * e.g., `el.hoverStyle = ...; graphic.setHoverStyle(el); `.
  14195. * Often used when item group has a label element and it's hoverStyle is different.
  14196. * @param {Object|boolean} [hoverStl] The specified hover style.
  14197. * If set as `false`, disable the hover style.
  14198. * Similarly, The `el.hoverStyle` can alse be set
  14199. * as `false` to disable the hover style.
  14200. * Otherwise, use the default hover style if not provided.
  14201. */
  14202. function setElementHoverStyle(el, hoverStl) {
  14203. // For performance consideration, it might be better to make the "hover style" only the
  14204. // difference properties from the "normal style", but not a entire copy of all styles.
  14205. hoverStl = el.__hoverStl = hoverStl !== false && (el.hoverStyle || hoverStl || {});
  14206. el.__hoverStlDirty = true; // FIXME
  14207. // It is not completely right to save "normal"/"emphasis" flag on elements.
  14208. // It probably should be saved on `data` of series. Consider the cases:
  14209. // (1) A highlighted elements are moved out of the view port and re-enter
  14210. // again by dataZoom.
  14211. // (2) call `setOption` and replace elements totally when they are highlighted.
  14212. if (el.__highlighted) {
  14213. // Consider the case:
  14214. // The styles of a highlighted `el` is being updated. The new "emphasis style"
  14215. // should be adapted to the `el`. Notice here new "normal styles" should have
  14216. // been set outside and the cached "normal style" is out of date.
  14217. el.__cachedNormalStl = null; // Do not clear `__cachedNormalZ2` here, because setting `z2` is not a constraint
  14218. // of this method. In most cases, `z2` is not set and hover style should be able
  14219. // to rollback. Of course, that would bring bug, but only in a rare case, see
  14220. // `doSingleLeaveHover` for details.
  14221. singleEnterNormal(el);
  14222. singleEnterEmphasis(el);
  14223. }
  14224. }
  14225. function onElementMouseOver(e) {
  14226. !shouldSilent(this, e) // "emphasis" event highlight has higher priority than mouse highlight.
  14227. && !this.__highByOuter && traverseUpdate(this, singleEnterEmphasis);
  14228. }
  14229. function onElementMouseOut(e) {
  14230. !shouldSilent(this, e) // "emphasis" event highlight has higher priority than mouse highlight.
  14231. && !this.__highByOuter && traverseUpdate(this, singleEnterNormal);
  14232. }
  14233. function onElementEmphasisEvent(highlightDigit) {
  14234. this.__highByOuter |= 1 << (highlightDigit || 0);
  14235. traverseUpdate(this, singleEnterEmphasis);
  14236. }
  14237. function onElementNormalEvent(highlightDigit) {
  14238. !(this.__highByOuter &= ~(1 << (highlightDigit || 0))) && traverseUpdate(this, singleEnterNormal);
  14239. }
  14240. function shouldSilent(el, e) {
  14241. return el.__highDownSilentOnTouch && e.zrByTouch;
  14242. }
  14243. /**
  14244. * Set hover style (namely "emphasis style") of element,
  14245. * based on the current style of the given `el`.
  14246. *
  14247. * (1)
  14248. * **CONSTRAINTS** for this method:
  14249. * <A> This method MUST be called after all of the normal styles having been adopted
  14250. * to the `el`.
  14251. * <B> The input `hoverStyle` (that is, "emphasis style") MUST be the subset of the
  14252. * "normal style" having been set to the el.
  14253. * <C> `color` MUST be one of the "normal styles" (because color might be lifted as
  14254. * a default hover style).
  14255. *
  14256. * The reason: this method treat the current style of the `el` as the "normal style"
  14257. * and cache them when enter/update the "emphasis style". Consider the case: the `el`
  14258. * is in "emphasis" state and `setOption`/`dispatchAction` trigger the style updating
  14259. * logic, where the el should shift from the original emphasis style to the new
  14260. * "emphasis style" and should be able to "downplay" back to the new "normal style".
  14261. *
  14262. * Indeed, it is error-prone to make a interface has so many constraints, but I have
  14263. * not found a better solution yet to fit the backward compatibility, performance and
  14264. * the current programming style.
  14265. *
  14266. * (2)
  14267. * Call the method for a "root" element once. Do not call it for each descendants.
  14268. * If the descendants elemenets of a group has itself hover style different from the
  14269. * root group, we can simply mount the style on `el.hoverStyle` for them, but should
  14270. * not call this method for them.
  14271. *
  14272. * (3) These input parameters can be set directly on `el`:
  14273. *
  14274. * @param {module:zrender/Element} el
  14275. * @param {Object} [el.hoverStyle] See `graphic.setElementHoverStyle`.
  14276. * @param {boolean} [el.highDownSilentOnTouch=false] See `graphic.setAsHighDownDispatcher`.
  14277. * @param {Function} [el.highDownOnUpdate] See `graphic.setAsHighDownDispatcher`.
  14278. * @param {Object|boolean} [hoverStyle] See `graphic.setElementHoverStyle`.
  14279. */
  14280. function setHoverStyle(el, hoverStyle) {
  14281. setAsHighDownDispatcher(el, true);
  14282. traverseUpdate(el, setElementHoverStyle, hoverStyle);
  14283. }
  14284. /**
  14285. * @param {module:zrender/Element} el
  14286. * @param {Function} [el.highDownOnUpdate] Called when state updated.
  14287. * Since `setHoverStyle` has the constraint that it must be called after
  14288. * all of the normal style updated, `highDownOnUpdate` is not needed to
  14289. * trigger if both `fromState` and `toState` is 'normal', and needed to
  14290. * trigger if both `fromState` and `toState` is 'emphasis', which enables
  14291. * to sync outside style settings to "emphasis" state.
  14292. * @this {string} This dispatcher `el`.
  14293. * @param {string} fromState Can be "normal" or "emphasis".
  14294. * `fromState` might equal to `toState`,
  14295. * for example, when this method is called when `el` is
  14296. * on "emphasis" state.
  14297. * @param {string} toState Can be "normal" or "emphasis".
  14298. *
  14299. * FIXME
  14300. * CAUTION: Do not expose `highDownOnUpdate` outside echarts.
  14301. * Because it is not a complete solution. The update
  14302. * listener should not have been mount in element,
  14303. * and the normal/emphasis state should not have
  14304. * mantained on elements.
  14305. *
  14306. * @param {boolean} [el.highDownSilentOnTouch=false]
  14307. * In touch device, mouseover event will be trigger on touchstart event
  14308. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  14309. * conveniently use hoverStyle when tap on touch screen without additional
  14310. * code for compatibility.
  14311. * But if the chart/component has select feature, which usually also use
  14312. * hoverStyle, there might be conflict between 'select-highlight' and
  14313. * 'hover-highlight' especially when roam is enabled (see geo for example).
  14314. * In this case, `highDownSilentOnTouch` should be used to disable
  14315. * hover-highlight on touch device.
  14316. * @param {boolean} [asDispatcher=true] If `false`, do not set as "highDownDispatcher".
  14317. */
  14318. function setAsHighDownDispatcher(el, asDispatcher) {
  14319. var disable = asDispatcher === false; // Make `highDownSilentOnTouch` and `highDownOnUpdate` only work after
  14320. // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.
  14321. el.__highDownSilentOnTouch = el.highDownSilentOnTouch;
  14322. el.__highDownOnUpdate = el.highDownOnUpdate; // Simple optimize, since this method might be
  14323. // called for each elements of a group in some cases.
  14324. if (!disable || el.__highDownDispatcher) {
  14325. var method = disable ? 'off' : 'on'; // Duplicated function will be auto-ignored, see Eventful.js.
  14326. el[method]('mouseover', onElementMouseOver)[method]('mouseout', onElementMouseOut); // Emphasis, normal can be triggered manually by API or other components like hover link.
  14327. el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent); // Also keep previous record.
  14328. el.__highByOuter = el.__highByOuter || 0;
  14329. el.__highDownDispatcher = !disable;
  14330. }
  14331. }
  14332. /**
  14333. * @param {module:zrender/src/Element} el
  14334. * @return {boolean}
  14335. */
  14336. function isHighDownDispatcher(el) {
  14337. return !!(el && el.__highDownDispatcher);
  14338. }
  14339. /**
  14340. * Support hightlight/downplay record on each elements.
  14341. * For the case: hover highlight/downplay (legend, visualMap, ...) and
  14342. * user triggerred hightlight/downplay should not conflict.
  14343. * Only all of the highlightDigit cleared, return to normal.
  14344. * @param {string} highlightKey
  14345. * @return {number} highlightDigit
  14346. */
  14347. function getHighlightDigit(highlightKey) {
  14348. var highlightDigit = _highlightKeyMap[highlightKey];
  14349. if (highlightDigit == null && _highlightNextDigit <= 32) {
  14350. highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;
  14351. }
  14352. return highlightDigit;
  14353. }
  14354. /**
  14355. * See more info in `setTextStyleCommon`.
  14356. * @param {Object|module:zrender/graphic/Style} normalStyle
  14357. * @param {Object} emphasisStyle
  14358. * @param {module:echarts/model/Model} normalModel
  14359. * @param {module:echarts/model/Model} emphasisModel
  14360. * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.
  14361. * @param {string|Function} [opt.defaultText]
  14362. * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by
  14363. * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14364. * @param {number} [opt.labelDataIndex] Fetch text by
  14365. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14366. * @param {number} [opt.labelDimIndex] Fetch text by
  14367. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14368. * @param {string} [opt.labelProp] Fetch text by
  14369. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14370. * @param {Object} [normalSpecified]
  14371. * @param {Object} [emphasisSpecified]
  14372. */
  14373. function setLabelStyle(normalStyle, emphasisStyle, normalModel, emphasisModel, opt, normalSpecified, emphasisSpecified) {
  14374. opt = opt || EMPTY_OBJ;
  14375. var labelFetcher = opt.labelFetcher;
  14376. var labelDataIndex = opt.labelDataIndex;
  14377. var labelDimIndex = opt.labelDimIndex;
  14378. var labelProp = opt.labelProp; // This scenario, `label.normal.show = true; label.emphasis.show = false`,
  14379. // is not supported util someone requests.
  14380. var showNormal = normalModel.getShallow('show');
  14381. var showEmphasis = emphasisModel.getShallow('show'); // Consider performance, only fetch label when necessary.
  14382. // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,
  14383. // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.
  14384. var baseText;
  14385. if (showNormal || showEmphasis) {
  14386. if (labelFetcher) {
  14387. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, labelProp);
  14388. }
  14389. if (baseText == null) {
  14390. baseText = isFunction$1(opt.defaultText) ? opt.defaultText(labelDataIndex, opt) : opt.defaultText;
  14391. }
  14392. }
  14393. var normalStyleText = showNormal ? baseText : null;
  14394. var emphasisStyleText = showEmphasis ? retrieve2(labelFetcher ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex, labelProp) : null, baseText) : null; // Optimize: If style.text is null, text will not be drawn.
  14395. if (normalStyleText != null || emphasisStyleText != null) {
  14396. // Always set `textStyle` even if `normalStyle.text` is null, because default
  14397. // values have to be set on `normalStyle`.
  14398. // If we set default values on `emphasisStyle`, consider case:
  14399. // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`
  14400. // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`
  14401. // Then the 'red' will not work on emphasis.
  14402. setTextStyle(normalStyle, normalModel, normalSpecified, opt);
  14403. setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);
  14404. }
  14405. normalStyle.text = normalStyleText;
  14406. emphasisStyle.text = emphasisStyleText;
  14407. }
  14408. /**
  14409. * Modify label style manually.
  14410. * Only works after `setLabelStyle` and `setElementHoverStyle` called.
  14411. *
  14412. * @param {module:zrender/src/Element} el
  14413. * @param {Object} [normalStyleProps] optional
  14414. * @param {Object} [emphasisStyleProps] optional
  14415. */
  14416. function modifyLabelStyle(el, normalStyleProps, emphasisStyleProps) {
  14417. var elStyle = el.style;
  14418. if (normalStyleProps) {
  14419. rollbackDefaultTextStyle(elStyle);
  14420. el.setStyle(normalStyleProps);
  14421. applyDefaultTextStyle(elStyle);
  14422. }
  14423. elStyle = el.__hoverStl;
  14424. if (emphasisStyleProps && elStyle) {
  14425. rollbackDefaultTextStyle(elStyle);
  14426. extend(elStyle, emphasisStyleProps);
  14427. applyDefaultTextStyle(elStyle);
  14428. }
  14429. }
  14430. /**
  14431. * Set basic textStyle properties.
  14432. * See more info in `setTextStyleCommon`.
  14433. * @param {Object|module:zrender/graphic/Style} textStyle
  14434. * @param {module:echarts/model/Model} model
  14435. * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.
  14436. * @param {Object} [opt] See `opt` of `setTextStyleCommon`.
  14437. * @param {boolean} [isEmphasis]
  14438. */
  14439. function setTextStyle(textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis) {
  14440. setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);
  14441. specifiedTextStyle && extend(textStyle, specifiedTextStyle); // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14442. return textStyle;
  14443. }
  14444. /**
  14445. * Set text option in the style.
  14446. * See more info in `setTextStyleCommon`.
  14447. * @deprecated
  14448. * @param {Object} textStyle
  14449. * @param {module:echarts/model/Model} labelModel
  14450. * @param {string|boolean} defaultColor Default text color.
  14451. * If set as false, it will be processed as a emphasis style.
  14452. */
  14453. function setText(textStyle, labelModel, defaultColor) {
  14454. var opt = {
  14455. isRectText: true
  14456. };
  14457. var isEmphasis;
  14458. if (defaultColor === false) {
  14459. isEmphasis = true;
  14460. } else {
  14461. // Support setting color as 'auto' to get visual color.
  14462. opt.autoColor = defaultColor;
  14463. }
  14464. setTextStyleCommon(textStyle, labelModel, opt, isEmphasis); // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14465. }
  14466. /**
  14467. * The uniform entry of set text style, that is, retrieve style definitions
  14468. * from `model` and set to `textStyle` object.
  14469. *
  14470. * Never in merge mode, but in overwrite mode, that is, all of the text style
  14471. * properties will be set. (Consider the states of normal and emphasis and
  14472. * default value can be adopted, merge would make the logic too complicated
  14473. * to manage.)
  14474. *
  14475. * The `textStyle` object can either be a plain object or an instance of
  14476. * `zrender/src/graphic/Style`, and either be the style of normal or emphasis.
  14477. * After this mothod called, the `textStyle` object can then be used in
  14478. * `el.setStyle(textStyle)` or `el.hoverStyle = textStyle`.
  14479. *
  14480. * Default value will be adopted and `insideRollbackOpt` will be created.
  14481. * See `applyDefaultTextStyle` `rollbackDefaultTextStyle` for more details.
  14482. *
  14483. * opt: {
  14484. * disableBox: boolean, Whether diable drawing box of block (outer most).
  14485. * isRectText: boolean,
  14486. * autoColor: string, specify a color when color is 'auto',
  14487. * for textFill, textStroke, textBackgroundColor, and textBorderColor.
  14488. * If autoColor specified, it is used as default textFill.
  14489. * useInsideStyle:
  14490. * `true`: Use inside style (textFill, textStroke, textStrokeWidth)
  14491. * if `textFill` is not specified.
  14492. * `false`: Do not use inside style.
  14493. * `null/undefined`: use inside style if `isRectText` is true and
  14494. * `textFill` is not specified and textPosition contains `'inside'`.
  14495. * forceRich: boolean
  14496. * }
  14497. */
  14498. function setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {
  14499. // Consider there will be abnormal when merge hover style to normal style if given default value.
  14500. opt = opt || EMPTY_OBJ;
  14501. if (opt.isRectText) {
  14502. var textPosition;
  14503. if (opt.getTextPosition) {
  14504. textPosition = opt.getTextPosition(textStyleModel, isEmphasis);
  14505. } else {
  14506. textPosition = textStyleModel.getShallow('position') || (isEmphasis ? null : 'inside'); // 'outside' is not a valid zr textPostion value, but used
  14507. // in bar series, and magric type should be considered.
  14508. textPosition === 'outside' && (textPosition = 'top');
  14509. }
  14510. textStyle.textPosition = textPosition;
  14511. textStyle.textOffset = textStyleModel.getShallow('offset');
  14512. var labelRotate = textStyleModel.getShallow('rotate');
  14513. labelRotate != null && (labelRotate *= Math.PI / 180);
  14514. textStyle.textRotation = labelRotate;
  14515. textStyle.textDistance = retrieve2(textStyleModel.getShallow('distance'), isEmphasis ? null : 5);
  14516. }
  14517. var ecModel = textStyleModel.ecModel;
  14518. var globalTextStyle = ecModel && ecModel.option.textStyle; // Consider case:
  14519. // {
  14520. // data: [{
  14521. // value: 12,
  14522. // label: {
  14523. // rich: {
  14524. // // no 'a' here but using parent 'a'.
  14525. // }
  14526. // }
  14527. // }],
  14528. // rich: {
  14529. // a: { ... }
  14530. // }
  14531. // }
  14532. var richItemNames = getRichItemNames(textStyleModel);
  14533. var richResult;
  14534. if (richItemNames) {
  14535. richResult = {};
  14536. for (var name in richItemNames) {
  14537. if (richItemNames.hasOwnProperty(name)) {
  14538. // Cascade is supported in rich.
  14539. var richTextStyle = textStyleModel.getModel(['rich', name]); // In rich, never `disableBox`.
  14540. // FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  14541. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  14542. // That might confuses users. So probably we should put `textStyleModel` as the
  14543. // root ancestor of the `richTextStyle`. But that would be a break change.
  14544. setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);
  14545. }
  14546. }
  14547. }
  14548. textStyle.rich = richResult;
  14549. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);
  14550. if (opt.forceRich && !opt.textStyle) {
  14551. opt.textStyle = {};
  14552. }
  14553. return textStyle;
  14554. } // Consider case:
  14555. // {
  14556. // data: [{
  14557. // value: 12,
  14558. // label: {
  14559. // rich: {
  14560. // // no 'a' here but using parent 'a'.
  14561. // }
  14562. // }
  14563. // }],
  14564. // rich: {
  14565. // a: { ... }
  14566. // }
  14567. // }
  14568. function getRichItemNames(textStyleModel) {
  14569. // Use object to remove duplicated names.
  14570. var richItemNameMap;
  14571. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  14572. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  14573. if (rich) {
  14574. richItemNameMap = richItemNameMap || {};
  14575. for (var name in rich) {
  14576. if (rich.hasOwnProperty(name)) {
  14577. richItemNameMap[name] = 1;
  14578. }
  14579. }
  14580. }
  14581. textStyleModel = textStyleModel.parentModel;
  14582. }
  14583. return richItemNameMap;
  14584. }
  14585. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {
  14586. // In merge mode, default value should not be given.
  14587. globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;
  14588. textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt) || globalTextStyle.color;
  14589. textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt) || globalTextStyle.textBorderColor;
  14590. textStyle.textStrokeWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
  14591. if (!isEmphasis) {
  14592. if (isBlock) {
  14593. textStyle.insideRollbackOpt = opt;
  14594. applyDefaultTextStyle(textStyle);
  14595. } // Set default finally.
  14596. if (textStyle.textFill == null) {
  14597. textStyle.textFill = opt.autoColor;
  14598. }
  14599. } // Do not use `getFont` here, because merge should be supported, where
  14600. // part of these properties may be changed in emphasis style, and the
  14601. // others should remain their original value got from normal style.
  14602. textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;
  14603. textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;
  14604. textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;
  14605. textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;
  14606. textStyle.textAlign = textStyleModel.getShallow('align');
  14607. textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign') || textStyleModel.getShallow('baseline');
  14608. textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');
  14609. textStyle.textWidth = textStyleModel.getShallow('width');
  14610. textStyle.textHeight = textStyleModel.getShallow('height');
  14611. textStyle.textTag = textStyleModel.getShallow('tag');
  14612. if (!isBlock || !opt.disableBox) {
  14613. textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);
  14614. textStyle.textPadding = textStyleModel.getShallow('padding');
  14615. textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);
  14616. textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');
  14617. textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');
  14618. textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');
  14619. textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');
  14620. textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');
  14621. textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');
  14622. }
  14623. textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor') || globalTextStyle.textShadowColor;
  14624. textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur') || globalTextStyle.textShadowBlur;
  14625. textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX') || globalTextStyle.textShadowOffsetX;
  14626. textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY') || globalTextStyle.textShadowOffsetY;
  14627. }
  14628. function getAutoColor(color, opt) {
  14629. return color !== 'auto' ? color : opt && opt.autoColor ? opt.autoColor : null;
  14630. }
  14631. /**
  14632. * Give some default value to the input `textStyle` object, based on the current settings
  14633. * in this `textStyle` object.
  14634. *
  14635. * The Scenario:
  14636. * when text position is `inside` and `textFill` is not specified, we show
  14637. * text border by default for better view. But it should be considered that text position
  14638. * might be changed when hovering or being emphasis, where the `insideRollback` is used to
  14639. * restore the style.
  14640. *
  14641. * Usage (& NOTICE):
  14642. * When a style object (eithor plain object or instance of `zrender/src/graphic/Style`) is
  14643. * about to be modified on its text related properties, `rollbackDefaultTextStyle` should
  14644. * be called before the modification and `applyDefaultTextStyle` should be called after that.
  14645. * (For the case that all of the text related properties is reset, like `setTextStyleCommon`
  14646. * does, `rollbackDefaultTextStyle` is not needed to be called).
  14647. */
  14648. function applyDefaultTextStyle(textStyle) {
  14649. var textPosition = textStyle.textPosition;
  14650. var opt = textStyle.insideRollbackOpt;
  14651. var insideRollback;
  14652. if (opt && textStyle.textFill == null) {
  14653. var autoColor = opt.autoColor;
  14654. var isRectText = opt.isRectText;
  14655. var useInsideStyle = opt.useInsideStyle;
  14656. var useInsideStyleCache = useInsideStyle !== false && (useInsideStyle === true || isRectText && textPosition // textPosition can be [10, 30]
  14657. && typeof textPosition === 'string' && textPosition.indexOf('inside') >= 0);
  14658. var useAutoColorCache = !useInsideStyleCache && autoColor != null; // All of the props declared in `CACHED_LABEL_STYLE_PROPERTIES` are to be cached.
  14659. if (useInsideStyleCache || useAutoColorCache) {
  14660. insideRollback = {
  14661. textFill: textStyle.textFill,
  14662. textStroke: textStyle.textStroke,
  14663. textStrokeWidth: textStyle.textStrokeWidth
  14664. };
  14665. }
  14666. if (useInsideStyleCache) {
  14667. textStyle.textFill = '#fff'; // Consider text with #fff overflow its container.
  14668. if (textStyle.textStroke == null) {
  14669. textStyle.textStroke = autoColor;
  14670. textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);
  14671. }
  14672. }
  14673. if (useAutoColorCache) {
  14674. textStyle.textFill = autoColor;
  14675. }
  14676. } // Always set `insideRollback`, so that the previous one can be cleared.
  14677. textStyle.insideRollback = insideRollback;
  14678. }
  14679. /**
  14680. * Consider the case: in a scatter,
  14681. * label: {
  14682. * normal: {position: 'inside'},
  14683. * emphasis: {position: 'top'}
  14684. * }
  14685. * In the normal state, the `textFill` will be set as '#fff' for pretty view (see
  14686. * `applyDefaultTextStyle`), but when switching to emphasis state, the `textFill`
  14687. * should be retured to 'autoColor', but not keep '#fff'.
  14688. */
  14689. function rollbackDefaultTextStyle(style) {
  14690. var insideRollback = style.insideRollback;
  14691. if (insideRollback) {
  14692. // Reset all of the props in `CACHED_LABEL_STYLE_PROPERTIES`.
  14693. style.textFill = insideRollback.textFill;
  14694. style.textStroke = insideRollback.textStroke;
  14695. style.textStrokeWidth = insideRollback.textStrokeWidth;
  14696. style.insideRollback = null;
  14697. }
  14698. }
  14699. function getFont(opt, ecModel) {
  14700. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  14701. return trim([// FIXME in node-canvas fontWeight is before fontStyle
  14702. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '', opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '', (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px', opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'].join(' '));
  14703. }
  14704. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  14705. if (typeof dataIndex === 'function') {
  14706. cb = dataIndex;
  14707. dataIndex = null;
  14708. } // Do not check 'animation' property directly here. Consider this case:
  14709. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  14710. // but its parent model (`seriesModel`) does.
  14711. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  14712. if (animationEnabled) {
  14713. var postfix = isUpdate ? 'Update' : '';
  14714. var duration = animatableModel.getShallow('animationDuration' + postfix);
  14715. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  14716. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  14717. if (typeof animationDelay === 'function') {
  14718. animationDelay = animationDelay(dataIndex, animatableModel.getAnimationDelayParams ? animatableModel.getAnimationDelayParams(el, dataIndex) : null);
  14719. }
  14720. if (typeof duration === 'function') {
  14721. duration = duration(dataIndex);
  14722. }
  14723. duration > 0 ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb) : (el.stopAnimation(), el.attr(props), cb && cb());
  14724. } else {
  14725. el.stopAnimation();
  14726. el.attr(props);
  14727. cb && cb();
  14728. }
  14729. }
  14730. /**
  14731. * Update graphic element properties with or without animation according to the
  14732. * configuration in series.
  14733. *
  14734. * Caution: this method will stop previous animation.
  14735. * So do not use this method to one element twice before
  14736. * animation starts, unless you know what you are doing.
  14737. *
  14738. * @param {module:zrender/Element} el
  14739. * @param {Object} props
  14740. * @param {module:echarts/model/Model} [animatableModel]
  14741. * @param {number} [dataIndex]
  14742. * @param {Function} [cb]
  14743. * @example
  14744. * graphic.updateProps(el, {
  14745. * position: [100, 100]
  14746. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  14747. * // Or
  14748. * graphic.updateProps(el, {
  14749. * position: [100, 100]
  14750. * }, seriesModel, function () { console.log('Animation done!'); });
  14751. */
  14752. function updateProps(el, props, animatableModel, dataIndex, cb) {
  14753. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  14754. }
  14755. /**
  14756. * Init graphic element properties with or without animation according to the
  14757. * configuration in series.
  14758. *
  14759. * Caution: this method will stop previous animation.
  14760. * So do not use this method to one element twice before
  14761. * animation starts, unless you know what you are doing.
  14762. *
  14763. * @param {module:zrender/Element} el
  14764. * @param {Object} props
  14765. * @param {module:echarts/model/Model} [animatableModel]
  14766. * @param {number} [dataIndex]
  14767. * @param {Function} cb
  14768. */
  14769. function initProps(el, props, animatableModel, dataIndex, cb) {
  14770. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  14771. }
  14772. /**
  14773. * Get transform matrix of target (param target),
  14774. * in coordinate of its ancestor (param ancestor)
  14775. *
  14776. * @param {module:zrender/mixin/Transformable} target
  14777. * @param {module:zrender/mixin/Transformable} [ancestor]
  14778. */
  14779. function getTransform(target, ancestor) {
  14780. var mat = identity([]);
  14781. while (target && target !== ancestor) {
  14782. mul$1(mat, target.getLocalTransform(), mat);
  14783. target = target.parent;
  14784. }
  14785. return mat;
  14786. }
  14787. /**
  14788. * Apply transform to an vertex.
  14789. * @param {Array.<number>} target [x, y]
  14790. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  14791. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  14792. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  14793. * @param {boolean=} invert Whether use invert matrix.
  14794. * @return {Array.<number>} [x, y]
  14795. */
  14796. function applyTransform$1(target, transform, invert$$1) {
  14797. if (transform && !isArrayLike(transform)) {
  14798. transform = Transformable.getLocalTransform(transform);
  14799. }
  14800. if (invert$$1) {
  14801. transform = invert([], transform);
  14802. }
  14803. return applyTransform([], target, transform);
  14804. }
  14805. /**
  14806. * @param {string} direction 'left' 'right' 'top' 'bottom'
  14807. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  14808. * @param {boolean=} invert Whether use invert matrix.
  14809. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  14810. */
  14811. function transformDirection(direction, transform, invert$$1) {
  14812. // Pick a base, ensure that transform result will not be (0, 0).
  14813. var hBase = transform[4] === 0 || transform[5] === 0 || transform[0] === 0 ? 1 : Math.abs(2 * transform[4] / transform[0]);
  14814. var vBase = transform[4] === 0 || transform[5] === 0 || transform[2] === 0 ? 1 : Math.abs(2 * transform[4] / transform[2]);
  14815. var vertex = [direction === 'left' ? -hBase : direction === 'right' ? hBase : 0, direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0];
  14816. vertex = applyTransform$1(vertex, transform, invert$$1);
  14817. return Math.abs(vertex[0]) > Math.abs(vertex[1]) ? vertex[0] > 0 ? 'right' : 'left' : vertex[1] > 0 ? 'bottom' : 'top';
  14818. }
  14819. /**
  14820. * Apply group transition animation from g1 to g2.
  14821. * If no animatableModel, no animation.
  14822. */
  14823. function groupTransition(g1, g2, animatableModel, cb) {
  14824. if (!g1 || !g2) {
  14825. return;
  14826. }
  14827. function getElMap(g) {
  14828. var elMap = {};
  14829. g.traverse(function (el) {
  14830. if (!el.isGroup && el.anid) {
  14831. elMap[el.anid] = el;
  14832. }
  14833. });
  14834. return elMap;
  14835. }
  14836. function getAnimatableProps(el) {
  14837. var obj = {
  14838. position: clone$1(el.position),
  14839. rotation: el.rotation
  14840. };
  14841. if (el.shape) {
  14842. obj.shape = extend({}, el.shape);
  14843. }
  14844. return obj;
  14845. }
  14846. var elMap1 = getElMap(g1);
  14847. g2.traverse(function (el) {
  14848. if (!el.isGroup && el.anid) {
  14849. var oldEl = elMap1[el.anid];
  14850. if (oldEl) {
  14851. var newProp = getAnimatableProps(el);
  14852. el.attr(getAnimatableProps(oldEl));
  14853. updateProps(el, newProp, animatableModel, el.dataIndex);
  14854. } // else {
  14855. // if (el.previousProps) {
  14856. // graphic.updateProps
  14857. // }
  14858. // }
  14859. }
  14860. });
  14861. }
  14862. /**
  14863. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  14864. * @param {Object} rect {x, y, width, height}
  14865. * @return {Array.<Array.<number>>} A new clipped points.
  14866. */
  14867. function clipPointsByRect(points, rect) {
  14868. // FIXME: this way migth be incorrect when grpahic clipped by a corner.
  14869. // and when element have border.
  14870. return map(points, function (point) {
  14871. var x = point[0];
  14872. x = mathMax$1(x, rect.x);
  14873. x = mathMin$1(x, rect.x + rect.width);
  14874. var y = point[1];
  14875. y = mathMax$1(y, rect.y);
  14876. y = mathMin$1(y, rect.y + rect.height);
  14877. return [x, y];
  14878. });
  14879. }
  14880. /**
  14881. * @param {Object} targetRect {x, y, width, height}
  14882. * @param {Object} rect {x, y, width, height}
  14883. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  14884. */
  14885. function clipRectByRect(targetRect, rect) {
  14886. var x = mathMax$1(targetRect.x, rect.x);
  14887. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  14888. var y = mathMax$1(targetRect.y, rect.y);
  14889. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height); // If the total rect is cliped, nothing, including the border,
  14890. // should be painted. So return undefined.
  14891. if (x2 >= x && y2 >= y) {
  14892. return {
  14893. x: x,
  14894. y: y,
  14895. width: x2 - x,
  14896. height: y2 - y
  14897. };
  14898. }
  14899. }
  14900. /**
  14901. * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.
  14902. * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.
  14903. * @param {Object} [rect] {x, y, width, height}
  14904. * @return {module:zrender/Element} Icon path or image element.
  14905. */
  14906. function createIcon(iconStr, opt, rect) {
  14907. opt = extend({
  14908. rectHover: true
  14909. }, opt);
  14910. var style = opt.style = {
  14911. strokeNoScale: true
  14912. };
  14913. rect = rect || {
  14914. x: -1,
  14915. y: -1,
  14916. width: 2,
  14917. height: 2
  14918. };
  14919. if (iconStr) {
  14920. return iconStr.indexOf('image://') === 0 ? (style.image = iconStr.slice(8), defaults(style, rect), new ZImage(opt)) : makePath(iconStr.replace('path://', ''), opt, rect, 'center');
  14921. }
  14922. }
  14923. /**
  14924. * Return `true` if the given line (line `a`) and the given polygon
  14925. * are intersect.
  14926. * Note that we do not count colinear as intersect here because no
  14927. * requirement for that. We could do that if required in future.
  14928. *
  14929. * @param {number} a1x
  14930. * @param {number} a1y
  14931. * @param {number} a2x
  14932. * @param {number} a2y
  14933. * @param {Array.<Array.<number>>} points Points of the polygon.
  14934. * @return {boolean}
  14935. */
  14936. function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {
  14937. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  14938. var p = points[i];
  14939. if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {
  14940. return true;
  14941. }
  14942. p2 = p;
  14943. }
  14944. }
  14945. /**
  14946. * Return `true` if the given two lines (line `a` and line `b`)
  14947. * are intersect.
  14948. * Note that we do not count colinear as intersect here because no
  14949. * requirement for that. We could do that if required in future.
  14950. *
  14951. * @param {number} a1x
  14952. * @param {number} a1y
  14953. * @param {number} a2x
  14954. * @param {number} a2y
  14955. * @param {number} b1x
  14956. * @param {number} b1y
  14957. * @param {number} b2x
  14958. * @param {number} b2y
  14959. * @return {boolean}
  14960. */
  14961. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  14962. // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.
  14963. var mx = a2x - a1x;
  14964. var my = a2y - a1y;
  14965. var nx = b2x - b1x;
  14966. var ny = b2y - b1y; // `vec_m` and `vec_n` are parallel iff
  14967. // exising `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.
  14968. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  14969. if (nearZero(nmCrossProduct)) {
  14970. return false;
  14971. } // `vec_m` and `vec_n` are intersect iff
  14972. // existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,
  14973. // such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`
  14974. // and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.
  14975. var b1a1x = a1x - b1x;
  14976. var b1a1y = a1y - b1y;
  14977. var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;
  14978. if (q < 0 || q > 1) {
  14979. return false;
  14980. }
  14981. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  14982. if (p < 0 || p > 1) {
  14983. return false;
  14984. }
  14985. return true;
  14986. }
  14987. /**
  14988. * Cross product of 2-dimension vector.
  14989. */
  14990. function crossProduct2d(x1, y1, x2, y2) {
  14991. return x1 * y2 - x2 * y1;
  14992. }
  14993. function nearZero(val) {
  14994. return val <= 1e-6 && val >= -1e-6;
  14995. } // Register built-in shapes. These shapes might be overwirtten
  14996. // by users, although we do not recommend that.
  14997. registerShape('circle', Circle);
  14998. registerShape('sector', Sector);
  14999. registerShape('ring', Ring);
  15000. registerShape('polygon', Polygon);
  15001. registerShape('polyline', Polyline);
  15002. registerShape('rect', Rect);
  15003. registerShape('line', Line);
  15004. registerShape('bezierCurve', BezierCurve);
  15005. registerShape('arc', Arc);
  15006. var graphicUtil = (Object.freeze || Object)({
  15007. Z2_EMPHASIS_LIFT: Z2_EMPHASIS_LIFT,
  15008. CACHED_LABEL_STYLE_PROPERTIES: CACHED_LABEL_STYLE_PROPERTIES,
  15009. extendShape: extendShape,
  15010. extendPath: extendPath,
  15011. registerShape: registerShape,
  15012. getShapeClass: getShapeClass,
  15013. makePath: makePath,
  15014. makeImage: makeImage,
  15015. mergePath: mergePath,
  15016. resizePath: resizePath,
  15017. subPixelOptimizeLine: subPixelOptimizeLine,
  15018. subPixelOptimizeRect: subPixelOptimizeRect,
  15019. subPixelOptimize: subPixelOptimize,
  15020. setElementHoverStyle: setElementHoverStyle,
  15021. setHoverStyle: setHoverStyle,
  15022. setAsHighDownDispatcher: setAsHighDownDispatcher,
  15023. isHighDownDispatcher: isHighDownDispatcher,
  15024. getHighlightDigit: getHighlightDigit,
  15025. setLabelStyle: setLabelStyle,
  15026. modifyLabelStyle: modifyLabelStyle,
  15027. setTextStyle: setTextStyle,
  15028. setText: setText,
  15029. getFont: getFont,
  15030. updateProps: updateProps,
  15031. initProps: initProps,
  15032. getTransform: getTransform,
  15033. applyTransform: applyTransform$1,
  15034. transformDirection: transformDirection,
  15035. groupTransition: groupTransition,
  15036. clipPointsByRect: clipPointsByRect,
  15037. clipRectByRect: clipRectByRect,
  15038. createIcon: createIcon,
  15039. linePolygonIntersect: linePolygonIntersect,
  15040. lineLineIntersect: lineLineIntersect,
  15041. Group: Group,
  15042. Image: ZImage,
  15043. Text: Text,
  15044. Circle: Circle,
  15045. Sector: Sector,
  15046. Ring: Ring,
  15047. Polygon: Polygon,
  15048. Polyline: Polyline,
  15049. Rect: Rect,
  15050. Line: Line,
  15051. BezierCurve: BezierCurve,
  15052. Arc: Arc,
  15053. IncrementalDisplayable: IncrementalDisplayble,
  15054. CompoundPath: CompoundPath,
  15055. LinearGradient: LinearGradient,
  15056. RadialGradient: RadialGradient,
  15057. BoundingRect: BoundingRect
  15058. });
  15059. /*
  15060. * Licensed to the Apache Software Foundation (ASF) under one
  15061. * or more contributor license agreements. See the NOTICE file
  15062. * distributed with this work for additional information
  15063. * regarding copyright ownership. The ASF licenses this file
  15064. * to you under the Apache License, Version 2.0 (the
  15065. * "License"); you may not use this file except in compliance
  15066. * with the License. You may obtain a copy of the License at
  15067. *
  15068. * http://www.apache.org/licenses/LICENSE-2.0
  15069. *
  15070. * Unless required by applicable law or agreed to in writing,
  15071. * software distributed under the License is distributed on an
  15072. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15073. * KIND, either express or implied. See the License for the
  15074. * specific language governing permissions and limitations
  15075. * under the License.
  15076. */
  15077. var PATH_COLOR = ['textStyle', 'color'];
  15078. var textStyleMixin = {
  15079. /**
  15080. * Get color property or get color from option.textStyle.color
  15081. * @param {boolean} [isEmphasis]
  15082. * @return {string}
  15083. */
  15084. getTextColor: function (isEmphasis) {
  15085. var ecModel = this.ecModel;
  15086. return this.getShallow('color') || (!isEmphasis && ecModel ? ecModel.get(PATH_COLOR) : null);
  15087. },
  15088. /**
  15089. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  15090. * @return {string}
  15091. */
  15092. getFont: function () {
  15093. return getFont({
  15094. fontStyle: this.getShallow('fontStyle'),
  15095. fontWeight: this.getShallow('fontWeight'),
  15096. fontSize: this.getShallow('fontSize'),
  15097. fontFamily: this.getShallow('fontFamily')
  15098. }, this.ecModel);
  15099. },
  15100. getTextRect: function (text) {
  15101. return getBoundingRect(text, this.getFont(), this.getShallow('align'), this.getShallow('verticalAlign') || this.getShallow('baseline'), this.getShallow('padding'), this.getShallow('lineHeight'), this.getShallow('rich'), this.getShallow('truncateText'));
  15102. }
  15103. };
  15104. /*
  15105. * Licensed to the Apache Software Foundation (ASF) under one
  15106. * or more contributor license agreements. See the NOTICE file
  15107. * distributed with this work for additional information
  15108. * regarding copyright ownership. The ASF licenses this file
  15109. * to you under the Apache License, Version 2.0 (the
  15110. * "License"); you may not use this file except in compliance
  15111. * with the License. You may obtain a copy of the License at
  15112. *
  15113. * http://www.apache.org/licenses/LICENSE-2.0
  15114. *
  15115. * Unless required by applicable law or agreed to in writing,
  15116. * software distributed under the License is distributed on an
  15117. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15118. * KIND, either express or implied. See the License for the
  15119. * specific language governing permissions and limitations
  15120. * under the License.
  15121. */
  15122. var getItemStyle = makeStyleMapper([['fill', 'color'], ['stroke', 'borderColor'], ['lineWidth', 'borderWidth'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['textPosition'], ['textAlign']]);
  15123. var itemStyleMixin = {
  15124. getItemStyle: function (excludes, includes) {
  15125. var style = getItemStyle(this, excludes, includes);
  15126. var lineDash = this.getBorderLineDash();
  15127. lineDash && (style.lineDash = lineDash);
  15128. return style;
  15129. },
  15130. getBorderLineDash: function () {
  15131. var lineType = this.get('borderType');
  15132. return lineType === 'solid' || lineType == null ? null : lineType === 'dashed' ? [5, 5] : [1, 1];
  15133. }
  15134. };
  15135. /*
  15136. * Licensed to the Apache Software Foundation (ASF) under one
  15137. * or more contributor license agreements. See the NOTICE file
  15138. * distributed with this work for additional information
  15139. * regarding copyright ownership. The ASF licenses this file
  15140. * to you under the Apache License, Version 2.0 (the
  15141. * "License"); you may not use this file except in compliance
  15142. * with the License. You may obtain a copy of the License at
  15143. *
  15144. * http://www.apache.org/licenses/LICENSE-2.0
  15145. *
  15146. * Unless required by applicable law or agreed to in writing,
  15147. * software distributed under the License is distributed on an
  15148. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15149. * KIND, either express or implied. See the License for the
  15150. * specific language governing permissions and limitations
  15151. * under the License.
  15152. */
  15153. /**
  15154. * @module echarts/model/Model
  15155. */
  15156. var mixin$1 = mixin;
  15157. var inner = makeInner();
  15158. /**
  15159. * @alias module:echarts/model/Model
  15160. * @constructor
  15161. * @param {Object} [option]
  15162. * @param {module:echarts/model/Model} [parentModel]
  15163. * @param {module:echarts/model/Global} [ecModel]
  15164. */
  15165. function Model(option, parentModel, ecModel) {
  15166. /**
  15167. * @type {module:echarts/model/Model}
  15168. * @readOnly
  15169. */
  15170. this.parentModel = parentModel;
  15171. /**
  15172. * @type {module:echarts/model/Global}
  15173. * @readOnly
  15174. */
  15175. this.ecModel = ecModel;
  15176. /**
  15177. * @type {Object}
  15178. * @protected
  15179. */
  15180. this.option = option; // Simple optimization
  15181. // if (this.init) {
  15182. // if (arguments.length <= 4) {
  15183. // this.init(option, parentModel, ecModel, extraOpt);
  15184. // }
  15185. // else {
  15186. // this.init.apply(this, arguments);
  15187. // }
  15188. // }
  15189. }
  15190. Model.prototype = {
  15191. constructor: Model,
  15192. /**
  15193. * Model 的初始化函数
  15194. * @param {Object} option
  15195. */
  15196. init: null,
  15197. /**
  15198. * 从新的 Option merge
  15199. */
  15200. mergeOption: function (option) {
  15201. merge(this.option, option, true);
  15202. },
  15203. /**
  15204. * @param {string|Array.<string>} path
  15205. * @param {boolean} [ignoreParent=false]
  15206. * @return {*}
  15207. */
  15208. get: function (path, ignoreParent) {
  15209. if (path == null) {
  15210. return this.option;
  15211. }
  15212. return doGet(this.option, this.parsePath(path), !ignoreParent && getParent(this, path));
  15213. },
  15214. /**
  15215. * @param {string} key
  15216. * @param {boolean} [ignoreParent=false]
  15217. * @return {*}
  15218. */
  15219. getShallow: function (key, ignoreParent) {
  15220. var option = this.option;
  15221. var val = option == null ? option : option[key];
  15222. var parentModel = !ignoreParent && getParent(this, key);
  15223. if (val == null && parentModel) {
  15224. val = parentModel.getShallow(key);
  15225. }
  15226. return val;
  15227. },
  15228. /**
  15229. * @param {string|Array.<string>} [path]
  15230. * @param {module:echarts/model/Model} [parentModel]
  15231. * @return {module:echarts/model/Model}
  15232. */
  15233. getModel: function (path, parentModel) {
  15234. var obj = path == null ? this.option : doGet(this.option, path = this.parsePath(path));
  15235. var thisParentModel;
  15236. parentModel = parentModel || (thisParentModel = getParent(this, path)) && thisParentModel.getModel(path);
  15237. return new Model(obj, parentModel, this.ecModel);
  15238. },
  15239. /**
  15240. * If model has option
  15241. */
  15242. isEmpty: function () {
  15243. return this.option == null;
  15244. },
  15245. restoreData: function () {},
  15246. // Pending
  15247. clone: function () {
  15248. var Ctor = this.constructor;
  15249. return new Ctor(clone(this.option));
  15250. },
  15251. setReadOnly: function (properties) {// clazzUtil.setReadOnly(this, properties);
  15252. },
  15253. // If path is null/undefined, return null/undefined.
  15254. parsePath: function (path) {
  15255. if (typeof path === 'string') {
  15256. path = path.split('.');
  15257. }
  15258. return path;
  15259. },
  15260. /**
  15261. * @param {Function} getParentMethod
  15262. * param {Array.<string>|string} path
  15263. * return {module:echarts/model/Model}
  15264. */
  15265. customizeGetParent: function (getParentMethod) {
  15266. inner(this).getParent = getParentMethod;
  15267. },
  15268. isAnimationEnabled: function () {
  15269. if (!env$1.node) {
  15270. if (this.option.animation != null) {
  15271. return !!this.option.animation;
  15272. } else if (this.parentModel) {
  15273. return this.parentModel.isAnimationEnabled();
  15274. }
  15275. }
  15276. }
  15277. };
  15278. function doGet(obj, pathArr, parentModel) {
  15279. for (var i = 0; i < pathArr.length; i++) {
  15280. // Ignore empty
  15281. if (!pathArr[i]) {
  15282. continue;
  15283. } // obj could be number/string/... (like 0)
  15284. obj = obj && typeof obj === 'object' ? obj[pathArr[i]] : null;
  15285. if (obj == null) {
  15286. break;
  15287. }
  15288. }
  15289. if (obj == null && parentModel) {
  15290. obj = parentModel.get(pathArr);
  15291. }
  15292. return obj;
  15293. } // `path` can be null/undefined
  15294. function getParent(model, path) {
  15295. var getParentMethod = inner(model).getParent;
  15296. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  15297. } // Enable Model.extend.
  15298. enableClassExtend(Model);
  15299. enableClassCheck(Model);
  15300. mixin$1(Model, lineStyleMixin);
  15301. mixin$1(Model, areaStyleMixin);
  15302. mixin$1(Model, textStyleMixin);
  15303. mixin$1(Model, itemStyleMixin);
  15304. /*
  15305. * Licensed to the Apache Software Foundation (ASF) under one
  15306. * or more contributor license agreements. See the NOTICE file
  15307. * distributed with this work for additional information
  15308. * regarding copyright ownership. The ASF licenses this file
  15309. * to you under the Apache License, Version 2.0 (the
  15310. * "License"); you may not use this file except in compliance
  15311. * with the License. You may obtain a copy of the License at
  15312. *
  15313. * http://www.apache.org/licenses/LICENSE-2.0
  15314. *
  15315. * Unless required by applicable law or agreed to in writing,
  15316. * software distributed under the License is distributed on an
  15317. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15318. * KIND, either express or implied. See the License for the
  15319. * specific language governing permissions and limitations
  15320. * under the License.
  15321. */
  15322. var base = 0;
  15323. /**
  15324. * @public
  15325. * @param {string} type
  15326. * @return {string}
  15327. */
  15328. function getUID(type) {
  15329. // Considering the case of crossing js context,
  15330. // use Math.random to make id as unique as possible.
  15331. return [type || '', base++, Math.random().toFixed(5)].join('_');
  15332. }
  15333. /**
  15334. * @inner
  15335. */
  15336. function enableSubTypeDefaulter(entity) {
  15337. var subTypeDefaulters = {};
  15338. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  15339. componentType = parseClassType$1(componentType);
  15340. subTypeDefaulters[componentType.main] = defaulter;
  15341. };
  15342. entity.determineSubType = function (componentType, option) {
  15343. var type = option.type;
  15344. if (!type) {
  15345. var componentTypeMain = parseClassType$1(componentType).main;
  15346. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  15347. type = subTypeDefaulters[componentTypeMain](option);
  15348. }
  15349. }
  15350. return type;
  15351. };
  15352. return entity;
  15353. }
  15354. /**
  15355. * Topological travel on Activity Network (Activity On Vertices).
  15356. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  15357. *
  15358. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  15359. *
  15360. * If there is circle dependencey, Error will be thrown.
  15361. *
  15362. */
  15363. function enableTopologicalTravel(entity, dependencyGetter) {
  15364. /**
  15365. * @public
  15366. * @param {Array.<string>} targetNameList Target Component type list.
  15367. * Can be ['aa', 'bb', 'aa.xx']
  15368. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  15369. * @param {Function} callback Params: componentType, dependencies.
  15370. * @param {Object} context Scope of callback.
  15371. */
  15372. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  15373. if (!targetNameList.length) {
  15374. return;
  15375. }
  15376. var result = makeDepndencyGraph(fullNameList);
  15377. var graph = result.graph;
  15378. var stack = result.noEntryList;
  15379. var targetNameSet = {};
  15380. each$1(targetNameList, function (name) {
  15381. targetNameSet[name] = true;
  15382. });
  15383. while (stack.length) {
  15384. var currComponentType = stack.pop();
  15385. var currVertex = graph[currComponentType];
  15386. var isInTargetNameSet = !!targetNameSet[currComponentType];
  15387. if (isInTargetNameSet) {
  15388. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  15389. delete targetNameSet[currComponentType];
  15390. }
  15391. each$1(currVertex.successor, isInTargetNameSet ? removeEdgeAndAdd : removeEdge);
  15392. }
  15393. each$1(targetNameSet, function () {
  15394. throw new Error('Circle dependency may exists');
  15395. });
  15396. function removeEdge(succComponentType) {
  15397. graph[succComponentType].entryCount--;
  15398. if (graph[succComponentType].entryCount === 0) {
  15399. stack.push(succComponentType);
  15400. }
  15401. } // Consider this case: legend depends on series, and we call
  15402. // chart.setOption({series: [...]}), where only series is in option.
  15403. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  15404. // not be called, but only sereis.mergeOption is called. Thus legend
  15405. // have no chance to update its local record about series (like which
  15406. // name of series is available in legend).
  15407. function removeEdgeAndAdd(succComponentType) {
  15408. targetNameSet[succComponentType] = true;
  15409. removeEdge(succComponentType);
  15410. }
  15411. };
  15412. /**
  15413. * DepndencyGraph: {Object}
  15414. * key: conponentType,
  15415. * value: {
  15416. * successor: [conponentTypes...],
  15417. * originalDeps: [conponentTypes...],
  15418. * entryCount: {number}
  15419. * }
  15420. */
  15421. function makeDepndencyGraph(fullNameList) {
  15422. var graph = {};
  15423. var noEntryList = [];
  15424. each$1(fullNameList, function (name) {
  15425. var thisItem = createDependencyGraphItem(graph, name);
  15426. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  15427. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  15428. thisItem.entryCount = availableDeps.length;
  15429. if (thisItem.entryCount === 0) {
  15430. noEntryList.push(name);
  15431. }
  15432. each$1(availableDeps, function (dependentName) {
  15433. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  15434. thisItem.predecessor.push(dependentName);
  15435. }
  15436. var thatItem = createDependencyGraphItem(graph, dependentName);
  15437. if (indexOf(thatItem.successor, dependentName) < 0) {
  15438. thatItem.successor.push(name);
  15439. }
  15440. });
  15441. });
  15442. return {
  15443. graph: graph,
  15444. noEntryList: noEntryList
  15445. };
  15446. }
  15447. function createDependencyGraphItem(graph, name) {
  15448. if (!graph[name]) {
  15449. graph[name] = {
  15450. predecessor: [],
  15451. successor: []
  15452. };
  15453. }
  15454. return graph[name];
  15455. }
  15456. function getAvailableDependencies(originalDeps, fullNameList) {
  15457. var availableDeps = [];
  15458. each$1(originalDeps, function (dep) {
  15459. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  15460. });
  15461. return availableDeps;
  15462. }
  15463. }
  15464. /*
  15465. * Licensed to the Apache Software Foundation (ASF) under one
  15466. * or more contributor license agreements. See the NOTICE file
  15467. * distributed with this work for additional information
  15468. * regarding copyright ownership. The ASF licenses this file
  15469. * to you under the Apache License, Version 2.0 (the
  15470. * "License"); you may not use this file except in compliance
  15471. * with the License. You may obtain a copy of the License at
  15472. *
  15473. * http://www.apache.org/licenses/LICENSE-2.0
  15474. *
  15475. * Unless required by applicable law or agreed to in writing,
  15476. * software distributed under the License is distributed on an
  15477. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15478. * KIND, either express or implied. See the License for the
  15479. * specific language governing permissions and limitations
  15480. * under the License.
  15481. */
  15482. /*
  15483. * A third-party license is embeded for some of the code in this file:
  15484. * The method "quantile" was copied from "d3.js".
  15485. * (See more details in the comment of the method below.)
  15486. * The use of the source code of this file is also subject to the terms
  15487. * and consitions of the license of "d3.js" (BSD-3Clause, see
  15488. * </licenses/LICENSE-d3>).
  15489. */
  15490. var RADIAN_EPSILON = 1e-4;
  15491. function _trim(str) {
  15492. return str.replace(/^\s+|\s+$/g, '');
  15493. }
  15494. /**
  15495. * Linear mapping a value from domain to range
  15496. * @memberOf module:echarts/util/number
  15497. * @param {(number|Array.<number>)} val
  15498. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  15499. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  15500. * @param {boolean} clamp
  15501. * @return {(number|Array.<number>}
  15502. */
  15503. function linearMap(val, domain, range, clamp) {
  15504. var subDomain = domain[1] - domain[0];
  15505. var subRange = range[1] - range[0];
  15506. if (subDomain === 0) {
  15507. return subRange === 0 ? range[0] : (range[0] + range[1]) / 2;
  15508. } // Avoid accuracy problem in edge, such as
  15509. // 146.39 - 62.83 === 83.55999999999999.
  15510. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  15511. // It is a little verbose for efficiency considering this method
  15512. // is a hotspot.
  15513. if (clamp) {
  15514. if (subDomain > 0) {
  15515. if (val <= domain[0]) {
  15516. return range[0];
  15517. } else if (val >= domain[1]) {
  15518. return range[1];
  15519. }
  15520. } else {
  15521. if (val >= domain[0]) {
  15522. return range[0];
  15523. } else if (val <= domain[1]) {
  15524. return range[1];
  15525. }
  15526. }
  15527. } else {
  15528. if (val === domain[0]) {
  15529. return range[0];
  15530. }
  15531. if (val === domain[1]) {
  15532. return range[1];
  15533. }
  15534. }
  15535. return (val - domain[0]) / subDomain * subRange + range[0];
  15536. }
  15537. /**
  15538. * Convert a percent string to absolute number.
  15539. * Returns NaN if percent is not a valid string or number
  15540. * @memberOf module:echarts/util/number
  15541. * @param {string|number} percent
  15542. * @param {number} all
  15543. * @return {number}
  15544. */
  15545. function parsePercent$1(percent, all) {
  15546. switch (percent) {
  15547. case 'center':
  15548. case 'middle':
  15549. percent = '50%';
  15550. break;
  15551. case 'left':
  15552. case 'top':
  15553. percent = '0%';
  15554. break;
  15555. case 'right':
  15556. case 'bottom':
  15557. percent = '100%';
  15558. break;
  15559. }
  15560. if (typeof percent === 'string') {
  15561. if (_trim(percent).match(/%$/)) {
  15562. return parseFloat(percent) / 100 * all;
  15563. }
  15564. return parseFloat(percent);
  15565. }
  15566. return percent == null ? NaN : +percent;
  15567. }
  15568. /**
  15569. * (1) Fix rounding error of float numbers.
  15570. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  15571. *
  15572. * @param {number} x
  15573. * @param {number} [precision]
  15574. * @param {boolean} [returnStr]
  15575. * @return {number|string}
  15576. */
  15577. function round$1(x, precision, returnStr) {
  15578. if (precision == null) {
  15579. precision = 10;
  15580. } // Avoid range error
  15581. precision = Math.min(Math.max(0, precision), 20);
  15582. x = (+x).toFixed(precision);
  15583. return returnStr ? x : +x;
  15584. }
  15585. /**
  15586. * asc sort arr.
  15587. * The input arr will be modified.
  15588. *
  15589. * @param {Array} arr
  15590. * @return {Array} The input arr.
  15591. */
  15592. function asc(arr) {
  15593. arr.sort(function (a, b) {
  15594. return a - b;
  15595. });
  15596. return arr;
  15597. }
  15598. /**
  15599. * Get precision
  15600. * @param {number} val
  15601. */
  15602. function getPrecision(val) {
  15603. val = +val;
  15604. if (isNaN(val)) {
  15605. return 0;
  15606. } // It is much faster than methods converting number to string as follows
  15607. // var tmp = val.toString();
  15608. // return tmp.length - 1 - tmp.indexOf('.');
  15609. // especially when precision is low
  15610. var e = 1;
  15611. var count = 0;
  15612. while (Math.round(val * e) / e !== val) {
  15613. e *= 10;
  15614. count++;
  15615. }
  15616. return count;
  15617. }
  15618. /**
  15619. * @param {string|number} val
  15620. * @return {number}
  15621. */
  15622. function getPrecisionSafe(val) {
  15623. var str = val.toString(); // Consider scientific notation: '3.4e-12' '3.4e+12'
  15624. var eIndex = str.indexOf('e');
  15625. if (eIndex > 0) {
  15626. var precision = +str.slice(eIndex + 1);
  15627. return precision < 0 ? -precision : 0;
  15628. } else {
  15629. var dotIndex = str.indexOf('.');
  15630. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  15631. }
  15632. }
  15633. /**
  15634. * Minimal dicernible data precisioin according to a single pixel.
  15635. *
  15636. * @param {Array.<number>} dataExtent
  15637. * @param {Array.<number>} pixelExtent
  15638. * @return {number} precision
  15639. */
  15640. function getPixelPrecision(dataExtent, pixelExtent) {
  15641. var log = Math.log;
  15642. var LN10 = Math.LN10;
  15643. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  15644. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10); // toFixed() digits argument must be between 0 and 20.
  15645. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  15646. return !isFinite(precision) ? 20 : precision;
  15647. }
  15648. /**
  15649. * Get a data of given precision, assuring the sum of percentages
  15650. * in valueList is 1.
  15651. * The largest remainer method is used.
  15652. * https://en.wikipedia.org/wiki/Largest_remainder_method
  15653. *
  15654. * @param {Array.<number>} valueList a list of all data
  15655. * @param {number} idx index of the data to be processed in valueList
  15656. * @param {number} precision integer number showing digits of precision
  15657. * @return {number} percent ranging from 0 to 100
  15658. */
  15659. function getPercentWithPrecision(valueList, idx, precision) {
  15660. if (!valueList[idx]) {
  15661. return 0;
  15662. }
  15663. var sum = reduce(valueList, function (acc, val) {
  15664. return acc + (isNaN(val) ? 0 : val);
  15665. }, 0);
  15666. if (sum === 0) {
  15667. return 0;
  15668. }
  15669. var digits = Math.pow(10, precision);
  15670. var votesPerQuota = map(valueList, function (val) {
  15671. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  15672. });
  15673. var targetSeats = digits * 100;
  15674. var seats = map(votesPerQuota, function (votes) {
  15675. // Assign automatic seats.
  15676. return Math.floor(votes);
  15677. });
  15678. var currentSum = reduce(seats, function (acc, val) {
  15679. return acc + val;
  15680. }, 0);
  15681. var remainder = map(votesPerQuota, function (votes, idx) {
  15682. return votes - seats[idx];
  15683. }); // Has remainding votes.
  15684. while (currentSum < targetSeats) {
  15685. // Find next largest remainder.
  15686. var max = Number.NEGATIVE_INFINITY;
  15687. var maxId = null;
  15688. for (var i = 0, len = remainder.length; i < len; ++i) {
  15689. if (remainder[i] > max) {
  15690. max = remainder[i];
  15691. maxId = i;
  15692. }
  15693. } // Add a vote to max remainder.
  15694. ++seats[maxId];
  15695. remainder[maxId] = 0;
  15696. ++currentSum;
  15697. }
  15698. return seats[idx] / digits;
  15699. } // Number.MAX_SAFE_INTEGER, ie do not support.
  15700. var MAX_SAFE_INTEGER = 9007199254740991;
  15701. /**
  15702. * To 0 - 2 * PI, considering negative radian.
  15703. * @param {number} radian
  15704. * @return {number}
  15705. */
  15706. function remRadian(radian) {
  15707. var pi2 = Math.PI * 2;
  15708. return (radian % pi2 + pi2) % pi2;
  15709. }
  15710. /**
  15711. * @param {type} radian
  15712. * @return {boolean}
  15713. */
  15714. function isRadianAroundZero(val) {
  15715. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  15716. }
  15717. /* eslint-disable */
  15718. 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
  15719. /* eslint-enable */
  15720. /**
  15721. * @param {string|Date|number} value These values can be accepted:
  15722. * + An instance of Date, represent a time in its own time zone.
  15723. * + Or string in a subset of ISO 8601, only including:
  15724. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  15725. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  15726. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  15727. * all of which will be treated as local time if time zone is not specified
  15728. * (see <https://momentjs.com/>).
  15729. * + Or other string format, including (all of which will be treated as loacal time):
  15730. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  15731. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  15732. * + a timestamp, which represent a time in UTC.
  15733. * @return {Date} date
  15734. */
  15735. function parseDate(value) {
  15736. if (value instanceof Date) {
  15737. return value;
  15738. } else if (typeof value === 'string') {
  15739. // Different browsers parse date in different way, so we parse it manually.
  15740. // Some other issues:
  15741. // new Date('1970-01-01') is UTC,
  15742. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  15743. // See issue #3623
  15744. var match = TIME_REG.exec(value);
  15745. if (!match) {
  15746. // return Invalid Date.
  15747. return new Date(NaN);
  15748. } // Use local time when no timezone offset specifed.
  15749. if (!match[8]) {
  15750. // match[n] can only be string or undefined.
  15751. // But take care of '12' + 1 => '121'.
  15752. return new Date(+match[1], +(match[2] || 1) - 1, +match[3] || 1, +match[4] || 0, +(match[5] || 0), +match[6] || 0, +match[7] || 0);
  15753. } // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  15754. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  15755. // For example, system timezone is set as "Time Zone: America/Toronto",
  15756. // then these code will get different result:
  15757. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  15758. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  15759. // So we should not use `new Date`, but use `Date.UTC`.
  15760. else {
  15761. var hour = +match[4] || 0;
  15762. if (match[8].toUpperCase() !== 'Z') {
  15763. hour -= match[8].slice(0, 3);
  15764. }
  15765. return new Date(Date.UTC(+match[1], +(match[2] || 1) - 1, +match[3] || 1, hour, +(match[5] || 0), +match[6] || 0, +match[7] || 0));
  15766. }
  15767. } else if (value == null) {
  15768. return new Date(NaN);
  15769. }
  15770. return new Date(Math.round(value));
  15771. }
  15772. /**
  15773. * Quantity of a number. e.g. 0.1, 1, 10, 100
  15774. *
  15775. * @param {number} val
  15776. * @return {number}
  15777. */
  15778. function quantity(val) {
  15779. return Math.pow(10, quantityExponent(val));
  15780. }
  15781. /**
  15782. * Exponent of the quantity of a number
  15783. * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
  15784. *
  15785. * @param {number} val non-negative value
  15786. * @return {number}
  15787. */
  15788. function quantityExponent(val) {
  15789. if (val === 0) {
  15790. return 0;
  15791. }
  15792. var exp = Math.floor(Math.log(val) / Math.LN10);
  15793. /**
  15794. * exp is expected to be the rounded-down result of the base-10 log of val.
  15795. * But due to the precision loss with Math.log(val), we need to restore it
  15796. * using 10^exp to make sure we can get val back from exp. #11249
  15797. */
  15798. if (val / Math.pow(10, exp) >= 10) {
  15799. exp++;
  15800. }
  15801. return exp;
  15802. }
  15803. /**
  15804. * find a “nice” number approximately equal to x. Round the number if round = true,
  15805. * take ceiling if round = false. The primary observation is that the “nicest”
  15806. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  15807. *
  15808. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  15809. *
  15810. * @param {number} val Non-negative value.
  15811. * @param {boolean} round
  15812. * @return {number}
  15813. */
  15814. function nice(val, round) {
  15815. var exponent = quantityExponent(val);
  15816. var exp10 = Math.pow(10, exponent);
  15817. var f = val / exp10; // 1 <= f < 10
  15818. var nf;
  15819. if (round) {
  15820. if (f < 1.5) {
  15821. nf = 1;
  15822. } else if (f < 2.5) {
  15823. nf = 2;
  15824. } else if (f < 4) {
  15825. nf = 3;
  15826. } else if (f < 7) {
  15827. nf = 5;
  15828. } else {
  15829. nf = 10;
  15830. }
  15831. } else {
  15832. if (f < 1) {
  15833. nf = 1;
  15834. } else if (f < 2) {
  15835. nf = 2;
  15836. } else if (f < 3) {
  15837. nf = 3;
  15838. } else if (f < 5) {
  15839. nf = 5;
  15840. } else {
  15841. nf = 10;
  15842. }
  15843. }
  15844. val = nf * exp10; // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  15845. // 20 is the uppper bound of toFixed.
  15846. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  15847. }
  15848. /**
  15849. * This code was copied from "d3.js"
  15850. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  15851. * See the license statement at the head of this file.
  15852. * @param {Array.<number>} ascArr
  15853. */
  15854. function quantile(ascArr, p) {
  15855. var H = (ascArr.length - 1) * p + 1;
  15856. var h = Math.floor(H);
  15857. var v = +ascArr[h - 1];
  15858. var e = H - h;
  15859. return e ? v + e * (ascArr[h] - v) : v;
  15860. }
  15861. /**
  15862. * Order intervals asc, and split them when overlap.
  15863. * expect(numberUtil.reformIntervals([
  15864. * {interval: [18, 62], close: [1, 1]},
  15865. * {interval: [-Infinity, -70], close: [0, 0]},
  15866. * {interval: [-70, -26], close: [1, 1]},
  15867. * {interval: [-26, 18], close: [1, 1]},
  15868. * {interval: [62, 150], close: [1, 1]},
  15869. * {interval: [106, 150], close: [1, 1]},
  15870. * {interval: [150, Infinity], close: [0, 0]}
  15871. * ])).toEqual([
  15872. * {interval: [-Infinity, -70], close: [0, 0]},
  15873. * {interval: [-70, -26], close: [1, 1]},
  15874. * {interval: [-26, 18], close: [0, 1]},
  15875. * {interval: [18, 62], close: [0, 1]},
  15876. * {interval: [62, 150], close: [0, 1]},
  15877. * {interval: [150, Infinity], close: [0, 0]}
  15878. * ]);
  15879. * @param {Array.<Object>} list, where `close` mean open or close
  15880. * of the interval, and Infinity can be used.
  15881. * @return {Array.<Object>} The origin list, which has been reformed.
  15882. */
  15883. function reformIntervals(list) {
  15884. list.sort(function (a, b) {
  15885. return littleThan(a, b, 0) ? -1 : 1;
  15886. });
  15887. var curr = -Infinity;
  15888. var currClose = 1;
  15889. for (var i = 0; i < list.length;) {
  15890. var interval = list[i].interval;
  15891. var close = list[i].close;
  15892. for (var lg = 0; lg < 2; lg++) {
  15893. if (interval[lg] <= curr) {
  15894. interval[lg] = curr;
  15895. close[lg] = !lg ? 1 - currClose : 1;
  15896. }
  15897. curr = interval[lg];
  15898. currClose = close[lg];
  15899. }
  15900. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  15901. list.splice(i, 1);
  15902. } else {
  15903. i++;
  15904. }
  15905. }
  15906. return list;
  15907. function littleThan(a, b, lg) {
  15908. return a.interval[lg] < b.interval[lg] || a.interval[lg] === b.interval[lg] && (a.close[lg] - b.close[lg] === (!lg ? 1 : -1) || !lg && littleThan(a, b, 1));
  15909. }
  15910. }
  15911. /**
  15912. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  15913. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  15914. * subtraction forces infinities to NaN
  15915. *
  15916. * @param {*} v
  15917. * @return {boolean}
  15918. */
  15919. function isNumeric(v) {
  15920. return v - parseFloat(v) >= 0;
  15921. }
  15922. var number = (Object.freeze || Object)({
  15923. linearMap: linearMap,
  15924. parsePercent: parsePercent$1,
  15925. round: round$1,
  15926. asc: asc,
  15927. getPrecision: getPrecision,
  15928. getPrecisionSafe: getPrecisionSafe,
  15929. getPixelPrecision: getPixelPrecision,
  15930. getPercentWithPrecision: getPercentWithPrecision,
  15931. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  15932. remRadian: remRadian,
  15933. isRadianAroundZero: isRadianAroundZero,
  15934. parseDate: parseDate,
  15935. quantity: quantity,
  15936. quantityExponent: quantityExponent,
  15937. nice: nice,
  15938. quantile: quantile,
  15939. reformIntervals: reformIntervals,
  15940. isNumeric: isNumeric
  15941. });
  15942. /*
  15943. * Licensed to the Apache Software Foundation (ASF) under one
  15944. * or more contributor license agreements. See the NOTICE file
  15945. * distributed with this work for additional information
  15946. * regarding copyright ownership. The ASF licenses this file
  15947. * to you under the Apache License, Version 2.0 (the
  15948. * "License"); you may not use this file except in compliance
  15949. * with the License. You may obtain a copy of the License at
  15950. *
  15951. * http://www.apache.org/licenses/LICENSE-2.0
  15952. *
  15953. * Unless required by applicable law or agreed to in writing,
  15954. * software distributed under the License is distributed on an
  15955. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15956. * KIND, either express or implied. See the License for the
  15957. * specific language governing permissions and limitations
  15958. * under the License.
  15959. */
  15960. // import Text from 'zrender/src/graphic/Text';
  15961. /**
  15962. * add commas after every three numbers
  15963. * @param {string|number} x
  15964. * @return {string}
  15965. */
  15966. function addCommas(x) {
  15967. if (isNaN(x)) {
  15968. return '-';
  15969. }
  15970. x = (x + '').split('.');
  15971. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (x.length > 1 ? '.' + x[1] : '');
  15972. }
  15973. /**
  15974. * @param {string} str
  15975. * @param {boolean} [upperCaseFirst=false]
  15976. * @return {string} str
  15977. */
  15978. function toCamelCase(str, upperCaseFirst) {
  15979. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  15980. return group1.toUpperCase();
  15981. });
  15982. if (upperCaseFirst && str) {
  15983. str = str.charAt(0).toUpperCase() + str.slice(1);
  15984. }
  15985. return str;
  15986. }
  15987. var normalizeCssArray$1 = normalizeCssArray;
  15988. var replaceReg = /([&<>"'])/g;
  15989. var replaceMap = {
  15990. '&': '&amp;',
  15991. '<': '&lt;',
  15992. '>': '&gt;',
  15993. '"': '&quot;',
  15994. '\'': '&#39;'
  15995. };
  15996. function encodeHTML(source) {
  15997. return source == null ? '' : (source + '').replace(replaceReg, function (str, c) {
  15998. return replaceMap[c];
  15999. });
  16000. }
  16001. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  16002. var wrapVar = function (varName, seriesIdx) {
  16003. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  16004. };
  16005. /**
  16006. * Template formatter
  16007. * @param {string} tpl
  16008. * @param {Array.<Object>|Object} paramsList
  16009. * @param {boolean} [encode=false]
  16010. * @return {string}
  16011. */
  16012. function formatTpl(tpl, paramsList, encode) {
  16013. if (!isArray(paramsList)) {
  16014. paramsList = [paramsList];
  16015. }
  16016. var seriesLen = paramsList.length;
  16017. if (!seriesLen) {
  16018. return '';
  16019. }
  16020. var $vars = paramsList[0].$vars || [];
  16021. for (var i = 0; i < $vars.length; i++) {
  16022. var alias = TPL_VAR_ALIAS[i];
  16023. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  16024. }
  16025. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  16026. for (var k = 0; k < $vars.length; k++) {
  16027. var val = paramsList[seriesIdx][$vars[k]];
  16028. tpl = tpl.replace(wrapVar(TPL_VAR_ALIAS[k], seriesIdx), encode ? encodeHTML(val) : val);
  16029. }
  16030. }
  16031. return tpl;
  16032. }
  16033. /**
  16034. * simple Template formatter
  16035. *
  16036. * @param {string} tpl
  16037. * @param {Object} param
  16038. * @param {boolean} [encode=false]
  16039. * @return {string}
  16040. */
  16041. function formatTplSimple(tpl, param, encode) {
  16042. each$1(param, function (value, key) {
  16043. tpl = tpl.replace('{' + key + '}', encode ? encodeHTML(value) : value);
  16044. });
  16045. return tpl;
  16046. }
  16047. /**
  16048. * @param {Object|string} [opt] If string, means color.
  16049. * @param {string} [opt.color]
  16050. * @param {string} [opt.extraCssText]
  16051. * @param {string} [opt.type='item'] 'item' or 'subItem'
  16052. * @param {string} [opt.renderMode='html'] render mode of tooltip, 'html' or 'richText'
  16053. * @param {string} [opt.markerId='X'] id name for marker. If only one marker is in a rich text, this can be omitted.
  16054. * @return {string}
  16055. */
  16056. function getTooltipMarker(opt, extraCssText) {
  16057. opt = isString(opt) ? {
  16058. color: opt,
  16059. extraCssText: extraCssText
  16060. } : opt || {};
  16061. var color = opt.color;
  16062. var type = opt.type;
  16063. var extraCssText = opt.extraCssText;
  16064. var renderMode = opt.renderMode || 'html';
  16065. var markerId = opt.markerId || 'X';
  16066. if (!color) {
  16067. return '';
  16068. }
  16069. if (renderMode === 'html') {
  16070. return type === 'subItem' ? '<span style="display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;' + 'border-radius:4px;width:4px;height:4px;background-color:' + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>' : '<span style="display:inline-block;margin-right:5px;' + 'border-radius:10px;width:10px;height:10px;background-color:' + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>';
  16071. } else {
  16072. // Space for rich element marker
  16073. return {
  16074. renderMode: renderMode,
  16075. content: '{marker' + markerId + '|} ',
  16076. style: {
  16077. color: color
  16078. }
  16079. };
  16080. }
  16081. }
  16082. function pad(str, len) {
  16083. str += '';
  16084. return '0000'.substr(0, len - str.length) + str;
  16085. }
  16086. /**
  16087. * ISO Date format
  16088. * @param {string} tpl
  16089. * @param {number} value
  16090. * @param {boolean} [isUTC=false] Default in local time.
  16091. * see `module:echarts/scale/Time`
  16092. * and `module:echarts/util/number#parseDate`.
  16093. * @inner
  16094. */
  16095. function formatTime(tpl, value, isUTC) {
  16096. if (tpl === 'week' || tpl === 'month' || tpl === 'quarter' || tpl === 'half-year' || tpl === 'year') {
  16097. tpl = 'MM-dd\nyyyy';
  16098. }
  16099. var date = parseDate(value);
  16100. var utc = isUTC ? 'UTC' : '';
  16101. var y = date['get' + utc + 'FullYear']();
  16102. var M = date['get' + utc + 'Month']() + 1;
  16103. var d = date['get' + utc + 'Date']();
  16104. var h = date['get' + utc + 'Hours']();
  16105. var m = date['get' + utc + 'Minutes']();
  16106. var s = date['get' + utc + 'Seconds']();
  16107. var S = date['get' + utc + 'Milliseconds']();
  16108. tpl = tpl.replace('MM', pad(M, 2)).replace('M', M).replace('yyyy', y).replace('yy', y % 100).replace('dd', pad(d, 2)).replace('d', d).replace('hh', pad(h, 2)).replace('h', h).replace('mm', pad(m, 2)).replace('m', m).replace('ss', pad(s, 2)).replace('s', s).replace('SSS', pad(S, 3));
  16109. return tpl;
  16110. }
  16111. /**
  16112. * Capital first
  16113. * @param {string} str
  16114. * @return {string}
  16115. */
  16116. function capitalFirst(str) {
  16117. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  16118. }
  16119. var truncateText$1 = truncateText;
  16120. /**
  16121. * @public
  16122. * @param {Object} opt
  16123. * @param {string} opt.text
  16124. * @param {string} opt.font
  16125. * @param {string} [opt.textAlign='left']
  16126. * @param {string} [opt.textVerticalAlign='top']
  16127. * @param {Array.<number>} [opt.textPadding]
  16128. * @param {number} [opt.textLineHeight]
  16129. * @param {Object} [opt.rich]
  16130. * @param {Object} [opt.truncate]
  16131. * @return {Object} {x, y, width, height, lineHeight}
  16132. */
  16133. function getTextBoundingRect(opt) {
  16134. return getBoundingRect(opt.text, opt.font, opt.textAlign, opt.textVerticalAlign, opt.textPadding, opt.textLineHeight, opt.rich, opt.truncate);
  16135. }
  16136. /**
  16137. * @deprecated
  16138. * the `textLineHeight` was added later.
  16139. * For backward compatiblility, put it as the last parameter.
  16140. * But deprecated this interface. Please use `getTextBoundingRect` instead.
  16141. */
  16142. function getTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate, textLineHeight) {
  16143. return getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate);
  16144. }
  16145. /**
  16146. * open new tab
  16147. * @param {string} link url
  16148. * @param {string} target blank or self
  16149. */
  16150. function windowOpen(link, target) {
  16151. if (target === '_blank' || target === 'blank') {
  16152. var blank = window.open();
  16153. blank.opener = null;
  16154. blank.location = link;
  16155. } else {
  16156. window.open(link, target);
  16157. }
  16158. }
  16159. var format = (Object.freeze || Object)({
  16160. addCommas: addCommas,
  16161. toCamelCase: toCamelCase,
  16162. normalizeCssArray: normalizeCssArray$1,
  16163. encodeHTML: encodeHTML,
  16164. formatTpl: formatTpl,
  16165. formatTplSimple: formatTplSimple,
  16166. getTooltipMarker: getTooltipMarker,
  16167. formatTime: formatTime,
  16168. capitalFirst: capitalFirst,
  16169. truncateText: truncateText$1,
  16170. getTextBoundingRect: getTextBoundingRect,
  16171. getTextRect: getTextRect,
  16172. windowOpen: windowOpen
  16173. });
  16174. /*
  16175. * Licensed to the Apache Software Foundation (ASF) under one
  16176. * or more contributor license agreements. See the NOTICE file
  16177. * distributed with this work for additional information
  16178. * regarding copyright ownership. The ASF licenses this file
  16179. * to you under the Apache License, Version 2.0 (the
  16180. * "License"); you may not use this file except in compliance
  16181. * with the License. You may obtain a copy of the License at
  16182. *
  16183. * http://www.apache.org/licenses/LICENSE-2.0
  16184. *
  16185. * Unless required by applicable law or agreed to in writing,
  16186. * software distributed under the License is distributed on an
  16187. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16188. * KIND, either express or implied. See the License for the
  16189. * specific language governing permissions and limitations
  16190. * under the License.
  16191. */
  16192. // Layout helpers for each component positioning
  16193. var each$3 = each$1;
  16194. /**
  16195. * @public
  16196. */
  16197. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  16198. /**
  16199. * @public
  16200. */
  16201. var HV_NAMES = [['width', 'left', 'right'], ['height', 'top', 'bottom']];
  16202. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  16203. var x = 0;
  16204. var y = 0;
  16205. if (maxWidth == null) {
  16206. maxWidth = Infinity;
  16207. }
  16208. if (maxHeight == null) {
  16209. maxHeight = Infinity;
  16210. }
  16211. var currentLineMaxSize = 0;
  16212. group.eachChild(function (child, idx) {
  16213. var position = child.position;
  16214. var rect = child.getBoundingRect();
  16215. var nextChild = group.childAt(idx + 1);
  16216. var nextChildRect = nextChild && nextChild.getBoundingRect();
  16217. var nextX;
  16218. var nextY;
  16219. if (orient === 'horizontal') {
  16220. var moveX = rect.width + (nextChildRect ? -nextChildRect.x + rect.x : 0);
  16221. nextX = x + moveX; // Wrap when width exceeds maxWidth or meet a `newline` group
  16222. // FIXME compare before adding gap?
  16223. if (nextX > maxWidth || child.newline) {
  16224. x = 0;
  16225. nextX = moveX;
  16226. y += currentLineMaxSize + gap;
  16227. currentLineMaxSize = rect.height;
  16228. } else {
  16229. // FIXME: consider rect.y is not `0`?
  16230. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  16231. }
  16232. } else {
  16233. var moveY = rect.height + (nextChildRect ? -nextChildRect.y + rect.y : 0);
  16234. nextY = y + moveY; // Wrap when width exceeds maxHeight or meet a `newline` group
  16235. if (nextY > maxHeight || child.newline) {
  16236. x += currentLineMaxSize + gap;
  16237. y = 0;
  16238. nextY = moveY;
  16239. currentLineMaxSize = rect.width;
  16240. } else {
  16241. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  16242. }
  16243. }
  16244. if (child.newline) {
  16245. return;
  16246. }
  16247. position[0] = x;
  16248. position[1] = y;
  16249. orient === 'horizontal' ? x = nextX + gap : y = nextY + gap;
  16250. });
  16251. }
  16252. /**
  16253. * VBox or HBox layouting
  16254. * @param {string} orient
  16255. * @param {module:zrender/container/Group} group
  16256. * @param {number} gap
  16257. * @param {number} [width=Infinity]
  16258. * @param {number} [height=Infinity]
  16259. */
  16260. /**
  16261. * VBox layouting
  16262. * @param {module:zrender/container/Group} group
  16263. * @param {number} gap
  16264. * @param {number} [width=Infinity]
  16265. * @param {number} [height=Infinity]
  16266. */
  16267. var vbox = curry(boxLayout, 'vertical');
  16268. /**
  16269. * HBox layouting
  16270. * @param {module:zrender/container/Group} group
  16271. * @param {number} gap
  16272. * @param {number} [width=Infinity]
  16273. * @param {number} [height=Infinity]
  16274. */
  16275. var hbox = curry(boxLayout, 'horizontal');
  16276. /**
  16277. * If x or x2 is not specified or 'center' 'left' 'right',
  16278. * the width would be as long as possible.
  16279. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  16280. * the height would be as long as possible.
  16281. *
  16282. * @param {Object} positionInfo
  16283. * @param {number|string} [positionInfo.x]
  16284. * @param {number|string} [positionInfo.y]
  16285. * @param {number|string} [positionInfo.x2]
  16286. * @param {number|string} [positionInfo.y2]
  16287. * @param {Object} containerRect {width, height}
  16288. * @param {string|number} margin
  16289. * @return {Object} {width, height}
  16290. */
  16291. /**
  16292. * Parse position info.
  16293. *
  16294. * @param {Object} positionInfo
  16295. * @param {number|string} [positionInfo.left]
  16296. * @param {number|string} [positionInfo.top]
  16297. * @param {number|string} [positionInfo.right]
  16298. * @param {number|string} [positionInfo.bottom]
  16299. * @param {number|string} [positionInfo.width]
  16300. * @param {number|string} [positionInfo.height]
  16301. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  16302. * @param {Object} containerRect
  16303. * @param {string|number} [margin]
  16304. *
  16305. * @return {module:zrender/core/BoundingRect}
  16306. */
  16307. function getLayoutRect(positionInfo, containerRect, margin) {
  16308. margin = normalizeCssArray$1(margin || 0);
  16309. var containerWidth = containerRect.width;
  16310. var containerHeight = containerRect.height;
  16311. var left = parsePercent$1(positionInfo.left, containerWidth);
  16312. var top = parsePercent$1(positionInfo.top, containerHeight);
  16313. var right = parsePercent$1(positionInfo.right, containerWidth);
  16314. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  16315. var width = parsePercent$1(positionInfo.width, containerWidth);
  16316. var height = parsePercent$1(positionInfo.height, containerHeight);
  16317. var verticalMargin = margin[2] + margin[0];
  16318. var horizontalMargin = margin[1] + margin[3];
  16319. var aspect = positionInfo.aspect; // If width is not specified, calculate width from left and right
  16320. if (isNaN(width)) {
  16321. width = containerWidth - right - horizontalMargin - left;
  16322. }
  16323. if (isNaN(height)) {
  16324. height = containerHeight - bottom - verticalMargin - top;
  16325. }
  16326. if (aspect != null) {
  16327. // If width and height are not given
  16328. // 1. Graph should not exceeds the container
  16329. // 2. Aspect must be keeped
  16330. // 3. Graph should take the space as more as possible
  16331. // FIXME
  16332. // Margin is not considered, because there is no case that both
  16333. // using margin and aspect so far.
  16334. if (isNaN(width) && isNaN(height)) {
  16335. if (aspect > containerWidth / containerHeight) {
  16336. width = containerWidth * 0.8;
  16337. } else {
  16338. height = containerHeight * 0.8;
  16339. }
  16340. } // Calculate width or height with given aspect
  16341. if (isNaN(width)) {
  16342. width = aspect * height;
  16343. }
  16344. if (isNaN(height)) {
  16345. height = width / aspect;
  16346. }
  16347. } // If left is not specified, calculate left from right and width
  16348. if (isNaN(left)) {
  16349. left = containerWidth - right - width - horizontalMargin;
  16350. }
  16351. if (isNaN(top)) {
  16352. top = containerHeight - bottom - height - verticalMargin;
  16353. } // Align left and top
  16354. switch (positionInfo.left || positionInfo.right) {
  16355. case 'center':
  16356. left = containerWidth / 2 - width / 2 - margin[3];
  16357. break;
  16358. case 'right':
  16359. left = containerWidth - width - horizontalMargin;
  16360. break;
  16361. }
  16362. switch (positionInfo.top || positionInfo.bottom) {
  16363. case 'middle':
  16364. case 'center':
  16365. top = containerHeight / 2 - height / 2 - margin[0];
  16366. break;
  16367. case 'bottom':
  16368. top = containerHeight - height - verticalMargin;
  16369. break;
  16370. } // If something is wrong and left, top, width, height are calculated as NaN
  16371. left = left || 0;
  16372. top = top || 0;
  16373. if (isNaN(width)) {
  16374. // Width may be NaN if only one value is given except width
  16375. width = containerWidth - horizontalMargin - left - (right || 0);
  16376. }
  16377. if (isNaN(height)) {
  16378. // Height may be NaN if only one value is given except height
  16379. height = containerHeight - verticalMargin - top - (bottom || 0);
  16380. }
  16381. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  16382. rect.margin = margin;
  16383. return rect;
  16384. }
  16385. /**
  16386. * Position a zr element in viewport
  16387. * Group position is specified by either
  16388. * {left, top}, {right, bottom}
  16389. * If all properties exists, right and bottom will be igonred.
  16390. *
  16391. * Logic:
  16392. * 1. Scale (against origin point in parent coord)
  16393. * 2. Rotate (against origin point in parent coord)
  16394. * 3. Traslate (with el.position by this method)
  16395. * So this method only fixes the last step 'Traslate', which does not affect
  16396. * scaling and rotating.
  16397. *
  16398. * If be called repeatly with the same input el, the same result will be gotten.
  16399. *
  16400. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  16401. * @param {Object} positionInfo
  16402. * @param {number|string} [positionInfo.left]
  16403. * @param {number|string} [positionInfo.top]
  16404. * @param {number|string} [positionInfo.right]
  16405. * @param {number|string} [positionInfo.bottom]
  16406. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  16407. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  16408. * @param {Object} containerRect
  16409. * @param {string|number} margin
  16410. * @param {Object} [opt]
  16411. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  16412. * @param {Array.<number>} [opt.boundingMode='all']
  16413. * Specify how to calculate boundingRect when locating.
  16414. * 'all': Position the boundingRect that is transformed and uioned
  16415. * both itself and its descendants.
  16416. * This mode simplies confine the elements in the bounding
  16417. * of their container (e.g., using 'right: 0').
  16418. * 'raw': Position the boundingRect that is not transformed and only itself.
  16419. * This mode is useful when you want a element can overflow its
  16420. * container. (Consider a rotated circle needs to be located in a corner.)
  16421. * In this mode positionInfo.width/height can only be number.
  16422. */
  16423. /**
  16424. * @param {Object} option Contains some of the properties in HV_NAMES.
  16425. * @param {number} hvIdx 0: horizontal; 1: vertical.
  16426. */
  16427. /**
  16428. * Consider Case:
  16429. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  16430. * through setOption or media query, using normal zrUtil.merge will cause
  16431. * {right: 0} does not take effect.
  16432. *
  16433. * @example
  16434. * ComponentModel.extend({
  16435. * init: function () {
  16436. * ...
  16437. * var inputPositionParams = layout.getLayoutParams(option);
  16438. * this.mergeOption(inputPositionParams);
  16439. * },
  16440. * mergeOption: function (newOption) {
  16441. * newOption && zrUtil.merge(thisOption, newOption, true);
  16442. * layout.mergeLayoutParam(thisOption, newOption);
  16443. * }
  16444. * });
  16445. *
  16446. * @param {Object} targetOption
  16447. * @param {Object} newOption
  16448. * @param {Object|string} [opt]
  16449. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  16450. * that width (or height) should not be calculated by left and right (or top and bottom).
  16451. */
  16452. function mergeLayoutParam(targetOption, newOption, opt) {
  16453. !isObject$1(opt) && (opt = {});
  16454. var ignoreSize = opt.ignoreSize;
  16455. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  16456. var hResult = merge$$1(HV_NAMES[0], 0);
  16457. var vResult = merge$$1(HV_NAMES[1], 1);
  16458. copy(HV_NAMES[0], targetOption, hResult);
  16459. copy(HV_NAMES[1], targetOption, vResult);
  16460. function merge$$1(names, hvIdx) {
  16461. var newParams = {};
  16462. var newValueCount = 0;
  16463. var merged = {};
  16464. var mergedValueCount = 0;
  16465. var enoughParamNumber = 2;
  16466. each$3(names, function (name) {
  16467. merged[name] = targetOption[name];
  16468. });
  16469. each$3(names, function (name) {
  16470. // Consider case: newOption.width is null, which is
  16471. // set by user for removing width setting.
  16472. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  16473. hasValue(newParams, name) && newValueCount++;
  16474. hasValue(merged, name) && mergedValueCount++;
  16475. });
  16476. if (ignoreSize[hvIdx]) {
  16477. // Only one of left/right is premitted to exist.
  16478. if (hasValue(newOption, names[1])) {
  16479. merged[names[2]] = null;
  16480. } else if (hasValue(newOption, names[2])) {
  16481. merged[names[1]] = null;
  16482. }
  16483. return merged;
  16484. } // Case: newOption: {width: ..., right: ...},
  16485. // or targetOption: {right: ...} and newOption: {width: ...},
  16486. // There is no conflict when merged only has params count
  16487. // little than enoughParamNumber.
  16488. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  16489. return merged;
  16490. } // Case: newOption: {width: ..., right: ...},
  16491. // Than we can make sure user only want those two, and ignore
  16492. // all origin params in targetOption.
  16493. else if (newValueCount >= enoughParamNumber) {
  16494. return newParams;
  16495. } else {
  16496. // Chose another param from targetOption by priority.
  16497. for (var i = 0; i < names.length; i++) {
  16498. var name = names[i];
  16499. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  16500. newParams[name] = targetOption[name];
  16501. break;
  16502. }
  16503. }
  16504. return newParams;
  16505. }
  16506. }
  16507. function hasProp(obj, name) {
  16508. return obj.hasOwnProperty(name);
  16509. }
  16510. function hasValue(obj, name) {
  16511. return obj[name] != null && obj[name] !== 'auto';
  16512. }
  16513. function copy(names, target, source) {
  16514. each$3(names, function (name) {
  16515. target[name] = source[name];
  16516. });
  16517. }
  16518. }
  16519. /**
  16520. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  16521. * @param {Object} source
  16522. * @return {Object} Result contains those props.
  16523. */
  16524. function getLayoutParams(source) {
  16525. return copyLayoutParams({}, source);
  16526. }
  16527. /**
  16528. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  16529. * @param {Object} source
  16530. * @return {Object} Result contains those props.
  16531. */
  16532. function copyLayoutParams(target, source) {
  16533. source && target && each$3(LOCATION_PARAMS, function (name) {
  16534. source.hasOwnProperty(name) && (target[name] = source[name]);
  16535. });
  16536. return target;
  16537. }
  16538. /*
  16539. * Licensed to the Apache Software Foundation (ASF) under one
  16540. * or more contributor license agreements. See the NOTICE file
  16541. * distributed with this work for additional information
  16542. * regarding copyright ownership. The ASF licenses this file
  16543. * to you under the Apache License, Version 2.0 (the
  16544. * "License"); you may not use this file except in compliance
  16545. * with the License. You may obtain a copy of the License at
  16546. *
  16547. * http://www.apache.org/licenses/LICENSE-2.0
  16548. *
  16549. * Unless required by applicable law or agreed to in writing,
  16550. * software distributed under the License is distributed on an
  16551. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16552. * KIND, either express or implied. See the License for the
  16553. * specific language governing permissions and limitations
  16554. * under the License.
  16555. */
  16556. var boxLayoutMixin = {
  16557. getBoxLayoutParams: function () {
  16558. return {
  16559. left: this.get('left'),
  16560. top: this.get('top'),
  16561. right: this.get('right'),
  16562. bottom: this.get('bottom'),
  16563. width: this.get('width'),
  16564. height: this.get('height')
  16565. };
  16566. }
  16567. };
  16568. /*
  16569. * Licensed to the Apache Software Foundation (ASF) under one
  16570. * or more contributor license agreements. See the NOTICE file
  16571. * distributed with this work for additional information
  16572. * regarding copyright ownership. The ASF licenses this file
  16573. * to you under the Apache License, Version 2.0 (the
  16574. * "License"); you may not use this file except in compliance
  16575. * with the License. You may obtain a copy of the License at
  16576. *
  16577. * http://www.apache.org/licenses/LICENSE-2.0
  16578. *
  16579. * Unless required by applicable law or agreed to in writing,
  16580. * software distributed under the License is distributed on an
  16581. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16582. * KIND, either express or implied. See the License for the
  16583. * specific language governing permissions and limitations
  16584. * under the License.
  16585. */
  16586. /**
  16587. * Component model
  16588. *
  16589. * @module echarts/model/Component
  16590. */
  16591. var inner$1 = makeInner();
  16592. /**
  16593. * @alias module:echarts/model/Component
  16594. * @constructor
  16595. * @param {Object} option
  16596. * @param {module:echarts/model/Model} parentModel
  16597. * @param {module:echarts/model/Model} ecModel
  16598. */
  16599. var ComponentModel = Model.extend({
  16600. type: 'component',
  16601. /**
  16602. * @readOnly
  16603. * @type {string}
  16604. */
  16605. id: '',
  16606. /**
  16607. * Because simplified concept is probably better, series.name (or component.name)
  16608. * has been having too many resposibilities:
  16609. * (1) Generating id (which requires name in option should not be modified).
  16610. * (2) As an index to mapping series when merging option or calling API (a name
  16611. * can refer to more then one components, which is convinient is some case).
  16612. * (3) Display.
  16613. * @readOnly
  16614. */
  16615. name: '',
  16616. /**
  16617. * @readOnly
  16618. * @type {string}
  16619. */
  16620. mainType: '',
  16621. /**
  16622. * @readOnly
  16623. * @type {string}
  16624. */
  16625. subType: '',
  16626. /**
  16627. * @readOnly
  16628. * @type {number}
  16629. */
  16630. componentIndex: 0,
  16631. /**
  16632. * @type {Object}
  16633. * @protected
  16634. */
  16635. defaultOption: null,
  16636. /**
  16637. * @type {module:echarts/model/Global}
  16638. * @readOnly
  16639. */
  16640. ecModel: null,
  16641. /**
  16642. * key: componentType
  16643. * value: Component model list, can not be null.
  16644. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  16645. * @readOnly
  16646. */
  16647. dependentModels: [],
  16648. /**
  16649. * @type {string}
  16650. * @readOnly
  16651. */
  16652. uid: null,
  16653. /**
  16654. * Support merge layout params.
  16655. * Only support 'box' now (left/right/top/bottom/width/height).
  16656. * @type {string|Object} Object can be {ignoreSize: true}
  16657. * @readOnly
  16658. */
  16659. layoutMode: null,
  16660. $constructor: function (option, parentModel, ecModel, extraOpt) {
  16661. Model.call(this, option, parentModel, ecModel, extraOpt);
  16662. this.uid = getUID('ec_cpt_model');
  16663. },
  16664. init: function (option, parentModel, ecModel, extraOpt) {
  16665. this.mergeDefaultAndTheme(option, ecModel);
  16666. },
  16667. mergeDefaultAndTheme: function (option, ecModel) {
  16668. var layoutMode = this.layoutMode;
  16669. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  16670. var themeModel = ecModel.getTheme();
  16671. merge(option, themeModel.get(this.mainType));
  16672. merge(option, this.getDefaultOption());
  16673. if (layoutMode) {
  16674. mergeLayoutParam(option, inputPositionParams, layoutMode);
  16675. }
  16676. },
  16677. mergeOption: function (option, extraOpt) {
  16678. merge(this.option, option, true);
  16679. var layoutMode = this.layoutMode;
  16680. if (layoutMode) {
  16681. mergeLayoutParam(this.option, option, layoutMode);
  16682. }
  16683. },
  16684. // Hooker after init or mergeOption
  16685. optionUpdated: function (newCptOption, isInit) {},
  16686. getDefaultOption: function () {
  16687. var fields = inner$1(this);
  16688. if (!fields.defaultOption) {
  16689. var optList = [];
  16690. var Class = this.constructor;
  16691. while (Class) {
  16692. var opt = Class.prototype.defaultOption;
  16693. opt && optList.push(opt);
  16694. Class = Class.superClass;
  16695. }
  16696. var defaultOption = {};
  16697. for (var i = optList.length - 1; i >= 0; i--) {
  16698. defaultOption = merge(defaultOption, optList[i], true);
  16699. }
  16700. fields.defaultOption = defaultOption;
  16701. }
  16702. return fields.defaultOption;
  16703. },
  16704. getReferringComponents: function (mainType) {
  16705. return this.ecModel.queryComponents({
  16706. mainType: mainType,
  16707. index: this.get(mainType + 'Index', true),
  16708. id: this.get(mainType + 'Id', true)
  16709. });
  16710. }
  16711. }); // Reset ComponentModel.extend, add preConstruct.
  16712. // clazzUtil.enableClassExtend(
  16713. // ComponentModel,
  16714. // function (option, parentModel, ecModel, extraOpt) {
  16715. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  16716. // zrUtil.extend(this, extraOpt);
  16717. // this.uid = componentUtil.getUID('componentModel');
  16718. // // this.setReadOnly([
  16719. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  16720. // // 'dependentModels', 'componentIndex'
  16721. // // ]);
  16722. // }
  16723. // );
  16724. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  16725. enableClassManagement(ComponentModel, {
  16726. registerWhenExtend: true
  16727. });
  16728. enableSubTypeDefaulter(ComponentModel); // Add capability of ComponentModel.topologicalTravel.
  16729. enableTopologicalTravel(ComponentModel, getDependencies);
  16730. function getDependencies(componentType) {
  16731. var deps = [];
  16732. each$1(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  16733. deps = deps.concat(Clazz.prototype.dependencies || []);
  16734. }); // Ensure main type.
  16735. deps = map(deps, function (type) {
  16736. return parseClassType$1(type).main;
  16737. }); // Hack dataset for convenience.
  16738. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  16739. deps.unshift('dataset');
  16740. }
  16741. return deps;
  16742. }
  16743. mixin(ComponentModel, boxLayoutMixin);
  16744. /*
  16745. * Licensed to the Apache Software Foundation (ASF) under one
  16746. * or more contributor license agreements. See the NOTICE file
  16747. * distributed with this work for additional information
  16748. * regarding copyright ownership. The ASF licenses this file
  16749. * to you under the Apache License, Version 2.0 (the
  16750. * "License"); you may not use this file except in compliance
  16751. * with the License. You may obtain a copy of the License at
  16752. *
  16753. * http://www.apache.org/licenses/LICENSE-2.0
  16754. *
  16755. * Unless required by applicable law or agreed to in writing,
  16756. * software distributed under the License is distributed on an
  16757. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16758. * KIND, either express or implied. See the License for the
  16759. * specific language governing permissions and limitations
  16760. * under the License.
  16761. */
  16762. var platform = ''; // Navigator not exists in node
  16763. if (typeof navigator !== 'undefined') {
  16764. platform = navigator.platform || '';
  16765. }
  16766. var globalDefault = {
  16767. // backgroundColor: 'rgba(0,0,0,0)',
  16768. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  16769. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  16770. // Light colors:
  16771. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  16772. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  16773. // Dark colors:
  16774. color: ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
  16775. gradientColor: ['#f6efa6', '#d88273', '#bf444c'],
  16776. // If xAxis and yAxis declared, grid is created by default.
  16777. // grid: {},
  16778. textStyle: {
  16779. // color: '#000',
  16780. // decoration: 'none',
  16781. // PENDING
  16782. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  16783. // fontFamily: 'Arial, Verdana, sans-serif',
  16784. fontSize: 12,
  16785. fontStyle: 'normal',
  16786. fontWeight: 'normal'
  16787. },
  16788. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  16789. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  16790. // Default is source-over
  16791. blendMode: null,
  16792. animation: 'auto',
  16793. animationDuration: 1000,
  16794. animationDurationUpdate: 300,
  16795. animationEasing: 'exponentialOut',
  16796. animationEasingUpdate: 'cubicOut',
  16797. animationThreshold: 2000,
  16798. // Configuration for progressive/incremental rendering
  16799. progressiveThreshold: 3000,
  16800. progressive: 400,
  16801. // Threshold of if use single hover layer to optimize.
  16802. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  16803. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  16804. // which is unexpected.
  16805. // see example <echarts/test/heatmap-large.html>.
  16806. hoverLayerThreshold: 3000,
  16807. // See: module:echarts/scale/Time
  16808. useUTC: false
  16809. };
  16810. /*
  16811. * Licensed to the Apache Software Foundation (ASF) under one
  16812. * or more contributor license agreements. See the NOTICE file
  16813. * distributed with this work for additional information
  16814. * regarding copyright ownership. The ASF licenses this file
  16815. * to you under the Apache License, Version 2.0 (the
  16816. * "License"); you may not use this file except in compliance
  16817. * with the License. You may obtain a copy of the License at
  16818. *
  16819. * http://www.apache.org/licenses/LICENSE-2.0
  16820. *
  16821. * Unless required by applicable law or agreed to in writing,
  16822. * software distributed under the License is distributed on an
  16823. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16824. * KIND, either express or implied. See the License for the
  16825. * specific language governing permissions and limitations
  16826. * under the License.
  16827. */
  16828. var inner$2 = makeInner();
  16829. function getNearestColorPalette(colors, requestColorNum) {
  16830. var paletteNum = colors.length; // TODO colors must be in order
  16831. for (var i = 0; i < paletteNum; i++) {
  16832. if (colors[i].length > requestColorNum) {
  16833. return colors[i];
  16834. }
  16835. }
  16836. return colors[paletteNum - 1];
  16837. }
  16838. var colorPaletteMixin = {
  16839. clearColorPalette: function () {
  16840. inner$2(this).colorIdx = 0;
  16841. inner$2(this).colorNameMap = {};
  16842. },
  16843. /**
  16844. * @param {string} name MUST NOT be null/undefined. Otherwise call this function
  16845. * twise with the same parameters will get different result.
  16846. * @param {Object} [scope=this]
  16847. * @param {Object} [requestColorNum]
  16848. * @return {string} color string.
  16849. */
  16850. getColorFromPalette: function (name, scope, requestColorNum) {
  16851. scope = scope || this;
  16852. var scopeFields = inner$2(scope);
  16853. var colorIdx = scopeFields.colorIdx || 0;
  16854. var colorNameMap = scopeFields.colorNameMap = scopeFields.colorNameMap || {}; // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  16855. if (colorNameMap.hasOwnProperty(name)) {
  16856. return colorNameMap[name];
  16857. }
  16858. var defaultColorPalette = normalizeToArray(this.get('color', true));
  16859. var layeredColorPalette = this.get('colorLayer', true);
  16860. var colorPalette = requestColorNum == null || !layeredColorPalette ? defaultColorPalette : getNearestColorPalette(layeredColorPalette, requestColorNum); // In case can't find in layered color palette.
  16861. colorPalette = colorPalette || defaultColorPalette;
  16862. if (!colorPalette || !colorPalette.length) {
  16863. return;
  16864. }
  16865. var color = colorPalette[colorIdx];
  16866. if (name) {
  16867. colorNameMap[name] = color;
  16868. }
  16869. scopeFields.colorIdx = (colorIdx + 1) % colorPalette.length;
  16870. return color;
  16871. }
  16872. };
  16873. /*
  16874. * Licensed to the Apache Software Foundation (ASF) under one
  16875. * or more contributor license agreements. See the NOTICE file
  16876. * distributed with this work for additional information
  16877. * regarding copyright ownership. The ASF licenses this file
  16878. * to you under the Apache License, Version 2.0 (the
  16879. * "License"); you may not use this file except in compliance
  16880. * with the License. You may obtain a copy of the License at
  16881. *
  16882. * http://www.apache.org/licenses/LICENSE-2.0
  16883. *
  16884. * Unless required by applicable law or agreed to in writing,
  16885. * software distributed under the License is distributed on an
  16886. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16887. * KIND, either express or implied. See the License for the
  16888. * specific language governing permissions and limitations
  16889. * under the License.
  16890. */
  16891. // Avoid typo.
  16892. var SOURCE_FORMAT_ORIGINAL = 'original';
  16893. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  16894. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  16895. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  16896. var SOURCE_FORMAT_UNKNOWN = 'unknown'; // ??? CHANGE A NAME
  16897. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  16898. var SERIES_LAYOUT_BY_COLUMN = 'column';
  16899. var SERIES_LAYOUT_BY_ROW = 'row';
  16900. /*
  16901. * Licensed to the Apache Software Foundation (ASF) under one
  16902. * or more contributor license agreements. See the NOTICE file
  16903. * distributed with this work for additional information
  16904. * regarding copyright ownership. The ASF licenses this file
  16905. * to you under the Apache License, Version 2.0 (the
  16906. * "License"); you may not use this file except in compliance
  16907. * with the License. You may obtain a copy of the License at
  16908. *
  16909. * http://www.apache.org/licenses/LICENSE-2.0
  16910. *
  16911. * Unless required by applicable law or agreed to in writing,
  16912. * software distributed under the License is distributed on an
  16913. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16914. * KIND, either express or implied. See the License for the
  16915. * specific language governing permissions and limitations
  16916. * under the License.
  16917. */
  16918. /**
  16919. * [sourceFormat]
  16920. *
  16921. * + "original":
  16922. * This format is only used in series.data, where
  16923. * itemStyle can be specified in data item.
  16924. *
  16925. * + "arrayRows":
  16926. * [
  16927. * ['product', 'score', 'amount'],
  16928. * ['Matcha Latte', 89.3, 95.8],
  16929. * ['Milk Tea', 92.1, 89.4],
  16930. * ['Cheese Cocoa', 94.4, 91.2],
  16931. * ['Walnut Brownie', 85.4, 76.9]
  16932. * ]
  16933. *
  16934. * + "objectRows":
  16935. * [
  16936. * {product: 'Matcha Latte', score: 89.3, amount: 95.8},
  16937. * {product: 'Milk Tea', score: 92.1, amount: 89.4},
  16938. * {product: 'Cheese Cocoa', score: 94.4, amount: 91.2},
  16939. * {product: 'Walnut Brownie', score: 85.4, amount: 76.9}
  16940. * ]
  16941. *
  16942. * + "keyedColumns":
  16943. * {
  16944. * 'product': ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
  16945. * 'count': [823, 235, 1042, 988],
  16946. * 'score': [95.8, 81.4, 91.2, 76.9]
  16947. * }
  16948. *
  16949. * + "typedArray"
  16950. *
  16951. * + "unknown"
  16952. */
  16953. /**
  16954. * @constructor
  16955. * @param {Object} fields
  16956. * @param {string} fields.sourceFormat
  16957. * @param {Array|Object} fields.fromDataset
  16958. * @param {Array|Object} [fields.data]
  16959. * @param {string} [seriesLayoutBy='column']
  16960. * @param {Array.<Object|string>} [dimensionsDefine]
  16961. * @param {Objet|HashMap} [encodeDefine]
  16962. * @param {number} [startIndex=0]
  16963. * @param {number} [dimensionsDetectCount]
  16964. */
  16965. function Source(fields) {
  16966. /**
  16967. * @type {boolean}
  16968. */
  16969. this.fromDataset = fields.fromDataset;
  16970. /**
  16971. * Not null/undefined.
  16972. * @type {Array|Object}
  16973. */
  16974. this.data = fields.data || (fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []);
  16975. /**
  16976. * See also "detectSourceFormat".
  16977. * Not null/undefined.
  16978. * @type {string}
  16979. */
  16980. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
  16981. /**
  16982. * 'row' or 'column'
  16983. * Not null/undefined.
  16984. * @type {string} seriesLayoutBy
  16985. */
  16986. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  16987. /**
  16988. * dimensions definition in option.
  16989. * can be null/undefined.
  16990. * @type {Array.<Object|string>}
  16991. */
  16992. this.dimensionsDefine = fields.dimensionsDefine;
  16993. /**
  16994. * encode definition in option.
  16995. * can be null/undefined.
  16996. * @type {Objet|HashMap}
  16997. */
  16998. this.encodeDefine = fields.encodeDefine && createHashMap(fields.encodeDefine);
  16999. /**
  17000. * Not null/undefined, uint.
  17001. * @type {number}
  17002. */
  17003. this.startIndex = fields.startIndex || 0;
  17004. /**
  17005. * Can be null/undefined (when unknown), uint.
  17006. * @type {number}
  17007. */
  17008. this.dimensionsDetectCount = fields.dimensionsDetectCount;
  17009. }
  17010. /**
  17011. * Wrap original series data for some compatibility cases.
  17012. */
  17013. Source.seriesDataToSource = function (data) {
  17014. return new Source({
  17015. data: data,
  17016. sourceFormat: isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL,
  17017. fromDataset: false
  17018. });
  17019. };
  17020. enableClassCheck(Source);
  17021. /*
  17022. * Licensed to the Apache Software Foundation (ASF) under one
  17023. * or more contributor license agreements. See the NOTICE file
  17024. * distributed with this work for additional information
  17025. * regarding copyright ownership. The ASF licenses this file
  17026. * to you under the Apache License, Version 2.0 (the
  17027. * "License"); you may not use this file except in compliance
  17028. * with the License. You may obtain a copy of the License at
  17029. *
  17030. * http://www.apache.org/licenses/LICENSE-2.0
  17031. *
  17032. * Unless required by applicable law or agreed to in writing,
  17033. * software distributed under the License is distributed on an
  17034. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17035. * KIND, either express or implied. See the License for the
  17036. * specific language governing permissions and limitations
  17037. * under the License.
  17038. */
  17039. // The result of `guessOrdinal`.
  17040. var BE_ORDINAL = {
  17041. Must: 1,
  17042. // Encounter string but not '-' and not number-like.
  17043. Might: 2,
  17044. // Encounter string but number-like.
  17045. Not: 3 // Other cases
  17046. };
  17047. var inner$3 = makeInner();
  17048. /**
  17049. * @see {module:echarts/data/Source}
  17050. * @param {module:echarts/component/dataset/DatasetModel} datasetModel
  17051. * @return {string} sourceFormat
  17052. */
  17053. function detectSourceFormat(datasetModel) {
  17054. var data = datasetModel.option.source;
  17055. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  17056. if (isTypedArray(data)) {
  17057. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  17058. } else if (isArray(data)) {
  17059. // FIXME Whether tolerate null in top level array?
  17060. if (data.length === 0) {
  17061. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17062. }
  17063. for (var i = 0, len = data.length; i < len; i++) {
  17064. var item = data[i];
  17065. if (item == null) {
  17066. continue;
  17067. } else if (isArray(item)) {
  17068. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17069. break;
  17070. } else if (isObject$1(item)) {
  17071. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  17072. break;
  17073. }
  17074. }
  17075. } else if (isObject$1(data)) {
  17076. for (var key in data) {
  17077. if (data.hasOwnProperty(key) && isArrayLike(data[key])) {
  17078. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  17079. break;
  17080. }
  17081. }
  17082. } else if (data != null) {
  17083. throw new Error('Invalid data');
  17084. }
  17085. inner$3(datasetModel).sourceFormat = sourceFormat;
  17086. }
  17087. /**
  17088. * [Scenarios]:
  17089. * (1) Provide source data directly:
  17090. * series: {
  17091. * encode: {...},
  17092. * dimensions: [...]
  17093. * seriesLayoutBy: 'row',
  17094. * data: [[...]]
  17095. * }
  17096. * (2) Refer to datasetModel.
  17097. * series: [{
  17098. * encode: {...}
  17099. * // Ignore datasetIndex means `datasetIndex: 0`
  17100. * // and the dimensions defination in dataset is used
  17101. * }, {
  17102. * encode: {...},
  17103. * seriesLayoutBy: 'column',
  17104. * datasetIndex: 1
  17105. * }]
  17106. *
  17107. * Get data from series itself or datset.
  17108. * @return {module:echarts/data/Source} source
  17109. */
  17110. function getSource(seriesModel) {
  17111. return inner$3(seriesModel).source;
  17112. }
  17113. /**
  17114. * MUST be called before mergeOption of all series.
  17115. * @param {module:echarts/model/Global} ecModel
  17116. */
  17117. function resetSourceDefaulter(ecModel) {
  17118. // `datasetMap` is used to make default encode.
  17119. inner$3(ecModel).datasetMap = createHashMap();
  17120. }
  17121. /**
  17122. * [Caution]:
  17123. * MUST be called after series option merged and
  17124. * before "series.getInitailData()" called.
  17125. *
  17126. * [The rule of making default encode]:
  17127. * Category axis (if exists) alway map to the first dimension.
  17128. * Each other axis occupies a subsequent dimension.
  17129. *
  17130. * [Why make default encode]:
  17131. * Simplify the typing of encode in option, avoiding the case like that:
  17132. * series: [{encode: {x: 0, y: 1}}, {encode: {x: 0, y: 2}}, {encode: {x: 0, y: 3}}],
  17133. * where the "y" have to be manually typed as "1, 2, 3, ...".
  17134. *
  17135. * @param {module:echarts/model/Series} seriesModel
  17136. */
  17137. function prepareSource(seriesModel) {
  17138. var seriesOption = seriesModel.option;
  17139. var data = seriesOption.data;
  17140. var sourceFormat = isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  17141. var fromDataset = false;
  17142. var seriesLayoutBy = seriesOption.seriesLayoutBy;
  17143. var sourceHeader = seriesOption.sourceHeader;
  17144. var dimensionsDefine = seriesOption.dimensions;
  17145. var datasetModel = getDatasetModel(seriesModel);
  17146. if (datasetModel) {
  17147. var datasetOption = datasetModel.option;
  17148. data = datasetOption.source;
  17149. sourceFormat = inner$3(datasetModel).sourceFormat;
  17150. fromDataset = true; // These settings from series has higher priority.
  17151. seriesLayoutBy = seriesLayoutBy || datasetOption.seriesLayoutBy;
  17152. sourceHeader == null && (sourceHeader = datasetOption.sourceHeader);
  17153. dimensionsDefine = dimensionsDefine || datasetOption.dimensions;
  17154. }
  17155. var completeResult = completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine);
  17156. inner$3(seriesModel).source = new Source({
  17157. data: data,
  17158. fromDataset: fromDataset,
  17159. seriesLayoutBy: seriesLayoutBy,
  17160. sourceFormat: sourceFormat,
  17161. dimensionsDefine: completeResult.dimensionsDefine,
  17162. startIndex: completeResult.startIndex,
  17163. dimensionsDetectCount: completeResult.dimensionsDetectCount,
  17164. // Note: dataset option does not have `encode`.
  17165. encodeDefine: seriesOption.encode
  17166. });
  17167. } // return {startIndex, dimensionsDefine, dimensionsCount}
  17168. function completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine) {
  17169. if (!data) {
  17170. return {
  17171. dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine)
  17172. };
  17173. }
  17174. var dimensionsDetectCount;
  17175. var startIndex;
  17176. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  17177. // Rule: Most of the first line are string: it is header.
  17178. // Caution: consider a line with 5 string and 1 number,
  17179. // it still can not be sure it is a head, because the
  17180. // 5 string may be 5 values of category columns.
  17181. if (sourceHeader === 'auto' || sourceHeader == null) {
  17182. arrayRowsTravelFirst(function (val) {
  17183. // '-' is regarded as null/undefined.
  17184. if (val != null && val !== '-') {
  17185. if (isString(val)) {
  17186. startIndex == null && (startIndex = 1);
  17187. } else {
  17188. startIndex = 0;
  17189. }
  17190. } // 10 is an experience number, avoid long loop.
  17191. }, seriesLayoutBy, data, 10);
  17192. } else {
  17193. startIndex = sourceHeader ? 1 : 0;
  17194. }
  17195. if (!dimensionsDefine && startIndex === 1) {
  17196. dimensionsDefine = [];
  17197. arrayRowsTravelFirst(function (val, index) {
  17198. dimensionsDefine[index] = val != null ? val : '';
  17199. }, seriesLayoutBy, data);
  17200. }
  17201. dimensionsDetectCount = dimensionsDefine ? dimensionsDefine.length : seriesLayoutBy === SERIES_LAYOUT_BY_ROW ? data.length : data[0] ? data[0].length : null;
  17202. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  17203. if (!dimensionsDefine) {
  17204. dimensionsDefine = objectRowsCollectDimensions(data);
  17205. }
  17206. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17207. if (!dimensionsDefine) {
  17208. dimensionsDefine = [];
  17209. each$1(data, function (colArr, key) {
  17210. dimensionsDefine.push(key);
  17211. });
  17212. }
  17213. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  17214. var value0 = getDataItemValue(data[0]);
  17215. dimensionsDetectCount = isArray(value0) && value0.length || 1;
  17216. } else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  17217. if (__DEV__) {
  17218. assert$1(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');
  17219. }
  17220. }
  17221. return {
  17222. startIndex: startIndex,
  17223. dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine),
  17224. dimensionsDetectCount: dimensionsDetectCount
  17225. };
  17226. } // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  17227. // which is reasonable. But dimension name is duplicated.
  17228. // Returns undefined or an array contains only object without null/undefiend or string.
  17229. function normalizeDimensionsDefine(dimensionsDefine) {
  17230. if (!dimensionsDefine) {
  17231. // The meaning of null/undefined is different from empty array.
  17232. return;
  17233. }
  17234. var nameMap = createHashMap();
  17235. return map(dimensionsDefine, function (item, index) {
  17236. item = extend({}, isObject$1(item) ? item : {
  17237. name: item
  17238. }); // User can set null in dimensions.
  17239. // We dont auto specify name, othewise a given name may
  17240. // cause it be refered unexpectedly.
  17241. if (item.name == null) {
  17242. return item;
  17243. } // Also consider number form like 2012.
  17244. item.name += ''; // User may also specify displayName.
  17245. // displayName will always exists except user not
  17246. // specified or dim name is not specified or detected.
  17247. // (A auto generated dim name will not be used as
  17248. // displayName).
  17249. if (item.displayName == null) {
  17250. item.displayName = item.name;
  17251. }
  17252. var exist = nameMap.get(item.name);
  17253. if (!exist) {
  17254. nameMap.set(item.name, {
  17255. count: 1
  17256. });
  17257. } else {
  17258. item.name += '-' + exist.count++;
  17259. }
  17260. return item;
  17261. });
  17262. }
  17263. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  17264. maxLoop == null && (maxLoop = Infinity);
  17265. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  17266. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17267. cb(data[i] ? data[i][0] : null, i);
  17268. }
  17269. } else {
  17270. var value0 = data[0] || [];
  17271. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  17272. cb(value0[i], i);
  17273. }
  17274. }
  17275. }
  17276. function objectRowsCollectDimensions(data) {
  17277. var firstIndex = 0;
  17278. var obj;
  17279. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  17280. if (obj) {
  17281. var dimensions = [];
  17282. each$1(obj, function (value, key) {
  17283. dimensions.push(key);
  17284. });
  17285. return dimensions;
  17286. }
  17287. }
  17288. /**
  17289. * [The strategy of the arrengment of data dimensions for dataset]:
  17290. * "value way": all axes are non-category axes. So series one by one take
  17291. * several (the number is coordSysDims.length) dimensions from dataset.
  17292. * The result of data arrengment of data dimensions like:
  17293. * | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |
  17294. * "category way": at least one axis is category axis. So the the first data
  17295. * dimension is always mapped to the first category axis and shared by
  17296. * all of the series. The other data dimensions are taken by series like
  17297. * "value way" does.
  17298. * The result of data arrengment of data dimensions like:
  17299. * | ser_shared_x | ser0_y | ser1_y | ser2_y |
  17300. *
  17301. * @param {Array.<Object|string>} coordDimensions [{name: <string>, type: <string>, dimsDef: <Array>}, ...]
  17302. * @param {module:model/Series} seriesModel
  17303. * @param {module:data/Source} source
  17304. * @return {Object} encode Never be `null/undefined`.
  17305. */
  17306. function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {
  17307. var encode = {};
  17308. var datasetModel = getDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur.
  17309. if (!datasetModel || !coordDimensions) {
  17310. return encode;
  17311. }
  17312. var encodeItemName = [];
  17313. var encodeSeriesName = [];
  17314. var ecModel = seriesModel.ecModel;
  17315. var datasetMap = inner$3(ecModel).datasetMap;
  17316. var key = datasetModel.uid + '_' + source.seriesLayoutBy;
  17317. var baseCategoryDimIndex;
  17318. var categoryWayValueDimStart;
  17319. coordDimensions = coordDimensions.slice();
  17320. each$1(coordDimensions, function (coordDimInfo, coordDimIdx) {
  17321. !isObject$1(coordDimInfo) && (coordDimensions[coordDimIdx] = {
  17322. name: coordDimInfo
  17323. });
  17324. if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {
  17325. baseCategoryDimIndex = coordDimIdx;
  17326. categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimensions[coordDimIdx]);
  17327. }
  17328. encode[coordDimInfo.name] = [];
  17329. });
  17330. var datasetRecord = datasetMap.get(key) || datasetMap.set(key, {
  17331. categoryWayDim: categoryWayValueDimStart,
  17332. valueWayDim: 0
  17333. }); // TODO
  17334. // Auto detect first time axis and do arrangement.
  17335. each$1(coordDimensions, function (coordDimInfo, coordDimIdx) {
  17336. var coordDimName = coordDimInfo.name;
  17337. var count = getDataDimCountOnCoordDim(coordDimInfo); // In value way.
  17338. if (baseCategoryDimIndex == null) {
  17339. var start = datasetRecord.valueWayDim;
  17340. pushDim(encode[coordDimName], start, count);
  17341. pushDim(encodeSeriesName, start, count);
  17342. datasetRecord.valueWayDim += count; // ??? TODO give a better default series name rule?
  17343. // especially when encode x y specified.
  17344. // consider: when mutiple series share one dimension
  17345. // category axis, series name should better use
  17346. // the other dimsion name. On the other hand, use
  17347. // both dimensions name.
  17348. } // In category way, the first category axis.
  17349. else if (baseCategoryDimIndex === coordDimIdx) {
  17350. pushDim(encode[coordDimName], 0, count);
  17351. pushDim(encodeItemName, 0, count);
  17352. } // In category way, the other axis.
  17353. else {
  17354. var start = datasetRecord.categoryWayDim;
  17355. pushDim(encode[coordDimName], start, count);
  17356. pushDim(encodeSeriesName, start, count);
  17357. datasetRecord.categoryWayDim += count;
  17358. }
  17359. });
  17360. function pushDim(dimIdxArr, idxFrom, idxCount) {
  17361. for (var i = 0; i < idxCount; i++) {
  17362. dimIdxArr.push(idxFrom + i);
  17363. }
  17364. }
  17365. function getDataDimCountOnCoordDim(coordDimInfo) {
  17366. var dimsDef = coordDimInfo.dimsDef;
  17367. return dimsDef ? dimsDef.length : 1;
  17368. }
  17369. encodeItemName.length && (encode.itemName = encodeItemName);
  17370. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  17371. return encode;
  17372. }
  17373. /**
  17374. * Work for data like [{name: ..., value: ...}, ...].
  17375. *
  17376. * @param {module:model/Series} seriesModel
  17377. * @param {module:data/Source} source
  17378. * @return {Object} encode Never be `null/undefined`.
  17379. */
  17380. /**
  17381. * If return null/undefined, indicate that should not use datasetModel.
  17382. */
  17383. function getDatasetModel(seriesModel) {
  17384. var option = seriesModel.option; // Caution: consider the scenario:
  17385. // A dataset is declared and a series is not expected to use the dataset,
  17386. // and at the beginning `setOption({series: { noData })` (just prepare other
  17387. // option but no data), then `setOption({series: {data: [...]}); In this case,
  17388. // the user should set an empty array to avoid that dataset is used by default.
  17389. var thisData = option.data;
  17390. if (!thisData) {
  17391. return seriesModel.ecModel.getComponent('dataset', option.datasetIndex || 0);
  17392. }
  17393. }
  17394. /**
  17395. * The rule should not be complex, otherwise user might not
  17396. * be able to known where the data is wrong.
  17397. * The code is ugly, but how to make it neat?
  17398. *
  17399. * @param {module:echars/data/Source} source
  17400. * @param {number} dimIndex
  17401. * @return {BE_ORDINAL} guess result.
  17402. */
  17403. function guessOrdinal(source, dimIndex) {
  17404. return doGuessOrdinal(source.data, source.sourceFormat, source.seriesLayoutBy, source.dimensionsDefine, source.startIndex, dimIndex);
  17405. } // dimIndex may be overflow source data.
  17406. // return {BE_ORDINAL}
  17407. function doGuessOrdinal(data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex) {
  17408. var result; // Experience value.
  17409. var maxLoop = 5;
  17410. if (isTypedArray(data)) {
  17411. return BE_ORDINAL.Not;
  17412. } // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  17413. // always exists in source.
  17414. var dimName;
  17415. var dimType;
  17416. if (dimensionsDefine) {
  17417. var dimDefItem = dimensionsDefine[dimIndex];
  17418. if (isObject$1(dimDefItem)) {
  17419. dimName = dimDefItem.name;
  17420. dimType = dimDefItem.type;
  17421. } else if (isString(dimDefItem)) {
  17422. dimName = dimDefItem;
  17423. }
  17424. }
  17425. if (dimType != null) {
  17426. return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;
  17427. }
  17428. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  17429. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  17430. var sample = data[dimIndex];
  17431. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  17432. if ((result = detectValue(sample[startIndex + i])) != null) {
  17433. return result;
  17434. }
  17435. }
  17436. } else {
  17437. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17438. var row = data[startIndex + i];
  17439. if (row && (result = detectValue(row[dimIndex])) != null) {
  17440. return result;
  17441. }
  17442. }
  17443. }
  17444. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  17445. if (!dimName) {
  17446. return BE_ORDINAL.Not;
  17447. }
  17448. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17449. var item = data[i];
  17450. if (item && (result = detectValue(item[dimName])) != null) {
  17451. return result;
  17452. }
  17453. }
  17454. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17455. if (!dimName) {
  17456. return BE_ORDINAL.Not;
  17457. }
  17458. var sample = data[dimName];
  17459. if (!sample || isTypedArray(sample)) {
  17460. return BE_ORDINAL.Not;
  17461. }
  17462. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  17463. if ((result = detectValue(sample[i])) != null) {
  17464. return result;
  17465. }
  17466. }
  17467. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  17468. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17469. var item = data[i];
  17470. var val = getDataItemValue(item);
  17471. if (!isArray(val)) {
  17472. return BE_ORDINAL.Not;
  17473. }
  17474. if ((result = detectValue(val[dimIndex])) != null) {
  17475. return result;
  17476. }
  17477. }
  17478. }
  17479. function detectValue(val) {
  17480. var beStr = isString(val); // Consider usage convenience, '1', '2' will be treated as "number".
  17481. // `isFinit('')` get `true`.
  17482. if (val != null && isFinite(val) && val !== '') {
  17483. return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;
  17484. } else if (beStr && val !== '-') {
  17485. return BE_ORDINAL.Must;
  17486. }
  17487. }
  17488. return BE_ORDINAL.Not;
  17489. }
  17490. /*
  17491. * Licensed to the Apache Software Foundation (ASF) under one
  17492. * or more contributor license agreements. See the NOTICE file
  17493. * distributed with this work for additional information
  17494. * regarding copyright ownership. The ASF licenses this file
  17495. * to you under the Apache License, Version 2.0 (the
  17496. * "License"); you may not use this file except in compliance
  17497. * with the License. You may obtain a copy of the License at
  17498. *
  17499. * http://www.apache.org/licenses/LICENSE-2.0
  17500. *
  17501. * Unless required by applicable law or agreed to in writing,
  17502. * software distributed under the License is distributed on an
  17503. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17504. * KIND, either express or implied. See the License for the
  17505. * specific language governing permissions and limitations
  17506. * under the License.
  17507. */
  17508. /**
  17509. * ECharts global model
  17510. *
  17511. * @module {echarts/model/Global}
  17512. */
  17513. /**
  17514. * Caution: If the mechanism should be changed some day, these cases
  17515. * should be considered:
  17516. *
  17517. * (1) In `merge option` mode, if using the same option to call `setOption`
  17518. * many times, the result should be the same (try our best to ensure that).
  17519. * (2) In `merge option` mode, if a component has no id/name specified, it
  17520. * will be merged by index, and the result sequence of the components is
  17521. * consistent to the original sequence.
  17522. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  17523. * `mergeOption` in module:echarts/model/OptionManager.
  17524. */
  17525. var OPTION_INNER_KEY = '\0_ec_inner';
  17526. /**
  17527. * @alias module:echarts/model/Global
  17528. *
  17529. * @param {Object} option
  17530. * @param {module:echarts/model/Model} parentModel
  17531. * @param {Object} theme
  17532. */
  17533. var GlobalModel = Model.extend({
  17534. init: function (option, parentModel, theme, optionManager) {
  17535. theme = theme || {};
  17536. this.option = null; // Mark as not initialized.
  17537. /**
  17538. * @type {module:echarts/model/Model}
  17539. * @private
  17540. */
  17541. this._theme = new Model(theme);
  17542. /**
  17543. * @type {module:echarts/model/OptionManager}
  17544. */
  17545. this._optionManager = optionManager;
  17546. },
  17547. setOption: function (option, optionPreprocessorFuncs) {
  17548. assert$1(!(OPTION_INNER_KEY in option), 'please use chart.getOption()');
  17549. this._optionManager.setOption(option, optionPreprocessorFuncs);
  17550. this.resetOption(null);
  17551. },
  17552. /**
  17553. * @param {string} type null/undefined: reset all.
  17554. * 'recreate': force recreate all.
  17555. * 'timeline': only reset timeline option
  17556. * 'media': only reset media query option
  17557. * @return {boolean} Whether option changed.
  17558. */
  17559. resetOption: function (type) {
  17560. var optionChanged = false;
  17561. var optionManager = this._optionManager;
  17562. if (!type || type === 'recreate') {
  17563. var baseOption = optionManager.mountOption(type === 'recreate');
  17564. if (!this.option || type === 'recreate') {
  17565. initBase.call(this, baseOption);
  17566. } else {
  17567. this.restoreData();
  17568. this.mergeOption(baseOption);
  17569. }
  17570. optionChanged = true;
  17571. }
  17572. if (type === 'timeline' || type === 'media') {
  17573. this.restoreData();
  17574. }
  17575. if (!type || type === 'recreate' || type === 'timeline') {
  17576. var timelineOption = optionManager.getTimelineOption(this);
  17577. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  17578. }
  17579. if (!type || type === 'recreate' || type === 'media') {
  17580. var mediaOptions = optionManager.getMediaOption(this, this._api);
  17581. if (mediaOptions.length) {
  17582. each$1(mediaOptions, function (mediaOption) {
  17583. this.mergeOption(mediaOption, optionChanged = true);
  17584. }, this);
  17585. }
  17586. }
  17587. return optionChanged;
  17588. },
  17589. /**
  17590. * @protected
  17591. */
  17592. mergeOption: function (newOption) {
  17593. var option = this.option;
  17594. var componentsMap = this._componentsMap;
  17595. var newCptTypes = [];
  17596. resetSourceDefaulter(this); // If no component class, merge directly.
  17597. // For example: color, animaiton options, etc.
  17598. each$1(newOption, function (componentOption, mainType) {
  17599. if (componentOption == null) {
  17600. return;
  17601. }
  17602. if (!ComponentModel.hasClass(mainType)) {
  17603. // globalSettingTask.dirty();
  17604. option[mainType] = option[mainType] == null ? clone(componentOption) : merge(option[mainType], componentOption, true);
  17605. } else if (mainType) {
  17606. newCptTypes.push(mainType);
  17607. }
  17608. });
  17609. ComponentModel.topologicalTravel(newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this);
  17610. function visitComponent(mainType, dependencies) {
  17611. var newCptOptionList = normalizeToArray(newOption[mainType]);
  17612. var mapResult = mappingToExists(componentsMap.get(mainType), newCptOptionList);
  17613. makeIdAndName(mapResult); // Set mainType and complete subType.
  17614. each$1(mapResult, function (item, index) {
  17615. var opt = item.option;
  17616. if (isObject$1(opt)) {
  17617. item.keyInfo.mainType = mainType;
  17618. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  17619. }
  17620. });
  17621. var dependentModels = getComponentsByTypes(componentsMap, dependencies);
  17622. option[mainType] = [];
  17623. componentsMap.set(mainType, []);
  17624. each$1(mapResult, function (resultItem, index) {
  17625. var componentModel = resultItem.exist;
  17626. var newCptOption = resultItem.option;
  17627. assert$1(isObject$1(newCptOption) || componentModel, 'Empty component definition'); // Consider where is no new option and should be merged using {},
  17628. // see removeEdgeAndAdd in topologicalTravel and
  17629. // ComponentModel.getAllClassMainTypes.
  17630. if (!newCptOption) {
  17631. componentModel.mergeOption({}, this);
  17632. componentModel.optionUpdated({}, false);
  17633. } else {
  17634. var ComponentModelClass = ComponentModel.getClass(mainType, resultItem.keyInfo.subType, true);
  17635. if (componentModel && componentModel.constructor === ComponentModelClass) {
  17636. componentModel.name = resultItem.keyInfo.name; // componentModel.settingTask && componentModel.settingTask.dirty();
  17637. componentModel.mergeOption(newCptOption, this);
  17638. componentModel.optionUpdated(newCptOption, false);
  17639. } else {
  17640. // PENDING Global as parent ?
  17641. var extraOpt = extend({
  17642. dependentModels: dependentModels,
  17643. componentIndex: index
  17644. }, resultItem.keyInfo);
  17645. componentModel = new ComponentModelClass(newCptOption, this, this, extraOpt);
  17646. extend(componentModel, extraOpt);
  17647. componentModel.init(newCptOption, this, this, extraOpt); // Call optionUpdated after init.
  17648. // newCptOption has been used as componentModel.option
  17649. // and may be merged with theme and default, so pass null
  17650. // to avoid confusion.
  17651. componentModel.optionUpdated(null, true);
  17652. }
  17653. }
  17654. componentsMap.get(mainType)[index] = componentModel;
  17655. option[mainType][index] = componentModel.option;
  17656. }, this); // Backup series for filtering.
  17657. if (mainType === 'series') {
  17658. createSeriesIndices(this, componentsMap.get('series'));
  17659. }
  17660. }
  17661. this._seriesIndicesMap = createHashMap(this._seriesIndices = this._seriesIndices || []);
  17662. },
  17663. /**
  17664. * Get option for output (cloned option and inner info removed)
  17665. * @public
  17666. * @return {Object}
  17667. */
  17668. getOption: function () {
  17669. var option = clone(this.option);
  17670. each$1(option, function (opts, mainType) {
  17671. if (ComponentModel.hasClass(mainType)) {
  17672. var opts = normalizeToArray(opts);
  17673. for (var i = opts.length - 1; i >= 0; i--) {
  17674. // Remove options with inner id.
  17675. if (isIdInner(opts[i])) {
  17676. opts.splice(i, 1);
  17677. }
  17678. }
  17679. option[mainType] = opts;
  17680. }
  17681. });
  17682. delete option[OPTION_INNER_KEY];
  17683. return option;
  17684. },
  17685. /**
  17686. * @return {module:echarts/model/Model}
  17687. */
  17688. getTheme: function () {
  17689. return this._theme;
  17690. },
  17691. /**
  17692. * @param {string} mainType
  17693. * @param {number} [idx=0]
  17694. * @return {module:echarts/model/Component}
  17695. */
  17696. getComponent: function (mainType, idx) {
  17697. var list = this._componentsMap.get(mainType);
  17698. if (list) {
  17699. return list[idx || 0];
  17700. }
  17701. },
  17702. /**
  17703. * If none of index and id and name used, return all components with mainType.
  17704. * @param {Object} condition
  17705. * @param {string} condition.mainType
  17706. * @param {string} [condition.subType] If ignore, only query by mainType
  17707. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  17708. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  17709. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  17710. * @return {Array.<module:echarts/model/Component>}
  17711. */
  17712. queryComponents: function (condition) {
  17713. var mainType = condition.mainType;
  17714. if (!mainType) {
  17715. return [];
  17716. }
  17717. var index = condition.index;
  17718. var id = condition.id;
  17719. var name = condition.name;
  17720. var cpts = this._componentsMap.get(mainType);
  17721. if (!cpts || !cpts.length) {
  17722. return [];
  17723. }
  17724. var result;
  17725. if (index != null) {
  17726. if (!isArray(index)) {
  17727. index = [index];
  17728. }
  17729. result = filter(map(index, function (idx) {
  17730. return cpts[idx];
  17731. }), function (val) {
  17732. return !!val;
  17733. });
  17734. } else if (id != null) {
  17735. var isIdArray = isArray(id);
  17736. result = filter(cpts, function (cpt) {
  17737. return isIdArray && indexOf(id, cpt.id) >= 0 || !isIdArray && cpt.id === id;
  17738. });
  17739. } else if (name != null) {
  17740. var isNameArray = isArray(name);
  17741. result = filter(cpts, function (cpt) {
  17742. return isNameArray && indexOf(name, cpt.name) >= 0 || !isNameArray && cpt.name === name;
  17743. });
  17744. } else {
  17745. // Return all components with mainType
  17746. result = cpts.slice();
  17747. }
  17748. return filterBySubType(result, condition);
  17749. },
  17750. /**
  17751. * The interface is different from queryComponents,
  17752. * which is convenient for inner usage.
  17753. *
  17754. * @usage
  17755. * var result = findComponents(
  17756. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  17757. * );
  17758. * var result = findComponents(
  17759. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  17760. * );
  17761. * var result = findComponents(
  17762. * {mainType: 'series',
  17763. * filter: function (model, index) {...}}
  17764. * );
  17765. * // result like [component0, componnet1, ...]
  17766. *
  17767. * @param {Object} condition
  17768. * @param {string} condition.mainType Mandatory.
  17769. * @param {string} [condition.subType] Optional.
  17770. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  17771. * where xxx is mainType.
  17772. * If query attribute is null/undefined or has no index/id/name,
  17773. * do not filtering by query conditions, which is convenient for
  17774. * no-payload situations or when target of action is global.
  17775. * @param {Function} [condition.filter] parameter: component, return boolean.
  17776. * @return {Array.<module:echarts/model/Component>}
  17777. */
  17778. findComponents: function (condition) {
  17779. var query = condition.query;
  17780. var mainType = condition.mainType;
  17781. var queryCond = getQueryCond(query);
  17782. var result = queryCond ? this.queryComponents(queryCond) : this._componentsMap.get(mainType);
  17783. return doFilter(filterBySubType(result, condition));
  17784. function getQueryCond(q) {
  17785. var indexAttr = mainType + 'Index';
  17786. var idAttr = mainType + 'Id';
  17787. var nameAttr = mainType + 'Name';
  17788. return q && (q[indexAttr] != null || q[idAttr] != null || q[nameAttr] != null) ? {
  17789. mainType: mainType,
  17790. // subType will be filtered finally.
  17791. index: q[indexAttr],
  17792. id: q[idAttr],
  17793. name: q[nameAttr]
  17794. } : null;
  17795. }
  17796. function doFilter(res) {
  17797. return condition.filter ? filter(res, condition.filter) : res;
  17798. }
  17799. },
  17800. /**
  17801. * @usage
  17802. * eachComponent('legend', function (legendModel, index) {
  17803. * ...
  17804. * });
  17805. * eachComponent(function (componentType, model, index) {
  17806. * // componentType does not include subType
  17807. * // (componentType is 'xxx' but not 'xxx.aa')
  17808. * });
  17809. * eachComponent(
  17810. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  17811. * function (model, index) {...}
  17812. * );
  17813. * eachComponent(
  17814. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  17815. * function (model, index) {...}
  17816. * );
  17817. *
  17818. * @param {string|Object=} mainType When mainType is object, the definition
  17819. * is the same as the method 'findComponents'.
  17820. * @param {Function} cb
  17821. * @param {*} context
  17822. */
  17823. eachComponent: function (mainType, cb, context) {
  17824. var componentsMap = this._componentsMap;
  17825. if (typeof mainType === 'function') {
  17826. context = cb;
  17827. cb = mainType;
  17828. componentsMap.each(function (components, componentType) {
  17829. each$1(components, function (component, index) {
  17830. cb.call(context, componentType, component, index);
  17831. });
  17832. });
  17833. } else if (isString(mainType)) {
  17834. each$1(componentsMap.get(mainType), cb, context);
  17835. } else if (isObject$1(mainType)) {
  17836. var queryResult = this.findComponents(mainType);
  17837. each$1(queryResult, cb, context);
  17838. }
  17839. },
  17840. /**
  17841. * @param {string} name
  17842. * @return {Array.<module:echarts/model/Series>}
  17843. */
  17844. getSeriesByName: function (name) {
  17845. var series = this._componentsMap.get('series');
  17846. return filter(series, function (oneSeries) {
  17847. return oneSeries.name === name;
  17848. });
  17849. },
  17850. /**
  17851. * @param {number} seriesIndex
  17852. * @return {module:echarts/model/Series}
  17853. */
  17854. getSeriesByIndex: function (seriesIndex) {
  17855. return this._componentsMap.get('series')[seriesIndex];
  17856. },
  17857. /**
  17858. * Get series list before filtered by type.
  17859. * FIXME: rename to getRawSeriesByType?
  17860. *
  17861. * @param {string} subType
  17862. * @return {Array.<module:echarts/model/Series>}
  17863. */
  17864. getSeriesByType: function (subType) {
  17865. var series = this._componentsMap.get('series');
  17866. return filter(series, function (oneSeries) {
  17867. return oneSeries.subType === subType;
  17868. });
  17869. },
  17870. /**
  17871. * @return {Array.<module:echarts/model/Series>}
  17872. */
  17873. getSeries: function () {
  17874. return this._componentsMap.get('series').slice();
  17875. },
  17876. /**
  17877. * @return {number}
  17878. */
  17879. getSeriesCount: function () {
  17880. return this._componentsMap.get('series').length;
  17881. },
  17882. /**
  17883. * After filtering, series may be different
  17884. * frome raw series.
  17885. *
  17886. * @param {Function} cb
  17887. * @param {*} context
  17888. */
  17889. eachSeries: function (cb, context) {
  17890. assertSeriesInitialized(this);
  17891. each$1(this._seriesIndices, function (rawSeriesIndex) {
  17892. var series = this._componentsMap.get('series')[rawSeriesIndex];
  17893. cb.call(context, series, rawSeriesIndex);
  17894. }, this);
  17895. },
  17896. /**
  17897. * Iterate raw series before filtered.
  17898. *
  17899. * @param {Function} cb
  17900. * @param {*} context
  17901. */
  17902. eachRawSeries: function (cb, context) {
  17903. each$1(this._componentsMap.get('series'), cb, context);
  17904. },
  17905. /**
  17906. * After filtering, series may be different.
  17907. * frome raw series.
  17908. *
  17909. * @param {string} subType.
  17910. * @param {Function} cb
  17911. * @param {*} context
  17912. */
  17913. eachSeriesByType: function (subType, cb, context) {
  17914. assertSeriesInitialized(this);
  17915. each$1(this._seriesIndices, function (rawSeriesIndex) {
  17916. var series = this._componentsMap.get('series')[rawSeriesIndex];
  17917. if (series.subType === subType) {
  17918. cb.call(context, series, rawSeriesIndex);
  17919. }
  17920. }, this);
  17921. },
  17922. /**
  17923. * Iterate raw series before filtered of given type.
  17924. *
  17925. * @parma {string} subType
  17926. * @param {Function} cb
  17927. * @param {*} context
  17928. */
  17929. eachRawSeriesByType: function (subType, cb, context) {
  17930. return each$1(this.getSeriesByType(subType), cb, context);
  17931. },
  17932. /**
  17933. * @param {module:echarts/model/Series} seriesModel
  17934. */
  17935. isSeriesFiltered: function (seriesModel) {
  17936. assertSeriesInitialized(this);
  17937. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  17938. },
  17939. /**
  17940. * @return {Array.<number>}
  17941. */
  17942. getCurrentSeriesIndices: function () {
  17943. return (this._seriesIndices || []).slice();
  17944. },
  17945. /**
  17946. * @param {Function} cb
  17947. * @param {*} context
  17948. */
  17949. filterSeries: function (cb, context) {
  17950. assertSeriesInitialized(this);
  17951. var filteredSeries = filter(this._componentsMap.get('series'), cb, context);
  17952. createSeriesIndices(this, filteredSeries);
  17953. },
  17954. restoreData: function (payload) {
  17955. var componentsMap = this._componentsMap;
  17956. createSeriesIndices(this, componentsMap.get('series'));
  17957. var componentTypes = [];
  17958. componentsMap.each(function (components, componentType) {
  17959. componentTypes.push(componentType);
  17960. });
  17961. ComponentModel.topologicalTravel(componentTypes, ComponentModel.getAllClassMainTypes(), function (componentType, dependencies) {
  17962. each$1(componentsMap.get(componentType), function (component) {
  17963. (componentType !== 'series' || !isNotTargetSeries(component, payload)) && component.restoreData();
  17964. });
  17965. });
  17966. }
  17967. });
  17968. function isNotTargetSeries(seriesModel, payload) {
  17969. if (payload) {
  17970. var index = payload.seiresIndex;
  17971. var id = payload.seriesId;
  17972. var name = payload.seriesName;
  17973. return index != null && seriesModel.componentIndex !== index || id != null && seriesModel.id !== id || name != null && seriesModel.name !== name;
  17974. }
  17975. }
  17976. /**
  17977. * @inner
  17978. */
  17979. function mergeTheme(option, theme) {
  17980. // PENDING
  17981. // NOT use `colorLayer` in theme if option has `color`
  17982. var notMergeColorLayer = option.color && !option.colorLayer;
  17983. each$1(theme, function (themeItem, name) {
  17984. if (name === 'colorLayer' && notMergeColorLayer) {
  17985. return;
  17986. } // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  17987. if (!ComponentModel.hasClass(name)) {
  17988. if (typeof themeItem === 'object') {
  17989. option[name] = !option[name] ? clone(themeItem) : merge(option[name], themeItem, false);
  17990. } else {
  17991. if (option[name] == null) {
  17992. option[name] = themeItem;
  17993. }
  17994. }
  17995. }
  17996. });
  17997. }
  17998. function initBase(baseOption) {
  17999. baseOption = baseOption; // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  18000. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  18001. this.option = {};
  18002. this.option[OPTION_INNER_KEY] = 1;
  18003. /**
  18004. * Init with series: [], in case of calling findSeries method
  18005. * before series initialized.
  18006. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  18007. * @private
  18008. */
  18009. this._componentsMap = createHashMap({
  18010. series: []
  18011. });
  18012. /**
  18013. * Mapping between filtered series list and raw series list.
  18014. * key: filtered series indices, value: raw series indices.
  18015. * @type {Array.<nubmer>}
  18016. * @private
  18017. */
  18018. this._seriesIndices;
  18019. this._seriesIndicesMap;
  18020. mergeTheme(baseOption, this._theme.option); // TODO Needs clone when merging to the unexisted property
  18021. merge(baseOption, globalDefault, false);
  18022. this.mergeOption(baseOption);
  18023. }
  18024. /**
  18025. * @inner
  18026. * @param {Array.<string>|string} types model types
  18027. * @return {Object} key: {string} type, value: {Array.<Object>} models
  18028. */
  18029. function getComponentsByTypes(componentsMap, types) {
  18030. if (!isArray(types)) {
  18031. types = types ? [types] : [];
  18032. }
  18033. var ret = {};
  18034. each$1(types, function (type) {
  18035. ret[type] = (componentsMap.get(type) || []).slice();
  18036. });
  18037. return ret;
  18038. }
  18039. /**
  18040. * @inner
  18041. */
  18042. function determineSubType(mainType, newCptOption, existComponent) {
  18043. var subType = newCptOption.type ? newCptOption.type : existComponent ? existComponent.subType // Use determineSubType only when there is no existComponent.
  18044. : ComponentModel.determineSubType(mainType, newCptOption); // tooltip, markline, markpoint may always has no subType
  18045. return subType;
  18046. }
  18047. /**
  18048. * @inner
  18049. */
  18050. function createSeriesIndices(ecModel, seriesModels) {
  18051. ecModel._seriesIndicesMap = createHashMap(ecModel._seriesIndices = map(seriesModels, function (series) {
  18052. return series.componentIndex;
  18053. }) || []);
  18054. }
  18055. /**
  18056. * @inner
  18057. */
  18058. function filterBySubType(components, condition) {
  18059. // Using hasOwnProperty for restrict. Consider
  18060. // subType is undefined in user payload.
  18061. return condition.hasOwnProperty('subType') ? filter(components, function (cpt) {
  18062. return cpt.subType === condition.subType;
  18063. }) : components;
  18064. }
  18065. /**
  18066. * @inner
  18067. */
  18068. function assertSeriesInitialized(ecModel) {
  18069. // Components that use _seriesIndices should depends on series component,
  18070. // which make sure that their initialization is after series.
  18071. if (__DEV__) {
  18072. if (!ecModel._seriesIndices) {
  18073. throw new Error('Option should contains series.');
  18074. }
  18075. }
  18076. }
  18077. mixin(GlobalModel, colorPaletteMixin);
  18078. /*
  18079. * Licensed to the Apache Software Foundation (ASF) under one
  18080. * or more contributor license agreements. See the NOTICE file
  18081. * distributed with this work for additional information
  18082. * regarding copyright ownership. The ASF licenses this file
  18083. * to you under the Apache License, Version 2.0 (the
  18084. * "License"); you may not use this file except in compliance
  18085. * with the License. You may obtain a copy of the License at
  18086. *
  18087. * http://www.apache.org/licenses/LICENSE-2.0
  18088. *
  18089. * Unless required by applicable law or agreed to in writing,
  18090. * software distributed under the License is distributed on an
  18091. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18092. * KIND, either express or implied. See the License for the
  18093. * specific language governing permissions and limitations
  18094. * under the License.
  18095. */
  18096. var echartsAPIList = ['getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed', 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption', 'getViewOfComponentModel', 'getViewOfSeriesModel']; // And `getCoordinateSystems` and `getComponentByElement` will be injected in echarts.js
  18097. function ExtensionAPI(chartInstance) {
  18098. each$1(echartsAPIList, function (name) {
  18099. this[name] = bind(chartInstance[name], chartInstance);
  18100. }, this);
  18101. }
  18102. /*
  18103. * Licensed to the Apache Software Foundation (ASF) under one
  18104. * or more contributor license agreements. See the NOTICE file
  18105. * distributed with this work for additional information
  18106. * regarding copyright ownership. The ASF licenses this file
  18107. * to you under the Apache License, Version 2.0 (the
  18108. * "License"); you may not use this file except in compliance
  18109. * with the License. You may obtain a copy of the License at
  18110. *
  18111. * http://www.apache.org/licenses/LICENSE-2.0
  18112. *
  18113. * Unless required by applicable law or agreed to in writing,
  18114. * software distributed under the License is distributed on an
  18115. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18116. * KIND, either express or implied. See the License for the
  18117. * specific language governing permissions and limitations
  18118. * under the License.
  18119. */
  18120. var coordinateSystemCreators = {};
  18121. function CoordinateSystemManager() {
  18122. this._coordinateSystems = [];
  18123. }
  18124. CoordinateSystemManager.prototype = {
  18125. constructor: CoordinateSystemManager,
  18126. create: function (ecModel, api) {
  18127. var coordinateSystems = [];
  18128. each$1(coordinateSystemCreators, function (creater, type) {
  18129. var list = creater.create(ecModel, api);
  18130. coordinateSystems = coordinateSystems.concat(list || []);
  18131. });
  18132. this._coordinateSystems = coordinateSystems;
  18133. },
  18134. update: function (ecModel, api) {
  18135. each$1(this._coordinateSystems, function (coordSys) {
  18136. coordSys.update && coordSys.update(ecModel, api);
  18137. });
  18138. },
  18139. getCoordinateSystems: function () {
  18140. return this._coordinateSystems.slice();
  18141. }
  18142. };
  18143. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  18144. coordinateSystemCreators[type] = coordinateSystemCreator;
  18145. };
  18146. CoordinateSystemManager.get = function (type) {
  18147. return coordinateSystemCreators[type];
  18148. };
  18149. /*
  18150. * Licensed to the Apache Software Foundation (ASF) under one
  18151. * or more contributor license agreements. See the NOTICE file
  18152. * distributed with this work for additional information
  18153. * regarding copyright ownership. The ASF licenses this file
  18154. * to you under the Apache License, Version 2.0 (the
  18155. * "License"); you may not use this file except in compliance
  18156. * with the License. You may obtain a copy of the License at
  18157. *
  18158. * http://www.apache.org/licenses/LICENSE-2.0
  18159. *
  18160. * Unless required by applicable law or agreed to in writing,
  18161. * software distributed under the License is distributed on an
  18162. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18163. * KIND, either express or implied. See the License for the
  18164. * specific language governing permissions and limitations
  18165. * under the License.
  18166. */
  18167. /**
  18168. * ECharts option manager
  18169. *
  18170. * @module {echarts/model/OptionManager}
  18171. */
  18172. var each$4 = each$1;
  18173. var clone$3 = clone;
  18174. var map$1 = map;
  18175. var merge$1 = merge;
  18176. var QUERY_REG = /^(min|max)?(.+)$/;
  18177. /**
  18178. * TERM EXPLANATIONS:
  18179. *
  18180. * [option]:
  18181. *
  18182. * An object that contains definitions of components. For example:
  18183. * var option = {
  18184. * title: {...},
  18185. * legend: {...},
  18186. * visualMap: {...},
  18187. * series: [
  18188. * {data: [...]},
  18189. * {data: [...]},
  18190. * ...
  18191. * ]
  18192. * };
  18193. *
  18194. * [rawOption]:
  18195. *
  18196. * An object input to echarts.setOption. 'rawOption' may be an
  18197. * 'option', or may be an object contains multi-options. For example:
  18198. * var option = {
  18199. * baseOption: {
  18200. * title: {...},
  18201. * legend: {...},
  18202. * series: [
  18203. * {data: [...]},
  18204. * {data: [...]},
  18205. * ...
  18206. * ]
  18207. * },
  18208. * timeline: {...},
  18209. * options: [
  18210. * {title: {...}, series: {data: [...]}},
  18211. * {title: {...}, series: {data: [...]}},
  18212. * ...
  18213. * ],
  18214. * media: [
  18215. * {
  18216. * query: {maxWidth: 320},
  18217. * option: {series: {x: 20}, visualMap: {show: false}}
  18218. * },
  18219. * {
  18220. * query: {minWidth: 320, maxWidth: 720},
  18221. * option: {series: {x: 500}, visualMap: {show: true}}
  18222. * },
  18223. * {
  18224. * option: {series: {x: 1200}, visualMap: {show: true}}
  18225. * }
  18226. * ]
  18227. * };
  18228. *
  18229. * @alias module:echarts/model/OptionManager
  18230. * @param {module:echarts/ExtensionAPI} api
  18231. */
  18232. function OptionManager(api) {
  18233. /**
  18234. * @private
  18235. * @type {module:echarts/ExtensionAPI}
  18236. */
  18237. this._api = api;
  18238. /**
  18239. * @private
  18240. * @type {Array.<number>}
  18241. */
  18242. this._timelineOptions = [];
  18243. /**
  18244. * @private
  18245. * @type {Array.<Object>}
  18246. */
  18247. this._mediaList = [];
  18248. /**
  18249. * @private
  18250. * @type {Object}
  18251. */
  18252. this._mediaDefault;
  18253. /**
  18254. * -1, means default.
  18255. * empty means no media.
  18256. * @private
  18257. * @type {Array.<number>}
  18258. */
  18259. this._currentMediaIndices = [];
  18260. /**
  18261. * @private
  18262. * @type {Object}
  18263. */
  18264. this._optionBackup;
  18265. /**
  18266. * @private
  18267. * @type {Object}
  18268. */
  18269. this._newBaseOption;
  18270. } // timeline.notMerge is not supported in ec3. Firstly there is rearly
  18271. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  18272. // rawOption cloned and backuped when timeline changed, which does no
  18273. // good to performance. What's more, that both timeline and setOption
  18274. // method supply 'notMerge' brings complex and some problems.
  18275. // Consider this case:
  18276. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  18277. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  18278. OptionManager.prototype = {
  18279. constructor: OptionManager,
  18280. /**
  18281. * @public
  18282. * @param {Object} rawOption Raw option.
  18283. * @param {module:echarts/model/Global} ecModel
  18284. * @param {Array.<Function>} optionPreprocessorFuncs
  18285. * @return {Object} Init option
  18286. */
  18287. setOption: function (rawOption, optionPreprocessorFuncs) {
  18288. if (rawOption) {
  18289. // That set dat primitive is dangerous if user reuse the data when setOption again.
  18290. each$1(normalizeToArray(rawOption.series), function (series) {
  18291. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  18292. });
  18293. } // Caution: some series modify option data, if do not clone,
  18294. // it should ensure that the repeat modify correctly
  18295. // (create a new object when modify itself).
  18296. rawOption = clone$3(rawOption); // FIXME
  18297. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  18298. var oldOptionBackup = this._optionBackup;
  18299. var newParsedOption = parseRawOption.call(this, rawOption, optionPreprocessorFuncs, !oldOptionBackup);
  18300. this._newBaseOption = newParsedOption.baseOption; // For setOption at second time (using merge mode);
  18301. if (oldOptionBackup) {
  18302. // Only baseOption can be merged.
  18303. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption); // For simplicity, timeline options and media options do not support merge,
  18304. // that is, if you `setOption` twice and both has timeline options, the latter
  18305. // timeline opitons will not be merged to the formers, but just substitude them.
  18306. if (newParsedOption.timelineOptions.length) {
  18307. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  18308. }
  18309. if (newParsedOption.mediaList.length) {
  18310. oldOptionBackup.mediaList = newParsedOption.mediaList;
  18311. }
  18312. if (newParsedOption.mediaDefault) {
  18313. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  18314. }
  18315. } else {
  18316. this._optionBackup = newParsedOption;
  18317. }
  18318. },
  18319. /**
  18320. * @param {boolean} isRecreate
  18321. * @return {Object}
  18322. */
  18323. mountOption: function (isRecreate) {
  18324. var optionBackup = this._optionBackup; // TODO
  18325. // 如果没有reset功能则不clone。
  18326. this._timelineOptions = map$1(optionBackup.timelineOptions, clone$3);
  18327. this._mediaList = map$1(optionBackup.mediaList, clone$3);
  18328. this._mediaDefault = clone$3(optionBackup.mediaDefault);
  18329. this._currentMediaIndices = [];
  18330. return clone$3(isRecreate // this._optionBackup.baseOption, which is created at the first `setOption`
  18331. // called, and is merged into every new option by inner method `mergeOption`
  18332. // each time `setOption` called, can be only used in `isRecreate`, because
  18333. // its reliability is under suspicion. In other cases option merge is
  18334. // performed by `model.mergeOption`.
  18335. ? optionBackup.baseOption : this._newBaseOption);
  18336. },
  18337. /**
  18338. * @param {module:echarts/model/Global} ecModel
  18339. * @return {Object}
  18340. */
  18341. getTimelineOption: function (ecModel) {
  18342. var option;
  18343. var timelineOptions = this._timelineOptions;
  18344. if (timelineOptions.length) {
  18345. // getTimelineOption can only be called after ecModel inited,
  18346. // so we can get currentIndex from timelineModel.
  18347. var timelineModel = ecModel.getComponent('timeline');
  18348. if (timelineModel) {
  18349. option = clone$3(timelineOptions[timelineModel.getCurrentIndex()], true);
  18350. }
  18351. }
  18352. return option;
  18353. },
  18354. /**
  18355. * @param {module:echarts/model/Global} ecModel
  18356. * @return {Array.<Object>}
  18357. */
  18358. getMediaOption: function (ecModel) {
  18359. var ecWidth = this._api.getWidth();
  18360. var ecHeight = this._api.getHeight();
  18361. var mediaList = this._mediaList;
  18362. var mediaDefault = this._mediaDefault;
  18363. var indices = [];
  18364. var result = []; // No media defined.
  18365. if (!mediaList.length && !mediaDefault) {
  18366. return result;
  18367. } // Multi media may be applied, the latter defined media has higher priority.
  18368. for (var i = 0, len = mediaList.length; i < len; i++) {
  18369. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  18370. indices.push(i);
  18371. }
  18372. } // FIXME
  18373. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  18374. if (!indices.length && mediaDefault) {
  18375. indices = [-1];
  18376. }
  18377. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  18378. result = map$1(indices, function (index) {
  18379. return clone$3(index === -1 ? mediaDefault.option : mediaList[index].option);
  18380. });
  18381. } // Otherwise return nothing.
  18382. this._currentMediaIndices = indices;
  18383. return result;
  18384. }
  18385. };
  18386. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  18387. var timelineOptions = [];
  18388. var mediaList = [];
  18389. var mediaDefault;
  18390. var baseOption; // Compatible with ec2.
  18391. var timelineOpt = rawOption.timeline;
  18392. if (rawOption.baseOption) {
  18393. baseOption = rawOption.baseOption;
  18394. } // For timeline
  18395. if (timelineOpt || rawOption.options) {
  18396. baseOption = baseOption || {};
  18397. timelineOptions = (rawOption.options || []).slice();
  18398. } // For media query
  18399. if (rawOption.media) {
  18400. baseOption = baseOption || {};
  18401. var media = rawOption.media;
  18402. each$4(media, function (singleMedia) {
  18403. if (singleMedia && singleMedia.option) {
  18404. if (singleMedia.query) {
  18405. mediaList.push(singleMedia);
  18406. } else if (!mediaDefault) {
  18407. // Use the first media default.
  18408. mediaDefault = singleMedia;
  18409. }
  18410. }
  18411. });
  18412. } // For normal option
  18413. if (!baseOption) {
  18414. baseOption = rawOption;
  18415. } // Set timelineOpt to baseOption in ec3,
  18416. // which is convenient for merge option.
  18417. if (!baseOption.timeline) {
  18418. baseOption.timeline = timelineOpt;
  18419. } // Preprocess.
  18420. each$4([baseOption].concat(timelineOptions).concat(map(mediaList, function (media) {
  18421. return media.option;
  18422. })), function (option) {
  18423. each$4(optionPreprocessorFuncs, function (preProcess) {
  18424. preProcess(option, isNew);
  18425. });
  18426. });
  18427. return {
  18428. baseOption: baseOption,
  18429. timelineOptions: timelineOptions,
  18430. mediaDefault: mediaDefault,
  18431. mediaList: mediaList
  18432. };
  18433. }
  18434. /**
  18435. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  18436. * Support: width, height, aspectRatio
  18437. * Can use max or min as prefix.
  18438. */
  18439. function applyMediaQuery(query, ecWidth, ecHeight) {
  18440. var realMap = {
  18441. width: ecWidth,
  18442. height: ecHeight,
  18443. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  18444. };
  18445. var applicatable = true;
  18446. each$1(query, function (value, attr) {
  18447. var matched = attr.match(QUERY_REG);
  18448. if (!matched || !matched[1] || !matched[2]) {
  18449. return;
  18450. }
  18451. var operator = matched[1];
  18452. var realAttr = matched[2].toLowerCase();
  18453. if (!compare(realMap[realAttr], value, operator)) {
  18454. applicatable = false;
  18455. }
  18456. });
  18457. return applicatable;
  18458. }
  18459. function compare(real, expect, operator) {
  18460. if (operator === 'min') {
  18461. return real >= expect;
  18462. } else if (operator === 'max') {
  18463. return real <= expect;
  18464. } else {
  18465. // Equals
  18466. return real === expect;
  18467. }
  18468. }
  18469. function indicesEquals(indices1, indices2) {
  18470. // indices is always order by asc and has only finite number.
  18471. return indices1.join(',') === indices2.join(',');
  18472. }
  18473. /**
  18474. * Consider case:
  18475. * `chart.setOption(opt1);`
  18476. * Then user do some interaction like dataZoom, dataView changing.
  18477. * `chart.setOption(opt2);`
  18478. * Then user press 'reset button' in toolbox.
  18479. *
  18480. * After doing that all of the interaction effects should be reset, the
  18481. * chart should be the same as the result of invoke
  18482. * `chart.setOption(opt1); chart.setOption(opt2);`.
  18483. *
  18484. * Although it is not able ensure that
  18485. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  18486. * `chart.setOption(merge(opt1, opt2));` exactly,
  18487. * this might be the only simple way to implement that feature.
  18488. *
  18489. * MEMO: We've considered some other approaches:
  18490. * 1. Each model handle its self restoration but not uniform treatment.
  18491. * (Too complex in logic and error-prone)
  18492. * 2. Use a shadow ecModel. (Performace expensive)
  18493. */
  18494. function mergeOption(oldOption, newOption) {
  18495. newOption = newOption || {};
  18496. each$4(newOption, function (newCptOpt, mainType) {
  18497. if (newCptOpt == null) {
  18498. return;
  18499. }
  18500. var oldCptOpt = oldOption[mainType];
  18501. if (!ComponentModel.hasClass(mainType)) {
  18502. oldOption[mainType] = merge$1(oldCptOpt, newCptOpt, true);
  18503. } else {
  18504. newCptOpt = normalizeToArray(newCptOpt);
  18505. oldCptOpt = normalizeToArray(oldCptOpt);
  18506. var mapResult = mappingToExists(oldCptOpt, newCptOpt);
  18507. oldOption[mainType] = map$1(mapResult, function (item) {
  18508. return item.option && item.exist ? merge$1(item.exist, item.option, true) : item.exist || item.option;
  18509. });
  18510. }
  18511. });
  18512. }
  18513. /*
  18514. * Licensed to the Apache Software Foundation (ASF) under one
  18515. * or more contributor license agreements. See the NOTICE file
  18516. * distributed with this work for additional information
  18517. * regarding copyright ownership. The ASF licenses this file
  18518. * to you under the Apache License, Version 2.0 (the
  18519. * "License"); you may not use this file except in compliance
  18520. * with the License. You may obtain a copy of the License at
  18521. *
  18522. * http://www.apache.org/licenses/LICENSE-2.0
  18523. *
  18524. * Unless required by applicable law or agreed to in writing,
  18525. * software distributed under the License is distributed on an
  18526. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18527. * KIND, either express or implied. See the License for the
  18528. * specific language governing permissions and limitations
  18529. * under the License.
  18530. */
  18531. var each$5 = each$1;
  18532. var isObject$3 = isObject$1;
  18533. var POSSIBLE_STYLES = ['areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle', 'chordStyle', 'label', 'labelLine'];
  18534. function compatEC2ItemStyle(opt) {
  18535. var itemStyleOpt = opt && opt.itemStyle;
  18536. if (!itemStyleOpt) {
  18537. return;
  18538. }
  18539. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  18540. var styleName = POSSIBLE_STYLES[i];
  18541. var normalItemStyleOpt = itemStyleOpt.normal;
  18542. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  18543. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  18544. opt[styleName] = opt[styleName] || {};
  18545. if (!opt[styleName].normal) {
  18546. opt[styleName].normal = normalItemStyleOpt[styleName];
  18547. } else {
  18548. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  18549. }
  18550. normalItemStyleOpt[styleName] = null;
  18551. }
  18552. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  18553. opt[styleName] = opt[styleName] || {};
  18554. if (!opt[styleName].emphasis) {
  18555. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  18556. } else {
  18557. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  18558. }
  18559. emphasisItemStyleOpt[styleName] = null;
  18560. }
  18561. }
  18562. }
  18563. function convertNormalEmphasis(opt, optType, useExtend) {
  18564. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  18565. var normalOpt = opt[optType].normal;
  18566. var emphasisOpt = opt[optType].emphasis;
  18567. if (normalOpt) {
  18568. // Timeline controlStyle has other properties besides normal and emphasis
  18569. if (useExtend) {
  18570. opt[optType].normal = opt[optType].emphasis = null;
  18571. defaults(opt[optType], normalOpt);
  18572. } else {
  18573. opt[optType] = normalOpt;
  18574. }
  18575. }
  18576. if (emphasisOpt) {
  18577. opt.emphasis = opt.emphasis || {};
  18578. opt.emphasis[optType] = emphasisOpt;
  18579. }
  18580. }
  18581. }
  18582. function removeEC3NormalStatus(opt) {
  18583. convertNormalEmphasis(opt, 'itemStyle');
  18584. convertNormalEmphasis(opt, 'lineStyle');
  18585. convertNormalEmphasis(opt, 'areaStyle');
  18586. convertNormalEmphasis(opt, 'label');
  18587. convertNormalEmphasis(opt, 'labelLine'); // treemap
  18588. convertNormalEmphasis(opt, 'upperLabel'); // graph
  18589. convertNormalEmphasis(opt, 'edgeLabel');
  18590. }
  18591. function compatTextStyle(opt, propName) {
  18592. // Check whether is not object (string\null\undefined ...)
  18593. var labelOptSingle = isObject$3(opt) && opt[propName];
  18594. var textStyle = isObject$3(labelOptSingle) && labelOptSingle.textStyle;
  18595. if (textStyle) {
  18596. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  18597. var propName = TEXT_STYLE_OPTIONS[i];
  18598. if (textStyle.hasOwnProperty(propName)) {
  18599. labelOptSingle[propName] = textStyle[propName];
  18600. }
  18601. }
  18602. }
  18603. }
  18604. function compatEC3CommonStyles(opt) {
  18605. if (opt) {
  18606. removeEC3NormalStatus(opt);
  18607. compatTextStyle(opt, 'label');
  18608. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  18609. }
  18610. }
  18611. function processSeries(seriesOpt) {
  18612. if (!isObject$3(seriesOpt)) {
  18613. return;
  18614. }
  18615. compatEC2ItemStyle(seriesOpt);
  18616. removeEC3NormalStatus(seriesOpt);
  18617. compatTextStyle(seriesOpt, 'label'); // treemap
  18618. compatTextStyle(seriesOpt, 'upperLabel'); // graph
  18619. compatTextStyle(seriesOpt, 'edgeLabel');
  18620. if (seriesOpt.emphasis) {
  18621. compatTextStyle(seriesOpt.emphasis, 'label'); // treemap
  18622. compatTextStyle(seriesOpt.emphasis, 'upperLabel'); // graph
  18623. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  18624. }
  18625. var markPoint = seriesOpt.markPoint;
  18626. if (markPoint) {
  18627. compatEC2ItemStyle(markPoint);
  18628. compatEC3CommonStyles(markPoint);
  18629. }
  18630. var markLine = seriesOpt.markLine;
  18631. if (markLine) {
  18632. compatEC2ItemStyle(markLine);
  18633. compatEC3CommonStyles(markLine);
  18634. }
  18635. var markArea = seriesOpt.markArea;
  18636. if (markArea) {
  18637. compatEC3CommonStyles(markArea);
  18638. }
  18639. var data = seriesOpt.data; // Break with ec3: if `setOption` again, there may be no `type` in option,
  18640. // then the backward compat based on option type will not be performed.
  18641. if (seriesOpt.type === 'graph') {
  18642. data = data || seriesOpt.nodes;
  18643. var edgeData = seriesOpt.links || seriesOpt.edges;
  18644. if (edgeData && !isTypedArray(edgeData)) {
  18645. for (var i = 0; i < edgeData.length; i++) {
  18646. compatEC3CommonStyles(edgeData[i]);
  18647. }
  18648. }
  18649. each$1(seriesOpt.categories, function (opt) {
  18650. removeEC3NormalStatus(opt);
  18651. });
  18652. }
  18653. if (data && !isTypedArray(data)) {
  18654. for (var i = 0; i < data.length; i++) {
  18655. compatEC3CommonStyles(data[i]);
  18656. }
  18657. } // mark point data
  18658. var markPoint = seriesOpt.markPoint;
  18659. if (markPoint && markPoint.data) {
  18660. var mpData = markPoint.data;
  18661. for (var i = 0; i < mpData.length; i++) {
  18662. compatEC3CommonStyles(mpData[i]);
  18663. }
  18664. } // mark line data
  18665. var markLine = seriesOpt.markLine;
  18666. if (markLine && markLine.data) {
  18667. var mlData = markLine.data;
  18668. for (var i = 0; i < mlData.length; i++) {
  18669. if (isArray(mlData[i])) {
  18670. compatEC3CommonStyles(mlData[i][0]);
  18671. compatEC3CommonStyles(mlData[i][1]);
  18672. } else {
  18673. compatEC3CommonStyles(mlData[i]);
  18674. }
  18675. }
  18676. } // Series
  18677. if (seriesOpt.type === 'gauge') {
  18678. compatTextStyle(seriesOpt, 'axisLabel');
  18679. compatTextStyle(seriesOpt, 'title');
  18680. compatTextStyle(seriesOpt, 'detail');
  18681. } else if (seriesOpt.type === 'treemap') {
  18682. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  18683. each$1(seriesOpt.levels, function (opt) {
  18684. removeEC3NormalStatus(opt);
  18685. });
  18686. } else if (seriesOpt.type === 'tree') {
  18687. removeEC3NormalStatus(seriesOpt.leaves);
  18688. } // sunburst starts from ec4, so it does not need to compat levels.
  18689. }
  18690. function toArr(o) {
  18691. return isArray(o) ? o : o ? [o] : [];
  18692. }
  18693. function toObj(o) {
  18694. return (isArray(o) ? o[0] : o) || {};
  18695. }
  18696. var compatStyle = function (option, isTheme) {
  18697. each$5(toArr(option.series), function (seriesOpt) {
  18698. isObject$3(seriesOpt) && processSeries(seriesOpt);
  18699. });
  18700. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  18701. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  18702. each$5(axes, function (axisName) {
  18703. each$5(toArr(option[axisName]), function (axisOpt) {
  18704. if (axisOpt) {
  18705. compatTextStyle(axisOpt, 'axisLabel');
  18706. compatTextStyle(axisOpt.axisPointer, 'label');
  18707. }
  18708. });
  18709. });
  18710. each$5(toArr(option.parallel), function (parallelOpt) {
  18711. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  18712. compatTextStyle(parallelAxisDefault, 'axisLabel');
  18713. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  18714. });
  18715. each$5(toArr(option.calendar), function (calendarOpt) {
  18716. convertNormalEmphasis(calendarOpt, 'itemStyle');
  18717. compatTextStyle(calendarOpt, 'dayLabel');
  18718. compatTextStyle(calendarOpt, 'monthLabel');
  18719. compatTextStyle(calendarOpt, 'yearLabel');
  18720. }); // radar.name.textStyle
  18721. each$5(toArr(option.radar), function (radarOpt) {
  18722. compatTextStyle(radarOpt, 'name');
  18723. });
  18724. each$5(toArr(option.geo), function (geoOpt) {
  18725. if (isObject$3(geoOpt)) {
  18726. compatEC3CommonStyles(geoOpt);
  18727. each$5(toArr(geoOpt.regions), function (regionObj) {
  18728. compatEC3CommonStyles(regionObj);
  18729. });
  18730. }
  18731. });
  18732. each$5(toArr(option.timeline), function (timelineOpt) {
  18733. compatEC3CommonStyles(timelineOpt);
  18734. convertNormalEmphasis(timelineOpt, 'label');
  18735. convertNormalEmphasis(timelineOpt, 'itemStyle');
  18736. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  18737. var data = timelineOpt.data;
  18738. isArray(data) && each$1(data, function (item) {
  18739. if (isObject$1(item)) {
  18740. convertNormalEmphasis(item, 'label');
  18741. convertNormalEmphasis(item, 'itemStyle');
  18742. }
  18743. });
  18744. });
  18745. each$5(toArr(option.toolbox), function (toolboxOpt) {
  18746. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  18747. each$5(toolboxOpt.feature, function (featureOpt) {
  18748. convertNormalEmphasis(featureOpt, 'iconStyle');
  18749. });
  18750. });
  18751. compatTextStyle(toObj(option.axisPointer), 'label');
  18752. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  18753. };
  18754. /*
  18755. * Licensed to the Apache Software Foundation (ASF) under one
  18756. * or more contributor license agreements. See the NOTICE file
  18757. * distributed with this work for additional information
  18758. * regarding copyright ownership. The ASF licenses this file
  18759. * to you under the Apache License, Version 2.0 (the
  18760. * "License"); you may not use this file except in compliance
  18761. * with the License. You may obtain a copy of the License at
  18762. *
  18763. * http://www.apache.org/licenses/LICENSE-2.0
  18764. *
  18765. * Unless required by applicable law or agreed to in writing,
  18766. * software distributed under the License is distributed on an
  18767. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18768. * KIND, either express or implied. See the License for the
  18769. * specific language governing permissions and limitations
  18770. * under the License.
  18771. */
  18772. // Compatitable with 2.0
  18773. function get(opt, path) {
  18774. path = path.split(',');
  18775. var obj = opt;
  18776. for (var i = 0; i < path.length; i++) {
  18777. obj = obj && obj[path[i]];
  18778. if (obj == null) {
  18779. break;
  18780. }
  18781. }
  18782. return obj;
  18783. }
  18784. function set$1(opt, path, val, overwrite) {
  18785. path = path.split(',');
  18786. var obj = opt;
  18787. var key;
  18788. for (var i = 0; i < path.length - 1; i++) {
  18789. key = path[i];
  18790. if (obj[key] == null) {
  18791. obj[key] = {};
  18792. }
  18793. obj = obj[key];
  18794. }
  18795. if (overwrite || obj[path[i]] == null) {
  18796. obj[path[i]] = val;
  18797. }
  18798. }
  18799. function compatLayoutProperties(option) {
  18800. each$1(LAYOUT_PROPERTIES, function (prop) {
  18801. if (prop[0] in option && !(prop[1] in option)) {
  18802. option[prop[1]] = option[prop[0]];
  18803. }
  18804. });
  18805. }
  18806. var LAYOUT_PROPERTIES = [['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']];
  18807. var COMPATITABLE_COMPONENTS = ['grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'];
  18808. var backwardCompat = function (option, isTheme) {
  18809. compatStyle(option, isTheme); // Make sure series array for model initialization.
  18810. option.series = normalizeToArray(option.series);
  18811. each$1(option.series, function (seriesOpt) {
  18812. if (!isObject$1(seriesOpt)) {
  18813. return;
  18814. }
  18815. var seriesType = seriesOpt.type;
  18816. if (seriesType === 'line') {
  18817. if (seriesOpt.clipOverflow != null) {
  18818. seriesOpt.clip = seriesOpt.clipOverflow;
  18819. }
  18820. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  18821. if (seriesOpt.clockWise != null) {
  18822. seriesOpt.clockwise = seriesOpt.clockWise;
  18823. }
  18824. } else if (seriesType === 'gauge') {
  18825. var pointerColor = get(seriesOpt, 'pointer.color');
  18826. pointerColor != null && set$1(seriesOpt, 'itemStyle.color', pointerColor);
  18827. }
  18828. compatLayoutProperties(seriesOpt);
  18829. }); // dataRange has changed to visualMap
  18830. if (option.dataRange) {
  18831. option.visualMap = option.dataRange;
  18832. }
  18833. each$1(COMPATITABLE_COMPONENTS, function (componentName) {
  18834. var options = option[componentName];
  18835. if (options) {
  18836. if (!isArray(options)) {
  18837. options = [options];
  18838. }
  18839. each$1(options, function (option) {
  18840. compatLayoutProperties(option);
  18841. });
  18842. }
  18843. });
  18844. };
  18845. /*
  18846. * Licensed to the Apache Software Foundation (ASF) under one
  18847. * or more contributor license agreements. See the NOTICE file
  18848. * distributed with this work for additional information
  18849. * regarding copyright ownership. The ASF licenses this file
  18850. * to you under the Apache License, Version 2.0 (the
  18851. * "License"); you may not use this file except in compliance
  18852. * with the License. You may obtain a copy of the License at
  18853. *
  18854. * http://www.apache.org/licenses/LICENSE-2.0
  18855. *
  18856. * Unless required by applicable law or agreed to in writing,
  18857. * software distributed under the License is distributed on an
  18858. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18859. * KIND, either express or implied. See the License for the
  18860. * specific language governing permissions and limitations
  18861. * under the License.
  18862. */
  18863. // (1) [Caution]: the logic is correct based on the premises:
  18864. // data processing stage is blocked in stream.
  18865. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  18866. // (2) Only register once when import repeatly.
  18867. // Should be executed after series filtered and before stack calculation.
  18868. var dataStack = function (ecModel) {
  18869. var stackInfoMap = createHashMap();
  18870. ecModel.eachSeries(function (seriesModel) {
  18871. var stack = seriesModel.get('stack'); // Compatibal: when `stack` is set as '', do not stack.
  18872. if (stack) {
  18873. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  18874. var data = seriesModel.getData();
  18875. var stackInfo = {
  18876. // Used for calculate axis extent automatically.
  18877. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  18878. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  18879. stackedDimension: data.getCalculationInfo('stackedDimension'),
  18880. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  18881. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  18882. data: data,
  18883. seriesModel: seriesModel
  18884. }; // If stacked on axis that do not support data stack.
  18885. if (!stackInfo.stackedDimension || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)) {
  18886. return;
  18887. }
  18888. stackInfoList.length && data.setCalculationInfo('stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel);
  18889. stackInfoList.push(stackInfo);
  18890. }
  18891. });
  18892. stackInfoMap.each(calculateStack);
  18893. };
  18894. function calculateStack(stackInfoList) {
  18895. each$1(stackInfoList, function (targetStackInfo, idxInStack) {
  18896. var resultVal = [];
  18897. var resultNaN = [NaN, NaN];
  18898. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  18899. var targetData = targetStackInfo.data;
  18900. var isStackedByIndex = targetStackInfo.isStackedByIndex; // Should not write on raw data, because stack series model list changes
  18901. // depending on legend selection.
  18902. var newData = targetData.map(dims, function (v0, v1, dataIndex) {
  18903. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex); // Consider `connectNulls` of line area, if value is NaN, stackedOver
  18904. // should also be NaN, to draw a appropriate belt area.
  18905. if (isNaN(sum)) {
  18906. return resultNaN;
  18907. }
  18908. var byValue;
  18909. var stackedDataRawIndex;
  18910. if (isStackedByIndex) {
  18911. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  18912. } else {
  18913. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  18914. } // If stackOver is NaN, chart view will render point on value start.
  18915. var stackedOver = NaN;
  18916. for (var j = idxInStack - 1; j >= 0; j--) {
  18917. var stackInfo = stackInfoList[j]; // Has been optimized by inverted indices on `stackedByDimension`.
  18918. if (!isStackedByIndex) {
  18919. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  18920. }
  18921. if (stackedDataRawIndex >= 0) {
  18922. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex); // Considering positive stack, negative stack and empty data
  18923. if (sum >= 0 && val > 0 || // Positive stack
  18924. sum <= 0 && val < 0 // Negative stack
  18925. ) {
  18926. sum += val;
  18927. stackedOver = val;
  18928. break;
  18929. }
  18930. }
  18931. }
  18932. resultVal[0] = sum;
  18933. resultVal[1] = stackedOver;
  18934. return resultVal;
  18935. });
  18936. targetData.hostModel.setData(newData); // Update for consequent calculation
  18937. targetStackInfo.data = newData;
  18938. });
  18939. }
  18940. /*
  18941. * Licensed to the Apache Software Foundation (ASF) under one
  18942. * or more contributor license agreements. See the NOTICE file
  18943. * distributed with this work for additional information
  18944. * regarding copyright ownership. The ASF licenses this file
  18945. * to you under the Apache License, Version 2.0 (the
  18946. * "License"); you may not use this file except in compliance
  18947. * with the License. You may obtain a copy of the License at
  18948. *
  18949. * http://www.apache.org/licenses/LICENSE-2.0
  18950. *
  18951. * Unless required by applicable law or agreed to in writing,
  18952. * software distributed under the License is distributed on an
  18953. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18954. * KIND, either express or implied. See the License for the
  18955. * specific language governing permissions and limitations
  18956. * under the License.
  18957. */
  18958. // TODO
  18959. // ??? refactor? check the outer usage of data provider.
  18960. // merge with defaultDimValueGetter?
  18961. /**
  18962. * If normal array used, mutable chunk size is supported.
  18963. * If typed array used, chunk size must be fixed.
  18964. */
  18965. function DefaultDataProvider(source, dimSize) {
  18966. if (!Source.isInstance(source)) {
  18967. source = Source.seriesDataToSource(source);
  18968. }
  18969. this._source = source;
  18970. var data = this._data = source.data;
  18971. var sourceFormat = source.sourceFormat; // Typed array. TODO IE10+?
  18972. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  18973. if (__DEV__) {
  18974. if (dimSize == null) {
  18975. throw new Error('Typed array data must specify dimension size');
  18976. }
  18977. }
  18978. this._offset = 0;
  18979. this._dimSize = dimSize;
  18980. this._data = data;
  18981. }
  18982. var methods = providerMethods[sourceFormat === SOURCE_FORMAT_ARRAY_ROWS ? sourceFormat + '_' + source.seriesLayoutBy : sourceFormat];
  18983. if (__DEV__) {
  18984. assert$1(methods, 'Invalide sourceFormat: ' + sourceFormat);
  18985. }
  18986. extend(this, methods);
  18987. }
  18988. var providerProto = DefaultDataProvider.prototype; // If data is pure without style configuration
  18989. providerProto.pure = false; // If data is persistent and will not be released after use.
  18990. providerProto.persistent = true; // ???! FIXME legacy data provider do not has method getSource
  18991. providerProto.getSource = function () {
  18992. return this._source;
  18993. };
  18994. var providerMethods = {
  18995. 'arrayRows_column': {
  18996. pure: true,
  18997. count: function () {
  18998. return Math.max(0, this._data.length - this._source.startIndex);
  18999. },
  19000. getItem: function (idx) {
  19001. return this._data[idx + this._source.startIndex];
  19002. },
  19003. appendData: appendDataSimply
  19004. },
  19005. 'arrayRows_row': {
  19006. pure: true,
  19007. count: function () {
  19008. var row = this._data[0];
  19009. return row ? Math.max(0, row.length - this._source.startIndex) : 0;
  19010. },
  19011. getItem: function (idx) {
  19012. idx += this._source.startIndex;
  19013. var item = [];
  19014. var data = this._data;
  19015. for (var i = 0; i < data.length; i++) {
  19016. var row = data[i];
  19017. item.push(row ? row[idx] : null);
  19018. }
  19019. return item;
  19020. },
  19021. appendData: function () {
  19022. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  19023. }
  19024. },
  19025. 'objectRows': {
  19026. pure: true,
  19027. count: countSimply,
  19028. getItem: getItemSimply,
  19029. appendData: appendDataSimply
  19030. },
  19031. 'keyedColumns': {
  19032. pure: true,
  19033. count: function () {
  19034. var dimName = this._source.dimensionsDefine[0].name;
  19035. var col = this._data[dimName];
  19036. return col ? col.length : 0;
  19037. },
  19038. getItem: function (idx) {
  19039. var item = [];
  19040. var dims = this._source.dimensionsDefine;
  19041. for (var i = 0; i < dims.length; i++) {
  19042. var col = this._data[dims[i].name];
  19043. item.push(col ? col[idx] : null);
  19044. }
  19045. return item;
  19046. },
  19047. appendData: function (newData) {
  19048. var data = this._data;
  19049. each$1(newData, function (newCol, key) {
  19050. var oldCol = data[key] || (data[key] = []);
  19051. for (var i = 0; i < (newCol || []).length; i++) {
  19052. oldCol.push(newCol[i]);
  19053. }
  19054. });
  19055. }
  19056. },
  19057. 'original': {
  19058. count: countSimply,
  19059. getItem: getItemSimply,
  19060. appendData: appendDataSimply
  19061. },
  19062. 'typedArray': {
  19063. persistent: false,
  19064. pure: true,
  19065. count: function () {
  19066. return this._data ? this._data.length / this._dimSize : 0;
  19067. },
  19068. getItem: function (idx, out) {
  19069. idx = idx - this._offset;
  19070. out = out || [];
  19071. var offset = this._dimSize * idx;
  19072. for (var i = 0; i < this._dimSize; i++) {
  19073. out[i] = this._data[offset + i];
  19074. }
  19075. return out;
  19076. },
  19077. appendData: function (newData) {
  19078. if (__DEV__) {
  19079. assert$1(isTypedArray(newData), 'Added data must be TypedArray if data in initialization is TypedArray');
  19080. }
  19081. this._data = newData;
  19082. },
  19083. // Clean self if data is already used.
  19084. clean: function () {
  19085. // PENDING
  19086. this._offset += this.count();
  19087. this._data = null;
  19088. }
  19089. }
  19090. };
  19091. function countSimply() {
  19092. return this._data.length;
  19093. }
  19094. function getItemSimply(idx) {
  19095. return this._data[idx];
  19096. }
  19097. function appendDataSimply(newData) {
  19098. for (var i = 0; i < newData.length; i++) {
  19099. this._data.push(newData[i]);
  19100. }
  19101. }
  19102. var rawValueGetters = {
  19103. arrayRows: getRawValueSimply,
  19104. objectRows: function (dataItem, dataIndex, dimIndex, dimName) {
  19105. return dimIndex != null ? dataItem[dimName] : dataItem;
  19106. },
  19107. keyedColumns: getRawValueSimply,
  19108. original: function (dataItem, dataIndex, dimIndex, dimName) {
  19109. // FIXME
  19110. // In some case (markpoint in geo (geo-map.html)), dataItem
  19111. // is {coord: [...]}
  19112. var value = getDataItemValue(dataItem);
  19113. return dimIndex == null || !(value instanceof Array) ? value : value[dimIndex];
  19114. },
  19115. typedArray: getRawValueSimply
  19116. };
  19117. function getRawValueSimply(dataItem, dataIndex, dimIndex, dimName) {
  19118. return dimIndex != null ? dataItem[dimIndex] : dataItem;
  19119. }
  19120. var defaultDimValueGetters = {
  19121. arrayRows: getDimValueSimply,
  19122. objectRows: function (dataItem, dimName, dataIndex, dimIndex) {
  19123. return converDataValue(dataItem[dimName], this._dimensionInfos[dimName]);
  19124. },
  19125. keyedColumns: getDimValueSimply,
  19126. original: function (dataItem, dimName, dataIndex, dimIndex) {
  19127. // Performance sensitive, do not use modelUtil.getDataItemValue.
  19128. // If dataItem is an plain object with no value field, the var `value`
  19129. // will be assigned with the object, but it will be tread correctly
  19130. // in the `convertDataValue`.
  19131. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value); // If any dataItem is like { value: 10 }
  19132. if (!this._rawData.pure && isDataItemOption(dataItem)) {
  19133. this.hasItemOption = true;
  19134. }
  19135. return converDataValue(value instanceof Array ? value[dimIndex] // If value is a single number or something else not array.
  19136. : value, this._dimensionInfos[dimName]);
  19137. },
  19138. typedArray: function (dataItem, dimName, dataIndex, dimIndex) {
  19139. return dataItem[dimIndex];
  19140. }
  19141. };
  19142. function getDimValueSimply(dataItem, dimName, dataIndex, dimIndex) {
  19143. return converDataValue(dataItem[dimIndex], this._dimensionInfos[dimName]);
  19144. }
  19145. /**
  19146. * This helper method convert value in data.
  19147. * @param {string|number|Date} value
  19148. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  19149. * If "dimInfo.ordinalParseAndSave", ordinal value can be parsed.
  19150. */
  19151. function converDataValue(value, dimInfo) {
  19152. // Performance sensitive.
  19153. var dimType = dimInfo && dimInfo.type;
  19154. if (dimType === 'ordinal') {
  19155. // If given value is a category string
  19156. var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
  19157. return ordinalMeta ? ordinalMeta.parseAndCollect(value) : value;
  19158. }
  19159. if (dimType === 'time' // spead up when using timestamp
  19160. && typeof value !== 'number' && value != null && value !== '-') {
  19161. value = +parseDate(value);
  19162. } // dimType defaults 'number'.
  19163. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  19164. // parse to NaN.
  19165. return value == null || value === '' ? NaN // If string (like '-'), using '+' parse to NaN
  19166. // If object, also parse to NaN
  19167. : +value;
  19168. } // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  19169. // Consider persistent.
  19170. // Caution: why use raw value to display on label or tooltip?
  19171. // A reason is to avoid format. For example time value we do not know
  19172. // how to format is expected. More over, if stack is used, calculated
  19173. // value may be 0.91000000001, which have brings trouble to display.
  19174. // TODO: consider how to treat null/undefined/NaN when display?
  19175. /**
  19176. * @param {module:echarts/data/List} data
  19177. * @param {number} dataIndex
  19178. * @param {string|number} [dim] dimName or dimIndex
  19179. * @return {Array.<number>|string|number} can be null/undefined.
  19180. */
  19181. function retrieveRawValue(data, dataIndex, dim) {
  19182. if (!data) {
  19183. return;
  19184. } // Consider data may be not persistent.
  19185. var dataItem = data.getRawDataItem(dataIndex);
  19186. if (dataItem == null) {
  19187. return;
  19188. }
  19189. var sourceFormat = data.getProvider().getSource().sourceFormat;
  19190. var dimName;
  19191. var dimIndex;
  19192. var dimInfo = data.getDimensionInfo(dim);
  19193. if (dimInfo) {
  19194. dimName = dimInfo.name;
  19195. dimIndex = dimInfo.index;
  19196. }
  19197. return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);
  19198. }
  19199. /**
  19200. * Compatible with some cases (in pie, map) like:
  19201. * data: [{name: 'xx', value: 5, selected: true}, ...]
  19202. * where only sourceFormat is 'original' and 'objectRows' supported.
  19203. *
  19204. * ??? TODO
  19205. * Supported detail options in data item when using 'arrayRows'.
  19206. *
  19207. * @param {module:echarts/data/List} data
  19208. * @param {number} dataIndex
  19209. * @param {string} attr like 'selected'
  19210. */
  19211. /*
  19212. * Licensed to the Apache Software Foundation (ASF) under one
  19213. * or more contributor license agreements. See the NOTICE file
  19214. * distributed with this work for additional information
  19215. * regarding copyright ownership. The ASF licenses this file
  19216. * to you under the Apache License, Version 2.0 (the
  19217. * "License"); you may not use this file except in compliance
  19218. * with the License. You may obtain a copy of the License at
  19219. *
  19220. * http://www.apache.org/licenses/LICENSE-2.0
  19221. *
  19222. * Unless required by applicable law or agreed to in writing,
  19223. * software distributed under the License is distributed on an
  19224. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19225. * KIND, either express or implied. See the License for the
  19226. * specific language governing permissions and limitations
  19227. * under the License.
  19228. */
  19229. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g; // PENDING A little ugly
  19230. var dataFormatMixin = {
  19231. /**
  19232. * Get params for formatter
  19233. * @param {number} dataIndex
  19234. * @param {string} [dataType]
  19235. * @return {Object}
  19236. */
  19237. getDataParams: function (dataIndex, dataType) {
  19238. var data = this.getData(dataType);
  19239. var rawValue = this.getRawValue(dataIndex, dataType);
  19240. var rawDataIndex = data.getRawIndex(dataIndex);
  19241. var name = data.getName(dataIndex);
  19242. var itemOpt = data.getRawDataItem(dataIndex);
  19243. var color = data.getItemVisual(dataIndex, 'color');
  19244. var borderColor = data.getItemVisual(dataIndex, 'borderColor');
  19245. var tooltipModel = this.ecModel.getComponent('tooltip');
  19246. var renderModeOption = tooltipModel && tooltipModel.get('renderMode');
  19247. var renderMode = getTooltipRenderMode(renderModeOption);
  19248. var mainType = this.mainType;
  19249. var isSeries = mainType === 'series';
  19250. var userOutput = data.userOutput;
  19251. return {
  19252. componentType: mainType,
  19253. componentSubType: this.subType,
  19254. componentIndex: this.componentIndex,
  19255. seriesType: isSeries ? this.subType : null,
  19256. seriesIndex: this.seriesIndex,
  19257. seriesId: isSeries ? this.id : null,
  19258. seriesName: isSeries ? this.name : null,
  19259. name: name,
  19260. dataIndex: rawDataIndex,
  19261. data: itemOpt,
  19262. dataType: dataType,
  19263. value: rawValue,
  19264. color: color,
  19265. borderColor: borderColor,
  19266. dimensionNames: userOutput ? userOutput.dimensionNames : null,
  19267. encode: userOutput ? userOutput.encode : null,
  19268. marker: getTooltipMarker({
  19269. color: color,
  19270. renderMode: renderMode
  19271. }),
  19272. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  19273. $vars: ['seriesName', 'name', 'value']
  19274. };
  19275. },
  19276. /**
  19277. * Format label
  19278. * @param {number} dataIndex
  19279. * @param {string} [status='normal'] 'normal' or 'emphasis'
  19280. * @param {string} [dataType]
  19281. * @param {number} [dimIndex] Only used in some chart that
  19282. * use formatter in different dimensions, like radar.
  19283. * @param {string} [labelProp='label']
  19284. * @return {string} If not formatter, return null/undefined
  19285. */
  19286. getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {
  19287. status = status || 'normal';
  19288. var data = this.getData(dataType);
  19289. var itemModel = data.getItemModel(dataIndex);
  19290. var params = this.getDataParams(dataIndex, dataType);
  19291. if (dimIndex != null && params.value instanceof Array) {
  19292. params.value = params.value[dimIndex];
  19293. }
  19294. var formatter = itemModel.get(status === 'normal' ? [labelProp || 'label', 'formatter'] : [status, labelProp || 'label', 'formatter']);
  19295. if (typeof formatter === 'function') {
  19296. params.status = status;
  19297. params.dimensionIndex = dimIndex;
  19298. return formatter(params);
  19299. } else if (typeof formatter === 'string') {
  19300. var str = formatTpl(formatter, params); // Support 'aaa{@[3]}bbb{@product}ccc'.
  19301. // Do not support '}' in dim name util have to.
  19302. return str.replace(DIMENSION_LABEL_REG, function (origin, dim) {
  19303. var len = dim.length;
  19304. if (dim.charAt(0) === '[' && dim.charAt(len - 1) === ']') {
  19305. dim = +dim.slice(1, len - 1); // Also: '[]' => 0
  19306. }
  19307. return retrieveRawValue(data, dataIndex, dim);
  19308. });
  19309. }
  19310. },
  19311. /**
  19312. * Get raw value in option
  19313. * @param {number} idx
  19314. * @param {string} [dataType]
  19315. * @return {Array|number|string}
  19316. */
  19317. getRawValue: function (idx, dataType) {
  19318. return retrieveRawValue(this.getData(dataType), idx);
  19319. },
  19320. /**
  19321. * Should be implemented.
  19322. * @param {number} dataIndex
  19323. * @param {boolean} [multipleSeries=false]
  19324. * @param {number} [dataType]
  19325. * @return {string} tooltip string
  19326. */
  19327. formatTooltip: function () {// Empty function
  19328. }
  19329. };
  19330. /*
  19331. * Licensed to the Apache Software Foundation (ASF) under one
  19332. * or more contributor license agreements. See the NOTICE file
  19333. * distributed with this work for additional information
  19334. * regarding copyright ownership. The ASF licenses this file
  19335. * to you under the Apache License, Version 2.0 (the
  19336. * "License"); you may not use this file except in compliance
  19337. * with the License. You may obtain a copy of the License at
  19338. *
  19339. * http://www.apache.org/licenses/LICENSE-2.0
  19340. *
  19341. * Unless required by applicable law or agreed to in writing,
  19342. * software distributed under the License is distributed on an
  19343. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19344. * KIND, either express or implied. See the License for the
  19345. * specific language governing permissions and limitations
  19346. * under the License.
  19347. */
  19348. /**
  19349. * @param {Object} define
  19350. * @return See the return of `createTask`.
  19351. */
  19352. function createTask(define) {
  19353. return new Task(define);
  19354. }
  19355. /**
  19356. * @constructor
  19357. * @param {Object} define
  19358. * @param {Function} define.reset Custom reset
  19359. * @param {Function} [define.plan] Returns 'reset' indicate reset immediately.
  19360. * @param {Function} [define.count] count is used to determin data task.
  19361. * @param {Function} [define.onDirty] count is used to determin data task.
  19362. */
  19363. function Task(define) {
  19364. define = define || {};
  19365. this._reset = define.reset;
  19366. this._plan = define.plan;
  19367. this._count = define.count;
  19368. this._onDirty = define.onDirty;
  19369. this._dirty = true; // Context must be specified implicitly, to
  19370. // avoid miss update context when model changed.
  19371. this.context;
  19372. }
  19373. var taskProto = Task.prototype;
  19374. /**
  19375. * @param {Object} performArgs
  19376. * @param {number} [performArgs.step] Specified step.
  19377. * @param {number} [performArgs.skip] Skip customer perform call.
  19378. * @param {number} [performArgs.modBy] Sampling window size.
  19379. * @param {number} [performArgs.modDataCount] Sampling count.
  19380. */
  19381. taskProto.perform = function (performArgs) {
  19382. var upTask = this._upstream;
  19383. var skip = performArgs && performArgs.skip; // TODO some refactor.
  19384. // Pull data. Must pull data each time, because context.data
  19385. // may be updated by Series.setData.
  19386. if (this._dirty && upTask) {
  19387. var context = this.context;
  19388. context.data = context.outputData = upTask.context.outputData;
  19389. }
  19390. if (this.__pipeline) {
  19391. this.__pipeline.currentTask = this;
  19392. }
  19393. var planResult;
  19394. if (this._plan && !skip) {
  19395. planResult = this._plan(this.context);
  19396. } // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  19397. // elements uniformed distributed when progress, especially when moving or zooming.
  19398. var lastModBy = normalizeModBy(this._modBy);
  19399. var lastModDataCount = this._modDataCount || 0;
  19400. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  19401. var modDataCount = performArgs && performArgs.modDataCount || 0;
  19402. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  19403. planResult = 'reset';
  19404. }
  19405. function normalizeModBy(val) {
  19406. !(val >= 1) && (val = 1); // jshint ignore:line
  19407. return val;
  19408. }
  19409. var forceFirstProgress;
  19410. if (this._dirty || planResult === 'reset') {
  19411. this._dirty = false;
  19412. forceFirstProgress = reset(this, skip);
  19413. }
  19414. this._modBy = modBy;
  19415. this._modDataCount = modDataCount;
  19416. var step = performArgs && performArgs.step;
  19417. if (upTask) {
  19418. if (__DEV__) {
  19419. assert$1(upTask._outputDueEnd != null);
  19420. }
  19421. this._dueEnd = upTask._outputDueEnd;
  19422. } // DataTask or overallTask
  19423. else {
  19424. if (__DEV__) {
  19425. assert$1(!this._progress || this._count);
  19426. }
  19427. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  19428. } // Note: Stubs, that its host overall task let it has progress, has progress.
  19429. // If no progress, pass index from upstream to downstream each time plan called.
  19430. if (this._progress) {
  19431. var start = this._dueIndex;
  19432. var end = Math.min(step != null ? this._dueIndex + step : Infinity, this._dueEnd);
  19433. if (!skip && (forceFirstProgress || start < end)) {
  19434. var progress = this._progress;
  19435. if (isArray(progress)) {
  19436. for (var i = 0; i < progress.length; i++) {
  19437. doProgress(this, progress[i], start, end, modBy, modDataCount);
  19438. }
  19439. } else {
  19440. doProgress(this, progress, start, end, modBy, modDataCount);
  19441. }
  19442. }
  19443. this._dueIndex = end; // If no `outputDueEnd`, assume that output data and
  19444. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  19445. var outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : end;
  19446. if (__DEV__) {
  19447. // ??? Can not rollback.
  19448. assert$1(outputDueEnd >= this._outputDueEnd);
  19449. }
  19450. this._outputDueEnd = outputDueEnd;
  19451. } else {
  19452. // (1) Some overall task has no progress.
  19453. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  19454. // This should always be performed so it can be passed to downstream.
  19455. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : this._dueEnd;
  19456. }
  19457. return this.unfinished();
  19458. };
  19459. var iterator = function () {
  19460. var end;
  19461. var current;
  19462. var modBy;
  19463. var modDataCount;
  19464. var winCount;
  19465. var it = {
  19466. reset: function (s, e, sStep, sCount) {
  19467. current = s;
  19468. end = e;
  19469. modBy = sStep;
  19470. modDataCount = sCount;
  19471. winCount = Math.ceil(modDataCount / modBy);
  19472. it.next = modBy > 1 && modDataCount > 0 ? modNext : sequentialNext;
  19473. }
  19474. };
  19475. return it;
  19476. function sequentialNext() {
  19477. return current < end ? current++ : null;
  19478. }
  19479. function modNext() {
  19480. var dataIndex = current % winCount * modBy + Math.ceil(current / winCount);
  19481. var result = current >= end ? null : dataIndex < modDataCount ? dataIndex // If modDataCount is smaller than data.count() (consider `appendData` case),
  19482. // Use normal linear rendering mode.
  19483. : current;
  19484. current++;
  19485. return result;
  19486. }
  19487. }();
  19488. taskProto.dirty = function () {
  19489. this._dirty = true;
  19490. this._onDirty && this._onDirty(this.context);
  19491. };
  19492. function doProgress(taskIns, progress, start, end, modBy, modDataCount) {
  19493. iterator.reset(start, end, modBy, modDataCount);
  19494. taskIns._callingProgress = progress;
  19495. taskIns._callingProgress({
  19496. start: start,
  19497. end: end,
  19498. count: end - start,
  19499. next: iterator.next
  19500. }, taskIns.context);
  19501. }
  19502. function reset(taskIns, skip) {
  19503. taskIns._dueIndex = taskIns._outputDueEnd = taskIns._dueEnd = 0;
  19504. taskIns._settedOutputEnd = null;
  19505. var progress;
  19506. var forceFirstProgress;
  19507. if (!skip && taskIns._reset) {
  19508. progress = taskIns._reset(taskIns.context);
  19509. if (progress && progress.progress) {
  19510. forceFirstProgress = progress.forceFirstProgress;
  19511. progress = progress.progress;
  19512. } // To simplify no progress checking, array must has item.
  19513. if (isArray(progress) && !progress.length) {
  19514. progress = null;
  19515. }
  19516. }
  19517. taskIns._progress = progress;
  19518. taskIns._modBy = taskIns._modDataCount = null;
  19519. var downstream = taskIns._downstream;
  19520. downstream && downstream.dirty();
  19521. return forceFirstProgress;
  19522. }
  19523. /**
  19524. * @return {boolean}
  19525. */
  19526. taskProto.unfinished = function () {
  19527. return this._progress && this._dueIndex < this._dueEnd;
  19528. };
  19529. /**
  19530. * @param {Object} downTask The downstream task.
  19531. * @return {Object} The downstream task.
  19532. */
  19533. taskProto.pipe = function (downTask) {
  19534. if (__DEV__) {
  19535. assert$1(downTask && !downTask._disposed && downTask !== this);
  19536. } // If already downstream, do not dirty downTask.
  19537. if (this._downstream !== downTask || this._dirty) {
  19538. this._downstream = downTask;
  19539. downTask._upstream = this;
  19540. downTask.dirty();
  19541. }
  19542. };
  19543. taskProto.dispose = function () {
  19544. if (this._disposed) {
  19545. return;
  19546. }
  19547. this._upstream && (this._upstream._downstream = null);
  19548. this._downstream && (this._downstream._upstream = null);
  19549. this._dirty = false;
  19550. this._disposed = true;
  19551. };
  19552. taskProto.getUpstream = function () {
  19553. return this._upstream;
  19554. };
  19555. taskProto.getDownstream = function () {
  19556. return this._downstream;
  19557. };
  19558. taskProto.setOutputEnd = function (end) {
  19559. // This only happend in dataTask, dataZoom, map, currently.
  19560. // where dataZoom do not set end each time, but only set
  19561. // when reset. So we should record the setted end, in case
  19562. // that the stub of dataZoom perform again and earse the
  19563. // setted end by upstream.
  19564. this._outputDueEnd = this._settedOutputEnd = end;
  19565. }; ///////////////////////////////////////////////////////////
  19566. // For stream debug (Should be commented out after used!)
  19567. // Usage: printTask(this, 'begin');
  19568. // Usage: printTask(this, null, {someExtraProp});
  19569. // function printTask(task, prefix, extra) {
  19570. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  19571. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  19572. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  19573. // var props = [];
  19574. // if (task.__pipeline) {
  19575. // var val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  19576. // props.push({text: 'idx', value: val});
  19577. // } else {
  19578. // var stubCount = 0;
  19579. // task.agentStubMap.each(() => stubCount++);
  19580. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  19581. // }
  19582. // props.push({text: 'uid', value: task.uidDebug});
  19583. // if (task.__pipeline) {
  19584. // props.push({text: 'pid', value: task.__pipeline.id});
  19585. // task.agent && props.push(
  19586. // {text: 'stubFor', value: task.agent.uidDebug}
  19587. // );
  19588. // }
  19589. // props.push(
  19590. // {text: 'dirty', value: task._dirty},
  19591. // {text: 'dueIndex', value: task._dueIndex},
  19592. // {text: 'dueEnd', value: task._dueEnd},
  19593. // {text: 'outputDueEnd', value: task._outputDueEnd}
  19594. // );
  19595. // if (extra) {
  19596. // Object.keys(extra).forEach(key => {
  19597. // props.push({text: key, value: extra[key]});
  19598. // });
  19599. // }
  19600. // var args = ['color: blue'];
  19601. // var msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  19602. // args.push('color: black', 'color: red'),
  19603. // `${item.text}: %c${item.value}`
  19604. // )).join('%c, ');
  19605. // console.log.apply(console, [msg].concat(args));
  19606. // // console.log(this);
  19607. // }
  19608. /*
  19609. * Licensed to the Apache Software Foundation (ASF) under one
  19610. * or more contributor license agreements. See the NOTICE file
  19611. * distributed with this work for additional information
  19612. * regarding copyright ownership. The ASF licenses this file
  19613. * to you under the Apache License, Version 2.0 (the
  19614. * "License"); you may not use this file except in compliance
  19615. * with the License. You may obtain a copy of the License at
  19616. *
  19617. * http://www.apache.org/licenses/LICENSE-2.0
  19618. *
  19619. * Unless required by applicable law or agreed to in writing,
  19620. * software distributed under the License is distributed on an
  19621. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19622. * KIND, either express or implied. See the License for the
  19623. * specific language governing permissions and limitations
  19624. * under the License.
  19625. */
  19626. var inner$4 = makeInner();
  19627. var SeriesModel = ComponentModel.extend({
  19628. type: 'series.__base__',
  19629. /**
  19630. * @readOnly
  19631. */
  19632. seriesIndex: 0,
  19633. // coodinateSystem will be injected in the echarts/CoordinateSystem
  19634. coordinateSystem: null,
  19635. /**
  19636. * @type {Object}
  19637. * @protected
  19638. */
  19639. defaultOption: null,
  19640. /**
  19641. * legend visual provider to the legend component
  19642. * @type {Object}
  19643. */
  19644. // PENDING
  19645. legendVisualProvider: null,
  19646. /**
  19647. * Access path of color for visual
  19648. */
  19649. visualColorAccessPath: 'itemStyle.color',
  19650. /**
  19651. * Access path of borderColor for visual
  19652. */
  19653. visualBorderColorAccessPath: 'itemStyle.borderColor',
  19654. /**
  19655. * Support merge layout params.
  19656. * Only support 'box' now (left/right/top/bottom/width/height).
  19657. * @type {string|Object} Object can be {ignoreSize: true}
  19658. * @readOnly
  19659. */
  19660. layoutMode: null,
  19661. init: function (option, parentModel, ecModel, extraOpt) {
  19662. /**
  19663. * @type {number}
  19664. * @readOnly
  19665. */
  19666. this.seriesIndex = this.componentIndex;
  19667. this.dataTask = createTask({
  19668. count: dataTaskCount,
  19669. reset: dataTaskReset
  19670. });
  19671. this.dataTask.context = {
  19672. model: this
  19673. };
  19674. this.mergeDefaultAndTheme(option, ecModel);
  19675. prepareSource(this);
  19676. var data = this.getInitialData(option, ecModel);
  19677. wrapData(data, this);
  19678. this.dataTask.context.data = data;
  19679. if (__DEV__) {
  19680. assert$1(data, 'getInitialData returned invalid data.');
  19681. }
  19682. /**
  19683. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  19684. * @private
  19685. */
  19686. inner$4(this).dataBeforeProcessed = data; // If we reverse the order (make data firstly, and then make
  19687. // dataBeforeProcessed by cloneShallow), cloneShallow will
  19688. // cause data.graph.data !== data when using
  19689. // module:echarts/data/Graph or module:echarts/data/Tree.
  19690. // See module:echarts/data/helper/linkList
  19691. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  19692. // init or merge stage, because the data can be restored. So we do not `restoreData`
  19693. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  19694. // Call `seriesModel.getRawData()` instead.
  19695. // this.restoreData();
  19696. autoSeriesName(this);
  19697. },
  19698. /**
  19699. * Util for merge default and theme to option
  19700. * @param {Object} option
  19701. * @param {module:echarts/model/Global} ecModel
  19702. */
  19703. mergeDefaultAndTheme: function (option, ecModel) {
  19704. var layoutMode = this.layoutMode;
  19705. var inputPositionParams = layoutMode ? getLayoutParams(option) : {}; // Backward compat: using subType on theme.
  19706. // But if name duplicate between series subType
  19707. // (for example: parallel) add component mainType,
  19708. // add suffix 'Series'.
  19709. var themeSubType = this.subType;
  19710. if (ComponentModel.hasClass(themeSubType)) {
  19711. themeSubType += 'Series';
  19712. }
  19713. merge(option, ecModel.getTheme().get(this.subType));
  19714. merge(option, this.getDefaultOption()); // Default label emphasis `show`
  19715. defaultEmphasis(option, 'label', ['show']);
  19716. this.fillDataTextStyle(option.data);
  19717. if (layoutMode) {
  19718. mergeLayoutParam(option, inputPositionParams, layoutMode);
  19719. }
  19720. },
  19721. mergeOption: function (newSeriesOption, ecModel) {
  19722. // this.settingTask.dirty();
  19723. newSeriesOption = merge(this.option, newSeriesOption, true);
  19724. this.fillDataTextStyle(newSeriesOption.data);
  19725. var layoutMode = this.layoutMode;
  19726. if (layoutMode) {
  19727. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  19728. }
  19729. prepareSource(this);
  19730. var data = this.getInitialData(newSeriesOption, ecModel);
  19731. wrapData(data, this);
  19732. this.dataTask.dirty();
  19733. this.dataTask.context.data = data;
  19734. inner$4(this).dataBeforeProcessed = data;
  19735. autoSeriesName(this);
  19736. },
  19737. fillDataTextStyle: function (data) {
  19738. // Default data label emphasis `show`
  19739. // FIXME Tree structure data ?
  19740. // FIXME Performance ?
  19741. if (data && !isTypedArray(data)) {
  19742. var props = ['show'];
  19743. for (var i = 0; i < data.length; i++) {
  19744. if (data[i] && data[i].label) {
  19745. defaultEmphasis(data[i], 'label', props);
  19746. }
  19747. }
  19748. }
  19749. },
  19750. /**
  19751. * Init a data structure from data related option in series
  19752. * Must be overwritten
  19753. */
  19754. getInitialData: function () {},
  19755. /**
  19756. * Append data to list
  19757. * @param {Object} params
  19758. * @param {Array|TypedArray} params.data
  19759. */
  19760. appendData: function (params) {
  19761. // FIXME ???
  19762. // (1) If data from dataset, forbidden append.
  19763. // (2) support append data of dataset.
  19764. var data = this.getRawData();
  19765. data.appendData(params.data);
  19766. },
  19767. /**
  19768. * Consider some method like `filter`, `map` need make new data,
  19769. * We should make sure that `seriesModel.getData()` get correct
  19770. * data in the stream procedure. So we fetch data from upstream
  19771. * each time `task.perform` called.
  19772. * @param {string} [dataType]
  19773. * @return {module:echarts/data/List}
  19774. */
  19775. getData: function (dataType) {
  19776. var task = getCurrentTask(this);
  19777. if (task) {
  19778. var data = task.context.data;
  19779. return dataType == null ? data : data.getLinkedData(dataType);
  19780. } else {
  19781. // When series is not alive (that may happen when click toolbox
  19782. // restore or setOption with not merge mode), series data may
  19783. // be still need to judge animation or something when graphic
  19784. // elements want to know whether fade out.
  19785. return inner$4(this).data;
  19786. }
  19787. },
  19788. /**
  19789. * @param {module:echarts/data/List} data
  19790. */
  19791. setData: function (data) {
  19792. var task = getCurrentTask(this);
  19793. if (task) {
  19794. var context = task.context; // Consider case: filter, data sample.
  19795. if (context.data !== data && task.modifyOutputEnd) {
  19796. task.setOutputEnd(data.count());
  19797. }
  19798. context.outputData = data; // Caution: setData should update context.data,
  19799. // Because getData may be called multiply in a
  19800. // single stage and expect to get the data just
  19801. // set. (For example, AxisProxy, x y both call
  19802. // getData and setDate sequentially).
  19803. // So the context.data should be fetched from
  19804. // upstream each time when a stage starts to be
  19805. // performed.
  19806. if (task !== this.dataTask) {
  19807. context.data = data;
  19808. }
  19809. }
  19810. inner$4(this).data = data;
  19811. },
  19812. /**
  19813. * @see {module:echarts/data/helper/sourceHelper#getSource}
  19814. * @return {module:echarts/data/Source} source
  19815. */
  19816. getSource: function () {
  19817. return getSource(this);
  19818. },
  19819. /**
  19820. * Get data before processed
  19821. * @return {module:echarts/data/List}
  19822. */
  19823. getRawData: function () {
  19824. return inner$4(this).dataBeforeProcessed;
  19825. },
  19826. /**
  19827. * Get base axis if has coordinate system and has axis.
  19828. * By default use coordSys.getBaseAxis();
  19829. * Can be overrided for some chart.
  19830. * @return {type} description
  19831. */
  19832. getBaseAxis: function () {
  19833. var coordSys = this.coordinateSystem;
  19834. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  19835. },
  19836. // FIXME
  19837. /**
  19838. * Default tooltip formatter
  19839. *
  19840. * @param {number} dataIndex
  19841. * @param {boolean} [multipleSeries=false]
  19842. * @param {number} [dataType]
  19843. * @param {string} [renderMode='html'] valid values: 'html' and 'richText'.
  19844. * 'html' is used for rendering tooltip in extra DOM form, and the result
  19845. * string is used as DOM HTML content.
  19846. * 'richText' is used for rendering tooltip in rich text form, for those where
  19847. * DOM operation is not supported.
  19848. * @return {Object} formatted tooltip with `html` and `markers`
  19849. */
  19850. formatTooltip: function (dataIndex, multipleSeries, dataType, renderMode) {
  19851. var series = this;
  19852. renderMode = renderMode || 'html';
  19853. var newLine = renderMode === 'html' ? '<br/>' : '\n';
  19854. var isRichText = renderMode === 'richText';
  19855. var markers = {};
  19856. var markerId = 0;
  19857. function formatArrayValue(value) {
  19858. // ??? TODO refactor these logic.
  19859. // check: category-no-encode-has-axis-data in dataset.html
  19860. var vertially = reduce(value, function (vertially, val, idx) {
  19861. var dimItem = data.getDimensionInfo(idx);
  19862. return vertially |= dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  19863. }, 0);
  19864. var result = [];
  19865. tooltipDims.length ? each$1(tooltipDims, function (dim) {
  19866. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  19867. }) // By default, all dims is used on tooltip.
  19868. : each$1(value, setEachItem);
  19869. function setEachItem(val, dim) {
  19870. var dimInfo = data.getDimensionInfo(dim); // If `dimInfo.tooltip` is not set, show tooltip.
  19871. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  19872. return;
  19873. }
  19874. var dimType = dimInfo.type;
  19875. var markName = 'sub' + series.seriesIndex + 'at' + markerId;
  19876. var dimHead = getTooltipMarker({
  19877. color: color,
  19878. type: 'subItem',
  19879. renderMode: renderMode,
  19880. markerId: markName
  19881. });
  19882. var dimHeadStr = typeof dimHead === 'string' ? dimHead : dimHead.content;
  19883. var valStr = (vertially ? dimHeadStr + encodeHTML(dimInfo.displayName || '-') + ': ' : '') + // FIXME should not format time for raw data?
  19884. encodeHTML(dimType === 'ordinal' ? val + '' : dimType === 'time' ? multipleSeries ? '' : formatTime('yyyy/MM/dd hh:mm:ss', val) : addCommas(val));
  19885. valStr && result.push(valStr);
  19886. if (isRichText) {
  19887. markers[markName] = color;
  19888. ++markerId;
  19889. }
  19890. }
  19891. var newLine = vertially ? isRichText ? '\n' : '<br/>' : '';
  19892. var content = newLine + result.join(newLine || ', ');
  19893. return {
  19894. renderMode: renderMode,
  19895. content: content,
  19896. style: markers
  19897. };
  19898. }
  19899. function formatSingleValue(val) {
  19900. // return encodeHTML(addCommas(val));
  19901. return {
  19902. renderMode: renderMode,
  19903. content: encodeHTML(addCommas(val)),
  19904. style: markers
  19905. };
  19906. }
  19907. var data = this.getData();
  19908. var tooltipDims = data.mapDimension('defaultedTooltip', true);
  19909. var tooltipDimLen = tooltipDims.length;
  19910. var value = this.getRawValue(dataIndex);
  19911. var isValueArr = isArray(value);
  19912. var color = data.getItemVisual(dataIndex, 'color');
  19913. if (isObject$1(color) && color.colorStops) {
  19914. color = (color.colorStops[0] || {}).color;
  19915. }
  19916. color = color || 'transparent'; // Complicated rule for pretty tooltip.
  19917. var formattedValue = tooltipDimLen > 1 || isValueArr && !tooltipDimLen ? formatArrayValue(value) : tooltipDimLen ? formatSingleValue(retrieveRawValue(data, dataIndex, tooltipDims[0])) : formatSingleValue(isValueArr ? value[0] : value);
  19918. var content = formattedValue.content;
  19919. var markName = series.seriesIndex + 'at' + markerId;
  19920. var colorEl = getTooltipMarker({
  19921. color: color,
  19922. type: 'item',
  19923. renderMode: renderMode,
  19924. markerId: markName
  19925. });
  19926. markers[markName] = color;
  19927. ++markerId;
  19928. var name = data.getName(dataIndex);
  19929. var seriesName = this.name;
  19930. if (!isNameSpecified(this)) {
  19931. seriesName = '';
  19932. }
  19933. seriesName = seriesName ? encodeHTML(seriesName) + (!multipleSeries ? newLine : ': ') : '';
  19934. var colorStr = typeof colorEl === 'string' ? colorEl : colorEl.content;
  19935. var html = !multipleSeries ? seriesName + colorStr + (name ? encodeHTML(name) + ': ' + content : content) : colorStr + seriesName + content;
  19936. return {
  19937. html: html,
  19938. markers: markers
  19939. };
  19940. },
  19941. /**
  19942. * @return {boolean}
  19943. */
  19944. isAnimationEnabled: function () {
  19945. if (env$1.node) {
  19946. return false;
  19947. }
  19948. var animationEnabled = this.getShallow('animation');
  19949. if (animationEnabled) {
  19950. if (this.getData().count() > this.getShallow('animationThreshold')) {
  19951. animationEnabled = false;
  19952. }
  19953. }
  19954. return animationEnabled;
  19955. },
  19956. restoreData: function () {
  19957. this.dataTask.dirty();
  19958. },
  19959. getColorFromPalette: function (name, scope, requestColorNum) {
  19960. var ecModel = this.ecModel; // PENDING
  19961. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope, requestColorNum);
  19962. if (!color) {
  19963. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  19964. }
  19965. return color;
  19966. },
  19967. /**
  19968. * Use `data.mapDimension(coordDim, true)` instead.
  19969. * @deprecated
  19970. */
  19971. coordDimToDataDim: function (coordDim) {
  19972. return this.getRawData().mapDimension(coordDim, true);
  19973. },
  19974. /**
  19975. * Get progressive rendering count each step
  19976. * @return {number}
  19977. */
  19978. getProgressive: function () {
  19979. return this.get('progressive');
  19980. },
  19981. /**
  19982. * Get progressive rendering count each step
  19983. * @return {number}
  19984. */
  19985. getProgressiveThreshold: function () {
  19986. return this.get('progressiveThreshold');
  19987. },
  19988. /**
  19989. * Get data indices for show tooltip content. See tooltip.
  19990. * @abstract
  19991. * @param {Array.<string>|string} dim
  19992. * @param {Array.<number>} value
  19993. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  19994. * @return {Object} {dataIndices, nestestValue}.
  19995. */
  19996. getAxisTooltipData: null,
  19997. /**
  19998. * See tooltip.
  19999. * @abstract
  20000. * @param {number} dataIndex
  20001. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  20002. */
  20003. getTooltipPosition: null,
  20004. /**
  20005. * @see {module:echarts/stream/Scheduler}
  20006. */
  20007. pipeTask: null,
  20008. /**
  20009. * Convinient for override in extended class.
  20010. * @protected
  20011. * @type {Function}
  20012. */
  20013. preventIncremental: null,
  20014. /**
  20015. * @public
  20016. * @readOnly
  20017. * @type {Object}
  20018. */
  20019. pipelineContext: null
  20020. });
  20021. mixin(SeriesModel, dataFormatMixin);
  20022. mixin(SeriesModel, colorPaletteMixin);
  20023. /**
  20024. * MUST be called after `prepareSource` called
  20025. * Here we need to make auto series, especially for auto legend. But we
  20026. * do not modify series.name in option to avoid side effects.
  20027. */
  20028. function autoSeriesName(seriesModel) {
  20029. // User specified name has higher priority, otherwise it may cause
  20030. // series can not be queried unexpectedly.
  20031. var name = seriesModel.name;
  20032. if (!isNameSpecified(seriesModel)) {
  20033. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  20034. }
  20035. }
  20036. function getSeriesAutoName(seriesModel) {
  20037. var data = seriesModel.getRawData();
  20038. var dataDims = data.mapDimension('seriesName', true);
  20039. var nameArr = [];
  20040. each$1(dataDims, function (dataDim) {
  20041. var dimInfo = data.getDimensionInfo(dataDim);
  20042. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  20043. });
  20044. return nameArr.join(' ');
  20045. }
  20046. function dataTaskCount(context) {
  20047. return context.model.getRawData().count();
  20048. }
  20049. function dataTaskReset(context) {
  20050. var seriesModel = context.model;
  20051. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  20052. return dataTaskProgress;
  20053. }
  20054. function dataTaskProgress(param, context) {
  20055. // Avoid repead cloneShallow when data just created in reset.
  20056. if (context.outputData && param.end > context.outputData.count()) {
  20057. context.model.getRawData().cloneShallow(context.outputData);
  20058. }
  20059. } // TODO refactor
  20060. function wrapData(data, seriesModel) {
  20061. each$1(data.CHANGABLE_METHODS, function (methodName) {
  20062. data.wrapMethod(methodName, curry(onDataSelfChange, seriesModel));
  20063. });
  20064. }
  20065. function onDataSelfChange(seriesModel) {
  20066. var task = getCurrentTask(seriesModel);
  20067. if (task) {
  20068. // Consider case: filter, selectRange
  20069. task.setOutputEnd(this.count());
  20070. }
  20071. }
  20072. function getCurrentTask(seriesModel) {
  20073. var scheduler = (seriesModel.ecModel || {}).scheduler;
  20074. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  20075. if (pipeline) {
  20076. // When pipline finished, the currrentTask keep the last
  20077. // task (renderTask).
  20078. var task = pipeline.currentTask;
  20079. if (task) {
  20080. var agentStubMap = task.agentStubMap;
  20081. if (agentStubMap) {
  20082. task = agentStubMap.get(seriesModel.uid);
  20083. }
  20084. }
  20085. return task;
  20086. }
  20087. }
  20088. /*
  20089. * Licensed to the Apache Software Foundation (ASF) under one
  20090. * or more contributor license agreements. See the NOTICE file
  20091. * distributed with this work for additional information
  20092. * regarding copyright ownership. The ASF licenses this file
  20093. * to you under the Apache License, Version 2.0 (the
  20094. * "License"); you may not use this file except in compliance
  20095. * with the License. You may obtain a copy of the License at
  20096. *
  20097. * http://www.apache.org/licenses/LICENSE-2.0
  20098. *
  20099. * Unless required by applicable law or agreed to in writing,
  20100. * software distributed under the License is distributed on an
  20101. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20102. * KIND, either express or implied. See the License for the
  20103. * specific language governing permissions and limitations
  20104. * under the License.
  20105. */
  20106. var Component = function () {
  20107. /**
  20108. * @type {module:zrender/container/Group}
  20109. * @readOnly
  20110. */
  20111. this.group = new Group();
  20112. /**
  20113. * @type {string}
  20114. * @readOnly
  20115. */
  20116. this.uid = getUID('viewComponent');
  20117. };
  20118. Component.prototype = {
  20119. constructor: Component,
  20120. init: function (ecModel, api) {},
  20121. render: function (componentModel, ecModel, api, payload) {},
  20122. dispose: function () {},
  20123. /**
  20124. * @param {string} eventType
  20125. * @param {Object} query
  20126. * @param {module:zrender/Element} targetEl
  20127. * @param {Object} packedEvent
  20128. * @return {boolen} Pass only when return `true`.
  20129. */
  20130. filterForExposedEvent: null
  20131. };
  20132. var componentProto = Component.prototype;
  20133. componentProto.updateView = componentProto.updateLayout = componentProto.updateVisual = function (seriesModel, ecModel, api, payload) {// Do nothing;
  20134. }; // Enable Component.extend.
  20135. enableClassExtend(Component); // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  20136. enableClassManagement(Component, {
  20137. registerWhenExtend: true
  20138. });
  20139. /*
  20140. * Licensed to the Apache Software Foundation (ASF) under one
  20141. * or more contributor license agreements. See the NOTICE file
  20142. * distributed with this work for additional information
  20143. * regarding copyright ownership. The ASF licenses this file
  20144. * to you under the Apache License, Version 2.0 (the
  20145. * "License"); you may not use this file except in compliance
  20146. * with the License. You may obtain a copy of the License at
  20147. *
  20148. * http://www.apache.org/licenses/LICENSE-2.0
  20149. *
  20150. * Unless required by applicable law or agreed to in writing,
  20151. * software distributed under the License is distributed on an
  20152. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20153. * KIND, either express or implied. See the License for the
  20154. * specific language governing permissions and limitations
  20155. * under the License.
  20156. */
  20157. /**
  20158. * @return {string} If large mode changed, return string 'reset';
  20159. */
  20160. var createRenderPlanner = function () {
  20161. var inner = makeInner();
  20162. return function (seriesModel) {
  20163. var fields = inner(seriesModel);
  20164. var pipelineContext = seriesModel.pipelineContext;
  20165. var originalLarge = fields.large;
  20166. var originalProgressive = fields.progressiveRender; // FIXME: if the planner works on a filtered series, `pipelineContext` does not
  20167. // exists. See #11611 . Probably we need to modify this structure, see the comment
  20168. // on `performRawSeries` in `Schedular.js`.
  20169. var large = fields.large = pipelineContext && pipelineContext.large;
  20170. var progressive = fields.progressiveRender = pipelineContext && pipelineContext.progressiveRender;
  20171. return !!(originalLarge ^ large || originalProgressive ^ progressive) && 'reset';
  20172. };
  20173. };
  20174. /*
  20175. * Licensed to the Apache Software Foundation (ASF) under one
  20176. * or more contributor license agreements. See the NOTICE file
  20177. * distributed with this work for additional information
  20178. * regarding copyright ownership. The ASF licenses this file
  20179. * to you under the Apache License, Version 2.0 (the
  20180. * "License"); you may not use this file except in compliance
  20181. * with the License. You may obtain a copy of the License at
  20182. *
  20183. * http://www.apache.org/licenses/LICENSE-2.0
  20184. *
  20185. * Unless required by applicable law or agreed to in writing,
  20186. * software distributed under the License is distributed on an
  20187. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20188. * KIND, either express or implied. See the License for the
  20189. * specific language governing permissions and limitations
  20190. * under the License.
  20191. */
  20192. var inner$5 = makeInner();
  20193. var renderPlanner = createRenderPlanner();
  20194. function Chart() {
  20195. /**
  20196. * @type {module:zrender/container/Group}
  20197. * @readOnly
  20198. */
  20199. this.group = new Group();
  20200. /**
  20201. * @type {string}
  20202. * @readOnly
  20203. */
  20204. this.uid = getUID('viewChart');
  20205. this.renderTask = createTask({
  20206. plan: renderTaskPlan,
  20207. reset: renderTaskReset
  20208. });
  20209. this.renderTask.context = {
  20210. view: this
  20211. };
  20212. }
  20213. Chart.prototype = {
  20214. type: 'chart',
  20215. /**
  20216. * Init the chart.
  20217. * @param {module:echarts/model/Global} ecModel
  20218. * @param {module:echarts/ExtensionAPI} api
  20219. */
  20220. init: function (ecModel, api) {},
  20221. /**
  20222. * Render the chart.
  20223. * @param {module:echarts/model/Series} seriesModel
  20224. * @param {module:echarts/model/Global} ecModel
  20225. * @param {module:echarts/ExtensionAPI} api
  20226. * @param {Object} payload
  20227. */
  20228. render: function (seriesModel, ecModel, api, payload) {},
  20229. /**
  20230. * Highlight series or specified data item.
  20231. * @param {module:echarts/model/Series} seriesModel
  20232. * @param {module:echarts/model/Global} ecModel
  20233. * @param {module:echarts/ExtensionAPI} api
  20234. * @param {Object} payload
  20235. */
  20236. highlight: function (seriesModel, ecModel, api, payload) {
  20237. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  20238. },
  20239. /**
  20240. * Downplay series or specified data item.
  20241. * @param {module:echarts/model/Series} seriesModel
  20242. * @param {module:echarts/model/Global} ecModel
  20243. * @param {module:echarts/ExtensionAPI} api
  20244. * @param {Object} payload
  20245. */
  20246. downplay: function (seriesModel, ecModel, api, payload) {
  20247. toggleHighlight(seriesModel.getData(), payload, 'normal');
  20248. },
  20249. /**
  20250. * Remove self.
  20251. * @param {module:echarts/model/Global} ecModel
  20252. * @param {module:echarts/ExtensionAPI} api
  20253. */
  20254. remove: function (ecModel, api) {
  20255. this.group.removeAll();
  20256. },
  20257. /**
  20258. * Dispose self.
  20259. * @param {module:echarts/model/Global} ecModel
  20260. * @param {module:echarts/ExtensionAPI} api
  20261. */
  20262. dispose: function () {},
  20263. /**
  20264. * Rendering preparation in progressive mode.
  20265. * @param {module:echarts/model/Series} seriesModel
  20266. * @param {module:echarts/model/Global} ecModel
  20267. * @param {module:echarts/ExtensionAPI} api
  20268. * @param {Object} payload
  20269. */
  20270. incrementalPrepareRender: null,
  20271. /**
  20272. * Render in progressive mode.
  20273. * @param {Object} params See taskParams in `stream/task.js`
  20274. * @param {module:echarts/model/Series} seriesModel
  20275. * @param {module:echarts/model/Global} ecModel
  20276. * @param {module:echarts/ExtensionAPI} api
  20277. * @param {Object} payload
  20278. */
  20279. incrementalRender: null,
  20280. /**
  20281. * Update transform directly.
  20282. * @param {module:echarts/model/Series} seriesModel
  20283. * @param {module:echarts/model/Global} ecModel
  20284. * @param {module:echarts/ExtensionAPI} api
  20285. * @param {Object} payload
  20286. * @return {Object} {update: true}
  20287. */
  20288. updateTransform: null,
  20289. /**
  20290. * The view contains the given point.
  20291. * @interface
  20292. * @param {Array.<number>} point
  20293. * @return {boolean}
  20294. */
  20295. // containPoint: function () {}
  20296. /**
  20297. * @param {string} eventType
  20298. * @param {Object} query
  20299. * @param {module:zrender/Element} targetEl
  20300. * @param {Object} packedEvent
  20301. * @return {boolen} Pass only when return `true`.
  20302. */
  20303. filterForExposedEvent: null
  20304. };
  20305. var chartProto = Chart.prototype;
  20306. chartProto.updateView = chartProto.updateLayout = chartProto.updateVisual = function (seriesModel, ecModel, api, payload) {
  20307. this.render(seriesModel, ecModel, api, payload);
  20308. };
  20309. /**
  20310. * Set state of single element
  20311. * @param {module:zrender/Element} el
  20312. * @param {string} state 'normal'|'emphasis'
  20313. * @param {number} highlightDigit
  20314. */
  20315. function elSetState(el, state, highlightDigit) {
  20316. if (el) {
  20317. el.trigger(state, highlightDigit);
  20318. if (el.isGroup // Simple optimize.
  20319. && !isHighDownDispatcher(el)) {
  20320. for (var i = 0, len = el.childCount(); i < len; i++) {
  20321. elSetState(el.childAt(i), state, highlightDigit);
  20322. }
  20323. }
  20324. }
  20325. }
  20326. /**
  20327. * @param {module:echarts/data/List} data
  20328. * @param {Object} payload
  20329. * @param {string} state 'normal'|'emphasis'
  20330. */
  20331. function toggleHighlight(data, payload, state) {
  20332. var dataIndex = queryDataIndex(data, payload);
  20333. var highlightDigit = payload && payload.highlightKey != null ? getHighlightDigit(payload.highlightKey) : null;
  20334. if (dataIndex != null) {
  20335. each$1(normalizeToArray(dataIndex), function (dataIdx) {
  20336. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  20337. });
  20338. } else {
  20339. data.eachItemGraphicEl(function (el) {
  20340. elSetState(el, state, highlightDigit);
  20341. });
  20342. }
  20343. } // Enable Chart.extend.
  20344. enableClassExtend(Chart, ['dispose']); // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  20345. enableClassManagement(Chart, {
  20346. registerWhenExtend: true
  20347. });
  20348. Chart.markUpdateMethod = function (payload, methodName) {
  20349. inner$5(payload).updateMethod = methodName;
  20350. };
  20351. function renderTaskPlan(context) {
  20352. return renderPlanner(context.model);
  20353. }
  20354. function renderTaskReset(context) {
  20355. var seriesModel = context.model;
  20356. var ecModel = context.ecModel;
  20357. var api = context.api;
  20358. var payload = context.payload; // ???! remove updateView updateVisual
  20359. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  20360. var view = context.view;
  20361. var updateMethod = payload && inner$5(payload).updateMethod;
  20362. var methodName = progressiveRender ? 'incrementalPrepareRender' : updateMethod && view[updateMethod] ? updateMethod // `appendData` is also supported when data amount
  20363. // is less than progressive threshold.
  20364. : 'render';
  20365. if (methodName !== 'render') {
  20366. view[methodName](seriesModel, ecModel, api, payload);
  20367. }
  20368. return progressMethodMap[methodName];
  20369. }
  20370. var progressMethodMap = {
  20371. incrementalPrepareRender: {
  20372. progress: function (params, context) {
  20373. context.view.incrementalRender(params, context.model, context.ecModel, context.api, context.payload);
  20374. }
  20375. },
  20376. render: {
  20377. // Put view.render in `progress` to support appendData. But in this case
  20378. // view.render should not be called in reset, otherwise it will be called
  20379. // twise. Use `forceFirstProgress` to make sure that view.render is called
  20380. // in any cases.
  20381. forceFirstProgress: true,
  20382. progress: function (params, context) {
  20383. context.view.render(context.model, context.ecModel, context.api, context.payload);
  20384. }
  20385. }
  20386. };
  20387. /*
  20388. * Licensed to the Apache Software Foundation (ASF) under one
  20389. * or more contributor license agreements. See the NOTICE file
  20390. * distributed with this work for additional information
  20391. * regarding copyright ownership. The ASF licenses this file
  20392. * to you under the Apache License, Version 2.0 (the
  20393. * "License"); you may not use this file except in compliance
  20394. * with the License. You may obtain a copy of the License at
  20395. *
  20396. * http://www.apache.org/licenses/LICENSE-2.0
  20397. *
  20398. * Unless required by applicable law or agreed to in writing,
  20399. * software distributed under the License is distributed on an
  20400. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20401. * KIND, either express or implied. See the License for the
  20402. * specific language governing permissions and limitations
  20403. * under the License.
  20404. */
  20405. /**
  20406. * @public
  20407. * @param {(Function)} fn
  20408. * @param {number} [delay=0] Unit: ms.
  20409. * @param {boolean} [debounce=false]
  20410. * true: If call interval less than `delay`, only the last call works.
  20411. * false: If call interval less than `delay, call works on fixed rate.
  20412. * @return {(Function)} throttled fn.
  20413. */
  20414. function throttle(fn, delay, debounce) {
  20415. var currCall;
  20416. var lastCall = 0;
  20417. var lastExec = 0;
  20418. var timer = null;
  20419. var diff;
  20420. var scope;
  20421. var args;
  20422. var debounceNextCall;
  20423. delay = delay || 0;
  20424. function exec() {
  20425. lastExec = new Date().getTime();
  20426. timer = null;
  20427. fn.apply(scope, args || []);
  20428. }
  20429. var cb = function () {
  20430. currCall = new Date().getTime();
  20431. scope = this;
  20432. args = arguments;
  20433. var thisDelay = debounceNextCall || delay;
  20434. var thisDebounce = debounceNextCall || debounce;
  20435. debounceNextCall = null;
  20436. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  20437. clearTimeout(timer); // Here we should make sure that: the `exec` SHOULD NOT be called later
  20438. // than a new call of `cb`, that is, preserving the command order. Consider
  20439. // calculating "scale rate" when roaming as an example. When a call of `cb`
  20440. // happens, either the `exec` is called dierectly, or the call is delayed.
  20441. // But the delayed call should never be later than next call of `cb`. Under
  20442. // this assurance, we can simply update view state each time `dispatchAction`
  20443. // triggered by user roaming, but not need to add extra code to avoid the
  20444. // state being "rolled-back".
  20445. if (thisDebounce) {
  20446. timer = setTimeout(exec, thisDelay);
  20447. } else {
  20448. if (diff >= 0) {
  20449. exec();
  20450. } else {
  20451. timer = setTimeout(exec, -diff);
  20452. }
  20453. }
  20454. lastCall = currCall;
  20455. };
  20456. /**
  20457. * Clear throttle.
  20458. * @public
  20459. */
  20460. cb.clear = function () {
  20461. if (timer) {
  20462. clearTimeout(timer);
  20463. timer = null;
  20464. }
  20465. };
  20466. /**
  20467. * Enable debounce once.
  20468. */
  20469. cb.debounceNextCall = function (debounceDelay) {
  20470. debounceNextCall = debounceDelay;
  20471. };
  20472. return cb;
  20473. }
  20474. /**
  20475. * Create throttle method or update throttle rate.
  20476. *
  20477. * @example
  20478. * ComponentView.prototype.render = function () {
  20479. * ...
  20480. * throttle.createOrUpdate(
  20481. * this,
  20482. * '_dispatchAction',
  20483. * this.model.get('throttle'),
  20484. * 'fixRate'
  20485. * );
  20486. * };
  20487. * ComponentView.prototype.remove = function () {
  20488. * throttle.clear(this, '_dispatchAction');
  20489. * };
  20490. * ComponentView.prototype.dispose = function () {
  20491. * throttle.clear(this, '_dispatchAction');
  20492. * };
  20493. *
  20494. * @public
  20495. * @param {Object} obj
  20496. * @param {string} fnAttr
  20497. * @param {number} [rate]
  20498. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  20499. * @return {Function} throttled function.
  20500. */
  20501. /**
  20502. * Clear throttle. Example see throttle.createOrUpdate.
  20503. *
  20504. * @public
  20505. * @param {Object} obj
  20506. * @param {string} fnAttr
  20507. */
  20508. /*
  20509. * Licensed to the Apache Software Foundation (ASF) under one
  20510. * or more contributor license agreements. See the NOTICE file
  20511. * distributed with this work for additional information
  20512. * regarding copyright ownership. The ASF licenses this file
  20513. * to you under the Apache License, Version 2.0 (the
  20514. * "License"); you may not use this file except in compliance
  20515. * with the License. You may obtain a copy of the License at
  20516. *
  20517. * http://www.apache.org/licenses/LICENSE-2.0
  20518. *
  20519. * Unless required by applicable law or agreed to in writing,
  20520. * software distributed under the License is distributed on an
  20521. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20522. * KIND, either express or implied. See the License for the
  20523. * specific language governing permissions and limitations
  20524. * under the License.
  20525. */
  20526. var seriesColor = {
  20527. createOnAllSeries: true,
  20528. performRawSeries: true,
  20529. reset: function (seriesModel, ecModel) {
  20530. var data = seriesModel.getData();
  20531. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.color').split('.'); // Set in itemStyle
  20532. var color = seriesModel.get(colorAccessPath);
  20533. var colorCallback = isFunction$1(color) && !(color instanceof Gradient) ? color : null; // Default color
  20534. if (!color || colorCallback) {
  20535. color = seriesModel.getColorFromPalette( // TODO series count changed.
  20536. seriesModel.name, null, ecModel.getSeriesCount());
  20537. }
  20538. data.setVisual('color', color);
  20539. var borderColorAccessPath = (seriesModel.visualBorderColorAccessPath || 'itemStyle.borderColor').split('.');
  20540. var borderColor = seriesModel.get(borderColorAccessPath);
  20541. data.setVisual('borderColor', borderColor); // Only visible series has each data be visual encoded
  20542. if (!ecModel.isSeriesFiltered(seriesModel)) {
  20543. if (colorCallback) {
  20544. data.each(function (idx) {
  20545. data.setItemVisual(idx, 'color', colorCallback(seriesModel.getDataParams(idx)));
  20546. });
  20547. } // itemStyle in each data item
  20548. var dataEach = function (data, idx) {
  20549. var itemModel = data.getItemModel(idx);
  20550. var color = itemModel.get(colorAccessPath, true);
  20551. var borderColor = itemModel.get(borderColorAccessPath, true);
  20552. if (color != null) {
  20553. data.setItemVisual(idx, 'color', color);
  20554. }
  20555. if (borderColor != null) {
  20556. data.setItemVisual(idx, 'borderColor', borderColor);
  20557. }
  20558. };
  20559. return {
  20560. dataEach: data.hasItemOption ? dataEach : null
  20561. };
  20562. }
  20563. }
  20564. };
  20565. /*
  20566. * Licensed to the Apache Software Foundation (ASF) under one
  20567. * or more contributor license agreements. See the NOTICE file
  20568. * distributed with this work for additional information
  20569. * regarding copyright ownership. The ASF licenses this file
  20570. * to you under the Apache License, Version 2.0 (the
  20571. * "License"); you may not use this file except in compliance
  20572. * with the License. You may obtain a copy of the License at
  20573. *
  20574. * http://www.apache.org/licenses/LICENSE-2.0
  20575. *
  20576. * Unless required by applicable law or agreed to in writing,
  20577. * software distributed under the License is distributed on an
  20578. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20579. * KIND, either express or implied. See the License for the
  20580. * specific language governing permissions and limitations
  20581. * under the License.
  20582. */
  20583. /**
  20584. * Language: (Simplified) Chinese.
  20585. */
  20586. var lang = {
  20587. legend: {
  20588. selector: {
  20589. all: '全选',
  20590. inverse: '反选'
  20591. }
  20592. },
  20593. toolbox: {
  20594. brush: {
  20595. title: {
  20596. rect: '矩形选择',
  20597. polygon: '圈选',
  20598. lineX: '横向选择',
  20599. lineY: '纵向选择',
  20600. keep: '保持选择',
  20601. clear: '清除选择'
  20602. }
  20603. },
  20604. dataView: {
  20605. title: '数据视图',
  20606. lang: ['数据视图', '关闭', '刷新']
  20607. },
  20608. dataZoom: {
  20609. title: {
  20610. zoom: '区域缩放',
  20611. back: '区域缩放还原'
  20612. }
  20613. },
  20614. magicType: {
  20615. title: {
  20616. line: '切换为折线图',
  20617. bar: '切换为柱状图',
  20618. stack: '切换为堆叠',
  20619. tiled: '切换为平铺'
  20620. }
  20621. },
  20622. restore: {
  20623. title: '还原'
  20624. },
  20625. saveAsImage: {
  20626. title: '保存为图片',
  20627. lang: ['右键另存为图片']
  20628. }
  20629. },
  20630. series: {
  20631. typeNames: {
  20632. pie: '饼图',
  20633. bar: '柱状图',
  20634. line: '折线图',
  20635. scatter: '散点图',
  20636. effectScatter: '涟漪散点图',
  20637. radar: '雷达图',
  20638. tree: '树图',
  20639. treemap: '矩形树图',
  20640. boxplot: '箱型图',
  20641. candlestick: 'K线图',
  20642. k: 'K线图',
  20643. heatmap: '热力图',
  20644. map: '地图',
  20645. parallel: '平行坐标图',
  20646. lines: '线图',
  20647. graph: '关系图',
  20648. sankey: '桑基图',
  20649. funnel: '漏斗图',
  20650. gauge: '仪表盘图',
  20651. pictorialBar: '象形柱图',
  20652. themeRiver: '主题河流图',
  20653. sunburst: '旭日图'
  20654. }
  20655. },
  20656. aria: {
  20657. general: {
  20658. withTitle: '这是一个关于“{title}”的图表。',
  20659. withoutTitle: '这是一个图表,'
  20660. },
  20661. series: {
  20662. single: {
  20663. prefix: '',
  20664. withName: '图表类型是{seriesType},表示{seriesName}。',
  20665. withoutName: '图表类型是{seriesType}。'
  20666. },
  20667. multiple: {
  20668. prefix: '它由{seriesCount}个图表系列组成。',
  20669. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  20670. withoutName: '第{seriesId}个系列是一个{seriesType},',
  20671. separator: {
  20672. middle: ';',
  20673. end: '。'
  20674. }
  20675. }
  20676. },
  20677. data: {
  20678. allData: '其数据是——',
  20679. partialData: '其中,前{displayCnt}项是——',
  20680. withName: '{name}的数据是{value}',
  20681. withoutName: '{value}',
  20682. separator: {
  20683. middle: ',',
  20684. end: ''
  20685. }
  20686. }
  20687. }
  20688. };
  20689. /*
  20690. * Licensed to the Apache Software Foundation (ASF) under one
  20691. * or more contributor license agreements. See the NOTICE file
  20692. * distributed with this work for additional information
  20693. * regarding copyright ownership. The ASF licenses this file
  20694. * to you under the Apache License, Version 2.0 (the
  20695. * "License"); you may not use this file except in compliance
  20696. * with the License. You may obtain a copy of the License at
  20697. *
  20698. * http://www.apache.org/licenses/LICENSE-2.0
  20699. *
  20700. * Unless required by applicable law or agreed to in writing,
  20701. * software distributed under the License is distributed on an
  20702. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20703. * KIND, either express or implied. See the License for the
  20704. * specific language governing permissions and limitations
  20705. * under the License.
  20706. */
  20707. var aria = function (dom, ecModel) {
  20708. var ariaModel = ecModel.getModel('aria');
  20709. if (!ariaModel.get('show')) {
  20710. return;
  20711. } else if (ariaModel.get('description')) {
  20712. dom.setAttribute('aria-label', ariaModel.get('description'));
  20713. return;
  20714. }
  20715. var seriesCnt = 0;
  20716. ecModel.eachSeries(function (seriesModel, idx) {
  20717. ++seriesCnt;
  20718. }, this);
  20719. var maxDataCnt = ariaModel.get('data.maxCount') || 10;
  20720. var maxSeriesCnt = ariaModel.get('series.maxCount') || 10;
  20721. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  20722. var ariaLabel;
  20723. if (seriesCnt < 1) {
  20724. // No series, no aria label
  20725. return;
  20726. } else {
  20727. var title = getTitle();
  20728. if (title) {
  20729. ariaLabel = replace(getConfig('general.withTitle'), {
  20730. title: title
  20731. });
  20732. } else {
  20733. ariaLabel = getConfig('general.withoutTitle');
  20734. }
  20735. var seriesLabels = [];
  20736. var prefix = seriesCnt > 1 ? 'series.multiple.prefix' : 'series.single.prefix';
  20737. ariaLabel += replace(getConfig(prefix), {
  20738. seriesCount: seriesCnt
  20739. });
  20740. ecModel.eachSeries(function (seriesModel, idx) {
  20741. if (idx < displaySeriesCnt) {
  20742. var seriesLabel;
  20743. var seriesName = seriesModel.get('name');
  20744. var seriesTpl = 'series.' + (seriesCnt > 1 ? 'multiple' : 'single') + '.';
  20745. seriesLabel = getConfig(seriesName ? seriesTpl + 'withName' : seriesTpl + 'withoutName');
  20746. seriesLabel = replace(seriesLabel, {
  20747. seriesId: seriesModel.seriesIndex,
  20748. seriesName: seriesModel.get('name'),
  20749. seriesType: getSeriesTypeName(seriesModel.subType)
  20750. });
  20751. var data = seriesModel.getData();
  20752. window.data = data;
  20753. if (data.count() > maxDataCnt) {
  20754. // Show part of data
  20755. seriesLabel += replace(getConfig('data.partialData'), {
  20756. displayCnt: maxDataCnt
  20757. });
  20758. } else {
  20759. seriesLabel += getConfig('data.allData');
  20760. }
  20761. var dataLabels = [];
  20762. for (var i = 0; i < data.count(); i++) {
  20763. if (i < maxDataCnt) {
  20764. var name = data.getName(i);
  20765. var value = retrieveRawValue(data, i);
  20766. dataLabels.push(replace(name ? getConfig('data.withName') : getConfig('data.withoutName'), {
  20767. name: name,
  20768. value: value
  20769. }));
  20770. }
  20771. }
  20772. seriesLabel += dataLabels.join(getConfig('data.separator.middle')) + getConfig('data.separator.end');
  20773. seriesLabels.push(seriesLabel);
  20774. }
  20775. });
  20776. ariaLabel += seriesLabels.join(getConfig('series.multiple.separator.middle')) + getConfig('series.multiple.separator.end');
  20777. dom.setAttribute('aria-label', ariaLabel);
  20778. }
  20779. function replace(str, keyValues) {
  20780. if (typeof str !== 'string') {
  20781. return str;
  20782. }
  20783. var result = str;
  20784. each$1(keyValues, function (value, key) {
  20785. result = result.replace(new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'), value);
  20786. });
  20787. return result;
  20788. }
  20789. function getConfig(path) {
  20790. var userConfig = ariaModel.get(path);
  20791. if (userConfig == null) {
  20792. var pathArr = path.split('.');
  20793. var result = lang.aria;
  20794. for (var i = 0; i < pathArr.length; ++i) {
  20795. result = result[pathArr[i]];
  20796. }
  20797. return result;
  20798. } else {
  20799. return userConfig;
  20800. }
  20801. }
  20802. function getTitle() {
  20803. var title = ecModel.getModel('title').option;
  20804. if (title && title.length) {
  20805. title = title[0];
  20806. }
  20807. return title && title.text;
  20808. }
  20809. function getSeriesTypeName(type) {
  20810. return lang.series.typeNames[type] || '自定义图';
  20811. }
  20812. };
  20813. /*
  20814. * Licensed to the Apache Software Foundation (ASF) under one
  20815. * or more contributor license agreements. See the NOTICE file
  20816. * distributed with this work for additional information
  20817. * regarding copyright ownership. The ASF licenses this file
  20818. * to you under the Apache License, Version 2.0 (the
  20819. * "License"); you may not use this file except in compliance
  20820. * with the License. You may obtain a copy of the License at
  20821. *
  20822. * http://www.apache.org/licenses/LICENSE-2.0
  20823. *
  20824. * Unless required by applicable law or agreed to in writing,
  20825. * software distributed under the License is distributed on an
  20826. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20827. * KIND, either express or implied. See the License for the
  20828. * specific language governing permissions and limitations
  20829. * under the License.
  20830. */
  20831. var PI$1 = Math.PI;
  20832. /**
  20833. * @param {module:echarts/ExtensionAPI} api
  20834. * @param {Object} [opts]
  20835. * @param {string} [opts.text]
  20836. * @param {string} [opts.color]
  20837. * @param {string} [opts.textColor]
  20838. * @return {module:zrender/Element}
  20839. */
  20840. var loadingDefault = function (api, opts) {
  20841. opts = opts || {};
  20842. defaults(opts, {
  20843. text: 'loading',
  20844. textColor: '#000',
  20845. fontSize: '12px',
  20846. maskColor: 'rgba(255, 255, 255, 0.8)',
  20847. showSpinner: true,
  20848. color: '#c23531',
  20849. spinnerRadius: 10,
  20850. lineWidth: 5,
  20851. zlevel: 0
  20852. });
  20853. var group = new Group();
  20854. var mask = new Rect({
  20855. style: {
  20856. fill: opts.maskColor
  20857. },
  20858. zlevel: opts.zlevel,
  20859. z: 10000
  20860. });
  20861. group.add(mask);
  20862. var font = opts.fontSize + ' sans-serif';
  20863. var labelRect = new Rect({
  20864. style: {
  20865. fill: 'none',
  20866. text: opts.text,
  20867. font: font,
  20868. textPosition: 'right',
  20869. textDistance: 10,
  20870. textFill: opts.textColor
  20871. },
  20872. zlevel: opts.zlevel,
  20873. z: 10001
  20874. });
  20875. group.add(labelRect);
  20876. if (opts.showSpinner) {
  20877. var arc = new Arc({
  20878. shape: {
  20879. startAngle: -PI$1 / 2,
  20880. endAngle: -PI$1 / 2 + 0.1,
  20881. r: opts.spinnerRadius
  20882. },
  20883. style: {
  20884. stroke: opts.color,
  20885. lineCap: 'round',
  20886. lineWidth: opts.lineWidth
  20887. },
  20888. zlevel: opts.zlevel,
  20889. z: 10001
  20890. });
  20891. arc.animateShape(true).when(1000, {
  20892. endAngle: PI$1 * 3 / 2
  20893. }).start('circularInOut');
  20894. arc.animateShape(true).when(1000, {
  20895. startAngle: PI$1 * 3 / 2
  20896. }).delay(300).start('circularInOut');
  20897. group.add(arc);
  20898. } // Inject resize
  20899. group.resize = function () {
  20900. var textWidth = getWidth(opts.text, font);
  20901. var r = opts.showSpinner ? opts.spinnerRadius : 0; // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  20902. // textDistance needs to be calculated when both animation and text exist
  20903. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2 // only show the text
  20904. - (opts.showSpinner ? 0 : textWidth / 2);
  20905. var cy = api.getHeight() / 2;
  20906. opts.showSpinner && arc.setShape({
  20907. cx: cx,
  20908. cy: cy
  20909. });
  20910. labelRect.setShape({
  20911. x: cx - r,
  20912. y: cy - r,
  20913. width: r * 2,
  20914. height: r * 2
  20915. });
  20916. mask.setShape({
  20917. x: 0,
  20918. y: 0,
  20919. width: api.getWidth(),
  20920. height: api.getHeight()
  20921. });
  20922. };
  20923. group.resize();
  20924. return group;
  20925. };
  20926. /*
  20927. * Licensed to the Apache Software Foundation (ASF) under one
  20928. * or more contributor license agreements. See the NOTICE file
  20929. * distributed with this work for additional information
  20930. * regarding copyright ownership. The ASF licenses this file
  20931. * to you under the Apache License, Version 2.0 (the
  20932. * "License"); you may not use this file except in compliance
  20933. * with the License. You may obtain a copy of the License at
  20934. *
  20935. * http://www.apache.org/licenses/LICENSE-2.0
  20936. *
  20937. * Unless required by applicable law or agreed to in writing,
  20938. * software distributed under the License is distributed on an
  20939. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20940. * KIND, either express or implied. See the License for the
  20941. * specific language governing permissions and limitations
  20942. * under the License.
  20943. */
  20944. /**
  20945. * @module echarts/stream/Scheduler
  20946. */
  20947. /**
  20948. * @constructor
  20949. */
  20950. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  20951. this.ecInstance = ecInstance;
  20952. this.api = api;
  20953. this.unfinished; // Fix current processors in case that in some rear cases that
  20954. // processors might be registered after echarts instance created.
  20955. // Register processors incrementally for a echarts instance is
  20956. // not supported by this stream architecture.
  20957. var dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  20958. var visualHandlers = this._visualHandlers = visualHandlers.slice();
  20959. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  20960. /**
  20961. * @private
  20962. * @type {
  20963. * [handlerUID: string]: {
  20964. * seriesTaskMap?: {
  20965. * [seriesUID: string]: Task
  20966. * },
  20967. * overallTask?: Task
  20968. * }
  20969. * }
  20970. */
  20971. this._stageTaskMap = createHashMap();
  20972. }
  20973. var proto = Scheduler.prototype;
  20974. /**
  20975. * @param {module:echarts/model/Global} ecModel
  20976. * @param {Object} payload
  20977. */
  20978. proto.restoreData = function (ecModel, payload) {
  20979. // TODO: Only restore needed series and components, but not all components.
  20980. // Currently `restoreData` of all of the series and component will be called.
  20981. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  20982. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  20983. // and some components like coordinate system, axes, dataZoom, visualMap only
  20984. // need their target series refresh.
  20985. // (1) If we are implementing this feature some day, we should consider these cases:
  20986. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  20987. // on the settings of `dataZoom`), it should be re-performed if the component
  20988. // is modified by `setOption`.
  20989. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  20990. // it should be re-performed when the result array of `getTargetSeries` changed.
  20991. // We use `dependencies` to cover these issues.
  20992. // (3) How to update target series when coordinate system related components modified.
  20993. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  20994. // and this case all of the tasks will be set as dirty.
  20995. ecModel.restoreData(payload); // Theoretically an overall task not only depends on each of its target series, but also
  20996. // depends on all of the series.
  20997. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  20998. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  20999. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  21000. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  21001. // probably cause state chaos (consider `dataZoomProcessor`).
  21002. this._stageTaskMap.each(function (taskRecord) {
  21003. var overallTask = taskRecord.overallTask;
  21004. overallTask && overallTask.dirty();
  21005. });
  21006. }; // If seriesModel provided, incremental threshold is check by series data.
  21007. proto.getPerformArgs = function (task, isBlock) {
  21008. // For overall task
  21009. if (!task.__pipeline) {
  21010. return;
  21011. }
  21012. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  21013. var pCtx = pipeline.context;
  21014. var incremental = !isBlock && pipeline.progressiveEnabled && (!pCtx || pCtx.progressiveRender) && task.__idxInPipeline > pipeline.blockIndex;
  21015. var step = incremental ? pipeline.step : null;
  21016. var modDataCount = pCtx && pCtx.modDataCount;
  21017. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  21018. return {
  21019. step: step,
  21020. modBy: modBy,
  21021. modDataCount: modDataCount
  21022. };
  21023. };
  21024. proto.getPipeline = function (pipelineId) {
  21025. return this._pipelineMap.get(pipelineId);
  21026. };
  21027. /**
  21028. * Current, progressive rendering starts from visual and layout.
  21029. * Always detect render mode in the same stage, avoiding that incorrect
  21030. * detection caused by data filtering.
  21031. * Caution:
  21032. * `updateStreamModes` use `seriesModel.getData()`.
  21033. */
  21034. proto.updateStreamModes = function (seriesModel, view) {
  21035. var pipeline = this._pipelineMap.get(seriesModel.uid);
  21036. var data = seriesModel.getData();
  21037. var dataLen = data.count(); // `progressiveRender` means that can render progressively in each
  21038. // animation frame. Note that some types of series do not provide
  21039. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  21040. // use the term `incremental` but not `progressive` to describe the
  21041. // case that `chart.appendData`.
  21042. var progressiveRender = pipeline.progressiveEnabled && view.incrementalPrepareRender && dataLen >= pipeline.threshold;
  21043. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold'); // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  21044. // see `test/candlestick-large3.html`
  21045. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  21046. seriesModel.pipelineContext = pipeline.context = {
  21047. progressiveRender: progressiveRender,
  21048. modDataCount: modDataCount,
  21049. large: large
  21050. };
  21051. };
  21052. proto.restorePipelines = function (ecModel) {
  21053. var scheduler = this;
  21054. var pipelineMap = scheduler._pipelineMap = createHashMap();
  21055. ecModel.eachSeries(function (seriesModel) {
  21056. var progressive = seriesModel.getProgressive();
  21057. var pipelineId = seriesModel.uid;
  21058. pipelineMap.set(pipelineId, {
  21059. id: pipelineId,
  21060. head: null,
  21061. tail: null,
  21062. threshold: seriesModel.getProgressiveThreshold(),
  21063. progressiveEnabled: progressive && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  21064. blockIndex: -1,
  21065. step: Math.round(progressive || 700),
  21066. count: 0
  21067. });
  21068. pipe(scheduler, seriesModel, seriesModel.dataTask);
  21069. });
  21070. };
  21071. proto.prepareStageTasks = function () {
  21072. var stageTaskMap = this._stageTaskMap;
  21073. var ecModel = this.ecInstance.getModel();
  21074. var api = this.api;
  21075. each$1(this._allHandlers, function (handler) {
  21076. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, []);
  21077. handler.reset && createSeriesStageTask(this, handler, record, ecModel, api);
  21078. handler.overallReset && createOverallStageTask(this, handler, record, ecModel, api);
  21079. }, this);
  21080. };
  21081. proto.prepareView = function (view, model, ecModel, api) {
  21082. var renderTask = view.renderTask;
  21083. var context = renderTask.context;
  21084. context.model = model;
  21085. context.ecModel = ecModel;
  21086. context.api = api;
  21087. renderTask.__block = !view.incrementalPrepareRender;
  21088. pipe(this, model, renderTask);
  21089. };
  21090. proto.performDataProcessorTasks = function (ecModel, payload) {
  21091. // If we do not use `block` here, it should be considered when to update modes.
  21092. performStageTasks(this, this._dataProcessorHandlers, ecModel, payload, {
  21093. block: true
  21094. });
  21095. }; // opt
  21096. // opt.visualType: 'visual' or 'layout'
  21097. // opt.setDirty
  21098. proto.performVisualTasks = function (ecModel, payload, opt) {
  21099. performStageTasks(this, this._visualHandlers, ecModel, payload, opt);
  21100. };
  21101. function performStageTasks(scheduler, stageHandlers, ecModel, payload, opt) {
  21102. opt = opt || {};
  21103. var unfinished;
  21104. each$1(stageHandlers, function (stageHandler, idx) {
  21105. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  21106. return;
  21107. }
  21108. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  21109. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  21110. var overallTask = stageHandlerRecord.overallTask;
  21111. if (overallTask) {
  21112. var overallNeedDirty;
  21113. var agentStubMap = overallTask.agentStubMap;
  21114. agentStubMap.each(function (stub) {
  21115. if (needSetDirty(opt, stub)) {
  21116. stub.dirty();
  21117. overallNeedDirty = true;
  21118. }
  21119. });
  21120. overallNeedDirty && overallTask.dirty();
  21121. updatePayload(overallTask, payload);
  21122. var performArgs = scheduler.getPerformArgs(overallTask, opt.block); // Execute stubs firstly, which may set the overall task dirty,
  21123. // then execute the overall task. And stub will call seriesModel.setData,
  21124. // which ensures that in the overallTask seriesModel.getData() will not
  21125. // return incorrect data.
  21126. agentStubMap.each(function (stub) {
  21127. stub.perform(performArgs);
  21128. });
  21129. unfinished |= overallTask.perform(performArgs);
  21130. } else if (seriesTaskMap) {
  21131. seriesTaskMap.each(function (task, pipelineId) {
  21132. if (needSetDirty(opt, task)) {
  21133. task.dirty();
  21134. }
  21135. var performArgs = scheduler.getPerformArgs(task, opt.block); // FIXME
  21136. // if intending to decalare `performRawSeries` in handlers, only
  21137. // stream-independent (specifically, data item independent) operations can be
  21138. // performed. Because is a series is filtered, most of the tasks will not
  21139. // be performed. A stream-dependent operation probably cause wrong biz logic.
  21140. // Perhaps we should not provide a separate callback for this case instead
  21141. // of providing the config `performRawSeries`. The stream-dependent operaions
  21142. // and stream-independent operations should better not be mixed.
  21143. performArgs.skip = !stageHandler.performRawSeries && ecModel.isSeriesFiltered(task.context.model);
  21144. updatePayload(task, payload);
  21145. unfinished |= task.perform(performArgs);
  21146. });
  21147. }
  21148. });
  21149. function needSetDirty(opt, task) {
  21150. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  21151. }
  21152. scheduler.unfinished |= unfinished;
  21153. }
  21154. proto.performSeriesTasks = function (ecModel) {
  21155. var unfinished;
  21156. ecModel.eachSeries(function (seriesModel) {
  21157. // Progress to the end for dataInit and dataRestore.
  21158. unfinished |= seriesModel.dataTask.perform();
  21159. });
  21160. this.unfinished |= unfinished;
  21161. };
  21162. proto.plan = function () {
  21163. // Travel pipelines, check block.
  21164. this._pipelineMap.each(function (pipeline) {
  21165. var task = pipeline.tail;
  21166. do {
  21167. if (task.__block) {
  21168. pipeline.blockIndex = task.__idxInPipeline;
  21169. break;
  21170. }
  21171. task = task.getUpstream();
  21172. } while (task);
  21173. });
  21174. };
  21175. var updatePayload = proto.updatePayload = function (task, payload) {
  21176. payload !== 'remain' && (task.context.payload = payload);
  21177. };
  21178. function createSeriesStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  21179. var seriesTaskMap = stageHandlerRecord.seriesTaskMap || (stageHandlerRecord.seriesTaskMap = createHashMap());
  21180. var seriesType = stageHandler.seriesType;
  21181. var getTargetSeries = stageHandler.getTargetSeries; // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  21182. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  21183. // it works but it may cause other irrelevant charts blocked.
  21184. if (stageHandler.createOnAllSeries) {
  21185. ecModel.eachRawSeries(create);
  21186. } else if (seriesType) {
  21187. ecModel.eachRawSeriesByType(seriesType, create);
  21188. } else if (getTargetSeries) {
  21189. getTargetSeries(ecModel, api).each(create);
  21190. }
  21191. function create(seriesModel) {
  21192. var pipelineId = seriesModel.uid; // Init tasks for each seriesModel only once.
  21193. // Reuse original task instance.
  21194. var task = seriesTaskMap.get(pipelineId) || seriesTaskMap.set(pipelineId, createTask({
  21195. plan: seriesTaskPlan,
  21196. reset: seriesTaskReset,
  21197. count: seriesTaskCount
  21198. }));
  21199. task.context = {
  21200. model: seriesModel,
  21201. ecModel: ecModel,
  21202. api: api,
  21203. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  21204. plan: stageHandler.plan,
  21205. reset: stageHandler.reset,
  21206. scheduler: scheduler
  21207. };
  21208. pipe(scheduler, seriesModel, task);
  21209. } // Clear unused series tasks.
  21210. var pipelineMap = scheduler._pipelineMap;
  21211. seriesTaskMap.each(function (task, pipelineId) {
  21212. if (!pipelineMap.get(pipelineId)) {
  21213. task.dispose();
  21214. seriesTaskMap.removeKey(pipelineId);
  21215. }
  21216. });
  21217. }
  21218. function createOverallStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  21219. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask // For overall task, the function only be called on reset stage.
  21220. || createTask({
  21221. reset: overallTaskReset
  21222. });
  21223. overallTask.context = {
  21224. ecModel: ecModel,
  21225. api: api,
  21226. overallReset: stageHandler.overallReset,
  21227. scheduler: scheduler
  21228. }; // Reuse orignal stubs.
  21229. var agentStubMap = overallTask.agentStubMap = overallTask.agentStubMap || createHashMap();
  21230. var seriesType = stageHandler.seriesType;
  21231. var getTargetSeries = stageHandler.getTargetSeries;
  21232. var overallProgress = true;
  21233. var modifyOutputEnd = stageHandler.modifyOutputEnd; // An overall task with seriesType detected or has `getTargetSeries`, we add
  21234. // stub in each pipelines, it will set the overall task dirty when the pipeline
  21235. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  21236. // we set the pipeline block.
  21237. if (seriesType) {
  21238. ecModel.eachRawSeriesByType(seriesType, createStub);
  21239. } else if (getTargetSeries) {
  21240. getTargetSeries(ecModel, api).each(createStub);
  21241. } // Otherwise, (usually it is legancy case), the overall task will only be
  21242. // executed when upstream dirty. Otherwise the progressive rendering of all
  21243. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  21244. // dirty info from upsteam.
  21245. else {
  21246. overallProgress = false;
  21247. each$1(ecModel.getSeries(), createStub);
  21248. }
  21249. function createStub(seriesModel) {
  21250. var pipelineId = seriesModel.uid;
  21251. var stub = agentStubMap.get(pipelineId);
  21252. if (!stub) {
  21253. stub = agentStubMap.set(pipelineId, createTask({
  21254. reset: stubReset,
  21255. onDirty: stubOnDirty
  21256. })); // When the result of `getTargetSeries` changed, the overallTask
  21257. // should be set as dirty and re-performed.
  21258. overallTask.dirty();
  21259. }
  21260. stub.context = {
  21261. model: seriesModel,
  21262. overallProgress: overallProgress,
  21263. modifyOutputEnd: modifyOutputEnd
  21264. };
  21265. stub.agent = overallTask;
  21266. stub.__block = overallProgress;
  21267. pipe(scheduler, seriesModel, stub);
  21268. } // Clear unused stubs.
  21269. var pipelineMap = scheduler._pipelineMap;
  21270. agentStubMap.each(function (stub, pipelineId) {
  21271. if (!pipelineMap.get(pipelineId)) {
  21272. stub.dispose(); // When the result of `getTargetSeries` changed, the overallTask
  21273. // should be set as dirty and re-performed.
  21274. overallTask.dirty();
  21275. agentStubMap.removeKey(pipelineId);
  21276. }
  21277. });
  21278. }
  21279. function overallTaskReset(context) {
  21280. context.overallReset(context.ecModel, context.api, context.payload);
  21281. }
  21282. function stubReset(context, upstreamContext) {
  21283. return context.overallProgress && stubProgress;
  21284. }
  21285. function stubProgress() {
  21286. this.agent.dirty();
  21287. this.getDownstream().dirty();
  21288. }
  21289. function stubOnDirty() {
  21290. this.agent && this.agent.dirty();
  21291. }
  21292. function seriesTaskPlan(context) {
  21293. return context.plan && context.plan(context.model, context.ecModel, context.api, context.payload);
  21294. }
  21295. function seriesTaskReset(context) {
  21296. if (context.useClearVisual) {
  21297. context.data.clearAllVisual();
  21298. }
  21299. var resetDefines = context.resetDefines = normalizeToArray(context.reset(context.model, context.ecModel, context.api, context.payload));
  21300. return resetDefines.length > 1 ? map(resetDefines, function (v, idx) {
  21301. return makeSeriesTaskProgress(idx);
  21302. }) : singleSeriesTaskProgress;
  21303. }
  21304. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  21305. function makeSeriesTaskProgress(resetDefineIdx) {
  21306. return function (params, context) {
  21307. var data = context.data;
  21308. var resetDefine = context.resetDefines[resetDefineIdx];
  21309. if (resetDefine && resetDefine.dataEach) {
  21310. for (var i = params.start; i < params.end; i++) {
  21311. resetDefine.dataEach(data, i);
  21312. }
  21313. } else if (resetDefine && resetDefine.progress) {
  21314. resetDefine.progress(params, data);
  21315. }
  21316. };
  21317. }
  21318. function seriesTaskCount(context) {
  21319. return context.data.count();
  21320. }
  21321. function pipe(scheduler, seriesModel, task) {
  21322. var pipelineId = seriesModel.uid;
  21323. var pipeline = scheduler._pipelineMap.get(pipelineId);
  21324. !pipeline.head && (pipeline.head = task);
  21325. pipeline.tail && pipeline.tail.pipe(task);
  21326. pipeline.tail = task;
  21327. task.__idxInPipeline = pipeline.count++;
  21328. task.__pipeline = pipeline;
  21329. }
  21330. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  21331. if (isFunction$1(stageHandler)) {
  21332. stageHandler = {
  21333. overallReset: stageHandler,
  21334. seriesType: detectSeriseType(stageHandler)
  21335. };
  21336. }
  21337. stageHandler.uid = getUID('stageHandler');
  21338. visualType && (stageHandler.visualType = visualType);
  21339. return stageHandler;
  21340. };
  21341. /**
  21342. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  21343. * To ensure that they can work normally, they should work in block mode, that is,
  21344. * they should not be started util the previous tasks finished. So they cause the
  21345. * progressive rendering disabled. We try to detect the series type, to narrow down
  21346. * the block range to only the series type they concern, but not all series.
  21347. */
  21348. function detectSeriseType(legacyFunc) {
  21349. seriesType = null;
  21350. try {
  21351. // Assume there is no async when calling `eachSeriesByType`.
  21352. legacyFunc(ecModelMock, apiMock);
  21353. } catch (e) {}
  21354. return seriesType;
  21355. }
  21356. var ecModelMock = {};
  21357. var apiMock = {};
  21358. var seriesType;
  21359. mockMethods(ecModelMock, GlobalModel);
  21360. mockMethods(apiMock, ExtensionAPI);
  21361. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  21362. seriesType = type;
  21363. };
  21364. ecModelMock.eachComponent = function (cond) {
  21365. if (cond.mainType === 'series' && cond.subType) {
  21366. seriesType = cond.subType;
  21367. }
  21368. };
  21369. function mockMethods(target, Clz) {
  21370. /* eslint-disable */
  21371. for (var name in Clz.prototype) {
  21372. // Do not use hasOwnProperty
  21373. target[name] = noop;
  21374. }
  21375. /* eslint-enable */
  21376. }
  21377. /*
  21378. * Licensed to the Apache Software Foundation (ASF) under one
  21379. * or more contributor license agreements. See the NOTICE file
  21380. * distributed with this work for additional information
  21381. * regarding copyright ownership. The ASF licenses this file
  21382. * to you under the Apache License, Version 2.0 (the
  21383. * "License"); you may not use this file except in compliance
  21384. * with the License. You may obtain a copy of the License at
  21385. *
  21386. * http://www.apache.org/licenses/LICENSE-2.0
  21387. *
  21388. * Unless required by applicable law or agreed to in writing,
  21389. * software distributed under the License is distributed on an
  21390. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21391. * KIND, either express or implied. See the License for the
  21392. * specific language governing permissions and limitations
  21393. * under the License.
  21394. */
  21395. var colorAll = ['#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'];
  21396. var lightTheme = {
  21397. color: colorAll,
  21398. colorLayer: [['#37A2DA', '#ffd85c', '#fd7b5f'], ['#37A2DA', '#67E0E3', '#FFDB5C', '#ff9f7f', '#E062AE', '#9d96f5'], ['#37A2DA', '#32C5E9', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#e7bcf3', '#8378EA', '#96BFFF'], colorAll]
  21399. };
  21400. /*
  21401. * Licensed to the Apache Software Foundation (ASF) under one
  21402. * or more contributor license agreements. See the NOTICE file
  21403. * distributed with this work for additional information
  21404. * regarding copyright ownership. The ASF licenses this file
  21405. * to you under the Apache License, Version 2.0 (the
  21406. * "License"); you may not use this file except in compliance
  21407. * with the License. You may obtain a copy of the License at
  21408. *
  21409. * http://www.apache.org/licenses/LICENSE-2.0
  21410. *
  21411. * Unless required by applicable law or agreed to in writing,
  21412. * software distributed under the License is distributed on an
  21413. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21414. * KIND, either express or implied. See the License for the
  21415. * specific language governing permissions and limitations
  21416. * under the License.
  21417. */
  21418. var contrastColor = '#eee';
  21419. var axisCommon = function () {
  21420. return {
  21421. axisLine: {
  21422. lineStyle: {
  21423. color: contrastColor
  21424. }
  21425. },
  21426. axisTick: {
  21427. lineStyle: {
  21428. color: contrastColor
  21429. }
  21430. },
  21431. axisLabel: {
  21432. textStyle: {
  21433. color: contrastColor
  21434. }
  21435. },
  21436. splitLine: {
  21437. lineStyle: {
  21438. type: 'dashed',
  21439. color: '#aaa'
  21440. }
  21441. },
  21442. splitArea: {
  21443. areaStyle: {
  21444. color: contrastColor
  21445. }
  21446. }
  21447. };
  21448. };
  21449. var colorPalette = ['#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53', '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42'];
  21450. var theme = {
  21451. color: colorPalette,
  21452. backgroundColor: '#333',
  21453. tooltip: {
  21454. axisPointer: {
  21455. lineStyle: {
  21456. color: contrastColor
  21457. },
  21458. crossStyle: {
  21459. color: contrastColor
  21460. },
  21461. label: {
  21462. color: '#000'
  21463. }
  21464. }
  21465. },
  21466. legend: {
  21467. textStyle: {
  21468. color: contrastColor
  21469. }
  21470. },
  21471. textStyle: {
  21472. color: contrastColor
  21473. },
  21474. title: {
  21475. textStyle: {
  21476. color: contrastColor
  21477. }
  21478. },
  21479. toolbox: {
  21480. iconStyle: {
  21481. normal: {
  21482. borderColor: contrastColor
  21483. }
  21484. }
  21485. },
  21486. dataZoom: {
  21487. textStyle: {
  21488. color: contrastColor
  21489. }
  21490. },
  21491. visualMap: {
  21492. textStyle: {
  21493. color: contrastColor
  21494. }
  21495. },
  21496. timeline: {
  21497. lineStyle: {
  21498. color: contrastColor
  21499. },
  21500. itemStyle: {
  21501. normal: {
  21502. color: colorPalette[1]
  21503. }
  21504. },
  21505. label: {
  21506. normal: {
  21507. textStyle: {
  21508. color: contrastColor
  21509. }
  21510. }
  21511. },
  21512. controlStyle: {
  21513. normal: {
  21514. color: contrastColor,
  21515. borderColor: contrastColor
  21516. }
  21517. }
  21518. },
  21519. timeAxis: axisCommon(),
  21520. logAxis: axisCommon(),
  21521. valueAxis: axisCommon(),
  21522. categoryAxis: axisCommon(),
  21523. line: {
  21524. symbol: 'circle'
  21525. },
  21526. graph: {
  21527. color: colorPalette
  21528. },
  21529. gauge: {
  21530. title: {
  21531. textStyle: {
  21532. color: contrastColor
  21533. }
  21534. }
  21535. },
  21536. candlestick: {
  21537. itemStyle: {
  21538. normal: {
  21539. color: '#FD1050',
  21540. color0: '#0CF49B',
  21541. borderColor: '#FD1050',
  21542. borderColor0: '#0CF49B'
  21543. }
  21544. }
  21545. }
  21546. };
  21547. theme.categoryAxis.splitLine.show = false;
  21548. /*
  21549. * Licensed to the Apache Software Foundation (ASF) under one
  21550. * or more contributor license agreements. See the NOTICE file
  21551. * distributed with this work for additional information
  21552. * regarding copyright ownership. The ASF licenses this file
  21553. * to you under the Apache License, Version 2.0 (the
  21554. * "License"); you may not use this file except in compliance
  21555. * with the License. You may obtain a copy of the License at
  21556. *
  21557. * http://www.apache.org/licenses/LICENSE-2.0
  21558. *
  21559. * Unless required by applicable law or agreed to in writing,
  21560. * software distributed under the License is distributed on an
  21561. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21562. * KIND, either express or implied. See the License for the
  21563. * specific language governing permissions and limitations
  21564. * under the License.
  21565. */
  21566. /**
  21567. * This module is imported by echarts directly.
  21568. *
  21569. * Notice:
  21570. * Always keep this file exists for backward compatibility.
  21571. * Because before 4.1.0, dataset is an optional component,
  21572. * some users may import this module manually.
  21573. */
  21574. ComponentModel.extend({
  21575. type: 'dataset',
  21576. /**
  21577. * @protected
  21578. */
  21579. defaultOption: {
  21580. // 'row', 'column'
  21581. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  21582. // null/'auto': auto detect header, see "module:echarts/data/helper/sourceHelper"
  21583. sourceHeader: null,
  21584. dimensions: null,
  21585. source: null
  21586. },
  21587. optionUpdated: function () {
  21588. detectSourceFormat(this);
  21589. }
  21590. });
  21591. Component.extend({
  21592. type: 'dataset'
  21593. });
  21594. /**
  21595. * 椭圆形状
  21596. * @module zrender/graphic/shape/Ellipse
  21597. */
  21598. var Ellipse = Path.extend({
  21599. type: 'ellipse',
  21600. shape: {
  21601. cx: 0,
  21602. cy: 0,
  21603. rx: 0,
  21604. ry: 0
  21605. },
  21606. buildPath: function (ctx, shape) {
  21607. var k = 0.5522848;
  21608. var x = shape.cx;
  21609. var y = shape.cy;
  21610. var a = shape.rx;
  21611. var b = shape.ry;
  21612. var ox = a * k; // 水平控制点偏移量
  21613. var oy = b * k; // 垂直控制点偏移量
  21614. // 从椭圆的左端点开始顺时针绘制四条三次贝塞尔曲线
  21615. ctx.moveTo(x - a, y);
  21616. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  21617. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  21618. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  21619. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  21620. ctx.closePath();
  21621. }
  21622. }); // import RadialGradient from '../graphic/RadialGradient';
  21623. // import Pattern from '../graphic/Pattern';
  21624. // import * as vector from '../core/vector';
  21625. // Most of the values can be separated by comma and/or white space.
  21626. var DILIMITER_REG = /[\s,]+/;
  21627. /**
  21628. * For big svg string, this method might be time consuming.
  21629. *
  21630. * @param {string} svg xml string
  21631. * @return {Object} xml root.
  21632. */
  21633. function parseXML(svg) {
  21634. if (isString(svg)) {
  21635. var parser = new DOMParser();
  21636. svg = parser.parseFromString(svg, 'text/xml');
  21637. } // Document node. If using $.get, doc node may be input.
  21638. if (svg.nodeType === 9) {
  21639. svg = svg.firstChild;
  21640. } // nodeName of <!DOCTYPE svg> is also 'svg'.
  21641. while (svg.nodeName.toLowerCase() !== 'svg' || svg.nodeType !== 1) {
  21642. svg = svg.nextSibling;
  21643. }
  21644. return svg;
  21645. }
  21646. function SVGParser() {
  21647. this._defs = {};
  21648. this._root = null;
  21649. this._isDefine = false;
  21650. this._isText = false;
  21651. }
  21652. SVGParser.prototype.parse = function (xml, opt) {
  21653. opt = opt || {};
  21654. var svg = parseXML(xml);
  21655. if (!svg) {
  21656. throw new Error('Illegal svg');
  21657. }
  21658. var root = new Group();
  21659. this._root = root; // parse view port
  21660. var viewBox = svg.getAttribute('viewBox') || ''; // If width/height not specified, means "100%" of `opt.width/height`.
  21661. // TODO: Other percent value not supported yet.
  21662. var width = parseFloat(svg.getAttribute('width') || opt.width);
  21663. var height = parseFloat(svg.getAttribute('height') || opt.height); // If width/height not specified, set as null for output.
  21664. isNaN(width) && (width = null);
  21665. isNaN(height) && (height = null); // Apply inline style on svg element.
  21666. parseAttributes(svg, root, null, true);
  21667. var child = svg.firstChild;
  21668. while (child) {
  21669. this._parseNode(child, root);
  21670. child = child.nextSibling;
  21671. }
  21672. var viewBoxRect;
  21673. var viewBoxTransform;
  21674. if (viewBox) {
  21675. var viewBoxArr = trim(viewBox).split(DILIMITER_REG); // Some invalid case like viewBox: 'none'.
  21676. if (viewBoxArr.length >= 4) {
  21677. viewBoxRect = {
  21678. x: parseFloat(viewBoxArr[0] || 0),
  21679. y: parseFloat(viewBoxArr[1] || 0),
  21680. width: parseFloat(viewBoxArr[2]),
  21681. height: parseFloat(viewBoxArr[3])
  21682. };
  21683. }
  21684. }
  21685. if (viewBoxRect && width != null && height != null) {
  21686. viewBoxTransform = makeViewBoxTransform(viewBoxRect, width, height);
  21687. if (!opt.ignoreViewBox) {
  21688. // If set transform on the output group, it probably bring trouble when
  21689. // some users only intend to show the clipped content inside the viewBox,
  21690. // but not intend to transform the output group. So we keep the output
  21691. // group no transform. If the user intend to use the viewBox as a
  21692. // camera, just set `opt.ignoreViewBox` as `true` and set transfrom
  21693. // manually according to the viewBox info in the output of this method.
  21694. var elRoot = root;
  21695. root = new Group();
  21696. root.add(elRoot);
  21697. elRoot.scale = viewBoxTransform.scale.slice();
  21698. elRoot.position = viewBoxTransform.position.slice();
  21699. }
  21700. } // Some shapes might be overflow the viewport, which should be
  21701. // clipped despite whether the viewBox is used, as the SVG does.
  21702. if (!opt.ignoreRootClip && width != null && height != null) {
  21703. root.setClipPath(new Rect({
  21704. shape: {
  21705. x: 0,
  21706. y: 0,
  21707. width: width,
  21708. height: height
  21709. }
  21710. }));
  21711. } // Set width/height on group just for output the viewport size.
  21712. return {
  21713. root: root,
  21714. width: width,
  21715. height: height,
  21716. viewBoxRect: viewBoxRect,
  21717. viewBoxTransform: viewBoxTransform
  21718. };
  21719. };
  21720. SVGParser.prototype._parseNode = function (xmlNode, parentGroup) {
  21721. var nodeName = xmlNode.nodeName.toLowerCase(); // TODO
  21722. // support <style>...</style> in svg, where nodeName is 'style',
  21723. // CSS classes is defined globally wherever the style tags are declared.
  21724. if (nodeName === 'defs') {
  21725. // define flag
  21726. this._isDefine = true;
  21727. } else if (nodeName === 'text') {
  21728. this._isText = true;
  21729. }
  21730. var el;
  21731. if (this._isDefine) {
  21732. var parser = defineParsers[nodeName];
  21733. if (parser) {
  21734. var def = parser.call(this, xmlNode);
  21735. var id = xmlNode.getAttribute('id');
  21736. if (id) {
  21737. this._defs[id] = def;
  21738. }
  21739. }
  21740. } else {
  21741. var parser = nodeParsers[nodeName];
  21742. if (parser) {
  21743. el = parser.call(this, xmlNode, parentGroup);
  21744. parentGroup.add(el);
  21745. }
  21746. }
  21747. var child = xmlNode.firstChild;
  21748. while (child) {
  21749. if (child.nodeType === 1) {
  21750. this._parseNode(child, el);
  21751. } // Is text
  21752. if (child.nodeType === 3 && this._isText) {
  21753. this._parseText(child, el);
  21754. }
  21755. child = child.nextSibling;
  21756. } // Quit define
  21757. if (nodeName === 'defs') {
  21758. this._isDefine = false;
  21759. } else if (nodeName === 'text') {
  21760. this._isText = false;
  21761. }
  21762. };
  21763. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  21764. if (xmlNode.nodeType === 1) {
  21765. var dx = xmlNode.getAttribute('dx') || 0;
  21766. var dy = xmlNode.getAttribute('dy') || 0;
  21767. this._textX += parseFloat(dx);
  21768. this._textY += parseFloat(dy);
  21769. }
  21770. var text = new Text({
  21771. style: {
  21772. text: xmlNode.textContent,
  21773. transformText: true
  21774. },
  21775. position: [this._textX || 0, this._textY || 0]
  21776. });
  21777. inheritStyle(parentGroup, text);
  21778. parseAttributes(xmlNode, text, this._defs);
  21779. var fontSize = text.style.fontSize;
  21780. if (fontSize && fontSize < 9) {
  21781. // PENDING
  21782. text.style.fontSize = 9;
  21783. text.scale = text.scale || [1, 1];
  21784. text.scale[0] *= fontSize / 9;
  21785. text.scale[1] *= fontSize / 9;
  21786. }
  21787. var rect = text.getBoundingRect();
  21788. this._textX += rect.width;
  21789. parentGroup.add(text);
  21790. return text;
  21791. };
  21792. var nodeParsers = {
  21793. 'g': function (xmlNode, parentGroup) {
  21794. var g = new Group();
  21795. inheritStyle(parentGroup, g);
  21796. parseAttributes(xmlNode, g, this._defs);
  21797. return g;
  21798. },
  21799. 'rect': function (xmlNode, parentGroup) {
  21800. var rect = new Rect();
  21801. inheritStyle(parentGroup, rect);
  21802. parseAttributes(xmlNode, rect, this._defs);
  21803. rect.setShape({
  21804. x: parseFloat(xmlNode.getAttribute('x') || 0),
  21805. y: parseFloat(xmlNode.getAttribute('y') || 0),
  21806. width: parseFloat(xmlNode.getAttribute('width') || 0),
  21807. height: parseFloat(xmlNode.getAttribute('height') || 0)
  21808. }); // console.log(xmlNode.getAttribute('transform'));
  21809. // console.log(rect.transform);
  21810. return rect;
  21811. },
  21812. 'circle': function (xmlNode, parentGroup) {
  21813. var circle = new Circle();
  21814. inheritStyle(parentGroup, circle);
  21815. parseAttributes(xmlNode, circle, this._defs);
  21816. circle.setShape({
  21817. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  21818. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  21819. r: parseFloat(xmlNode.getAttribute('r') || 0)
  21820. });
  21821. return circle;
  21822. },
  21823. 'line': function (xmlNode, parentGroup) {
  21824. var line = new Line();
  21825. inheritStyle(parentGroup, line);
  21826. parseAttributes(xmlNode, line, this._defs);
  21827. line.setShape({
  21828. x1: parseFloat(xmlNode.getAttribute('x1') || 0),
  21829. y1: parseFloat(xmlNode.getAttribute('y1') || 0),
  21830. x2: parseFloat(xmlNode.getAttribute('x2') || 0),
  21831. y2: parseFloat(xmlNode.getAttribute('y2') || 0)
  21832. });
  21833. return line;
  21834. },
  21835. 'ellipse': function (xmlNode, parentGroup) {
  21836. var ellipse = new Ellipse();
  21837. inheritStyle(parentGroup, ellipse);
  21838. parseAttributes(xmlNode, ellipse, this._defs);
  21839. ellipse.setShape({
  21840. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  21841. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  21842. rx: parseFloat(xmlNode.getAttribute('rx') || 0),
  21843. ry: parseFloat(xmlNode.getAttribute('ry') || 0)
  21844. });
  21845. return ellipse;
  21846. },
  21847. 'polygon': function (xmlNode, parentGroup) {
  21848. var points = xmlNode.getAttribute('points');
  21849. if (points) {
  21850. points = parsePoints(points);
  21851. }
  21852. var polygon = new Polygon({
  21853. shape: {
  21854. points: points || []
  21855. }
  21856. });
  21857. inheritStyle(parentGroup, polygon);
  21858. parseAttributes(xmlNode, polygon, this._defs);
  21859. return polygon;
  21860. },
  21861. 'polyline': function (xmlNode, parentGroup) {
  21862. var path = new Path();
  21863. inheritStyle(parentGroup, path);
  21864. parseAttributes(xmlNode, path, this._defs);
  21865. var points = xmlNode.getAttribute('points');
  21866. if (points) {
  21867. points = parsePoints(points);
  21868. }
  21869. var polyline = new Polyline({
  21870. shape: {
  21871. points: points || []
  21872. }
  21873. });
  21874. return polyline;
  21875. },
  21876. 'image': function (xmlNode, parentGroup) {
  21877. var img = new ZImage();
  21878. inheritStyle(parentGroup, img);
  21879. parseAttributes(xmlNode, img, this._defs);
  21880. img.setStyle({
  21881. image: xmlNode.getAttribute('xlink:href'),
  21882. x: xmlNode.getAttribute('x'),
  21883. y: xmlNode.getAttribute('y'),
  21884. width: xmlNode.getAttribute('width'),
  21885. height: xmlNode.getAttribute('height')
  21886. });
  21887. return img;
  21888. },
  21889. 'text': function (xmlNode, parentGroup) {
  21890. var x = xmlNode.getAttribute('x') || 0;
  21891. var y = xmlNode.getAttribute('y') || 0;
  21892. var dx = xmlNode.getAttribute('dx') || 0;
  21893. var dy = xmlNode.getAttribute('dy') || 0;
  21894. this._textX = parseFloat(x) + parseFloat(dx);
  21895. this._textY = parseFloat(y) + parseFloat(dy);
  21896. var g = new Group();
  21897. inheritStyle(parentGroup, g);
  21898. parseAttributes(xmlNode, g, this._defs);
  21899. return g;
  21900. },
  21901. 'tspan': function (xmlNode, parentGroup) {
  21902. var x = xmlNode.getAttribute('x');
  21903. var y = xmlNode.getAttribute('y');
  21904. if (x != null) {
  21905. // new offset x
  21906. this._textX = parseFloat(x);
  21907. }
  21908. if (y != null) {
  21909. // new offset y
  21910. this._textY = parseFloat(y);
  21911. }
  21912. var dx = xmlNode.getAttribute('dx') || 0;
  21913. var dy = xmlNode.getAttribute('dy') || 0;
  21914. var g = new Group();
  21915. inheritStyle(parentGroup, g);
  21916. parseAttributes(xmlNode, g, this._defs);
  21917. this._textX += dx;
  21918. this._textY += dy;
  21919. return g;
  21920. },
  21921. 'path': function (xmlNode, parentGroup) {
  21922. // TODO svg fill rule
  21923. // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
  21924. // path.style.globalCompositeOperation = 'xor';
  21925. var d = xmlNode.getAttribute('d') || ''; // Performance sensitive.
  21926. var path = createFromString(d);
  21927. inheritStyle(parentGroup, path);
  21928. parseAttributes(xmlNode, path, this._defs);
  21929. return path;
  21930. }
  21931. };
  21932. var defineParsers = {
  21933. 'lineargradient': function (xmlNode) {
  21934. var x1 = parseInt(xmlNode.getAttribute('x1') || 0, 10);
  21935. var y1 = parseInt(xmlNode.getAttribute('y1') || 0, 10);
  21936. var x2 = parseInt(xmlNode.getAttribute('x2') || 10, 10);
  21937. var y2 = parseInt(xmlNode.getAttribute('y2') || 0, 10);
  21938. var gradient = new LinearGradient(x1, y1, x2, y2);
  21939. _parseGradientColorStops(xmlNode, gradient);
  21940. return gradient;
  21941. },
  21942. 'radialgradient': function (xmlNode) {}
  21943. };
  21944. function _parseGradientColorStops(xmlNode, gradient) {
  21945. var stop = xmlNode.firstChild;
  21946. while (stop) {
  21947. if (stop.nodeType === 1) {
  21948. var offset = stop.getAttribute('offset');
  21949. if (offset.indexOf('%') > 0) {
  21950. // percentage
  21951. offset = parseInt(offset, 10) / 100;
  21952. } else if (offset) {
  21953. // number from 0 to 1
  21954. offset = parseFloat(offset);
  21955. } else {
  21956. offset = 0;
  21957. }
  21958. var stopColor = stop.getAttribute('stop-color') || '#000000';
  21959. gradient.addColorStop(offset, stopColor);
  21960. }
  21961. stop = stop.nextSibling;
  21962. }
  21963. }
  21964. function inheritStyle(parent, child) {
  21965. if (parent && parent.__inheritedStyle) {
  21966. if (!child.__inheritedStyle) {
  21967. child.__inheritedStyle = {};
  21968. }
  21969. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  21970. }
  21971. }
  21972. function parsePoints(pointsString) {
  21973. var list = trim(pointsString).split(DILIMITER_REG);
  21974. var points = [];
  21975. for (var i = 0; i < list.length; i += 2) {
  21976. var x = parseFloat(list[i]);
  21977. var y = parseFloat(list[i + 1]);
  21978. points.push([x, y]);
  21979. }
  21980. return points;
  21981. }
  21982. var attributesMap = {
  21983. 'fill': 'fill',
  21984. 'stroke': 'stroke',
  21985. 'stroke-width': 'lineWidth',
  21986. 'opacity': 'opacity',
  21987. 'fill-opacity': 'fillOpacity',
  21988. 'stroke-opacity': 'strokeOpacity',
  21989. 'stroke-dasharray': 'lineDash',
  21990. 'stroke-dashoffset': 'lineDashOffset',
  21991. 'stroke-linecap': 'lineCap',
  21992. 'stroke-linejoin': 'lineJoin',
  21993. 'stroke-miterlimit': 'miterLimit',
  21994. 'font-family': 'fontFamily',
  21995. 'font-size': 'fontSize',
  21996. 'font-style': 'fontStyle',
  21997. 'font-weight': 'fontWeight',
  21998. 'text-align': 'textAlign',
  21999. 'alignment-baseline': 'textBaseline'
  22000. };
  22001. function parseAttributes(xmlNode, el, defs, onlyInlineStyle) {
  22002. var zrStyle = el.__inheritedStyle || {};
  22003. var isTextEl = el.type === 'text'; // TODO Shadow
  22004. if (xmlNode.nodeType === 1) {
  22005. parseTransformAttribute(xmlNode, el);
  22006. extend(zrStyle, parseStyleAttribute(xmlNode));
  22007. if (!onlyInlineStyle) {
  22008. for (var svgAttrName in attributesMap) {
  22009. if (attributesMap.hasOwnProperty(svgAttrName)) {
  22010. var attrValue = xmlNode.getAttribute(svgAttrName);
  22011. if (attrValue != null) {
  22012. zrStyle[attributesMap[svgAttrName]] = attrValue;
  22013. }
  22014. }
  22015. }
  22016. }
  22017. }
  22018. var elFillProp = isTextEl ? 'textFill' : 'fill';
  22019. var elStrokeProp = isTextEl ? 'textStroke' : 'stroke';
  22020. el.style = el.style || new Style();
  22021. var elStyle = el.style;
  22022. zrStyle.fill != null && elStyle.set(elFillProp, getPaint(zrStyle.fill, defs));
  22023. zrStyle.stroke != null && elStyle.set(elStrokeProp, getPaint(zrStyle.stroke, defs));
  22024. each$1(['lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'], function (propName) {
  22025. var elPropName = propName === 'lineWidth' && isTextEl ? 'textStrokeWidth' : propName;
  22026. zrStyle[propName] != null && elStyle.set(elPropName, parseFloat(zrStyle[propName]));
  22027. });
  22028. if (!zrStyle.textBaseline || zrStyle.textBaseline === 'auto') {
  22029. zrStyle.textBaseline = 'alphabetic';
  22030. }
  22031. if (zrStyle.textBaseline === 'alphabetic') {
  22032. zrStyle.textBaseline = 'bottom';
  22033. }
  22034. if (zrStyle.textAlign === 'start') {
  22035. zrStyle.textAlign = 'left';
  22036. }
  22037. if (zrStyle.textAlign === 'end') {
  22038. zrStyle.textAlign = 'right';
  22039. }
  22040. each$1(['lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'textBaseline'], function (propName) {
  22041. zrStyle[propName] != null && elStyle.set(propName, zrStyle[propName]);
  22042. });
  22043. if (zrStyle.lineDash) {
  22044. el.style.lineDash = trim(zrStyle.lineDash).split(DILIMITER_REG);
  22045. }
  22046. if (elStyle[elStrokeProp] && elStyle[elStrokeProp] !== 'none') {
  22047. // enable stroke
  22048. el[elStrokeProp] = true;
  22049. }
  22050. el.__inheritedStyle = zrStyle;
  22051. }
  22052. var urlRegex = /url\(\s*#(.*?)\)/;
  22053. function getPaint(str, defs) {
  22054. // if (str === 'none') {
  22055. // return;
  22056. // }
  22057. var urlMatch = defs && str && str.match(urlRegex);
  22058. if (urlMatch) {
  22059. var url = trim(urlMatch[1]);
  22060. var def = defs[url];
  22061. return def;
  22062. }
  22063. return str;
  22064. }
  22065. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.e,]*)\)/g;
  22066. function parseTransformAttribute(xmlNode, node) {
  22067. var transform = xmlNode.getAttribute('transform');
  22068. if (transform) {
  22069. transform = transform.replace(/,/g, ' ');
  22070. var m = null;
  22071. var transformOps = [];
  22072. transform.replace(transformRegex, function (str, type, value) {
  22073. transformOps.push(type, value);
  22074. });
  22075. for (var i = transformOps.length - 1; i > 0; i -= 2) {
  22076. var value = transformOps[i];
  22077. var type = transformOps[i - 1];
  22078. m = m || create$1();
  22079. switch (type) {
  22080. case 'translate':
  22081. value = trim(value).split(DILIMITER_REG);
  22082. translate(m, m, [parseFloat(value[0]), parseFloat(value[1] || 0)]);
  22083. break;
  22084. case 'scale':
  22085. value = trim(value).split(DILIMITER_REG);
  22086. scale$1(m, m, [parseFloat(value[0]), parseFloat(value[1] || value[0])]);
  22087. break;
  22088. case 'rotate':
  22089. value = trim(value).split(DILIMITER_REG);
  22090. rotate(m, m, parseFloat(value[0]));
  22091. break;
  22092. case 'skew':
  22093. value = trim(value).split(DILIMITER_REG);
  22094. console.warn('Skew transform is not supported yet');
  22095. break;
  22096. case 'matrix':
  22097. var value = trim(value).split(DILIMITER_REG);
  22098. m[0] = parseFloat(value[0]);
  22099. m[1] = parseFloat(value[1]);
  22100. m[2] = parseFloat(value[2]);
  22101. m[3] = parseFloat(value[3]);
  22102. m[4] = parseFloat(value[4]);
  22103. m[5] = parseFloat(value[5]);
  22104. break;
  22105. }
  22106. }
  22107. node.setLocalTransform(m);
  22108. }
  22109. } // Value may contain space.
  22110. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  22111. function parseStyleAttribute(xmlNode) {
  22112. var style = xmlNode.getAttribute('style');
  22113. var result = {};
  22114. if (!style) {
  22115. return result;
  22116. }
  22117. var styleList = {};
  22118. styleRegex.lastIndex = 0;
  22119. var styleRegResult;
  22120. while ((styleRegResult = styleRegex.exec(style)) != null) {
  22121. styleList[styleRegResult[1]] = styleRegResult[2];
  22122. }
  22123. for (var svgAttrName in attributesMap) {
  22124. if (attributesMap.hasOwnProperty(svgAttrName) && styleList[svgAttrName] != null) {
  22125. result[attributesMap[svgAttrName]] = styleList[svgAttrName];
  22126. }
  22127. }
  22128. return result;
  22129. }
  22130. /**
  22131. * @param {Array.<number>} viewBoxRect
  22132. * @param {number} width
  22133. * @param {number} height
  22134. * @return {Object} {scale, position}
  22135. */
  22136. function makeViewBoxTransform(viewBoxRect, width, height) {
  22137. var scaleX = width / viewBoxRect.width;
  22138. var scaleY = height / viewBoxRect.height;
  22139. var scale = Math.min(scaleX, scaleY); // preserveAspectRatio 'xMidYMid'
  22140. var viewBoxScale = [scale, scale];
  22141. var viewBoxPosition = [-(viewBoxRect.x + viewBoxRect.width / 2) * scale + width / 2, -(viewBoxRect.y + viewBoxRect.height / 2) * scale + height / 2];
  22142. return {
  22143. scale: viewBoxScale,
  22144. position: viewBoxPosition
  22145. };
  22146. }
  22147. /**
  22148. * @param {string|XMLElement} xml
  22149. * @param {Object} [opt]
  22150. * @param {number} [opt.width] Default width if svg width not specified or is a percent value.
  22151. * @param {number} [opt.height] Default height if svg height not specified or is a percent value.
  22152. * @param {boolean} [opt.ignoreViewBox]
  22153. * @param {boolean} [opt.ignoreRootClip]
  22154. * @return {Object} result:
  22155. * {
  22156. * root: Group, The root of the the result tree of zrender shapes,
  22157. * width: number, the viewport width of the SVG,
  22158. * height: number, the viewport height of the SVG,
  22159. * viewBoxRect: {x, y, width, height}, the declared viewBox rect of the SVG, if exists,
  22160. * viewBoxTransform: the {scale, position} calculated by viewBox and viewport, is exists.
  22161. * }
  22162. */
  22163. /*
  22164. * Licensed to the Apache Software Foundation (ASF) under one
  22165. * or more contributor license agreements. See the NOTICE file
  22166. * distributed with this work for additional information
  22167. * regarding copyright ownership. The ASF licenses this file
  22168. * to you under the Apache License, Version 2.0 (the
  22169. * "License"); you may not use this file except in compliance
  22170. * with the License. You may obtain a copy of the License at
  22171. *
  22172. * http://www.apache.org/licenses/LICENSE-2.0
  22173. *
  22174. * Unless required by applicable law or agreed to in writing,
  22175. * software distributed under the License is distributed on an
  22176. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22177. * KIND, either express or implied. See the License for the
  22178. * specific language governing permissions and limitations
  22179. * under the License.
  22180. */
  22181. var storage = createHashMap(); // For minimize the code size of common echarts package,
  22182. // do not put too much logic in this module.
  22183. var mapDataStorage = {
  22184. // The format of record: see `echarts.registerMap`.
  22185. // Compatible with previous `echarts.registerMap`.
  22186. registerMap: function (mapName, rawGeoJson, rawSpecialAreas) {
  22187. var records;
  22188. if (isArray(rawGeoJson)) {
  22189. records = rawGeoJson;
  22190. } else if (rawGeoJson.svg) {
  22191. records = [{
  22192. type: 'svg',
  22193. source: rawGeoJson.svg,
  22194. specialAreas: rawGeoJson.specialAreas
  22195. }];
  22196. } else {
  22197. // Backward compatibility.
  22198. if (rawGeoJson.geoJson && !rawGeoJson.features) {
  22199. rawSpecialAreas = rawGeoJson.specialAreas;
  22200. rawGeoJson = rawGeoJson.geoJson;
  22201. }
  22202. records = [{
  22203. type: 'geoJSON',
  22204. source: rawGeoJson,
  22205. specialAreas: rawSpecialAreas
  22206. }];
  22207. }
  22208. each$1(records, function (record) {
  22209. var type = record.type;
  22210. type === 'geoJson' && (type = record.type = 'geoJSON');
  22211. var parse = parsers[type];
  22212. if (__DEV__) {
  22213. assert$1(parse, 'Illegal map type: ' + type);
  22214. }
  22215. parse(record);
  22216. });
  22217. return storage.set(mapName, records);
  22218. },
  22219. retrieveMap: function (mapName) {
  22220. return storage.get(mapName);
  22221. }
  22222. };
  22223. var parsers = {
  22224. geoJSON: function (record) {
  22225. var source = record.source;
  22226. record.geoJSON = !isString(source) ? source : typeof JSON !== 'undefined' && JSON.parse ? JSON.parse(source) : new Function('return (' + source + ');')();
  22227. },
  22228. // Only perform parse to XML object here, which might be time
  22229. // consiming for large SVG.
  22230. // Although convert XML to zrender element is also time consiming,
  22231. // if we do it here, the clone of zrender elements has to be
  22232. // required. So we do it once for each geo instance, util real
  22233. // performance issues call for optimizing it.
  22234. svg: function (record) {
  22235. record.svgXML = parseXML(record.source);
  22236. }
  22237. };
  22238. /*
  22239. * Licensed to the Apache Software Foundation (ASF) under one
  22240. * or more contributor license agreements. See the NOTICE file
  22241. * distributed with this work for additional information
  22242. * regarding copyright ownership. The ASF licenses this file
  22243. * to you under the Apache License, Version 2.0 (the
  22244. * "License"); you may not use this file except in compliance
  22245. * with the License. You may obtain a copy of the License at
  22246. *
  22247. * http://www.apache.org/licenses/LICENSE-2.0
  22248. *
  22249. * Unless required by applicable law or agreed to in writing,
  22250. * software distributed under the License is distributed on an
  22251. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22252. * KIND, either express or implied. See the License for the
  22253. * specific language governing permissions and limitations
  22254. * under the License.
  22255. */
  22256. var assert = assert$1;
  22257. var each = each$1;
  22258. var isFunction = isFunction$1;
  22259. var isObject = isObject$1;
  22260. var parseClassType = ComponentModel.parseClassType;
  22261. var version = '4.9.0';
  22262. var dependencies = {
  22263. zrender: '4.3.2'
  22264. };
  22265. var TEST_FRAME_REMAIN_TIME = 1;
  22266. var PRIORITY_PROCESSOR_FILTER = 1000;
  22267. var PRIORITY_PROCESSOR_SERIES_FILTER = 800;
  22268. var PRIORITY_PROCESSOR_DATASTACK = 900;
  22269. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  22270. var PRIORITY_VISUAL_LAYOUT = 1000;
  22271. var PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;
  22272. var PRIORITY_VISUAL_GLOBAL = 2000;
  22273. var PRIORITY_VISUAL_CHART = 3000;
  22274. var PRIORITY_VISUAL_POST_CHART_LAYOUT = 3500;
  22275. var PRIORITY_VISUAL_COMPONENT = 4000; // FIXME
  22276. // necessary?
  22277. var PRIORITY_VISUAL_BRUSH = 5000;
  22278. var PRIORITY = {
  22279. PROCESSOR: {
  22280. FILTER: PRIORITY_PROCESSOR_FILTER,
  22281. SERIES_FILTER: PRIORITY_PROCESSOR_SERIES_FILTER,
  22282. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  22283. },
  22284. VISUAL: {
  22285. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  22286. PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,
  22287. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  22288. CHART: PRIORITY_VISUAL_CHART,
  22289. POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,
  22290. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  22291. BRUSH: PRIORITY_VISUAL_BRUSH
  22292. }
  22293. }; // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  22294. // where they must not be invoked nestedly, except the only case: invoke
  22295. // dispatchAction with updateMethod "none" in main process.
  22296. // This flag is used to carry out this rule.
  22297. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  22298. var IN_MAIN_PROCESS = '__flagInMainProcess';
  22299. var OPTION_UPDATED = '__optionUpdated';
  22300. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  22301. function createRegisterEventWithLowercaseName(method, ignoreDisposed) {
  22302. return function (eventName, handler, context) {
  22303. if (!ignoreDisposed && this._disposed) {
  22304. disposedWarning(this.id);
  22305. return;
  22306. } // Event name is all lowercase
  22307. eventName = eventName && eventName.toLowerCase();
  22308. Eventful.prototype[method].call(this, eventName, handler, context);
  22309. };
  22310. }
  22311. /**
  22312. * @module echarts~MessageCenter
  22313. */
  22314. function MessageCenter() {
  22315. Eventful.call(this);
  22316. }
  22317. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on', true);
  22318. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off', true);
  22319. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one', true);
  22320. mixin(MessageCenter, Eventful);
  22321. /**
  22322. * @module echarts~ECharts
  22323. */
  22324. function ECharts(dom, theme$$1, opts) {
  22325. opts = opts || {}; // Get theme by name
  22326. if (typeof theme$$1 === 'string') {
  22327. theme$$1 = themeStorage[theme$$1];
  22328. }
  22329. /**
  22330. * @type {string}
  22331. */
  22332. this.id;
  22333. /**
  22334. * Group id
  22335. * @type {string}
  22336. */
  22337. this.group;
  22338. /**
  22339. * @type {HTMLElement}
  22340. * @private
  22341. */
  22342. this._dom = dom;
  22343. var defaultRenderer = 'canvas';
  22344. if (__DEV__) {
  22345. defaultRenderer = (typeof window === 'undefined' ? global : window).__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
  22346. }
  22347. /**
  22348. * @type {module:zrender/ZRender}
  22349. * @private
  22350. */
  22351. var zr = this._zr = init$1(dom, {
  22352. renderer: opts.renderer || defaultRenderer,
  22353. devicePixelRatio: opts.devicePixelRatio,
  22354. width: opts.width,
  22355. height: opts.height
  22356. });
  22357. /**
  22358. * Expect 60 fps.
  22359. * @type {Function}
  22360. * @private
  22361. */
  22362. this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  22363. var theme$$1 = clone(theme$$1);
  22364. theme$$1 && backwardCompat(theme$$1, true);
  22365. /**
  22366. * @type {Object}
  22367. * @private
  22368. */
  22369. this._theme = theme$$1;
  22370. /**
  22371. * @type {Array.<module:echarts/view/Chart>}
  22372. * @private
  22373. */
  22374. this._chartsViews = [];
  22375. /**
  22376. * @type {Object.<string, module:echarts/view/Chart>}
  22377. * @private
  22378. */
  22379. this._chartsMap = {};
  22380. /**
  22381. * @type {Array.<module:echarts/view/Component>}
  22382. * @private
  22383. */
  22384. this._componentsViews = [];
  22385. /**
  22386. * @type {Object.<string, module:echarts/view/Component>}
  22387. * @private
  22388. */
  22389. this._componentsMap = {};
  22390. /**
  22391. * @type {module:echarts/CoordinateSystem}
  22392. * @private
  22393. */
  22394. this._coordSysMgr = new CoordinateSystemManager();
  22395. /**
  22396. * @type {module:echarts/ExtensionAPI}
  22397. * @private
  22398. */
  22399. var api = this._api = createExtensionAPI(this); // Sort on demand
  22400. function prioritySortFunc(a, b) {
  22401. return a.__prio - b.__prio;
  22402. }
  22403. sort(visualFuncs, prioritySortFunc);
  22404. sort(dataProcessorFuncs, prioritySortFunc);
  22405. /**
  22406. * @type {module:echarts/stream/Scheduler}
  22407. */
  22408. this._scheduler = new Scheduler(this, api, dataProcessorFuncs, visualFuncs);
  22409. Eventful.call(this, this._ecEventProcessor = new EventProcessor());
  22410. /**
  22411. * @type {module:echarts~MessageCenter}
  22412. * @private
  22413. */
  22414. this._messageCenter = new MessageCenter(); // Init mouse events
  22415. this._initEvents(); // In case some people write `window.onresize = chart.resize`
  22416. this.resize = bind(this.resize, this); // Can't dispatch action during rendering procedure
  22417. this._pendingActions = [];
  22418. zr.animation.on('frame', this._onframe, this);
  22419. bindRenderedEvent(zr, this); // ECharts instance can be used as value.
  22420. setAsPrimitive(this);
  22421. }
  22422. var echartsProto = ECharts.prototype;
  22423. echartsProto._onframe = function () {
  22424. if (this._disposed) {
  22425. return;
  22426. }
  22427. var scheduler = this._scheduler; // Lazy update
  22428. if (this[OPTION_UPDATED]) {
  22429. var silent = this[OPTION_UPDATED].silent;
  22430. this[IN_MAIN_PROCESS] = true;
  22431. prepare(this);
  22432. updateMethods.update.call(this);
  22433. this[IN_MAIN_PROCESS] = false;
  22434. this[OPTION_UPDATED] = false;
  22435. flushPendingActions.call(this, silent);
  22436. triggerUpdatedEvent.call(this, silent);
  22437. } // Avoid do both lazy update and progress in one frame.
  22438. else if (scheduler.unfinished) {
  22439. // Stream progress.
  22440. var remainTime = TEST_FRAME_REMAIN_TIME;
  22441. var ecModel = this._model;
  22442. var api = this._api;
  22443. scheduler.unfinished = false;
  22444. do {
  22445. var startTime = +new Date();
  22446. scheduler.performSeriesTasks(ecModel); // Currently dataProcessorFuncs do not check threshold.
  22447. scheduler.performDataProcessorTasks(ecModel);
  22448. updateStreamModes(this, ecModel); // Do not update coordinate system here. Because that coord system update in
  22449. // each frame is not a good user experience. So we follow the rule that
  22450. // the extent of the coordinate system is determin in the first frame (the
  22451. // frame is executed immedietely after task reset.
  22452. // this._coordSysMgr.update(ecModel, api);
  22453. // console.log('--- ec frame visual ---', remainTime);
  22454. scheduler.performVisualTasks(ecModel);
  22455. renderSeries(this, this._model, api, 'remain');
  22456. remainTime -= +new Date() - startTime;
  22457. } while (remainTime > 0 && scheduler.unfinished); // Call flush explicitly for trigger finished event.
  22458. if (!scheduler.unfinished) {
  22459. this._zr.flush();
  22460. } // Else, zr flushing be ensue within the same frame,
  22461. // because zr flushing is after onframe event.
  22462. }
  22463. };
  22464. /**
  22465. * @return {HTMLElement}
  22466. */
  22467. echartsProto.getDom = function () {
  22468. return this._dom;
  22469. };
  22470. /**
  22471. * @return {module:zrender~ZRender}
  22472. */
  22473. echartsProto.getZr = function () {
  22474. return this._zr;
  22475. };
  22476. /**
  22477. * Usage:
  22478. * chart.setOption(option, notMerge, lazyUpdate);
  22479. * chart.setOption(option, {
  22480. * notMerge: ...,
  22481. * lazyUpdate: ...,
  22482. * silent: ...
  22483. * });
  22484. *
  22485. * @param {Object} option
  22486. * @param {Object|boolean} [opts] opts or notMerge.
  22487. * @param {boolean} [opts.notMerge=false]
  22488. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  22489. */
  22490. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  22491. if (__DEV__) {
  22492. assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  22493. }
  22494. if (this._disposed) {
  22495. disposedWarning(this.id);
  22496. return;
  22497. }
  22498. var silent;
  22499. if (isObject(notMerge)) {
  22500. lazyUpdate = notMerge.lazyUpdate;
  22501. silent = notMerge.silent;
  22502. notMerge = notMerge.notMerge;
  22503. }
  22504. this[IN_MAIN_PROCESS] = true;
  22505. if (!this._model || notMerge) {
  22506. var optionManager = new OptionManager(this._api);
  22507. var theme$$1 = this._theme;
  22508. var ecModel = this._model = new GlobalModel();
  22509. ecModel.scheduler = this._scheduler;
  22510. ecModel.init(null, null, theme$$1, optionManager);
  22511. }
  22512. this._model.setOption(option, optionPreprocessorFuncs);
  22513. if (lazyUpdate) {
  22514. this[OPTION_UPDATED] = {
  22515. silent: silent
  22516. };
  22517. this[IN_MAIN_PROCESS] = false;
  22518. } else {
  22519. prepare(this);
  22520. updateMethods.update.call(this); // Ensure zr refresh sychronously, and then pixel in canvas can be
  22521. // fetched after `setOption`.
  22522. this._zr.flush();
  22523. this[OPTION_UPDATED] = false;
  22524. this[IN_MAIN_PROCESS] = false;
  22525. flushPendingActions.call(this, silent);
  22526. triggerUpdatedEvent.call(this, silent);
  22527. }
  22528. };
  22529. /**
  22530. * @DEPRECATED
  22531. */
  22532. echartsProto.setTheme = function () {
  22533. console.error('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  22534. };
  22535. /**
  22536. * @return {module:echarts/model/Global}
  22537. */
  22538. echartsProto.getModel = function () {
  22539. return this._model;
  22540. };
  22541. /**
  22542. * @return {Object}
  22543. */
  22544. echartsProto.getOption = function () {
  22545. return this._model && this._model.getOption();
  22546. };
  22547. /**
  22548. * @return {number}
  22549. */
  22550. echartsProto.getWidth = function () {
  22551. return this._zr.getWidth();
  22552. };
  22553. /**
  22554. * @return {number}
  22555. */
  22556. echartsProto.getHeight = function () {
  22557. return this._zr.getHeight();
  22558. };
  22559. /**
  22560. * @return {number}
  22561. */
  22562. echartsProto.getDevicePixelRatio = function () {
  22563. return this._zr.painter.dpr || window.devicePixelRatio || 1;
  22564. };
  22565. /**
  22566. * Get canvas which has all thing rendered
  22567. * @param {Object} opts
  22568. * @param {string} [opts.backgroundColor]
  22569. * @return {string}
  22570. */
  22571. echartsProto.getRenderedCanvas = function (opts) {
  22572. if (!env$1.canvasSupported) {
  22573. return;
  22574. }
  22575. opts = opts || {};
  22576. opts.pixelRatio = opts.pixelRatio || 1;
  22577. opts.backgroundColor = opts.backgroundColor || this._model.get('backgroundColor');
  22578. var zr = this._zr; // var list = zr.storage.getDisplayList();
  22579. // Stop animations
  22580. // Never works before in init animation, so remove it.
  22581. // zrUtil.each(list, function (el) {
  22582. // el.stopAnimation(true);
  22583. // });
  22584. return zr.painter.getRenderedCanvas(opts);
  22585. };
  22586. /**
  22587. * Get svg data url
  22588. * @return {string}
  22589. */
  22590. echartsProto.getSvgDataURL = function () {
  22591. if (!env$1.svgSupported) {
  22592. return;
  22593. }
  22594. var zr = this._zr;
  22595. var list = zr.storage.getDisplayList(); // Stop animations
  22596. each$1(list, function (el) {
  22597. el.stopAnimation(true);
  22598. });
  22599. return zr.painter.toDataURL();
  22600. };
  22601. /**
  22602. * @return {string}
  22603. * @param {Object} opts
  22604. * @param {string} [opts.type='png']
  22605. * @param {string} [opts.pixelRatio=1]
  22606. * @param {string} [opts.backgroundColor]
  22607. * @param {string} [opts.excludeComponents]
  22608. */
  22609. echartsProto.getDataURL = function (opts) {
  22610. if (this._disposed) {
  22611. disposedWarning(this.id);
  22612. return;
  22613. }
  22614. opts = opts || {};
  22615. var excludeComponents = opts.excludeComponents;
  22616. var ecModel = this._model;
  22617. var excludesComponentViews = [];
  22618. var self = this;
  22619. each(excludeComponents, function (componentType) {
  22620. ecModel.eachComponent({
  22621. mainType: componentType
  22622. }, function (component) {
  22623. var view = self._componentsMap[component.__viewId];
  22624. if (!view.group.ignore) {
  22625. excludesComponentViews.push(view);
  22626. view.group.ignore = true;
  22627. }
  22628. });
  22629. });
  22630. var url = this._zr.painter.getType() === 'svg' ? this.getSvgDataURL() : this.getRenderedCanvas(opts).toDataURL('image/' + (opts && opts.type || 'png'));
  22631. each(excludesComponentViews, function (view) {
  22632. view.group.ignore = false;
  22633. });
  22634. return url;
  22635. };
  22636. /**
  22637. * @return {string}
  22638. * @param {Object} opts
  22639. * @param {string} [opts.type='png']
  22640. * @param {string} [opts.pixelRatio=1]
  22641. * @param {string} [opts.backgroundColor]
  22642. */
  22643. echartsProto.getConnectedDataURL = function (opts) {
  22644. if (this._disposed) {
  22645. disposedWarning(this.id);
  22646. return;
  22647. }
  22648. if (!env$1.canvasSupported) {
  22649. return;
  22650. }
  22651. var isSvg = opts.type === 'svg';
  22652. var groupId = this.group;
  22653. var mathMin = Math.min;
  22654. var mathMax = Math.max;
  22655. var MAX_NUMBER = Infinity;
  22656. if (connectedGroups[groupId]) {
  22657. var left = MAX_NUMBER;
  22658. var top = MAX_NUMBER;
  22659. var right = -MAX_NUMBER;
  22660. var bottom = -MAX_NUMBER;
  22661. var canvasList = [];
  22662. var dpr = opts && opts.pixelRatio || 1;
  22663. each$1(instances, function (chart, id) {
  22664. if (chart.group === groupId) {
  22665. var canvas = isSvg ? chart.getZr().painter.getSvgDom().innerHTML : chart.getRenderedCanvas(clone(opts));
  22666. var boundingRect = chart.getDom().getBoundingClientRect();
  22667. left = mathMin(boundingRect.left, left);
  22668. top = mathMin(boundingRect.top, top);
  22669. right = mathMax(boundingRect.right, right);
  22670. bottom = mathMax(boundingRect.bottom, bottom);
  22671. canvasList.push({
  22672. dom: canvas,
  22673. left: boundingRect.left,
  22674. top: boundingRect.top
  22675. });
  22676. }
  22677. });
  22678. left *= dpr;
  22679. top *= dpr;
  22680. right *= dpr;
  22681. bottom *= dpr;
  22682. var width = right - left;
  22683. var height = bottom - top;
  22684. var targetCanvas = createCanvas();
  22685. var zr = init$1(targetCanvas, {
  22686. renderer: isSvg ? 'svg' : 'canvas'
  22687. });
  22688. zr.resize({
  22689. width: width,
  22690. height: height
  22691. });
  22692. if (isSvg) {
  22693. var content = '';
  22694. each(canvasList, function (item) {
  22695. var x = item.left - left;
  22696. var y = item.top - top;
  22697. content += '<g transform="translate(' + x + ',' + y + ')">' + item.dom + '</g>';
  22698. });
  22699. zr.painter.getSvgRoot().innerHTML = content;
  22700. if (opts.connectedBackgroundColor) {
  22701. zr.painter.setBackgroundColor(opts.connectedBackgroundColor);
  22702. }
  22703. zr.refreshImmediately();
  22704. return zr.painter.toDataURL();
  22705. } else {
  22706. // Background between the charts
  22707. if (opts.connectedBackgroundColor) {
  22708. zr.add(new Rect({
  22709. shape: {
  22710. x: 0,
  22711. y: 0,
  22712. width: width,
  22713. height: height
  22714. },
  22715. style: {
  22716. fill: opts.connectedBackgroundColor
  22717. }
  22718. }));
  22719. }
  22720. each(canvasList, function (item) {
  22721. var img = new ZImage({
  22722. style: {
  22723. x: item.left * dpr - left,
  22724. y: item.top * dpr - top,
  22725. image: item.dom
  22726. }
  22727. });
  22728. zr.add(img);
  22729. });
  22730. zr.refreshImmediately();
  22731. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  22732. }
  22733. } else {
  22734. return this.getDataURL(opts);
  22735. }
  22736. };
  22737. /**
  22738. * Convert from logical coordinate system to pixel coordinate system.
  22739. * See CoordinateSystem#convertToPixel.
  22740. * @param {string|Object} finder
  22741. * If string, e.g., 'geo', means {geoIndex: 0}.
  22742. * If Object, could contain some of these properties below:
  22743. * {
  22744. * seriesIndex / seriesId / seriesName,
  22745. * geoIndex / geoId, geoName,
  22746. * bmapIndex / bmapId / bmapName,
  22747. * xAxisIndex / xAxisId / xAxisName,
  22748. * yAxisIndex / yAxisId / yAxisName,
  22749. * gridIndex / gridId / gridName,
  22750. * ... (can be extended)
  22751. * }
  22752. * @param {Array|number} value
  22753. * @return {Array|number} result
  22754. */
  22755. echartsProto.convertToPixel = curry(doConvertPixel, 'convertToPixel');
  22756. /**
  22757. * Convert from pixel coordinate system to logical coordinate system.
  22758. * See CoordinateSystem#convertFromPixel.
  22759. * @param {string|Object} finder
  22760. * If string, e.g., 'geo', means {geoIndex: 0}.
  22761. * If Object, could contain some of these properties below:
  22762. * {
  22763. * seriesIndex / seriesId / seriesName,
  22764. * geoIndex / geoId / geoName,
  22765. * bmapIndex / bmapId / bmapName,
  22766. * xAxisIndex / xAxisId / xAxisName,
  22767. * yAxisIndex / yAxisId / yAxisName
  22768. * gridIndex / gridId / gridName,
  22769. * ... (can be extended)
  22770. * }
  22771. * @param {Array|number} value
  22772. * @return {Array|number} result
  22773. */
  22774. echartsProto.convertFromPixel = curry(doConvertPixel, 'convertFromPixel');
  22775. function doConvertPixel(methodName, finder, value) {
  22776. if (this._disposed) {
  22777. disposedWarning(this.id);
  22778. return;
  22779. }
  22780. var ecModel = this._model;
  22781. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  22782. var result;
  22783. finder = parseFinder(ecModel, finder);
  22784. for (var i = 0; i < coordSysList.length; i++) {
  22785. var coordSys = coordSysList[i];
  22786. if (coordSys[methodName] && (result = coordSys[methodName](ecModel, finder, value)) != null) {
  22787. return result;
  22788. }
  22789. }
  22790. if (__DEV__) {
  22791. console.warn('No coordinate system that supports ' + methodName + ' found by the given finder.');
  22792. }
  22793. }
  22794. /**
  22795. * Is the specified coordinate systems or components contain the given pixel point.
  22796. * @param {string|Object} finder
  22797. * If string, e.g., 'geo', means {geoIndex: 0}.
  22798. * If Object, could contain some of these properties below:
  22799. * {
  22800. * seriesIndex / seriesId / seriesName,
  22801. * geoIndex / geoId / geoName,
  22802. * bmapIndex / bmapId / bmapName,
  22803. * xAxisIndex / xAxisId / xAxisName,
  22804. * yAxisIndex / yAxisId / yAxisName,
  22805. * gridIndex / gridId / gridName,
  22806. * ... (can be extended)
  22807. * }
  22808. * @param {Array|number} value
  22809. * @return {boolean} result
  22810. */
  22811. echartsProto.containPixel = function (finder, value) {
  22812. if (this._disposed) {
  22813. disposedWarning(this.id);
  22814. return;
  22815. }
  22816. var ecModel = this._model;
  22817. var result;
  22818. finder = parseFinder(ecModel, finder);
  22819. each$1(finder, function (models, key) {
  22820. key.indexOf('Models') >= 0 && each$1(models, function (model) {
  22821. var coordSys = model.coordinateSystem;
  22822. if (coordSys && coordSys.containPoint) {
  22823. result |= !!coordSys.containPoint(value);
  22824. } else if (key === 'seriesModels') {
  22825. var view = this._chartsMap[model.__viewId];
  22826. if (view && view.containPoint) {
  22827. result |= view.containPoint(value, model);
  22828. } else {
  22829. if (__DEV__) {
  22830. console.warn(key + ': ' + (view ? 'The found component do not support containPoint.' : 'No view mapping to the found component.'));
  22831. }
  22832. }
  22833. } else {
  22834. if (__DEV__) {
  22835. console.warn(key + ': containPoint is not supported');
  22836. }
  22837. }
  22838. }, this);
  22839. }, this);
  22840. return !!result;
  22841. };
  22842. /**
  22843. * Get visual from series or data.
  22844. * @param {string|Object} finder
  22845. * If string, e.g., 'series', means {seriesIndex: 0}.
  22846. * If Object, could contain some of these properties below:
  22847. * {
  22848. * seriesIndex / seriesId / seriesName,
  22849. * dataIndex / dataIndexInside
  22850. * }
  22851. * If dataIndex is not specified, series visual will be fetched,
  22852. * but not data item visual.
  22853. * If all of seriesIndex, seriesId, seriesName are not specified,
  22854. * visual will be fetched from first series.
  22855. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  22856. */
  22857. echartsProto.getVisual = function (finder, visualType) {
  22858. var ecModel = this._model;
  22859. finder = parseFinder(ecModel, finder, {
  22860. defaultMainType: 'series'
  22861. });
  22862. var seriesModel = finder.seriesModel;
  22863. if (__DEV__) {
  22864. if (!seriesModel) {
  22865. console.warn('There is no specified seires model');
  22866. }
  22867. }
  22868. var data = seriesModel.getData();
  22869. var dataIndexInside = finder.hasOwnProperty('dataIndexInside') ? finder.dataIndexInside : finder.hasOwnProperty('dataIndex') ? data.indexOfRawIndex(finder.dataIndex) : null;
  22870. return dataIndexInside != null ? data.getItemVisual(dataIndexInside, visualType) : data.getVisual(visualType);
  22871. };
  22872. /**
  22873. * Get view of corresponding component model
  22874. * @param {module:echarts/model/Component} componentModel
  22875. * @return {module:echarts/view/Component}
  22876. */
  22877. echartsProto.getViewOfComponentModel = function (componentModel) {
  22878. return this._componentsMap[componentModel.__viewId];
  22879. };
  22880. /**
  22881. * Get view of corresponding series model
  22882. * @param {module:echarts/model/Series} seriesModel
  22883. * @return {module:echarts/view/Chart}
  22884. */
  22885. echartsProto.getViewOfSeriesModel = function (seriesModel) {
  22886. return this._chartsMap[seriesModel.__viewId];
  22887. };
  22888. var updateMethods = {
  22889. prepareAndUpdate: function (payload) {
  22890. prepare(this);
  22891. updateMethods.update.call(this, payload);
  22892. },
  22893. /**
  22894. * @param {Object} payload
  22895. * @private
  22896. */
  22897. update: function (payload) {
  22898. // console.profile && console.profile('update');
  22899. var ecModel = this._model;
  22900. var api = this._api;
  22901. var zr = this._zr;
  22902. var coordSysMgr = this._coordSysMgr;
  22903. var scheduler = this._scheduler; // update before setOption
  22904. if (!ecModel) {
  22905. return;
  22906. }
  22907. scheduler.restoreData(ecModel, payload);
  22908. scheduler.performSeriesTasks(ecModel); // TODO
  22909. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  22910. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  22911. // Create new coordinate system each update
  22912. // In LineView may save the old coordinate system and use it to get the orignal point
  22913. coordSysMgr.create(ecModel, api);
  22914. scheduler.performDataProcessorTasks(ecModel, payload); // Current stream render is not supported in data process. So we can update
  22915. // stream modes after data processing, where the filtered data is used to
  22916. // deteming whether use progressive rendering.
  22917. updateStreamModes(this, ecModel); // We update stream modes before coordinate system updated, then the modes info
  22918. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  22919. // the drawback is the full coord info can not be fetched. Fortunately this full
  22920. // coord is not requied in stream mode updater currently.
  22921. coordSysMgr.update(ecModel, api);
  22922. clearColorPalette(ecModel);
  22923. scheduler.performVisualTasks(ecModel, payload);
  22924. render(this, ecModel, api, payload); // Set background
  22925. var backgroundColor = ecModel.get('backgroundColor') || 'transparent'; // In IE8
  22926. if (!env$1.canvasSupported) {
  22927. var colorArr = parse(backgroundColor);
  22928. backgroundColor = stringify(colorArr, 'rgb');
  22929. if (colorArr[3] === 0) {
  22930. backgroundColor = 'transparent';
  22931. }
  22932. } else {
  22933. zr.setBackgroundColor(backgroundColor);
  22934. }
  22935. performPostUpdateFuncs(ecModel, api); // console.profile && console.profileEnd('update');
  22936. },
  22937. /**
  22938. * @param {Object} payload
  22939. * @private
  22940. */
  22941. updateTransform: function (payload) {
  22942. var ecModel = this._model;
  22943. var ecIns = this;
  22944. var api = this._api; // update before setOption
  22945. if (!ecModel) {
  22946. return;
  22947. } // ChartView.markUpdateMethod(payload, 'updateTransform');
  22948. var componentDirtyList = [];
  22949. ecModel.eachComponent(function (componentType, componentModel) {
  22950. var componentView = ecIns.getViewOfComponentModel(componentModel);
  22951. if (componentView && componentView.__alive) {
  22952. if (componentView.updateTransform) {
  22953. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  22954. result && result.update && componentDirtyList.push(componentView);
  22955. } else {
  22956. componentDirtyList.push(componentView);
  22957. }
  22958. }
  22959. });
  22960. var seriesDirtyMap = createHashMap();
  22961. ecModel.eachSeries(function (seriesModel) {
  22962. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  22963. if (chartView.updateTransform) {
  22964. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  22965. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  22966. } else {
  22967. seriesDirtyMap.set(seriesModel.uid, 1);
  22968. }
  22969. });
  22970. clearColorPalette(ecModel); // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  22971. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  22972. this._scheduler.performVisualTasks(ecModel, payload, {
  22973. setDirty: true,
  22974. dirtyMap: seriesDirtyMap
  22975. }); // Currently, not call render of components. Geo render cost a lot.
  22976. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  22977. renderSeries(ecIns, ecModel, api, payload, seriesDirtyMap);
  22978. performPostUpdateFuncs(ecModel, this._api);
  22979. },
  22980. /**
  22981. * @param {Object} payload
  22982. * @private
  22983. */
  22984. updateView: function (payload) {
  22985. var ecModel = this._model; // update before setOption
  22986. if (!ecModel) {
  22987. return;
  22988. }
  22989. Chart.markUpdateMethod(payload, 'updateView');
  22990. clearColorPalette(ecModel); // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  22991. this._scheduler.performVisualTasks(ecModel, payload, {
  22992. setDirty: true
  22993. });
  22994. render(this, this._model, this._api, payload);
  22995. performPostUpdateFuncs(ecModel, this._api);
  22996. },
  22997. /**
  22998. * @param {Object} payload
  22999. * @private
  23000. */
  23001. updateVisual: function (payload) {
  23002. updateMethods.update.call(this, payload); // var ecModel = this._model;
  23003. // // update before setOption
  23004. // if (!ecModel) {
  23005. // return;
  23006. // }
  23007. // ChartView.markUpdateMethod(payload, 'updateVisual');
  23008. // clearColorPalette(ecModel);
  23009. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  23010. // this._scheduler.performVisualTasks(ecModel, payload, {visualType: 'visual', setDirty: true});
  23011. // render(this, this._model, this._api, payload);
  23012. // performPostUpdateFuncs(ecModel, this._api);
  23013. },
  23014. /**
  23015. * @param {Object} payload
  23016. * @private
  23017. */
  23018. updateLayout: function (payload) {
  23019. updateMethods.update.call(this, payload); // var ecModel = this._model;
  23020. // // update before setOption
  23021. // if (!ecModel) {
  23022. // return;
  23023. // }
  23024. // ChartView.markUpdateMethod(payload, 'updateLayout');
  23025. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  23026. // // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  23027. // this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  23028. // render(this, this._model, this._api, payload);
  23029. // performPostUpdateFuncs(ecModel, this._api);
  23030. }
  23031. };
  23032. function prepare(ecIns) {
  23033. var ecModel = ecIns._model;
  23034. var scheduler = ecIns._scheduler;
  23035. scheduler.restorePipelines(ecModel);
  23036. scheduler.prepareStageTasks();
  23037. prepareView(ecIns, 'component', ecModel, scheduler);
  23038. prepareView(ecIns, 'chart', ecModel, scheduler);
  23039. scheduler.plan();
  23040. }
  23041. /**
  23042. * @private
  23043. */
  23044. function updateDirectly(ecIns, method, payload, mainType, subType) {
  23045. var ecModel = ecIns._model; // broadcast
  23046. if (!mainType) {
  23047. // FIXME
  23048. // Chart will not be update directly here, except set dirty.
  23049. // But there is no such scenario now.
  23050. each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
  23051. return;
  23052. }
  23053. var query = {};
  23054. query[mainType + 'Id'] = payload[mainType + 'Id'];
  23055. query[mainType + 'Index'] = payload[mainType + 'Index'];
  23056. query[mainType + 'Name'] = payload[mainType + 'Name'];
  23057. var condition = {
  23058. mainType: mainType,
  23059. query: query
  23060. };
  23061. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  23062. var excludeSeriesId = payload.excludeSeriesId;
  23063. if (excludeSeriesId != null) {
  23064. excludeSeriesId = createHashMap(normalizeToArray(excludeSeriesId));
  23065. } // If dispatchAction before setOption, do nothing.
  23066. ecModel && ecModel.eachComponent(condition, function (model) {
  23067. if (!excludeSeriesId || excludeSeriesId.get(model.id) == null) {
  23068. callView(ecIns[mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId]);
  23069. }
  23070. }, ecIns);
  23071. function callView(view) {
  23072. view && view.__alive && view[method] && view[method](view.__model, ecModel, ecIns._api, payload);
  23073. }
  23074. }
  23075. /**
  23076. * Resize the chart
  23077. * @param {Object} opts
  23078. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  23079. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  23080. * @param {boolean} [opts.silent=false]
  23081. */
  23082. echartsProto.resize = function (opts) {
  23083. if (__DEV__) {
  23084. assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  23085. }
  23086. if (this._disposed) {
  23087. disposedWarning(this.id);
  23088. return;
  23089. }
  23090. this._zr.resize(opts);
  23091. var ecModel = this._model; // Resize loading effect
  23092. this._loadingFX && this._loadingFX.resize();
  23093. if (!ecModel) {
  23094. return;
  23095. }
  23096. var optionChanged = ecModel.resetOption('media');
  23097. var silent = opts && opts.silent;
  23098. this[IN_MAIN_PROCESS] = true;
  23099. optionChanged && prepare(this);
  23100. updateMethods.update.call(this);
  23101. this[IN_MAIN_PROCESS] = false;
  23102. flushPendingActions.call(this, silent);
  23103. triggerUpdatedEvent.call(this, silent);
  23104. };
  23105. function updateStreamModes(ecIns, ecModel) {
  23106. var chartsMap = ecIns._chartsMap;
  23107. var scheduler = ecIns._scheduler;
  23108. ecModel.eachSeries(function (seriesModel) {
  23109. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  23110. });
  23111. }
  23112. /**
  23113. * Show loading effect
  23114. * @param {string} [name='default']
  23115. * @param {Object} [cfg]
  23116. */
  23117. echartsProto.showLoading = function (name, cfg) {
  23118. if (this._disposed) {
  23119. disposedWarning(this.id);
  23120. return;
  23121. }
  23122. if (isObject(name)) {
  23123. cfg = name;
  23124. name = '';
  23125. }
  23126. name = name || 'default';
  23127. this.hideLoading();
  23128. if (!loadingEffects[name]) {
  23129. if (__DEV__) {
  23130. console.warn('Loading effects ' + name + ' not exists.');
  23131. }
  23132. return;
  23133. }
  23134. var el = loadingEffects[name](this._api, cfg);
  23135. var zr = this._zr;
  23136. this._loadingFX = el;
  23137. zr.add(el);
  23138. };
  23139. /**
  23140. * Hide loading effect
  23141. */
  23142. echartsProto.hideLoading = function () {
  23143. if (this._disposed) {
  23144. disposedWarning(this.id);
  23145. return;
  23146. }
  23147. this._loadingFX && this._zr.remove(this._loadingFX);
  23148. this._loadingFX = null;
  23149. };
  23150. /**
  23151. * @param {Object} eventObj
  23152. * @return {Object}
  23153. */
  23154. echartsProto.makeActionFromEvent = function (eventObj) {
  23155. var payload = extend({}, eventObj);
  23156. payload.type = eventActionMap[eventObj.type];
  23157. return payload;
  23158. };
  23159. /**
  23160. * @pubilc
  23161. * @param {Object} payload
  23162. * @param {string} [payload.type] Action type
  23163. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  23164. * @param {boolean} [opt.silent=false] Whether trigger events.
  23165. * @param {boolean} [opt.flush=undefined]
  23166. * true: Flush immediately, and then pixel in canvas can be fetched
  23167. * immediately. Caution: it might affect performance.
  23168. * false: Not flush.
  23169. * undefined: Auto decide whether perform flush.
  23170. */
  23171. echartsProto.dispatchAction = function (payload, opt) {
  23172. if (this._disposed) {
  23173. disposedWarning(this.id);
  23174. return;
  23175. }
  23176. if (!isObject(opt)) {
  23177. opt = {
  23178. silent: !!opt
  23179. };
  23180. }
  23181. if (!actions[payload.type]) {
  23182. return;
  23183. } // Avoid dispatch action before setOption. Especially in `connect`.
  23184. if (!this._model) {
  23185. return;
  23186. } // May dispatchAction in rendering procedure
  23187. if (this[IN_MAIN_PROCESS]) {
  23188. this._pendingActions.push(payload);
  23189. return;
  23190. }
  23191. doDispatchAction.call(this, payload, opt.silent);
  23192. if (opt.flush) {
  23193. this._zr.flush(true);
  23194. } else if (opt.flush !== false && env$1.browser.weChat) {
  23195. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  23196. // hang when sliding page (on touch event), which cause that zr does not
  23197. // refresh util user interaction finished, which is not expected.
  23198. // But `dispatchAction` may be called too frequently when pan on touch
  23199. // screen, which impacts performance if do not throttle them.
  23200. this._throttledZrFlush();
  23201. }
  23202. flushPendingActions.call(this, opt.silent);
  23203. triggerUpdatedEvent.call(this, opt.silent);
  23204. };
  23205. function doDispatchAction(payload, silent) {
  23206. var payloadType = payload.type;
  23207. var escapeConnect = payload.escapeConnect;
  23208. var actionWrap = actions[payloadType];
  23209. var actionInfo = actionWrap.actionInfo;
  23210. var cptType = (actionInfo.update || 'update').split(':');
  23211. var updateMethod = cptType.pop();
  23212. cptType = cptType[0] != null && parseClassType(cptType[0]);
  23213. this[IN_MAIN_PROCESS] = true;
  23214. var payloads = [payload];
  23215. var batched = false; // Batch action
  23216. if (payload.batch) {
  23217. batched = true;
  23218. payloads = map(payload.batch, function (item) {
  23219. item = defaults(extend({}, item), payload);
  23220. item.batch = null;
  23221. return item;
  23222. });
  23223. }
  23224. var eventObjBatch = [];
  23225. var eventObj;
  23226. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  23227. each(payloads, function (batchItem) {
  23228. // Action can specify the event by return it.
  23229. eventObj = actionWrap.action(batchItem, this._model, this._api); // Emit event outside
  23230. eventObj = eventObj || extend({}, batchItem); // Convert type to eventType
  23231. eventObj.type = actionInfo.event || eventObj.type;
  23232. eventObjBatch.push(eventObj); // light update does not perform data process, layout and visual.
  23233. if (isHighDown) {
  23234. // method, payload, mainType, subType
  23235. updateDirectly(this, updateMethod, batchItem, 'series');
  23236. } else if (cptType) {
  23237. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  23238. }
  23239. }, this);
  23240. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  23241. // Still dirty
  23242. if (this[OPTION_UPDATED]) {
  23243. // FIXME Pass payload ?
  23244. prepare(this);
  23245. updateMethods.update.call(this, payload);
  23246. this[OPTION_UPDATED] = false;
  23247. } else {
  23248. updateMethods[updateMethod].call(this, payload);
  23249. }
  23250. } // Follow the rule of action batch
  23251. if (batched) {
  23252. eventObj = {
  23253. type: actionInfo.event || payloadType,
  23254. escapeConnect: escapeConnect,
  23255. batch: eventObjBatch
  23256. };
  23257. } else {
  23258. eventObj = eventObjBatch[0];
  23259. }
  23260. this[IN_MAIN_PROCESS] = false;
  23261. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  23262. }
  23263. function flushPendingActions(silent) {
  23264. var pendingActions = this._pendingActions;
  23265. while (pendingActions.length) {
  23266. var payload = pendingActions.shift();
  23267. doDispatchAction.call(this, payload, silent);
  23268. }
  23269. }
  23270. function triggerUpdatedEvent(silent) {
  23271. !silent && this.trigger('updated');
  23272. }
  23273. /**
  23274. * Event `rendered` is triggered when zr
  23275. * rendered. It is useful for realtime
  23276. * snapshot (reflect animation).
  23277. *
  23278. * Event `finished` is triggered when:
  23279. * (1) zrender rendering finished.
  23280. * (2) initial animation finished.
  23281. * (3) progressive rendering finished.
  23282. * (4) no pending action.
  23283. * (5) no delayed setOption needs to be processed.
  23284. */
  23285. function bindRenderedEvent(zr, ecIns) {
  23286. zr.on('rendered', function () {
  23287. ecIns.trigger('rendered'); // The `finished` event should not be triggered repeatly,
  23288. // so it should only be triggered when rendering indeed happend
  23289. // in zrender. (Consider the case that dipatchAction is keep
  23290. // triggering when mouse move).
  23291. if ( // Although zr is dirty if initial animation is not finished
  23292. // and this checking is called on frame, we also check
  23293. // animation finished for robustness.
  23294. zr.animation.isFinished() && !ecIns[OPTION_UPDATED] && !ecIns._scheduler.unfinished && !ecIns._pendingActions.length) {
  23295. ecIns.trigger('finished');
  23296. }
  23297. });
  23298. }
  23299. /**
  23300. * @param {Object} params
  23301. * @param {number} params.seriesIndex
  23302. * @param {Array|TypedArray} params.data
  23303. */
  23304. echartsProto.appendData = function (params) {
  23305. if (this._disposed) {
  23306. disposedWarning(this.id);
  23307. return;
  23308. }
  23309. var seriesIndex = params.seriesIndex;
  23310. var ecModel = this.getModel();
  23311. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  23312. if (__DEV__) {
  23313. assert(params.data && seriesModel);
  23314. }
  23315. seriesModel.appendData(params); // Note: `appendData` does not support that update extent of coordinate
  23316. // system, util some scenario require that. In the expected usage of
  23317. // `appendData`, the initial extent of coordinate system should better
  23318. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  23319. // the extent changed while `appendData`, the location of the painted
  23320. // graphic elements have to be changed, which make the usage of
  23321. // `appendData` meaningless.
  23322. this._scheduler.unfinished = true;
  23323. };
  23324. /**
  23325. * Register event
  23326. * @method
  23327. */
  23328. echartsProto.on = createRegisterEventWithLowercaseName('on', false);
  23329. echartsProto.off = createRegisterEventWithLowercaseName('off', false);
  23330. echartsProto.one = createRegisterEventWithLowercaseName('one', false);
  23331. /**
  23332. * Prepare view instances of charts and components
  23333. * @param {module:echarts/model/Global} ecModel
  23334. * @private
  23335. */
  23336. function prepareView(ecIns, type, ecModel, scheduler) {
  23337. var isComponent = type === 'component';
  23338. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  23339. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  23340. var zr = ecIns._zr;
  23341. var api = ecIns._api;
  23342. for (var i = 0; i < viewList.length; i++) {
  23343. viewList[i].__alive = false;
  23344. }
  23345. isComponent ? ecModel.eachComponent(function (componentType, model) {
  23346. componentType !== 'series' && doPrepare(model);
  23347. }) : ecModel.eachSeries(doPrepare);
  23348. function doPrepare(model) {
  23349. // Consider: id same and type changed.
  23350. var viewId = '_ec_' + model.id + '_' + model.type;
  23351. var view = viewMap[viewId];
  23352. if (!view) {
  23353. var classType = parseClassType(model.type);
  23354. var Clazz = isComponent ? Component.getClass(classType.main, classType.sub) : Chart.getClass(classType.sub);
  23355. if (__DEV__) {
  23356. assert(Clazz, classType.sub + ' does not exist.');
  23357. }
  23358. view = new Clazz();
  23359. view.init(ecModel, api);
  23360. viewMap[viewId] = view;
  23361. viewList.push(view);
  23362. zr.add(view.group);
  23363. }
  23364. model.__viewId = view.__id = viewId;
  23365. view.__alive = true;
  23366. view.__model = model;
  23367. view.group.__ecComponentInfo = {
  23368. mainType: model.mainType,
  23369. index: model.componentIndex
  23370. };
  23371. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  23372. }
  23373. for (var i = 0; i < viewList.length;) {
  23374. var view = viewList[i];
  23375. if (!view.__alive) {
  23376. !isComponent && view.renderTask.dispose();
  23377. zr.remove(view.group);
  23378. view.dispose(ecModel, api);
  23379. viewList.splice(i, 1);
  23380. delete viewMap[view.__id];
  23381. view.__id = view.group.__ecComponentInfo = null;
  23382. } else {
  23383. i++;
  23384. }
  23385. }
  23386. } // /**
  23387. // * Encode visual infomation from data after data processing
  23388. // *
  23389. // * @param {module:echarts/model/Global} ecModel
  23390. // * @param {object} layout
  23391. // * @param {boolean} [layoutFilter] `true`: only layout,
  23392. // * `false`: only not layout,
  23393. // * `null`/`undefined`: all.
  23394. // * @param {string} taskBaseTag
  23395. // * @private
  23396. // */
  23397. // function startVisualEncoding(ecIns, ecModel, api, payload, layoutFilter) {
  23398. // each(visualFuncs, function (visual, index) {
  23399. // var isLayout = visual.isLayout;
  23400. // if (layoutFilter == null
  23401. // || (layoutFilter === false && !isLayout)
  23402. // || (layoutFilter === true && isLayout)
  23403. // ) {
  23404. // visual.func(ecModel, api, payload);
  23405. // }
  23406. // });
  23407. // }
  23408. function clearColorPalette(ecModel) {
  23409. ecModel.clearColorPalette();
  23410. ecModel.eachSeries(function (seriesModel) {
  23411. seriesModel.clearColorPalette();
  23412. });
  23413. }
  23414. function render(ecIns, ecModel, api, payload) {
  23415. renderComponents(ecIns, ecModel, api, payload);
  23416. each(ecIns._chartsViews, function (chart) {
  23417. chart.__alive = false;
  23418. });
  23419. renderSeries(ecIns, ecModel, api, payload); // Remove groups of unrendered charts
  23420. each(ecIns._chartsViews, function (chart) {
  23421. if (!chart.__alive) {
  23422. chart.remove(ecModel, api);
  23423. }
  23424. });
  23425. }
  23426. function renderComponents(ecIns, ecModel, api, payload, dirtyList) {
  23427. each(dirtyList || ecIns._componentsViews, function (componentView) {
  23428. var componentModel = componentView.__model;
  23429. componentView.render(componentModel, ecModel, api, payload);
  23430. updateZ(componentModel, componentView);
  23431. });
  23432. }
  23433. /**
  23434. * Render each chart and component
  23435. * @private
  23436. */
  23437. function renderSeries(ecIns, ecModel, api, payload, dirtyMap) {
  23438. // Render all charts
  23439. var scheduler = ecIns._scheduler;
  23440. var unfinished;
  23441. ecModel.eachSeries(function (seriesModel) {
  23442. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  23443. chartView.__alive = true;
  23444. var renderTask = chartView.renderTask;
  23445. scheduler.updatePayload(renderTask, payload);
  23446. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  23447. renderTask.dirty();
  23448. }
  23449. unfinished |= renderTask.perform(scheduler.getPerformArgs(renderTask));
  23450. chartView.group.silent = !!seriesModel.get('silent');
  23451. updateZ(seriesModel, chartView);
  23452. updateBlend(seriesModel, chartView);
  23453. });
  23454. scheduler.unfinished |= unfinished; // If use hover layer
  23455. updateHoverLayerStatus(ecIns, ecModel); // Add aria
  23456. aria(ecIns._zr.dom, ecModel);
  23457. }
  23458. function performPostUpdateFuncs(ecModel, api) {
  23459. each(postUpdateFuncs, function (func) {
  23460. func(ecModel, api);
  23461. });
  23462. }
  23463. var MOUSE_EVENT_NAMES = ['click', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'mouseup', 'globalout', 'contextmenu'];
  23464. /**
  23465. * @private
  23466. */
  23467. echartsProto._initEvents = function () {
  23468. each(MOUSE_EVENT_NAMES, function (eveName) {
  23469. var handler = function (e) {
  23470. var ecModel = this.getModel();
  23471. var el = e.target;
  23472. var params;
  23473. var isGlobalOut = eveName === 'globalout'; // no e.target when 'globalout'.
  23474. if (isGlobalOut) {
  23475. params = {};
  23476. } else if (el && el.dataIndex != null) {
  23477. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  23478. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType, el) || {};
  23479. } // If element has custom eventData of components
  23480. else if (el && el.eventData) {
  23481. params = extend({}, el.eventData);
  23482. } // Contract: if params prepared in mouse event,
  23483. // these properties must be specified:
  23484. // {
  23485. // componentType: string (component main type)
  23486. // componentIndex: number
  23487. // }
  23488. // Otherwise event query can not work.
  23489. if (params) {
  23490. var componentType = params.componentType;
  23491. var componentIndex = params.componentIndex; // Special handling for historic reason: when trigger by
  23492. // markLine/markPoint/markArea, the componentType is
  23493. // 'markLine'/'markPoint'/'markArea', but we should better
  23494. // enable them to be queried by seriesIndex, since their
  23495. // option is set in each series.
  23496. if (componentType === 'markLine' || componentType === 'markPoint' || componentType === 'markArea') {
  23497. componentType = 'series';
  23498. componentIndex = params.seriesIndex;
  23499. }
  23500. var model = componentType && componentIndex != null && ecModel.getComponent(componentType, componentIndex);
  23501. var view = model && this[model.mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId];
  23502. if (__DEV__) {
  23503. // `event.componentType` and `event[componentTpype + 'Index']` must not
  23504. // be missed, otherwise there is no way to distinguish source component.
  23505. // See `dataFormat.getDataParams`.
  23506. if (!isGlobalOut && !(model && view)) {
  23507. console.warn('model or view can not be found by params');
  23508. }
  23509. }
  23510. params.event = e;
  23511. params.type = eveName;
  23512. this._ecEventProcessor.eventInfo = {
  23513. targetEl: el,
  23514. packedEvent: params,
  23515. model: model,
  23516. view: view
  23517. };
  23518. this.trigger(eveName, params);
  23519. }
  23520. }; // Consider that some component (like tooltip, brush, ...)
  23521. // register zr event handler, but user event handler might
  23522. // do anything, such as call `setOption` or `dispatchAction`,
  23523. // which probably update any of the content and probably
  23524. // cause problem if it is called previous other inner handlers.
  23525. handler.zrEventfulCallAtLast = true;
  23526. this._zr.on(eveName, handler, this);
  23527. }, this);
  23528. each(eventActionMap, function (actionType, eventType) {
  23529. this._messageCenter.on(eventType, function (event) {
  23530. this.trigger(eventType, event);
  23531. }, this);
  23532. }, this);
  23533. };
  23534. /**
  23535. * @return {boolean}
  23536. */
  23537. echartsProto.isDisposed = function () {
  23538. return this._disposed;
  23539. };
  23540. /**
  23541. * Clear
  23542. */
  23543. echartsProto.clear = function () {
  23544. if (this._disposed) {
  23545. disposedWarning(this.id);
  23546. return;
  23547. }
  23548. this.setOption({
  23549. series: []
  23550. }, true);
  23551. };
  23552. /**
  23553. * Dispose instance
  23554. */
  23555. echartsProto.dispose = function () {
  23556. if (this._disposed) {
  23557. disposedWarning(this.id);
  23558. return;
  23559. }
  23560. this._disposed = true;
  23561. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  23562. var api = this._api;
  23563. var ecModel = this._model;
  23564. each(this._componentsViews, function (component) {
  23565. component.dispose(ecModel, api);
  23566. });
  23567. each(this._chartsViews, function (chart) {
  23568. chart.dispose(ecModel, api);
  23569. }); // Dispose after all views disposed
  23570. this._zr.dispose();
  23571. delete instances[this.id];
  23572. };
  23573. mixin(ECharts, Eventful);
  23574. function disposedWarning(id) {
  23575. if (__DEV__) {
  23576. console.warn('Instance ' + id + ' has been disposed');
  23577. }
  23578. }
  23579. function updateHoverLayerStatus(ecIns, ecModel) {
  23580. var zr = ecIns._zr;
  23581. var storage = zr.storage;
  23582. var elCount = 0;
  23583. storage.traverse(function (el) {
  23584. elCount++;
  23585. });
  23586. if (elCount > ecModel.get('hoverLayerThreshold') && !env$1.node) {
  23587. ecModel.eachSeries(function (seriesModel) {
  23588. if (seriesModel.preventUsingHoverLayer) {
  23589. return;
  23590. }
  23591. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  23592. if (chartView.__alive) {
  23593. chartView.group.traverse(function (el) {
  23594. // Don't switch back.
  23595. el.useHoverLayer = true;
  23596. });
  23597. }
  23598. });
  23599. }
  23600. }
  23601. /**
  23602. * Update chart progressive and blend.
  23603. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  23604. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  23605. */
  23606. function updateBlend(seriesModel, chartView) {
  23607. var blendMode = seriesModel.get('blendMode') || null;
  23608. if (__DEV__) {
  23609. if (!env$1.canvasSupported && blendMode && blendMode !== 'source-over') {
  23610. console.warn('Only canvas support blendMode');
  23611. }
  23612. }
  23613. chartView.group.traverse(function (el) {
  23614. // FIXME marker and other components
  23615. if (!el.isGroup) {
  23616. // Only set if blendMode is changed. In case element is incremental and don't wan't to rerender.
  23617. if (el.style.blend !== blendMode) {
  23618. el.setStyle('blend', blendMode);
  23619. }
  23620. }
  23621. if (el.eachPendingDisplayable) {
  23622. el.eachPendingDisplayable(function (displayable) {
  23623. displayable.setStyle('blend', blendMode);
  23624. });
  23625. }
  23626. });
  23627. }
  23628. /**
  23629. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  23630. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  23631. */
  23632. function updateZ(model, view) {
  23633. var z = model.get('z');
  23634. var zlevel = model.get('zlevel'); // Set z and zlevel
  23635. view.group.traverse(function (el) {
  23636. if (el.type !== 'group') {
  23637. z != null && (el.z = z);
  23638. zlevel != null && (el.zlevel = zlevel);
  23639. }
  23640. });
  23641. }
  23642. function createExtensionAPI(ecInstance) {
  23643. var coordSysMgr = ecInstance._coordSysMgr;
  23644. return extend(new ExtensionAPI(ecInstance), {
  23645. // Inject methods
  23646. getCoordinateSystems: bind(coordSysMgr.getCoordinateSystems, coordSysMgr),
  23647. getComponentByElement: function (el) {
  23648. while (el) {
  23649. var modelInfo = el.__ecComponentInfo;
  23650. if (modelInfo != null) {
  23651. return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
  23652. }
  23653. el = el.parent;
  23654. }
  23655. }
  23656. });
  23657. }
  23658. /**
  23659. * @class
  23660. * Usage of query:
  23661. * `chart.on('click', query, handler);`
  23662. * The `query` can be:
  23663. * + The component type query string, only `mainType` or `mainType.subType`,
  23664. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  23665. * + The component query object, like:
  23666. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  23667. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  23668. * + The data query object, like:
  23669. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  23670. * + The other query object (cmponent customized query), like:
  23671. * `{element: 'some'}` (only available in custom series).
  23672. *
  23673. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  23674. * same as there is no such prop in the `query` object.
  23675. */
  23676. function EventProcessor() {
  23677. // These info required: targetEl, packedEvent, model, view
  23678. this.eventInfo;
  23679. }
  23680. EventProcessor.prototype = {
  23681. constructor: EventProcessor,
  23682. normalizeQuery: function (query) {
  23683. var cptQuery = {};
  23684. var dataQuery = {};
  23685. var otherQuery = {}; // `query` is `mainType` or `mainType.subType` of component.
  23686. if (isString(query)) {
  23687. var condCptType = parseClassType(query); // `.main` and `.sub` may be ''.
  23688. cptQuery.mainType = condCptType.main || null;
  23689. cptQuery.subType = condCptType.sub || null;
  23690. } // `query` is an object, convert to {mainType, index, name, id}.
  23691. else {
  23692. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  23693. // can not be used in `compomentModel.filterForExposedEvent`.
  23694. var suffixes = ['Index', 'Name', 'Id'];
  23695. var dataKeys = {
  23696. name: 1,
  23697. dataIndex: 1,
  23698. dataType: 1
  23699. };
  23700. each$1(query, function (val, key) {
  23701. var reserved = false;
  23702. for (var i = 0; i < suffixes.length; i++) {
  23703. var propSuffix = suffixes[i];
  23704. var suffixPos = key.lastIndexOf(propSuffix);
  23705. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  23706. var mainType = key.slice(0, suffixPos); // Consider `dataIndex`.
  23707. if (mainType !== 'data') {
  23708. cptQuery.mainType = mainType;
  23709. cptQuery[propSuffix.toLowerCase()] = val;
  23710. reserved = true;
  23711. }
  23712. }
  23713. }
  23714. if (dataKeys.hasOwnProperty(key)) {
  23715. dataQuery[key] = val;
  23716. reserved = true;
  23717. }
  23718. if (!reserved) {
  23719. otherQuery[key] = val;
  23720. }
  23721. });
  23722. }
  23723. return {
  23724. cptQuery: cptQuery,
  23725. dataQuery: dataQuery,
  23726. otherQuery: otherQuery
  23727. };
  23728. },
  23729. filter: function (eventType, query, args) {
  23730. // They should be assigned before each trigger call.
  23731. var eventInfo = this.eventInfo;
  23732. if (!eventInfo) {
  23733. return true;
  23734. }
  23735. var targetEl = eventInfo.targetEl;
  23736. var packedEvent = eventInfo.packedEvent;
  23737. var model = eventInfo.model;
  23738. var view = eventInfo.view; // For event like 'globalout'.
  23739. if (!model || !view) {
  23740. return true;
  23741. }
  23742. var cptQuery = query.cptQuery;
  23743. var dataQuery = query.dataQuery;
  23744. return check(cptQuery, model, 'mainType') && check(cptQuery, model, 'subType') && check(cptQuery, model, 'index', 'componentIndex') && check(cptQuery, model, 'name') && check(cptQuery, model, 'id') && check(dataQuery, packedEvent, 'name') && check(dataQuery, packedEvent, 'dataIndex') && check(dataQuery, packedEvent, 'dataType') && (!view.filterForExposedEvent || view.filterForExposedEvent(eventType, query.otherQuery, targetEl, packedEvent));
  23745. function check(query, host, prop, propOnHost) {
  23746. return query[prop] == null || host[propOnHost || prop] === query[prop];
  23747. }
  23748. },
  23749. afterTrigger: function () {
  23750. // Make sure the eventInfo wont be used in next trigger.
  23751. this.eventInfo = null;
  23752. }
  23753. };
  23754. /**
  23755. * @type {Object} key: actionType.
  23756. * @inner
  23757. */
  23758. var actions = {};
  23759. /**
  23760. * Map eventType to actionType
  23761. * @type {Object}
  23762. */
  23763. var eventActionMap = {};
  23764. /**
  23765. * Data processor functions of each stage
  23766. * @type {Array.<Object.<string, Function>>}
  23767. * @inner
  23768. */
  23769. var dataProcessorFuncs = [];
  23770. /**
  23771. * @type {Array.<Function>}
  23772. * @inner
  23773. */
  23774. var optionPreprocessorFuncs = [];
  23775. /**
  23776. * @type {Array.<Function>}
  23777. * @inner
  23778. */
  23779. var postUpdateFuncs = [];
  23780. /**
  23781. * Visual encoding functions of each stage
  23782. * @type {Array.<Object.<string, Function>>}
  23783. */
  23784. var visualFuncs = [];
  23785. /**
  23786. * Theme storage
  23787. * @type {Object.<key, Object>}
  23788. */
  23789. var themeStorage = {};
  23790. /**
  23791. * Loading effects
  23792. */
  23793. var loadingEffects = {};
  23794. var instances = {};
  23795. var connectedGroups = {};
  23796. var idBase = new Date() - 0;
  23797. var groupIdBase = new Date() - 0;
  23798. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  23799. function enableConnect(chart) {
  23800. var STATUS_PENDING = 0;
  23801. var STATUS_UPDATING = 1;
  23802. var STATUS_UPDATED = 2;
  23803. var STATUS_KEY = '__connectUpdateStatus';
  23804. function updateConnectedChartsStatus(charts, status) {
  23805. for (var i = 0; i < charts.length; i++) {
  23806. var otherChart = charts[i];
  23807. otherChart[STATUS_KEY] = status;
  23808. }
  23809. }
  23810. each(eventActionMap, function (actionType, eventType) {
  23811. chart._messageCenter.on(eventType, function (event) {
  23812. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  23813. if (event && event.escapeConnect) {
  23814. return;
  23815. }
  23816. var action = chart.makeActionFromEvent(event);
  23817. var otherCharts = [];
  23818. each(instances, function (otherChart) {
  23819. if (otherChart !== chart && otherChart.group === chart.group) {
  23820. otherCharts.push(otherChart);
  23821. }
  23822. });
  23823. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  23824. each(otherCharts, function (otherChart) {
  23825. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  23826. otherChart.dispatchAction(action);
  23827. }
  23828. });
  23829. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  23830. }
  23831. });
  23832. });
  23833. }
  23834. /**
  23835. * @param {HTMLElement} dom
  23836. * @param {Object} [theme]
  23837. * @param {Object} opts
  23838. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  23839. * @param {string} [opts.renderer] Can choose 'canvas' or 'svg' to render the chart.
  23840. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  23841. * Can be 'auto' (the same as null/undefined)
  23842. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  23843. * Can be 'auto' (the same as null/undefined)
  23844. */
  23845. function init(dom, theme$$1, opts) {
  23846. if (__DEV__) {
  23847. // Check version
  23848. if (version$1.replace('.', '') - 0 < dependencies.zrender.replace('.', '') - 0) {
  23849. throw new Error('zrender/src ' + version$1 + ' is too old for ECharts ' + version + '. Current version need ZRender ' + dependencies.zrender + '+');
  23850. }
  23851. if (!dom) {
  23852. throw new Error('Initialize failed: invalid dom.');
  23853. }
  23854. }
  23855. var existInstance = getInstanceByDom(dom);
  23856. if (existInstance) {
  23857. if (__DEV__) {
  23858. console.warn('There is a chart instance already initialized on the dom.');
  23859. }
  23860. return existInstance;
  23861. }
  23862. if (__DEV__) {
  23863. if (isDom(dom) && dom.nodeName.toUpperCase() !== 'CANVAS' && (!dom.clientWidth && (!opts || opts.width == null) || !dom.clientHeight && (!opts || opts.height == null))) {
  23864. console.warn('Can\'t get DOM width or height. Please check ' + 'dom.clientWidth and dom.clientHeight. They should not be 0.' + 'For example, you may need to call this in the callback ' + 'of window.onload.');
  23865. }
  23866. }
  23867. var chart = new ECharts(dom, theme$$1, opts);
  23868. chart.id = 'ec_' + idBase++;
  23869. instances[chart.id] = chart;
  23870. setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  23871. enableConnect(chart);
  23872. return chart;
  23873. }
  23874. /**
  23875. * @return {string|Array.<module:echarts~ECharts>} groupId
  23876. */
  23877. function connect(groupId) {
  23878. // Is array of charts
  23879. if (isArray(groupId)) {
  23880. var charts = groupId;
  23881. groupId = null; // If any chart has group
  23882. each(charts, function (chart) {
  23883. if (chart.group != null) {
  23884. groupId = chart.group;
  23885. }
  23886. });
  23887. groupId = groupId || 'g_' + groupIdBase++;
  23888. each(charts, function (chart) {
  23889. chart.group = groupId;
  23890. });
  23891. }
  23892. connectedGroups[groupId] = true;
  23893. return groupId;
  23894. }
  23895. /**
  23896. * @DEPRECATED
  23897. * @return {string} groupId
  23898. */
  23899. function disConnect(groupId) {
  23900. connectedGroups[groupId] = false;
  23901. }
  23902. /**
  23903. * @return {string} groupId
  23904. */
  23905. var disconnect = disConnect;
  23906. /**
  23907. * Dispose a chart instance
  23908. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  23909. */
  23910. function dispose(chart) {
  23911. if (typeof chart === 'string') {
  23912. chart = instances[chart];
  23913. } else if (!(chart instanceof ECharts)) {
  23914. // Try to treat as dom
  23915. chart = getInstanceByDom(chart);
  23916. }
  23917. if (chart instanceof ECharts && !chart.isDisposed()) {
  23918. chart.dispose();
  23919. }
  23920. }
  23921. /**
  23922. * @param {HTMLElement} dom
  23923. * @return {echarts~ECharts}
  23924. */
  23925. function getInstanceByDom(dom) {
  23926. return instances[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  23927. }
  23928. /**
  23929. * @param {string} key
  23930. * @return {echarts~ECharts}
  23931. */
  23932. function getInstanceById(key) {
  23933. return instances[key];
  23934. }
  23935. /**
  23936. * Register theme
  23937. */
  23938. function registerTheme(name, theme$$1) {
  23939. themeStorage[name] = theme$$1;
  23940. }
  23941. /**
  23942. * Register option preprocessor
  23943. * @param {Function} preprocessorFunc
  23944. */
  23945. function registerPreprocessor(preprocessorFunc) {
  23946. optionPreprocessorFuncs.push(preprocessorFunc);
  23947. }
  23948. /**
  23949. * @param {number} [priority=1000]
  23950. * @param {Object|Function} processor
  23951. */
  23952. function registerProcessor(priority, processor) {
  23953. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_FILTER);
  23954. }
  23955. /**
  23956. * Register postUpdater
  23957. * @param {Function} postUpdateFunc
  23958. */
  23959. function registerPostUpdate(postUpdateFunc) {
  23960. postUpdateFuncs.push(postUpdateFunc);
  23961. }
  23962. /**
  23963. * Usage:
  23964. * registerAction('someAction', 'someEvent', function () { ... });
  23965. * registerAction('someAction', function () { ... });
  23966. * registerAction(
  23967. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  23968. * function () { ... }
  23969. * );
  23970. *
  23971. * @param {(string|Object)} actionInfo
  23972. * @param {string} actionInfo.type
  23973. * @param {string} [actionInfo.event]
  23974. * @param {string} [actionInfo.update]
  23975. * @param {string} [eventName]
  23976. * @param {Function} action
  23977. */
  23978. function registerAction(actionInfo, eventName, action) {
  23979. if (typeof eventName === 'function') {
  23980. action = eventName;
  23981. eventName = '';
  23982. }
  23983. var actionType = isObject(actionInfo) ? actionInfo.type : [actionInfo, actionInfo = {
  23984. event: eventName
  23985. }][0]; // Event name is all lowercase
  23986. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  23987. eventName = actionInfo.event; // Validate action type and event name.
  23988. assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  23989. if (!actions[actionType]) {
  23990. actions[actionType] = {
  23991. action: action,
  23992. actionInfo: actionInfo
  23993. };
  23994. }
  23995. eventActionMap[eventName] = actionType;
  23996. }
  23997. /**
  23998. * @param {string} type
  23999. * @param {*} CoordinateSystem
  24000. */
  24001. function registerCoordinateSystem(type, CoordinateSystem$$1) {
  24002. CoordinateSystemManager.register(type, CoordinateSystem$$1);
  24003. }
  24004. /**
  24005. * Get dimensions of specified coordinate system.
  24006. * @param {string} type
  24007. * @return {Array.<string|Object>}
  24008. */
  24009. function getCoordinateSystemDimensions(type) {
  24010. var coordSysCreator = CoordinateSystemManager.get(type);
  24011. if (coordSysCreator) {
  24012. return coordSysCreator.getDimensionsInfo ? coordSysCreator.getDimensionsInfo() : coordSysCreator.dimensions.slice();
  24013. }
  24014. }
  24015. /**
  24016. * Layout is a special stage of visual encoding
  24017. * Most visual encoding like color are common for different chart
  24018. * But each chart has it's own layout algorithm
  24019. *
  24020. * @param {number} [priority=1000]
  24021. * @param {Function} layoutTask
  24022. */
  24023. function registerLayout(priority, layoutTask) {
  24024. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  24025. }
  24026. /**
  24027. * @param {number} [priority=3000]
  24028. * @param {module:echarts/stream/Task} visualTask
  24029. */
  24030. function registerVisual(priority, visualTask) {
  24031. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  24032. }
  24033. /**
  24034. * @param {Object|Function} fn: {seriesType, createOnAllSeries, performRawSeries, reset}
  24035. */
  24036. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  24037. if (isFunction(priority) || isObject(priority)) {
  24038. fn = priority;
  24039. priority = defaultPriority;
  24040. }
  24041. if (__DEV__) {
  24042. if (isNaN(priority) || priority == null) {
  24043. throw new Error('Illegal priority');
  24044. } // Check duplicate
  24045. each(targetList, function (wrap) {
  24046. assert(wrap.__raw !== fn);
  24047. });
  24048. }
  24049. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  24050. stageHandler.__prio = priority;
  24051. stageHandler.__raw = fn;
  24052. targetList.push(stageHandler);
  24053. return stageHandler;
  24054. }
  24055. /**
  24056. * @param {string} name
  24057. */
  24058. function registerLoading(name, loadingFx) {
  24059. loadingEffects[name] = loadingFx;
  24060. }
  24061. /**
  24062. * @param {Object} opts
  24063. * @param {string} [superClass]
  24064. */
  24065. function extendComponentModel(opts
  24066. /*, superClass*/
  24067. ) {
  24068. // var Clazz = ComponentModel;
  24069. // if (superClass) {
  24070. // var classType = parseClassType(superClass);
  24071. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  24072. // }
  24073. return ComponentModel.extend(opts);
  24074. }
  24075. /**
  24076. * @param {Object} opts
  24077. * @param {string} [superClass]
  24078. */
  24079. function extendComponentView(opts
  24080. /*, superClass*/
  24081. ) {
  24082. // var Clazz = ComponentView;
  24083. // if (superClass) {
  24084. // var classType = parseClassType(superClass);
  24085. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  24086. // }
  24087. return Component.extend(opts);
  24088. }
  24089. /**
  24090. * @param {Object} opts
  24091. * @param {string} [superClass]
  24092. */
  24093. function extendSeriesModel(opts
  24094. /*, superClass*/
  24095. ) {
  24096. // var Clazz = SeriesModel;
  24097. // if (superClass) {
  24098. // superClass = 'series.' + superClass.replace('series.', '');
  24099. // var classType = parseClassType(superClass);
  24100. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  24101. // }
  24102. return SeriesModel.extend(opts);
  24103. }
  24104. /**
  24105. * @param {Object} opts
  24106. * @param {string} [superClass]
  24107. */
  24108. function extendChartView(opts
  24109. /*, superClass*/
  24110. ) {
  24111. // var Clazz = ChartView;
  24112. // if (superClass) {
  24113. // superClass = superClass.replace('series.', '');
  24114. // var classType = parseClassType(superClass);
  24115. // Clazz = ChartView.getClass(classType.main, true);
  24116. // }
  24117. return Chart.extend(opts);
  24118. }
  24119. /**
  24120. * ZRender need a canvas context to do measureText.
  24121. * But in node environment canvas may be created by node-canvas.
  24122. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  24123. *
  24124. * Be careful of using it in the browser.
  24125. *
  24126. * @param {Function} creator
  24127. * @example
  24128. * var Canvas = require('canvas');
  24129. * var echarts = require('echarts');
  24130. * echarts.setCanvasCreator(function () {
  24131. * // Small size is enough.
  24132. * return new Canvas(32, 32);
  24133. * });
  24134. */
  24135. function setCanvasCreator(creator) {
  24136. $override('createCanvas', creator);
  24137. }
  24138. /**
  24139. * @param {string} mapName
  24140. * @param {Array.<Object>|Object|string} geoJson
  24141. * @param {Object} [specialAreas]
  24142. *
  24143. * @example GeoJSON
  24144. * $.get('USA.json', function (geoJson) {
  24145. * echarts.registerMap('USA', geoJson);
  24146. * // Or
  24147. * echarts.registerMap('USA', {
  24148. * geoJson: geoJson,
  24149. * specialAreas: {}
  24150. * })
  24151. * });
  24152. *
  24153. * $.get('airport.svg', function (svg) {
  24154. * echarts.registerMap('airport', {
  24155. * svg: svg
  24156. * }
  24157. * });
  24158. *
  24159. * echarts.registerMap('eu', [
  24160. * {svg: eu-topographic.svg},
  24161. * {geoJSON: eu.json}
  24162. * ])
  24163. */
  24164. function registerMap(mapName, geoJson, specialAreas) {
  24165. mapDataStorage.registerMap(mapName, geoJson, specialAreas);
  24166. }
  24167. /**
  24168. * @param {string} mapName
  24169. * @return {Object}
  24170. */
  24171. function getMap(mapName) {
  24172. // For backward compatibility, only return the first one.
  24173. var records = mapDataStorage.retrieveMap(mapName);
  24174. return records && records[0] && {
  24175. geoJson: records[0].geoJSON,
  24176. specialAreas: records[0].specialAreas
  24177. };
  24178. }
  24179. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);
  24180. registerPreprocessor(backwardCompat);
  24181. registerProcessor(PRIORITY_PROCESSOR_DATASTACK, dataStack);
  24182. registerLoading('default', loadingDefault); // Default actions
  24183. registerAction({
  24184. type: 'highlight',
  24185. event: 'highlight',
  24186. update: 'highlight'
  24187. }, noop);
  24188. registerAction({
  24189. type: 'downplay',
  24190. event: 'downplay',
  24191. update: 'downplay'
  24192. }, noop); // Default theme
  24193. registerTheme('light', lightTheme);
  24194. registerTheme('dark', theme); // For backward compatibility, where the namespace `dataTool` will
  24195. // be mounted on `echarts` is the extension `dataTool` is imported.
  24196. var dataTool = {};
  24197. /*
  24198. * Licensed to the Apache Software Foundation (ASF) under one
  24199. * or more contributor license agreements. See the NOTICE file
  24200. * distributed with this work for additional information
  24201. * regarding copyright ownership. The ASF licenses this file
  24202. * to you under the Apache License, Version 2.0 (the
  24203. * "License"); you may not use this file except in compliance
  24204. * with the License. You may obtain a copy of the License at
  24205. *
  24206. * http://www.apache.org/licenses/LICENSE-2.0
  24207. *
  24208. * Unless required by applicable law or agreed to in writing,
  24209. * software distributed under the License is distributed on an
  24210. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24211. * KIND, either express or implied. See the License for the
  24212. * specific language governing permissions and limitations
  24213. * under the License.
  24214. */
  24215. function defaultKeyGetter(item) {
  24216. return item;
  24217. }
  24218. /**
  24219. * @param {Array} oldArr
  24220. * @param {Array} newArr
  24221. * @param {Function} oldKeyGetter
  24222. * @param {Function} newKeyGetter
  24223. * @param {Object} [context] Can be visited by this.context in callback.
  24224. */
  24225. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {
  24226. this._old = oldArr;
  24227. this._new = newArr;
  24228. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  24229. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  24230. this.context = context;
  24231. }
  24232. DataDiffer.prototype = {
  24233. constructor: DataDiffer,
  24234. /**
  24235. * Callback function when add a data
  24236. */
  24237. add: function (func) {
  24238. this._add = func;
  24239. return this;
  24240. },
  24241. /**
  24242. * Callback function when update a data
  24243. */
  24244. update: function (func) {
  24245. this._update = func;
  24246. return this;
  24247. },
  24248. /**
  24249. * Callback function when remove a data
  24250. */
  24251. remove: function (func) {
  24252. this._remove = func;
  24253. return this;
  24254. },
  24255. execute: function () {
  24256. var oldArr = this._old;
  24257. var newArr = this._new;
  24258. var oldDataIndexMap = {};
  24259. var newDataIndexMap = {};
  24260. var oldDataKeyArr = [];
  24261. var newDataKeyArr = [];
  24262. var i;
  24263. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);
  24264. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);
  24265. for (i = 0; i < oldArr.length; i++) {
  24266. var key = oldDataKeyArr[i];
  24267. var idx = newDataIndexMap[key]; // idx can never be empty array here. see 'set null' logic below.
  24268. if (idx != null) {
  24269. // Consider there is duplicate key (for example, use dataItem.name as key).
  24270. // We should make sure every item in newArr and oldArr can be visited.
  24271. var len = idx.length;
  24272. if (len) {
  24273. len === 1 && (newDataIndexMap[key] = null);
  24274. idx = idx.shift();
  24275. } else {
  24276. newDataIndexMap[key] = null;
  24277. }
  24278. this._update && this._update(idx, i);
  24279. } else {
  24280. this._remove && this._remove(i);
  24281. }
  24282. }
  24283. for (var i = 0; i < newDataKeyArr.length; i++) {
  24284. var key = newDataKeyArr[i];
  24285. if (newDataIndexMap.hasOwnProperty(key)) {
  24286. var idx = newDataIndexMap[key];
  24287. if (idx == null) {
  24288. continue;
  24289. } // idx can never be empty array here. see 'set null' logic above.
  24290. if (!idx.length) {
  24291. this._add && this._add(idx);
  24292. } else {
  24293. for (var j = 0, len = idx.length; j < len; j++) {
  24294. this._add && this._add(idx[j]);
  24295. }
  24296. }
  24297. }
  24298. }
  24299. }
  24300. };
  24301. function initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {
  24302. for (var i = 0; i < arr.length; i++) {
  24303. // Add prefix to avoid conflict with Object.prototype.
  24304. var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);
  24305. var existence = map[key];
  24306. if (existence == null) {
  24307. keyArr.push(key);
  24308. map[key] = i;
  24309. } else {
  24310. if (!existence.length) {
  24311. map[key] = existence = [existence];
  24312. }
  24313. existence.push(i);
  24314. }
  24315. }
  24316. }
  24317. /*
  24318. * Licensed to the Apache Software Foundation (ASF) under one
  24319. * or more contributor license agreements. See the NOTICE file
  24320. * distributed with this work for additional information
  24321. * regarding copyright ownership. The ASF licenses this file
  24322. * to you under the Apache License, Version 2.0 (the
  24323. * "License"); you may not use this file except in compliance
  24324. * with the License. You may obtain a copy of the License at
  24325. *
  24326. * http://www.apache.org/licenses/LICENSE-2.0
  24327. *
  24328. * Unless required by applicable law or agreed to in writing,
  24329. * software distributed under the License is distributed on an
  24330. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24331. * KIND, either express or implied. See the License for the
  24332. * specific language governing permissions and limitations
  24333. * under the License.
  24334. */
  24335. var OTHER_DIMENSIONS = createHashMap(['tooltip', 'label', 'itemName', 'itemId', 'seriesName']);
  24336. function summarizeDimensions(data) {
  24337. var summary = {};
  24338. var encode = summary.encode = {};
  24339. var notExtraCoordDimMap = createHashMap();
  24340. var defaultedLabel = [];
  24341. var defaultedTooltip = []; // See the comment of `List.js#userOutput`.
  24342. var userOutput = summary.userOutput = {
  24343. dimensionNames: data.dimensions.slice(),
  24344. encode: {}
  24345. };
  24346. each$1(data.dimensions, function (dimName) {
  24347. var dimItem = data.getDimensionInfo(dimName);
  24348. var coordDim = dimItem.coordDim;
  24349. if (coordDim) {
  24350. if (__DEV__) {
  24351. assert$1(OTHER_DIMENSIONS.get(coordDim) == null);
  24352. }
  24353. var coordDimIndex = dimItem.coordDimIndex;
  24354. getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
  24355. if (!dimItem.isExtraCoord) {
  24356. notExtraCoordDimMap.set(coordDim, 1); // Use the last coord dim (and label friendly) as default label,
  24357. // because when dataset is used, it is hard to guess which dimension
  24358. // can be value dimension. If both show x, y on label is not look good,
  24359. // and conventionally y axis is focused more.
  24360. if (mayLabelDimType(dimItem.type)) {
  24361. defaultedLabel[0] = dimName;
  24362. } // User output encode do not contain generated coords.
  24363. // And it only has index. User can use index to retrieve value from the raw item array.
  24364. getOrCreateEncodeArr(userOutput.encode, coordDim)[coordDimIndex] = dimItem.index;
  24365. }
  24366. if (dimItem.defaultTooltip) {
  24367. defaultedTooltip.push(dimName);
  24368. }
  24369. }
  24370. OTHER_DIMENSIONS.each(function (v, otherDim) {
  24371. var encodeArr = getOrCreateEncodeArr(encode, otherDim);
  24372. var dimIndex = dimItem.otherDims[otherDim];
  24373. if (dimIndex != null && dimIndex !== false) {
  24374. encodeArr[dimIndex] = dimItem.name;
  24375. }
  24376. });
  24377. });
  24378. var dataDimsOnCoord = [];
  24379. var encodeFirstDimNotExtra = {};
  24380. notExtraCoordDimMap.each(function (v, coordDim) {
  24381. var dimArr = encode[coordDim]; // ??? FIXME extra coord should not be set in dataDimsOnCoord.
  24382. // But should fix the case that radar axes: simplify the logic
  24383. // of `completeDimension`, remove `extraPrefix`.
  24384. encodeFirstDimNotExtra[coordDim] = dimArr[0]; // Not necessary to remove duplicate, because a data
  24385. // dim canot on more than one coordDim.
  24386. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  24387. });
  24388. summary.dataDimsOnCoord = dataDimsOnCoord;
  24389. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  24390. var encodeLabel = encode.label; // FIXME `encode.label` is not recommanded, because formatter can not be set
  24391. // in this way. Use label.formatter instead. May be remove this approach someday.
  24392. if (encodeLabel && encodeLabel.length) {
  24393. defaultedLabel = encodeLabel.slice();
  24394. }
  24395. var encodeTooltip = encode.tooltip;
  24396. if (encodeTooltip && encodeTooltip.length) {
  24397. defaultedTooltip = encodeTooltip.slice();
  24398. } else if (!defaultedTooltip.length) {
  24399. defaultedTooltip = defaultedLabel.slice();
  24400. }
  24401. encode.defaultedLabel = defaultedLabel;
  24402. encode.defaultedTooltip = defaultedTooltip;
  24403. return summary;
  24404. }
  24405. function getOrCreateEncodeArr(encode, dim) {
  24406. if (!encode.hasOwnProperty(dim)) {
  24407. encode[dim] = [];
  24408. }
  24409. return encode[dim];
  24410. }
  24411. function getDimensionTypeByAxis(axisType) {
  24412. return axisType === 'category' ? 'ordinal' : axisType === 'time' ? 'time' : 'float';
  24413. }
  24414. function mayLabelDimType(dimType) {
  24415. // In most cases, ordinal and time do not suitable for label.
  24416. // Ordinal info can be displayed on axis. Time is too long.
  24417. return !(dimType === 'ordinal' || dimType === 'time');
  24418. } // function findTheLastDimMayLabel(data) {
  24419. // // Get last value dim
  24420. // var dimensions = data.dimensions.slice();
  24421. // var valueType;
  24422. // var valueDim;
  24423. // while (dimensions.length && (
  24424. // valueDim = dimensions.pop(),
  24425. // valueType = data.getDimensionInfo(valueDim).type,
  24426. // valueType === 'ordinal' || valueType === 'time'
  24427. // )) {} // jshint ignore:line
  24428. // return valueDim;
  24429. // }
  24430. /*
  24431. * Licensed to the Apache Software Foundation (ASF) under one
  24432. * or more contributor license agreements. See the NOTICE file
  24433. * distributed with this work for additional information
  24434. * regarding copyright ownership. The ASF licenses this file
  24435. * to you under the Apache License, Version 2.0 (the
  24436. * "License"); you may not use this file except in compliance
  24437. * with the License. You may obtain a copy of the License at
  24438. *
  24439. * http://www.apache.org/licenses/LICENSE-2.0
  24440. *
  24441. * Unless required by applicable law or agreed to in writing,
  24442. * software distributed under the License is distributed on an
  24443. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24444. * KIND, either express or implied. See the License for the
  24445. * specific language governing permissions and limitations
  24446. * under the License.
  24447. */
  24448. /**
  24449. * @class
  24450. * @param {Object|DataDimensionInfo} [opt] All of the fields will be shallow copied.
  24451. */
  24452. function DataDimensionInfo(opt) {
  24453. if (opt != null) {
  24454. extend(this, opt);
  24455. }
  24456. /**
  24457. * Dimension name.
  24458. * Mandatory.
  24459. * @type {string}
  24460. */
  24461. // this.name;
  24462. /**
  24463. * The origin name in dimsDef, see source helper.
  24464. * If displayName given, the tooltip will displayed vertically.
  24465. * Optional.
  24466. * @type {string}
  24467. */
  24468. // this.displayName;
  24469. /**
  24470. * Which coordSys dimension this dimension mapped to.
  24471. * A `coordDim` can be a "coordSysDim" that the coordSys required
  24472. * (for example, an item in `coordSysDims` of `model/referHelper#CoordSysInfo`),
  24473. * or an generated "extra coord name" if does not mapped to any "coordSysDim"
  24474. * (That is determined by whether `isExtraCoord` is `true`).
  24475. * Mandatory.
  24476. * @type {string}
  24477. */
  24478. // this.coordDim;
  24479. /**
  24480. * The index of this dimension in `series.encode[coordDim]`.
  24481. * Mandatory.
  24482. * @type {number}
  24483. */
  24484. // this.coordDimIndex;
  24485. /**
  24486. * Dimension type. The enumerable values are the key of
  24487. * `dataCtors` of `data/List`.
  24488. * Optional.
  24489. * @type {string}
  24490. */
  24491. // this.type;
  24492. /**
  24493. * This index of this dimension info in `data/List#_dimensionInfos`.
  24494. * Mandatory after added to `data/List`.
  24495. * @type {number}
  24496. */
  24497. // this.index;
  24498. /**
  24499. * The format of `otherDims` is:
  24500. * ```js
  24501. * {
  24502. * tooltip: number optional,
  24503. * label: number optional,
  24504. * itemName: number optional,
  24505. * seriesName: number optional,
  24506. * }
  24507. * ```
  24508. *
  24509. * A `series.encode` can specified these fields:
  24510. * ```js
  24511. * encode: {
  24512. * // "3, 1, 5" is the index of data dimension.
  24513. * tooltip: [3, 1, 5],
  24514. * label: [0, 3],
  24515. * ...
  24516. * }
  24517. * ```
  24518. * `otherDims` is the parse result of the `series.encode` above, like:
  24519. * ```js
  24520. * // Suppose the index of this data dimension is `3`.
  24521. * this.otherDims = {
  24522. * // `3` is at the index `0` of the `encode.tooltip`
  24523. * tooltip: 0,
  24524. * // `3` is at the index `1` of the `encode.tooltip`
  24525. * label: 1
  24526. * };
  24527. * ```
  24528. *
  24529. * This prop should never be `null`/`undefined` after initialized.
  24530. * @type {Object}
  24531. */
  24532. this.otherDims = {};
  24533. /**
  24534. * Be `true` if this dimension is not mapped to any "coordSysDim" that the
  24535. * "coordSys" required.
  24536. * Mandatory.
  24537. * @type {boolean}
  24538. */
  24539. // this.isExtraCoord;
  24540. /**
  24541. * @type {module:data/OrdinalMeta}
  24542. */
  24543. // this.ordinalMeta;
  24544. /**
  24545. * Whether to create inverted indices.
  24546. * @type {boolean}
  24547. */
  24548. // this.createInvertedIndices;
  24549. }
  24550. /*
  24551. * Licensed to the Apache Software Foundation (ASF) under one
  24552. * or more contributor license agreements. See the NOTICE file
  24553. * distributed with this work for additional information
  24554. * regarding copyright ownership. The ASF licenses this file
  24555. * to you under the Apache License, Version 2.0 (the
  24556. * "License"); you may not use this file except in compliance
  24557. * with the License. You may obtain a copy of the License at
  24558. *
  24559. * http://www.apache.org/licenses/LICENSE-2.0
  24560. *
  24561. * Unless required by applicable law or agreed to in writing,
  24562. * software distributed under the License is distributed on an
  24563. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24564. * KIND, either express or implied. See the License for the
  24565. * specific language governing permissions and limitations
  24566. * under the License.
  24567. */
  24568. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  24569. /**
  24570. * List for data storage
  24571. * @module echarts/data/List
  24572. */
  24573. var isObject$4 = isObject$1;
  24574. var UNDEFINED = 'undefined';
  24575. var INDEX_NOT_FOUND = -1; // Use prefix to avoid index to be the same as otherIdList[idx],
  24576. // which will cause weird udpate animation.
  24577. var ID_PREFIX = 'e\0\0';
  24578. var dataCtors = {
  24579. 'float': typeof Float64Array === UNDEFINED ? Array : Float64Array,
  24580. 'int': typeof Int32Array === UNDEFINED ? Array : Int32Array,
  24581. // Ordinal data type can be string or int
  24582. 'ordinal': Array,
  24583. 'number': Array,
  24584. 'time': Array
  24585. }; // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  24586. // different from the Ctor of typed array.
  24587. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  24588. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  24589. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  24590. function getIndicesCtor(list) {
  24591. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  24592. return list._rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  24593. }
  24594. function cloneChunk(originalChunk) {
  24595. var Ctor = originalChunk.constructor; // Only shallow clone is enough when Array.
  24596. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  24597. }
  24598. var TRANSFERABLE_PROPERTIES = ['hasItemOption', '_nameList', '_idList', '_invertedIndicesMap', '_rawData', '_chunkSize', '_chunkCount', '_dimValueGetter', '_count', '_rawCount', '_nameDimIdx', '_idDimIdx'];
  24599. var CLONE_PROPERTIES = ['_extent', '_approximateExtent', '_rawExtent'];
  24600. function transferProperties(target, source) {
  24601. each$1(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  24602. if (source.hasOwnProperty(propName)) {
  24603. target[propName] = source[propName];
  24604. }
  24605. });
  24606. target.__wrappedMethods = source.__wrappedMethods;
  24607. each$1(CLONE_PROPERTIES, function (propName) {
  24608. target[propName] = clone(source[propName]);
  24609. });
  24610. target._calculationInfo = extend(source._calculationInfo);
  24611. }
  24612. /**
  24613. * @constructor
  24614. * @alias module:echarts/data/List
  24615. *
  24616. * @param {Array.<string|Object|module:data/DataDimensionInfo>} dimensions
  24617. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  24618. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  24619. * @param {module:echarts/model/Model} hostModel
  24620. */
  24621. var List = function (dimensions, hostModel) {
  24622. dimensions = dimensions || ['x', 'y'];
  24623. var dimensionInfos = {};
  24624. var dimensionNames = [];
  24625. var invertedIndicesMap = {};
  24626. for (var i = 0; i < dimensions.length; i++) {
  24627. // Use the original dimensions[i], where other flag props may exists.
  24628. var dimensionInfo = dimensions[i];
  24629. if (isString(dimensionInfo)) {
  24630. dimensionInfo = new DataDimensionInfo({
  24631. name: dimensionInfo
  24632. });
  24633. } else if (!(dimensionInfo instanceof DataDimensionInfo)) {
  24634. dimensionInfo = new DataDimensionInfo(dimensionInfo);
  24635. }
  24636. var dimensionName = dimensionInfo.name;
  24637. dimensionInfo.type = dimensionInfo.type || 'float';
  24638. if (!dimensionInfo.coordDim) {
  24639. dimensionInfo.coordDim = dimensionName;
  24640. dimensionInfo.coordDimIndex = 0;
  24641. }
  24642. dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  24643. dimensionNames.push(dimensionName);
  24644. dimensionInfos[dimensionName] = dimensionInfo;
  24645. dimensionInfo.index = i;
  24646. if (dimensionInfo.createInvertedIndices) {
  24647. invertedIndicesMap[dimensionName] = [];
  24648. }
  24649. }
  24650. /**
  24651. * @readOnly
  24652. * @type {Array.<string>}
  24653. */
  24654. this.dimensions = dimensionNames;
  24655. /**
  24656. * Infomation of each data dimension, like data type.
  24657. * @type {Object}
  24658. */
  24659. this._dimensionInfos = dimensionInfos;
  24660. /**
  24661. * @type {module:echarts/model/Model}
  24662. */
  24663. this.hostModel = hostModel;
  24664. /**
  24665. * @type {module:echarts/model/Model}
  24666. */
  24667. this.dataType;
  24668. /**
  24669. * Indices stores the indices of data subset after filtered.
  24670. * This data subset will be used in chart.
  24671. * @type {Array.<number>}
  24672. * @readOnly
  24673. */
  24674. this._indices = null;
  24675. this._count = 0;
  24676. this._rawCount = 0;
  24677. /**
  24678. * Data storage
  24679. * @type {Object.<key, Array.<TypedArray|Array>>}
  24680. * @private
  24681. */
  24682. this._storage = {};
  24683. /**
  24684. * @type {Array.<string>}
  24685. */
  24686. this._nameList = [];
  24687. /**
  24688. * @type {Array.<string>}
  24689. */
  24690. this._idList = [];
  24691. /**
  24692. * Models of data option is stored sparse for optimizing memory cost
  24693. * @type {Array.<module:echarts/model/Model>}
  24694. * @private
  24695. */
  24696. this._optionModels = [];
  24697. /**
  24698. * Global visual properties after visual coding
  24699. * @type {Object}
  24700. * @private
  24701. */
  24702. this._visual = {};
  24703. /**
  24704. * Globel layout properties.
  24705. * @type {Object}
  24706. * @private
  24707. */
  24708. this._layout = {};
  24709. /**
  24710. * Item visual properties after visual coding
  24711. * @type {Array.<Object>}
  24712. * @private
  24713. */
  24714. this._itemVisuals = [];
  24715. /**
  24716. * Key: visual type, Value: boolean
  24717. * @type {Object}
  24718. * @readOnly
  24719. */
  24720. this.hasItemVisual = {};
  24721. /**
  24722. * Item layout properties after layout
  24723. * @type {Array.<Object>}
  24724. * @private
  24725. */
  24726. this._itemLayouts = [];
  24727. /**
  24728. * Graphic elemnents
  24729. * @type {Array.<module:zrender/Element>}
  24730. * @private
  24731. */
  24732. this._graphicEls = [];
  24733. /**
  24734. * Max size of each chunk.
  24735. * @type {number}
  24736. * @private
  24737. */
  24738. this._chunkSize = 1e5;
  24739. /**
  24740. * @type {number}
  24741. * @private
  24742. */
  24743. this._chunkCount = 0;
  24744. /**
  24745. * @type {Array.<Array|Object>}
  24746. * @private
  24747. */
  24748. this._rawData;
  24749. /**
  24750. * Raw extent will not be cloned, but only transfered.
  24751. * It will not be calculated util needed.
  24752. * key: dim,
  24753. * value: {end: number, extent: Array.<number>}
  24754. * @type {Object}
  24755. * @private
  24756. */
  24757. this._rawExtent = {};
  24758. /**
  24759. * @type {Object}
  24760. * @private
  24761. */
  24762. this._extent = {};
  24763. /**
  24764. * key: dim
  24765. * value: extent
  24766. * @type {Object}
  24767. * @private
  24768. */
  24769. this._approximateExtent = {};
  24770. /**
  24771. * Cache summary info for fast visit. See "dimensionHelper".
  24772. * @type {Object}
  24773. * @private
  24774. */
  24775. this._dimensionsSummary = summarizeDimensions(this);
  24776. /**
  24777. * @type {Object.<Array|TypedArray>}
  24778. * @private
  24779. */
  24780. this._invertedIndicesMap = invertedIndicesMap;
  24781. /**
  24782. * @type {Object}
  24783. * @private
  24784. */
  24785. this._calculationInfo = {};
  24786. /**
  24787. * User output info of this data.
  24788. * DO NOT use it in other places!
  24789. *
  24790. * When preparing user params for user callbacks, we have
  24791. * to clone these inner data structures to prevent users
  24792. * from modifying them to effect built-in logic. And for
  24793. * performance consideration we make this `userOutput` to
  24794. * avoid clone them too many times.
  24795. *
  24796. * @type {Object}
  24797. * @readOnly
  24798. */
  24799. this.userOutput = this._dimensionsSummary.userOutput;
  24800. };
  24801. var listProto = List.prototype;
  24802. listProto.type = 'list';
  24803. /**
  24804. * If each data item has it's own option
  24805. * @type {boolean}
  24806. */
  24807. listProto.hasItemOption = true;
  24808. /**
  24809. * The meanings of the input parameter `dim`:
  24810. *
  24811. * + If dim is a number (e.g., `1`), it means the index of the dimension.
  24812. * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.
  24813. * + If dim is a number-like string (e.g., `"1"`):
  24814. * + If there is the same concrete dim name defined in `this.dimensions`, it means that concrete name.
  24815. * + If not, it will be converted to a number, which means the index of the dimension.
  24816. * (why? because of the backward compatbility. We have been tolerating number-like string in
  24817. * dimension setting, although now it seems that it is not a good idea.)
  24818. * For example, `visualMap[i].dimension: "1"` is the same meaning as `visualMap[i].dimension: 1`,
  24819. * if no dimension name is defined as `"1"`.
  24820. * + If dim is a not-number-like string, it means the concrete dim name.
  24821. * For example, it can be be default name `"x"`, `"y"`, `"z"`, `"lng"`, `"lat"`, `"angle"`, `"radius"`,
  24822. * or customized in `dimensions` property of option like `"age"`.
  24823. *
  24824. * Get dimension name
  24825. * @param {string|number} dim See above.
  24826. * @return {string} Concrete dim name.
  24827. */
  24828. listProto.getDimension = function (dim) {
  24829. if (typeof dim === 'number' // If being a number-like string but not being defined a dimension name.
  24830. || !isNaN(dim) && !this._dimensionInfos.hasOwnProperty(dim)) {
  24831. dim = this.dimensions[dim];
  24832. }
  24833. return dim;
  24834. };
  24835. /**
  24836. * Get type and calculation info of particular dimension
  24837. * @param {string|number} dim
  24838. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  24839. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  24840. */
  24841. listProto.getDimensionInfo = function (dim) {
  24842. // Do not clone, because there may be categories in dimInfo.
  24843. return this._dimensionInfos[this.getDimension(dim)];
  24844. };
  24845. /**
  24846. * @return {Array.<string>} concrete dimension name list on coord.
  24847. */
  24848. listProto.getDimensionsOnCoord = function () {
  24849. return this._dimensionsSummary.dataDimsOnCoord.slice();
  24850. };
  24851. /**
  24852. * @param {string} coordDim
  24853. * @param {number} [idx] A coordDim may map to more than one data dim.
  24854. * If idx is `true`, return a array of all mapped dims.
  24855. * If idx is not specified, return the first dim not extra.
  24856. * @return {string|Array.<string>} concrete data dim.
  24857. * If idx is number, and not found, return null/undefined.
  24858. * If idx is `true`, and not found, return empty array (always return array).
  24859. */
  24860. listProto.mapDimension = function (coordDim, idx) {
  24861. var dimensionsSummary = this._dimensionsSummary;
  24862. if (idx == null) {
  24863. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  24864. }
  24865. var dims = dimensionsSummary.encode[coordDim];
  24866. return idx === true // always return array if idx is `true`
  24867. ? (dims || []).slice() : dims && dims[idx];
  24868. };
  24869. /**
  24870. * Initialize from data
  24871. * @param {Array.<Object|number|Array>} data source or data or data provider.
  24872. * @param {Array.<string>} [nameLIst] The name of a datum is used on data diff and
  24873. * default label/tooltip.
  24874. * A name can be specified in encode.itemName,
  24875. * or dataItem.name (only for series option data),
  24876. * or provided in nameList from outside.
  24877. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  24878. */
  24879. listProto.initData = function (data, nameList, dimValueGetter) {
  24880. var notProvider = Source.isInstance(data) || isArrayLike(data);
  24881. if (notProvider) {
  24882. data = new DefaultDataProvider(data, this.dimensions.length);
  24883. }
  24884. if (__DEV__) {
  24885. if (!notProvider && (typeof data.getItem !== 'function' || typeof data.count !== 'function')) {
  24886. throw new Error('Inavlid data provider.');
  24887. }
  24888. }
  24889. this._rawData = data; // Clear
  24890. this._storage = {};
  24891. this._indices = null;
  24892. this._nameList = nameList || [];
  24893. this._idList = [];
  24894. this._nameRepeatCount = {};
  24895. if (!dimValueGetter) {
  24896. this.hasItemOption = false;
  24897. }
  24898. /**
  24899. * @readOnly
  24900. */
  24901. this.defaultDimValueGetter = defaultDimValueGetters[this._rawData.getSource().sourceFormat]; // Default dim value getter
  24902. this._dimValueGetter = dimValueGetter = dimValueGetter || this.defaultDimValueGetter;
  24903. this._dimValueGetterArrayRows = defaultDimValueGetters.arrayRows; // Reset raw extent.
  24904. this._rawExtent = {};
  24905. this._initDataFromProvider(0, data.count()); // If data has no item option.
  24906. if (data.pure) {
  24907. this.hasItemOption = false;
  24908. }
  24909. };
  24910. listProto.getProvider = function () {
  24911. return this._rawData;
  24912. };
  24913. /**
  24914. * Caution: Can be only called on raw data (before `this._indices` created).
  24915. */
  24916. listProto.appendData = function (data) {
  24917. if (__DEV__) {
  24918. assert$1(!this._indices, 'appendData can only be called on raw data.');
  24919. }
  24920. var rawData = this._rawData;
  24921. var start = this.count();
  24922. rawData.appendData(data);
  24923. var end = rawData.count();
  24924. if (!rawData.persistent) {
  24925. end += start;
  24926. }
  24927. this._initDataFromProvider(start, end);
  24928. };
  24929. /**
  24930. * Caution: Can be only called on raw data (before `this._indices` created).
  24931. * This method does not modify `rawData` (`dataProvider`), but only
  24932. * add values to storage.
  24933. *
  24934. * The final count will be increased by `Math.max(values.length, names.length)`.
  24935. *
  24936. * @param {Array.<Array.<*>>} values That is the SourceType: 'arrayRows', like
  24937. * [
  24938. * [12, 33, 44],
  24939. * [NaN, 43, 1],
  24940. * ['-', 'asdf', 0]
  24941. * ]
  24942. * Each item is exaclty cooresponding to a dimension.
  24943. * @param {Array.<string>} [names]
  24944. */
  24945. listProto.appendValues = function (values, names) {
  24946. var chunkSize = this._chunkSize;
  24947. var storage = this._storage;
  24948. var dimensions = this.dimensions;
  24949. var dimLen = dimensions.length;
  24950. var rawExtent = this._rawExtent;
  24951. var start = this.count();
  24952. var end = start + Math.max(values.length, names ? names.length : 0);
  24953. var originalChunkCount = this._chunkCount;
  24954. for (var i = 0; i < dimLen; i++) {
  24955. var dim = dimensions[i];
  24956. if (!rawExtent[dim]) {
  24957. rawExtent[dim] = getInitialExtent();
  24958. }
  24959. if (!storage[dim]) {
  24960. storage[dim] = [];
  24961. }
  24962. prepareChunks(storage, this._dimensionInfos[dim], chunkSize, originalChunkCount, end);
  24963. this._chunkCount = storage[dim].length;
  24964. }
  24965. var emptyDataItem = new Array(dimLen);
  24966. for (var idx = start; idx < end; idx++) {
  24967. var sourceIdx = idx - start;
  24968. var chunkIndex = Math.floor(idx / chunkSize);
  24969. var chunkOffset = idx % chunkSize; // Store the data by dimensions
  24970. for (var k = 0; k < dimLen; k++) {
  24971. var dim = dimensions[k];
  24972. var val = this._dimValueGetterArrayRows(values[sourceIdx] || emptyDataItem, dim, sourceIdx, k);
  24973. storage[dim][chunkIndex][chunkOffset] = val;
  24974. var dimRawExtent = rawExtent[dim];
  24975. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  24976. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  24977. }
  24978. if (names) {
  24979. this._nameList[idx] = names[sourceIdx];
  24980. }
  24981. }
  24982. this._rawCount = this._count = end; // Reset data extent
  24983. this._extent = {};
  24984. prepareInvertedIndex(this);
  24985. };
  24986. listProto._initDataFromProvider = function (start, end) {
  24987. // Optimize.
  24988. if (start >= end) {
  24989. return;
  24990. }
  24991. var chunkSize = this._chunkSize;
  24992. var rawData = this._rawData;
  24993. var storage = this._storage;
  24994. var dimensions = this.dimensions;
  24995. var dimLen = dimensions.length;
  24996. var dimensionInfoMap = this._dimensionInfos;
  24997. var nameList = this._nameList;
  24998. var idList = this._idList;
  24999. var rawExtent = this._rawExtent;
  25000. var nameRepeatCount = this._nameRepeatCount = {};
  25001. var nameDimIdx;
  25002. var originalChunkCount = this._chunkCount;
  25003. for (var i = 0; i < dimLen; i++) {
  25004. var dim = dimensions[i];
  25005. if (!rawExtent[dim]) {
  25006. rawExtent[dim] = getInitialExtent();
  25007. }
  25008. var dimInfo = dimensionInfoMap[dim];
  25009. if (dimInfo.otherDims.itemName === 0) {
  25010. nameDimIdx = this._nameDimIdx = i;
  25011. }
  25012. if (dimInfo.otherDims.itemId === 0) {
  25013. this._idDimIdx = i;
  25014. }
  25015. if (!storage[dim]) {
  25016. storage[dim] = [];
  25017. }
  25018. prepareChunks(storage, dimInfo, chunkSize, originalChunkCount, end);
  25019. this._chunkCount = storage[dim].length;
  25020. }
  25021. var dataItem = new Array(dimLen);
  25022. for (var idx = start; idx < end; idx++) {
  25023. // NOTICE: Try not to write things into dataItem
  25024. dataItem = rawData.getItem(idx, dataItem); // Each data item is value
  25025. // [1, 2]
  25026. // 2
  25027. // Bar chart, line chart which uses category axis
  25028. // only gives the 'y' value. 'x' value is the indices of category
  25029. // Use a tempValue to normalize the value to be a (x, y) value
  25030. var chunkIndex = Math.floor(idx / chunkSize);
  25031. var chunkOffset = idx % chunkSize; // Store the data by dimensions
  25032. for (var k = 0; k < dimLen; k++) {
  25033. var dim = dimensions[k];
  25034. var dimStorage = storage[dim][chunkIndex]; // PENDING NULL is empty or zero
  25035. var val = this._dimValueGetter(dataItem, dim, idx, k);
  25036. dimStorage[chunkOffset] = val;
  25037. var dimRawExtent = rawExtent[dim];
  25038. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  25039. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  25040. } // ??? FIXME not check by pure but sourceFormat?
  25041. // TODO refactor these logic.
  25042. if (!rawData.pure) {
  25043. var name = nameList[idx];
  25044. if (dataItem && name == null) {
  25045. // If dataItem is {name: ...}, it has highest priority.
  25046. // That is appropriate for many common cases.
  25047. if (dataItem.name != null) {
  25048. // There is no other place to persistent dataItem.name,
  25049. // so save it to nameList.
  25050. nameList[idx] = name = dataItem.name;
  25051. } else if (nameDimIdx != null) {
  25052. var nameDim = dimensions[nameDimIdx];
  25053. var nameDimChunk = storage[nameDim][chunkIndex];
  25054. if (nameDimChunk) {
  25055. name = nameDimChunk[chunkOffset];
  25056. var ordinalMeta = dimensionInfoMap[nameDim].ordinalMeta;
  25057. if (ordinalMeta && ordinalMeta.categories.length) {
  25058. name = ordinalMeta.categories[name];
  25059. }
  25060. }
  25061. }
  25062. } // Try using the id in option
  25063. // id or name is used on dynamical data, mapping old and new items.
  25064. var id = dataItem == null ? null : dataItem.id;
  25065. if (id == null && name != null) {
  25066. // Use name as id and add counter to avoid same name
  25067. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  25068. id = name;
  25069. if (nameRepeatCount[name] > 0) {
  25070. id += '__ec__' + nameRepeatCount[name];
  25071. }
  25072. nameRepeatCount[name]++;
  25073. }
  25074. id != null && (idList[idx] = id);
  25075. }
  25076. }
  25077. if (!rawData.persistent && rawData.clean) {
  25078. // Clean unused data if data source is typed array.
  25079. rawData.clean();
  25080. }
  25081. this._rawCount = this._count = end; // Reset data extent
  25082. this._extent = {};
  25083. prepareInvertedIndex(this);
  25084. };
  25085. function prepareChunks(storage, dimInfo, chunkSize, chunkCount, end) {
  25086. var DataCtor = dataCtors[dimInfo.type];
  25087. var lastChunkIndex = chunkCount - 1;
  25088. var dim = dimInfo.name;
  25089. var resizeChunkArray = storage[dim][lastChunkIndex];
  25090. if (resizeChunkArray && resizeChunkArray.length < chunkSize) {
  25091. var newStore = new DataCtor(Math.min(end - lastChunkIndex * chunkSize, chunkSize)); // The cost of the copy is probably inconsiderable
  25092. // within the initial chunkSize.
  25093. for (var j = 0; j < resizeChunkArray.length; j++) {
  25094. newStore[j] = resizeChunkArray[j];
  25095. }
  25096. storage[dim][lastChunkIndex] = newStore;
  25097. } // Create new chunks.
  25098. for (var k = chunkCount * chunkSize; k < end; k += chunkSize) {
  25099. storage[dim].push(new DataCtor(Math.min(end - k, chunkSize)));
  25100. }
  25101. }
  25102. function prepareInvertedIndex(list) {
  25103. var invertedIndicesMap = list._invertedIndicesMap;
  25104. each$1(invertedIndicesMap, function (invertedIndices, dim) {
  25105. var dimInfo = list._dimensionInfos[dim]; // Currently, only dimensions that has ordinalMeta can create inverted indices.
  25106. var ordinalMeta = dimInfo.ordinalMeta;
  25107. if (ordinalMeta) {
  25108. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array(ordinalMeta.categories.length); // The default value of TypedArray is 0. To avoid miss
  25109. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  25110. for (var i = 0; i < invertedIndices.length; i++) {
  25111. invertedIndices[i] = INDEX_NOT_FOUND;
  25112. }
  25113. for (var i = 0; i < list._count; i++) {
  25114. // Only support the case that all values are distinct.
  25115. invertedIndices[list.get(dim, i)] = i;
  25116. }
  25117. }
  25118. });
  25119. }
  25120. function getRawValueFromStore(list, dimIndex, rawIndex) {
  25121. var val;
  25122. if (dimIndex != null) {
  25123. var chunkSize = list._chunkSize;
  25124. var chunkIndex = Math.floor(rawIndex / chunkSize);
  25125. var chunkOffset = rawIndex % chunkSize;
  25126. var dim = list.dimensions[dimIndex];
  25127. var chunk = list._storage[dim][chunkIndex];
  25128. if (chunk) {
  25129. val = chunk[chunkOffset];
  25130. var ordinalMeta = list._dimensionInfos[dim].ordinalMeta;
  25131. if (ordinalMeta && ordinalMeta.categories.length) {
  25132. val = ordinalMeta.categories[val];
  25133. }
  25134. }
  25135. }
  25136. return val;
  25137. }
  25138. /**
  25139. * @return {number}
  25140. */
  25141. listProto.count = function () {
  25142. return this._count;
  25143. };
  25144. listProto.getIndices = function () {
  25145. var newIndices;
  25146. var indices = this._indices;
  25147. if (indices) {
  25148. var Ctor = indices.constructor;
  25149. var thisCount = this._count; // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  25150. if (Ctor === Array) {
  25151. newIndices = new Ctor(thisCount);
  25152. for (var i = 0; i < thisCount; i++) {
  25153. newIndices[i] = indices[i];
  25154. }
  25155. } else {
  25156. newIndices = new Ctor(indices.buffer, 0, thisCount);
  25157. }
  25158. } else {
  25159. var Ctor = getIndicesCtor(this);
  25160. var newIndices = new Ctor(this.count());
  25161. for (var i = 0; i < newIndices.length; i++) {
  25162. newIndices[i] = i;
  25163. }
  25164. }
  25165. return newIndices;
  25166. };
  25167. /**
  25168. * Get value. Return NaN if idx is out of range.
  25169. * @param {string} dim Dim must be concrete name.
  25170. * @param {number} idx
  25171. * @param {boolean} stack
  25172. * @return {number}
  25173. */
  25174. listProto.get = function (dim, idx
  25175. /*, stack */
  25176. ) {
  25177. if (!(idx >= 0 && idx < this._count)) {
  25178. return NaN;
  25179. }
  25180. var storage = this._storage;
  25181. if (!storage[dim]) {
  25182. // TODO Warn ?
  25183. return NaN;
  25184. }
  25185. idx = this.getRawIndex(idx);
  25186. var chunkIndex = Math.floor(idx / this._chunkSize);
  25187. var chunkOffset = idx % this._chunkSize;
  25188. var chunkStore = storage[dim][chunkIndex];
  25189. var value = chunkStore[chunkOffset]; // FIXME ordinal data type is not stackable
  25190. // if (stack) {
  25191. // var dimensionInfo = this._dimensionInfos[dim];
  25192. // if (dimensionInfo && dimensionInfo.stackable) {
  25193. // var stackedOn = this.stackedOn;
  25194. // while (stackedOn) {
  25195. // // Get no stacked data of stacked on
  25196. // var stackedValue = stackedOn.get(dim, idx);
  25197. // // Considering positive stack, negative stack and empty data
  25198. // if ((value >= 0 && stackedValue > 0) // Positive stack
  25199. // || (value <= 0 && stackedValue < 0) // Negative stack
  25200. // ) {
  25201. // value += stackedValue;
  25202. // }
  25203. // stackedOn = stackedOn.stackedOn;
  25204. // }
  25205. // }
  25206. // }
  25207. return value;
  25208. };
  25209. /**
  25210. * @param {string} dim concrete dim
  25211. * @param {number} rawIndex
  25212. * @return {number|string}
  25213. */
  25214. listProto.getByRawIndex = function (dim, rawIdx) {
  25215. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  25216. return NaN;
  25217. }
  25218. var dimStore = this._storage[dim];
  25219. if (!dimStore) {
  25220. // TODO Warn ?
  25221. return NaN;
  25222. }
  25223. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  25224. var chunkOffset = rawIdx % this._chunkSize;
  25225. var chunkStore = dimStore[chunkIndex];
  25226. return chunkStore[chunkOffset];
  25227. };
  25228. /**
  25229. * FIXME Use `get` on chrome maybe slow(in filterSelf and selectRange).
  25230. * Hack a much simpler _getFast
  25231. * @private
  25232. */
  25233. listProto._getFast = function (dim, rawIdx) {
  25234. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  25235. var chunkOffset = rawIdx % this._chunkSize;
  25236. var chunkStore = this._storage[dim][chunkIndex];
  25237. return chunkStore[chunkOffset];
  25238. };
  25239. /**
  25240. * Get value for multi dimensions.
  25241. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  25242. * @param {number} idx
  25243. * @return {number}
  25244. */
  25245. listProto.getValues = function (dimensions, idx
  25246. /*, stack */
  25247. ) {
  25248. var values = [];
  25249. if (!isArray(dimensions)) {
  25250. // stack = idx;
  25251. idx = dimensions;
  25252. dimensions = this.dimensions;
  25253. }
  25254. for (var i = 0, len = dimensions.length; i < len; i++) {
  25255. values.push(this.get(dimensions[i], idx
  25256. /*, stack */
  25257. ));
  25258. }
  25259. return values;
  25260. };
  25261. /**
  25262. * If value is NaN. Inlcuding '-'
  25263. * Only check the coord dimensions.
  25264. * @param {string} dim
  25265. * @param {number} idx
  25266. * @return {number}
  25267. */
  25268. listProto.hasValue = function (idx) {
  25269. var dataDimsOnCoord = this._dimensionsSummary.dataDimsOnCoord;
  25270. for (var i = 0, len = dataDimsOnCoord.length; i < len; i++) {
  25271. // Ordinal type originally can be string or number.
  25272. // But when an ordinal type is used on coord, it can
  25273. // not be string but only number. So we can also use isNaN.
  25274. if (isNaN(this.get(dataDimsOnCoord[i], idx))) {
  25275. return false;
  25276. }
  25277. }
  25278. return true;
  25279. };
  25280. /**
  25281. * Get extent of data in one dimension
  25282. * @param {string} dim
  25283. * @param {boolean} stack
  25284. */
  25285. listProto.getDataExtent = function (dim
  25286. /*, stack */
  25287. ) {
  25288. // Make sure use concrete dim as cache name.
  25289. dim = this.getDimension(dim);
  25290. var dimData = this._storage[dim];
  25291. var initialExtent = getInitialExtent(); // stack = !!((stack || false) && this.getCalculationInfo(dim));
  25292. if (!dimData) {
  25293. return initialExtent;
  25294. } // Make more strict checkings to ensure hitting cache.
  25295. var currEnd = this.count(); // var cacheName = [dim, !!stack].join('_');
  25296. // var cacheName = dim;
  25297. // Consider the most cases when using data zoom, `getDataExtent`
  25298. // happened before filtering. We cache raw extent, which is not
  25299. // necessary to be cleared and recalculated when restore data.
  25300. var useRaw = !this._indices; // && !stack;
  25301. var dimExtent;
  25302. if (useRaw) {
  25303. return this._rawExtent[dim].slice();
  25304. }
  25305. dimExtent = this._extent[dim];
  25306. if (dimExtent) {
  25307. return dimExtent.slice();
  25308. }
  25309. dimExtent = initialExtent;
  25310. var min = dimExtent[0];
  25311. var max = dimExtent[1];
  25312. for (var i = 0; i < currEnd; i++) {
  25313. // var value = stack ? this.get(dim, i, true) : this._getFast(dim, this.getRawIndex(i));
  25314. var value = this._getFast(dim, this.getRawIndex(i));
  25315. value < min && (min = value);
  25316. value > max && (max = value);
  25317. }
  25318. dimExtent = [min, max];
  25319. this._extent[dim] = dimExtent;
  25320. return dimExtent;
  25321. };
  25322. /**
  25323. * Optimize for the scenario that data is filtered by a given extent.
  25324. * Consider that if data amount is more than hundreds of thousand,
  25325. * extent calculation will cost more than 10ms and the cache will
  25326. * be erased because of the filtering.
  25327. */
  25328. listProto.getApproximateExtent = function (dim
  25329. /*, stack */
  25330. ) {
  25331. dim = this.getDimension(dim);
  25332. return this._approximateExtent[dim] || this.getDataExtent(dim
  25333. /*, stack */
  25334. );
  25335. };
  25336. listProto.setApproximateExtent = function (extent, dim
  25337. /*, stack */
  25338. ) {
  25339. dim = this.getDimension(dim);
  25340. this._approximateExtent[dim] = extent.slice();
  25341. };
  25342. /**
  25343. * @param {string} key
  25344. * @return {*}
  25345. */
  25346. listProto.getCalculationInfo = function (key) {
  25347. return this._calculationInfo[key];
  25348. };
  25349. /**
  25350. * @param {string|Object} key or k-v object
  25351. * @param {*} [value]
  25352. */
  25353. listProto.setCalculationInfo = function (key, value) {
  25354. isObject$4(key) ? extend(this._calculationInfo, key) : this._calculationInfo[key] = value;
  25355. };
  25356. /**
  25357. * Get sum of data in one dimension
  25358. * @param {string} dim
  25359. */
  25360. listProto.getSum = function (dim
  25361. /*, stack */
  25362. ) {
  25363. var dimData = this._storage[dim];
  25364. var sum = 0;
  25365. if (dimData) {
  25366. for (var i = 0, len = this.count(); i < len; i++) {
  25367. var value = this.get(dim, i
  25368. /*, stack */
  25369. );
  25370. if (!isNaN(value)) {
  25371. sum += value;
  25372. }
  25373. }
  25374. }
  25375. return sum;
  25376. };
  25377. /**
  25378. * Get median of data in one dimension
  25379. * @param {string} dim
  25380. */
  25381. listProto.getMedian = function (dim
  25382. /*, stack */
  25383. ) {
  25384. var dimDataArray = []; // map all data of one dimension
  25385. this.each(dim, function (val, idx) {
  25386. if (!isNaN(val)) {
  25387. dimDataArray.push(val);
  25388. }
  25389. }); // TODO
  25390. // Use quick select?
  25391. // immutability & sort
  25392. var sortedDimDataArray = [].concat(dimDataArray).sort(function (a, b) {
  25393. return a - b;
  25394. });
  25395. var len = this.count(); // calculate median
  25396. return len === 0 ? 0 : len % 2 === 1 ? sortedDimDataArray[(len - 1) / 2] : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  25397. }; // /**
  25398. // * Retreive the index with given value
  25399. // * @param {string} dim Concrete dimension.
  25400. // * @param {number} value
  25401. // * @return {number}
  25402. // */
  25403. // Currently incorrect: should return dataIndex but not rawIndex.
  25404. // Do not fix it until this method is to be used somewhere.
  25405. // FIXME Precision of float value
  25406. // listProto.indexOf = function (dim, value) {
  25407. // var storage = this._storage;
  25408. // var dimData = storage[dim];
  25409. // var chunkSize = this._chunkSize;
  25410. // if (dimData) {
  25411. // for (var i = 0, len = this.count(); i < len; i++) {
  25412. // var chunkIndex = Math.floor(i / chunkSize);
  25413. // var chunkOffset = i % chunkSize;
  25414. // if (dimData[chunkIndex][chunkOffset] === value) {
  25415. // return i;
  25416. // }
  25417. // }
  25418. // }
  25419. // return -1;
  25420. // };
  25421. /**
  25422. * Only support the dimension which inverted index created.
  25423. * Do not support other cases until required.
  25424. * @param {string} concrete dim
  25425. * @param {number|string} value
  25426. * @return {number} rawIndex
  25427. */
  25428. listProto.rawIndexOf = function (dim, value) {
  25429. var invertedIndices = dim && this._invertedIndicesMap[dim];
  25430. if (__DEV__) {
  25431. if (!invertedIndices) {
  25432. throw new Error('Do not supported yet');
  25433. }
  25434. }
  25435. var rawIndex = invertedIndices[value];
  25436. if (rawIndex == null || isNaN(rawIndex)) {
  25437. return INDEX_NOT_FOUND;
  25438. }
  25439. return rawIndex;
  25440. };
  25441. /**
  25442. * Retreive the index with given name
  25443. * @param {number} idx
  25444. * @param {number} name
  25445. * @return {number}
  25446. */
  25447. listProto.indexOfName = function (name) {
  25448. for (var i = 0, len = this.count(); i < len; i++) {
  25449. if (this.getName(i) === name) {
  25450. return i;
  25451. }
  25452. }
  25453. return -1;
  25454. };
  25455. /**
  25456. * Retreive the index with given raw data index
  25457. * @param {number} idx
  25458. * @param {number} name
  25459. * @return {number}
  25460. */
  25461. listProto.indexOfRawIndex = function (rawIndex) {
  25462. if (rawIndex >= this._rawCount || rawIndex < 0) {
  25463. return -1;
  25464. }
  25465. if (!this._indices) {
  25466. return rawIndex;
  25467. } // Indices are ascending
  25468. var indices = this._indices; // If rawIndex === dataIndex
  25469. var rawDataIndex = indices[rawIndex];
  25470. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  25471. return rawIndex;
  25472. }
  25473. var left = 0;
  25474. var right = this._count - 1;
  25475. while (left <= right) {
  25476. var mid = (left + right) / 2 | 0;
  25477. if (indices[mid] < rawIndex) {
  25478. left = mid + 1;
  25479. } else if (indices[mid] > rawIndex) {
  25480. right = mid - 1;
  25481. } else {
  25482. return mid;
  25483. }
  25484. }
  25485. return -1;
  25486. };
  25487. /**
  25488. * Retreive the index of nearest value
  25489. * @param {string} dim
  25490. * @param {number} value
  25491. * @param {number} [maxDistance=Infinity]
  25492. * @return {Array.<number>} If and only if multiple indices has
  25493. * the same value, they are put to the result.
  25494. */
  25495. listProto.indicesOfNearest = function (dim, value, maxDistance) {
  25496. var storage = this._storage;
  25497. var dimData = storage[dim];
  25498. var nearestIndices = [];
  25499. if (!dimData) {
  25500. return nearestIndices;
  25501. }
  25502. if (maxDistance == null) {
  25503. maxDistance = Infinity;
  25504. }
  25505. var minDist = Infinity;
  25506. var minDiff = -1;
  25507. var nearestIndicesLen = 0; // Check the test case of `test/ut/spec/data/List.js`.
  25508. for (var i = 0, len = this.count(); i < len; i++) {
  25509. var diff = value - this.get(dim, i);
  25510. var dist = Math.abs(diff);
  25511. if (dist <= maxDistance) {
  25512. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  25513. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  25514. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  25515. // So we chose the one that `diff >= 0` in this csae.
  25516. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  25517. // should be push to `nearestIndices`.
  25518. if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
  25519. minDist = dist;
  25520. minDiff = diff;
  25521. nearestIndicesLen = 0;
  25522. }
  25523. if (diff === minDiff) {
  25524. nearestIndices[nearestIndicesLen++] = i;
  25525. }
  25526. }
  25527. }
  25528. nearestIndices.length = nearestIndicesLen;
  25529. return nearestIndices;
  25530. };
  25531. /**
  25532. * Get raw data index
  25533. * @param {number} idx
  25534. * @return {number}
  25535. */
  25536. listProto.getRawIndex = getRawIndexWithoutIndices;
  25537. function getRawIndexWithoutIndices(idx) {
  25538. return idx;
  25539. }
  25540. function getRawIndexWithIndices(idx) {
  25541. if (idx < this._count && idx >= 0) {
  25542. return this._indices[idx];
  25543. }
  25544. return -1;
  25545. }
  25546. /**
  25547. * Get raw data item
  25548. * @param {number} idx
  25549. * @return {number}
  25550. */
  25551. listProto.getRawDataItem = function (idx) {
  25552. if (!this._rawData.persistent) {
  25553. var val = [];
  25554. for (var i = 0; i < this.dimensions.length; i++) {
  25555. var dim = this.dimensions[i];
  25556. val.push(this.get(dim, idx));
  25557. }
  25558. return val;
  25559. } else {
  25560. return this._rawData.getItem(this.getRawIndex(idx));
  25561. }
  25562. };
  25563. /**
  25564. * @param {number} idx
  25565. * @param {boolean} [notDefaultIdx=false]
  25566. * @return {string}
  25567. */
  25568. listProto.getName = function (idx) {
  25569. var rawIndex = this.getRawIndex(idx);
  25570. return this._nameList[rawIndex] || getRawValueFromStore(this, this._nameDimIdx, rawIndex) || '';
  25571. };
  25572. /**
  25573. * @param {number} idx
  25574. * @param {boolean} [notDefaultIdx=false]
  25575. * @return {string}
  25576. */
  25577. listProto.getId = function (idx) {
  25578. return getId(this, this.getRawIndex(idx));
  25579. };
  25580. function getId(list, rawIndex) {
  25581. var id = list._idList[rawIndex];
  25582. if (id == null) {
  25583. id = getRawValueFromStore(list, list._idDimIdx, rawIndex);
  25584. }
  25585. if (id == null) {
  25586. // FIXME Check the usage in graph, should not use prefix.
  25587. id = ID_PREFIX + rawIndex;
  25588. }
  25589. return id;
  25590. }
  25591. function normalizeDimensions(dimensions) {
  25592. if (!isArray(dimensions)) {
  25593. dimensions = [dimensions];
  25594. }
  25595. return dimensions;
  25596. }
  25597. function validateDimensions(list, dims) {
  25598. for (var i = 0; i < dims.length; i++) {
  25599. // stroage may be empty when no data, so use
  25600. // dimensionInfos to check.
  25601. if (!list._dimensionInfos[dims[i]]) {
  25602. console.error('Unkown dimension ' + dims[i]);
  25603. }
  25604. }
  25605. }
  25606. /**
  25607. * Data iteration
  25608. * @param {string|Array.<string>}
  25609. * @param {Function} cb
  25610. * @param {*} [context=this]
  25611. *
  25612. * @example
  25613. * list.each('x', function (x, idx) {});
  25614. * list.each(['x', 'y'], function (x, y, idx) {});
  25615. * list.each(function (idx) {})
  25616. */
  25617. listProto.each = function (dims, cb, context, contextCompat) {
  25618. 'use strict';
  25619. if (!this._count) {
  25620. return;
  25621. }
  25622. if (typeof dims === 'function') {
  25623. contextCompat = context;
  25624. context = cb;
  25625. cb = dims;
  25626. dims = [];
  25627. } // contextCompat just for compat echarts3
  25628. context = context || contextCompat || this;
  25629. dims = map(normalizeDimensions(dims), this.getDimension, this);
  25630. if (__DEV__) {
  25631. validateDimensions(this, dims);
  25632. }
  25633. var dimSize = dims.length;
  25634. for (var i = 0; i < this.count(); i++) {
  25635. // Simple optimization
  25636. switch (dimSize) {
  25637. case 0:
  25638. cb.call(context, i);
  25639. break;
  25640. case 1:
  25641. cb.call(context, this.get(dims[0], i), i);
  25642. break;
  25643. case 2:
  25644. cb.call(context, this.get(dims[0], i), this.get(dims[1], i), i);
  25645. break;
  25646. default:
  25647. var k = 0;
  25648. var value = [];
  25649. for (; k < dimSize; k++) {
  25650. value[k] = this.get(dims[k], i);
  25651. } // Index
  25652. value[k] = i;
  25653. cb.apply(context, value);
  25654. }
  25655. }
  25656. };
  25657. /**
  25658. * Data filter
  25659. * @param {string|Array.<string>}
  25660. * @param {Function} cb
  25661. * @param {*} [context=this]
  25662. */
  25663. listProto.filterSelf = function (dimensions, cb, context, contextCompat) {
  25664. 'use strict';
  25665. if (!this._count) {
  25666. return;
  25667. }
  25668. if (typeof dimensions === 'function') {
  25669. contextCompat = context;
  25670. context = cb;
  25671. cb = dimensions;
  25672. dimensions = [];
  25673. } // contextCompat just for compat echarts3
  25674. context = context || contextCompat || this;
  25675. dimensions = map(normalizeDimensions(dimensions), this.getDimension, this);
  25676. if (__DEV__) {
  25677. validateDimensions(this, dimensions);
  25678. }
  25679. var count = this.count();
  25680. var Ctor = getIndicesCtor(this);
  25681. var newIndices = new Ctor(count);
  25682. var value = [];
  25683. var dimSize = dimensions.length;
  25684. var offset = 0;
  25685. var dim0 = dimensions[0];
  25686. for (var i = 0; i < count; i++) {
  25687. var keep;
  25688. var rawIdx = this.getRawIndex(i); // Simple optimization
  25689. if (dimSize === 0) {
  25690. keep = cb.call(context, i);
  25691. } else if (dimSize === 1) {
  25692. var val = this._getFast(dim0, rawIdx);
  25693. keep = cb.call(context, val, i);
  25694. } else {
  25695. for (var k = 0; k < dimSize; k++) {
  25696. value[k] = this._getFast(dim0, rawIdx);
  25697. }
  25698. value[k] = i;
  25699. keep = cb.apply(context, value);
  25700. }
  25701. if (keep) {
  25702. newIndices[offset++] = rawIdx;
  25703. }
  25704. } // Set indices after filtered.
  25705. if (offset < count) {
  25706. this._indices = newIndices;
  25707. }
  25708. this._count = offset; // Reset data extent
  25709. this._extent = {};
  25710. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  25711. return this;
  25712. };
  25713. /**
  25714. * Select data in range. (For optimization of filter)
  25715. * (Manually inline code, support 5 million data filtering in data zoom.)
  25716. */
  25717. listProto.selectRange = function (range) {
  25718. 'use strict';
  25719. if (!this._count) {
  25720. return;
  25721. }
  25722. var dimensions = [];
  25723. for (var dim in range) {
  25724. if (range.hasOwnProperty(dim)) {
  25725. dimensions.push(dim);
  25726. }
  25727. }
  25728. if (__DEV__) {
  25729. validateDimensions(this, dimensions);
  25730. }
  25731. var dimSize = dimensions.length;
  25732. if (!dimSize) {
  25733. return;
  25734. }
  25735. var originalCount = this.count();
  25736. var Ctor = getIndicesCtor(this);
  25737. var newIndices = new Ctor(originalCount);
  25738. var offset = 0;
  25739. var dim0 = dimensions[0];
  25740. var min = range[dim0][0];
  25741. var max = range[dim0][1];
  25742. var quickFinished = false;
  25743. if (!this._indices) {
  25744. // Extreme optimization for common case. About 2x faster in chrome.
  25745. var idx = 0;
  25746. if (dimSize === 1) {
  25747. var dimStorage = this._storage[dimensions[0]];
  25748. for (var k = 0; k < this._chunkCount; k++) {
  25749. var chunkStorage = dimStorage[k];
  25750. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  25751. for (var i = 0; i < len; i++) {
  25752. var val = chunkStorage[i]; // NaN will not be filtered. Consider the case, in line chart, empty
  25753. // value indicates the line should be broken. But for the case like
  25754. // scatter plot, a data item with empty value will not be rendered,
  25755. // but the axis extent may be effected if some other dim of the data
  25756. // item has value. Fortunately it is not a significant negative effect.
  25757. if (val >= min && val <= max || isNaN(val)) {
  25758. newIndices[offset++] = idx;
  25759. }
  25760. idx++;
  25761. }
  25762. }
  25763. quickFinished = true;
  25764. } else if (dimSize === 2) {
  25765. var dimStorage = this._storage[dim0];
  25766. var dimStorage2 = this._storage[dimensions[1]];
  25767. var min2 = range[dimensions[1]][0];
  25768. var max2 = range[dimensions[1]][1];
  25769. for (var k = 0; k < this._chunkCount; k++) {
  25770. var chunkStorage = dimStorage[k];
  25771. var chunkStorage2 = dimStorage2[k];
  25772. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  25773. for (var i = 0; i < len; i++) {
  25774. var val = chunkStorage[i];
  25775. var val2 = chunkStorage2[i]; // Do not filter NaN, see comment above.
  25776. if ((val >= min && val <= max || isNaN(val)) && (val2 >= min2 && val2 <= max2 || isNaN(val2))) {
  25777. newIndices[offset++] = idx;
  25778. }
  25779. idx++;
  25780. }
  25781. }
  25782. quickFinished = true;
  25783. }
  25784. }
  25785. if (!quickFinished) {
  25786. if (dimSize === 1) {
  25787. for (var i = 0; i < originalCount; i++) {
  25788. var rawIndex = this.getRawIndex(i);
  25789. var val = this._getFast(dim0, rawIndex); // Do not filter NaN, see comment above.
  25790. if (val >= min && val <= max || isNaN(val)) {
  25791. newIndices[offset++] = rawIndex;
  25792. }
  25793. }
  25794. } else {
  25795. for (var i = 0; i < originalCount; i++) {
  25796. var keep = true;
  25797. var rawIndex = this.getRawIndex(i);
  25798. for (var k = 0; k < dimSize; k++) {
  25799. var dimk = dimensions[k];
  25800. var val = this._getFast(dim, rawIndex); // Do not filter NaN, see comment above.
  25801. if (val < range[dimk][0] || val > range[dimk][1]) {
  25802. keep = false;
  25803. }
  25804. }
  25805. if (keep) {
  25806. newIndices[offset++] = this.getRawIndex(i);
  25807. }
  25808. }
  25809. }
  25810. } // Set indices after filtered.
  25811. if (offset < originalCount) {
  25812. this._indices = newIndices;
  25813. }
  25814. this._count = offset; // Reset data extent
  25815. this._extent = {};
  25816. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  25817. return this;
  25818. };
  25819. /**
  25820. * Data mapping to a plain array
  25821. * @param {string|Array.<string>} [dimensions]
  25822. * @param {Function} cb
  25823. * @param {*} [context=this]
  25824. * @return {Array}
  25825. */
  25826. listProto.mapArray = function (dimensions, cb, context, contextCompat) {
  25827. 'use strict';
  25828. if (typeof dimensions === 'function') {
  25829. contextCompat = context;
  25830. context = cb;
  25831. cb = dimensions;
  25832. dimensions = [];
  25833. } // contextCompat just for compat echarts3
  25834. context = context || contextCompat || this;
  25835. var result = [];
  25836. this.each(dimensions, function () {
  25837. result.push(cb && cb.apply(this, arguments));
  25838. }, context);
  25839. return result;
  25840. }; // Data in excludeDimensions is copied, otherwise transfered.
  25841. function cloneListForMapAndSample(original, excludeDimensions) {
  25842. var allDimensions = original.dimensions;
  25843. var list = new List(map(allDimensions, original.getDimensionInfo, original), original.hostModel); // FIXME If needs stackedOn, value may already been stacked
  25844. transferProperties(list, original);
  25845. var storage = list._storage = {};
  25846. var originalStorage = original._storage; // Init storage
  25847. for (var i = 0; i < allDimensions.length; i++) {
  25848. var dim = allDimensions[i];
  25849. if (originalStorage[dim]) {
  25850. // Notice that we do not reset invertedIndicesMap here, becuase
  25851. // there is no scenario of mapping or sampling ordinal dimension.
  25852. if (indexOf(excludeDimensions, dim) >= 0) {
  25853. storage[dim] = cloneDimStore(originalStorage[dim]);
  25854. list._rawExtent[dim] = getInitialExtent();
  25855. list._extent[dim] = null;
  25856. } else {
  25857. // Direct reference for other dimensions
  25858. storage[dim] = originalStorage[dim];
  25859. }
  25860. }
  25861. }
  25862. return list;
  25863. }
  25864. function cloneDimStore(originalDimStore) {
  25865. var newDimStore = new Array(originalDimStore.length);
  25866. for (var j = 0; j < originalDimStore.length; j++) {
  25867. newDimStore[j] = cloneChunk(originalDimStore[j]);
  25868. }
  25869. return newDimStore;
  25870. }
  25871. function getInitialExtent() {
  25872. return [Infinity, -Infinity];
  25873. }
  25874. /**
  25875. * Data mapping to a new List with given dimensions
  25876. * @param {string|Array.<string>} dimensions
  25877. * @param {Function} cb
  25878. * @param {*} [context=this]
  25879. * @return {Array}
  25880. */
  25881. listProto.map = function (dimensions, cb, context, contextCompat) {
  25882. 'use strict'; // contextCompat just for compat echarts3
  25883. context = context || contextCompat || this;
  25884. dimensions = map(normalizeDimensions(dimensions), this.getDimension, this);
  25885. if (__DEV__) {
  25886. validateDimensions(this, dimensions);
  25887. }
  25888. var list = cloneListForMapAndSample(this, dimensions); // Following properties are all immutable.
  25889. // So we can reference to the same value
  25890. list._indices = this._indices;
  25891. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  25892. var storage = list._storage;
  25893. var tmpRetValue = [];
  25894. var chunkSize = this._chunkSize;
  25895. var dimSize = dimensions.length;
  25896. var dataCount = this.count();
  25897. var values = [];
  25898. var rawExtent = list._rawExtent;
  25899. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  25900. for (var dimIndex = 0; dimIndex < dimSize; dimIndex++) {
  25901. values[dimIndex] = this.get(dimensions[dimIndex], dataIndex
  25902. /*, stack */
  25903. );
  25904. }
  25905. values[dimSize] = dataIndex;
  25906. var retValue = cb && cb.apply(context, values);
  25907. if (retValue != null) {
  25908. // a number or string (in oridinal dimension)?
  25909. if (typeof retValue !== 'object') {
  25910. tmpRetValue[0] = retValue;
  25911. retValue = tmpRetValue;
  25912. }
  25913. var rawIndex = this.getRawIndex(dataIndex);
  25914. var chunkIndex = Math.floor(rawIndex / chunkSize);
  25915. var chunkOffset = rawIndex % chunkSize;
  25916. for (var i = 0; i < retValue.length; i++) {
  25917. var dim = dimensions[i];
  25918. var val = retValue[i];
  25919. var rawExtentOnDim = rawExtent[dim];
  25920. var dimStore = storage[dim];
  25921. if (dimStore) {
  25922. dimStore[chunkIndex][chunkOffset] = val;
  25923. }
  25924. if (val < rawExtentOnDim[0]) {
  25925. rawExtentOnDim[0] = val;
  25926. }
  25927. if (val > rawExtentOnDim[1]) {
  25928. rawExtentOnDim[1] = val;
  25929. }
  25930. }
  25931. }
  25932. }
  25933. return list;
  25934. };
  25935. /**
  25936. * Large data down sampling on given dimension
  25937. * @param {string} dimension
  25938. * @param {number} rate
  25939. * @param {Function} sampleValue
  25940. * @param {Function} sampleIndex Sample index for name and id
  25941. */
  25942. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  25943. var list = cloneListForMapAndSample(this, [dimension]);
  25944. var targetStorage = list._storage;
  25945. var frameValues = [];
  25946. var frameSize = Math.floor(1 / rate);
  25947. var dimStore = targetStorage[dimension];
  25948. var len = this.count();
  25949. var chunkSize = this._chunkSize;
  25950. var rawExtentOnDim = list._rawExtent[dimension];
  25951. var newIndices = new (getIndicesCtor(this))(len);
  25952. var offset = 0;
  25953. for (var i = 0; i < len; i += frameSize) {
  25954. // Last frame
  25955. if (frameSize > len - i) {
  25956. frameSize = len - i;
  25957. frameValues.length = frameSize;
  25958. }
  25959. for (var k = 0; k < frameSize; k++) {
  25960. var dataIdx = this.getRawIndex(i + k);
  25961. var originalChunkIndex = Math.floor(dataIdx / chunkSize);
  25962. var originalChunkOffset = dataIdx % chunkSize;
  25963. frameValues[k] = dimStore[originalChunkIndex][originalChunkOffset];
  25964. }
  25965. var value = sampleValue(frameValues);
  25966. var sampleFrameIdx = this.getRawIndex(Math.min(i + sampleIndex(frameValues, value) || 0, len - 1));
  25967. var sampleChunkIndex = Math.floor(sampleFrameIdx / chunkSize);
  25968. var sampleChunkOffset = sampleFrameIdx % chunkSize; // Only write value on the filtered data
  25969. dimStore[sampleChunkIndex][sampleChunkOffset] = value;
  25970. if (value < rawExtentOnDim[0]) {
  25971. rawExtentOnDim[0] = value;
  25972. }
  25973. if (value > rawExtentOnDim[1]) {
  25974. rawExtentOnDim[1] = value;
  25975. }
  25976. newIndices[offset++] = sampleFrameIdx;
  25977. }
  25978. list._count = offset;
  25979. list._indices = newIndices;
  25980. list.getRawIndex = getRawIndexWithIndices;
  25981. return list;
  25982. };
  25983. /**
  25984. * Get model of one data item.
  25985. *
  25986. * @param {number} idx
  25987. */
  25988. // FIXME Model proxy ?
  25989. listProto.getItemModel = function (idx) {
  25990. var hostModel = this.hostModel;
  25991. return new Model(this.getRawDataItem(idx), hostModel, hostModel && hostModel.ecModel);
  25992. };
  25993. /**
  25994. * Create a data differ
  25995. * @param {module:echarts/data/List} otherList
  25996. * @return {module:echarts/data/DataDiffer}
  25997. */
  25998. listProto.diff = function (otherList) {
  25999. var thisList = this;
  26000. return new DataDiffer(otherList ? otherList.getIndices() : [], this.getIndices(), function (idx) {
  26001. return getId(otherList, idx);
  26002. }, function (idx) {
  26003. return getId(thisList, idx);
  26004. });
  26005. };
  26006. /**
  26007. * Get visual property.
  26008. * @param {string} key
  26009. */
  26010. listProto.getVisual = function (key) {
  26011. var visual = this._visual;
  26012. return visual && visual[key];
  26013. };
  26014. /**
  26015. * Set visual property
  26016. * @param {string|Object} key
  26017. * @param {*} [value]
  26018. *
  26019. * @example
  26020. * setVisual('color', color);
  26021. * setVisual({
  26022. * 'color': color
  26023. * });
  26024. */
  26025. listProto.setVisual = function (key, val) {
  26026. if (isObject$4(key)) {
  26027. for (var name in key) {
  26028. if (key.hasOwnProperty(name)) {
  26029. this.setVisual(name, key[name]);
  26030. }
  26031. }
  26032. return;
  26033. }
  26034. this._visual = this._visual || {};
  26035. this._visual[key] = val;
  26036. };
  26037. /**
  26038. * Set layout property.
  26039. * @param {string|Object} key
  26040. * @param {*} [val]
  26041. */
  26042. listProto.setLayout = function (key, val) {
  26043. if (isObject$4(key)) {
  26044. for (var name in key) {
  26045. if (key.hasOwnProperty(name)) {
  26046. this.setLayout(name, key[name]);
  26047. }
  26048. }
  26049. return;
  26050. }
  26051. this._layout[key] = val;
  26052. };
  26053. /**
  26054. * Get layout property.
  26055. * @param {string} key.
  26056. * @return {*}
  26057. */
  26058. listProto.getLayout = function (key) {
  26059. return this._layout[key];
  26060. };
  26061. /**
  26062. * Get layout of single data item
  26063. * @param {number} idx
  26064. */
  26065. listProto.getItemLayout = function (idx) {
  26066. return this._itemLayouts[idx];
  26067. };
  26068. /**
  26069. * Set layout of single data item
  26070. * @param {number} idx
  26071. * @param {Object} layout
  26072. * @param {boolean=} [merge=false]
  26073. */
  26074. listProto.setItemLayout = function (idx, layout, merge$$1) {
  26075. this._itemLayouts[idx] = merge$$1 ? extend(this._itemLayouts[idx] || {}, layout) : layout;
  26076. };
  26077. /**
  26078. * Clear all layout of single data item
  26079. */
  26080. listProto.clearItemLayouts = function () {
  26081. this._itemLayouts.length = 0;
  26082. };
  26083. /**
  26084. * Get visual property of single data item
  26085. * @param {number} idx
  26086. * @param {string} key
  26087. * @param {boolean} [ignoreParent=false]
  26088. */
  26089. listProto.getItemVisual = function (idx, key, ignoreParent) {
  26090. var itemVisual = this._itemVisuals[idx];
  26091. var val = itemVisual && itemVisual[key];
  26092. if (val == null && !ignoreParent) {
  26093. // Use global visual property
  26094. return this.getVisual(key);
  26095. }
  26096. return val;
  26097. };
  26098. /**
  26099. * Set visual property of single data item
  26100. *
  26101. * @param {number} idx
  26102. * @param {string|Object} key
  26103. * @param {*} [value]
  26104. *
  26105. * @example
  26106. * setItemVisual(0, 'color', color);
  26107. * setItemVisual(0, {
  26108. * 'color': color
  26109. * });
  26110. */
  26111. listProto.setItemVisual = function (idx, key, value) {
  26112. var itemVisual = this._itemVisuals[idx] || {};
  26113. var hasItemVisual = this.hasItemVisual;
  26114. this._itemVisuals[idx] = itemVisual;
  26115. if (isObject$4(key)) {
  26116. for (var name in key) {
  26117. if (key.hasOwnProperty(name)) {
  26118. itemVisual[name] = key[name];
  26119. hasItemVisual[name] = true;
  26120. }
  26121. }
  26122. return;
  26123. }
  26124. itemVisual[key] = value;
  26125. hasItemVisual[key] = true;
  26126. };
  26127. /**
  26128. * Clear itemVisuals and list visual.
  26129. */
  26130. listProto.clearAllVisual = function () {
  26131. this._visual = {};
  26132. this._itemVisuals = [];
  26133. this.hasItemVisual = {};
  26134. };
  26135. var setItemDataAndSeriesIndex = function (child) {
  26136. child.seriesIndex = this.seriesIndex;
  26137. child.dataIndex = this.dataIndex;
  26138. child.dataType = this.dataType;
  26139. };
  26140. /**
  26141. * Set graphic element relative to data. It can be set as null
  26142. * @param {number} idx
  26143. * @param {module:zrender/Element} [el]
  26144. */
  26145. listProto.setItemGraphicEl = function (idx, el) {
  26146. var hostModel = this.hostModel;
  26147. if (el) {
  26148. // Add data index and series index for indexing the data by element
  26149. // Useful in tooltip
  26150. el.dataIndex = idx;
  26151. el.dataType = this.dataType;
  26152. el.seriesIndex = hostModel && hostModel.seriesIndex;
  26153. if (el.type === 'group') {
  26154. el.traverse(setItemDataAndSeriesIndex, el);
  26155. }
  26156. }
  26157. this._graphicEls[idx] = el;
  26158. };
  26159. /**
  26160. * @param {number} idx
  26161. * @return {module:zrender/Element}
  26162. */
  26163. listProto.getItemGraphicEl = function (idx) {
  26164. return this._graphicEls[idx];
  26165. };
  26166. /**
  26167. * @param {Function} cb
  26168. * @param {*} context
  26169. */
  26170. listProto.eachItemGraphicEl = function (cb, context) {
  26171. each$1(this._graphicEls, function (el, idx) {
  26172. if (el) {
  26173. cb && cb.call(context, el, idx);
  26174. }
  26175. });
  26176. };
  26177. /**
  26178. * Shallow clone a new list except visual and layout properties, and graph elements.
  26179. * New list only change the indices.
  26180. */
  26181. listProto.cloneShallow = function (list) {
  26182. if (!list) {
  26183. var dimensionInfoList = map(this.dimensions, this.getDimensionInfo, this);
  26184. list = new List(dimensionInfoList, this.hostModel);
  26185. } // FIXME
  26186. list._storage = this._storage;
  26187. transferProperties(list, this); // Clone will not change the data extent and indices
  26188. if (this._indices) {
  26189. var Ctor = this._indices.constructor;
  26190. list._indices = new Ctor(this._indices);
  26191. } else {
  26192. list._indices = null;
  26193. }
  26194. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  26195. return list;
  26196. };
  26197. /**
  26198. * Wrap some method to add more feature
  26199. * @param {string} methodName
  26200. * @param {Function} injectFunction
  26201. */
  26202. listProto.wrapMethod = function (methodName, injectFunction) {
  26203. var originalMethod = this[methodName];
  26204. if (typeof originalMethod !== 'function') {
  26205. return;
  26206. }
  26207. this.__wrappedMethods = this.__wrappedMethods || [];
  26208. this.__wrappedMethods.push(methodName);
  26209. this[methodName] = function () {
  26210. var res = originalMethod.apply(this, arguments);
  26211. return injectFunction.apply(this, [res].concat(slice(arguments)));
  26212. };
  26213. }; // Methods that create a new list based on this list should be listed here.
  26214. // Notice that those method should `RETURN` the new list.
  26215. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map']; // Methods that change indices of this list should be listed here.
  26216. listProto.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  26217. /*
  26218. * Licensed to the Apache Software Foundation (ASF) under one
  26219. * or more contributor license agreements. See the NOTICE file
  26220. * distributed with this work for additional information
  26221. * regarding copyright ownership. The ASF licenses this file
  26222. * to you under the Apache License, Version 2.0 (the
  26223. * "License"); you may not use this file except in compliance
  26224. * with the License. You may obtain a copy of the License at
  26225. *
  26226. * http://www.apache.org/licenses/LICENSE-2.0
  26227. *
  26228. * Unless required by applicable law or agreed to in writing,
  26229. * software distributed under the License is distributed on an
  26230. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26231. * KIND, either express or implied. See the License for the
  26232. * specific language governing permissions and limitations
  26233. * under the License.
  26234. */
  26235. /**
  26236. * @deprecated
  26237. * Use `echarts/data/helper/createDimensions` instead.
  26238. */
  26239. /**
  26240. * @see {module:echarts/test/ut/spec/data/completeDimensions}
  26241. *
  26242. * This method builds the relationship between:
  26243. * + "what the coord sys or series requires (see `sysDims`)",
  26244. * + "what the user defines (in `encode` and `dimensions`, see `opt.dimsDef` and `opt.encodeDef`)"
  26245. * + "what the data source provids (see `source`)".
  26246. *
  26247. * Some guess strategy will be adapted if user does not define something.
  26248. * If no 'value' dimension specified, the first no-named dimension will be
  26249. * named as 'value'.
  26250. *
  26251. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  26252. * provides not only dim template, but also default order.
  26253. * properties: 'name', 'type', 'displayName'.
  26254. * `name` of each item provides default coord name.
  26255. * [{dimsDef: [string|Object, ...]}, ...] dimsDef of sysDim item provides default dim name, and
  26256. * provide dims count that the sysDim required.
  26257. * [{ordinalMeta}] can be specified.
  26258. * @param {module:echarts/data/Source|Array|Object} source or data (for compatibal with pervious)
  26259. * @param {Object} [opt]
  26260. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  26261. * For example: ['asdf', {name, type}, ...].
  26262. * @param {Object|HashMap} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  26263. * @param {Function} [opt.encodeDefaulter] Called if no `opt.encodeDef` exists.
  26264. * If not specified, auto find the next available data dim.
  26265. * param source {module:data/Source}
  26266. * param dimCount {number}
  26267. * return {Object} encode Never be `null/undefined`.
  26268. * @param {string} [opt.generateCoord] Generate coord dim with the given name.
  26269. * If not specified, extra dim names will be:
  26270. * 'value', 'value0', 'value1', ...
  26271. * @param {number} [opt.generateCoordCount] By default, the generated dim name is `generateCoord`.
  26272. * If `generateCoordCount` specified, the generated dim names will be:
  26273. * `generateCoord` + 0, `generateCoord` + 1, ...
  26274. * can be Infinity, indicate that use all of the remain columns.
  26275. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  26276. * @return {Array.<module:data/DataDimensionInfo>}
  26277. */
  26278. function completeDimensions(sysDims, source, opt) {
  26279. if (!Source.isInstance(source)) {
  26280. source = Source.seriesDataToSource(source);
  26281. }
  26282. opt = opt || {};
  26283. sysDims = (sysDims || []).slice();
  26284. var dimsDef = (opt.dimsDef || []).slice();
  26285. var dataDimNameMap = createHashMap();
  26286. var coordDimNameMap = createHashMap(); // var valueCandidate;
  26287. var result = [];
  26288. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimCount); // Apply user defined dims (`name` and `type`) and init result.
  26289. for (var i = 0; i < dimCount; i++) {
  26290. var dimDefItem = dimsDef[i] = extend({}, isObject$1(dimsDef[i]) ? dimsDef[i] : {
  26291. name: dimsDef[i]
  26292. });
  26293. var userDimName = dimDefItem.name;
  26294. var resultItem = result[i] = new DataDimensionInfo(); // Name will be applied later for avoiding duplication.
  26295. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  26296. // Only if `series.dimensions` is defined in option
  26297. // displayName, will be set, and dimension will be diplayed vertically in
  26298. // tooltip by default.
  26299. resultItem.name = resultItem.displayName = userDimName;
  26300. dataDimNameMap.set(userDimName, i);
  26301. }
  26302. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  26303. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  26304. }
  26305. var encodeDef = opt.encodeDef;
  26306. if (!encodeDef && opt.encodeDefaulter) {
  26307. encodeDef = opt.encodeDefaulter(source, dimCount);
  26308. }
  26309. encodeDef = createHashMap(encodeDef); // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  26310. encodeDef.each(function (dataDims, coordDim) {
  26311. dataDims = normalizeToArray(dataDims).slice(); // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  26312. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  26313. // this case.
  26314. if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
  26315. encodeDef.set(coordDim, false);
  26316. return;
  26317. }
  26318. var validDataDims = encodeDef.set(coordDim, []);
  26319. each$1(dataDims, function (resultDimIdx, idx) {
  26320. // The input resultDimIdx can be dim name or index.
  26321. isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  26322. if (resultDimIdx != null && resultDimIdx < dimCount) {
  26323. validDataDims[idx] = resultDimIdx;
  26324. applyDim(result[resultDimIdx], coordDim, idx);
  26325. }
  26326. });
  26327. }); // Apply templetes and default order from `sysDims`.
  26328. var availDimIdx = 0;
  26329. each$1(sysDims, function (sysDimItem, sysDimIndex) {
  26330. var coordDim;
  26331. var sysDimItem;
  26332. var sysDimItemDimsDef;
  26333. var sysDimItemOtherDims;
  26334. if (isString(sysDimItem)) {
  26335. coordDim = sysDimItem;
  26336. sysDimItem = {};
  26337. } else {
  26338. coordDim = sysDimItem.name;
  26339. var ordinalMeta = sysDimItem.ordinalMeta;
  26340. sysDimItem.ordinalMeta = null;
  26341. sysDimItem = clone(sysDimItem);
  26342. sysDimItem.ordinalMeta = ordinalMeta; // `coordDimIndex` should not be set directly.
  26343. sysDimItemDimsDef = sysDimItem.dimsDef;
  26344. sysDimItemOtherDims = sysDimItem.otherDims;
  26345. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  26346. }
  26347. var dataDims = encodeDef.get(coordDim); // negative resultDimIdx means no need to mapping.
  26348. if (dataDims === false) {
  26349. return;
  26350. }
  26351. var dataDims = normalizeToArray(dataDims); // dimensions provides default dim sequences.
  26352. if (!dataDims.length) {
  26353. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  26354. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  26355. availDimIdx++;
  26356. }
  26357. availDimIdx < result.length && dataDims.push(availDimIdx++);
  26358. }
  26359. } // Apply templates.
  26360. each$1(dataDims, function (resultDimIdx, coordDimIndex) {
  26361. var resultItem = result[resultDimIdx];
  26362. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  26363. if (resultItem.name == null && sysDimItemDimsDef) {
  26364. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  26365. !isObject$1(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {
  26366. name: sysDimItemDimsDefItem
  26367. });
  26368. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  26369. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  26370. } // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  26371. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  26372. });
  26373. });
  26374. function applyDim(resultItem, coordDim, coordDimIndex) {
  26375. if (OTHER_DIMENSIONS.get(coordDim) != null) {
  26376. resultItem.otherDims[coordDim] = coordDimIndex;
  26377. } else {
  26378. resultItem.coordDim = coordDim;
  26379. resultItem.coordDimIndex = coordDimIndex;
  26380. coordDimNameMap.set(coordDim, true);
  26381. }
  26382. } // Make sure the first extra dim is 'value'.
  26383. var generateCoord = opt.generateCoord;
  26384. var generateCoordCount = opt.generateCoordCount;
  26385. var fromZero = generateCoordCount != null;
  26386. generateCoordCount = generateCoord ? generateCoordCount || 1 : 0;
  26387. var extra = generateCoord || 'value'; // Set dim `name` and other `coordDim` and other props.
  26388. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  26389. var resultItem = result[resultDimIdx] = result[resultDimIdx] || new DataDimensionInfo();
  26390. var coordDim = resultItem.coordDim;
  26391. if (coordDim == null) {
  26392. resultItem.coordDim = genName(extra, coordDimNameMap, fromZero);
  26393. resultItem.coordDimIndex = 0;
  26394. if (!generateCoord || generateCoordCount <= 0) {
  26395. resultItem.isExtraCoord = true;
  26396. }
  26397. generateCoordCount--;
  26398. }
  26399. resultItem.name == null && (resultItem.name = genName(resultItem.coordDim, dataDimNameMap));
  26400. if (resultItem.type == null && (guessOrdinal(source, resultDimIdx, resultItem.name) === BE_ORDINAL.Must // Consider the case:
  26401. // {
  26402. // dataset: {source: [
  26403. // ['2001', 123],
  26404. // ['2002', 456],
  26405. // ...
  26406. // ['The others', 987],
  26407. // ]},
  26408. // series: {type: 'pie'}
  26409. // }
  26410. // The first colum should better be treated as a "ordinal" although it
  26411. // might not able to be detected as an "ordinal" by `guessOrdinal`.
  26412. || resultItem.isExtraCoord && (resultItem.otherDims.itemName != null || resultItem.otherDims.seriesName != null))) {
  26413. resultItem.type = 'ordinal';
  26414. }
  26415. }
  26416. return result;
  26417. } // ??? TODO
  26418. // Originally detect dimCount by data[0]. Should we
  26419. // optimize it to only by sysDims and dimensions and encode.
  26420. // So only necessary dims will be initialized.
  26421. // But
  26422. // (1) custom series should be considered. where other dims
  26423. // may be visited.
  26424. // (2) sometimes user need to calcualte bubble size or use visualMap
  26425. // on other dimensions besides coordSys needed.
  26426. // So, dims that is not used by system, should be shared in storage?
  26427. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  26428. // Note that the result dimCount should not small than columns count
  26429. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  26430. var dimCount = Math.max(source.dimensionsDetectCount || 1, sysDims.length, dimsDef.length, optDimCount || 0);
  26431. each$1(sysDims, function (sysDimItem) {
  26432. var sysDimItemDimsDef = sysDimItem.dimsDef;
  26433. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  26434. });
  26435. return dimCount;
  26436. }
  26437. function genName(name, map$$1, fromZero) {
  26438. if (fromZero || map$$1.get(name) != null) {
  26439. var i = 0;
  26440. while (map$$1.get(name + i) != null) {
  26441. i++;
  26442. }
  26443. name += i;
  26444. }
  26445. map$$1.set(name, true);
  26446. return name;
  26447. }
  26448. /*
  26449. * Licensed to the Apache Software Foundation (ASF) under one
  26450. * or more contributor license agreements. See the NOTICE file
  26451. * distributed with this work for additional information
  26452. * regarding copyright ownership. The ASF licenses this file
  26453. * to you under the Apache License, Version 2.0 (the
  26454. * "License"); you may not use this file except in compliance
  26455. * with the License. You may obtain a copy of the License at
  26456. *
  26457. * http://www.apache.org/licenses/LICENSE-2.0
  26458. *
  26459. * Unless required by applicable law or agreed to in writing,
  26460. * software distributed under the License is distributed on an
  26461. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26462. * KIND, either express or implied. See the License for the
  26463. * specific language governing permissions and limitations
  26464. * under the License.
  26465. */
  26466. /**
  26467. * Substitute `completeDimensions`.
  26468. * `completeDimensions` is to be deprecated.
  26469. */
  26470. /**
  26471. * @param {module:echarts/data/Source|module:echarts/data/List} source or data.
  26472. * @param {Object|Array} [opt]
  26473. * @param {Array.<string|Object>} [opt.coordDimensions=[]]
  26474. * @param {number} [opt.dimensionsCount]
  26475. * @param {string} [opt.generateCoord]
  26476. * @param {string} [opt.generateCoordCount]
  26477. * @param {Array.<string|Object>} [opt.dimensionsDefine=source.dimensionsDefine] Overwrite source define.
  26478. * @param {Object|HashMap} [opt.encodeDefine=source.encodeDefine] Overwrite source define.
  26479. * @param {Function} [opt.encodeDefaulter] Make default encode if user not specified.
  26480. * @return {Array.<Object>} dimensionsInfo
  26481. */
  26482. var createDimensions = function (source, opt) {
  26483. opt = opt || {};
  26484. return completeDimensions(opt.coordDimensions || [], source, {
  26485. dimsDef: opt.dimensionsDefine || source.dimensionsDefine,
  26486. encodeDef: opt.encodeDefine || source.encodeDefine,
  26487. dimCount: opt.dimensionsCount,
  26488. encodeDefaulter: opt.encodeDefaulter,
  26489. generateCoord: opt.generateCoord,
  26490. generateCoordCount: opt.generateCoordCount
  26491. });
  26492. };
  26493. /*
  26494. * Licensed to the Apache Software Foundation (ASF) under one
  26495. * or more contributor license agreements. See the NOTICE file
  26496. * distributed with this work for additional information
  26497. * regarding copyright ownership. The ASF licenses this file
  26498. * to you under the Apache License, Version 2.0 (the
  26499. * "License"); you may not use this file except in compliance
  26500. * with the License. You may obtain a copy of the License at
  26501. *
  26502. * http://www.apache.org/licenses/LICENSE-2.0
  26503. *
  26504. * Unless required by applicable law or agreed to in writing,
  26505. * software distributed under the License is distributed on an
  26506. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26507. * KIND, either express or implied. See the License for the
  26508. * specific language governing permissions and limitations
  26509. * under the License.
  26510. */
  26511. /**
  26512. * Helper for model references.
  26513. * There are many manners to refer axis/coordSys.
  26514. */
  26515. // TODO
  26516. // merge relevant logic to this file?
  26517. // check: "modelHelper" of tooltip and "BrushTargetManager".
  26518. /**
  26519. * @class
  26520. * For example:
  26521. * {
  26522. * coordSysName: 'cartesian2d',
  26523. * coordSysDims: ['x', 'y', ...],
  26524. * axisMap: HashMap({
  26525. * x: xAxisModel,
  26526. * y: yAxisModel
  26527. * }),
  26528. * categoryAxisMap: HashMap({
  26529. * x: xAxisModel,
  26530. * y: undefined
  26531. * }),
  26532. * // The index of the first category axis in `coordSysDims`.
  26533. * // `null/undefined` means no category axis exists.
  26534. * firstCategoryDimIndex: 1,
  26535. * // To replace user specified encode.
  26536. * }
  26537. */
  26538. function CoordSysInfo(coordSysName) {
  26539. /**
  26540. * @type {string}
  26541. */
  26542. this.coordSysName = coordSysName;
  26543. /**
  26544. * @type {Array.<string>}
  26545. */
  26546. this.coordSysDims = [];
  26547. /**
  26548. * @type {module:zrender/core/util#HashMap}
  26549. */
  26550. this.axisMap = createHashMap();
  26551. /**
  26552. * @type {module:zrender/core/util#HashMap}
  26553. */
  26554. this.categoryAxisMap = createHashMap();
  26555. /**
  26556. * @type {number}
  26557. */
  26558. this.firstCategoryDimIndex = null;
  26559. }
  26560. /**
  26561. * @return {module:model/referHelper#CoordSysInfo}
  26562. */
  26563. function getCoordSysInfoBySeries(seriesModel) {
  26564. var coordSysName = seriesModel.get('coordinateSystem');
  26565. var result = new CoordSysInfo(coordSysName);
  26566. var fetch = fetchers[coordSysName];
  26567. if (fetch) {
  26568. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  26569. return result;
  26570. }
  26571. }
  26572. var fetchers = {
  26573. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  26574. var xAxisModel = seriesModel.getReferringComponents('xAxis')[0];
  26575. var yAxisModel = seriesModel.getReferringComponents('yAxis')[0];
  26576. if (__DEV__) {
  26577. if (!xAxisModel) {
  26578. throw new Error('xAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('xAxisId'), 0) + '" not found');
  26579. }
  26580. if (!yAxisModel) {
  26581. throw new Error('yAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('yAxisId'), 0) + '" not found');
  26582. }
  26583. }
  26584. result.coordSysDims = ['x', 'y'];
  26585. axisMap.set('x', xAxisModel);
  26586. axisMap.set('y', yAxisModel);
  26587. if (isCategory(xAxisModel)) {
  26588. categoryAxisMap.set('x', xAxisModel);
  26589. result.firstCategoryDimIndex = 0;
  26590. }
  26591. if (isCategory(yAxisModel)) {
  26592. categoryAxisMap.set('y', yAxisModel);
  26593. result.firstCategoryDimIndex == null & (result.firstCategoryDimIndex = 1);
  26594. }
  26595. },
  26596. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  26597. var singleAxisModel = seriesModel.getReferringComponents('singleAxis')[0];
  26598. if (__DEV__) {
  26599. if (!singleAxisModel) {
  26600. throw new Error('singleAxis should be specified.');
  26601. }
  26602. }
  26603. result.coordSysDims = ['single'];
  26604. axisMap.set('single', singleAxisModel);
  26605. if (isCategory(singleAxisModel)) {
  26606. categoryAxisMap.set('single', singleAxisModel);
  26607. result.firstCategoryDimIndex = 0;
  26608. }
  26609. },
  26610. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  26611. var polarModel = seriesModel.getReferringComponents('polar')[0];
  26612. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  26613. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  26614. if (__DEV__) {
  26615. if (!angleAxisModel) {
  26616. throw new Error('angleAxis option not found');
  26617. }
  26618. if (!radiusAxisModel) {
  26619. throw new Error('radiusAxis option not found');
  26620. }
  26621. }
  26622. result.coordSysDims = ['radius', 'angle'];
  26623. axisMap.set('radius', radiusAxisModel);
  26624. axisMap.set('angle', angleAxisModel);
  26625. if (isCategory(radiusAxisModel)) {
  26626. categoryAxisMap.set('radius', radiusAxisModel);
  26627. result.firstCategoryDimIndex = 0;
  26628. }
  26629. if (isCategory(angleAxisModel)) {
  26630. categoryAxisMap.set('angle', angleAxisModel);
  26631. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  26632. }
  26633. },
  26634. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  26635. result.coordSysDims = ['lng', 'lat'];
  26636. },
  26637. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  26638. var ecModel = seriesModel.ecModel;
  26639. var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  26640. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  26641. each$1(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  26642. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  26643. var axisDim = coordSysDims[index];
  26644. axisMap.set(axisDim, axisModel);
  26645. if (isCategory(axisModel) && result.firstCategoryDimIndex == null) {
  26646. categoryAxisMap.set(axisDim, axisModel);
  26647. result.firstCategoryDimIndex = index;
  26648. }
  26649. });
  26650. }
  26651. };
  26652. function isCategory(axisModel) {
  26653. return axisModel.get('type') === 'category';
  26654. }
  26655. /*
  26656. * Licensed to the Apache Software Foundation (ASF) under one
  26657. * or more contributor license agreements. See the NOTICE file
  26658. * distributed with this work for additional information
  26659. * regarding copyright ownership. The ASF licenses this file
  26660. * to you under the Apache License, Version 2.0 (the
  26661. * "License"); you may not use this file except in compliance
  26662. * with the License. You may obtain a copy of the License at
  26663. *
  26664. * http://www.apache.org/licenses/LICENSE-2.0
  26665. *
  26666. * Unless required by applicable law or agreed to in writing,
  26667. * software distributed under the License is distributed on an
  26668. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26669. * KIND, either express or implied. See the License for the
  26670. * specific language governing permissions and limitations
  26671. * under the License.
  26672. */
  26673. /**
  26674. * Note that it is too complicated to support 3d stack by value
  26675. * (have to create two-dimension inverted index), so in 3d case
  26676. * we just support that stacked by index.
  26677. *
  26678. * @param {module:echarts/model/Series} seriesModel
  26679. * @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
  26680. * The input dimensionInfoList will be modified.
  26681. * @param {Object} [opt]
  26682. * @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
  26683. * @param {boolean} [opt.byIndex=false]
  26684. * @return {Object} calculationInfo
  26685. * {
  26686. * stackedDimension: string
  26687. * stackedByDimension: string
  26688. * isStackedByIndex: boolean
  26689. * stackedOverDimension: string
  26690. * stackResultDimension: string
  26691. * }
  26692. */
  26693. function enableDataStack(seriesModel, dimensionInfoList, opt) {
  26694. opt = opt || {};
  26695. var byIndex = opt.byIndex;
  26696. var stackedCoordDimension = opt.stackedCoordDimension; // Compatibal: when `stack` is set as '', do not stack.
  26697. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  26698. var stackedByDimInfo;
  26699. var stackedDimInfo;
  26700. var stackResultDimension;
  26701. var stackedOverDimension;
  26702. each$1(dimensionInfoList, function (dimensionInfo, index) {
  26703. if (isString(dimensionInfo)) {
  26704. dimensionInfoList[index] = dimensionInfo = {
  26705. name: dimensionInfo
  26706. };
  26707. }
  26708. if (mayStack && !dimensionInfo.isExtraCoord) {
  26709. // Find the first ordinal dimension as the stackedByDimInfo.
  26710. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  26711. stackedByDimInfo = dimensionInfo;
  26712. } // Find the first stackable dimension as the stackedDimInfo.
  26713. if (!stackedDimInfo && dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time' && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)) {
  26714. stackedDimInfo = dimensionInfo;
  26715. }
  26716. }
  26717. });
  26718. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  26719. // Compatible with previous design, value axis (time axis) only stack by index.
  26720. // It may make sense if the user provides elaborately constructed data.
  26721. byIndex = true;
  26722. } // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  26723. // That put stack logic in List is for using conveniently in echarts extensions, but it
  26724. // might not be a good way.
  26725. if (stackedDimInfo) {
  26726. // Use a weird name that not duplicated with other names.
  26727. stackResultDimension = '__\0ecstackresult';
  26728. stackedOverDimension = '__\0ecstackedover'; // Create inverted index to fast query index by value.
  26729. if (stackedByDimInfo) {
  26730. stackedByDimInfo.createInvertedIndices = true;
  26731. }
  26732. var stackedDimCoordDim = stackedDimInfo.coordDim;
  26733. var stackedDimType = stackedDimInfo.type;
  26734. var stackedDimCoordIndex = 0;
  26735. each$1(dimensionInfoList, function (dimensionInfo) {
  26736. if (dimensionInfo.coordDim === stackedDimCoordDim) {
  26737. stackedDimCoordIndex++;
  26738. }
  26739. });
  26740. dimensionInfoList.push({
  26741. name: stackResultDimension,
  26742. coordDim: stackedDimCoordDim,
  26743. coordDimIndex: stackedDimCoordIndex,
  26744. type: stackedDimType,
  26745. isExtraCoord: true,
  26746. isCalculationCoord: true
  26747. });
  26748. stackedDimCoordIndex++;
  26749. dimensionInfoList.push({
  26750. name: stackedOverDimension,
  26751. // This dimension contains stack base (generally, 0), so do not set it as
  26752. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  26753. coordDim: stackedOverDimension,
  26754. coordDimIndex: stackedDimCoordIndex,
  26755. type: stackedDimType,
  26756. isExtraCoord: true,
  26757. isCalculationCoord: true
  26758. });
  26759. }
  26760. return {
  26761. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  26762. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  26763. isStackedByIndex: byIndex,
  26764. stackedOverDimension: stackedOverDimension,
  26765. stackResultDimension: stackResultDimension
  26766. };
  26767. }
  26768. /**
  26769. * @param {module:echarts/data/List} data
  26770. * @param {string} stackedDim
  26771. */
  26772. function isDimensionStacked(data, stackedDim
  26773. /*, stackedByDim*/
  26774. ) {
  26775. // Each single series only maps to one pair of axis. So we do not need to
  26776. // check stackByDim, whatever stacked by a dimension or stacked by index.
  26777. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension'); // && (
  26778. // stackedByDim != null
  26779. // ? stackedByDim === data.getCalculationInfo('stackedByDimension')
  26780. // : data.getCalculationInfo('isStackedByIndex')
  26781. // );
  26782. }
  26783. /**
  26784. * @param {module:echarts/data/List} data
  26785. * @param {string} targetDim
  26786. * @param {string} [stackedByDim] If not input this parameter, check whether
  26787. * stacked by index.
  26788. * @return {string} dimension
  26789. */
  26790. function getStackedDimension(data, targetDim) {
  26791. return isDimensionStacked(data, targetDim) ? data.getCalculationInfo('stackResultDimension') : targetDim;
  26792. }
  26793. /*
  26794. * Licensed to the Apache Software Foundation (ASF) under one
  26795. * or more contributor license agreements. See the NOTICE file
  26796. * distributed with this work for additional information
  26797. * regarding copyright ownership. The ASF licenses this file
  26798. * to you under the Apache License, Version 2.0 (the
  26799. * "License"); you may not use this file except in compliance
  26800. * with the License. You may obtain a copy of the License at
  26801. *
  26802. * http://www.apache.org/licenses/LICENSE-2.0
  26803. *
  26804. * Unless required by applicable law or agreed to in writing,
  26805. * software distributed under the License is distributed on an
  26806. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26807. * KIND, either express or implied. See the License for the
  26808. * specific language governing permissions and limitations
  26809. * under the License.
  26810. */
  26811. /**
  26812. * @param {module:echarts/data/Source|Array} source Or raw data.
  26813. * @param {module:echarts/model/Series} seriesModel
  26814. * @param {Object} [opt]
  26815. * @param {string} [opt.generateCoord]
  26816. * @param {boolean} [opt.useEncodeDefaulter]
  26817. */
  26818. function createListFromArray(source, seriesModel, opt) {
  26819. opt = opt || {};
  26820. if (!Source.isInstance(source)) {
  26821. source = Source.seriesDataToSource(source);
  26822. }
  26823. var coordSysName = seriesModel.get('coordinateSystem');
  26824. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  26825. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  26826. var coordSysDimDefs;
  26827. if (coordSysInfo) {
  26828. coordSysDimDefs = map(coordSysInfo.coordSysDims, function (dim) {
  26829. var dimInfo = {
  26830. name: dim
  26831. };
  26832. var axisModel = coordSysInfo.axisMap.get(dim);
  26833. if (axisModel) {
  26834. var axisType = axisModel.get('type');
  26835. dimInfo.type = getDimensionTypeByAxis(axisType); // dimInfo.stackable = isStackable(axisType);
  26836. }
  26837. return dimInfo;
  26838. });
  26839. }
  26840. if (!coordSysDimDefs) {
  26841. // Get dimensions from registered coordinate system
  26842. coordSysDimDefs = registeredCoordSys && (registeredCoordSys.getDimensionsInfo ? registeredCoordSys.getDimensionsInfo() : registeredCoordSys.dimensions.slice()) || ['x', 'y'];
  26843. }
  26844. var dimInfoList = createDimensions(source, {
  26845. coordDimensions: coordSysDimDefs,
  26846. generateCoord: opt.generateCoord,
  26847. encodeDefaulter: opt.useEncodeDefaulter ? curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null
  26848. });
  26849. var firstCategoryDimIndex;
  26850. var hasNameEncode;
  26851. coordSysInfo && each$1(dimInfoList, function (dimInfo, dimIndex) {
  26852. var coordDim = dimInfo.coordDim;
  26853. var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
  26854. if (categoryAxisModel) {
  26855. if (firstCategoryDimIndex == null) {
  26856. firstCategoryDimIndex = dimIndex;
  26857. }
  26858. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  26859. }
  26860. if (dimInfo.otherDims.itemName != null) {
  26861. hasNameEncode = true;
  26862. }
  26863. });
  26864. if (!hasNameEncode && firstCategoryDimIndex != null) {
  26865. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  26866. }
  26867. var stackCalculationInfo = enableDataStack(seriesModel, dimInfoList);
  26868. var list = new List(dimInfoList, seriesModel);
  26869. list.setCalculationInfo(stackCalculationInfo);
  26870. var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source) ? function (itemOpt, dimName, dataIndex, dimIndex) {
  26871. // Use dataIndex as ordinal value in categoryAxis
  26872. return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  26873. } : null;
  26874. list.hasItemOption = false;
  26875. list.initData(source, null, dimValueGetter);
  26876. return list;
  26877. }
  26878. function isNeedCompleteOrdinalData(source) {
  26879. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  26880. var sampleItem = firstDataNotNull(source.data || []);
  26881. return sampleItem != null && !isArray(getDataItemValue(sampleItem));
  26882. }
  26883. }
  26884. function firstDataNotNull(data) {
  26885. var i = 0;
  26886. while (i < data.length && data[i] == null) {
  26887. i++;
  26888. }
  26889. return data[i];
  26890. }
  26891. /*
  26892. * Licensed to the Apache Software Foundation (ASF) under one
  26893. * or more contributor license agreements. See the NOTICE file
  26894. * distributed with this work for additional information
  26895. * regarding copyright ownership. The ASF licenses this file
  26896. * to you under the Apache License, Version 2.0 (the
  26897. * "License"); you may not use this file except in compliance
  26898. * with the License. You may obtain a copy of the License at
  26899. *
  26900. * http://www.apache.org/licenses/LICENSE-2.0
  26901. *
  26902. * Unless required by applicable law or agreed to in writing,
  26903. * software distributed under the License is distributed on an
  26904. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26905. * KIND, either express or implied. See the License for the
  26906. * specific language governing permissions and limitations
  26907. * under the License.
  26908. */
  26909. /**
  26910. * // Scale class management
  26911. * @module echarts/scale/Scale
  26912. */
  26913. /**
  26914. * @param {Object} [setting]
  26915. */
  26916. function Scale(setting) {
  26917. this._setting = setting || {};
  26918. /**
  26919. * Extent
  26920. * @type {Array.<number>}
  26921. * @protected
  26922. */
  26923. this._extent = [Infinity, -Infinity];
  26924. /**
  26925. * Step is calculated in adjustExtent
  26926. * @type {Array.<number>}
  26927. * @protected
  26928. */
  26929. this._interval = 0;
  26930. this.init && this.init.apply(this, arguments);
  26931. }
  26932. /**
  26933. * Parse input val to valid inner number.
  26934. * @param {*} val
  26935. * @return {number}
  26936. */
  26937. Scale.prototype.parse = function (val) {
  26938. // Notice: This would be a trap here, If the implementation
  26939. // of this method depends on extent, and this method is used
  26940. // before extent set (like in dataZoom), it would be wrong.
  26941. // Nevertheless, parse does not depend on extent generally.
  26942. return val;
  26943. };
  26944. Scale.prototype.getSetting = function (name) {
  26945. return this._setting[name];
  26946. };
  26947. Scale.prototype.contain = function (val) {
  26948. var extent = this._extent;
  26949. return val >= extent[0] && val <= extent[1];
  26950. };
  26951. /**
  26952. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  26953. * @param {number} val
  26954. * @return {number}
  26955. */
  26956. Scale.prototype.normalize = function (val) {
  26957. var extent = this._extent;
  26958. if (extent[1] === extent[0]) {
  26959. return 0.5;
  26960. }
  26961. return (val - extent[0]) / (extent[1] - extent[0]);
  26962. };
  26963. /**
  26964. * Scale normalized value
  26965. * @param {number} val
  26966. * @return {number}
  26967. */
  26968. Scale.prototype.scale = function (val) {
  26969. var extent = this._extent;
  26970. return val * (extent[1] - extent[0]) + extent[0];
  26971. };
  26972. /**
  26973. * Set extent from data
  26974. * @param {Array.<number>} other
  26975. */
  26976. Scale.prototype.unionExtent = function (other) {
  26977. var extent = this._extent;
  26978. other[0] < extent[0] && (extent[0] = other[0]);
  26979. other[1] > extent[1] && (extent[1] = other[1]); // not setExtent because in log axis it may transformed to power
  26980. // this.setExtent(extent[0], extent[1]);
  26981. };
  26982. /**
  26983. * Set extent from data
  26984. * @param {module:echarts/data/List} data
  26985. * @param {string} dim
  26986. */
  26987. Scale.prototype.unionExtentFromData = function (data, dim) {
  26988. this.unionExtent(data.getApproximateExtent(dim));
  26989. };
  26990. /**
  26991. * Get extent
  26992. * @return {Array.<number>}
  26993. */
  26994. Scale.prototype.getExtent = function () {
  26995. return this._extent.slice();
  26996. };
  26997. /**
  26998. * Set extent
  26999. * @param {number} start
  27000. * @param {number} end
  27001. */
  27002. Scale.prototype.setExtent = function (start, end) {
  27003. var thisExtent = this._extent;
  27004. if (!isNaN(start)) {
  27005. thisExtent[0] = start;
  27006. }
  27007. if (!isNaN(end)) {
  27008. thisExtent[1] = end;
  27009. }
  27010. };
  27011. /**
  27012. * When axis extent depends on data and no data exists,
  27013. * axis ticks should not be drawn, which is named 'blank'.
  27014. */
  27015. Scale.prototype.isBlank = function () {
  27016. return this._isBlank;
  27017. },
  27018. /**
  27019. * When axis extent depends on data and no data exists,
  27020. * axis ticks should not be drawn, which is named 'blank'.
  27021. */
  27022. Scale.prototype.setBlank = function (isBlank) {
  27023. this._isBlank = isBlank;
  27024. };
  27025. /**
  27026. * @abstract
  27027. * @param {*} tick
  27028. * @return {string} label of the tick.
  27029. */
  27030. Scale.prototype.getLabel = null;
  27031. enableClassExtend(Scale);
  27032. enableClassManagement(Scale, {
  27033. registerWhenExtend: true
  27034. });
  27035. /*
  27036. * Licensed to the Apache Software Foundation (ASF) under one
  27037. * or more contributor license agreements. See the NOTICE file
  27038. * distributed with this work for additional information
  27039. * regarding copyright ownership. The ASF licenses this file
  27040. * to you under the Apache License, Version 2.0 (the
  27041. * "License"); you may not use this file except in compliance
  27042. * with the License. You may obtain a copy of the License at
  27043. *
  27044. * http://www.apache.org/licenses/LICENSE-2.0
  27045. *
  27046. * Unless required by applicable law or agreed to in writing,
  27047. * software distributed under the License is distributed on an
  27048. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27049. * KIND, either express or implied. See the License for the
  27050. * specific language governing permissions and limitations
  27051. * under the License.
  27052. */
  27053. /**
  27054. * @constructor
  27055. * @param {Object} [opt]
  27056. * @param {Object} [opt.categories=[]]
  27057. * @param {Object} [opt.needCollect=false]
  27058. * @param {Object} [opt.deduplication=false]
  27059. */
  27060. function OrdinalMeta(opt) {
  27061. /**
  27062. * @readOnly
  27063. * @type {Array.<string>}
  27064. */
  27065. this.categories = opt.categories || [];
  27066. /**
  27067. * @private
  27068. * @type {boolean}
  27069. */
  27070. this._needCollect = opt.needCollect;
  27071. /**
  27072. * @private
  27073. * @type {boolean}
  27074. */
  27075. this._deduplication = opt.deduplication;
  27076. /**
  27077. * @private
  27078. * @type {boolean}
  27079. */
  27080. this._map;
  27081. }
  27082. /**
  27083. * @param {module:echarts/model/Model} axisModel
  27084. * @return {module:echarts/data/OrdinalMeta}
  27085. */
  27086. OrdinalMeta.createByAxisModel = function (axisModel) {
  27087. var option = axisModel.option;
  27088. var data = option.data;
  27089. var categories = data && map(data, getName);
  27090. return new OrdinalMeta({
  27091. categories: categories,
  27092. needCollect: !categories,
  27093. // deduplication is default in axis.
  27094. deduplication: option.dedplication !== false
  27095. });
  27096. };
  27097. var proto$1 = OrdinalMeta.prototype;
  27098. /**
  27099. * @param {string} category
  27100. * @return {number} ordinal
  27101. */
  27102. proto$1.getOrdinal = function (category) {
  27103. return getOrCreateMap(this).get(category);
  27104. };
  27105. /**
  27106. * @param {*} category
  27107. * @return {number} The ordinal. If not found, return NaN.
  27108. */
  27109. proto$1.parseAndCollect = function (category) {
  27110. var index;
  27111. var needCollect = this._needCollect; // The value of category dim can be the index of the given category set.
  27112. // This feature is only supported when !needCollect, because we should
  27113. // consider a common case: a value is 2017, which is a number but is
  27114. // expected to be tread as a category. This case usually happen in dataset,
  27115. // where it happent to be no need of the index feature.
  27116. if (typeof category !== 'string' && !needCollect) {
  27117. return category;
  27118. } // Optimize for the scenario:
  27119. // category is ['2012-01-01', '2012-01-02', ...], where the input
  27120. // data has been ensured not duplicate and is large data.
  27121. // Notice, if a dataset dimension provide categroies, usually echarts
  27122. // should remove duplication except user tell echarts dont do that
  27123. // (set axis.deduplication = false), because echarts do not know whether
  27124. // the values in the category dimension has duplication (consider the
  27125. // parallel-aqi example)
  27126. if (needCollect && !this._deduplication) {
  27127. index = this.categories.length;
  27128. this.categories[index] = category;
  27129. return index;
  27130. }
  27131. var map$$1 = getOrCreateMap(this);
  27132. index = map$$1.get(category);
  27133. if (index == null) {
  27134. if (needCollect) {
  27135. index = this.categories.length;
  27136. this.categories[index] = category;
  27137. map$$1.set(category, index);
  27138. } else {
  27139. index = NaN;
  27140. }
  27141. }
  27142. return index;
  27143. }; // Consider big data, do not create map until needed.
  27144. function getOrCreateMap(ordinalMeta) {
  27145. return ordinalMeta._map || (ordinalMeta._map = createHashMap(ordinalMeta.categories));
  27146. }
  27147. function getName(obj) {
  27148. if (isObject$1(obj) && obj.value != null) {
  27149. return obj.value;
  27150. } else {
  27151. return obj + '';
  27152. }
  27153. }
  27154. /*
  27155. * Licensed to the Apache Software Foundation (ASF) under one
  27156. * or more contributor license agreements. See the NOTICE file
  27157. * distributed with this work for additional information
  27158. * regarding copyright ownership. The ASF licenses this file
  27159. * to you under the Apache License, Version 2.0 (the
  27160. * "License"); you may not use this file except in compliance
  27161. * with the License. You may obtain a copy of the License at
  27162. *
  27163. * http://www.apache.org/licenses/LICENSE-2.0
  27164. *
  27165. * Unless required by applicable law or agreed to in writing,
  27166. * software distributed under the License is distributed on an
  27167. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27168. * KIND, either express or implied. See the License for the
  27169. * specific language governing permissions and limitations
  27170. * under the License.
  27171. */
  27172. /**
  27173. * Linear continuous scale
  27174. * @module echarts/coord/scale/Ordinal
  27175. *
  27176. * http://en.wikipedia.org/wiki/Level_of_measurement
  27177. */
  27178. // FIXME only one data
  27179. var scaleProto = Scale.prototype;
  27180. var OrdinalScale = Scale.extend({
  27181. type: 'ordinal',
  27182. /**
  27183. * @param {module:echarts/data/OrdianlMeta|Array.<string>} ordinalMeta
  27184. */
  27185. init: function (ordinalMeta, extent) {
  27186. // Caution: Should not use instanceof, consider ec-extensions using
  27187. // import approach to get OrdinalMeta class.
  27188. if (!ordinalMeta || isArray(ordinalMeta)) {
  27189. ordinalMeta = new OrdinalMeta({
  27190. categories: ordinalMeta
  27191. });
  27192. }
  27193. this._ordinalMeta = ordinalMeta;
  27194. this._extent = extent || [0, ordinalMeta.categories.length - 1];
  27195. },
  27196. parse: function (val) {
  27197. return typeof val === 'string' ? this._ordinalMeta.getOrdinal(val) // val might be float.
  27198. : Math.round(val);
  27199. },
  27200. contain: function (rank) {
  27201. rank = this.parse(rank);
  27202. return scaleProto.contain.call(this, rank) && this._ordinalMeta.categories[rank] != null;
  27203. },
  27204. /**
  27205. * Normalize given rank or name to linear [0, 1]
  27206. * @param {number|string} [val]
  27207. * @return {number}
  27208. */
  27209. normalize: function (val) {
  27210. return scaleProto.normalize.call(this, this.parse(val));
  27211. },
  27212. scale: function (val) {
  27213. return Math.round(scaleProto.scale.call(this, val));
  27214. },
  27215. /**
  27216. * @return {Array}
  27217. */
  27218. getTicks: function () {
  27219. var ticks = [];
  27220. var extent = this._extent;
  27221. var rank = extent[0];
  27222. while (rank <= extent[1]) {
  27223. ticks.push(rank);
  27224. rank++;
  27225. }
  27226. return ticks;
  27227. },
  27228. /**
  27229. * Get item on rank n
  27230. * @param {number} n
  27231. * @return {string}
  27232. */
  27233. getLabel: function (n) {
  27234. if (!this.isBlank()) {
  27235. // Note that if no data, ordinalMeta.categories is an empty array.
  27236. return this._ordinalMeta.categories[n];
  27237. }
  27238. },
  27239. /**
  27240. * @return {number}
  27241. */
  27242. count: function () {
  27243. return this._extent[1] - this._extent[0] + 1;
  27244. },
  27245. /**
  27246. * @override
  27247. */
  27248. unionExtentFromData: function (data, dim) {
  27249. this.unionExtent(data.getApproximateExtent(dim));
  27250. },
  27251. getOrdinalMeta: function () {
  27252. return this._ordinalMeta;
  27253. },
  27254. niceTicks: noop,
  27255. niceExtent: noop
  27256. });
  27257. /**
  27258. * @return {module:echarts/scale/Time}
  27259. */
  27260. OrdinalScale.create = function () {
  27261. return new OrdinalScale();
  27262. };
  27263. /*
  27264. * Licensed to the Apache Software Foundation (ASF) under one
  27265. * or more contributor license agreements. See the NOTICE file
  27266. * distributed with this work for additional information
  27267. * regarding copyright ownership. The ASF licenses this file
  27268. * to you under the Apache License, Version 2.0 (the
  27269. * "License"); you may not use this file except in compliance
  27270. * with the License. You may obtain a copy of the License at
  27271. *
  27272. * http://www.apache.org/licenses/LICENSE-2.0
  27273. *
  27274. * Unless required by applicable law or agreed to in writing,
  27275. * software distributed under the License is distributed on an
  27276. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27277. * KIND, either express or implied. See the License for the
  27278. * specific language governing permissions and limitations
  27279. * under the License.
  27280. */
  27281. /**
  27282. * For testable.
  27283. */
  27284. var roundNumber$1 = round$1;
  27285. /**
  27286. * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
  27287. * Should be extent[0] < extent[1].
  27288. * @param {number} splitNumber splitNumber should be >= 1.
  27289. * @param {number} [minInterval]
  27290. * @param {number} [maxInterval]
  27291. * @return {Object} {interval, intervalPrecision, niceTickExtent}
  27292. */
  27293. function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
  27294. var result = {};
  27295. var span = extent[1] - extent[0];
  27296. var interval = result.interval = nice(span / splitNumber, true);
  27297. if (minInterval != null && interval < minInterval) {
  27298. interval = result.interval = minInterval;
  27299. }
  27300. if (maxInterval != null && interval > maxInterval) {
  27301. interval = result.interval = maxInterval;
  27302. } // Tow more digital for tick.
  27303. var precision = result.intervalPrecision = getIntervalPrecision(interval); // Niced extent inside original extent
  27304. var niceTickExtent = result.niceTickExtent = [roundNumber$1(Math.ceil(extent[0] / interval) * interval, precision), roundNumber$1(Math.floor(extent[1] / interval) * interval, precision)];
  27305. fixExtent(niceTickExtent, extent);
  27306. return result;
  27307. }
  27308. /**
  27309. * @param {number} interval
  27310. * @return {number} interval precision
  27311. */
  27312. function getIntervalPrecision(interval) {
  27313. // Tow more digital for tick.
  27314. return getPrecisionSafe(interval) + 2;
  27315. }
  27316. function clamp(niceTickExtent, idx, extent) {
  27317. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  27318. } // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  27319. function fixExtent(niceTickExtent, extent) {
  27320. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  27321. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  27322. clamp(niceTickExtent, 0, extent);
  27323. clamp(niceTickExtent, 1, extent);
  27324. if (niceTickExtent[0] > niceTickExtent[1]) {
  27325. niceTickExtent[0] = niceTickExtent[1];
  27326. }
  27327. }
  27328. /*
  27329. * Licensed to the Apache Software Foundation (ASF) under one
  27330. * or more contributor license agreements. See the NOTICE file
  27331. * distributed with this work for additional information
  27332. * regarding copyright ownership. The ASF licenses this file
  27333. * to you under the Apache License, Version 2.0 (the
  27334. * "License"); you may not use this file except in compliance
  27335. * with the License. You may obtain a copy of the License at
  27336. *
  27337. * http://www.apache.org/licenses/LICENSE-2.0
  27338. *
  27339. * Unless required by applicable law or agreed to in writing,
  27340. * software distributed under the License is distributed on an
  27341. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27342. * KIND, either express or implied. See the License for the
  27343. * specific language governing permissions and limitations
  27344. * under the License.
  27345. */
  27346. /**
  27347. * Interval scale
  27348. * @module echarts/scale/Interval
  27349. */
  27350. var roundNumber = round$1;
  27351. /**
  27352. * @alias module:echarts/coord/scale/Interval
  27353. * @constructor
  27354. */
  27355. var IntervalScale = Scale.extend({
  27356. type: 'interval',
  27357. _interval: 0,
  27358. _intervalPrecision: 2,
  27359. setExtent: function (start, end) {
  27360. var thisExtent = this._extent; //start,end may be a Number like '25',so...
  27361. if (!isNaN(start)) {
  27362. thisExtent[0] = parseFloat(start);
  27363. }
  27364. if (!isNaN(end)) {
  27365. thisExtent[1] = parseFloat(end);
  27366. }
  27367. },
  27368. unionExtent: function (other) {
  27369. var extent = this._extent;
  27370. other[0] < extent[0] && (extent[0] = other[0]);
  27371. other[1] > extent[1] && (extent[1] = other[1]); // unionExtent may called by it's sub classes
  27372. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  27373. },
  27374. /**
  27375. * Get interval
  27376. */
  27377. getInterval: function () {
  27378. return this._interval;
  27379. },
  27380. /**
  27381. * Set interval
  27382. */
  27383. setInterval: function (interval) {
  27384. this._interval = interval; // Dropped auto calculated niceExtent and use user setted extent
  27385. // We assume user wan't to set both interval, min, max to get a better result
  27386. this._niceExtent = this._extent.slice();
  27387. this._intervalPrecision = getIntervalPrecision(interval);
  27388. },
  27389. /**
  27390. * @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
  27391. * @return {Array.<number>}
  27392. */
  27393. getTicks: function (expandToNicedExtent) {
  27394. var interval = this._interval;
  27395. var extent = this._extent;
  27396. var niceTickExtent = this._niceExtent;
  27397. var intervalPrecision = this._intervalPrecision;
  27398. var ticks = []; // If interval is 0, return [];
  27399. if (!interval) {
  27400. return ticks;
  27401. } // Consider this case: using dataZoom toolbox, zoom and zoom.
  27402. var safeLimit = 10000;
  27403. if (extent[0] < niceTickExtent[0]) {
  27404. if (expandToNicedExtent) {
  27405. ticks.push(roundNumber(niceTickExtent[0] - interval, intervalPrecision));
  27406. } else {
  27407. ticks.push(extent[0]);
  27408. }
  27409. }
  27410. var tick = niceTickExtent[0];
  27411. while (tick <= niceTickExtent[1]) {
  27412. ticks.push(tick); // Avoid rounding error
  27413. tick = roundNumber(tick + interval, intervalPrecision);
  27414. if (tick === ticks[ticks.length - 1]) {
  27415. // Consider out of safe float point, e.g.,
  27416. // -3711126.9907707 + 2e-10 === -3711126.9907707
  27417. break;
  27418. }
  27419. if (ticks.length > safeLimit) {
  27420. return [];
  27421. }
  27422. } // Consider this case: the last item of ticks is smaller
  27423. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  27424. var lastNiceTick = ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1];
  27425. if (extent[1] > lastNiceTick) {
  27426. if (expandToNicedExtent) {
  27427. ticks.push(roundNumber(lastNiceTick + interval, intervalPrecision));
  27428. } else {
  27429. ticks.push(extent[1]);
  27430. }
  27431. }
  27432. return ticks;
  27433. },
  27434. /**
  27435. * @param {number} [splitNumber=5]
  27436. * @return {Array.<Array.<number>>}
  27437. */
  27438. getMinorTicks: function (splitNumber) {
  27439. var ticks = this.getTicks(true);
  27440. var minorTicks = [];
  27441. var extent = this.getExtent();
  27442. for (var i = 1; i < ticks.length; i++) {
  27443. var nextTick = ticks[i];
  27444. var prevTick = ticks[i - 1];
  27445. var count = 0;
  27446. var minorTicksGroup = [];
  27447. var interval = nextTick - prevTick;
  27448. var minorInterval = interval / splitNumber;
  27449. while (count < splitNumber - 1) {
  27450. var minorTick = round$1(prevTick + (count + 1) * minorInterval); // For the first and last interval. The count may be less than splitNumber.
  27451. if (minorTick > extent[0] && minorTick < extent[1]) {
  27452. minorTicksGroup.push(minorTick);
  27453. }
  27454. count++;
  27455. }
  27456. minorTicks.push(minorTicksGroup);
  27457. }
  27458. return minorTicks;
  27459. },
  27460. /**
  27461. * @param {number} data
  27462. * @param {Object} [opt]
  27463. * @param {number|string} [opt.precision] If 'auto', use nice presision.
  27464. * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
  27465. * @return {string}
  27466. */
  27467. getLabel: function (data, opt) {
  27468. if (data == null) {
  27469. return '';
  27470. }
  27471. var precision = opt && opt.precision;
  27472. if (precision == null) {
  27473. precision = getPrecisionSafe(data) || 0;
  27474. } else if (precision === 'auto') {
  27475. // Should be more precise then tick.
  27476. precision = this._intervalPrecision;
  27477. } // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  27478. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  27479. data = roundNumber(data, precision, true);
  27480. return addCommas(data);
  27481. },
  27482. /**
  27483. * Update interval and extent of intervals for nice ticks
  27484. *
  27485. * @param {number} [splitNumber = 5] Desired number of ticks
  27486. * @param {number} [minInterval]
  27487. * @param {number} [maxInterval]
  27488. */
  27489. niceTicks: function (splitNumber, minInterval, maxInterval) {
  27490. splitNumber = splitNumber || 5;
  27491. var extent = this._extent;
  27492. var span = extent[1] - extent[0];
  27493. if (!isFinite(span)) {
  27494. return;
  27495. } // User may set axis min 0 and data are all negative
  27496. // FIXME If it needs to reverse ?
  27497. if (span < 0) {
  27498. span = -span;
  27499. extent.reverse();
  27500. }
  27501. var result = intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval);
  27502. this._intervalPrecision = result.intervalPrecision;
  27503. this._interval = result.interval;
  27504. this._niceExtent = result.niceTickExtent;
  27505. },
  27506. /**
  27507. * Nice extent.
  27508. * @param {Object} opt
  27509. * @param {number} [opt.splitNumber = 5] Given approx tick number
  27510. * @param {boolean} [opt.fixMin=false]
  27511. * @param {boolean} [opt.fixMax=false]
  27512. * @param {boolean} [opt.minInterval]
  27513. * @param {boolean} [opt.maxInterval]
  27514. */
  27515. niceExtent: function (opt) {
  27516. var extent = this._extent; // If extent start and end are same, expand them
  27517. if (extent[0] === extent[1]) {
  27518. if (extent[0] !== 0) {
  27519. // Expand extent
  27520. var expandSize = extent[0]; // In the fowllowing case
  27521. // Axis has been fixed max 100
  27522. // Plus data are all 100 and axis extent are [100, 100].
  27523. // Extend to the both side will cause expanded max is larger than fixed max.
  27524. // So only expand to the smaller side.
  27525. if (!opt.fixMax) {
  27526. extent[1] += expandSize / 2;
  27527. extent[0] -= expandSize / 2;
  27528. } else {
  27529. extent[0] -= expandSize / 2;
  27530. }
  27531. } else {
  27532. extent[1] = 1;
  27533. }
  27534. }
  27535. var span = extent[1] - extent[0]; // If there are no data and extent are [Infinity, -Infinity]
  27536. if (!isFinite(span)) {
  27537. extent[0] = 0;
  27538. extent[1] = 1;
  27539. }
  27540. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent;
  27541. var interval = this._interval;
  27542. if (!opt.fixMin) {
  27543. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
  27544. }
  27545. if (!opt.fixMax) {
  27546. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
  27547. }
  27548. }
  27549. });
  27550. /**
  27551. * @return {module:echarts/scale/Time}
  27552. */
  27553. IntervalScale.create = function () {
  27554. return new IntervalScale();
  27555. };
  27556. /*
  27557. * Licensed to the Apache Software Foundation (ASF) under one
  27558. * or more contributor license agreements. See the NOTICE file
  27559. * distributed with this work for additional information
  27560. * regarding copyright ownership. The ASF licenses this file
  27561. * to you under the Apache License, Version 2.0 (the
  27562. * "License"); you may not use this file except in compliance
  27563. * with the License. You may obtain a copy of the License at
  27564. *
  27565. * http://www.apache.org/licenses/LICENSE-2.0
  27566. *
  27567. * Unless required by applicable law or agreed to in writing,
  27568. * software distributed under the License is distributed on an
  27569. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27570. * KIND, either express or implied. See the License for the
  27571. * specific language governing permissions and limitations
  27572. * under the License.
  27573. */
  27574. /* global Float32Array */
  27575. var STACK_PREFIX = '__ec_stack_';
  27576. var LARGE_BAR_MIN_WIDTH = 0.5;
  27577. var LargeArr = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  27578. function getSeriesStackId(seriesModel) {
  27579. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  27580. }
  27581. function getAxisKey(axis) {
  27582. return axis.dim + axis.index;
  27583. }
  27584. /**
  27585. * @param {Object} opt
  27586. * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
  27587. * @param {number} opt.count Positive interger.
  27588. * @param {number} [opt.barWidth]
  27589. * @param {number} [opt.barMaxWidth]
  27590. * @param {number} [opt.barMinWidth]
  27591. * @param {number} [opt.barGap]
  27592. * @param {number} [opt.barCategoryGap]
  27593. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  27594. */
  27595. function prepareLayoutBarSeries(seriesType, ecModel) {
  27596. var seriesModels = [];
  27597. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  27598. // Check series coordinate, do layout for cartesian2d only
  27599. if (isOnCartesian(seriesModel) && !isInLargeMode(seriesModel)) {
  27600. seriesModels.push(seriesModel);
  27601. }
  27602. });
  27603. return seriesModels;
  27604. }
  27605. /**
  27606. * Map from (baseAxis.dim + '_' + baseAxis.index) to min gap of two adjacent
  27607. * values.
  27608. * This works for time axes, value axes, and log axes.
  27609. * For a single time axis, return value is in the form like
  27610. * {'x_0': [1000000]}.
  27611. * The value of 1000000 is in milliseconds.
  27612. */
  27613. function getValueAxesMinGaps(barSeries) {
  27614. /**
  27615. * Map from axis.index to values.
  27616. * For a single time axis, axisValues is in the form like
  27617. * {'x_0': [1495555200000, 1495641600000, 1495728000000]}.
  27618. * Items in axisValues[x], e.g. 1495555200000, are time values of all
  27619. * series.
  27620. */
  27621. var axisValues = {};
  27622. each$1(barSeries, function (seriesModel) {
  27623. var cartesian = seriesModel.coordinateSystem;
  27624. var baseAxis = cartesian.getBaseAxis();
  27625. if (baseAxis.type !== 'time' && baseAxis.type !== 'value') {
  27626. return;
  27627. }
  27628. var data = seriesModel.getData();
  27629. var key = baseAxis.dim + '_' + baseAxis.index;
  27630. var dim = data.mapDimension(baseAxis.dim);
  27631. for (var i = 0, cnt = data.count(); i < cnt; ++i) {
  27632. var value = data.get(dim, i);
  27633. if (!axisValues[key]) {
  27634. // No previous data for the axis
  27635. axisValues[key] = [value];
  27636. } else {
  27637. // No value in previous series
  27638. axisValues[key].push(value);
  27639. } // Ignore duplicated time values in the same axis
  27640. }
  27641. });
  27642. var axisMinGaps = [];
  27643. for (var key in axisValues) {
  27644. if (axisValues.hasOwnProperty(key)) {
  27645. var valuesInAxis = axisValues[key];
  27646. if (valuesInAxis) {
  27647. // Sort axis values into ascending order to calculate gaps
  27648. valuesInAxis.sort(function (a, b) {
  27649. return a - b;
  27650. });
  27651. var min = null;
  27652. for (var j = 1; j < valuesInAxis.length; ++j) {
  27653. var delta = valuesInAxis[j] - valuesInAxis[j - 1];
  27654. if (delta > 0) {
  27655. // Ignore 0 delta because they are of the same axis value
  27656. min = min === null ? delta : Math.min(min, delta);
  27657. }
  27658. } // Set to null if only have one data
  27659. axisMinGaps[key] = min;
  27660. }
  27661. }
  27662. }
  27663. return axisMinGaps;
  27664. }
  27665. function makeColumnLayout(barSeries) {
  27666. var axisMinGaps = getValueAxesMinGaps(barSeries);
  27667. var seriesInfoList = [];
  27668. each$1(barSeries, function (seriesModel) {
  27669. var cartesian = seriesModel.coordinateSystem;
  27670. var baseAxis = cartesian.getBaseAxis();
  27671. var axisExtent = baseAxis.getExtent();
  27672. var bandWidth;
  27673. if (baseAxis.type === 'category') {
  27674. bandWidth = baseAxis.getBandWidth();
  27675. } else if (baseAxis.type === 'value' || baseAxis.type === 'time') {
  27676. var key = baseAxis.dim + '_' + baseAxis.index;
  27677. var minGap = axisMinGaps[key];
  27678. var extentSpan = Math.abs(axisExtent[1] - axisExtent[0]);
  27679. var scale = baseAxis.scale.getExtent();
  27680. var scaleSpan = Math.abs(scale[1] - scale[0]);
  27681. bandWidth = minGap ? extentSpan / scaleSpan * minGap : extentSpan; // When there is only one data value
  27682. } else {
  27683. var data = seriesModel.getData();
  27684. bandWidth = Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
  27685. }
  27686. var barWidth = parsePercent$1(seriesModel.get('barWidth'), bandWidth);
  27687. var barMaxWidth = parsePercent$1(seriesModel.get('barMaxWidth'), bandWidth);
  27688. var barMinWidth = parsePercent$1( // barMinWidth by default is 1 in cartesian. Because in value axis,
  27689. // the auto-calculated bar width might be less than 1.
  27690. seriesModel.get('barMinWidth') || 1, bandWidth);
  27691. var barGap = seriesModel.get('barGap');
  27692. var barCategoryGap = seriesModel.get('barCategoryGap');
  27693. seriesInfoList.push({
  27694. bandWidth: bandWidth,
  27695. barWidth: barWidth,
  27696. barMaxWidth: barMaxWidth,
  27697. barMinWidth: barMinWidth,
  27698. barGap: barGap,
  27699. barCategoryGap: barCategoryGap,
  27700. axisKey: getAxisKey(baseAxis),
  27701. stackId: getSeriesStackId(seriesModel)
  27702. });
  27703. });
  27704. return doCalBarWidthAndOffset(seriesInfoList);
  27705. }
  27706. function doCalBarWidthAndOffset(seriesInfoList) {
  27707. // Columns info on each category axis. Key is cartesian name
  27708. var columnsMap = {};
  27709. each$1(seriesInfoList, function (seriesInfo, idx) {
  27710. var axisKey = seriesInfo.axisKey;
  27711. var bandWidth = seriesInfo.bandWidth;
  27712. var columnsOnAxis = columnsMap[axisKey] || {
  27713. bandWidth: bandWidth,
  27714. remainedWidth: bandWidth,
  27715. autoWidthCount: 0,
  27716. categoryGap: '20%',
  27717. gap: '30%',
  27718. stacks: {}
  27719. };
  27720. var stacks = columnsOnAxis.stacks;
  27721. columnsMap[axisKey] = columnsOnAxis;
  27722. var stackId = seriesInfo.stackId;
  27723. if (!stacks[stackId]) {
  27724. columnsOnAxis.autoWidthCount++;
  27725. }
  27726. stacks[stackId] = stacks[stackId] || {
  27727. width: 0,
  27728. maxWidth: 0
  27729. }; // Caution: In a single coordinate system, these barGrid attributes
  27730. // will be shared by series. Consider that they have default values,
  27731. // only the attributes set on the last series will work.
  27732. // Do not change this fact unless there will be a break change.
  27733. var barWidth = seriesInfo.barWidth;
  27734. if (barWidth && !stacks[stackId].width) {
  27735. // See #6312, do not restrict width.
  27736. stacks[stackId].width = barWidth;
  27737. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  27738. columnsOnAxis.remainedWidth -= barWidth;
  27739. }
  27740. var barMaxWidth = seriesInfo.barMaxWidth;
  27741. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  27742. var barMinWidth = seriesInfo.barMinWidth;
  27743. barMinWidth && (stacks[stackId].minWidth = barMinWidth);
  27744. var barGap = seriesInfo.barGap;
  27745. barGap != null && (columnsOnAxis.gap = barGap);
  27746. var barCategoryGap = seriesInfo.barCategoryGap;
  27747. barCategoryGap != null && (columnsOnAxis.categoryGap = barCategoryGap);
  27748. });
  27749. var result = {};
  27750. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  27751. result[coordSysName] = {};
  27752. var stacks = columnsOnAxis.stacks;
  27753. var bandWidth = columnsOnAxis.bandWidth;
  27754. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  27755. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  27756. var remainedWidth = columnsOnAxis.remainedWidth;
  27757. var autoWidthCount = columnsOnAxis.autoWidthCount;
  27758. var autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  27759. autoWidth = Math.max(autoWidth, 0); // Find if any auto calculated bar exceeded maxBarWidth
  27760. each$1(stacks, function (column) {
  27761. var maxWidth = column.maxWidth;
  27762. var minWidth = column.minWidth;
  27763. if (!column.width) {
  27764. var finalWidth = autoWidth;
  27765. if (maxWidth && maxWidth < finalWidth) {
  27766. finalWidth = Math.min(maxWidth, remainedWidth);
  27767. } // `minWidth` has higher priority. `minWidth` decide that wheter the
  27768. // bar is able to be visible. So `minWidth` should not be restricted
  27769. // by `maxWidth` or `remainedWidth` (which is from `bandWidth`). In
  27770. // the extreme cases for `value` axis, bars are allowed to overlap
  27771. // with each other if `minWidth` specified.
  27772. if (minWidth && minWidth > finalWidth) {
  27773. finalWidth = minWidth;
  27774. }
  27775. if (finalWidth !== autoWidth) {
  27776. column.width = finalWidth;
  27777. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  27778. autoWidthCount--;
  27779. }
  27780. } else {
  27781. // `barMinWidth/barMaxWidth` has higher priority than `barWidth`, as
  27782. // CSS does. Becuase barWidth can be a percent value, where
  27783. // `barMaxWidth` can be used to restrict the final width.
  27784. var finalWidth = column.width;
  27785. if (maxWidth) {
  27786. finalWidth = Math.min(finalWidth, maxWidth);
  27787. } // `minWidth` has higher priority, as described above
  27788. if (minWidth) {
  27789. finalWidth = Math.max(finalWidth, minWidth);
  27790. }
  27791. column.width = finalWidth;
  27792. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  27793. autoWidthCount--;
  27794. }
  27795. }); // Recalculate width again
  27796. autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  27797. autoWidth = Math.max(autoWidth, 0);
  27798. var widthSum = 0;
  27799. var lastColumn;
  27800. each$1(stacks, function (column, idx) {
  27801. if (!column.width) {
  27802. column.width = autoWidth;
  27803. }
  27804. lastColumn = column;
  27805. widthSum += column.width * (1 + barGapPercent);
  27806. });
  27807. if (lastColumn) {
  27808. widthSum -= lastColumn.width * barGapPercent;
  27809. }
  27810. var offset = -widthSum / 2;
  27811. each$1(stacks, function (column, stackId) {
  27812. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  27813. bandWidth: bandWidth,
  27814. offset: offset,
  27815. width: column.width
  27816. };
  27817. offset += column.width * (1 + barGapPercent);
  27818. });
  27819. });
  27820. return result;
  27821. }
  27822. /**
  27823. * @param {Object} barWidthAndOffset The result of makeColumnLayout
  27824. * @param {module:echarts/coord/Axis} axis
  27825. * @param {module:echarts/model/Series} [seriesModel] If not provided, return all.
  27826. * @return {Object} {stackId: {offset, width}} or {offset, width} if seriesModel provided.
  27827. */
  27828. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  27829. if (barWidthAndOffset && axis) {
  27830. var result = barWidthAndOffset[getAxisKey(axis)];
  27831. if (result != null && seriesModel != null) {
  27832. result = result[getSeriesStackId(seriesModel)];
  27833. }
  27834. return result;
  27835. }
  27836. }
  27837. /**
  27838. * @param {string} seriesType
  27839. * @param {module:echarts/model/Global} ecModel
  27840. */
  27841. // TODO: Do not support stack in large mode yet.
  27842. var largeLayout = {
  27843. seriesType: 'bar',
  27844. plan: createRenderPlanner(),
  27845. reset: function (seriesModel) {
  27846. if (!isOnCartesian(seriesModel) || !isInLargeMode(seriesModel)) {
  27847. return;
  27848. }
  27849. var data = seriesModel.getData();
  27850. var cartesian = seriesModel.coordinateSystem;
  27851. var coordLayout = cartesian.grid.getRect();
  27852. var baseAxis = cartesian.getBaseAxis();
  27853. var valueAxis = cartesian.getOtherAxis(baseAxis);
  27854. var valueDim = data.mapDimension(valueAxis.dim);
  27855. var baseDim = data.mapDimension(baseAxis.dim);
  27856. var valueAxisHorizontal = valueAxis.isHorizontal();
  27857. var valueDimIdx = valueAxisHorizontal ? 0 : 1;
  27858. var barWidth = retrieveColumnLayout(makeColumnLayout([seriesModel]), baseAxis, seriesModel).width;
  27859. if (!(barWidth > LARGE_BAR_MIN_WIDTH)) {
  27860. // jshint ignore:line
  27861. barWidth = LARGE_BAR_MIN_WIDTH;
  27862. }
  27863. return {
  27864. progress: progress
  27865. };
  27866. function progress(params, data) {
  27867. var count = params.count;
  27868. var largePoints = new LargeArr(count * 2);
  27869. var largeBackgroundPoints = new LargeArr(count * 2);
  27870. var largeDataIndices = new LargeArr(count);
  27871. var dataIndex;
  27872. var coord = [];
  27873. var valuePair = [];
  27874. var pointsOffset = 0;
  27875. var idxOffset = 0;
  27876. while ((dataIndex = params.next()) != null) {
  27877. valuePair[valueDimIdx] = data.get(valueDim, dataIndex);
  27878. valuePair[1 - valueDimIdx] = data.get(baseDim, dataIndex);
  27879. coord = cartesian.dataToPoint(valuePair, null, coord); // Data index might not be in order, depends on `progressiveChunkMode`.
  27880. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal ? coordLayout.x + coordLayout.width : coord[0];
  27881. largePoints[pointsOffset++] = coord[0];
  27882. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal ? coord[1] : coordLayout.y + coordLayout.height;
  27883. largePoints[pointsOffset++] = coord[1];
  27884. largeDataIndices[idxOffset++] = dataIndex;
  27885. }
  27886. data.setLayout({
  27887. largePoints: largePoints,
  27888. largeDataIndices: largeDataIndices,
  27889. largeBackgroundPoints: largeBackgroundPoints,
  27890. barWidth: barWidth,
  27891. valueAxisStart: getValueAxisStart(baseAxis, valueAxis, false),
  27892. backgroundStart: valueAxisHorizontal ? coordLayout.x : coordLayout.y,
  27893. valueAxisHorizontal: valueAxisHorizontal
  27894. });
  27895. }
  27896. }
  27897. };
  27898. function isOnCartesian(seriesModel) {
  27899. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  27900. }
  27901. function isInLargeMode(seriesModel) {
  27902. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  27903. } // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  27904. function getValueAxisStart(baseAxis, valueAxis, stacked) {
  27905. return valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.type === 'log' ? 1 : 0));
  27906. }
  27907. /*
  27908. * Licensed to the Apache Software Foundation (ASF) under one
  27909. * or more contributor license agreements. See the NOTICE file
  27910. * distributed with this work for additional information
  27911. * regarding copyright ownership. The ASF licenses this file
  27912. * to you under the Apache License, Version 2.0 (the
  27913. * "License"); you may not use this file except in compliance
  27914. * with the License. You may obtain a copy of the License at
  27915. *
  27916. * http://www.apache.org/licenses/LICENSE-2.0
  27917. *
  27918. * Unless required by applicable law or agreed to in writing,
  27919. * software distributed under the License is distributed on an
  27920. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27921. * KIND, either express or implied. See the License for the
  27922. * specific language governing permissions and limitations
  27923. * under the License.
  27924. */
  27925. /*
  27926. * A third-party license is embeded for some of the code in this file:
  27927. * The "scaleLevels" was originally copied from "d3.js" with some
  27928. * modifications made for this project.
  27929. * (See more details in the comment on the definition of "scaleLevels" below.)
  27930. * The use of the source code of this file is also subject to the terms
  27931. * and consitions of the license of "d3.js" (BSD-3Clause, see
  27932. * </licenses/LICENSE-d3>).
  27933. */
  27934. // [About UTC and local time zone]:
  27935. // In most cases, `number.parseDate` will treat input data string as local time
  27936. // (except time zone is specified in time string). And `format.formateTime` returns
  27937. // local time by default. option.useUTC is false by default. This design have
  27938. // concidered these common case:
  27939. // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
  27940. // in local time by default.
  27941. // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
  27942. // as its original time, without any time difference.
  27943. var intervalScaleProto = IntervalScale.prototype;
  27944. var mathCeil = Math.ceil;
  27945. var mathFloor = Math.floor;
  27946. var ONE_SECOND = 1000;
  27947. var ONE_MINUTE = ONE_SECOND * 60;
  27948. var ONE_HOUR = ONE_MINUTE * 60;
  27949. var ONE_DAY = ONE_HOUR * 24; // FIXME 公用?
  27950. var bisect = function (a, x, lo, hi) {
  27951. while (lo < hi) {
  27952. var mid = lo + hi >>> 1;
  27953. if (a[mid][1] < x) {
  27954. lo = mid + 1;
  27955. } else {
  27956. hi = mid;
  27957. }
  27958. }
  27959. return lo;
  27960. };
  27961. /**
  27962. * @alias module:echarts/coord/scale/Time
  27963. * @constructor
  27964. */
  27965. var TimeScale = IntervalScale.extend({
  27966. type: 'time',
  27967. /**
  27968. * @override
  27969. */
  27970. getLabel: function (val) {
  27971. var stepLvl = this._stepLvl;
  27972. var date = new Date(val);
  27973. return formatTime(stepLvl[0], date, this.getSetting('useUTC'));
  27974. },
  27975. /**
  27976. * @override
  27977. */
  27978. niceExtent: function (opt) {
  27979. var extent = this._extent; // If extent start and end are same, expand them
  27980. if (extent[0] === extent[1]) {
  27981. // Expand extent
  27982. extent[0] -= ONE_DAY;
  27983. extent[1] += ONE_DAY;
  27984. } // If there are no data and extent are [Infinity, -Infinity]
  27985. if (extent[1] === -Infinity && extent[0] === Infinity) {
  27986. var d = new Date();
  27987. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  27988. extent[0] = extent[1] - ONE_DAY;
  27989. }
  27990. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent;
  27991. var interval = this._interval;
  27992. if (!opt.fixMin) {
  27993. extent[0] = round$1(mathFloor(extent[0] / interval) * interval);
  27994. }
  27995. if (!opt.fixMax) {
  27996. extent[1] = round$1(mathCeil(extent[1] / interval) * interval);
  27997. }
  27998. },
  27999. /**
  28000. * @override
  28001. */
  28002. niceTicks: function (approxTickNum, minInterval, maxInterval) {
  28003. approxTickNum = approxTickNum || 10;
  28004. var extent = this._extent;
  28005. var span = extent[1] - extent[0];
  28006. var approxInterval = span / approxTickNum;
  28007. if (minInterval != null && approxInterval < minInterval) {
  28008. approxInterval = minInterval;
  28009. }
  28010. if (maxInterval != null && approxInterval > maxInterval) {
  28011. approxInterval = maxInterval;
  28012. }
  28013. var scaleLevelsLen = scaleLevels.length;
  28014. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  28015. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  28016. var interval = level[1]; // Same with interval scale if span is much larger than 1 year
  28017. if (level[0] === 'year') {
  28018. var yearSpan = span / interval; // From "Nice Numbers for Graph Labels" of Graphic Gems
  28019. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  28020. var yearStep = nice(yearSpan / approxTickNum, true);
  28021. interval *= yearStep;
  28022. }
  28023. var timezoneOffset = this.getSetting('useUTC') ? 0 : new Date(+extent[0] || +extent[1]).getTimezoneOffset() * 60 * 1000;
  28024. var niceExtent = [Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset), Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)];
  28025. fixExtent(niceExtent, extent);
  28026. this._stepLvl = level; // Interval will be used in getTicks
  28027. this._interval = interval;
  28028. this._niceExtent = niceExtent;
  28029. },
  28030. parse: function (val) {
  28031. // val might be float.
  28032. return +parseDate(val);
  28033. }
  28034. });
  28035. each$1(['contain', 'normalize'], function (methodName) {
  28036. TimeScale.prototype[methodName] = function (val) {
  28037. return intervalScaleProto[methodName].call(this, this.parse(val));
  28038. };
  28039. });
  28040. /**
  28041. * This implementation was originally copied from "d3.js"
  28042. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  28043. * with some modifications made for this program.
  28044. * See the license statement at the head of this file.
  28045. */
  28046. var scaleLevels = [// Format interval
  28047. ['hh:mm:ss', ONE_SECOND], // 1s
  28048. ['hh:mm:ss', ONE_SECOND * 5], // 5s
  28049. ['hh:mm:ss', ONE_SECOND * 10], // 10s
  28050. ['hh:mm:ss', ONE_SECOND * 15], // 15s
  28051. ['hh:mm:ss', ONE_SECOND * 30], // 30s
  28052. ['hh:mm\nMM-dd', ONE_MINUTE], // 1m
  28053. ['hh:mm\nMM-dd', ONE_MINUTE * 5], // 5m
  28054. ['hh:mm\nMM-dd', ONE_MINUTE * 10], // 10m
  28055. ['hh:mm\nMM-dd', ONE_MINUTE * 15], // 15m
  28056. ['hh:mm\nMM-dd', ONE_MINUTE * 30], // 30m
  28057. ['hh:mm\nMM-dd', ONE_HOUR], // 1h
  28058. ['hh:mm\nMM-dd', ONE_HOUR * 2], // 2h
  28059. ['hh:mm\nMM-dd', ONE_HOUR * 6], // 6h
  28060. ['hh:mm\nMM-dd', ONE_HOUR * 12], // 12h
  28061. ['MM-dd\nyyyy', ONE_DAY], // 1d
  28062. ['MM-dd\nyyyy', ONE_DAY * 2], // 2d
  28063. ['MM-dd\nyyyy', ONE_DAY * 3], // 3d
  28064. ['MM-dd\nyyyy', ONE_DAY * 4], // 4d
  28065. ['MM-dd\nyyyy', ONE_DAY * 5], // 5d
  28066. ['MM-dd\nyyyy', ONE_DAY * 6], // 6d
  28067. ['week', ONE_DAY * 7], // 7d
  28068. ['MM-dd\nyyyy', ONE_DAY * 10], // 10d
  28069. ['week', ONE_DAY * 14], // 2w
  28070. ['week', ONE_DAY * 21], // 3w
  28071. ['month', ONE_DAY * 31], // 1M
  28072. ['week', ONE_DAY * 42], // 6w
  28073. ['month', ONE_DAY * 62], // 2M
  28074. ['week', ONE_DAY * 70], // 10w
  28075. ['quarter', ONE_DAY * 95], // 3M
  28076. ['month', ONE_DAY * 31 * 4], // 4M
  28077. ['month', ONE_DAY * 31 * 5], // 5M
  28078. ['half-year', ONE_DAY * 380 / 2], // 6M
  28079. ['month', ONE_DAY * 31 * 8], // 8M
  28080. ['month', ONE_DAY * 31 * 10], // 10M
  28081. ['year', ONE_DAY * 380] // 1Y
  28082. ];
  28083. /**
  28084. * @param {module:echarts/model/Model}
  28085. * @return {module:echarts/scale/Time}
  28086. */
  28087. TimeScale.create = function (model) {
  28088. return new TimeScale({
  28089. useUTC: model.ecModel.get('useUTC')
  28090. });
  28091. };
  28092. /*
  28093. * Licensed to the Apache Software Foundation (ASF) under one
  28094. * or more contributor license agreements. See the NOTICE file
  28095. * distributed with this work for additional information
  28096. * regarding copyright ownership. The ASF licenses this file
  28097. * to you under the Apache License, Version 2.0 (the
  28098. * "License"); you may not use this file except in compliance
  28099. * with the License. You may obtain a copy of the License at
  28100. *
  28101. * http://www.apache.org/licenses/LICENSE-2.0
  28102. *
  28103. * Unless required by applicable law or agreed to in writing,
  28104. * software distributed under the License is distributed on an
  28105. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28106. * KIND, either express or implied. See the License for the
  28107. * specific language governing permissions and limitations
  28108. * under the License.
  28109. */
  28110. /**
  28111. * Log scale
  28112. * @module echarts/scale/Log
  28113. */
  28114. // Use some method of IntervalScale
  28115. var scaleProto$1 = Scale.prototype;
  28116. var intervalScaleProto$1 = IntervalScale.prototype;
  28117. var getPrecisionSafe$1 = getPrecisionSafe;
  28118. var roundingErrorFix = round$1;
  28119. var mathFloor$1 = Math.floor;
  28120. var mathCeil$1 = Math.ceil;
  28121. var mathPow$1 = Math.pow;
  28122. var mathLog = Math.log;
  28123. var LogScale = Scale.extend({
  28124. type: 'log',
  28125. base: 10,
  28126. $constructor: function () {
  28127. Scale.apply(this, arguments);
  28128. this._originalScale = new IntervalScale();
  28129. },
  28130. /**
  28131. * @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
  28132. * @return {Array.<number>}
  28133. */
  28134. getTicks: function (expandToNicedExtent) {
  28135. var originalScale = this._originalScale;
  28136. var extent = this._extent;
  28137. var originalExtent = originalScale.getExtent();
  28138. return map(intervalScaleProto$1.getTicks.call(this, expandToNicedExtent), function (val) {
  28139. var powVal = round$1(mathPow$1(this.base, val)); // Fix #4158
  28140. powVal = val === extent[0] && originalScale.__fixMin ? fixRoundingError(powVal, originalExtent[0]) : powVal;
  28141. powVal = val === extent[1] && originalScale.__fixMax ? fixRoundingError(powVal, originalExtent[1]) : powVal;
  28142. return powVal;
  28143. }, this);
  28144. },
  28145. /**
  28146. * @param {number} splitNumber
  28147. * @return {Array.<Array.<number>>}
  28148. */
  28149. getMinorTicks: intervalScaleProto$1.getMinorTicks,
  28150. /**
  28151. * @param {number} val
  28152. * @return {string}
  28153. */
  28154. getLabel: intervalScaleProto$1.getLabel,
  28155. /**
  28156. * @param {number} val
  28157. * @return {number}
  28158. */
  28159. scale: function (val) {
  28160. val = scaleProto$1.scale.call(this, val);
  28161. return mathPow$1(this.base, val);
  28162. },
  28163. /**
  28164. * @param {number} start
  28165. * @param {number} end
  28166. */
  28167. setExtent: function (start, end) {
  28168. var base = this.base;
  28169. start = mathLog(start) / mathLog(base);
  28170. end = mathLog(end) / mathLog(base);
  28171. intervalScaleProto$1.setExtent.call(this, start, end);
  28172. },
  28173. /**
  28174. * @return {number} end
  28175. */
  28176. getExtent: function () {
  28177. var base = this.base;
  28178. var extent = scaleProto$1.getExtent.call(this);
  28179. extent[0] = mathPow$1(base, extent[0]);
  28180. extent[1] = mathPow$1(base, extent[1]); // Fix #4158
  28181. var originalScale = this._originalScale;
  28182. var originalExtent = originalScale.getExtent();
  28183. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  28184. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  28185. return extent;
  28186. },
  28187. /**
  28188. * @param {Array.<number>} extent
  28189. */
  28190. unionExtent: function (extent) {
  28191. this._originalScale.unionExtent(extent);
  28192. var base = this.base;
  28193. extent[0] = mathLog(extent[0]) / mathLog(base);
  28194. extent[1] = mathLog(extent[1]) / mathLog(base);
  28195. scaleProto$1.unionExtent.call(this, extent);
  28196. },
  28197. /**
  28198. * @override
  28199. */
  28200. unionExtentFromData: function (data, dim) {
  28201. // TODO
  28202. // filter value that <= 0
  28203. this.unionExtent(data.getApproximateExtent(dim));
  28204. },
  28205. /**
  28206. * Update interval and extent of intervals for nice ticks
  28207. * @param {number} [approxTickNum = 10] Given approx tick number
  28208. */
  28209. niceTicks: function (approxTickNum) {
  28210. approxTickNum = approxTickNum || 10;
  28211. var extent = this._extent;
  28212. var span = extent[1] - extent[0];
  28213. if (span === Infinity || span <= 0) {
  28214. return;
  28215. }
  28216. var interval = quantity(span);
  28217. var err = approxTickNum / span * interval; // Filter ticks to get closer to the desired count.
  28218. if (err <= 0.5) {
  28219. interval *= 10;
  28220. } // Interval should be integer
  28221. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  28222. interval *= 10;
  28223. }
  28224. var niceExtent = [round$1(mathCeil$1(extent[0] / interval) * interval), round$1(mathFloor$1(extent[1] / interval) * interval)];
  28225. this._interval = interval;
  28226. this._niceExtent = niceExtent;
  28227. },
  28228. /**
  28229. * Nice extent.
  28230. * @override
  28231. */
  28232. niceExtent: function (opt) {
  28233. intervalScaleProto$1.niceExtent.call(this, opt);
  28234. var originalScale = this._originalScale;
  28235. originalScale.__fixMin = opt.fixMin;
  28236. originalScale.__fixMax = opt.fixMax;
  28237. }
  28238. });
  28239. each$1(['contain', 'normalize'], function (methodName) {
  28240. LogScale.prototype[methodName] = function (val) {
  28241. val = mathLog(val) / mathLog(this.base);
  28242. return scaleProto$1[methodName].call(this, val);
  28243. };
  28244. });
  28245. LogScale.create = function () {
  28246. return new LogScale();
  28247. };
  28248. function fixRoundingError(val, originalVal) {
  28249. return roundingErrorFix(val, getPrecisionSafe$1(originalVal));
  28250. }
  28251. /*
  28252. * Licensed to the Apache Software Foundation (ASF) under one
  28253. * or more contributor license agreements. See the NOTICE file
  28254. * distributed with this work for additional information
  28255. * regarding copyright ownership. The ASF licenses this file
  28256. * to you under the Apache License, Version 2.0 (the
  28257. * "License"); you may not use this file except in compliance
  28258. * with the License. You may obtain a copy of the License at
  28259. *
  28260. * http://www.apache.org/licenses/LICENSE-2.0
  28261. *
  28262. * Unless required by applicable law or agreed to in writing,
  28263. * software distributed under the License is distributed on an
  28264. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28265. * KIND, either express or implied. See the License for the
  28266. * specific language governing permissions and limitations
  28267. * under the License.
  28268. */
  28269. /**
  28270. * Get axis scale extent before niced.
  28271. * Item of returned array can only be number (including Infinity and NaN).
  28272. */
  28273. function getScaleExtent(scale, model) {
  28274. var scaleType = scale.type;
  28275. var min = model.getMin();
  28276. var max = model.getMax();
  28277. var originalExtent = scale.getExtent();
  28278. var axisDataLen;
  28279. var boundaryGap;
  28280. var span;
  28281. if (scaleType === 'ordinal') {
  28282. axisDataLen = model.getCategories().length;
  28283. } else {
  28284. boundaryGap = model.get('boundaryGap');
  28285. if (!isArray(boundaryGap)) {
  28286. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  28287. }
  28288. if (typeof boundaryGap[0] === 'boolean') {
  28289. if (__DEV__) {
  28290. console.warn('Boolean type for boundaryGap is only ' + 'allowed for ordinal axis. Please use string in ' + 'percentage instead, e.g., "20%". Currently, ' + 'boundaryGap is set to be 0.');
  28291. }
  28292. boundaryGap = [0, 0];
  28293. }
  28294. boundaryGap[0] = parsePercent$1(boundaryGap[0], 1);
  28295. boundaryGap[1] = parsePercent$1(boundaryGap[1], 1);
  28296. span = originalExtent[1] - originalExtent[0] || Math.abs(originalExtent[0]);
  28297. } // Notice: When min/max is not set (that is, when there are null/undefined,
  28298. // which is the most common case), these cases should be ensured:
  28299. // (1) For 'ordinal', show all axis.data.
  28300. // (2) For others:
  28301. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  28302. // disabled).
  28303. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  28304. // be the result that originalExtent enlarged by boundaryGap.
  28305. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  28306. // FIXME
  28307. // (1) When min/max is 'dataMin' or 'dataMax', should boundaryGap be able to used?
  28308. // (2) When `needCrossZero` and all data is positive/negative, should it be ensured
  28309. // that the results processed by boundaryGap are positive/negative?
  28310. if (min === 'dataMin') {
  28311. min = originalExtent[0];
  28312. } else if (typeof min === 'function') {
  28313. min = min({
  28314. min: originalExtent[0],
  28315. max: originalExtent[1]
  28316. });
  28317. }
  28318. if (max === 'dataMax') {
  28319. max = originalExtent[1];
  28320. } else if (typeof max === 'function') {
  28321. max = max({
  28322. min: originalExtent[0],
  28323. max: originalExtent[1]
  28324. });
  28325. }
  28326. var fixMin = min != null;
  28327. var fixMax = max != null;
  28328. if (min == null) {
  28329. min = scaleType === 'ordinal' ? axisDataLen ? 0 : NaN : originalExtent[0] - boundaryGap[0] * span;
  28330. }
  28331. if (max == null) {
  28332. max = scaleType === 'ordinal' ? axisDataLen ? axisDataLen - 1 : NaN : originalExtent[1] + boundaryGap[1] * span;
  28333. }
  28334. (min == null || !isFinite(min)) && (min = NaN);
  28335. (max == null || !isFinite(max)) && (max = NaN);
  28336. scale.setBlank(eqNaN(min) || eqNaN(max) || scaleType === 'ordinal' && !scale.getOrdinalMeta().categories.length); // Evaluate if axis needs cross zero
  28337. if (model.getNeedCrossZero()) {
  28338. // Axis is over zero and min is not set
  28339. if (min > 0 && max > 0 && !fixMin) {
  28340. min = 0;
  28341. } // Axis is under zero and max is not set
  28342. if (min < 0 && max < 0 && !fixMax) {
  28343. max = 0;
  28344. }
  28345. } // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  28346. // is base axis
  28347. // FIXME
  28348. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  28349. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  28350. // Should not depend on series type `bar`?
  28351. // (3) Fix that might overlap when using dataZoom.
  28352. // (4) Consider other chart types using `barGrid`?
  28353. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  28354. var ecModel = model.ecModel;
  28355. if (ecModel && scaleType === 'time'
  28356. /*|| scaleType === 'interval' */
  28357. ) {
  28358. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  28359. var isBaseAxisAndHasBarSeries;
  28360. each$1(barSeriesModels, function (seriesModel) {
  28361. isBaseAxisAndHasBarSeries |= seriesModel.getBaseAxis() === model.axis;
  28362. });
  28363. if (isBaseAxisAndHasBarSeries) {
  28364. // Calculate placement of bars on axis
  28365. var barWidthAndOffset = makeColumnLayout(barSeriesModels); // Adjust axis min and max to account for overflow
  28366. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  28367. min = adjustedScale.min;
  28368. max = adjustedScale.max;
  28369. }
  28370. }
  28371. return {
  28372. extent: [min, max],
  28373. // "fix" means "fixed", the value should not be
  28374. // changed in the subsequent steps.
  28375. fixMin: fixMin,
  28376. fixMax: fixMax
  28377. };
  28378. }
  28379. function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
  28380. // Get Axis Length
  28381. var axisExtent = model.axis.getExtent();
  28382. var axisLength = axisExtent[1] - axisExtent[0]; // Get bars on current base axis and calculate min and max overflow
  28383. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  28384. if (barsOnCurrentAxis === undefined) {
  28385. return {
  28386. min: min,
  28387. max: max
  28388. };
  28389. }
  28390. var minOverflow = Infinity;
  28391. each$1(barsOnCurrentAxis, function (item) {
  28392. minOverflow = Math.min(item.offset, minOverflow);
  28393. });
  28394. var maxOverflow = -Infinity;
  28395. each$1(barsOnCurrentAxis, function (item) {
  28396. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  28397. });
  28398. minOverflow = Math.abs(minOverflow);
  28399. maxOverflow = Math.abs(maxOverflow);
  28400. var totalOverFlow = minOverflow + maxOverflow; // Calulate required buffer based on old range and overflow
  28401. var oldRange = max - min;
  28402. var oldRangePercentOfNew = 1 - (minOverflow + maxOverflow) / axisLength;
  28403. var overflowBuffer = oldRange / oldRangePercentOfNew - oldRange;
  28404. max += overflowBuffer * (maxOverflow / totalOverFlow);
  28405. min -= overflowBuffer * (minOverflow / totalOverFlow);
  28406. return {
  28407. min: min,
  28408. max: max
  28409. };
  28410. }
  28411. function niceScaleExtent(scale, model) {
  28412. var extentInfo = getScaleExtent(scale, model);
  28413. var extent = extentInfo.extent;
  28414. var splitNumber = model.get('splitNumber');
  28415. if (scale.type === 'log') {
  28416. scale.base = model.get('logBase');
  28417. }
  28418. var scaleType = scale.type;
  28419. scale.setExtent(extent[0], extent[1]);
  28420. scale.niceExtent({
  28421. splitNumber: splitNumber,
  28422. fixMin: extentInfo.fixMin,
  28423. fixMax: extentInfo.fixMax,
  28424. minInterval: scaleType === 'interval' || scaleType === 'time' ? model.get('minInterval') : null,
  28425. maxInterval: scaleType === 'interval' || scaleType === 'time' ? model.get('maxInterval') : null
  28426. }); // If some one specified the min, max. And the default calculated interval
  28427. // is not good enough. He can specify the interval. It is often appeared
  28428. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  28429. // to be 60.
  28430. // FIXME
  28431. var interval = model.get('interval');
  28432. if (interval != null) {
  28433. scale.setInterval && scale.setInterval(interval);
  28434. }
  28435. }
  28436. /**
  28437. * @param {module:echarts/model/Model} model
  28438. * @param {string} [axisType] Default retrieve from model.type
  28439. * @return {module:echarts/scale/*}
  28440. */
  28441. function createScaleByModel(model, axisType) {
  28442. axisType = axisType || model.get('type');
  28443. if (axisType) {
  28444. switch (axisType) {
  28445. // Buildin scale
  28446. case 'category':
  28447. return new OrdinalScale(model.getOrdinalMeta ? model.getOrdinalMeta() : model.getCategories(), [Infinity, -Infinity]);
  28448. case 'value':
  28449. return new IntervalScale();
  28450. // Extended scale, like time and log
  28451. default:
  28452. return (Scale.getClass(axisType) || IntervalScale).create(model);
  28453. }
  28454. }
  28455. }
  28456. /**
  28457. * Check if the axis corss 0
  28458. */
  28459. function ifAxisCrossZero(axis) {
  28460. var dataExtent = axis.scale.getExtent();
  28461. var min = dataExtent[0];
  28462. var max = dataExtent[1];
  28463. return !(min > 0 && max > 0 || min < 0 && max < 0);
  28464. }
  28465. /**
  28466. * @param {module:echarts/coord/Axis} axis
  28467. * @return {Function} Label formatter function.
  28468. * param: {number} tickValue,
  28469. * param: {number} idx, the index in all ticks.
  28470. * If category axis, this param is not requied.
  28471. * return: {string} label string.
  28472. */
  28473. function makeLabelFormatter(axis) {
  28474. var labelFormatter = axis.getLabelModel().get('formatter');
  28475. var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
  28476. if (typeof labelFormatter === 'string') {
  28477. labelFormatter = function (tpl) {
  28478. return function (val) {
  28479. // For category axis, get raw value; for numeric axis,
  28480. // get foramtted label like '1,333,444'.
  28481. val = axis.scale.getLabel(val);
  28482. return tpl.replace('{value}', val != null ? val : '');
  28483. };
  28484. }(labelFormatter); // Consider empty array
  28485. return labelFormatter;
  28486. } else if (typeof labelFormatter === 'function') {
  28487. return function (tickValue, idx) {
  28488. // The original intention of `idx` is "the index of the tick in all ticks".
  28489. // But the previous implementation of category axis do not consider the
  28490. // `axisLabel.interval`, which cause that, for example, the `interval` is
  28491. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  28492. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  28493. // the definition here for back compatibility.
  28494. if (categoryTickStart != null) {
  28495. idx = tickValue - categoryTickStart;
  28496. }
  28497. return labelFormatter(getAxisRawValue(axis, tickValue), idx);
  28498. };
  28499. } else {
  28500. return function (tick) {
  28501. return axis.scale.getLabel(tick);
  28502. };
  28503. }
  28504. }
  28505. function getAxisRawValue(axis, value) {
  28506. // In category axis with data zoom, tick is not the original
  28507. // index of axis.data. So tick should not be exposed to user
  28508. // in category axis.
  28509. return axis.type === 'category' ? axis.scale.getLabel(value) : value;
  28510. }
  28511. /**
  28512. * @param {module:echarts/coord/Axis} axis
  28513. * @return {module:zrender/core/BoundingRect} Be null/undefined if no labels.
  28514. */
  28515. function estimateLabelUnionRect(axis) {
  28516. var axisModel = axis.model;
  28517. var scale = axis.scale;
  28518. if (!axisModel.get('axisLabel.show') || scale.isBlank()) {
  28519. return;
  28520. }
  28521. var isCategory = axis.type === 'category';
  28522. var realNumberScaleTicks;
  28523. var tickCount;
  28524. var categoryScaleExtent = scale.getExtent(); // Optimize for large category data, avoid call `getTicks()`.
  28525. if (isCategory) {
  28526. tickCount = scale.count();
  28527. } else {
  28528. realNumberScaleTicks = scale.getTicks();
  28529. tickCount = realNumberScaleTicks.length;
  28530. }
  28531. var axisLabelModel = axis.getLabelModel();
  28532. var labelFormatter = makeLabelFormatter(axis);
  28533. var rect;
  28534. var step = 1; // Simple optimization for large amount of labels
  28535. if (tickCount > 40) {
  28536. step = Math.ceil(tickCount / 40);
  28537. }
  28538. for (var i = 0; i < tickCount; i += step) {
  28539. var tickValue = realNumberScaleTicks ? realNumberScaleTicks[i] : categoryScaleExtent[0] + i;
  28540. var label = labelFormatter(tickValue);
  28541. var unrotatedSingleRect = axisLabelModel.getTextRect(label);
  28542. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  28543. rect ? rect.union(singleRect) : rect = singleRect;
  28544. }
  28545. return rect;
  28546. }
  28547. function rotateTextRect(textRect, rotate) {
  28548. var rotateRadians = rotate * Math.PI / 180;
  28549. var boundingBox = textRect.plain();
  28550. var beforeWidth = boundingBox.width;
  28551. var beforeHeight = boundingBox.height;
  28552. var afterWidth = beforeWidth * Math.abs(Math.cos(rotateRadians)) + Math.abs(beforeHeight * Math.sin(rotateRadians));
  28553. var afterHeight = beforeWidth * Math.abs(Math.sin(rotateRadians)) + Math.abs(beforeHeight * Math.cos(rotateRadians));
  28554. var rotatedRect = new BoundingRect(boundingBox.x, boundingBox.y, afterWidth, afterHeight);
  28555. return rotatedRect;
  28556. }
  28557. /**
  28558. * @param {module:echarts/src/model/Model} model axisLabelModel or axisTickModel
  28559. * @return {number|String} Can be null|'auto'|number|function
  28560. */
  28561. function getOptionCategoryInterval(model) {
  28562. var interval = model.get('interval');
  28563. return interval == null ? 'auto' : interval;
  28564. }
  28565. /**
  28566. * Set `categoryInterval` as 0 implicitly indicates that
  28567. * show all labels reguardless of overlap.
  28568. * @param {Object} axis axisModel.axis
  28569. * @return {boolean}
  28570. */
  28571. function shouldShowAllLabels(axis) {
  28572. return axis.type === 'category' && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  28573. }
  28574. /*
  28575. * Licensed to the Apache Software Foundation (ASF) under one
  28576. * or more contributor license agreements. See the NOTICE file
  28577. * distributed with this work for additional information
  28578. * regarding copyright ownership. The ASF licenses this file
  28579. * to you under the Apache License, Version 2.0 (the
  28580. * "License"); you may not use this file except in compliance
  28581. * with the License. You may obtain a copy of the License at
  28582. *
  28583. * http://www.apache.org/licenses/LICENSE-2.0
  28584. *
  28585. * Unless required by applicable law or agreed to in writing,
  28586. * software distributed under the License is distributed on an
  28587. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28588. * KIND, either express or implied. See the License for the
  28589. * specific language governing permissions and limitations
  28590. * under the License.
  28591. */
  28592. // import * as axisHelper from './axisHelper';
  28593. var axisModelCommonMixin = {
  28594. /**
  28595. * @param {boolean} origin
  28596. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  28597. */
  28598. getMin: function (origin) {
  28599. var option = this.option;
  28600. var min = !origin && option.rangeStart != null ? option.rangeStart : option.min;
  28601. if (this.axis && min != null && min !== 'dataMin' && typeof min !== 'function' && !eqNaN(min)) {
  28602. min = this.axis.scale.parse(min);
  28603. }
  28604. return min;
  28605. },
  28606. /**
  28607. * @param {boolean} origin
  28608. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  28609. */
  28610. getMax: function (origin) {
  28611. var option = this.option;
  28612. var max = !origin && option.rangeEnd != null ? option.rangeEnd : option.max;
  28613. if (this.axis && max != null && max !== 'dataMax' && typeof max !== 'function' && !eqNaN(max)) {
  28614. max = this.axis.scale.parse(max);
  28615. }
  28616. return max;
  28617. },
  28618. /**
  28619. * @return {boolean}
  28620. */
  28621. getNeedCrossZero: function () {
  28622. var option = this.option;
  28623. return option.rangeStart != null || option.rangeEnd != null ? false : !option.scale;
  28624. },
  28625. /**
  28626. * Should be implemented by each axis model if necessary.
  28627. * @return {module:echarts/model/Component} coordinate system model
  28628. */
  28629. getCoordSysModel: noop,
  28630. /**
  28631. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  28632. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  28633. */
  28634. setRange: function (rangeStart, rangeEnd) {
  28635. this.option.rangeStart = rangeStart;
  28636. this.option.rangeEnd = rangeEnd;
  28637. },
  28638. /**
  28639. * Reset range
  28640. */
  28641. resetRange: function () {
  28642. // rangeStart and rangeEnd is readonly.
  28643. this.option.rangeStart = this.option.rangeEnd = null;
  28644. }
  28645. };
  28646. /*
  28647. * Licensed to the Apache Software Foundation (ASF) under one
  28648. * or more contributor license agreements. See the NOTICE file
  28649. * distributed with this work for additional information
  28650. * regarding copyright ownership. The ASF licenses this file
  28651. * to you under the Apache License, Version 2.0 (the
  28652. * "License"); you may not use this file except in compliance
  28653. * with the License. You may obtain a copy of the License at
  28654. *
  28655. * http://www.apache.org/licenses/LICENSE-2.0
  28656. *
  28657. * Unless required by applicable law or agreed to in writing,
  28658. * software distributed under the License is distributed on an
  28659. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28660. * KIND, either express or implied. See the License for the
  28661. * specific language governing permissions and limitations
  28662. * under the License.
  28663. */
  28664. // Symbol factory
  28665. /**
  28666. * Triangle shape
  28667. * @inner
  28668. */
  28669. var Triangle = extendShape({
  28670. type: 'triangle',
  28671. shape: {
  28672. cx: 0,
  28673. cy: 0,
  28674. width: 0,
  28675. height: 0
  28676. },
  28677. buildPath: function (path, shape) {
  28678. var cx = shape.cx;
  28679. var cy = shape.cy;
  28680. var width = shape.width / 2;
  28681. var height = shape.height / 2;
  28682. path.moveTo(cx, cy - height);
  28683. path.lineTo(cx + width, cy + height);
  28684. path.lineTo(cx - width, cy + height);
  28685. path.closePath();
  28686. }
  28687. });
  28688. /**
  28689. * Diamond shape
  28690. * @inner
  28691. */
  28692. var Diamond = extendShape({
  28693. type: 'diamond',
  28694. shape: {
  28695. cx: 0,
  28696. cy: 0,
  28697. width: 0,
  28698. height: 0
  28699. },
  28700. buildPath: function (path, shape) {
  28701. var cx = shape.cx;
  28702. var cy = shape.cy;
  28703. var width = shape.width / 2;
  28704. var height = shape.height / 2;
  28705. path.moveTo(cx, cy - height);
  28706. path.lineTo(cx + width, cy);
  28707. path.lineTo(cx, cy + height);
  28708. path.lineTo(cx - width, cy);
  28709. path.closePath();
  28710. }
  28711. });
  28712. /**
  28713. * Pin shape
  28714. * @inner
  28715. */
  28716. var Pin = extendShape({
  28717. type: 'pin',
  28718. shape: {
  28719. // x, y on the cusp
  28720. x: 0,
  28721. y: 0,
  28722. width: 0,
  28723. height: 0
  28724. },
  28725. buildPath: function (path, shape) {
  28726. var x = shape.x;
  28727. var y = shape.y;
  28728. var w = shape.width / 5 * 3; // Height must be larger than width
  28729. var h = Math.max(w, shape.height);
  28730. var r = w / 2; // Dist on y with tangent point and circle center
  28731. var dy = r * r / (h - r);
  28732. var cy = y - h + r + dy;
  28733. var angle = Math.asin(dy / r); // Dist on x with tangent point and circle center
  28734. var dx = Math.cos(angle) * r;
  28735. var tanX = Math.sin(angle);
  28736. var tanY = Math.cos(angle);
  28737. var cpLen = r * 0.6;
  28738. var cpLen2 = r * 0.7;
  28739. path.moveTo(x - dx, cy + dy);
  28740. path.arc(x, cy, r, Math.PI - angle, Math.PI * 2 + angle);
  28741. path.bezierCurveTo(x + dx - tanX * cpLen, cy + dy + tanY * cpLen, x, y - cpLen2, x, y);
  28742. path.bezierCurveTo(x, y - cpLen2, x - dx + tanX * cpLen, cy + dy + tanY * cpLen, x - dx, cy + dy);
  28743. path.closePath();
  28744. }
  28745. });
  28746. /**
  28747. * Arrow shape
  28748. * @inner
  28749. */
  28750. var Arrow = extendShape({
  28751. type: 'arrow',
  28752. shape: {
  28753. x: 0,
  28754. y: 0,
  28755. width: 0,
  28756. height: 0
  28757. },
  28758. buildPath: function (ctx, shape) {
  28759. var height = shape.height;
  28760. var width = shape.width;
  28761. var x = shape.x;
  28762. var y = shape.y;
  28763. var dx = width / 3 * 2;
  28764. ctx.moveTo(x, y);
  28765. ctx.lineTo(x + dx, y + height);
  28766. ctx.lineTo(x, y + height / 4 * 3);
  28767. ctx.lineTo(x - dx, y + height);
  28768. ctx.lineTo(x, y);
  28769. ctx.closePath();
  28770. }
  28771. });
  28772. /**
  28773. * Map of path contructors
  28774. * @type {Object.<string, module:zrender/graphic/Path>}
  28775. */
  28776. var symbolCtors = {
  28777. line: Line,
  28778. rect: Rect,
  28779. roundRect: Rect,
  28780. square: Rect,
  28781. circle: Circle,
  28782. diamond: Diamond,
  28783. pin: Pin,
  28784. arrow: Arrow,
  28785. triangle: Triangle
  28786. };
  28787. var symbolShapeMakers = {
  28788. line: function (x, y, w, h, shape) {
  28789. // FIXME
  28790. shape.x1 = x;
  28791. shape.y1 = y + h / 2;
  28792. shape.x2 = x + w;
  28793. shape.y2 = y + h / 2;
  28794. },
  28795. rect: function (x, y, w, h, shape) {
  28796. shape.x = x;
  28797. shape.y = y;
  28798. shape.width = w;
  28799. shape.height = h;
  28800. },
  28801. roundRect: function (x, y, w, h, shape) {
  28802. shape.x = x;
  28803. shape.y = y;
  28804. shape.width = w;
  28805. shape.height = h;
  28806. shape.r = Math.min(w, h) / 4;
  28807. },
  28808. square: function (x, y, w, h, shape) {
  28809. var size = Math.min(w, h);
  28810. shape.x = x;
  28811. shape.y = y;
  28812. shape.width = size;
  28813. shape.height = size;
  28814. },
  28815. circle: function (x, y, w, h, shape) {
  28816. // Put circle in the center of square
  28817. shape.cx = x + w / 2;
  28818. shape.cy = y + h / 2;
  28819. shape.r = Math.min(w, h) / 2;
  28820. },
  28821. diamond: function (x, y, w, h, shape) {
  28822. shape.cx = x + w / 2;
  28823. shape.cy = y + h / 2;
  28824. shape.width = w;
  28825. shape.height = h;
  28826. },
  28827. pin: function (x, y, w, h, shape) {
  28828. shape.x = x + w / 2;
  28829. shape.y = y + h / 2;
  28830. shape.width = w;
  28831. shape.height = h;
  28832. },
  28833. arrow: function (x, y, w, h, shape) {
  28834. shape.x = x + w / 2;
  28835. shape.y = y + h / 2;
  28836. shape.width = w;
  28837. shape.height = h;
  28838. },
  28839. triangle: function (x, y, w, h, shape) {
  28840. shape.cx = x + w / 2;
  28841. shape.cy = y + h / 2;
  28842. shape.width = w;
  28843. shape.height = h;
  28844. }
  28845. };
  28846. var symbolBuildProxies = {};
  28847. each$1(symbolCtors, function (Ctor, name) {
  28848. symbolBuildProxies[name] = new Ctor();
  28849. });
  28850. var SymbolClz = extendShape({
  28851. type: 'symbol',
  28852. shape: {
  28853. symbolType: '',
  28854. x: 0,
  28855. y: 0,
  28856. width: 0,
  28857. height: 0
  28858. },
  28859. calculateTextPosition: function (out, style, rect) {
  28860. var res = calculateTextPosition(out, style, rect);
  28861. var shape = this.shape;
  28862. if (shape && shape.symbolType === 'pin' && style.textPosition === 'inside') {
  28863. res.y = rect.y + rect.height * 0.4;
  28864. }
  28865. return res;
  28866. },
  28867. buildPath: function (ctx, shape, inBundle) {
  28868. var symbolType = shape.symbolType;
  28869. if (symbolType !== 'none') {
  28870. var proxySymbol = symbolBuildProxies[symbolType];
  28871. if (!proxySymbol) {
  28872. // Default rect
  28873. symbolType = 'rect';
  28874. proxySymbol = symbolBuildProxies[symbolType];
  28875. }
  28876. symbolShapeMakers[symbolType](shape.x, shape.y, shape.width, shape.height, proxySymbol.shape);
  28877. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  28878. }
  28879. }
  28880. }); // Provide setColor helper method to avoid determine if set the fill or stroke outside
  28881. function symbolPathSetColor(color, innerColor) {
  28882. if (this.type !== 'image') {
  28883. var symbolStyle = this.style;
  28884. var symbolShape = this.shape;
  28885. if (symbolShape && symbolShape.symbolType === 'line') {
  28886. symbolStyle.stroke = color;
  28887. } else if (this.__isEmptyBrush) {
  28888. symbolStyle.stroke = color;
  28889. symbolStyle.fill = innerColor || '#fff';
  28890. } else {
  28891. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  28892. symbolStyle.fill && (symbolStyle.fill = color);
  28893. symbolStyle.stroke && (symbolStyle.stroke = color);
  28894. }
  28895. this.dirty(false);
  28896. }
  28897. }
  28898. /**
  28899. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  28900. * @param {string} symbolType
  28901. * @param {number} x
  28902. * @param {number} y
  28903. * @param {number} w
  28904. * @param {number} h
  28905. * @param {string} color
  28906. * @param {boolean} [keepAspect=false] whether to keep the ratio of w/h,
  28907. * for path and image only.
  28908. */
  28909. function createSymbol(symbolType, x, y, w, h, color, keepAspect) {
  28910. // TODO Support image object, DynamicImage.
  28911. var isEmpty = symbolType.indexOf('empty') === 0;
  28912. if (isEmpty) {
  28913. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  28914. }
  28915. var symbolPath;
  28916. if (symbolType.indexOf('image://') === 0) {
  28917. symbolPath = makeImage(symbolType.slice(8), new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  28918. } else if (symbolType.indexOf('path://') === 0) {
  28919. symbolPath = makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  28920. } else {
  28921. symbolPath = new SymbolClz({
  28922. shape: {
  28923. symbolType: symbolType,
  28924. x: x,
  28925. y: y,
  28926. width: w,
  28927. height: h
  28928. }
  28929. });
  28930. }
  28931. symbolPath.__isEmptyBrush = isEmpty;
  28932. symbolPath.setColor = symbolPathSetColor;
  28933. symbolPath.setColor(color);
  28934. return symbolPath;
  28935. }
  28936. /*
  28937. * Licensed to the Apache Software Foundation (ASF) under one
  28938. * or more contributor license agreements. See the NOTICE file
  28939. * distributed with this work for additional information
  28940. * regarding copyright ownership. The ASF licenses this file
  28941. * to you under the Apache License, Version 2.0 (the
  28942. * "License"); you may not use this file except in compliance
  28943. * with the License. You may obtain a copy of the License at
  28944. *
  28945. * http://www.apache.org/licenses/LICENSE-2.0
  28946. *
  28947. * Unless required by applicable law or agreed to in writing,
  28948. * software distributed under the License is distributed on an
  28949. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28950. * KIND, either express or implied. See the License for the
  28951. * specific language governing permissions and limitations
  28952. * under the License.
  28953. */
  28954. // import createGraphFromNodeEdge from './chart/helper/createGraphFromNodeEdge';
  28955. /**
  28956. * Create a muti dimension List structure from seriesModel.
  28957. * @param {module:echarts/model/Model} seriesModel
  28958. * @return {module:echarts/data/List} list
  28959. */
  28960. function createList(seriesModel) {
  28961. return createListFromArray(seriesModel.getSource(), seriesModel);
  28962. }
  28963. var dataStack$1 = {
  28964. isDimensionStacked: isDimensionStacked,
  28965. enableDataStack: enableDataStack,
  28966. getStackedDimension: getStackedDimension
  28967. };
  28968. /**
  28969. * Create scale
  28970. * @param {Array.<number>} dataExtent
  28971. * @param {Object|module:echarts/Model} option
  28972. */
  28973. function createScale(dataExtent, option) {
  28974. var axisModel = option;
  28975. if (!Model.isInstance(option)) {
  28976. axisModel = new Model(option);
  28977. mixin(axisModel, axisModelCommonMixin);
  28978. }
  28979. var scale = createScaleByModel(axisModel);
  28980. scale.setExtent(dataExtent[0], dataExtent[1]);
  28981. niceScaleExtent(scale, axisModel);
  28982. return scale;
  28983. }
  28984. /**
  28985. * Mixin common methods to axis model,
  28986. *
  28987. * Inlcude methods
  28988. * `getFormattedLabels() => Array.<string>`
  28989. * `getCategories() => Array.<string>`
  28990. * `getMin(origin: boolean) => number`
  28991. * `getMax(origin: boolean) => number`
  28992. * `getNeedCrossZero() => boolean`
  28993. * `setRange(start: number, end: number)`
  28994. * `resetRange()`
  28995. */
  28996. function mixinAxisModelCommonMethods(Model$$1) {
  28997. mixin(Model$$1, axisModelCommonMixin);
  28998. }
  28999. var helper = (Object.freeze || Object)({
  29000. createList: createList,
  29001. getLayoutRect: getLayoutRect,
  29002. dataStack: dataStack$1,
  29003. createScale: createScale,
  29004. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  29005. completeDimensions: completeDimensions,
  29006. createDimensions: createDimensions,
  29007. createSymbol: createSymbol
  29008. });
  29009. var EPSILON$3 = 1e-8;
  29010. function isAroundEqual$1(a, b) {
  29011. return Math.abs(a - b) < EPSILON$3;
  29012. }
  29013. function contain$1(points, x, y) {
  29014. var w = 0;
  29015. var p = points[0];
  29016. if (!p) {
  29017. return false;
  29018. }
  29019. for (var i = 1; i < points.length; i++) {
  29020. var p2 = points[i];
  29021. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  29022. p = p2;
  29023. } // Close polygon
  29024. var p0 = points[0];
  29025. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  29026. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  29027. }
  29028. return w !== 0;
  29029. }
  29030. /*
  29031. * Licensed to the Apache Software Foundation (ASF) under one
  29032. * or more contributor license agreements. See the NOTICE file
  29033. * distributed with this work for additional information
  29034. * regarding copyright ownership. The ASF licenses this file
  29035. * to you under the Apache License, Version 2.0 (the
  29036. * "License"); you may not use this file except in compliance
  29037. * with the License. You may obtain a copy of the License at
  29038. *
  29039. * http://www.apache.org/licenses/LICENSE-2.0
  29040. *
  29041. * Unless required by applicable law or agreed to in writing,
  29042. * software distributed under the License is distributed on an
  29043. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29044. * KIND, either express or implied. See the License for the
  29045. * specific language governing permissions and limitations
  29046. * under the License.
  29047. */
  29048. /**
  29049. * @module echarts/coord/geo/Region
  29050. */
  29051. /**
  29052. * @param {string|Region} name
  29053. * @param {Array} geometries
  29054. * @param {Array.<number>} cp
  29055. */
  29056. function Region(name, geometries, cp) {
  29057. /**
  29058. * @type {string}
  29059. * @readOnly
  29060. */
  29061. this.name = name;
  29062. /**
  29063. * @type {Array.<Array>}
  29064. * @readOnly
  29065. */
  29066. this.geometries = geometries;
  29067. if (!cp) {
  29068. var rect = this.getBoundingRect();
  29069. cp = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  29070. } else {
  29071. cp = [cp[0], cp[1]];
  29072. }
  29073. /**
  29074. * @type {Array.<number>}
  29075. */
  29076. this.center = cp;
  29077. }
  29078. Region.prototype = {
  29079. constructor: Region,
  29080. properties: null,
  29081. /**
  29082. * @return {module:zrender/core/BoundingRect}
  29083. */
  29084. getBoundingRect: function () {
  29085. var rect = this._rect;
  29086. if (rect) {
  29087. return rect;
  29088. }
  29089. var MAX_NUMBER = Number.MAX_VALUE;
  29090. var min$$1 = [MAX_NUMBER, MAX_NUMBER];
  29091. var max$$1 = [-MAX_NUMBER, -MAX_NUMBER];
  29092. var min2 = [];
  29093. var max2 = [];
  29094. var geometries = this.geometries;
  29095. for (var i = 0; i < geometries.length; i++) {
  29096. // Only support polygon
  29097. if (geometries[i].type !== 'polygon') {
  29098. continue;
  29099. } // Doesn't consider hole
  29100. var exterior = geometries[i].exterior;
  29101. fromPoints(exterior, min2, max2);
  29102. min(min$$1, min$$1, min2);
  29103. max(max$$1, max$$1, max2);
  29104. } // No data
  29105. if (i === 0) {
  29106. min$$1[0] = min$$1[1] = max$$1[0] = max$$1[1] = 0;
  29107. }
  29108. return this._rect = new BoundingRect(min$$1[0], min$$1[1], max$$1[0] - min$$1[0], max$$1[1] - min$$1[1]);
  29109. },
  29110. /**
  29111. * @param {<Array.<number>} coord
  29112. * @return {boolean}
  29113. */
  29114. contain: function (coord) {
  29115. var rect = this.getBoundingRect();
  29116. var geometries = this.geometries;
  29117. if (!rect.contain(coord[0], coord[1])) {
  29118. return false;
  29119. }
  29120. loopGeo: for (var i = 0, len$$1 = geometries.length; i < len$$1; i++) {
  29121. // Only support polygon.
  29122. if (geometries[i].type !== 'polygon') {
  29123. continue;
  29124. }
  29125. var exterior = geometries[i].exterior;
  29126. var interiors = geometries[i].interiors;
  29127. if (contain$1(exterior, coord[0], coord[1])) {
  29128. // Not in the region if point is in the hole.
  29129. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  29130. if (contain$1(interiors[k])) {
  29131. continue loopGeo;
  29132. }
  29133. }
  29134. return true;
  29135. }
  29136. }
  29137. return false;
  29138. },
  29139. transformTo: function (x, y, width, height) {
  29140. var rect = this.getBoundingRect();
  29141. var aspect = rect.width / rect.height;
  29142. if (!width) {
  29143. width = aspect * height;
  29144. } else if (!height) {
  29145. height = width / aspect;
  29146. }
  29147. var target = new BoundingRect(x, y, width, height);
  29148. var transform = rect.calculateTransform(target);
  29149. var geometries = this.geometries;
  29150. for (var i = 0; i < geometries.length; i++) {
  29151. // Only support polygon.
  29152. if (geometries[i].type !== 'polygon') {
  29153. continue;
  29154. }
  29155. var exterior = geometries[i].exterior;
  29156. var interiors = geometries[i].interiors;
  29157. for (var p = 0; p < exterior.length; p++) {
  29158. applyTransform(exterior[p], exterior[p], transform);
  29159. }
  29160. for (var h = 0; h < (interiors ? interiors.length : 0); h++) {
  29161. for (var p = 0; p < interiors[h].length; p++) {
  29162. applyTransform(interiors[h][p], interiors[h][p], transform);
  29163. }
  29164. }
  29165. }
  29166. rect = this._rect;
  29167. rect.copy(target); // Update center
  29168. this.center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  29169. },
  29170. cloneShallow: function (name) {
  29171. name == null && (name = this.name);
  29172. var newRegion = new Region(name, this.geometries, this.center);
  29173. newRegion._rect = this._rect;
  29174. newRegion.transformTo = null; // Simply avoid to be called.
  29175. return newRegion;
  29176. }
  29177. };
  29178. /*
  29179. * Licensed to the Apache Software Foundation (ASF) under one
  29180. * or more contributor license agreements. See the NOTICE file
  29181. * distributed with this work for additional information
  29182. * regarding copyright ownership. The ASF licenses this file
  29183. * to you under the Apache License, Version 2.0 (the
  29184. * "License"); you may not use this file except in compliance
  29185. * with the License. You may obtain a copy of the License at
  29186. *
  29187. * http://www.apache.org/licenses/LICENSE-2.0
  29188. *
  29189. * Unless required by applicable law or agreed to in writing,
  29190. * software distributed under the License is distributed on an
  29191. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29192. * KIND, either express or implied. See the License for the
  29193. * specific language governing permissions and limitations
  29194. * under the License.
  29195. */
  29196. /**
  29197. * Parse and decode geo json
  29198. * @module echarts/coord/geo/parseGeoJson
  29199. */
  29200. function decode(json) {
  29201. if (!json.UTF8Encoding) {
  29202. return json;
  29203. }
  29204. var encodeScale = json.UTF8Scale;
  29205. if (encodeScale == null) {
  29206. encodeScale = 1024;
  29207. }
  29208. var features = json.features;
  29209. for (var f = 0; f < features.length; f++) {
  29210. var feature = features[f];
  29211. var geometry = feature.geometry;
  29212. var coordinates = geometry.coordinates;
  29213. var encodeOffsets = geometry.encodeOffsets;
  29214. for (var c = 0; c < coordinates.length; c++) {
  29215. var coordinate = coordinates[c];
  29216. if (geometry.type === 'Polygon') {
  29217. coordinates[c] = decodePolygon(coordinate, encodeOffsets[c], encodeScale);
  29218. } else if (geometry.type === 'MultiPolygon') {
  29219. for (var c2 = 0; c2 < coordinate.length; c2++) {
  29220. var polygon = coordinate[c2];
  29221. coordinate[c2] = decodePolygon(polygon, encodeOffsets[c][c2], encodeScale);
  29222. }
  29223. }
  29224. }
  29225. } // Has been decoded
  29226. json.UTF8Encoding = false;
  29227. return json;
  29228. }
  29229. function decodePolygon(coordinate, encodeOffsets, encodeScale) {
  29230. var result = [];
  29231. var prevX = encodeOffsets[0];
  29232. var prevY = encodeOffsets[1];
  29233. for (var i = 0; i < coordinate.length; i += 2) {
  29234. var x = coordinate.charCodeAt(i) - 64;
  29235. var y = coordinate.charCodeAt(i + 1) - 64; // ZigZag decoding
  29236. x = x >> 1 ^ -(x & 1);
  29237. y = y >> 1 ^ -(y & 1); // Delta deocding
  29238. x += prevX;
  29239. y += prevY;
  29240. prevX = x;
  29241. prevY = y; // Dequantize
  29242. result.push([x / encodeScale, y / encodeScale]);
  29243. }
  29244. return result;
  29245. }
  29246. /**
  29247. * @alias module:echarts/coord/geo/parseGeoJson
  29248. * @param {Object} geoJson
  29249. * @param {string} nameProperty
  29250. * @return {module:zrender/container/Group}
  29251. */
  29252. var parseGeoJSON = function (geoJson, nameProperty) {
  29253. decode(geoJson);
  29254. return map(filter(geoJson.features, function (featureObj) {
  29255. // Output of mapshaper may have geometry null
  29256. return featureObj.geometry && featureObj.properties && featureObj.geometry.coordinates.length > 0;
  29257. }), function (featureObj) {
  29258. var properties = featureObj.properties;
  29259. var geo = featureObj.geometry;
  29260. var coordinates = geo.coordinates;
  29261. var geometries = [];
  29262. if (geo.type === 'Polygon') {
  29263. geometries.push({
  29264. type: 'polygon',
  29265. // According to the GeoJSON specification.
  29266. // First must be exterior, and the rest are all interior(holes).
  29267. exterior: coordinates[0],
  29268. interiors: coordinates.slice(1)
  29269. });
  29270. }
  29271. if (geo.type === 'MultiPolygon') {
  29272. each$1(coordinates, function (item) {
  29273. if (item[0]) {
  29274. geometries.push({
  29275. type: 'polygon',
  29276. exterior: item[0],
  29277. interiors: item.slice(1)
  29278. });
  29279. }
  29280. });
  29281. }
  29282. var region = new Region(properties[nameProperty || 'name'], geometries, properties.cp);
  29283. region.properties = properties;
  29284. return region;
  29285. });
  29286. };
  29287. /*
  29288. * Licensed to the Apache Software Foundation (ASF) under one
  29289. * or more contributor license agreements. See the NOTICE file
  29290. * distributed with this work for additional information
  29291. * regarding copyright ownership. The ASF licenses this file
  29292. * to you under the Apache License, Version 2.0 (the
  29293. * "License"); you may not use this file except in compliance
  29294. * with the License. You may obtain a copy of the License at
  29295. *
  29296. * http://www.apache.org/licenses/LICENSE-2.0
  29297. *
  29298. * Unless required by applicable law or agreed to in writing,
  29299. * software distributed under the License is distributed on an
  29300. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29301. * KIND, either express or implied. See the License for the
  29302. * specific language governing permissions and limitations
  29303. * under the License.
  29304. */
  29305. var inner$6 = makeInner();
  29306. /**
  29307. * @param {module:echats/coord/Axis} axis
  29308. * @return {Object} {
  29309. * labels: [{
  29310. * formattedLabel: string,
  29311. * rawLabel: string,
  29312. * tickValue: number
  29313. * }, ...],
  29314. * labelCategoryInterval: number
  29315. * }
  29316. */
  29317. function createAxisLabels(axis) {
  29318. // Only ordinal scale support tick interval
  29319. return axis.type === 'category' ? makeCategoryLabels(axis) : makeRealNumberLabels(axis);
  29320. }
  29321. /**
  29322. * @param {module:echats/coord/Axis} axis
  29323. * @param {module:echarts/model/Model} tickModel For example, can be axisTick, splitLine, splitArea.
  29324. * @return {Object} {
  29325. * ticks: Array.<number>
  29326. * tickCategoryInterval: number
  29327. * }
  29328. */
  29329. function createAxisTicks(axis, tickModel) {
  29330. // Only ordinal scale support tick interval
  29331. return axis.type === 'category' ? makeCategoryTicks(axis, tickModel) : {
  29332. ticks: axis.scale.getTicks()
  29333. };
  29334. }
  29335. function makeCategoryLabels(axis) {
  29336. var labelModel = axis.getLabelModel();
  29337. var result = makeCategoryLabelsActually(axis, labelModel);
  29338. return !labelModel.get('show') || axis.scale.isBlank() ? {
  29339. labels: [],
  29340. labelCategoryInterval: result.labelCategoryInterval
  29341. } : result;
  29342. }
  29343. function makeCategoryLabelsActually(axis, labelModel) {
  29344. var labelsCache = getListCache(axis, 'labels');
  29345. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  29346. var result = listCacheGet(labelsCache, optionLabelInterval);
  29347. if (result) {
  29348. return result;
  29349. }
  29350. var labels;
  29351. var numericLabelInterval;
  29352. if (isFunction$1(optionLabelInterval)) {
  29353. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  29354. } else {
  29355. numericLabelInterval = optionLabelInterval === 'auto' ? makeAutoCategoryInterval(axis) : optionLabelInterval;
  29356. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  29357. } // Cache to avoid calling interval function repeatly.
  29358. return listCacheSet(labelsCache, optionLabelInterval, {
  29359. labels: labels,
  29360. labelCategoryInterval: numericLabelInterval
  29361. });
  29362. }
  29363. function makeCategoryTicks(axis, tickModel) {
  29364. var ticksCache = getListCache(axis, 'ticks');
  29365. var optionTickInterval = getOptionCategoryInterval(tickModel);
  29366. var result = listCacheGet(ticksCache, optionTickInterval);
  29367. if (result) {
  29368. return result;
  29369. }
  29370. var ticks;
  29371. var tickCategoryInterval; // Optimize for the case that large category data and no label displayed,
  29372. // we should not return all ticks.
  29373. if (!tickModel.get('show') || axis.scale.isBlank()) {
  29374. ticks = [];
  29375. }
  29376. if (isFunction$1(optionTickInterval)) {
  29377. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  29378. } // Always use label interval by default despite label show. Consider this
  29379. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  29380. // labels. `splitLine` and `axisTick` should be consistent in this case.
  29381. else if (optionTickInterval === 'auto') {
  29382. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel());
  29383. tickCategoryInterval = labelsResult.labelCategoryInterval;
  29384. ticks = map(labelsResult.labels, function (labelItem) {
  29385. return labelItem.tickValue;
  29386. });
  29387. } else {
  29388. tickCategoryInterval = optionTickInterval;
  29389. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  29390. } // Cache to avoid calling interval function repeatly.
  29391. return listCacheSet(ticksCache, optionTickInterval, {
  29392. ticks: ticks,
  29393. tickCategoryInterval: tickCategoryInterval
  29394. });
  29395. }
  29396. function makeRealNumberLabels(axis) {
  29397. var ticks = axis.scale.getTicks();
  29398. var labelFormatter = makeLabelFormatter(axis);
  29399. return {
  29400. labels: map(ticks, function (tickValue, idx) {
  29401. return {
  29402. formattedLabel: labelFormatter(tickValue, idx),
  29403. rawLabel: axis.scale.getLabel(tickValue),
  29404. tickValue: tickValue
  29405. };
  29406. })
  29407. };
  29408. } // Large category data calculation is performence sensitive, and ticks and label
  29409. // probably be fetched by multiple times. So we cache the result.
  29410. // axis is created each time during a ec process, so we do not need to clear cache.
  29411. function getListCache(axis, prop) {
  29412. // Because key can be funciton, and cache size always be small, we use array cache.
  29413. return inner$6(axis)[prop] || (inner$6(axis)[prop] = []);
  29414. }
  29415. function listCacheGet(cache, key) {
  29416. for (var i = 0; i < cache.length; i++) {
  29417. if (cache[i].key === key) {
  29418. return cache[i].value;
  29419. }
  29420. }
  29421. }
  29422. function listCacheSet(cache, key, value) {
  29423. cache.push({
  29424. key: key,
  29425. value: value
  29426. });
  29427. return value;
  29428. }
  29429. function makeAutoCategoryInterval(axis) {
  29430. var result = inner$6(axis).autoInterval;
  29431. return result != null ? result : inner$6(axis).autoInterval = axis.calculateCategoryInterval();
  29432. }
  29433. /**
  29434. * Calculate interval for category axis ticks and labels.
  29435. * To get precise result, at least one of `getRotate` and `isHorizontal`
  29436. * should be implemented in axis.
  29437. */
  29438. function calculateCategoryInterval(axis) {
  29439. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  29440. var labelFormatter = makeLabelFormatter(axis);
  29441. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  29442. var ordinalScale = axis.scale;
  29443. var ordinalExtent = ordinalScale.getExtent(); // Providing this method is for optimization:
  29444. // avoid generating a long array by `getTicks`
  29445. // in large category data case.
  29446. var tickCount = ordinalScale.count();
  29447. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  29448. return 0;
  29449. }
  29450. var step = 1; // Simple optimization. Empirical value: tick count should less than 40.
  29451. if (tickCount > 40) {
  29452. step = Math.max(1, Math.floor(tickCount / 40));
  29453. }
  29454. var tickValue = ordinalExtent[0];
  29455. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  29456. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  29457. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  29458. var maxW = 0;
  29459. var maxH = 0; // Caution: Performance sensitive for large category data.
  29460. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  29461. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  29462. var width = 0;
  29463. var height = 0; // Not precise, do not consider align and vertical align
  29464. // and each distance from axis line yet.
  29465. var rect = getBoundingRect(labelFormatter(tickValue), params.font, 'center', 'top'); // Magic number
  29466. width = rect.width * 1.3;
  29467. height = rect.height * 1.3; // Min size, void long loop.
  29468. maxW = Math.max(maxW, width, 7);
  29469. maxH = Math.max(maxH, height, 7);
  29470. }
  29471. var dw = maxW / unitW;
  29472. var dh = maxH / unitH; // 0/0 is NaN, 1/0 is Infinity.
  29473. isNaN(dw) && (dw = Infinity);
  29474. isNaN(dh) && (dh = Infinity);
  29475. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  29476. var cache = inner$6(axis.model);
  29477. var axisExtent = axis.getExtent();
  29478. var lastAutoInterval = cache.lastAutoInterval;
  29479. var lastTickCount = cache.lastTickCount; // Use cache to keep interval stable while moving zoom window,
  29480. // otherwise the calculated interval might jitter when the zoom
  29481. // window size is close to the interval-changing size.
  29482. // For example, if all of the axis labels are `a, b, c, d, e, f, g`.
  29483. // The jitter will cause that sometimes the displayed labels are
  29484. // `a, d, g` (interval: 2) sometimes `a, c, e`(interval: 1).
  29485. if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1 // Always choose the bigger one, otherwise the critical
  29486. // point is not the same when zooming in or zooming out.
  29487. && lastAutoInterval > interval // If the axis change is caused by chart resize, the cache should not
  29488. // be used. Otherwise some hiden labels might not be shown again.
  29489. && cache.axisExtend0 === axisExtent[0] && cache.axisExtend1 === axisExtent[1]) {
  29490. interval = lastAutoInterval;
  29491. } // Only update cache if cache not used, otherwise the
  29492. // changing of interval is too insensitive.
  29493. else {
  29494. cache.lastTickCount = tickCount;
  29495. cache.lastAutoInterval = interval;
  29496. cache.axisExtend0 = axisExtent[0];
  29497. cache.axisExtend1 = axisExtent[1];
  29498. }
  29499. return interval;
  29500. }
  29501. function fetchAutoCategoryIntervalCalculationParams(axis) {
  29502. var labelModel = axis.getLabelModel();
  29503. return {
  29504. axisRotate: axis.getRotate ? axis.getRotate() : axis.isHorizontal && !axis.isHorizontal() ? 90 : 0,
  29505. labelRotate: labelModel.get('rotate') || 0,
  29506. font: labelModel.getFont()
  29507. };
  29508. }
  29509. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  29510. var labelFormatter = makeLabelFormatter(axis);
  29511. var ordinalScale = axis.scale;
  29512. var ordinalExtent = ordinalScale.getExtent();
  29513. var labelModel = axis.getLabelModel();
  29514. var result = []; // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  29515. var step = Math.max((categoryInterval || 0) + 1, 1);
  29516. var startTick = ordinalExtent[0];
  29517. var tickCount = ordinalScale.count(); // Calculate start tick based on zero if possible to keep label consistent
  29518. // while zooming and moving while interval > 0. Otherwise the selection
  29519. // of displayable ticks and symbols probably keep changing.
  29520. // 3 is empirical value.
  29521. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  29522. startTick = Math.round(Math.ceil(startTick / step) * step);
  29523. } // (1) Only add min max label here but leave overlap checking
  29524. // to render stage, which also ensure the returned list
  29525. // suitable for splitLine and splitArea rendering.
  29526. // (2) Scales except category always contain min max label so
  29527. // do not need to perform this process.
  29528. var showAllLabel = shouldShowAllLabels(axis);
  29529. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  29530. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  29531. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  29532. addItem(ordinalExtent[0]);
  29533. } // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  29534. var tickValue = startTick;
  29535. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  29536. addItem(tickValue);
  29537. }
  29538. if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
  29539. addItem(ordinalExtent[1]);
  29540. }
  29541. function addItem(tVal) {
  29542. result.push(onlyTick ? tVal : {
  29543. formattedLabel: labelFormatter(tVal),
  29544. rawLabel: ordinalScale.getLabel(tVal),
  29545. tickValue: tVal
  29546. });
  29547. }
  29548. return result;
  29549. } // When interval is function, the result `false` means ignore the tick.
  29550. // It is time consuming for large category data.
  29551. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  29552. var ordinalScale = axis.scale;
  29553. var labelFormatter = makeLabelFormatter(axis);
  29554. var result = [];
  29555. each$1(ordinalScale.getTicks(), function (tickValue) {
  29556. var rawLabel = ordinalScale.getLabel(tickValue);
  29557. if (categoryInterval(tickValue, rawLabel)) {
  29558. result.push(onlyTick ? tickValue : {
  29559. formattedLabel: labelFormatter(tickValue),
  29560. rawLabel: rawLabel,
  29561. tickValue: tickValue
  29562. });
  29563. }
  29564. });
  29565. return result;
  29566. }
  29567. /*
  29568. * Licensed to the Apache Software Foundation (ASF) under one
  29569. * or more contributor license agreements. See the NOTICE file
  29570. * distributed with this work for additional information
  29571. * regarding copyright ownership. The ASF licenses this file
  29572. * to you under the Apache License, Version 2.0 (the
  29573. * "License"); you may not use this file except in compliance
  29574. * with the License. You may obtain a copy of the License at
  29575. *
  29576. * http://www.apache.org/licenses/LICENSE-2.0
  29577. *
  29578. * Unless required by applicable law or agreed to in writing,
  29579. * software distributed under the License is distributed on an
  29580. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29581. * KIND, either express or implied. See the License for the
  29582. * specific language governing permissions and limitations
  29583. * under the License.
  29584. */
  29585. var NORMALIZED_EXTENT = [0, 1];
  29586. /**
  29587. * Base class of Axis.
  29588. * @constructor
  29589. */
  29590. var Axis = function (dim, scale, extent) {
  29591. /**
  29592. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'.
  29593. * @type {string}
  29594. */
  29595. this.dim = dim;
  29596. /**
  29597. * Axis scale
  29598. * @type {module:echarts/coord/scale/*}
  29599. */
  29600. this.scale = scale;
  29601. /**
  29602. * @type {Array.<number>}
  29603. * @private
  29604. */
  29605. this._extent = extent || [0, 0];
  29606. /**
  29607. * @type {boolean}
  29608. */
  29609. this.inverse = false;
  29610. /**
  29611. * Usually true when axis has a ordinal scale
  29612. * @type {boolean}
  29613. */
  29614. this.onBand = false;
  29615. };
  29616. Axis.prototype = {
  29617. constructor: Axis,
  29618. /**
  29619. * If axis extent contain given coord
  29620. * @param {number} coord
  29621. * @return {boolean}
  29622. */
  29623. contain: function (coord) {
  29624. var extent = this._extent;
  29625. var min = Math.min(extent[0], extent[1]);
  29626. var max = Math.max(extent[0], extent[1]);
  29627. return coord >= min && coord <= max;
  29628. },
  29629. /**
  29630. * If axis extent contain given data
  29631. * @param {number} data
  29632. * @return {boolean}
  29633. */
  29634. containData: function (data) {
  29635. return this.scale.contain(data);
  29636. },
  29637. /**
  29638. * Get coord extent.
  29639. * @return {Array.<number>}
  29640. */
  29641. getExtent: function () {
  29642. return this._extent.slice();
  29643. },
  29644. /**
  29645. * Get precision used for formatting
  29646. * @param {Array.<number>} [dataExtent]
  29647. * @return {number}
  29648. */
  29649. getPixelPrecision: function (dataExtent) {
  29650. return getPixelPrecision(dataExtent || this.scale.getExtent(), this._extent);
  29651. },
  29652. /**
  29653. * Set coord extent
  29654. * @param {number} start
  29655. * @param {number} end
  29656. */
  29657. setExtent: function (start, end) {
  29658. var extent = this._extent;
  29659. extent[0] = start;
  29660. extent[1] = end;
  29661. },
  29662. /**
  29663. * Convert data to coord. Data is the rank if it has an ordinal scale
  29664. * @param {number} data
  29665. * @param {boolean} clamp
  29666. * @return {number}
  29667. */
  29668. dataToCoord: function (data, clamp) {
  29669. var extent = this._extent;
  29670. var scale = this.scale;
  29671. data = scale.normalize(data);
  29672. if (this.onBand && scale.type === 'ordinal') {
  29673. extent = extent.slice();
  29674. fixExtentWithBands(extent, scale.count());
  29675. }
  29676. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  29677. },
  29678. /**
  29679. * Convert coord to data. Data is the rank if it has an ordinal scale
  29680. * @param {number} coord
  29681. * @param {boolean} clamp
  29682. * @return {number}
  29683. */
  29684. coordToData: function (coord, clamp) {
  29685. var extent = this._extent;
  29686. var scale = this.scale;
  29687. if (this.onBand && scale.type === 'ordinal') {
  29688. extent = extent.slice();
  29689. fixExtentWithBands(extent, scale.count());
  29690. }
  29691. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  29692. return this.scale.scale(t);
  29693. },
  29694. /**
  29695. * Convert pixel point to data in axis
  29696. * @param {Array.<number>} point
  29697. * @param {boolean} clamp
  29698. * @return {number} data
  29699. */
  29700. pointToData: function (point, clamp) {// Should be implemented in derived class if necessary.
  29701. },
  29702. /**
  29703. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  29704. * `axis.getTicksCoords` considers `onBand`, which is used by
  29705. * `boundaryGap:true` of category axis and splitLine and splitArea.
  29706. * @param {Object} [opt]
  29707. * @param {Model} [opt.tickModel=axis.model.getModel('axisTick')]
  29708. * @param {boolean} [opt.clamp] If `true`, the first and the last
  29709. * tick must be at the axis end points. Otherwise, clip ticks
  29710. * that outside the axis extent.
  29711. * @return {Array.<Object>} [{
  29712. * coord: ...,
  29713. * tickValue: ...
  29714. * }, ...]
  29715. */
  29716. getTicksCoords: function (opt) {
  29717. opt = opt || {};
  29718. var tickModel = opt.tickModel || this.getTickModel();
  29719. var result = createAxisTicks(this, tickModel);
  29720. var ticks = result.ticks;
  29721. var ticksCoords = map(ticks, function (tickValue) {
  29722. return {
  29723. coord: this.dataToCoord(tickValue),
  29724. tickValue: tickValue
  29725. };
  29726. }, this);
  29727. var alignWithLabel = tickModel.get('alignWithLabel');
  29728. fixOnBandTicksCoords(this, ticksCoords, alignWithLabel, opt.clamp);
  29729. return ticksCoords;
  29730. },
  29731. /**
  29732. * @return {Array.<Array.<Object>>} [{ coord: ..., tickValue: ...}]
  29733. */
  29734. getMinorTicksCoords: function () {
  29735. if (this.scale.type === 'ordinal') {
  29736. // Category axis doesn't support minor ticks
  29737. return [];
  29738. }
  29739. var minorTickModel = this.model.getModel('minorTick');
  29740. var splitNumber = minorTickModel.get('splitNumber'); // Protection.
  29741. if (!(splitNumber > 0 && splitNumber < 100)) {
  29742. splitNumber = 5;
  29743. }
  29744. var minorTicks = this.scale.getMinorTicks(splitNumber);
  29745. var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
  29746. return map(minorTicksGroup, function (minorTick) {
  29747. return {
  29748. coord: this.dataToCoord(minorTick),
  29749. tickValue: minorTick
  29750. };
  29751. }, this);
  29752. }, this);
  29753. return minorTicksCoords;
  29754. },
  29755. /**
  29756. * @return {Array.<Object>} [{
  29757. * formattedLabel: string,
  29758. * rawLabel: axis.scale.getLabel(tickValue)
  29759. * tickValue: number
  29760. * }, ...]
  29761. */
  29762. getViewLabels: function () {
  29763. return createAxisLabels(this).labels;
  29764. },
  29765. /**
  29766. * @return {module:echarts/coord/model/Model}
  29767. */
  29768. getLabelModel: function () {
  29769. return this.model.getModel('axisLabel');
  29770. },
  29771. /**
  29772. * Notice here we only get the default tick model. For splitLine
  29773. * or splitArea, we should pass the splitLineModel or splitAreaModel
  29774. * manually when calling `getTicksCoords`.
  29775. * In GL, this method may be overrided to:
  29776. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  29777. * @return {module:echarts/coord/model/Model}
  29778. */
  29779. getTickModel: function () {
  29780. return this.model.getModel('axisTick');
  29781. },
  29782. /**
  29783. * Get width of band
  29784. * @return {number}
  29785. */
  29786. getBandWidth: function () {
  29787. var axisExtent = this._extent;
  29788. var dataExtent = this.scale.getExtent();
  29789. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0); // Fix #2728, avoid NaN when only one data.
  29790. len === 0 && (len = 1);
  29791. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  29792. return Math.abs(size) / len;
  29793. },
  29794. /**
  29795. * @abstract
  29796. * @return {boolean} Is horizontal
  29797. */
  29798. isHorizontal: null,
  29799. /**
  29800. * @abstract
  29801. * @return {number} Get axis rotate, by degree.
  29802. */
  29803. getRotate: null,
  29804. /**
  29805. * Only be called in category axis.
  29806. * Can be overrided, consider other axes like in 3D.
  29807. * @return {number} Auto interval for cateogry axis tick and label
  29808. */
  29809. calculateCategoryInterval: function () {
  29810. return calculateCategoryInterval(this);
  29811. }
  29812. };
  29813. function fixExtentWithBands(extent, nTick) {
  29814. var size = extent[1] - extent[0];
  29815. var len = nTick;
  29816. var margin = size / len / 2;
  29817. extent[0] += margin;
  29818. extent[1] -= margin;
  29819. } // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  29820. // |---1---|---2---|---3---|---4---|.
  29821. // So the displayed ticks and splitLine/splitArea should between
  29822. // each data item, otherwise cause misleading (e.g., split tow bars
  29823. // of a single data item when there are two bar series).
  29824. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  29825. // splitLine/spliteArea should layout appropriately corresponding
  29826. // to displayed labels. (So we should not use `getBandWidth` in this
  29827. // case).
  29828. function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) {
  29829. var ticksLen = ticksCoords.length;
  29830. if (!axis.onBand || alignWithLabel || !ticksLen) {
  29831. return;
  29832. }
  29833. var axisExtent = axis.getExtent();
  29834. var last;
  29835. var diffSize;
  29836. if (ticksLen === 1) {
  29837. ticksCoords[0].coord = axisExtent[0];
  29838. last = ticksCoords[1] = {
  29839. coord: axisExtent[0]
  29840. };
  29841. } else {
  29842. var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
  29843. var shift = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen;
  29844. each$1(ticksCoords, function (ticksItem) {
  29845. ticksItem.coord -= shift / 2;
  29846. });
  29847. var dataExtent = axis.scale.getExtent();
  29848. diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
  29849. last = {
  29850. coord: ticksCoords[ticksLen - 1].coord + shift * diffSize
  29851. };
  29852. ticksCoords.push(last);
  29853. }
  29854. var inverse = axisExtent[0] > axisExtent[1]; // Handling clamp.
  29855. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  29856. clamp ? ticksCoords[0].coord = axisExtent[0] : ticksCoords.shift();
  29857. }
  29858. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  29859. ticksCoords.unshift({
  29860. coord: axisExtent[0]
  29861. });
  29862. }
  29863. if (littleThan(axisExtent[1], last.coord)) {
  29864. clamp ? last.coord = axisExtent[1] : ticksCoords.pop();
  29865. }
  29866. if (clamp && littleThan(last.coord, axisExtent[1])) {
  29867. ticksCoords.push({
  29868. coord: axisExtent[1]
  29869. });
  29870. }
  29871. function littleThan(a, b) {
  29872. // Avoid rounding error cause calculated tick coord different with extent.
  29873. // It may cause an extra unecessary tick added.
  29874. a = round$1(a);
  29875. b = round$1(b);
  29876. return inverse ? a > b : a < b;
  29877. }
  29878. }
  29879. /*
  29880. * Licensed to the Apache Software Foundation (ASF) under one
  29881. * or more contributor license agreements. See the NOTICE file
  29882. * distributed with this work for additional information
  29883. * regarding copyright ownership. The ASF licenses this file
  29884. * to you under the Apache License, Version 2.0 (the
  29885. * "License"); you may not use this file except in compliance
  29886. * with the License. You may obtain a copy of the License at
  29887. *
  29888. * http://www.apache.org/licenses/LICENSE-2.0
  29889. *
  29890. * Unless required by applicable law or agreed to in writing,
  29891. * software distributed under the License is distributed on an
  29892. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29893. * KIND, either express or implied. See the License for the
  29894. * specific language governing permissions and limitations
  29895. * under the License.
  29896. */
  29897. /**
  29898. * Do not mount those modules on 'src/echarts' for better tree shaking.
  29899. */
  29900. var parseGeoJson = parseGeoJSON;
  29901. var ecUtil = {};
  29902. each$1(['map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter', 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction', 'extend', 'defaults', 'clone', 'merge'], function (name) {
  29903. ecUtil[name] = zrUtil[name];
  29904. });
  29905. var graphic = {};
  29906. each$1(['extendShape', 'extendPath', 'makePath', 'makeImage', 'mergePath', 'resizePath', 'createIcon', 'setHoverStyle', 'setLabelStyle', 'setTextStyle', 'setText', 'getFont', 'updateProps', 'initProps', 'getTransform', 'clipPointsByRect', 'clipRectByRect', 'registerShape', 'getShapeClass', 'Group', 'Image', 'Text', 'Circle', 'Sector', 'Ring', 'Polygon', 'Polyline', 'Rect', 'Line', 'BezierCurve', 'Arc', 'IncrementalDisplayable', 'CompoundPath', 'LinearGradient', 'RadialGradient', 'BoundingRect'], function (name) {
  29907. graphic[name] = graphicUtil[name];
  29908. });
  29909. /*
  29910. * Licensed to the Apache Software Foundation (ASF) under one
  29911. * or more contributor license agreements. See the NOTICE file
  29912. * distributed with this work for additional information
  29913. * regarding copyright ownership. The ASF licenses this file
  29914. * to you under the Apache License, Version 2.0 (the
  29915. * "License"); you may not use this file except in compliance
  29916. * with the License. You may obtain a copy of the License at
  29917. *
  29918. * http://www.apache.org/licenses/LICENSE-2.0
  29919. *
  29920. * Unless required by applicable law or agreed to in writing,
  29921. * software distributed under the License is distributed on an
  29922. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29923. * KIND, either express or implied. See the License for the
  29924. * specific language governing permissions and limitations
  29925. * under the License.
  29926. */
  29927. SeriesModel.extend({
  29928. type: 'series.line',
  29929. dependencies: ['grid', 'polar'],
  29930. getInitialData: function (option, ecModel) {
  29931. if (__DEV__) {
  29932. var coordSys = option.coordinateSystem;
  29933. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  29934. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  29935. }
  29936. }
  29937. return createListFromArray(this.getSource(), this, {
  29938. useEncodeDefaulter: true
  29939. });
  29940. },
  29941. defaultOption: {
  29942. zlevel: 0,
  29943. z: 2,
  29944. coordinateSystem: 'cartesian2d',
  29945. legendHoverLink: true,
  29946. hoverAnimation: true,
  29947. // stack: null
  29948. // xAxisIndex: 0,
  29949. // yAxisIndex: 0,
  29950. // polarIndex: 0,
  29951. // If clip the overflow value
  29952. clip: true,
  29953. // cursor: null,
  29954. label: {
  29955. position: 'top'
  29956. },
  29957. // itemStyle: {
  29958. // },
  29959. lineStyle: {
  29960. width: 2,
  29961. type: 'solid'
  29962. },
  29963. // areaStyle: {
  29964. // origin of areaStyle. Valid values:
  29965. // `'auto'/null/undefined`: from axisLine to data
  29966. // `'start'`: from min to data
  29967. // `'end'`: from data to max
  29968. // origin: 'auto'
  29969. // },
  29970. // false, 'start', 'end', 'middle'
  29971. step: false,
  29972. // Disabled if step is true
  29973. smooth: false,
  29974. smoothMonotone: null,
  29975. symbol: 'emptyCircle',
  29976. symbolSize: 4,
  29977. symbolRotate: null,
  29978. showSymbol: true,
  29979. // `false`: follow the label interval strategy.
  29980. // `true`: show all symbols.
  29981. // `'auto'`: If possible, show all symbols, otherwise
  29982. // follow the label interval strategy.
  29983. showAllSymbol: 'auto',
  29984. // Whether to connect break point.
  29985. connectNulls: false,
  29986. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum'.
  29987. sampling: 'none',
  29988. animationEasing: 'linear',
  29989. // Disable progressive
  29990. progressive: 0,
  29991. hoverLayerThreshold: Infinity
  29992. }
  29993. });
  29994. /*
  29995. * Licensed to the Apache Software Foundation (ASF) under one
  29996. * or more contributor license agreements. See the NOTICE file
  29997. * distributed with this work for additional information
  29998. * regarding copyright ownership. The ASF licenses this file
  29999. * to you under the Apache License, Version 2.0 (the
  30000. * "License"); you may not use this file except in compliance
  30001. * with the License. You may obtain a copy of the License at
  30002. *
  30003. * http://www.apache.org/licenses/LICENSE-2.0
  30004. *
  30005. * Unless required by applicable law or agreed to in writing,
  30006. * software distributed under the License is distributed on an
  30007. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30008. * KIND, either express or implied. See the License for the
  30009. * specific language governing permissions and limitations
  30010. * under the License.
  30011. */
  30012. /**
  30013. * @param {module:echarts/data/List} data
  30014. * @param {number} dataIndex
  30015. * @return {string} label string. Not null/undefined
  30016. */
  30017. function getDefaultLabel(data, dataIndex) {
  30018. var labelDims = data.mapDimension('defaultedLabel', true);
  30019. var len = labelDims.length; // Simple optimization (in lots of cases, label dims length is 1)
  30020. if (len === 1) {
  30021. return retrieveRawValue(data, dataIndex, labelDims[0]);
  30022. } else if (len) {
  30023. var vals = [];
  30024. for (var i = 0; i < labelDims.length; i++) {
  30025. var val = retrieveRawValue(data, dataIndex, labelDims[i]);
  30026. vals.push(val);
  30027. }
  30028. return vals.join(' ');
  30029. }
  30030. }
  30031. /*
  30032. * Licensed to the Apache Software Foundation (ASF) under one
  30033. * or more contributor license agreements. See the NOTICE file
  30034. * distributed with this work for additional information
  30035. * regarding copyright ownership. The ASF licenses this file
  30036. * to you under the Apache License, Version 2.0 (the
  30037. * "License"); you may not use this file except in compliance
  30038. * with the License. You may obtain a copy of the License at
  30039. *
  30040. * http://www.apache.org/licenses/LICENSE-2.0
  30041. *
  30042. * Unless required by applicable law or agreed to in writing,
  30043. * software distributed under the License is distributed on an
  30044. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30045. * KIND, either express or implied. See the License for the
  30046. * specific language governing permissions and limitations
  30047. * under the License.
  30048. */
  30049. /**
  30050. * @module echarts/chart/helper/Symbol
  30051. */
  30052. /**
  30053. * @constructor
  30054. * @alias {module:echarts/chart/helper/Symbol}
  30055. * @param {module:echarts/data/List} data
  30056. * @param {number} idx
  30057. * @extends {module:zrender/graphic/Group}
  30058. */
  30059. function SymbolClz$1(data, idx, seriesScope) {
  30060. Group.call(this);
  30061. this.updateData(data, idx, seriesScope);
  30062. }
  30063. var symbolProto = SymbolClz$1.prototype;
  30064. /**
  30065. * @public
  30066. * @static
  30067. * @param {module:echarts/data/List} data
  30068. * @param {number} dataIndex
  30069. * @return {Array.<number>} [width, height]
  30070. */
  30071. var getSymbolSize = SymbolClz$1.getSymbolSize = function (data, idx) {
  30072. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  30073. return symbolSize instanceof Array ? symbolSize.slice() : [+symbolSize, +symbolSize];
  30074. };
  30075. function getScale(symbolSize) {
  30076. return [symbolSize[0] / 2, symbolSize[1] / 2];
  30077. }
  30078. function driftSymbol(dx, dy) {
  30079. this.parent.drift(dx, dy);
  30080. }
  30081. symbolProto._createSymbol = function (symbolType, data, idx, symbolSize, keepAspect) {
  30082. // Remove paths created before
  30083. this.removeAll();
  30084. var color = data.getItemVisual(idx, 'color'); // var symbolPath = createSymbol(
  30085. // symbolType, -0.5, -0.5, 1, 1, color
  30086. // );
  30087. // If width/height are set too small (e.g., set to 1) on ios10
  30088. // and macOS Sierra, a circle stroke become a rect, no matter what
  30089. // the scale is set. So we set width/height as 2. See #4150.
  30090. var symbolPath = createSymbol(symbolType, -1, -1, 2, 2, color, keepAspect);
  30091. symbolPath.attr({
  30092. z2: 100,
  30093. culling: true,
  30094. scale: getScale(symbolSize)
  30095. }); // Rewrite drift method
  30096. symbolPath.drift = driftSymbol;
  30097. this._symbolType = symbolType;
  30098. this.add(symbolPath);
  30099. };
  30100. /**
  30101. * Stop animation
  30102. * @param {boolean} toLastFrame
  30103. */
  30104. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  30105. this.childAt(0).stopAnimation(toLastFrame);
  30106. };
  30107. /**
  30108. * FIXME:
  30109. * Caution: This method breaks the encapsulation of this module,
  30110. * but it indeed brings convenience. So do not use the method
  30111. * unless you detailedly know all the implements of `Symbol`,
  30112. * especially animation.
  30113. *
  30114. * Get symbol path element.
  30115. */
  30116. symbolProto.getSymbolPath = function () {
  30117. return this.childAt(0);
  30118. };
  30119. /**
  30120. * Get scale(aka, current symbol size).
  30121. * Including the change caused by animation
  30122. */
  30123. symbolProto.getScale = function () {
  30124. return this.childAt(0).scale;
  30125. };
  30126. /**
  30127. * Highlight symbol
  30128. */
  30129. symbolProto.highlight = function () {
  30130. this.childAt(0).trigger('emphasis');
  30131. };
  30132. /**
  30133. * Downplay symbol
  30134. */
  30135. symbolProto.downplay = function () {
  30136. this.childAt(0).trigger('normal');
  30137. };
  30138. /**
  30139. * @param {number} zlevel
  30140. * @param {number} z
  30141. */
  30142. symbolProto.setZ = function (zlevel, z) {
  30143. var symbolPath = this.childAt(0);
  30144. symbolPath.zlevel = zlevel;
  30145. symbolPath.z = z;
  30146. };
  30147. symbolProto.setDraggable = function (draggable) {
  30148. var symbolPath = this.childAt(0);
  30149. symbolPath.draggable = draggable;
  30150. symbolPath.cursor = draggable ? 'move' : symbolPath.cursor;
  30151. };
  30152. /**
  30153. * Update symbol properties
  30154. * @param {module:echarts/data/List} data
  30155. * @param {number} idx
  30156. * @param {Object} [seriesScope]
  30157. * @param {Object} [seriesScope.itemStyle]
  30158. * @param {Object} [seriesScope.hoverItemStyle]
  30159. * @param {Object} [seriesScope.symbolRotate]
  30160. * @param {Object} [seriesScope.symbolOffset]
  30161. * @param {module:echarts/model/Model} [seriesScope.labelModel]
  30162. * @param {module:echarts/model/Model} [seriesScope.hoverLabelModel]
  30163. * @param {boolean} [seriesScope.hoverAnimation]
  30164. * @param {Object} [seriesScope.cursorStyle]
  30165. * @param {module:echarts/model/Model} [seriesScope.itemModel]
  30166. * @param {string} [seriesScope.symbolInnerColor]
  30167. * @param {Object} [seriesScope.fadeIn=false]
  30168. */
  30169. symbolProto.updateData = function (data, idx, seriesScope) {
  30170. this.silent = false;
  30171. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  30172. var seriesModel = data.hostModel;
  30173. var symbolSize = getSymbolSize(data, idx);
  30174. var isInit = symbolType !== this._symbolType;
  30175. if (isInit) {
  30176. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  30177. this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
  30178. } else {
  30179. var symbolPath = this.childAt(0);
  30180. symbolPath.silent = false;
  30181. updateProps(symbolPath, {
  30182. scale: getScale(symbolSize)
  30183. }, seriesModel, idx);
  30184. }
  30185. this._updateCommon(data, idx, symbolSize, seriesScope);
  30186. if (isInit) {
  30187. var symbolPath = this.childAt(0);
  30188. var fadeIn = seriesScope && seriesScope.fadeIn;
  30189. var target = {
  30190. scale: symbolPath.scale.slice()
  30191. };
  30192. fadeIn && (target.style = {
  30193. opacity: symbolPath.style.opacity
  30194. });
  30195. symbolPath.scale = [0, 0];
  30196. fadeIn && (symbolPath.style.opacity = 0);
  30197. initProps(symbolPath, target, seriesModel, idx);
  30198. }
  30199. this._seriesModel = seriesModel;
  30200. }; // Update common properties
  30201. var normalStyleAccessPath = ['itemStyle'];
  30202. var emphasisStyleAccessPath = ['emphasis', 'itemStyle'];
  30203. var normalLabelAccessPath = ['label'];
  30204. var emphasisLabelAccessPath = ['emphasis', 'label'];
  30205. /**
  30206. * @param {module:echarts/data/List} data
  30207. * @param {number} idx
  30208. * @param {Array.<number>} symbolSize
  30209. * @param {Object} [seriesScope]
  30210. */
  30211. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  30212. var symbolPath = this.childAt(0);
  30213. var seriesModel = data.hostModel;
  30214. var color = data.getItemVisual(idx, 'color'); // Reset style
  30215. if (symbolPath.type !== 'image') {
  30216. symbolPath.useStyle({
  30217. strokeNoScale: true
  30218. });
  30219. } else {
  30220. symbolPath.setStyle({
  30221. opacity: 1,
  30222. shadowBlur: null,
  30223. shadowOffsetX: null,
  30224. shadowOffsetY: null,
  30225. shadowColor: null
  30226. });
  30227. }
  30228. var itemStyle = seriesScope && seriesScope.itemStyle;
  30229. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  30230. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  30231. var labelModel = seriesScope && seriesScope.labelModel;
  30232. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  30233. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  30234. var cursorStyle = seriesScope && seriesScope.cursorStyle;
  30235. if (!seriesScope || data.hasItemOption) {
  30236. var itemModel = seriesScope && seriesScope.itemModel ? seriesScope.itemModel : data.getItemModel(idx); // Color must be excluded.
  30237. // Because symbol provide setColor individually to set fill and stroke
  30238. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  30239. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  30240. symbolOffset = itemModel.getShallow('symbolOffset');
  30241. labelModel = itemModel.getModel(normalLabelAccessPath);
  30242. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  30243. hoverAnimation = itemModel.getShallow('hoverAnimation');
  30244. cursorStyle = itemModel.getShallow('cursor');
  30245. } else {
  30246. hoverItemStyle = extend({}, hoverItemStyle);
  30247. }
  30248. var elStyle = symbolPath.style;
  30249. var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
  30250. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  30251. if (symbolOffset) {
  30252. symbolPath.attr('position', [parsePercent$1(symbolOffset[0], symbolSize[0]), parsePercent$1(symbolOffset[1], symbolSize[1])]);
  30253. }
  30254. cursorStyle && symbolPath.attr('cursor', cursorStyle); // PENDING setColor before setStyle!!!
  30255. symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
  30256. symbolPath.setStyle(itemStyle);
  30257. var opacity = data.getItemVisual(idx, 'opacity');
  30258. if (opacity != null) {
  30259. elStyle.opacity = opacity;
  30260. }
  30261. var liftZ = data.getItemVisual(idx, 'liftZ');
  30262. var z2Origin = symbolPath.__z2Origin;
  30263. if (liftZ != null) {
  30264. if (z2Origin == null) {
  30265. symbolPath.__z2Origin = symbolPath.z2;
  30266. symbolPath.z2 += liftZ;
  30267. }
  30268. } else if (z2Origin != null) {
  30269. symbolPath.z2 = z2Origin;
  30270. symbolPath.__z2Origin = null;
  30271. }
  30272. var useNameLabel = seriesScope && seriesScope.useNameLabel;
  30273. setLabelStyle(elStyle, hoverItemStyle, labelModel, hoverLabelModel, {
  30274. labelFetcher: seriesModel,
  30275. labelDataIndex: idx,
  30276. defaultText: getLabelDefaultText,
  30277. isRectText: true,
  30278. autoColor: color
  30279. }); // Do not execute util needed.
  30280. function getLabelDefaultText(idx, opt) {
  30281. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  30282. }
  30283. symbolPath.__symbolOriginalScale = getScale(symbolSize);
  30284. symbolPath.hoverStyle = hoverItemStyle;
  30285. symbolPath.highDownOnUpdate = hoverAnimation && seriesModel.isAnimationEnabled() ? highDownOnUpdate : null;
  30286. setHoverStyle(symbolPath);
  30287. };
  30288. function highDownOnUpdate(fromState, toState) {
  30289. // Do not support this hover animation util some scenario required.
  30290. // Animation can only be supported in hover layer when using `el.incremetal`.
  30291. if (this.incremental || this.useHoverLayer) {
  30292. return;
  30293. }
  30294. if (toState === 'emphasis') {
  30295. var scale = this.__symbolOriginalScale;
  30296. var ratio = scale[1] / scale[0];
  30297. var emphasisOpt = {
  30298. scale: [Math.max(scale[0] * 1.1, scale[0] + 3), Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)]
  30299. }; // FIXME
  30300. // modify it after support stop specified animation.
  30301. // toState === fromState
  30302. // ? (this.stopAnimation(), this.attr(emphasisOpt))
  30303. this.animateTo(emphasisOpt, 400, 'elasticOut');
  30304. } else if (toState === 'normal') {
  30305. this.animateTo({
  30306. scale: this.__symbolOriginalScale
  30307. }, 400, 'elasticOut');
  30308. }
  30309. }
  30310. /**
  30311. * @param {Function} cb
  30312. * @param {Object} [opt]
  30313. * @param {Object} [opt.keepLabel=true]
  30314. */
  30315. symbolProto.fadeOut = function (cb, opt) {
  30316. var symbolPath = this.childAt(0); // Avoid mistaken hover when fading out
  30317. this.silent = symbolPath.silent = true; // Not show text when animating
  30318. !(opt && opt.keepLabel) && (symbolPath.style.text = null);
  30319. updateProps(symbolPath, {
  30320. style: {
  30321. opacity: 0
  30322. },
  30323. scale: [0, 0]
  30324. }, this._seriesModel, this.dataIndex, cb);
  30325. };
  30326. inherits(SymbolClz$1, Group);
  30327. /*
  30328. * Licensed to the Apache Software Foundation (ASF) under one
  30329. * or more contributor license agreements. See the NOTICE file
  30330. * distributed with this work for additional information
  30331. * regarding copyright ownership. The ASF licenses this file
  30332. * to you under the Apache License, Version 2.0 (the
  30333. * "License"); you may not use this file except in compliance
  30334. * with the License. You may obtain a copy of the License at
  30335. *
  30336. * http://www.apache.org/licenses/LICENSE-2.0
  30337. *
  30338. * Unless required by applicable law or agreed to in writing,
  30339. * software distributed under the License is distributed on an
  30340. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30341. * KIND, either express or implied. See the License for the
  30342. * specific language governing permissions and limitations
  30343. * under the License.
  30344. */
  30345. /**
  30346. * @module echarts/chart/helper/SymbolDraw
  30347. */
  30348. /**
  30349. * @constructor
  30350. * @alias module:echarts/chart/helper/SymbolDraw
  30351. * @param {module:zrender/graphic/Group} [symbolCtor]
  30352. */
  30353. function SymbolDraw(symbolCtor) {
  30354. this.group = new Group();
  30355. this._symbolCtor = symbolCtor || SymbolClz$1;
  30356. }
  30357. var symbolDrawProto = SymbolDraw.prototype;
  30358. function symbolNeedsDraw(data, point, idx, opt) {
  30359. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(opt.isIgnore && opt.isIgnore(idx)) // We do not set clipShape on group, because it will cut part of
  30360. // the symbol element shape. We use the same clip shape here as
  30361. // the line clip.
  30362. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1])) && data.getItemVisual(idx, 'symbol') !== 'none';
  30363. }
  30364. /**
  30365. * Update symbols draw by new data
  30366. * @param {module:echarts/data/List} data
  30367. * @param {Object} [opt] Or isIgnore
  30368. * @param {Function} [opt.isIgnore]
  30369. * @param {Object} [opt.clipShape]
  30370. */
  30371. symbolDrawProto.updateData = function (data, opt) {
  30372. opt = normalizeUpdateOpt(opt);
  30373. var group = this.group;
  30374. var seriesModel = data.hostModel;
  30375. var oldData = this._data;
  30376. var SymbolCtor = this._symbolCtor;
  30377. var seriesScope = makeSeriesScope(data); // There is no oldLineData only when first rendering or switching from
  30378. // stream mode to normal mode, where previous elements should be removed.
  30379. if (!oldData) {
  30380. group.removeAll();
  30381. }
  30382. data.diff(oldData).add(function (newIdx) {
  30383. var point = data.getItemLayout(newIdx);
  30384. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  30385. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  30386. symbolEl.attr('position', point);
  30387. data.setItemGraphicEl(newIdx, symbolEl);
  30388. group.add(symbolEl);
  30389. }
  30390. }).update(function (newIdx, oldIdx) {
  30391. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  30392. var point = data.getItemLayout(newIdx);
  30393. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  30394. group.remove(symbolEl);
  30395. return;
  30396. }
  30397. if (!symbolEl) {
  30398. symbolEl = new SymbolCtor(data, newIdx);
  30399. symbolEl.attr('position', point);
  30400. } else {
  30401. symbolEl.updateData(data, newIdx, seriesScope);
  30402. updateProps(symbolEl, {
  30403. position: point
  30404. }, seriesModel);
  30405. } // Add back
  30406. group.add(symbolEl);
  30407. data.setItemGraphicEl(newIdx, symbolEl);
  30408. }).remove(function (oldIdx) {
  30409. var el = oldData.getItemGraphicEl(oldIdx);
  30410. el && el.fadeOut(function () {
  30411. group.remove(el);
  30412. });
  30413. }).execute();
  30414. this._data = data;
  30415. };
  30416. symbolDrawProto.isPersistent = function () {
  30417. return true;
  30418. };
  30419. symbolDrawProto.updateLayout = function () {
  30420. var data = this._data;
  30421. if (data) {
  30422. // Not use animation
  30423. data.eachItemGraphicEl(function (el, idx) {
  30424. var point = data.getItemLayout(idx);
  30425. el.attr('position', point);
  30426. });
  30427. }
  30428. };
  30429. symbolDrawProto.incrementalPrepareUpdate = function (data) {
  30430. this._seriesScope = makeSeriesScope(data);
  30431. this._data = null;
  30432. this.group.removeAll();
  30433. };
  30434. /**
  30435. * Update symbols draw by new data
  30436. * @param {module:echarts/data/List} data
  30437. * @param {Object} [opt] Or isIgnore
  30438. * @param {Function} [opt.isIgnore]
  30439. * @param {Object} [opt.clipShape]
  30440. */
  30441. symbolDrawProto.incrementalUpdate = function (taskParams, data, opt) {
  30442. opt = normalizeUpdateOpt(opt);
  30443. function updateIncrementalAndHover(el) {
  30444. if (!el.isGroup) {
  30445. el.incremental = el.useHoverLayer = true;
  30446. }
  30447. }
  30448. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  30449. var point = data.getItemLayout(idx);
  30450. if (symbolNeedsDraw(data, point, idx, opt)) {
  30451. var el = new this._symbolCtor(data, idx, this._seriesScope);
  30452. el.traverse(updateIncrementalAndHover);
  30453. el.attr('position', point);
  30454. this.group.add(el);
  30455. data.setItemGraphicEl(idx, el);
  30456. }
  30457. }
  30458. };
  30459. function normalizeUpdateOpt(opt) {
  30460. if (opt != null && !isObject$1(opt)) {
  30461. opt = {
  30462. isIgnore: opt
  30463. };
  30464. }
  30465. return opt || {};
  30466. }
  30467. symbolDrawProto.remove = function (enableAnimation) {
  30468. var group = this.group;
  30469. var data = this._data; // Incremental model do not have this._data.
  30470. if (data && enableAnimation) {
  30471. data.eachItemGraphicEl(function (el) {
  30472. el.fadeOut(function () {
  30473. group.remove(el);
  30474. });
  30475. });
  30476. } else {
  30477. group.removeAll();
  30478. }
  30479. };
  30480. function makeSeriesScope(data) {
  30481. var seriesModel = data.hostModel;
  30482. return {
  30483. itemStyle: seriesModel.getModel('itemStyle').getItemStyle(['color']),
  30484. hoverItemStyle: seriesModel.getModel('emphasis.itemStyle').getItemStyle(),
  30485. symbolRotate: seriesModel.get('symbolRotate'),
  30486. symbolOffset: seriesModel.get('symbolOffset'),
  30487. hoverAnimation: seriesModel.get('hoverAnimation'),
  30488. labelModel: seriesModel.getModel('label'),
  30489. hoverLabelModel: seriesModel.getModel('emphasis.label'),
  30490. cursorStyle: seriesModel.get('cursor')
  30491. };
  30492. }
  30493. /*
  30494. * Licensed to the Apache Software Foundation (ASF) under one
  30495. * or more contributor license agreements. See the NOTICE file
  30496. * distributed with this work for additional information
  30497. * regarding copyright ownership. The ASF licenses this file
  30498. * to you under the Apache License, Version 2.0 (the
  30499. * "License"); you may not use this file except in compliance
  30500. * with the License. You may obtain a copy of the License at
  30501. *
  30502. * http://www.apache.org/licenses/LICENSE-2.0
  30503. *
  30504. * Unless required by applicable law or agreed to in writing,
  30505. * software distributed under the License is distributed on an
  30506. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30507. * KIND, either express or implied. See the License for the
  30508. * specific language governing permissions and limitations
  30509. * under the License.
  30510. */
  30511. /**
  30512. * @param {Object} coordSys
  30513. * @param {module:echarts/data/List} data
  30514. * @param {string} valueOrigin lineSeries.option.areaStyle.origin
  30515. */
  30516. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  30517. var baseAxis = coordSys.getBaseAxis();
  30518. var valueAxis = coordSys.getOtherAxis(baseAxis);
  30519. var valueStart = getValueStart(valueAxis, valueOrigin);
  30520. var baseAxisDim = baseAxis.dim;
  30521. var valueAxisDim = valueAxis.dim;
  30522. var valueDim = data.mapDimension(valueAxisDim);
  30523. var baseDim = data.mapDimension(baseAxisDim);
  30524. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  30525. var dims = map(coordSys.dimensions, function (coordDim) {
  30526. return data.mapDimension(coordDim);
  30527. });
  30528. var stacked;
  30529. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  30530. if (stacked |= isDimensionStacked(data, dims[0]
  30531. /*, dims[1]*/
  30532. )) {
  30533. // jshint ignore:line
  30534. dims[0] = stackResultDim;
  30535. }
  30536. if (stacked |= isDimensionStacked(data, dims[1]
  30537. /*, dims[0]*/
  30538. )) {
  30539. // jshint ignore:line
  30540. dims[1] = stackResultDim;
  30541. }
  30542. return {
  30543. dataDimsForPoint: dims,
  30544. valueStart: valueStart,
  30545. valueAxisDim: valueAxisDim,
  30546. baseAxisDim: baseAxisDim,
  30547. stacked: !!stacked,
  30548. valueDim: valueDim,
  30549. baseDim: baseDim,
  30550. baseDataOffset: baseDataOffset,
  30551. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  30552. };
  30553. }
  30554. function getValueStart(valueAxis, valueOrigin) {
  30555. var valueStart = 0;
  30556. var extent = valueAxis.scale.getExtent();
  30557. if (valueOrigin === 'start') {
  30558. valueStart = extent[0];
  30559. } else if (valueOrigin === 'end') {
  30560. valueStart = extent[1];
  30561. } // auto
  30562. else {
  30563. // Both positive
  30564. if (extent[0] > 0) {
  30565. valueStart = extent[0];
  30566. } // Both negative
  30567. else if (extent[1] < 0) {
  30568. valueStart = extent[1];
  30569. } // If is one positive, and one negative, onZero shall be true
  30570. }
  30571. return valueStart;
  30572. }
  30573. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  30574. var value = NaN;
  30575. if (dataCoordInfo.stacked) {
  30576. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  30577. }
  30578. if (isNaN(value)) {
  30579. value = dataCoordInfo.valueStart;
  30580. }
  30581. var baseDataOffset = dataCoordInfo.baseDataOffset;
  30582. var stackedData = [];
  30583. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  30584. stackedData[1 - baseDataOffset] = value;
  30585. return coordSys.dataToPoint(stackedData);
  30586. }
  30587. /*
  30588. * Licensed to the Apache Software Foundation (ASF) under one
  30589. * or more contributor license agreements. See the NOTICE file
  30590. * distributed with this work for additional information
  30591. * regarding copyright ownership. The ASF licenses this file
  30592. * to you under the Apache License, Version 2.0 (the
  30593. * "License"); you may not use this file except in compliance
  30594. * with the License. You may obtain a copy of the License at
  30595. *
  30596. * http://www.apache.org/licenses/LICENSE-2.0
  30597. *
  30598. * Unless required by applicable law or agreed to in writing,
  30599. * software distributed under the License is distributed on an
  30600. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30601. * KIND, either express or implied. See the License for the
  30602. * specific language governing permissions and limitations
  30603. * under the License.
  30604. */
  30605. // var arrayDiff = require('zrender/src/core/arrayDiff');
  30606. // 'zrender/src/core/arrayDiff' has been used before, but it did
  30607. // not do well in performance when roam with fixed dataZoom window.
  30608. // function convertToIntId(newIdList, oldIdList) {
  30609. // // Generate int id instead of string id.
  30610. // // Compare string maybe slow in score function of arrDiff
  30611. // // Assume id in idList are all unique
  30612. // var idIndicesMap = {};
  30613. // var idx = 0;
  30614. // for (var i = 0; i < newIdList.length; i++) {
  30615. // idIndicesMap[newIdList[i]] = idx;
  30616. // newIdList[i] = idx++;
  30617. // }
  30618. // for (var i = 0; i < oldIdList.length; i++) {
  30619. // var oldId = oldIdList[i];
  30620. // // Same with newIdList
  30621. // if (idIndicesMap[oldId]) {
  30622. // oldIdList[i] = idIndicesMap[oldId];
  30623. // }
  30624. // else {
  30625. // oldIdList[i] = idx++;
  30626. // }
  30627. // }
  30628. // }
  30629. function diffData(oldData, newData) {
  30630. var diffResult = [];
  30631. newData.diff(oldData).add(function (idx) {
  30632. diffResult.push({
  30633. cmd: '+',
  30634. idx: idx
  30635. });
  30636. }).update(function (newIdx, oldIdx) {
  30637. diffResult.push({
  30638. cmd: '=',
  30639. idx: oldIdx,
  30640. idx1: newIdx
  30641. });
  30642. }).remove(function (idx) {
  30643. diffResult.push({
  30644. cmd: '-',
  30645. idx: idx
  30646. });
  30647. }).execute();
  30648. return diffResult;
  30649. }
  30650. var lineAnimationDiff = function (oldData, newData, oldStackedOnPoints, newStackedOnPoints, oldCoordSys, newCoordSys, oldValueOrigin, newValueOrigin) {
  30651. var diff = diffData(oldData, newData); // var newIdList = newData.mapArray(newData.getId);
  30652. // var oldIdList = oldData.mapArray(oldData.getId);
  30653. // convertToIntId(newIdList, oldIdList);
  30654. // // FIXME One data ?
  30655. // diff = arrayDiff(oldIdList, newIdList);
  30656. var currPoints = [];
  30657. var nextPoints = []; // Points for stacking base line
  30658. var currStackedPoints = [];
  30659. var nextStackedPoints = [];
  30660. var status = [];
  30661. var sortedIndices = [];
  30662. var rawIndices = [];
  30663. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  30664. var oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  30665. for (var i = 0; i < diff.length; i++) {
  30666. var diffItem = diff[i];
  30667. var pointAdded = true; // FIXME, animation is not so perfect when dataZoom window moves fast
  30668. // Which is in case remvoing or add more than one data in the tail or head
  30669. switch (diffItem.cmd) {
  30670. case '=':
  30671. var currentPt = oldData.getItemLayout(diffItem.idx);
  30672. var nextPt = newData.getItemLayout(diffItem.idx1); // If previous data is NaN, use next point directly
  30673. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  30674. currentPt = nextPt.slice();
  30675. }
  30676. currPoints.push(currentPt);
  30677. nextPoints.push(nextPt);
  30678. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  30679. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  30680. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  30681. break;
  30682. case '+':
  30683. var idx = diffItem.idx;
  30684. currPoints.push(oldCoordSys.dataToPoint([newData.get(newDataOldCoordInfo.dataDimsForPoint[0], idx), newData.get(newDataOldCoordInfo.dataDimsForPoint[1], idx)]));
  30685. nextPoints.push(newData.getItemLayout(idx).slice());
  30686. currStackedPoints.push(getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, idx));
  30687. nextStackedPoints.push(newStackedOnPoints[idx]);
  30688. rawIndices.push(newData.getRawIndex(idx));
  30689. break;
  30690. case '-':
  30691. var idx = diffItem.idx;
  30692. var rawIndex = oldData.getRawIndex(idx); // Data is replaced. In the case of dynamic data queue
  30693. // FIXME FIXME FIXME
  30694. if (rawIndex !== idx) {
  30695. currPoints.push(oldData.getItemLayout(idx));
  30696. nextPoints.push(newCoordSys.dataToPoint([oldData.get(oldDataNewCoordInfo.dataDimsForPoint[0], idx), oldData.get(oldDataNewCoordInfo.dataDimsForPoint[1], idx)]));
  30697. currStackedPoints.push(oldStackedOnPoints[idx]);
  30698. nextStackedPoints.push(getStackedOnPoint(oldDataNewCoordInfo, newCoordSys, oldData, idx));
  30699. rawIndices.push(rawIndex);
  30700. } else {
  30701. pointAdded = false;
  30702. }
  30703. } // Original indices
  30704. if (pointAdded) {
  30705. status.push(diffItem);
  30706. sortedIndices.push(sortedIndices.length);
  30707. }
  30708. } // Diff result may be crossed if all items are changed
  30709. // Sort by data index
  30710. sortedIndices.sort(function (a, b) {
  30711. return rawIndices[a] - rawIndices[b];
  30712. });
  30713. var sortedCurrPoints = [];
  30714. var sortedNextPoints = [];
  30715. var sortedCurrStackedPoints = [];
  30716. var sortedNextStackedPoints = [];
  30717. var sortedStatus = [];
  30718. for (var i = 0; i < sortedIndices.length; i++) {
  30719. var idx = sortedIndices[i];
  30720. sortedCurrPoints[i] = currPoints[idx];
  30721. sortedNextPoints[i] = nextPoints[idx];
  30722. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  30723. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  30724. sortedStatus[i] = status[idx];
  30725. }
  30726. return {
  30727. current: sortedCurrPoints,
  30728. next: sortedNextPoints,
  30729. stackedOnCurrent: sortedCurrStackedPoints,
  30730. stackedOnNext: sortedNextStackedPoints,
  30731. status: sortedStatus
  30732. };
  30733. };
  30734. /*
  30735. * Licensed to the Apache Software Foundation (ASF) under one
  30736. * or more contributor license agreements. See the NOTICE file
  30737. * distributed with this work for additional information
  30738. * regarding copyright ownership. The ASF licenses this file
  30739. * to you under the Apache License, Version 2.0 (the
  30740. * "License"); you may not use this file except in compliance
  30741. * with the License. You may obtain a copy of the License at
  30742. *
  30743. * http://www.apache.org/licenses/LICENSE-2.0
  30744. *
  30745. * Unless required by applicable law or agreed to in writing,
  30746. * software distributed under the License is distributed on an
  30747. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30748. * KIND, either express or implied. See the License for the
  30749. * specific language governing permissions and limitations
  30750. * under the License.
  30751. */
  30752. // Poly path support NaN point
  30753. var vec2Min = min;
  30754. var vec2Max = max;
  30755. var scaleAndAdd$1 = scaleAndAdd;
  30756. var v2Copy = copy; // Temporary variable
  30757. var v = [];
  30758. var cp0 = [];
  30759. var cp1 = [];
  30760. function isPointNull(p) {
  30761. return isNaN(p[0]) || isNaN(p[1]);
  30762. }
  30763. function drawSegment(ctx, points, start, segLen, allLen, dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls) {
  30764. // if (smoothMonotone == null) {
  30765. // if (isMono(points, 'x')) {
  30766. // return drawMono(ctx, points, start, segLen, allLen,
  30767. // dir, smoothMin, smoothMax, smooth, 'x', connectNulls);
  30768. // }
  30769. // else if (isMono(points, 'y')) {
  30770. // return drawMono(ctx, points, start, segLen, allLen,
  30771. // dir, smoothMin, smoothMax, smooth, 'y', connectNulls);
  30772. // }
  30773. // else {
  30774. // return drawNonMono.apply(this, arguments);
  30775. // }
  30776. // }
  30777. // else if (smoothMonotone !== 'none' && isMono(points, smoothMonotone)) {
  30778. // return drawMono.apply(this, arguments);
  30779. // }
  30780. // else {
  30781. // return drawNonMono.apply(this, arguments);
  30782. // }
  30783. if (smoothMonotone === 'none' || !smoothMonotone) {
  30784. return drawNonMono.apply(this, arguments);
  30785. } else {
  30786. return drawMono.apply(this, arguments);
  30787. }
  30788. }
  30789. /**
  30790. * Check if points is in monotone.
  30791. *
  30792. * @param {number[][]} points Array of points which is in [x, y] form
  30793. * @param {string} smoothMonotone 'x', 'y', or 'none', stating for which
  30794. * dimension that is checking.
  30795. * If is 'none', `drawNonMono` should be
  30796. * called.
  30797. * If is undefined, either being monotone
  30798. * in 'x' or 'y' will call `drawMono`.
  30799. */
  30800. // function isMono(points, smoothMonotone) {
  30801. // if (points.length <= 1) {
  30802. // return true;
  30803. // }
  30804. // var dim = smoothMonotone === 'x' ? 0 : 1;
  30805. // var last = points[0][dim];
  30806. // var lastDiff = 0;
  30807. // for (var i = 1; i < points.length; ++i) {
  30808. // var diff = points[i][dim] - last;
  30809. // if (!isNaN(diff) && !isNaN(lastDiff)
  30810. // && diff !== 0 && lastDiff !== 0
  30811. // && ((diff >= 0) !== (lastDiff >= 0))
  30812. // ) {
  30813. // return false;
  30814. // }
  30815. // if (!isNaN(diff) && diff !== 0) {
  30816. // lastDiff = diff;
  30817. // last = points[i][dim];
  30818. // }
  30819. // }
  30820. // return true;
  30821. // }
  30822. /**
  30823. * Draw smoothed line in monotone, in which only vertical or horizontal bezier
  30824. * control points will be used. This should be used when points are monotone
  30825. * either in x or y dimension.
  30826. */
  30827. function drawMono(ctx, points, start, segLen, allLen, dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls) {
  30828. var prevIdx = 0;
  30829. var idx = start;
  30830. for (var k = 0; k < segLen; k++) {
  30831. var p = points[idx];
  30832. if (idx >= allLen || idx < 0) {
  30833. break;
  30834. }
  30835. if (isPointNull(p)) {
  30836. if (connectNulls) {
  30837. idx += dir;
  30838. continue;
  30839. }
  30840. break;
  30841. }
  30842. if (idx === start) {
  30843. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  30844. } else {
  30845. if (smooth > 0) {
  30846. var prevP = points[prevIdx];
  30847. var dim = smoothMonotone === 'y' ? 1 : 0; // Length of control point to p, either in x or y, but not both
  30848. var ctrlLen = (p[dim] - prevP[dim]) * smooth;
  30849. v2Copy(cp0, prevP);
  30850. cp0[dim] = prevP[dim] + ctrlLen;
  30851. v2Copy(cp1, p);
  30852. cp1[dim] = p[dim] - ctrlLen;
  30853. ctx.bezierCurveTo(cp0[0], cp0[1], cp1[0], cp1[1], p[0], p[1]);
  30854. } else {
  30855. ctx.lineTo(p[0], p[1]);
  30856. }
  30857. }
  30858. prevIdx = idx;
  30859. idx += dir;
  30860. }
  30861. return k;
  30862. }
  30863. /**
  30864. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  30865. * situations. This should be used when points are non-monotone neither in x or
  30866. * y dimension.
  30867. */
  30868. function drawNonMono(ctx, points, start, segLen, allLen, dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls) {
  30869. var prevIdx = 0;
  30870. var idx = start;
  30871. for (var k = 0; k < segLen; k++) {
  30872. var p = points[idx];
  30873. if (idx >= allLen || idx < 0) {
  30874. break;
  30875. }
  30876. if (isPointNull(p)) {
  30877. if (connectNulls) {
  30878. idx += dir;
  30879. continue;
  30880. }
  30881. break;
  30882. }
  30883. if (idx === start) {
  30884. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  30885. v2Copy(cp0, p);
  30886. } else {
  30887. if (smooth > 0) {
  30888. var nextIdx = idx + dir;
  30889. var nextP = points[nextIdx];
  30890. if (connectNulls) {
  30891. // Find next point not null
  30892. while (nextP && isPointNull(points[nextIdx])) {
  30893. nextIdx += dir;
  30894. nextP = points[nextIdx];
  30895. }
  30896. }
  30897. var ratioNextSeg = 0.5;
  30898. var prevP = points[prevIdx];
  30899. var nextP = points[nextIdx]; // Last point
  30900. if (!nextP || isPointNull(nextP)) {
  30901. v2Copy(cp1, p);
  30902. } else {
  30903. // If next data is null in not connect case
  30904. if (isPointNull(nextP) && !connectNulls) {
  30905. nextP = p;
  30906. }
  30907. sub(v, nextP, prevP);
  30908. var lenPrevSeg;
  30909. var lenNextSeg;
  30910. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  30911. var dim = smoothMonotone === 'x' ? 0 : 1;
  30912. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  30913. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  30914. } else {
  30915. lenPrevSeg = dist(p, prevP);
  30916. lenNextSeg = dist(p, nextP);
  30917. } // Use ratio of seg length
  30918. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  30919. scaleAndAdd$1(cp1, p, v, -smooth * (1 - ratioNextSeg));
  30920. } // Smooth constraint
  30921. vec2Min(cp0, cp0, smoothMax);
  30922. vec2Max(cp0, cp0, smoothMin);
  30923. vec2Min(cp1, cp1, smoothMax);
  30924. vec2Max(cp1, cp1, smoothMin);
  30925. ctx.bezierCurveTo(cp0[0], cp0[1], cp1[0], cp1[1], p[0], p[1]); // cp0 of next segment
  30926. scaleAndAdd$1(cp0, p, v, smooth * ratioNextSeg);
  30927. } else {
  30928. ctx.lineTo(p[0], p[1]);
  30929. }
  30930. }
  30931. prevIdx = idx;
  30932. idx += dir;
  30933. }
  30934. return k;
  30935. }
  30936. function getBoundingBox(points, smoothConstraint) {
  30937. var ptMin = [Infinity, Infinity];
  30938. var ptMax = [-Infinity, -Infinity];
  30939. if (smoothConstraint) {
  30940. for (var i = 0; i < points.length; i++) {
  30941. var pt = points[i];
  30942. if (pt[0] < ptMin[0]) {
  30943. ptMin[0] = pt[0];
  30944. }
  30945. if (pt[1] < ptMin[1]) {
  30946. ptMin[1] = pt[1];
  30947. }
  30948. if (pt[0] > ptMax[0]) {
  30949. ptMax[0] = pt[0];
  30950. }
  30951. if (pt[1] > ptMax[1]) {
  30952. ptMax[1] = pt[1];
  30953. }
  30954. }
  30955. }
  30956. return {
  30957. min: smoothConstraint ? ptMin : ptMax,
  30958. max: smoothConstraint ? ptMax : ptMin
  30959. };
  30960. }
  30961. var Polyline$1 = Path.extend({
  30962. type: 'ec-polyline',
  30963. shape: {
  30964. points: [],
  30965. smooth: 0,
  30966. smoothConstraint: true,
  30967. smoothMonotone: null,
  30968. connectNulls: false
  30969. },
  30970. style: {
  30971. fill: null,
  30972. stroke: '#000'
  30973. },
  30974. brush: fixClipWithShadow(Path.prototype.brush),
  30975. buildPath: function (ctx, shape) {
  30976. var points = shape.points;
  30977. var i = 0;
  30978. var len$$1 = points.length;
  30979. var result = getBoundingBox(points, shape.smoothConstraint);
  30980. if (shape.connectNulls) {
  30981. // Must remove first and last null values avoid draw error in polygon
  30982. for (; len$$1 > 0; len$$1--) {
  30983. if (!isPointNull(points[len$$1 - 1])) {
  30984. break;
  30985. }
  30986. }
  30987. for (; i < len$$1; i++) {
  30988. if (!isPointNull(points[i])) {
  30989. break;
  30990. }
  30991. }
  30992. }
  30993. while (i < len$$1) {
  30994. i += drawSegment(ctx, points, i, len$$1, len$$1, 1, result.min, result.max, shape.smooth, shape.smoothMonotone, shape.connectNulls) + 1;
  30995. }
  30996. }
  30997. });
  30998. var Polygon$1 = Path.extend({
  30999. type: 'ec-polygon',
  31000. shape: {
  31001. points: [],
  31002. // Offset between stacked base points and points
  31003. stackedOnPoints: [],
  31004. smooth: 0,
  31005. stackedOnSmooth: 0,
  31006. smoothConstraint: true,
  31007. smoothMonotone: null,
  31008. connectNulls: false
  31009. },
  31010. brush: fixClipWithShadow(Path.prototype.brush),
  31011. buildPath: function (ctx, shape) {
  31012. var points = shape.points;
  31013. var stackedOnPoints = shape.stackedOnPoints;
  31014. var i = 0;
  31015. var len$$1 = points.length;
  31016. var smoothMonotone = shape.smoothMonotone;
  31017. var bbox = getBoundingBox(points, shape.smoothConstraint);
  31018. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  31019. if (shape.connectNulls) {
  31020. // Must remove first and last null values avoid draw error in polygon
  31021. for (; len$$1 > 0; len$$1--) {
  31022. if (!isPointNull(points[len$$1 - 1])) {
  31023. break;
  31024. }
  31025. }
  31026. for (; i < len$$1; i++) {
  31027. if (!isPointNull(points[i])) {
  31028. break;
  31029. }
  31030. }
  31031. }
  31032. while (i < len$$1) {
  31033. var k = drawSegment(ctx, points, i, len$$1, len$$1, 1, bbox.min, bbox.max, shape.smooth, smoothMonotone, shape.connectNulls);
  31034. drawSegment(ctx, stackedOnPoints, i + k - 1, k, len$$1, -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth, smoothMonotone, shape.connectNulls);
  31035. i += k + 1;
  31036. ctx.closePath();
  31037. }
  31038. }
  31039. });
  31040. /*
  31041. * Licensed to the Apache Software Foundation (ASF) under one
  31042. * or more contributor license agreements. See the NOTICE file
  31043. * distributed with this work for additional information
  31044. * regarding copyright ownership. The ASF licenses this file
  31045. * to you under the Apache License, Version 2.0 (the
  31046. * "License"); you may not use this file except in compliance
  31047. * with the License. You may obtain a copy of the License at
  31048. *
  31049. * http://www.apache.org/licenses/LICENSE-2.0
  31050. *
  31051. * Unless required by applicable law or agreed to in writing,
  31052. * software distributed under the License is distributed on an
  31053. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31054. * KIND, either express or implied. See the License for the
  31055. * specific language governing permissions and limitations
  31056. * under the License.
  31057. */
  31058. function createGridClipPath(cartesian, hasAnimation, seriesModel) {
  31059. var rect = cartesian.getArea();
  31060. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  31061. var x = rect.x;
  31062. var y = rect.y;
  31063. var width = rect.width;
  31064. var height = rect.height;
  31065. var lineWidth = seriesModel.get('lineStyle.width') || 2; // Expand the clip path a bit to avoid the border is clipped and looks thinner
  31066. x -= lineWidth / 2;
  31067. y -= lineWidth / 2;
  31068. width += lineWidth;
  31069. height += lineWidth; // fix: https://github.com/apache/incubator-echarts/issues/11369
  31070. x = Math.floor(x);
  31071. width = Math.round(width);
  31072. var clipPath = new Rect({
  31073. shape: {
  31074. x: x,
  31075. y: y,
  31076. width: width,
  31077. height: height
  31078. }
  31079. });
  31080. if (hasAnimation) {
  31081. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  31082. initProps(clipPath, {
  31083. shape: {
  31084. width: width,
  31085. height: height
  31086. }
  31087. }, seriesModel);
  31088. }
  31089. return clipPath;
  31090. }
  31091. function createPolarClipPath(polar, hasAnimation, seriesModel) {
  31092. var sectorArea = polar.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
  31093. var clipPath = new Sector({
  31094. shape: {
  31095. cx: round$1(polar.cx, 1),
  31096. cy: round$1(polar.cy, 1),
  31097. r0: round$1(sectorArea.r0, 1),
  31098. r: round$1(sectorArea.r, 1),
  31099. startAngle: sectorArea.startAngle,
  31100. endAngle: sectorArea.endAngle,
  31101. clockwise: sectorArea.clockwise
  31102. }
  31103. });
  31104. if (hasAnimation) {
  31105. clipPath.shape.endAngle = sectorArea.startAngle;
  31106. initProps(clipPath, {
  31107. shape: {
  31108. endAngle: sectorArea.endAngle
  31109. }
  31110. }, seriesModel);
  31111. }
  31112. return clipPath;
  31113. }
  31114. /*
  31115. * Licensed to the Apache Software Foundation (ASF) under one
  31116. * or more contributor license agreements. See the NOTICE file
  31117. * distributed with this work for additional information
  31118. * regarding copyright ownership. The ASF licenses this file
  31119. * to you under the Apache License, Version 2.0 (the
  31120. * "License"); you may not use this file except in compliance
  31121. * with the License. You may obtain a copy of the License at
  31122. *
  31123. * http://www.apache.org/licenses/LICENSE-2.0
  31124. *
  31125. * Unless required by applicable law or agreed to in writing,
  31126. * software distributed under the License is distributed on an
  31127. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31128. * KIND, either express or implied. See the License for the
  31129. * specific language governing permissions and limitations
  31130. * under the License.
  31131. */
  31132. // FIXME step not support polar
  31133. function isPointsSame(points1, points2) {
  31134. if (points1.length !== points2.length) {
  31135. return;
  31136. }
  31137. for (var i = 0; i < points1.length; i++) {
  31138. var p1 = points1[i];
  31139. var p2 = points2[i];
  31140. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  31141. return;
  31142. }
  31143. }
  31144. return true;
  31145. }
  31146. function getBoundingDiff(points1, points2) {
  31147. var min1 = [];
  31148. var max1 = [];
  31149. var min2 = [];
  31150. var max2 = [];
  31151. fromPoints(points1, min1, max1);
  31152. fromPoints(points2, min2, max2); // Get a max value from each corner of two boundings.
  31153. return Math.max(Math.abs(min1[0] - min2[0]), Math.abs(min1[1] - min2[1]), Math.abs(max1[0] - max2[0]), Math.abs(max1[1] - max2[1]));
  31154. }
  31155. function getSmooth(smooth) {
  31156. return typeof smooth === 'number' ? smooth : smooth ? 0.5 : 0;
  31157. }
  31158. /**
  31159. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  31160. * @param {module:echarts/data/List} data
  31161. * @param {Object} dataCoordInfo
  31162. * @param {Array.<Array.<number>>} points
  31163. */
  31164. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  31165. if (!dataCoordInfo.valueDim) {
  31166. return [];
  31167. }
  31168. var points = [];
  31169. for (var idx = 0, len = data.count(); idx < len; idx++) {
  31170. points.push(getStackedOnPoint(dataCoordInfo, coordSys, data, idx));
  31171. }
  31172. return points;
  31173. }
  31174. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  31175. var baseAxis = coordSys.getBaseAxis();
  31176. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  31177. var stepPoints = [];
  31178. for (var i = 0; i < points.length - 1; i++) {
  31179. var nextPt = points[i + 1];
  31180. var pt = points[i];
  31181. stepPoints.push(pt);
  31182. var stepPt = [];
  31183. switch (stepTurnAt) {
  31184. case 'end':
  31185. stepPt[baseIndex] = nextPt[baseIndex];
  31186. stepPt[1 - baseIndex] = pt[1 - baseIndex]; // default is start
  31187. stepPoints.push(stepPt);
  31188. break;
  31189. case 'middle':
  31190. // default is start
  31191. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  31192. var stepPt2 = [];
  31193. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  31194. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  31195. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  31196. stepPoints.push(stepPt);
  31197. stepPoints.push(stepPt2);
  31198. break;
  31199. default:
  31200. stepPt[baseIndex] = pt[baseIndex];
  31201. stepPt[1 - baseIndex] = nextPt[1 - baseIndex]; // default is start
  31202. stepPoints.push(stepPt);
  31203. }
  31204. } // Last points
  31205. points[i] && stepPoints.push(points[i]);
  31206. return stepPoints;
  31207. }
  31208. function getVisualGradient(data, coordSys) {
  31209. var visualMetaList = data.getVisual('visualMeta');
  31210. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  31211. // When data.count() is 0, gradient range can not be calculated.
  31212. return;
  31213. }
  31214. if (coordSys.type !== 'cartesian2d') {
  31215. if (__DEV__) {
  31216. console.warn('Visual map on line style is only supported on cartesian2d.');
  31217. }
  31218. return;
  31219. }
  31220. var coordDim;
  31221. var visualMeta;
  31222. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  31223. var dimIndex = visualMetaList[i].dimension;
  31224. var dimName = data.dimensions[dimIndex];
  31225. var dimInfo = data.getDimensionInfo(dimName);
  31226. coordDim = dimInfo && dimInfo.coordDim; // Can only be x or y
  31227. if (coordDim === 'x' || coordDim === 'y') {
  31228. visualMeta = visualMetaList[i];
  31229. break;
  31230. }
  31231. }
  31232. if (!visualMeta) {
  31233. if (__DEV__) {
  31234. console.warn('Visual map on line style only support x or y dimension.');
  31235. }
  31236. return;
  31237. } // If the area to be rendered is bigger than area defined by LinearGradient,
  31238. // the canvas spec prescribes that the color of the first stop and the last
  31239. // stop should be used. But if two stops are added at offset 0, in effect
  31240. // browsers use the color of the second stop to render area outside
  31241. // LinearGradient. So we can only infinitesimally extend area defined in
  31242. // LinearGradient to render `outerColors`.
  31243. var axis = coordSys.getAxis(coordDim); // dataToCoor mapping may not be linear, but must be monotonic.
  31244. var colorStops = map(visualMeta.stops, function (stop) {
  31245. return {
  31246. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  31247. color: stop.color
  31248. };
  31249. });
  31250. var stopLen = colorStops.length;
  31251. var outerColors = visualMeta.outerColors.slice();
  31252. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  31253. colorStops.reverse();
  31254. outerColors.reverse();
  31255. }
  31256. var tinyExtent = 10; // Arbitrary value: 10px
  31257. var minCoord = colorStops[0].coord - tinyExtent;
  31258. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  31259. var coordSpan = maxCoord - minCoord;
  31260. if (coordSpan < 1e-3) {
  31261. return 'transparent';
  31262. }
  31263. each$1(colorStops, function (stop) {
  31264. stop.offset = (stop.coord - minCoord) / coordSpan;
  31265. });
  31266. colorStops.push({
  31267. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  31268. color: outerColors[1] || 'transparent'
  31269. });
  31270. colorStops.unshift({
  31271. // notice colorStops.length have been changed.
  31272. offset: stopLen ? colorStops[0].offset : 0.5,
  31273. color: outerColors[0] || 'transparent'
  31274. }); // zrUtil.each(colorStops, function (colorStop) {
  31275. // // Make sure each offset has rounded px to avoid not sharp edge
  31276. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  31277. // });
  31278. var gradient = new LinearGradient(0, 0, 0, 0, colorStops, true);
  31279. gradient[coordDim] = minCoord;
  31280. gradient[coordDim + '2'] = maxCoord;
  31281. return gradient;
  31282. }
  31283. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  31284. var showAllSymbol = seriesModel.get('showAllSymbol');
  31285. var isAuto = showAllSymbol === 'auto';
  31286. if (showAllSymbol && !isAuto) {
  31287. return;
  31288. }
  31289. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  31290. if (!categoryAxis) {
  31291. return;
  31292. } // Note that category label interval strategy might bring some weird effect
  31293. // in some scenario: users may wonder why some of the symbols are not
  31294. // displayed. So we show all symbols as possible as we can.
  31295. if (isAuto // Simplify the logic, do not determine label overlap here.
  31296. && canShowAllSymbolForCategory(categoryAxis, data)) {
  31297. return;
  31298. } // Otherwise follow the label interval strategy on category axis.
  31299. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  31300. var labelMap = {};
  31301. each$1(categoryAxis.getViewLabels(), function (labelItem) {
  31302. labelMap[labelItem.tickValue] = 1;
  31303. });
  31304. return function (dataIndex) {
  31305. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  31306. };
  31307. }
  31308. function canShowAllSymbolForCategory(categoryAxis, data) {
  31309. // In mose cases, line is monotonous on category axis, and the label size
  31310. // is close with each other. So we check the symbol size and some of the
  31311. // label size alone with the category axis to estimate whether all symbol
  31312. // can be shown without overlap.
  31313. var axisExtent = categoryAxis.getExtent();
  31314. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  31315. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  31316. // Sampling some points, max 5.
  31317. var dataLen = data.count();
  31318. var step = Math.max(1, Math.round(dataLen / 5));
  31319. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  31320. if (SymbolClz$1.getSymbolSize(data, dataIndex // Only for cartesian, where `isHorizontal` exists.
  31321. )[categoryAxis.isHorizontal() ? 1 : 0] // Empirical number
  31322. * 1.5 > availSize) {
  31323. return false;
  31324. }
  31325. }
  31326. return true;
  31327. }
  31328. function createLineClipPath(coordSys, hasAnimation, seriesModel) {
  31329. if (coordSys.type === 'cartesian2d') {
  31330. var isHorizontal = coordSys.getBaseAxis().isHorizontal();
  31331. var clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel); // Expand clip shape to avoid clipping when line value exceeds axis
  31332. if (!seriesModel.get('clip', true)) {
  31333. var rectShape = clipPath.shape;
  31334. var expandSize = Math.max(rectShape.width, rectShape.height);
  31335. if (isHorizontal) {
  31336. rectShape.y -= expandSize;
  31337. rectShape.height += expandSize * 2;
  31338. } else {
  31339. rectShape.x -= expandSize;
  31340. rectShape.width += expandSize * 2;
  31341. }
  31342. }
  31343. return clipPath;
  31344. } else {
  31345. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  31346. }
  31347. }
  31348. Chart.extend({
  31349. type: 'line',
  31350. init: function () {
  31351. var lineGroup = new Group();
  31352. var symbolDraw = new SymbolDraw();
  31353. this.group.add(symbolDraw.group);
  31354. this._symbolDraw = symbolDraw;
  31355. this._lineGroup = lineGroup;
  31356. },
  31357. render: function (seriesModel, ecModel, api) {
  31358. var coordSys = seriesModel.coordinateSystem;
  31359. var group = this.group;
  31360. var data = seriesModel.getData();
  31361. var lineStyleModel = seriesModel.getModel('lineStyle');
  31362. var areaStyleModel = seriesModel.getModel('areaStyle');
  31363. var points = data.mapArray(data.getItemLayout);
  31364. var isCoordSysPolar = coordSys.type === 'polar';
  31365. var prevCoordSys = this._coordSys;
  31366. var symbolDraw = this._symbolDraw;
  31367. var polyline = this._polyline;
  31368. var polygon = this._polygon;
  31369. var lineGroup = this._lineGroup;
  31370. var hasAnimation = seriesModel.get('animation');
  31371. var isAreaChart = !areaStyleModel.isEmpty();
  31372. var valueOrigin = areaStyleModel.get('origin');
  31373. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  31374. var stackedOnPoints = getStackedOnPoints(coordSys, data, dataCoordInfo);
  31375. var showSymbol = seriesModel.get('showSymbol');
  31376. var isIgnoreFunc = showSymbol && !isCoordSysPolar && getIsIgnoreFunc(seriesModel, data, coordSys); // Remove temporary symbols
  31377. var oldData = this._data;
  31378. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  31379. if (el.__temp) {
  31380. group.remove(el);
  31381. oldData.setItemGraphicEl(idx, null);
  31382. }
  31383. }); // Remove previous created symbols if showSymbol changed to false
  31384. if (!showSymbol) {
  31385. symbolDraw.remove();
  31386. }
  31387. group.add(lineGroup); // FIXME step not support polar
  31388. var step = !isCoordSysPolar && seriesModel.get('step');
  31389. var clipShapeForSymbol;
  31390. if (coordSys && coordSys.getArea && seriesModel.get('clip', true)) {
  31391. clipShapeForSymbol = coordSys.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
  31392. // See #7913 and `test/dataZoom-clip.html`.
  31393. if (clipShapeForSymbol.width != null) {
  31394. clipShapeForSymbol.x -= 0.1;
  31395. clipShapeForSymbol.y -= 0.1;
  31396. clipShapeForSymbol.width += 0.2;
  31397. clipShapeForSymbol.height += 0.2;
  31398. } else if (clipShapeForSymbol.r0) {
  31399. clipShapeForSymbol.r0 -= 0.5;
  31400. clipShapeForSymbol.r1 += 0.5;
  31401. }
  31402. }
  31403. this._clipShapeForSymbol = clipShapeForSymbol; // Initialization animation or coordinate system changed
  31404. if (!(polyline && prevCoordSys.type === coordSys.type && step === this._step)) {
  31405. showSymbol && symbolDraw.updateData(data, {
  31406. isIgnore: isIgnoreFunc,
  31407. clipShape: clipShapeForSymbol
  31408. });
  31409. if (step) {
  31410. // TODO If stacked series is not step
  31411. points = turnPointsIntoStep(points, coordSys, step);
  31412. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  31413. }
  31414. polyline = this._newPolyline(points, coordSys, hasAnimation);
  31415. if (isAreaChart) {
  31416. polygon = this._newPolygon(points, stackedOnPoints, coordSys, hasAnimation);
  31417. }
  31418. lineGroup.setClipPath(createLineClipPath(coordSys, true, seriesModel));
  31419. } else {
  31420. if (isAreaChart && !polygon) {
  31421. // If areaStyle is added
  31422. polygon = this._newPolygon(points, stackedOnPoints, coordSys, hasAnimation);
  31423. } else if (polygon && !isAreaChart) {
  31424. // If areaStyle is removed
  31425. lineGroup.remove(polygon);
  31426. polygon = this._polygon = null;
  31427. } // Update clipPath
  31428. lineGroup.setClipPath(createLineClipPath(coordSys, false, seriesModel)); // Always update, or it is wrong in the case turning on legend
  31429. // because points are not changed
  31430. showSymbol && symbolDraw.updateData(data, {
  31431. isIgnore: isIgnoreFunc,
  31432. clipShape: clipShapeForSymbol
  31433. }); // Stop symbol animation and sync with line points
  31434. // FIXME performance?
  31435. data.eachItemGraphicEl(function (el) {
  31436. el.stopAnimation(true);
  31437. }); // In the case data zoom triggerred refreshing frequently
  31438. // Data may not change if line has a category axis. So it should animate nothing
  31439. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints) || !isPointsSame(this._points, points)) {
  31440. if (hasAnimation) {
  31441. this._updateAnimation(data, stackedOnPoints, coordSys, api, step, valueOrigin);
  31442. } else {
  31443. // Not do it in update with animation
  31444. if (step) {
  31445. // TODO If stacked series is not step
  31446. points = turnPointsIntoStep(points, coordSys, step);
  31447. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  31448. }
  31449. polyline.setShape({
  31450. points: points
  31451. });
  31452. polygon && polygon.setShape({
  31453. points: points,
  31454. stackedOnPoints: stackedOnPoints
  31455. });
  31456. }
  31457. }
  31458. }
  31459. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  31460. polyline.useStyle(defaults( // Use color in lineStyle first
  31461. lineStyleModel.getLineStyle(), {
  31462. fill: 'none',
  31463. stroke: visualColor,
  31464. lineJoin: 'bevel'
  31465. }));
  31466. var smooth = seriesModel.get('smooth');
  31467. smooth = getSmooth(seriesModel.get('smooth'));
  31468. polyline.setShape({
  31469. smooth: smooth,
  31470. smoothMonotone: seriesModel.get('smoothMonotone'),
  31471. connectNulls: seriesModel.get('connectNulls')
  31472. });
  31473. if (polygon) {
  31474. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  31475. var stackedOnSmooth = 0;
  31476. polygon.useStyle(defaults(areaStyleModel.getAreaStyle(), {
  31477. fill: visualColor,
  31478. opacity: 0.7,
  31479. lineJoin: 'bevel'
  31480. }));
  31481. if (stackedOnSeries) {
  31482. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  31483. }
  31484. polygon.setShape({
  31485. smooth: smooth,
  31486. stackedOnSmooth: stackedOnSmooth,
  31487. smoothMonotone: seriesModel.get('smoothMonotone'),
  31488. connectNulls: seriesModel.get('connectNulls')
  31489. });
  31490. }
  31491. this._data = data; // Save the coordinate system for transition animation when data changed
  31492. this._coordSys = coordSys;
  31493. this._stackedOnPoints = stackedOnPoints;
  31494. this._points = points;
  31495. this._step = step;
  31496. this._valueOrigin = valueOrigin;
  31497. },
  31498. dispose: function () {},
  31499. highlight: function (seriesModel, ecModel, api, payload) {
  31500. var data = seriesModel.getData();
  31501. var dataIndex = queryDataIndex(data, payload);
  31502. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  31503. var symbol = data.getItemGraphicEl(dataIndex);
  31504. if (!symbol) {
  31505. // Create a temporary symbol if it is not exists
  31506. var pt = data.getItemLayout(dataIndex);
  31507. if (!pt) {
  31508. // Null data
  31509. return;
  31510. } // fix #11360: should't draw symbol outside clipShapeForSymbol
  31511. if (this._clipShapeForSymbol && !this._clipShapeForSymbol.contain(pt[0], pt[1])) {
  31512. return;
  31513. }
  31514. symbol = new SymbolClz$1(data, dataIndex);
  31515. symbol.position = pt;
  31516. symbol.setZ(seriesModel.get('zlevel'), seriesModel.get('z'));
  31517. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  31518. symbol.__temp = true;
  31519. data.setItemGraphicEl(dataIndex, symbol); // Stop scale animation
  31520. symbol.stopSymbolAnimation(true);
  31521. this.group.add(symbol);
  31522. }
  31523. symbol.highlight();
  31524. } else {
  31525. // Highlight whole series
  31526. Chart.prototype.highlight.call(this, seriesModel, ecModel, api, payload);
  31527. }
  31528. },
  31529. downplay: function (seriesModel, ecModel, api, payload) {
  31530. var data = seriesModel.getData();
  31531. var dataIndex = queryDataIndex(data, payload);
  31532. if (dataIndex != null && dataIndex >= 0) {
  31533. var symbol = data.getItemGraphicEl(dataIndex);
  31534. if (symbol) {
  31535. if (symbol.__temp) {
  31536. data.setItemGraphicEl(dataIndex, null);
  31537. this.group.remove(symbol);
  31538. } else {
  31539. symbol.downplay();
  31540. }
  31541. }
  31542. } else {
  31543. // FIXME
  31544. // can not downplay completely.
  31545. // Downplay whole series
  31546. Chart.prototype.downplay.call(this, seriesModel, ecModel, api, payload);
  31547. }
  31548. },
  31549. /**
  31550. * @param {module:zrender/container/Group} group
  31551. * @param {Array.<Array.<number>>} points
  31552. * @private
  31553. */
  31554. _newPolyline: function (points) {
  31555. var polyline = this._polyline; // Remove previous created polyline
  31556. if (polyline) {
  31557. this._lineGroup.remove(polyline);
  31558. }
  31559. polyline = new Polyline$1({
  31560. shape: {
  31561. points: points
  31562. },
  31563. silent: true,
  31564. z2: 10
  31565. });
  31566. this._lineGroup.add(polyline);
  31567. this._polyline = polyline;
  31568. return polyline;
  31569. },
  31570. /**
  31571. * @param {module:zrender/container/Group} group
  31572. * @param {Array.<Array.<number>>} stackedOnPoints
  31573. * @param {Array.<Array.<number>>} points
  31574. * @private
  31575. */
  31576. _newPolygon: function (points, stackedOnPoints) {
  31577. var polygon = this._polygon; // Remove previous created polygon
  31578. if (polygon) {
  31579. this._lineGroup.remove(polygon);
  31580. }
  31581. polygon = new Polygon$1({
  31582. shape: {
  31583. points: points,
  31584. stackedOnPoints: stackedOnPoints
  31585. },
  31586. silent: true
  31587. });
  31588. this._lineGroup.add(polygon);
  31589. this._polygon = polygon;
  31590. return polygon;
  31591. },
  31592. /**
  31593. * @private
  31594. */
  31595. // FIXME Two value axis
  31596. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step, valueOrigin) {
  31597. var polyline = this._polyline;
  31598. var polygon = this._polygon;
  31599. var seriesModel = data.hostModel;
  31600. var diff = lineAnimationDiff(this._data, data, this._stackedOnPoints, stackedOnPoints, this._coordSys, coordSys, this._valueOrigin, valueOrigin);
  31601. var current = diff.current;
  31602. var stackedOnCurrent = diff.stackedOnCurrent;
  31603. var next = diff.next;
  31604. var stackedOnNext = diff.stackedOnNext;
  31605. if (step) {
  31606. // TODO If stacked series is not step
  31607. current = turnPointsIntoStep(diff.current, coordSys, step);
  31608. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  31609. next = turnPointsIntoStep(diff.next, coordSys, step);
  31610. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  31611. } // Don't apply animation if diff is large.
  31612. // For better result and avoid memory explosion problems like
  31613. // https://github.com/apache/incubator-echarts/issues/12229
  31614. if (getBoundingDiff(current, next) > 3000 || polygon && getBoundingDiff(stackedOnCurrent, stackedOnNext) > 3000) {
  31615. polyline.setShape({
  31616. points: next
  31617. });
  31618. if (polygon) {
  31619. polygon.setShape({
  31620. points: next,
  31621. stackedOnPoints: stackedOnNext
  31622. });
  31623. }
  31624. return;
  31625. } // `diff.current` is subset of `current` (which should be ensured by
  31626. // turnPointsIntoStep), so points in `__points` can be updated when
  31627. // points in `current` are update during animation.
  31628. polyline.shape.__points = diff.current;
  31629. polyline.shape.points = current;
  31630. updateProps(polyline, {
  31631. shape: {
  31632. points: next
  31633. }
  31634. }, seriesModel);
  31635. if (polygon) {
  31636. polygon.setShape({
  31637. points: current,
  31638. stackedOnPoints: stackedOnCurrent
  31639. });
  31640. updateProps(polygon, {
  31641. shape: {
  31642. points: next,
  31643. stackedOnPoints: stackedOnNext
  31644. }
  31645. }, seriesModel);
  31646. }
  31647. var updatedDataInfo = [];
  31648. var diffStatus = diff.status;
  31649. for (var i = 0; i < diffStatus.length; i++) {
  31650. var cmd = diffStatus[i].cmd;
  31651. if (cmd === '=') {
  31652. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  31653. if (el) {
  31654. updatedDataInfo.push({
  31655. el: el,
  31656. ptIdx: i // Index of points
  31657. });
  31658. }
  31659. }
  31660. }
  31661. if (polyline.animators && polyline.animators.length) {
  31662. polyline.animators[0].during(function () {
  31663. for (var i = 0; i < updatedDataInfo.length; i++) {
  31664. var el = updatedDataInfo[i].el;
  31665. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  31666. }
  31667. });
  31668. }
  31669. },
  31670. remove: function (ecModel) {
  31671. var group = this.group;
  31672. var oldData = this._data;
  31673. this._lineGroup.removeAll();
  31674. this._symbolDraw.remove(true); // Remove temporary created elements when highlighting
  31675. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  31676. if (el.__temp) {
  31677. group.remove(el);
  31678. oldData.setItemGraphicEl(idx, null);
  31679. }
  31680. });
  31681. this._polyline = this._polygon = this._coordSys = this._points = this._stackedOnPoints = this._data = null;
  31682. }
  31683. });
  31684. /*
  31685. * Licensed to the Apache Software Foundation (ASF) under one
  31686. * or more contributor license agreements. See the NOTICE file
  31687. * distributed with this work for additional information
  31688. * regarding copyright ownership. The ASF licenses this file
  31689. * to you under the Apache License, Version 2.0 (the
  31690. * "License"); you may not use this file except in compliance
  31691. * with the License. You may obtain a copy of the License at
  31692. *
  31693. * http://www.apache.org/licenses/LICENSE-2.0
  31694. *
  31695. * Unless required by applicable law or agreed to in writing,
  31696. * software distributed under the License is distributed on an
  31697. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31698. * KIND, either express or implied. See the License for the
  31699. * specific language governing permissions and limitations
  31700. * under the License.
  31701. */
  31702. var visualSymbol = function (seriesType, defaultSymbolType, legendSymbol) {
  31703. // Encoding visual for all series include which is filtered for legend drawing
  31704. return {
  31705. seriesType: seriesType,
  31706. // For legend.
  31707. performRawSeries: true,
  31708. reset: function (seriesModel, ecModel, api) {
  31709. var data = seriesModel.getData();
  31710. var symbolType = seriesModel.get('symbol');
  31711. var symbolSize = seriesModel.get('symbolSize');
  31712. var keepAspect = seriesModel.get('symbolKeepAspect');
  31713. var symbolRotate = seriesModel.get('symbolRotate');
  31714. var hasSymbolTypeCallback = isFunction$1(symbolType);
  31715. var hasSymbolSizeCallback = isFunction$1(symbolSize);
  31716. var hasSymbolRotateCallback = isFunction$1(symbolRotate);
  31717. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback || hasSymbolRotateCallback;
  31718. var seriesSymbol = !hasSymbolTypeCallback && symbolType ? symbolType : defaultSymbolType;
  31719. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  31720. data.setVisual({
  31721. legendSymbol: legendSymbol || seriesSymbol,
  31722. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  31723. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  31724. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  31725. // some cases but generally it is not recommanded.
  31726. symbol: seriesSymbol,
  31727. symbolSize: seriesSymbolSize,
  31728. symbolKeepAspect: keepAspect,
  31729. symbolRotate: symbolRotate
  31730. }); // Only visible series has each data be visual encoded
  31731. if (ecModel.isSeriesFiltered(seriesModel)) {
  31732. return;
  31733. }
  31734. function dataEach(data, idx) {
  31735. if (hasCallback) {
  31736. var rawValue = seriesModel.getRawValue(idx);
  31737. var params = seriesModel.getDataParams(idx);
  31738. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  31739. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  31740. hasSymbolRotateCallback && data.setItemVisual(idx, 'symbolRotate', symbolRotate(rawValue, params));
  31741. }
  31742. if (data.hasItemOption) {
  31743. var itemModel = data.getItemModel(idx);
  31744. var itemSymbolType = itemModel.getShallow('symbol', true);
  31745. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  31746. var itemSymbolRotate = itemModel.getShallow('symbolRotate', true);
  31747. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true); // If has item symbol
  31748. if (itemSymbolType != null) {
  31749. data.setItemVisual(idx, 'symbol', itemSymbolType);
  31750. }
  31751. if (itemSymbolSize != null) {
  31752. // PENDING Transform symbolSize ?
  31753. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  31754. }
  31755. if (itemSymbolRotate != null) {
  31756. data.setItemVisual(idx, 'symbolRotate', itemSymbolRotate);
  31757. }
  31758. if (itemSymbolKeepAspect != null) {
  31759. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  31760. }
  31761. }
  31762. }
  31763. return {
  31764. dataEach: data.hasItemOption || hasCallback ? dataEach : null
  31765. };
  31766. }
  31767. };
  31768. };
  31769. /*
  31770. * Licensed to the Apache Software Foundation (ASF) under one
  31771. * or more contributor license agreements. See the NOTICE file
  31772. * distributed with this work for additional information
  31773. * regarding copyright ownership. The ASF licenses this file
  31774. * to you under the Apache License, Version 2.0 (the
  31775. * "License"); you may not use this file except in compliance
  31776. * with the License. You may obtain a copy of the License at
  31777. *
  31778. * http://www.apache.org/licenses/LICENSE-2.0
  31779. *
  31780. * Unless required by applicable law or agreed to in writing,
  31781. * software distributed under the License is distributed on an
  31782. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31783. * KIND, either express or implied. See the License for the
  31784. * specific language governing permissions and limitations
  31785. * under the License.
  31786. */
  31787. /* global Float32Array */
  31788. var layoutPoints = function (seriesType) {
  31789. return {
  31790. seriesType: seriesType,
  31791. plan: createRenderPlanner(),
  31792. reset: function (seriesModel) {
  31793. var data = seriesModel.getData();
  31794. var coordSys = seriesModel.coordinateSystem;
  31795. var pipelineContext = seriesModel.pipelineContext;
  31796. var isLargeRender = pipelineContext.large;
  31797. if (!coordSys) {
  31798. return;
  31799. }
  31800. var dims = map(coordSys.dimensions, function (dim) {
  31801. return data.mapDimension(dim);
  31802. }).slice(0, 2);
  31803. var dimLen = dims.length;
  31804. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  31805. if (isDimensionStacked(data, dims[0]
  31806. /*, dims[1]*/
  31807. )) {
  31808. dims[0] = stackResultDim;
  31809. }
  31810. if (isDimensionStacked(data, dims[1]
  31811. /*, dims[0]*/
  31812. )) {
  31813. dims[1] = stackResultDim;
  31814. }
  31815. function progress(params, data) {
  31816. var segCount = params.end - params.start;
  31817. var points = isLargeRender && new Float32Array(segCount * dimLen);
  31818. for (var i = params.start, offset = 0, tmpIn = [], tmpOut = []; i < params.end; i++) {
  31819. var point;
  31820. if (dimLen === 1) {
  31821. var x = data.get(dims[0], i);
  31822. point = !isNaN(x) && coordSys.dataToPoint(x, null, tmpOut);
  31823. } else {
  31824. var x = tmpIn[0] = data.get(dims[0], i);
  31825. var y = tmpIn[1] = data.get(dims[1], i); // Also {Array.<number>}, not undefined to avoid if...else... statement
  31826. point = !isNaN(x) && !isNaN(y) && coordSys.dataToPoint(tmpIn, null, tmpOut);
  31827. }
  31828. if (isLargeRender) {
  31829. points[offset++] = point ? point[0] : NaN;
  31830. points[offset++] = point ? point[1] : NaN;
  31831. } else {
  31832. data.setItemLayout(i, point && point.slice() || [NaN, NaN]);
  31833. }
  31834. }
  31835. isLargeRender && data.setLayout('symbolPoints', points);
  31836. }
  31837. return dimLen && {
  31838. progress: progress
  31839. };
  31840. }
  31841. };
  31842. };
  31843. /*
  31844. * Licensed to the Apache Software Foundation (ASF) under one
  31845. * or more contributor license agreements. See the NOTICE file
  31846. * distributed with this work for additional information
  31847. * regarding copyright ownership. The ASF licenses this file
  31848. * to you under the Apache License, Version 2.0 (the
  31849. * "License"); you may not use this file except in compliance
  31850. * with the License. You may obtain a copy of the License at
  31851. *
  31852. * http://www.apache.org/licenses/LICENSE-2.0
  31853. *
  31854. * Unless required by applicable law or agreed to in writing,
  31855. * software distributed under the License is distributed on an
  31856. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31857. * KIND, either express or implied. See the License for the
  31858. * specific language governing permissions and limitations
  31859. * under the License.
  31860. */
  31861. var samplers = {
  31862. average: function (frame) {
  31863. var sum = 0;
  31864. var count = 0;
  31865. for (var i = 0; i < frame.length; i++) {
  31866. if (!isNaN(frame[i])) {
  31867. sum += frame[i];
  31868. count++;
  31869. }
  31870. } // Return NaN if count is 0
  31871. return count === 0 ? NaN : sum / count;
  31872. },
  31873. sum: function (frame) {
  31874. var sum = 0;
  31875. for (var i = 0; i < frame.length; i++) {
  31876. // Ignore NaN
  31877. sum += frame[i] || 0;
  31878. }
  31879. return sum;
  31880. },
  31881. max: function (frame) {
  31882. var max = -Infinity;
  31883. for (var i = 0; i < frame.length; i++) {
  31884. frame[i] > max && (max = frame[i]);
  31885. } // NaN will cause illegal axis extent.
  31886. return isFinite(max) ? max : NaN;
  31887. },
  31888. min: function (frame) {
  31889. var min = Infinity;
  31890. for (var i = 0; i < frame.length; i++) {
  31891. frame[i] < min && (min = frame[i]);
  31892. } // NaN will cause illegal axis extent.
  31893. return isFinite(min) ? min : NaN;
  31894. },
  31895. // TODO
  31896. // Median
  31897. nearest: function (frame) {
  31898. return frame[0];
  31899. }
  31900. };
  31901. var indexSampler = function (frame, value) {
  31902. return Math.round(frame.length / 2);
  31903. };
  31904. var dataSample = function (seriesType) {
  31905. return {
  31906. seriesType: seriesType,
  31907. modifyOutputEnd: true,
  31908. reset: function (seriesModel, ecModel, api) {
  31909. var data = seriesModel.getData();
  31910. var sampling = seriesModel.get('sampling');
  31911. var coordSys = seriesModel.coordinateSystem; // Only cartesian2d support down sampling
  31912. if (coordSys.type === 'cartesian2d' && sampling) {
  31913. var baseAxis = coordSys.getBaseAxis();
  31914. var valueAxis = coordSys.getOtherAxis(baseAxis);
  31915. var extent = baseAxis.getExtent(); // Coordinste system has been resized
  31916. var size = Math.abs(extent[1] - extent[0]);
  31917. var rate = Math.round(data.count() / size);
  31918. if (rate > 1) {
  31919. var sampler;
  31920. if (typeof sampling === 'string') {
  31921. sampler = samplers[sampling];
  31922. } else if (typeof sampling === 'function') {
  31923. sampler = sampling;
  31924. }
  31925. if (sampler) {
  31926. // Only support sample the first dim mapped from value axis.
  31927. seriesModel.setData(data.downSample(data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler));
  31928. }
  31929. }
  31930. }
  31931. }
  31932. };
  31933. };
  31934. /*
  31935. * Licensed to the Apache Software Foundation (ASF) under one
  31936. * or more contributor license agreements. See the NOTICE file
  31937. * distributed with this work for additional information
  31938. * regarding copyright ownership. The ASF licenses this file
  31939. * to you under the Apache License, Version 2.0 (the
  31940. * "License"); you may not use this file except in compliance
  31941. * with the License. You may obtain a copy of the License at
  31942. *
  31943. * http://www.apache.org/licenses/LICENSE-2.0
  31944. *
  31945. * Unless required by applicable law or agreed to in writing,
  31946. * software distributed under the License is distributed on an
  31947. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31948. * KIND, either express or implied. See the License for the
  31949. * specific language governing permissions and limitations
  31950. * under the License.
  31951. */
  31952. /**
  31953. * Cartesian coordinate system
  31954. * @module echarts/coord/Cartesian
  31955. *
  31956. */
  31957. function dimAxisMapper(dim) {
  31958. return this._axes[dim];
  31959. }
  31960. /**
  31961. * @alias module:echarts/coord/Cartesian
  31962. * @constructor
  31963. */
  31964. var Cartesian = function (name) {
  31965. this._axes = {};
  31966. this._dimList = [];
  31967. /**
  31968. * @type {string}
  31969. */
  31970. this.name = name || '';
  31971. };
  31972. Cartesian.prototype = {
  31973. constructor: Cartesian,
  31974. type: 'cartesian',
  31975. /**
  31976. * Get axis
  31977. * @param {number|string} dim
  31978. * @return {module:echarts/coord/Cartesian~Axis}
  31979. */
  31980. getAxis: function (dim) {
  31981. return this._axes[dim];
  31982. },
  31983. /**
  31984. * Get axes list
  31985. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  31986. */
  31987. getAxes: function () {
  31988. return map(this._dimList, dimAxisMapper, this);
  31989. },
  31990. /**
  31991. * Get axes list by given scale type
  31992. */
  31993. getAxesByScale: function (scaleType) {
  31994. scaleType = scaleType.toLowerCase();
  31995. return filter(this.getAxes(), function (axis) {
  31996. return axis.scale.type === scaleType;
  31997. });
  31998. },
  31999. /**
  32000. * Add axis
  32001. * @param {module:echarts/coord/Cartesian.Axis}
  32002. */
  32003. addAxis: function (axis) {
  32004. var dim = axis.dim;
  32005. this._axes[dim] = axis;
  32006. this._dimList.push(dim);
  32007. },
  32008. /**
  32009. * Convert data to coord in nd space
  32010. * @param {Array.<number>|Object.<string, number>} val
  32011. * @return {Array.<number>|Object.<string, number>}
  32012. */
  32013. dataToCoord: function (val) {
  32014. return this._dataCoordConvert(val, 'dataToCoord');
  32015. },
  32016. /**
  32017. * Convert coord in nd space to data
  32018. * @param {Array.<number>|Object.<string, number>} val
  32019. * @return {Array.<number>|Object.<string, number>}
  32020. */
  32021. coordToData: function (val) {
  32022. return this._dataCoordConvert(val, 'coordToData');
  32023. },
  32024. _dataCoordConvert: function (input, method) {
  32025. var dimList = this._dimList;
  32026. var output = input instanceof Array ? [] : {};
  32027. for (var i = 0; i < dimList.length; i++) {
  32028. var dim = dimList[i];
  32029. var axis = this._axes[dim];
  32030. output[dim] = axis[method](input[dim]);
  32031. }
  32032. return output;
  32033. }
  32034. };
  32035. /*
  32036. * Licensed to the Apache Software Foundation (ASF) under one
  32037. * or more contributor license agreements. See the NOTICE file
  32038. * distributed with this work for additional information
  32039. * regarding copyright ownership. The ASF licenses this file
  32040. * to you under the Apache License, Version 2.0 (the
  32041. * "License"); you may not use this file except in compliance
  32042. * with the License. You may obtain a copy of the License at
  32043. *
  32044. * http://www.apache.org/licenses/LICENSE-2.0
  32045. *
  32046. * Unless required by applicable law or agreed to in writing,
  32047. * software distributed under the License is distributed on an
  32048. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32049. * KIND, either express or implied. See the License for the
  32050. * specific language governing permissions and limitations
  32051. * under the License.
  32052. */
  32053. function Cartesian2D(name) {
  32054. Cartesian.call(this, name);
  32055. }
  32056. Cartesian2D.prototype = {
  32057. constructor: Cartesian2D,
  32058. type: 'cartesian2d',
  32059. /**
  32060. * @type {Array.<string>}
  32061. * @readOnly
  32062. */
  32063. dimensions: ['x', 'y'],
  32064. /**
  32065. * Base axis will be used on stacking.
  32066. *
  32067. * @return {module:echarts/coord/cartesian/Axis2D}
  32068. */
  32069. getBaseAxis: function () {
  32070. return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x');
  32071. },
  32072. /**
  32073. * If contain point
  32074. * @param {Array.<number>} point
  32075. * @return {boolean}
  32076. */
  32077. containPoint: function (point) {
  32078. var axisX = this.getAxis('x');
  32079. var axisY = this.getAxis('y');
  32080. return axisX.contain(axisX.toLocalCoord(point[0])) && axisY.contain(axisY.toLocalCoord(point[1]));
  32081. },
  32082. /**
  32083. * If contain data
  32084. * @param {Array.<number>} data
  32085. * @return {boolean}
  32086. */
  32087. containData: function (data) {
  32088. return this.getAxis('x').containData(data[0]) && this.getAxis('y').containData(data[1]);
  32089. },
  32090. /**
  32091. * @param {Array.<number>} data
  32092. * @param {Array.<number>} out
  32093. * @return {Array.<number>}
  32094. */
  32095. dataToPoint: function (data, reserved, out) {
  32096. var xAxis = this.getAxis('x');
  32097. var yAxis = this.getAxis('y');
  32098. out = out || [];
  32099. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(data[0]));
  32100. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(data[1]));
  32101. return out;
  32102. },
  32103. /**
  32104. * @param {Array.<number>} data
  32105. * @param {Array.<number>} out
  32106. * @return {Array.<number>}
  32107. */
  32108. clampData: function (data, out) {
  32109. var xScale = this.getAxis('x').scale;
  32110. var yScale = this.getAxis('y').scale;
  32111. var xAxisExtent = xScale.getExtent();
  32112. var yAxisExtent = yScale.getExtent();
  32113. var x = xScale.parse(data[0]);
  32114. var y = yScale.parse(data[1]);
  32115. out = out || [];
  32116. out[0] = Math.min(Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x), Math.max(xAxisExtent[0], xAxisExtent[1]));
  32117. out[1] = Math.min(Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y), Math.max(yAxisExtent[0], yAxisExtent[1]));
  32118. return out;
  32119. },
  32120. /**
  32121. * @param {Array.<number>} point
  32122. * @param {Array.<number>} out
  32123. * @return {Array.<number>}
  32124. */
  32125. pointToData: function (point, out) {
  32126. var xAxis = this.getAxis('x');
  32127. var yAxis = this.getAxis('y');
  32128. out = out || [];
  32129. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]));
  32130. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]));
  32131. return out;
  32132. },
  32133. /**
  32134. * Get other axis
  32135. * @param {module:echarts/coord/cartesian/Axis2D} axis
  32136. */
  32137. getOtherAxis: function (axis) {
  32138. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  32139. },
  32140. /**
  32141. * Get rect area of cartesian.
  32142. * Area will have a contain function to determine if a point is in the coordinate system.
  32143. * @return {BoundingRect}
  32144. */
  32145. getArea: function () {
  32146. var xExtent = this.getAxis('x').getGlobalExtent();
  32147. var yExtent = this.getAxis('y').getGlobalExtent();
  32148. var x = Math.min(xExtent[0], xExtent[1]);
  32149. var y = Math.min(yExtent[0], yExtent[1]);
  32150. var width = Math.max(xExtent[0], xExtent[1]) - x;
  32151. var height = Math.max(yExtent[0], yExtent[1]) - y;
  32152. var rect = new BoundingRect(x, y, width, height);
  32153. return rect;
  32154. }
  32155. };
  32156. inherits(Cartesian2D, Cartesian);
  32157. /*
  32158. * Licensed to the Apache Software Foundation (ASF) under one
  32159. * or more contributor license agreements. See the NOTICE file
  32160. * distributed with this work for additional information
  32161. * regarding copyright ownership. The ASF licenses this file
  32162. * to you under the Apache License, Version 2.0 (the
  32163. * "License"); you may not use this file except in compliance
  32164. * with the License. You may obtain a copy of the License at
  32165. *
  32166. * http://www.apache.org/licenses/LICENSE-2.0
  32167. *
  32168. * Unless required by applicable law or agreed to in writing,
  32169. * software distributed under the License is distributed on an
  32170. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32171. * KIND, either express or implied. See the License for the
  32172. * specific language governing permissions and limitations
  32173. * under the License.
  32174. */
  32175. /**
  32176. * Extend axis 2d
  32177. * @constructor module:echarts/coord/cartesian/Axis2D
  32178. * @extends {module:echarts/coord/cartesian/Axis}
  32179. * @param {string} dim
  32180. * @param {*} scale
  32181. * @param {Array.<number>} coordExtent
  32182. * @param {string} axisType
  32183. * @param {string} position
  32184. */
  32185. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  32186. Axis.call(this, dim, scale, coordExtent);
  32187. /**
  32188. * Axis type
  32189. * - 'category'
  32190. * - 'value'
  32191. * - 'time'
  32192. * - 'log'
  32193. * @type {string}
  32194. */
  32195. this.type = axisType || 'value';
  32196. /**
  32197. * Axis position
  32198. * - 'top'
  32199. * - 'bottom'
  32200. * - 'left'
  32201. * - 'right'
  32202. */
  32203. this.position = position || 'bottom';
  32204. };
  32205. Axis2D.prototype = {
  32206. constructor: Axis2D,
  32207. /**
  32208. * Index of axis, can be used as key
  32209. */
  32210. index: 0,
  32211. /**
  32212. * Implemented in <module:echarts/coord/cartesian/Grid>.
  32213. * @return {Array.<module:echarts/coord/cartesian/Axis2D>}
  32214. * If not on zero of other axis, return null/undefined.
  32215. * If no axes, return an empty array.
  32216. */
  32217. getAxesOnZeroOf: null,
  32218. /**
  32219. * Axis model
  32220. * @param {module:echarts/coord/cartesian/AxisModel}
  32221. */
  32222. model: null,
  32223. isHorizontal: function () {
  32224. var position = this.position;
  32225. return position === 'top' || position === 'bottom';
  32226. },
  32227. /**
  32228. * Each item cooresponds to this.getExtent(), which
  32229. * means globalExtent[0] may greater than globalExtent[1],
  32230. * unless `asc` is input.
  32231. *
  32232. * @param {boolean} [asc]
  32233. * @return {Array.<number>}
  32234. */
  32235. getGlobalExtent: function (asc) {
  32236. var ret = this.getExtent();
  32237. ret[0] = this.toGlobalCoord(ret[0]);
  32238. ret[1] = this.toGlobalCoord(ret[1]);
  32239. asc && ret[0] > ret[1] && ret.reverse();
  32240. return ret;
  32241. },
  32242. getOtherAxis: function () {
  32243. this.grid.getOtherAxis();
  32244. },
  32245. /**
  32246. * @override
  32247. */
  32248. pointToData: function (point, clamp) {
  32249. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  32250. },
  32251. /**
  32252. * Transform global coord to local coord,
  32253. * i.e. var localCoord = axis.toLocalCoord(80);
  32254. * designate by module:echarts/coord/cartesian/Grid.
  32255. * @type {Function}
  32256. */
  32257. toLocalCoord: null,
  32258. /**
  32259. * Transform global coord to local coord,
  32260. * i.e. var globalCoord = axis.toLocalCoord(40);
  32261. * designate by module:echarts/coord/cartesian/Grid.
  32262. * @type {Function}
  32263. */
  32264. toGlobalCoord: null
  32265. };
  32266. inherits(Axis2D, Axis);
  32267. /*
  32268. * Licensed to the Apache Software Foundation (ASF) under one
  32269. * or more contributor license agreements. See the NOTICE file
  32270. * distributed with this work for additional information
  32271. * regarding copyright ownership. The ASF licenses this file
  32272. * to you under the Apache License, Version 2.0 (the
  32273. * "License"); you may not use this file except in compliance
  32274. * with the License. You may obtain a copy of the License at
  32275. *
  32276. * http://www.apache.org/licenses/LICENSE-2.0
  32277. *
  32278. * Unless required by applicable law or agreed to in writing,
  32279. * software distributed under the License is distributed on an
  32280. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32281. * KIND, either express or implied. See the License for the
  32282. * specific language governing permissions and limitations
  32283. * under the License.
  32284. */
  32285. var defaultOption = {
  32286. show: true,
  32287. zlevel: 0,
  32288. z: 0,
  32289. // Inverse the axis.
  32290. inverse: false,
  32291. // Axis name displayed.
  32292. name: '',
  32293. // 'start' | 'middle' | 'end'
  32294. nameLocation: 'end',
  32295. // By degree. By default auto rotate by nameLocation.
  32296. nameRotate: null,
  32297. nameTruncate: {
  32298. maxWidth: null,
  32299. ellipsis: '...',
  32300. placeholder: '.'
  32301. },
  32302. // Use global text style by default.
  32303. nameTextStyle: {},
  32304. // The gap between axisName and axisLine.
  32305. nameGap: 15,
  32306. // Default `false` to support tooltip.
  32307. silent: false,
  32308. // Default `false` to avoid legacy user event listener fail.
  32309. triggerEvent: false,
  32310. tooltip: {
  32311. show: false
  32312. },
  32313. axisPointer: {},
  32314. axisLine: {
  32315. show: true,
  32316. onZero: true,
  32317. onZeroAxisIndex: null,
  32318. lineStyle: {
  32319. color: '#333',
  32320. width: 1,
  32321. type: 'solid'
  32322. },
  32323. // The arrow at both ends the the axis.
  32324. symbol: ['none', 'none'],
  32325. symbolSize: [10, 15]
  32326. },
  32327. axisTick: {
  32328. show: true,
  32329. // Whether axisTick is inside the grid or outside the grid.
  32330. inside: false,
  32331. // The length of axisTick.
  32332. length: 5,
  32333. lineStyle: {
  32334. width: 1
  32335. }
  32336. },
  32337. axisLabel: {
  32338. show: true,
  32339. // Whether axisLabel is inside the grid or outside the grid.
  32340. inside: false,
  32341. rotate: 0,
  32342. // true | false | null/undefined (auto)
  32343. showMinLabel: null,
  32344. // true | false | null/undefined (auto)
  32345. showMaxLabel: null,
  32346. margin: 8,
  32347. // formatter: null,
  32348. fontSize: 12
  32349. },
  32350. splitLine: {
  32351. show: true,
  32352. lineStyle: {
  32353. color: ['#ccc'],
  32354. width: 1,
  32355. type: 'solid'
  32356. }
  32357. },
  32358. splitArea: {
  32359. show: false,
  32360. areaStyle: {
  32361. color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
  32362. }
  32363. }
  32364. };
  32365. var axisDefault = {};
  32366. axisDefault.categoryAxis = merge({
  32367. // The gap at both ends of the axis. For categoryAxis, boolean.
  32368. boundaryGap: true,
  32369. // Set false to faster category collection.
  32370. // Only usefull in the case like: category is
  32371. // ['2012-01-01', '2012-01-02', ...], where the input
  32372. // data has been ensured not duplicate and is large data.
  32373. // null means "auto":
  32374. // if axis.data provided, do not deduplication,
  32375. // else do deduplication.
  32376. deduplication: null,
  32377. // splitArea: {
  32378. // show: false
  32379. // },
  32380. splitLine: {
  32381. show: false
  32382. },
  32383. axisTick: {
  32384. // If tick is align with label when boundaryGap is true
  32385. alignWithLabel: false,
  32386. interval: 'auto'
  32387. },
  32388. axisLabel: {
  32389. interval: 'auto'
  32390. }
  32391. }, defaultOption);
  32392. axisDefault.valueAxis = merge({
  32393. // The gap at both ends of the axis. For value axis, [GAP, GAP], where
  32394. // `GAP` can be an absolute pixel number (like `35`), or percent (like `'30%'`)
  32395. boundaryGap: [0, 0],
  32396. // TODO
  32397. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  32398. // Min value of the axis. can be:
  32399. // + a number
  32400. // + 'dataMin': use the min value in data.
  32401. // + null/undefined: auto decide min value (consider pretty look and boundaryGap).
  32402. // min: null,
  32403. // Max value of the axis. can be:
  32404. // + a number
  32405. // + 'dataMax': use the max value in data.
  32406. // + null/undefined: auto decide max value (consider pretty look and boundaryGap).
  32407. // max: null,
  32408. // Readonly prop, specifies start value of the range when using data zoom.
  32409. // rangeStart: null
  32410. // Readonly prop, specifies end value of the range when using data zoom.
  32411. // rangeEnd: null
  32412. // Optional value can be:
  32413. // + `false`: always include value 0.
  32414. // + `true`: the extent do not consider value 0.
  32415. // scale: false,
  32416. // AxisTick and axisLabel and splitLine are caculated based on splitNumber.
  32417. splitNumber: 5,
  32418. // Interval specifies the span of the ticks is mandatorily.
  32419. // interval: null
  32420. // Specify min interval when auto calculate tick interval.
  32421. // minInterval: null
  32422. // Specify max interval when auto calculate tick interval.
  32423. // maxInterval: null
  32424. minorTick: {
  32425. // Minor tick, not available for cateogry axis.
  32426. show: false,
  32427. // Split number of minor ticks. The value should be in range of (0, 100)
  32428. splitNumber: 5,
  32429. // Lenght of minor tick
  32430. length: 3,
  32431. // Same inside with axisTick
  32432. // Line style
  32433. lineStyle: {// Default to be same with axisTick
  32434. }
  32435. },
  32436. minorSplitLine: {
  32437. show: false,
  32438. lineStyle: {
  32439. color: '#eee',
  32440. width: 1
  32441. }
  32442. }
  32443. }, defaultOption);
  32444. axisDefault.timeAxis = defaults({
  32445. scale: true,
  32446. min: 'dataMin',
  32447. max: 'dataMax'
  32448. }, axisDefault.valueAxis);
  32449. axisDefault.logAxis = defaults({
  32450. scale: true,
  32451. logBase: 10
  32452. }, axisDefault.valueAxis);
  32453. /*
  32454. * Licensed to the Apache Software Foundation (ASF) under one
  32455. * or more contributor license agreements. See the NOTICE file
  32456. * distributed with this work for additional information
  32457. * regarding copyright ownership. The ASF licenses this file
  32458. * to you under the Apache License, Version 2.0 (the
  32459. * "License"); you may not use this file except in compliance
  32460. * with the License. You may obtain a copy of the License at
  32461. *
  32462. * http://www.apache.org/licenses/LICENSE-2.0
  32463. *
  32464. * Unless required by applicable law or agreed to in writing,
  32465. * software distributed under the License is distributed on an
  32466. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32467. * KIND, either express or implied. See the License for the
  32468. * specific language governing permissions and limitations
  32469. * under the License.
  32470. */
  32471. // FIXME axisType is fixed ?
  32472. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  32473. /**
  32474. * Generate sub axis model class
  32475. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  32476. * @param {module:echarts/model/Component} BaseAxisModelClass
  32477. * @param {Function} axisTypeDefaulter
  32478. * @param {Object} [extraDefaultOption]
  32479. */
  32480. var axisModelCreator = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  32481. each$1(AXIS_TYPES, function (axisType) {
  32482. BaseAxisModelClass.extend({
  32483. /**
  32484. * @readOnly
  32485. */
  32486. type: axisName + 'Axis.' + axisType,
  32487. mergeDefaultAndTheme: function (option, ecModel) {
  32488. var layoutMode = this.layoutMode;
  32489. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  32490. var themeModel = ecModel.getTheme();
  32491. merge(option, themeModel.get(axisType + 'Axis'));
  32492. merge(option, this.getDefaultOption());
  32493. option.type = axisTypeDefaulter(axisName, option);
  32494. if (layoutMode) {
  32495. mergeLayoutParam(option, inputPositionParams, layoutMode);
  32496. }
  32497. },
  32498. /**
  32499. * @override
  32500. */
  32501. optionUpdated: function () {
  32502. var thisOption = this.option;
  32503. if (thisOption.type === 'category') {
  32504. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  32505. }
  32506. },
  32507. /**
  32508. * Should not be called before all of 'getInitailData' finished.
  32509. * Because categories are collected during initializing data.
  32510. */
  32511. getCategories: function (rawData) {
  32512. var option = this.option; // FIXME
  32513. // warning if called before all of 'getInitailData' finished.
  32514. if (option.type === 'category') {
  32515. if (rawData) {
  32516. return option.data;
  32517. }
  32518. return this.__ordinalMeta.categories;
  32519. }
  32520. },
  32521. getOrdinalMeta: function () {
  32522. return this.__ordinalMeta;
  32523. },
  32524. defaultOption: mergeAll([{}, axisDefault[axisType + 'Axis'], extraDefaultOption], true)
  32525. });
  32526. });
  32527. ComponentModel.registerSubTypeDefaulter(axisName + 'Axis', curry(axisTypeDefaulter, axisName));
  32528. };
  32529. /*
  32530. * Licensed to the Apache Software Foundation (ASF) under one
  32531. * or more contributor license agreements. See the NOTICE file
  32532. * distributed with this work for additional information
  32533. * regarding copyright ownership. The ASF licenses this file
  32534. * to you under the Apache License, Version 2.0 (the
  32535. * "License"); you may not use this file except in compliance
  32536. * with the License. You may obtain a copy of the License at
  32537. *
  32538. * http://www.apache.org/licenses/LICENSE-2.0
  32539. *
  32540. * Unless required by applicable law or agreed to in writing,
  32541. * software distributed under the License is distributed on an
  32542. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32543. * KIND, either express or implied. See the License for the
  32544. * specific language governing permissions and limitations
  32545. * under the License.
  32546. */
  32547. var AxisModel = ComponentModel.extend({
  32548. type: 'cartesian2dAxis',
  32549. /**
  32550. * @type {module:echarts/coord/cartesian/Axis2D}
  32551. */
  32552. axis: null,
  32553. /**
  32554. * @override
  32555. */
  32556. init: function () {
  32557. AxisModel.superApply(this, 'init', arguments);
  32558. this.resetRange();
  32559. },
  32560. /**
  32561. * @override
  32562. */
  32563. mergeOption: function () {
  32564. AxisModel.superApply(this, 'mergeOption', arguments);
  32565. this.resetRange();
  32566. },
  32567. /**
  32568. * @override
  32569. */
  32570. restoreData: function () {
  32571. AxisModel.superApply(this, 'restoreData', arguments);
  32572. this.resetRange();
  32573. },
  32574. /**
  32575. * @override
  32576. * @return {module:echarts/model/Component}
  32577. */
  32578. getCoordSysModel: function () {
  32579. return this.ecModel.queryComponents({
  32580. mainType: 'grid',
  32581. index: this.option.gridIndex,
  32582. id: this.option.gridId
  32583. })[0];
  32584. }
  32585. });
  32586. function getAxisType(axisDim, option) {
  32587. // Default axis with data is category axis
  32588. return option.type || (option.data ? 'category' : 'value');
  32589. }
  32590. merge(AxisModel.prototype, axisModelCommonMixin);
  32591. var extraOption = {
  32592. // gridIndex: 0,
  32593. // gridId: '',
  32594. // Offset is for multiple axis on the same position
  32595. offset: 0
  32596. };
  32597. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  32598. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  32599. /*
  32600. * Licensed to the Apache Software Foundation (ASF) under one
  32601. * or more contributor license agreements. See the NOTICE file
  32602. * distributed with this work for additional information
  32603. * regarding copyright ownership. The ASF licenses this file
  32604. * to you under the Apache License, Version 2.0 (the
  32605. * "License"); you may not use this file except in compliance
  32606. * with the License. You may obtain a copy of the License at
  32607. *
  32608. * http://www.apache.org/licenses/LICENSE-2.0
  32609. *
  32610. * Unless required by applicable law or agreed to in writing,
  32611. * software distributed under the License is distributed on an
  32612. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32613. * KIND, either express or implied. See the License for the
  32614. * specific language governing permissions and limitations
  32615. * under the License.
  32616. */
  32617. // Grid 是在有直角坐标系的时候必须要存在的
  32618. // 所以这里也要被 Cartesian2D 依赖
  32619. ComponentModel.extend({
  32620. type: 'grid',
  32621. dependencies: ['xAxis', 'yAxis'],
  32622. layoutMode: 'box',
  32623. /**
  32624. * @type {module:echarts/coord/cartesian/Grid}
  32625. */
  32626. coordinateSystem: null,
  32627. defaultOption: {
  32628. show: false,
  32629. zlevel: 0,
  32630. z: 0,
  32631. left: '10%',
  32632. top: 60,
  32633. right: '10%',
  32634. bottom: 60,
  32635. // If grid size contain label
  32636. containLabel: false,
  32637. // width: {totalWidth} - left - right,
  32638. // height: {totalHeight} - top - bottom,
  32639. backgroundColor: 'rgba(0,0,0,0)',
  32640. borderWidth: 1,
  32641. borderColor: '#ccc'
  32642. }
  32643. });
  32644. /*
  32645. * Licensed to the Apache Software Foundation (ASF) under one
  32646. * or more contributor license agreements. See the NOTICE file
  32647. * distributed with this work for additional information
  32648. * regarding copyright ownership. The ASF licenses this file
  32649. * to you under the Apache License, Version 2.0 (the
  32650. * "License"); you may not use this file except in compliance
  32651. * with the License. You may obtain a copy of the License at
  32652. *
  32653. * http://www.apache.org/licenses/LICENSE-2.0
  32654. *
  32655. * Unless required by applicable law or agreed to in writing,
  32656. * software distributed under the License is distributed on an
  32657. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32658. * KIND, either express or implied. See the License for the
  32659. * specific language governing permissions and limitations
  32660. * under the License.
  32661. */
  32662. /**
  32663. * Grid is a region which contains at most 4 cartesian systems
  32664. *
  32665. * TODO Default cartesian
  32666. */
  32667. // Depends on GridModel, AxisModel, which performs preprocess.
  32668. /**
  32669. * Check if the axis is used in the specified grid
  32670. * @inner
  32671. */
  32672. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  32673. return axisModel.getCoordSysModel() === gridModel;
  32674. }
  32675. function Grid(gridModel, ecModel, api) {
  32676. /**
  32677. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  32678. * @private
  32679. */
  32680. this._coordsMap = {};
  32681. /**
  32682. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  32683. * @private
  32684. */
  32685. this._coordsList = [];
  32686. /**
  32687. * @type {Object.<string, Array.<module:echarts/coord/cartesian/Axis2D>>}
  32688. * @private
  32689. */
  32690. this._axesMap = {};
  32691. /**
  32692. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  32693. * @private
  32694. */
  32695. this._axesList = [];
  32696. this._initCartesian(gridModel, ecModel, api);
  32697. this.model = gridModel;
  32698. }
  32699. var gridProto = Grid.prototype;
  32700. gridProto.type = 'grid';
  32701. gridProto.axisPointerEnabled = true;
  32702. gridProto.getRect = function () {
  32703. return this._rect;
  32704. };
  32705. gridProto.update = function (ecModel, api) {
  32706. var axesMap = this._axesMap;
  32707. this._updateScale(ecModel, this.model);
  32708. each$1(axesMap.x, function (xAxis) {
  32709. niceScaleExtent(xAxis.scale, xAxis.model);
  32710. });
  32711. each$1(axesMap.y, function (yAxis) {
  32712. niceScaleExtent(yAxis.scale, yAxis.model);
  32713. }); // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  32714. var onZeroRecords = {};
  32715. each$1(axesMap.x, function (xAxis) {
  32716. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  32717. });
  32718. each$1(axesMap.y, function (yAxis) {
  32719. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  32720. }); // Resize again if containLabel is enabled
  32721. // FIXME It may cause getting wrong grid size in data processing stage
  32722. this.resize(this.model, api);
  32723. };
  32724. function fixAxisOnZero(axesMap, otherAxisDim, axis, onZeroRecords) {
  32725. axis.getAxesOnZeroOf = function () {
  32726. // TODO: onZero of multiple axes.
  32727. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  32728. }; // onZero can not be enabled in these two situations:
  32729. // 1. When any other axis is a category axis.
  32730. // 2. When no axis is cross 0 point.
  32731. var otherAxes = axesMap[otherAxisDim];
  32732. var otherAxisOnZeroOf;
  32733. var axisModel = axis.model;
  32734. var onZero = axisModel.get('axisLine.onZero');
  32735. var onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex');
  32736. if (!onZero) {
  32737. return;
  32738. } // If target axis is specified.
  32739. if (onZeroAxisIndex != null) {
  32740. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  32741. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  32742. }
  32743. } else {
  32744. // Find the first available other axis.
  32745. for (var idx in otherAxes) {
  32746. if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx]) // Consider that two Y axes on one value axis,
  32747. // if both onZero, the two Y axes overlap.
  32748. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]) {
  32749. otherAxisOnZeroOf = otherAxes[idx];
  32750. break;
  32751. }
  32752. }
  32753. }
  32754. if (otherAxisOnZeroOf) {
  32755. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  32756. }
  32757. function getOnZeroRecordKey(axis) {
  32758. return axis.dim + '_' + axis.index;
  32759. }
  32760. }
  32761. function canOnZeroToAxis(axis) {
  32762. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  32763. }
  32764. /**
  32765. * Resize the grid
  32766. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  32767. * @param {module:echarts/ExtensionAPI} api
  32768. */
  32769. gridProto.resize = function (gridModel, api, ignoreContainLabel) {
  32770. var gridRect = getLayoutRect(gridModel.getBoxLayoutParams(), {
  32771. width: api.getWidth(),
  32772. height: api.getHeight()
  32773. });
  32774. this._rect = gridRect;
  32775. var axesList = this._axesList;
  32776. adjustAxes(); // Minus label size
  32777. if (!ignoreContainLabel && gridModel.get('containLabel')) {
  32778. each$1(axesList, function (axis) {
  32779. if (!axis.model.get('axisLabel.inside')) {
  32780. var labelUnionRect = estimateLabelUnionRect(axis);
  32781. if (labelUnionRect) {
  32782. var dim = axis.isHorizontal() ? 'height' : 'width';
  32783. var margin = axis.model.get('axisLabel.margin');
  32784. gridRect[dim] -= labelUnionRect[dim] + margin;
  32785. if (axis.position === 'top') {
  32786. gridRect.y += labelUnionRect.height + margin;
  32787. } else if (axis.position === 'left') {
  32788. gridRect.x += labelUnionRect.width + margin;
  32789. }
  32790. }
  32791. }
  32792. });
  32793. adjustAxes();
  32794. }
  32795. function adjustAxes() {
  32796. each$1(axesList, function (axis) {
  32797. var isHorizontal = axis.isHorizontal();
  32798. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  32799. var idx = axis.inverse ? 1 : 0;
  32800. axis.setExtent(extent[idx], extent[1 - idx]);
  32801. updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
  32802. });
  32803. }
  32804. };
  32805. /**
  32806. * @param {string} axisType
  32807. * @param {number} [axisIndex]
  32808. */
  32809. gridProto.getAxis = function (axisType, axisIndex) {
  32810. var axesMapOnDim = this._axesMap[axisType];
  32811. if (axesMapOnDim != null) {
  32812. if (axisIndex == null) {
  32813. // Find first axis
  32814. for (var name in axesMapOnDim) {
  32815. if (axesMapOnDim.hasOwnProperty(name)) {
  32816. return axesMapOnDim[name];
  32817. }
  32818. }
  32819. }
  32820. return axesMapOnDim[axisIndex];
  32821. }
  32822. };
  32823. /**
  32824. * @return {Array.<module:echarts/coord/Axis>}
  32825. */
  32826. gridProto.getAxes = function () {
  32827. return this._axesList.slice();
  32828. };
  32829. /**
  32830. * Usage:
  32831. * grid.getCartesian(xAxisIndex, yAxisIndex);
  32832. * grid.getCartesian(xAxisIndex);
  32833. * grid.getCartesian(null, yAxisIndex);
  32834. * grid.getCartesian({xAxisIndex: ..., yAxisIndex: ...});
  32835. *
  32836. * @param {number|Object} [xAxisIndex]
  32837. * @param {number} [yAxisIndex]
  32838. */
  32839. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  32840. if (xAxisIndex != null && yAxisIndex != null) {
  32841. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  32842. return this._coordsMap[key];
  32843. }
  32844. if (isObject$1(xAxisIndex)) {
  32845. yAxisIndex = xAxisIndex.yAxisIndex;
  32846. xAxisIndex = xAxisIndex.xAxisIndex;
  32847. } // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  32848. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  32849. if (coordList[i].getAxis('x').index === xAxisIndex || coordList[i].getAxis('y').index === yAxisIndex) {
  32850. return coordList[i];
  32851. }
  32852. }
  32853. };
  32854. gridProto.getCartesians = function () {
  32855. return this._coordsList.slice();
  32856. };
  32857. /**
  32858. * @implements
  32859. * see {module:echarts/CoodinateSystem}
  32860. */
  32861. gridProto.convertToPixel = function (ecModel, finder, value) {
  32862. var target = this._findConvertTarget(ecModel, finder);
  32863. return target.cartesian ? target.cartesian.dataToPoint(value) : target.axis ? target.axis.toGlobalCoord(target.axis.dataToCoord(value)) : null;
  32864. };
  32865. /**
  32866. * @implements
  32867. * see {module:echarts/CoodinateSystem}
  32868. */
  32869. gridProto.convertFromPixel = function (ecModel, finder, value) {
  32870. var target = this._findConvertTarget(ecModel, finder);
  32871. return target.cartesian ? target.cartesian.pointToData(value) : target.axis ? target.axis.coordToData(target.axis.toLocalCoord(value)) : null;
  32872. };
  32873. /**
  32874. * @inner
  32875. */
  32876. gridProto._findConvertTarget = function (ecModel, finder) {
  32877. var seriesModel = finder.seriesModel;
  32878. var xAxisModel = finder.xAxisModel || seriesModel && seriesModel.getReferringComponents('xAxis')[0];
  32879. var yAxisModel = finder.yAxisModel || seriesModel && seriesModel.getReferringComponents('yAxis')[0];
  32880. var gridModel = finder.gridModel;
  32881. var coordsList = this._coordsList;
  32882. var cartesian;
  32883. var axis;
  32884. if (seriesModel) {
  32885. cartesian = seriesModel.coordinateSystem;
  32886. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  32887. } else if (xAxisModel && yAxisModel) {
  32888. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  32889. } else if (xAxisModel) {
  32890. axis = this.getAxis('x', xAxisModel.componentIndex);
  32891. } else if (yAxisModel) {
  32892. axis = this.getAxis('y', yAxisModel.componentIndex);
  32893. } // Lowest priority.
  32894. else if (gridModel) {
  32895. var grid = gridModel.coordinateSystem;
  32896. if (grid === this) {
  32897. cartesian = this._coordsList[0];
  32898. }
  32899. }
  32900. return {
  32901. cartesian: cartesian,
  32902. axis: axis
  32903. };
  32904. };
  32905. /**
  32906. * @implements
  32907. * see {module:echarts/CoodinateSystem}
  32908. */
  32909. gridProto.containPoint = function (point) {
  32910. var coord = this._coordsList[0];
  32911. if (coord) {
  32912. return coord.containPoint(point);
  32913. }
  32914. };
  32915. /**
  32916. * Initialize cartesian coordinate systems
  32917. * @private
  32918. */
  32919. gridProto._initCartesian = function (gridModel, ecModel, api) {
  32920. var axisPositionUsed = {
  32921. left: false,
  32922. right: false,
  32923. top: false,
  32924. bottom: false
  32925. };
  32926. var axesMap = {
  32927. x: {},
  32928. y: {}
  32929. };
  32930. var axesCount = {
  32931. x: 0,
  32932. y: 0
  32933. }; /// Create axis
  32934. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  32935. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  32936. if (!axesCount.x || !axesCount.y) {
  32937. // Roll back when there no either x or y axis
  32938. this._axesMap = {};
  32939. this._axesList = [];
  32940. return;
  32941. }
  32942. this._axesMap = axesMap; /// Create cartesian2d
  32943. each$1(axesMap.x, function (xAxis, xAxisIndex) {
  32944. each$1(axesMap.y, function (yAxis, yAxisIndex) {
  32945. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  32946. var cartesian = new Cartesian2D(key);
  32947. cartesian.grid = this;
  32948. cartesian.model = gridModel;
  32949. this._coordsMap[key] = cartesian;
  32950. this._coordsList.push(cartesian);
  32951. cartesian.addAxis(xAxis);
  32952. cartesian.addAxis(yAxis);
  32953. }, this);
  32954. }, this);
  32955. function createAxisCreator(axisType) {
  32956. return function (axisModel, idx) {
  32957. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  32958. return;
  32959. }
  32960. var axisPosition = axisModel.get('position');
  32961. if (axisType === 'x') {
  32962. // Fix position
  32963. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  32964. // Default bottom of X
  32965. axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
  32966. }
  32967. } else {
  32968. // Fix position
  32969. if (axisPosition !== 'left' && axisPosition !== 'right') {
  32970. // Default left of Y
  32971. axisPosition = axisPositionUsed.left ? 'right' : 'left';
  32972. }
  32973. }
  32974. axisPositionUsed[axisPosition] = true;
  32975. var axis = new Axis2D(axisType, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisPosition);
  32976. var isCategory = axis.type === 'category';
  32977. axis.onBand = isCategory && axisModel.get('boundaryGap');
  32978. axis.inverse = axisModel.get('inverse'); // Inject axis into axisModel
  32979. axisModel.axis = axis; // Inject axisModel into axis
  32980. axis.model = axisModel; // Inject grid info axis
  32981. axis.grid = this; // Index of axis, can be used as key
  32982. axis.index = idx;
  32983. this._axesList.push(axis);
  32984. axesMap[axisType][idx] = axis;
  32985. axesCount[axisType]++;
  32986. };
  32987. }
  32988. };
  32989. /**
  32990. * Update cartesian properties from series
  32991. * @param {module:echarts/model/Option} option
  32992. * @private
  32993. */
  32994. gridProto._updateScale = function (ecModel, gridModel) {
  32995. // Reset scale
  32996. each$1(this._axesList, function (axis) {
  32997. axis.scale.setExtent(Infinity, -Infinity);
  32998. });
  32999. ecModel.eachSeries(function (seriesModel) {
  33000. if (isCartesian2D(seriesModel)) {
  33001. var axesModels = findAxesModels(seriesModel, ecModel);
  33002. var xAxisModel = axesModels[0];
  33003. var yAxisModel = axesModels[1];
  33004. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel) || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)) {
  33005. return;
  33006. }
  33007. var cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  33008. var data = seriesModel.getData();
  33009. var xAxis = cartesian.getAxis('x');
  33010. var yAxis = cartesian.getAxis('y');
  33011. if (data.type === 'list') {
  33012. unionExtent(data, xAxis, seriesModel);
  33013. unionExtent(data, yAxis, seriesModel);
  33014. }
  33015. }
  33016. }, this);
  33017. function unionExtent(data, axis, seriesModel) {
  33018. each$1(data.mapDimension(axis.dim, true), function (dim) {
  33019. axis.scale.unionExtentFromData( // For example, the extent of the orginal dimension
  33020. // is [0.1, 0.5], the extent of the `stackResultDimension`
  33021. // is [7, 9], the final extent should not include [0.1, 0.5].
  33022. data, getStackedDimension(data, dim));
  33023. });
  33024. }
  33025. };
  33026. /**
  33027. * @param {string} [dim] 'x' or 'y' or 'auto' or null/undefined
  33028. * @return {Object} {baseAxes: [], otherAxes: []}
  33029. */
  33030. gridProto.getTooltipAxes = function (dim) {
  33031. var baseAxes = [];
  33032. var otherAxes = [];
  33033. each$1(this.getCartesians(), function (cartesian) {
  33034. var baseAxis = dim != null && dim !== 'auto' ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  33035. var otherAxis = cartesian.getOtherAxis(baseAxis);
  33036. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  33037. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  33038. });
  33039. return {
  33040. baseAxes: baseAxes,
  33041. otherAxes: otherAxes
  33042. };
  33043. };
  33044. /**
  33045. * @inner
  33046. */
  33047. function updateAxisTransform(axis, coordBase) {
  33048. var axisExtent = axis.getExtent();
  33049. var axisExtentSum = axisExtent[0] + axisExtent[1]; // Fast transform
  33050. axis.toGlobalCoord = axis.dim === 'x' ? function (coord) {
  33051. return coord + coordBase;
  33052. } : function (coord) {
  33053. return axisExtentSum - coord + coordBase;
  33054. };
  33055. axis.toLocalCoord = axis.dim === 'x' ? function (coord) {
  33056. return coord - coordBase;
  33057. } : function (coord) {
  33058. return axisExtentSum - coord + coordBase;
  33059. };
  33060. }
  33061. var axesTypes = ['xAxis', 'yAxis'];
  33062. /**
  33063. * @inner
  33064. */
  33065. function findAxesModels(seriesModel, ecModel) {
  33066. return map(axesTypes, function (axisType) {
  33067. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  33068. if (__DEV__) {
  33069. if (!axisModel) {
  33070. throw new Error(axisType + ' "' + retrieve(seriesModel.get(axisType + 'Index'), seriesModel.get(axisType + 'Id'), 0) + '" not found');
  33071. }
  33072. }
  33073. return axisModel;
  33074. });
  33075. }
  33076. /**
  33077. * @inner
  33078. */
  33079. function isCartesian2D(seriesModel) {
  33080. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  33081. }
  33082. Grid.create = function (ecModel, api) {
  33083. var grids = [];
  33084. ecModel.eachComponent('grid', function (gridModel, idx) {
  33085. var grid = new Grid(gridModel, ecModel, api);
  33086. grid.name = 'grid_' + idx; // dataSampling requires axis extent, so resize
  33087. // should be performed in create stage.
  33088. grid.resize(gridModel, api, true);
  33089. gridModel.coordinateSystem = grid;
  33090. grids.push(grid);
  33091. }); // Inject the coordinateSystems into seriesModel
  33092. ecModel.eachSeries(function (seriesModel) {
  33093. if (!isCartesian2D(seriesModel)) {
  33094. return;
  33095. }
  33096. var axesModels = findAxesModels(seriesModel, ecModel);
  33097. var xAxisModel = axesModels[0];
  33098. var yAxisModel = axesModels[1];
  33099. var gridModel = xAxisModel.getCoordSysModel();
  33100. if (__DEV__) {
  33101. if (!gridModel) {
  33102. throw new Error('Grid "' + retrieve(xAxisModel.get('gridIndex'), xAxisModel.get('gridId'), 0) + '" not found');
  33103. }
  33104. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  33105. throw new Error('xAxis and yAxis must use the same grid');
  33106. }
  33107. }
  33108. var grid = gridModel.coordinateSystem;
  33109. seriesModel.coordinateSystem = grid.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  33110. });
  33111. return grids;
  33112. }; // For deciding which dimensions to use when creating list data
  33113. Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
  33114. CoordinateSystemManager.register('cartesian2d', Grid);
  33115. /*
  33116. * Licensed to the Apache Software Foundation (ASF) under one
  33117. * or more contributor license agreements. See the NOTICE file
  33118. * distributed with this work for additional information
  33119. * regarding copyright ownership. The ASF licenses this file
  33120. * to you under the Apache License, Version 2.0 (the
  33121. * "License"); you may not use this file except in compliance
  33122. * with the License. You may obtain a copy of the License at
  33123. *
  33124. * http://www.apache.org/licenses/LICENSE-2.0
  33125. *
  33126. * Unless required by applicable law or agreed to in writing,
  33127. * software distributed under the License is distributed on an
  33128. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33129. * KIND, either express or implied. See the License for the
  33130. * specific language governing permissions and limitations
  33131. * under the License.
  33132. */
  33133. var PI$2 = Math.PI;
  33134. /**
  33135. * A final axis is translated and rotated from a "standard axis".
  33136. * So opt.position and opt.rotation is required.
  33137. *
  33138. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  33139. * for example: (0, 0) ------------> (0, 50)
  33140. *
  33141. * nameDirection or tickDirection or labelDirection is 1 means tick
  33142. * or label is below the standard axis, whereas is -1 means above
  33143. * the standard axis. labelOffset means offset between label and axis,
  33144. * which is useful when 'onZero', where axisLabel is in the grid and
  33145. * label in outside grid.
  33146. *
  33147. * Tips: like always,
  33148. * positive rotation represents anticlockwise, and negative rotation
  33149. * represents clockwise.
  33150. * The direction of position coordinate is the same as the direction
  33151. * of screen coordinate.
  33152. *
  33153. * Do not need to consider axis 'inverse', which is auto processed by
  33154. * axis extent.
  33155. *
  33156. * @param {module:zrender/container/Group} group
  33157. * @param {Object} axisModel
  33158. * @param {Object} opt Standard axis parameters.
  33159. * @param {Array.<number>} opt.position [x, y]
  33160. * @param {number} opt.rotation by radian
  33161. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle' or 'center'.
  33162. * @param {number} [opt.tickDirection=1] 1 or -1
  33163. * @param {number} [opt.labelDirection=1] 1 or -1
  33164. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  33165. * @param {string} [opt.axisLabelShow] default get from axisModel.
  33166. * @param {string} [opt.axisName] default get from axisModel.
  33167. * @param {number} [opt.axisNameAvailableWidth]
  33168. * @param {number} [opt.labelRotate] by degree, default get from axisModel.
  33169. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  33170. * @param {number} [opt.nameTruncateMaxWidth]
  33171. */
  33172. var AxisBuilder = function (axisModel, opt) {
  33173. /**
  33174. * @readOnly
  33175. */
  33176. this.opt = opt;
  33177. /**
  33178. * @readOnly
  33179. */
  33180. this.axisModel = axisModel; // Default value
  33181. defaults(opt, {
  33182. labelOffset: 0,
  33183. nameDirection: 1,
  33184. tickDirection: 1,
  33185. labelDirection: 1,
  33186. silent: true
  33187. });
  33188. /**
  33189. * @readOnly
  33190. */
  33191. this.group = new Group(); // FIXME Not use a seperate text group?
  33192. var dumbGroup = new Group({
  33193. position: opt.position.slice(),
  33194. rotation: opt.rotation
  33195. }); // this.group.add(dumbGroup);
  33196. // this._dumbGroup = dumbGroup;
  33197. dumbGroup.updateTransform();
  33198. this._transform = dumbGroup.transform;
  33199. this._dumbGroup = dumbGroup;
  33200. };
  33201. AxisBuilder.prototype = {
  33202. constructor: AxisBuilder,
  33203. hasBuilder: function (name) {
  33204. return !!builders[name];
  33205. },
  33206. add: function (name) {
  33207. builders[name].call(this);
  33208. },
  33209. getGroup: function () {
  33210. return this.group;
  33211. }
  33212. };
  33213. var builders = {
  33214. /**
  33215. * @private
  33216. */
  33217. axisLine: function () {
  33218. var opt = this.opt;
  33219. var axisModel = this.axisModel;
  33220. if (!axisModel.get('axisLine.show')) {
  33221. return;
  33222. }
  33223. var extent = this.axisModel.axis.getExtent();
  33224. var matrix = this._transform;
  33225. var pt1 = [extent[0], 0];
  33226. var pt2 = [extent[1], 0];
  33227. if (matrix) {
  33228. applyTransform(pt1, pt1, matrix);
  33229. applyTransform(pt2, pt2, matrix);
  33230. }
  33231. var lineStyle = extend({
  33232. lineCap: 'round'
  33233. }, axisModel.getModel('axisLine.lineStyle').getLineStyle());
  33234. this.group.add(new Line({
  33235. // Id for animation
  33236. anid: 'line',
  33237. subPixelOptimize: true,
  33238. shape: {
  33239. x1: pt1[0],
  33240. y1: pt1[1],
  33241. x2: pt2[0],
  33242. y2: pt2[1]
  33243. },
  33244. style: lineStyle,
  33245. strokeContainThreshold: opt.strokeContainThreshold || 5,
  33246. silent: true,
  33247. z2: 1
  33248. }));
  33249. var arrows = axisModel.get('axisLine.symbol');
  33250. var arrowSize = axisModel.get('axisLine.symbolSize');
  33251. var arrowOffset = axisModel.get('axisLine.symbolOffset') || 0;
  33252. if (typeof arrowOffset === 'number') {
  33253. arrowOffset = [arrowOffset, arrowOffset];
  33254. }
  33255. if (arrows != null) {
  33256. if (typeof arrows === 'string') {
  33257. // Use the same arrow for start and end point
  33258. arrows = [arrows, arrows];
  33259. }
  33260. if (typeof arrowSize === 'string' || typeof arrowSize === 'number') {
  33261. // Use the same size for width and height
  33262. arrowSize = [arrowSize, arrowSize];
  33263. }
  33264. var symbolWidth = arrowSize[0];
  33265. var symbolHeight = arrowSize[1];
  33266. each$1([{
  33267. rotate: opt.rotation + Math.PI / 2,
  33268. offset: arrowOffset[0],
  33269. r: 0
  33270. }, {
  33271. rotate: opt.rotation - Math.PI / 2,
  33272. offset: arrowOffset[1],
  33273. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0]) + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  33274. }], function (point, index) {
  33275. if (arrows[index] !== 'none' && arrows[index] != null) {
  33276. var symbol = createSymbol(arrows[index], -symbolWidth / 2, -symbolHeight / 2, symbolWidth, symbolHeight, lineStyle.stroke, true); // Calculate arrow position with offset
  33277. var r = point.r + point.offset;
  33278. var pos = [pt1[0] + r * Math.cos(opt.rotation), pt1[1] - r * Math.sin(opt.rotation)];
  33279. symbol.attr({
  33280. rotation: point.rotate,
  33281. position: pos,
  33282. silent: true,
  33283. z2: 11
  33284. });
  33285. this.group.add(symbol);
  33286. }
  33287. }, this);
  33288. }
  33289. },
  33290. /**
  33291. * @private
  33292. */
  33293. axisTickLabel: function () {
  33294. var axisModel = this.axisModel;
  33295. var opt = this.opt;
  33296. var ticksEls = buildAxisMajorTicks(this, axisModel, opt);
  33297. var labelEls = buildAxisLabel(this, axisModel, opt);
  33298. fixMinMaxLabelShow(axisModel, labelEls, ticksEls);
  33299. buildAxisMinorTicks(this, axisModel, opt);
  33300. },
  33301. /**
  33302. * @private
  33303. */
  33304. axisName: function () {
  33305. var opt = this.opt;
  33306. var axisModel = this.axisModel;
  33307. var name = retrieve(opt.axisName, axisModel.get('name'));
  33308. if (!name) {
  33309. return;
  33310. }
  33311. var nameLocation = axisModel.get('nameLocation');
  33312. var nameDirection = opt.nameDirection;
  33313. var textStyleModel = axisModel.getModel('nameTextStyle');
  33314. var gap = axisModel.get('nameGap') || 0;
  33315. var extent = this.axisModel.axis.getExtent();
  33316. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  33317. var pos = [nameLocation === 'start' ? extent[0] - gapSignal * gap : nameLocation === 'end' ? extent[1] + gapSignal * gap : (extent[0] + extent[1]) / 2, // 'middle'
  33318. // Reuse labelOffset.
  33319. isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0];
  33320. var labelLayout;
  33321. var nameRotation = axisModel.get('nameRotate');
  33322. if (nameRotation != null) {
  33323. nameRotation = nameRotation * PI$2 / 180; // To radian.
  33324. }
  33325. var axisNameAvailableWidth;
  33326. if (isNameLocationCenter(nameLocation)) {
  33327. labelLayout = innerTextLayout(opt.rotation, nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  33328. nameDirection);
  33329. } else {
  33330. labelLayout = endTextLayout(opt, nameLocation, nameRotation || 0, extent);
  33331. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  33332. if (axisNameAvailableWidth != null) {
  33333. axisNameAvailableWidth = Math.abs(axisNameAvailableWidth / Math.sin(labelLayout.rotation));
  33334. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  33335. }
  33336. }
  33337. var textFont = textStyleModel.getFont();
  33338. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  33339. var ellipsis = truncateOpt.ellipsis;
  33340. var maxWidth = retrieve(opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth); // FIXME
  33341. // truncate rich text? (consider performance)
  33342. var truncatedText = ellipsis != null && maxWidth != null ? truncateText$1(name, maxWidth, textFont, ellipsis, {
  33343. minChar: 2,
  33344. placeholder: truncateOpt.placeholder
  33345. }) : name;
  33346. var tooltipOpt = axisModel.get('tooltip', true);
  33347. var mainType = axisModel.mainType;
  33348. var formatterParams = {
  33349. componentType: mainType,
  33350. name: name,
  33351. $vars: ['name']
  33352. };
  33353. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  33354. var textEl = new Text({
  33355. // Id for animation
  33356. anid: 'name',
  33357. __fullText: name,
  33358. __truncatedText: truncatedText,
  33359. position: pos,
  33360. rotation: labelLayout.rotation,
  33361. silent: isLabelSilent(axisModel),
  33362. z2: 1,
  33363. tooltip: tooltipOpt && tooltipOpt.show ? extend({
  33364. content: name,
  33365. formatter: function () {
  33366. return name;
  33367. },
  33368. formatterParams: formatterParams
  33369. }, tooltipOpt) : null
  33370. });
  33371. setTextStyle(textEl.style, textStyleModel, {
  33372. text: truncatedText,
  33373. textFont: textFont,
  33374. textFill: textStyleModel.getTextColor() || axisModel.get('axisLine.lineStyle.color'),
  33375. textAlign: textStyleModel.get('align') || labelLayout.textAlign,
  33376. textVerticalAlign: textStyleModel.get('verticalAlign') || labelLayout.textVerticalAlign
  33377. });
  33378. if (axisModel.get('triggerEvent')) {
  33379. textEl.eventData = makeAxisEventDataBase(axisModel);
  33380. textEl.eventData.targetType = 'axisName';
  33381. textEl.eventData.name = name;
  33382. } // FIXME
  33383. this._dumbGroup.add(textEl);
  33384. textEl.updateTransform();
  33385. this.group.add(textEl);
  33386. textEl.decomposeTransform();
  33387. }
  33388. };
  33389. var makeAxisEventDataBase = AxisBuilder.makeAxisEventDataBase = function (axisModel) {
  33390. var eventData = {
  33391. componentType: axisModel.mainType,
  33392. componentIndex: axisModel.componentIndex
  33393. };
  33394. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  33395. return eventData;
  33396. };
  33397. /**
  33398. * @public
  33399. * @static
  33400. * @param {Object} opt
  33401. * @param {number} axisRotation in radian
  33402. * @param {number} textRotation in radian
  33403. * @param {number} direction
  33404. * @return {Object} {
  33405. * rotation, // according to axis
  33406. * textAlign,
  33407. * textVerticalAlign
  33408. * }
  33409. */
  33410. var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  33411. var rotationDiff = remRadian(textRotation - axisRotation);
  33412. var textAlign;
  33413. var textVerticalAlign;
  33414. if (isRadianAroundZero(rotationDiff)) {
  33415. // Label is parallel with axis line.
  33416. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  33417. textAlign = 'center';
  33418. } else if (isRadianAroundZero(rotationDiff - PI$2)) {
  33419. // Label is inverse parallel with axis line.
  33420. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  33421. textAlign = 'center';
  33422. } else {
  33423. textVerticalAlign = 'middle';
  33424. if (rotationDiff > 0 && rotationDiff < PI$2) {
  33425. textAlign = direction > 0 ? 'right' : 'left';
  33426. } else {
  33427. textAlign = direction > 0 ? 'left' : 'right';
  33428. }
  33429. }
  33430. return {
  33431. rotation: rotationDiff,
  33432. textAlign: textAlign,
  33433. textVerticalAlign: textVerticalAlign
  33434. };
  33435. };
  33436. function endTextLayout(opt, textPosition, textRotate, extent) {
  33437. var rotationDiff = remRadian(textRotate - opt.rotation);
  33438. var textAlign;
  33439. var textVerticalAlign;
  33440. var inverse = extent[0] > extent[1];
  33441. var onLeft = textPosition === 'start' && !inverse || textPosition !== 'start' && inverse;
  33442. if (isRadianAroundZero(rotationDiff - PI$2 / 2)) {
  33443. textVerticalAlign = onLeft ? 'bottom' : 'top';
  33444. textAlign = 'center';
  33445. } else if (isRadianAroundZero(rotationDiff - PI$2 * 1.5)) {
  33446. textVerticalAlign = onLeft ? 'top' : 'bottom';
  33447. textAlign = 'center';
  33448. } else {
  33449. textVerticalAlign = 'middle';
  33450. if (rotationDiff < PI$2 * 1.5 && rotationDiff > PI$2 / 2) {
  33451. textAlign = onLeft ? 'left' : 'right';
  33452. } else {
  33453. textAlign = onLeft ? 'right' : 'left';
  33454. }
  33455. }
  33456. return {
  33457. rotation: rotationDiff,
  33458. textAlign: textAlign,
  33459. textVerticalAlign: textVerticalAlign
  33460. };
  33461. }
  33462. var isLabelSilent = AxisBuilder.isLabelSilent = function (axisModel) {
  33463. var tooltipOpt = axisModel.get('tooltip');
  33464. return axisModel.get('silent') // Consider mouse cursor, add these restrictions.
  33465. || !(axisModel.get('triggerEvent') || tooltipOpt && tooltipOpt.show);
  33466. };
  33467. function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
  33468. if (shouldShowAllLabels(axisModel.axis)) {
  33469. return;
  33470. } // If min or max are user set, we need to check
  33471. // If the tick on min(max) are overlap on their neighbour tick
  33472. // If they are overlapped, we need to hide the min(max) tick label
  33473. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  33474. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel'); // FIXME
  33475. // Have not consider onBand yet, where tick els is more than label els.
  33476. labelEls = labelEls || [];
  33477. tickEls = tickEls || [];
  33478. var firstLabel = labelEls[0];
  33479. var nextLabel = labelEls[1];
  33480. var lastLabel = labelEls[labelEls.length - 1];
  33481. var prevLabel = labelEls[labelEls.length - 2];
  33482. var firstTick = tickEls[0];
  33483. var nextTick = tickEls[1];
  33484. var lastTick = tickEls[tickEls.length - 1];
  33485. var prevTick = tickEls[tickEls.length - 2];
  33486. if (showMinLabel === false) {
  33487. ignoreEl(firstLabel);
  33488. ignoreEl(firstTick);
  33489. } else if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  33490. if (showMinLabel) {
  33491. ignoreEl(nextLabel);
  33492. ignoreEl(nextTick);
  33493. } else {
  33494. ignoreEl(firstLabel);
  33495. ignoreEl(firstTick);
  33496. }
  33497. }
  33498. if (showMaxLabel === false) {
  33499. ignoreEl(lastLabel);
  33500. ignoreEl(lastTick);
  33501. } else if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  33502. if (showMaxLabel) {
  33503. ignoreEl(prevLabel);
  33504. ignoreEl(prevTick);
  33505. } else {
  33506. ignoreEl(lastLabel);
  33507. ignoreEl(lastTick);
  33508. }
  33509. }
  33510. }
  33511. function ignoreEl(el) {
  33512. el && (el.ignore = true);
  33513. }
  33514. function isTwoLabelOverlapped(current, next, labelLayout) {
  33515. // current and next has the same rotation.
  33516. var firstRect = current && current.getBoundingRect().clone();
  33517. var nextRect = next && next.getBoundingRect().clone();
  33518. if (!firstRect || !nextRect) {
  33519. return;
  33520. } // When checking intersect of two rotated labels, we use mRotationBack
  33521. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  33522. var mRotationBack = identity([]);
  33523. rotate(mRotationBack, mRotationBack, -current.rotation);
  33524. firstRect.applyTransform(mul$1([], mRotationBack, current.getLocalTransform()));
  33525. nextRect.applyTransform(mul$1([], mRotationBack, next.getLocalTransform()));
  33526. return firstRect.intersect(nextRect);
  33527. }
  33528. function isNameLocationCenter(nameLocation) {
  33529. return nameLocation === 'middle' || nameLocation === 'center';
  33530. }
  33531. function createTicks(ticksCoords, tickTransform, tickEndCoord, tickLineStyle, aniid) {
  33532. var tickEls = [];
  33533. var pt1 = [];
  33534. var pt2 = [];
  33535. for (var i = 0; i < ticksCoords.length; i++) {
  33536. var tickCoord = ticksCoords[i].coord;
  33537. pt1[0] = tickCoord;
  33538. pt1[1] = 0;
  33539. pt2[0] = tickCoord;
  33540. pt2[1] = tickEndCoord;
  33541. if (tickTransform) {
  33542. applyTransform(pt1, pt1, tickTransform);
  33543. applyTransform(pt2, pt2, tickTransform);
  33544. } // Tick line, Not use group transform to have better line draw
  33545. var tickEl = new Line({
  33546. // Id for animation
  33547. anid: aniid + '_' + ticksCoords[i].tickValue,
  33548. subPixelOptimize: true,
  33549. shape: {
  33550. x1: pt1[0],
  33551. y1: pt1[1],
  33552. x2: pt2[0],
  33553. y2: pt2[1]
  33554. },
  33555. style: tickLineStyle,
  33556. z2: 2,
  33557. silent: true
  33558. });
  33559. tickEls.push(tickEl);
  33560. }
  33561. return tickEls;
  33562. }
  33563. function buildAxisMajorTicks(axisBuilder, axisModel, opt) {
  33564. var axis = axisModel.axis;
  33565. var tickModel = axisModel.getModel('axisTick');
  33566. if (!tickModel.get('show') || axis.scale.isBlank()) {
  33567. return;
  33568. }
  33569. var lineStyleModel = tickModel.getModel('lineStyle');
  33570. var tickEndCoord = opt.tickDirection * tickModel.get('length');
  33571. var ticksCoords = axis.getTicksCoords();
  33572. var ticksEls = createTicks(ticksCoords, axisBuilder._transform, tickEndCoord, defaults(lineStyleModel.getLineStyle(), {
  33573. stroke: axisModel.get('axisLine.lineStyle.color')
  33574. }), 'ticks');
  33575. for (var i = 0; i < ticksEls.length; i++) {
  33576. axisBuilder.group.add(ticksEls[i]);
  33577. }
  33578. return ticksEls;
  33579. }
  33580. function buildAxisMinorTicks(axisBuilder, axisModel, opt) {
  33581. var axis = axisModel.axis;
  33582. var minorTickModel = axisModel.getModel('minorTick');
  33583. if (!minorTickModel.get('show') || axis.scale.isBlank()) {
  33584. return;
  33585. }
  33586. var minorTicksCoords = axis.getMinorTicksCoords();
  33587. if (!minorTicksCoords.length) {
  33588. return;
  33589. }
  33590. var lineStyleModel = minorTickModel.getModel('lineStyle');
  33591. var tickEndCoord = opt.tickDirection * minorTickModel.get('length');
  33592. var minorTickLineStyle = defaults(lineStyleModel.getLineStyle(), defaults(axisModel.getModel('axisTick').getLineStyle(), {
  33593. stroke: axisModel.get('axisLine.lineStyle.color')
  33594. }));
  33595. for (var i = 0; i < minorTicksCoords.length; i++) {
  33596. var minorTicksEls = createTicks(minorTicksCoords[i], axisBuilder._transform, tickEndCoord, minorTickLineStyle, 'minorticks_' + i);
  33597. for (var k = 0; k < minorTicksEls.length; k++) {
  33598. axisBuilder.group.add(minorTicksEls[k]);
  33599. }
  33600. }
  33601. }
  33602. function buildAxisLabel(axisBuilder, axisModel, opt) {
  33603. var axis = axisModel.axis;
  33604. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  33605. if (!show || axis.scale.isBlank()) {
  33606. return;
  33607. }
  33608. var labelModel = axisModel.getModel('axisLabel');
  33609. var labelMargin = labelModel.get('margin');
  33610. var labels = axis.getViewLabels(); // Special label rotate.
  33611. var labelRotation = (retrieve(opt.labelRotate, labelModel.get('rotate')) || 0) * PI$2 / 180;
  33612. var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  33613. var rawCategoryData = axisModel.getCategories && axisModel.getCategories(true);
  33614. var labelEls = [];
  33615. var silent = isLabelSilent(axisModel);
  33616. var triggerEvent = axisModel.get('triggerEvent');
  33617. each$1(labels, function (labelItem, index) {
  33618. var tickValue = labelItem.tickValue;
  33619. var formattedLabel = labelItem.formattedLabel;
  33620. var rawLabel = labelItem.rawLabel;
  33621. var itemLabelModel = labelModel;
  33622. if (rawCategoryData && rawCategoryData[tickValue] && rawCategoryData[tickValue].textStyle) {
  33623. itemLabelModel = new Model(rawCategoryData[tickValue].textStyle, labelModel, axisModel.ecModel);
  33624. }
  33625. var textColor = itemLabelModel.getTextColor() || axisModel.get('axisLine.lineStyle.color');
  33626. var tickCoord = axis.dataToCoord(tickValue);
  33627. var pos = [tickCoord, opt.labelOffset + opt.labelDirection * labelMargin];
  33628. var textEl = new Text({
  33629. // Id for animation
  33630. anid: 'label_' + tickValue,
  33631. position: pos,
  33632. rotation: labelLayout.rotation,
  33633. silent: silent,
  33634. z2: 10
  33635. });
  33636. setTextStyle(textEl.style, itemLabelModel, {
  33637. text: formattedLabel,
  33638. textAlign: itemLabelModel.getShallow('align', true) || labelLayout.textAlign,
  33639. textVerticalAlign: itemLabelModel.getShallow('verticalAlign', true) || itemLabelModel.getShallow('baseline', true) || labelLayout.textVerticalAlign,
  33640. textFill: typeof textColor === 'function' ? textColor( // (1) In category axis with data zoom, tick is not the original
  33641. // index of axis.data. So tick should not be exposed to user
  33642. // in category axis.
  33643. // (2) Compatible with previous version, which always use formatted label as
  33644. // input. But in interval scale the formatted label is like '223,445', which
  33645. // maked user repalce ','. So we modify it to return original val but remain
  33646. // it as 'string' to avoid error in replacing.
  33647. axis.type === 'category' ? rawLabel : axis.type === 'value' ? tickValue + '' : tickValue, index) : textColor
  33648. }); // Pack data for mouse event
  33649. if (triggerEvent) {
  33650. textEl.eventData = makeAxisEventDataBase(axisModel);
  33651. textEl.eventData.targetType = 'axisLabel';
  33652. textEl.eventData.value = rawLabel;
  33653. } // FIXME
  33654. axisBuilder._dumbGroup.add(textEl);
  33655. textEl.updateTransform();
  33656. labelEls.push(textEl);
  33657. axisBuilder.group.add(textEl);
  33658. textEl.decomposeTransform();
  33659. });
  33660. return labelEls;
  33661. }
  33662. /*
  33663. * Licensed to the Apache Software Foundation (ASF) under one
  33664. * or more contributor license agreements. See the NOTICE file
  33665. * distributed with this work for additional information
  33666. * regarding copyright ownership. The ASF licenses this file
  33667. * to you under the Apache License, Version 2.0 (the
  33668. * "License"); you may not use this file except in compliance
  33669. * with the License. You may obtain a copy of the License at
  33670. *
  33671. * http://www.apache.org/licenses/LICENSE-2.0
  33672. *
  33673. * Unless required by applicable law or agreed to in writing,
  33674. * software distributed under the License is distributed on an
  33675. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33676. * KIND, either express or implied. See the License for the
  33677. * specific language governing permissions and limitations
  33678. * under the License.
  33679. */
  33680. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  33681. // allAxesInfo should be updated when setOption performed.
  33682. function fixValue(axisModel) {
  33683. var axisInfo = getAxisInfo(axisModel);
  33684. if (!axisInfo) {
  33685. return;
  33686. }
  33687. var axisPointerModel = axisInfo.axisPointerModel;
  33688. var scale = axisInfo.axis.scale;
  33689. var option = axisPointerModel.option;
  33690. var status = axisPointerModel.get('status');
  33691. var value = axisPointerModel.get('value'); // Parse init value for category and time axis.
  33692. if (value != null) {
  33693. value = scale.parse(value);
  33694. }
  33695. var useHandle = isHandleTrigger(axisPointerModel); // If `handle` used, `axisPointer` will always be displayed, so value
  33696. // and status should be initialized.
  33697. if (status == null) {
  33698. option.status = useHandle ? 'show' : 'hide';
  33699. }
  33700. var extent = scale.getExtent().slice();
  33701. extent[0] > extent[1] && extent.reverse();
  33702. if ( // Pick a value on axis when initializing.
  33703. value == null // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  33704. // where we should re-pick a value to keep `handle` displaying normally.
  33705. || value > extent[1]) {
  33706. // Make handle displayed on the end of the axis when init, which looks better.
  33707. value = extent[1];
  33708. }
  33709. if (value < extent[0]) {
  33710. value = extent[0];
  33711. }
  33712. option.value = value;
  33713. if (useHandle) {
  33714. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  33715. }
  33716. }
  33717. function getAxisInfo(axisModel) {
  33718. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  33719. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  33720. }
  33721. function getAxisPointerModel(axisModel) {
  33722. var axisInfo = getAxisInfo(axisModel);
  33723. return axisInfo && axisInfo.axisPointerModel;
  33724. }
  33725. function isHandleTrigger(axisPointerModel) {
  33726. return !!axisPointerModel.get('handle.show');
  33727. }
  33728. /**
  33729. * @param {module:echarts/model/Model} model
  33730. * @return {string} unique key
  33731. */
  33732. function makeKey(model) {
  33733. return model.type + '||' + model.id;
  33734. }
  33735. /*
  33736. * Licensed to the Apache Software Foundation (ASF) under one
  33737. * or more contributor license agreements. See the NOTICE file
  33738. * distributed with this work for additional information
  33739. * regarding copyright ownership. The ASF licenses this file
  33740. * to you under the Apache License, Version 2.0 (the
  33741. * "License"); you may not use this file except in compliance
  33742. * with the License. You may obtain a copy of the License at
  33743. *
  33744. * http://www.apache.org/licenses/LICENSE-2.0
  33745. *
  33746. * Unless required by applicable law or agreed to in writing,
  33747. * software distributed under the License is distributed on an
  33748. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33749. * KIND, either express or implied. See the License for the
  33750. * specific language governing permissions and limitations
  33751. * under the License.
  33752. */
  33753. /**
  33754. * Base class of AxisView.
  33755. */
  33756. var AxisView = extendComponentView({
  33757. type: 'axis',
  33758. /**
  33759. * @private
  33760. */
  33761. _axisPointer: null,
  33762. /**
  33763. * @protected
  33764. * @type {string}
  33765. */
  33766. axisPointerClass: null,
  33767. /**
  33768. * @override
  33769. */
  33770. render: function (axisModel, ecModel, api, payload) {
  33771. // FIXME
  33772. // This process should proformed after coordinate systems updated
  33773. // (axis scale updated), and should be performed each time update.
  33774. // So put it here temporarily, although it is not appropriate to
  33775. // put a model-writing procedure in `view`.
  33776. this.axisPointerClass && fixValue(axisModel);
  33777. AxisView.superApply(this, 'render', arguments);
  33778. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  33779. },
  33780. /**
  33781. * Action handler.
  33782. * @public
  33783. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  33784. * @param {module:echarts/model/Global} ecModel
  33785. * @param {module:echarts/ExtensionAPI} api
  33786. * @param {Object} payload
  33787. */
  33788. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  33789. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  33790. },
  33791. /**
  33792. * @override
  33793. */
  33794. remove: function (ecModel, api) {
  33795. var axisPointer = this._axisPointer;
  33796. axisPointer && axisPointer.remove(api);
  33797. AxisView.superApply(this, 'remove', arguments);
  33798. },
  33799. /**
  33800. * @override
  33801. */
  33802. dispose: function (ecModel, api) {
  33803. disposeAxisPointer(this, api);
  33804. AxisView.superApply(this, 'dispose', arguments);
  33805. }
  33806. });
  33807. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  33808. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  33809. if (!Clazz) {
  33810. return;
  33811. }
  33812. var axisPointerModel = getAxisPointerModel(axisModel);
  33813. axisPointerModel ? (axisView._axisPointer || (axisView._axisPointer = new Clazz())).render(axisModel, axisPointerModel, api, forceRender) : disposeAxisPointer(axisView, api);
  33814. }
  33815. function disposeAxisPointer(axisView, ecModel, api) {
  33816. var axisPointer = axisView._axisPointer;
  33817. axisPointer && axisPointer.dispose(ecModel, api);
  33818. axisView._axisPointer = null;
  33819. }
  33820. var axisPointerClazz = [];
  33821. AxisView.registerAxisPointerClass = function (type, clazz) {
  33822. if (__DEV__) {
  33823. if (axisPointerClazz[type]) {
  33824. throw new Error('axisPointer ' + type + ' exists');
  33825. }
  33826. }
  33827. axisPointerClazz[type] = clazz;
  33828. };
  33829. AxisView.getAxisPointerClass = function (type) {
  33830. return type && axisPointerClazz[type];
  33831. };
  33832. /*
  33833. * Licensed to the Apache Software Foundation (ASF) under one
  33834. * or more contributor license agreements. See the NOTICE file
  33835. * distributed with this work for additional information
  33836. * regarding copyright ownership. The ASF licenses this file
  33837. * to you under the Apache License, Version 2.0 (the
  33838. * "License"); you may not use this file except in compliance
  33839. * with the License. You may obtain a copy of the License at
  33840. *
  33841. * http://www.apache.org/licenses/LICENSE-2.0
  33842. *
  33843. * Unless required by applicable law or agreed to in writing,
  33844. * software distributed under the License is distributed on an
  33845. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33846. * KIND, either express or implied. See the License for the
  33847. * specific language governing permissions and limitations
  33848. * under the License.
  33849. */
  33850. /**
  33851. * Can only be called after coordinate system creation stage.
  33852. * (Can be called before coordinate system update stage).
  33853. *
  33854. * @param {Object} opt {labelInside}
  33855. * @return {Object} {
  33856. * position, rotation, labelDirection, labelOffset,
  33857. * tickDirection, labelRotate, z2
  33858. * }
  33859. */
  33860. function layout$1(gridModel, axisModel, opt) {
  33861. opt = opt || {};
  33862. var grid = gridModel.coordinateSystem;
  33863. var axis = axisModel.axis;
  33864. var layout = {};
  33865. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  33866. var rawAxisPosition = axis.position;
  33867. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  33868. var axisDim = axis.dim;
  33869. var rect = grid.getRect();
  33870. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  33871. var idx = {
  33872. left: 0,
  33873. right: 1,
  33874. top: 0,
  33875. bottom: 1,
  33876. onZero: 2
  33877. };
  33878. var axisOffset = axisModel.get('offset') || 0;
  33879. var posBound = axisDim === 'x' ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset] : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  33880. if (otherAxisOnZeroOf) {
  33881. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  33882. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  33883. } // Axis position
  33884. layout.position = [axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0], axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]]; // Axis rotation
  33885. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1); // Tick and label direction, x y is axisDim
  33886. var dirMap = {
  33887. top: -1,
  33888. bottom: 1,
  33889. left: -1,
  33890. right: 1
  33891. };
  33892. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  33893. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  33894. if (axisModel.get('axisTick.inside')) {
  33895. layout.tickDirection = -layout.tickDirection;
  33896. }
  33897. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  33898. layout.labelDirection = -layout.labelDirection;
  33899. } // Special label rotation
  33900. var labelRotate = axisModel.get('axisLabel.rotate');
  33901. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate; // Over splitLine and splitArea
  33902. layout.z2 = 1;
  33903. return layout;
  33904. }
  33905. /*
  33906. * Licensed to the Apache Software Foundation (ASF) under one
  33907. * or more contributor license agreements. See the NOTICE file
  33908. * distributed with this work for additional information
  33909. * regarding copyright ownership. The ASF licenses this file
  33910. * to you under the Apache License, Version 2.0 (the
  33911. * "License"); you may not use this file except in compliance
  33912. * with the License. You may obtain a copy of the License at
  33913. *
  33914. * http://www.apache.org/licenses/LICENSE-2.0
  33915. *
  33916. * Unless required by applicable law or agreed to in writing,
  33917. * software distributed under the License is distributed on an
  33918. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33919. * KIND, either express or implied. See the License for the
  33920. * specific language governing permissions and limitations
  33921. * under the License.
  33922. */
  33923. function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
  33924. var axis = axisModel.axis;
  33925. if (axis.scale.isBlank()) {
  33926. return;
  33927. }
  33928. var splitAreaModel = axisModel.getModel('splitArea');
  33929. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  33930. var areaColors = areaStyleModel.get('color');
  33931. var gridRect = gridModel.coordinateSystem.getRect();
  33932. var ticksCoords = axis.getTicksCoords({
  33933. tickModel: splitAreaModel,
  33934. clamp: true
  33935. });
  33936. if (!ticksCoords.length) {
  33937. return;
  33938. } // For Making appropriate splitArea animation, the color and anid
  33939. // should be corresponding to previous one if possible.
  33940. var areaColorsLen = areaColors.length;
  33941. var lastSplitAreaColors = axisView.__splitAreaColors;
  33942. var newSplitAreaColors = createHashMap();
  33943. var colorIndex = 0;
  33944. if (lastSplitAreaColors) {
  33945. for (var i = 0; i < ticksCoords.length; i++) {
  33946. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  33947. if (cIndex != null) {
  33948. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  33949. break;
  33950. }
  33951. }
  33952. }
  33953. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  33954. var areaStyle = areaStyleModel.getAreaStyle();
  33955. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  33956. for (var i = 1; i < ticksCoords.length; i++) {
  33957. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  33958. var x;
  33959. var y;
  33960. var width;
  33961. var height;
  33962. if (axis.isHorizontal()) {
  33963. x = prev;
  33964. y = gridRect.y;
  33965. width = tickCoord - x;
  33966. height = gridRect.height;
  33967. prev = x + width;
  33968. } else {
  33969. x = gridRect.x;
  33970. y = prev;
  33971. width = gridRect.width;
  33972. height = tickCoord - y;
  33973. prev = y + height;
  33974. }
  33975. var tickValue = ticksCoords[i - 1].tickValue;
  33976. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  33977. axisGroup.add(new Rect({
  33978. anid: tickValue != null ? 'area_' + tickValue : null,
  33979. shape: {
  33980. x: x,
  33981. y: y,
  33982. width: width,
  33983. height: height
  33984. },
  33985. style: defaults({
  33986. fill: areaColors[colorIndex]
  33987. }, areaStyle),
  33988. silent: true
  33989. }));
  33990. colorIndex = (colorIndex + 1) % areaColorsLen;
  33991. }
  33992. axisView.__splitAreaColors = newSplitAreaColors;
  33993. }
  33994. function rectCoordAxisHandleRemove(axisView) {
  33995. axisView.__splitAreaColors = null;
  33996. }
  33997. /*
  33998. * Licensed to the Apache Software Foundation (ASF) under one
  33999. * or more contributor license agreements. See the NOTICE file
  34000. * distributed with this work for additional information
  34001. * regarding copyright ownership. The ASF licenses this file
  34002. * to you under the Apache License, Version 2.0 (the
  34003. * "License"); you may not use this file except in compliance
  34004. * with the License. You may obtain a copy of the License at
  34005. *
  34006. * http://www.apache.org/licenses/LICENSE-2.0
  34007. *
  34008. * Unless required by applicable law or agreed to in writing,
  34009. * software distributed under the License is distributed on an
  34010. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34011. * KIND, either express or implied. See the License for the
  34012. * specific language governing permissions and limitations
  34013. * under the License.
  34014. */
  34015. var axisBuilderAttrs = ['axisLine', 'axisTickLabel', 'axisName'];
  34016. var selfBuilderAttrs = ['splitArea', 'splitLine', 'minorSplitLine'];
  34017. var CartesianAxisView = AxisView.extend({
  34018. type: 'cartesianAxis',
  34019. axisPointerClass: 'CartesianAxisPointer',
  34020. /**
  34021. * @override
  34022. */
  34023. render: function (axisModel, ecModel, api, payload) {
  34024. this.group.removeAll();
  34025. var oldAxisGroup = this._axisGroup;
  34026. this._axisGroup = new Group();
  34027. this.group.add(this._axisGroup);
  34028. if (!axisModel.get('show')) {
  34029. return;
  34030. }
  34031. var gridModel = axisModel.getCoordSysModel();
  34032. var layout = layout$1(gridModel, axisModel);
  34033. var axisBuilder = new AxisBuilder(axisModel, layout);
  34034. each$1(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  34035. this._axisGroup.add(axisBuilder.getGroup());
  34036. each$1(selfBuilderAttrs, function (name) {
  34037. if (axisModel.get(name + '.show')) {
  34038. this['_' + name](axisModel, gridModel);
  34039. }
  34040. }, this);
  34041. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  34042. CartesianAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  34043. },
  34044. remove: function () {
  34045. rectCoordAxisHandleRemove(this);
  34046. },
  34047. /**
  34048. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  34049. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  34050. * @private
  34051. */
  34052. _splitLine: function (axisModel, gridModel) {
  34053. var axis = axisModel.axis;
  34054. if (axis.scale.isBlank()) {
  34055. return;
  34056. }
  34057. var splitLineModel = axisModel.getModel('splitLine');
  34058. var lineStyleModel = splitLineModel.getModel('lineStyle');
  34059. var lineColors = lineStyleModel.get('color');
  34060. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  34061. var gridRect = gridModel.coordinateSystem.getRect();
  34062. var isHorizontal = axis.isHorizontal();
  34063. var lineCount = 0;
  34064. var ticksCoords = axis.getTicksCoords({
  34065. tickModel: splitLineModel
  34066. });
  34067. var p1 = [];
  34068. var p2 = [];
  34069. var lineStyle = lineStyleModel.getLineStyle();
  34070. for (var i = 0; i < ticksCoords.length; i++) {
  34071. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  34072. if (isHorizontal) {
  34073. p1[0] = tickCoord;
  34074. p1[1] = gridRect.y;
  34075. p2[0] = tickCoord;
  34076. p2[1] = gridRect.y + gridRect.height;
  34077. } else {
  34078. p1[0] = gridRect.x;
  34079. p1[1] = tickCoord;
  34080. p2[0] = gridRect.x + gridRect.width;
  34081. p2[1] = tickCoord;
  34082. }
  34083. var colorIndex = lineCount++ % lineColors.length;
  34084. var tickValue = ticksCoords[i].tickValue;
  34085. this._axisGroup.add(new Line({
  34086. anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
  34087. subPixelOptimize: true,
  34088. shape: {
  34089. x1: p1[0],
  34090. y1: p1[1],
  34091. x2: p2[0],
  34092. y2: p2[1]
  34093. },
  34094. style: defaults({
  34095. stroke: lineColors[colorIndex]
  34096. }, lineStyle),
  34097. silent: true
  34098. }));
  34099. }
  34100. },
  34101. /**
  34102. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  34103. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  34104. * @private
  34105. */
  34106. _minorSplitLine: function (axisModel, gridModel) {
  34107. var axis = axisModel.axis;
  34108. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  34109. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  34110. var gridRect = gridModel.coordinateSystem.getRect();
  34111. var isHorizontal = axis.isHorizontal();
  34112. var minorTicksCoords = axis.getMinorTicksCoords();
  34113. if (!minorTicksCoords.length) {
  34114. return;
  34115. }
  34116. var p1 = [];
  34117. var p2 = [];
  34118. var lineStyle = lineStyleModel.getLineStyle();
  34119. for (var i = 0; i < minorTicksCoords.length; i++) {
  34120. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  34121. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  34122. if (isHorizontal) {
  34123. p1[0] = tickCoord;
  34124. p1[1] = gridRect.y;
  34125. p2[0] = tickCoord;
  34126. p2[1] = gridRect.y + gridRect.height;
  34127. } else {
  34128. p1[0] = gridRect.x;
  34129. p1[1] = tickCoord;
  34130. p2[0] = gridRect.x + gridRect.width;
  34131. p2[1] = tickCoord;
  34132. }
  34133. this._axisGroup.add(new Line({
  34134. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  34135. subPixelOptimize: true,
  34136. shape: {
  34137. x1: p1[0],
  34138. y1: p1[1],
  34139. x2: p2[0],
  34140. y2: p2[1]
  34141. },
  34142. style: lineStyle,
  34143. silent: true
  34144. }));
  34145. }
  34146. }
  34147. },
  34148. /**
  34149. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  34150. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  34151. * @private
  34152. */
  34153. _splitArea: function (axisModel, gridModel) {
  34154. rectCoordAxisBuildSplitArea(this, this._axisGroup, axisModel, gridModel);
  34155. }
  34156. });
  34157. CartesianAxisView.extend({
  34158. type: 'xAxis'
  34159. });
  34160. CartesianAxisView.extend({
  34161. type: 'yAxis'
  34162. });
  34163. /*
  34164. * Licensed to the Apache Software Foundation (ASF) under one
  34165. * or more contributor license agreements. See the NOTICE file
  34166. * distributed with this work for additional information
  34167. * regarding copyright ownership. The ASF licenses this file
  34168. * to you under the Apache License, Version 2.0 (the
  34169. * "License"); you may not use this file except in compliance
  34170. * with the License. You may obtain a copy of the License at
  34171. *
  34172. * http://www.apache.org/licenses/LICENSE-2.0
  34173. *
  34174. * Unless required by applicable law or agreed to in writing,
  34175. * software distributed under the License is distributed on an
  34176. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34177. * KIND, either express or implied. See the License for the
  34178. * specific language governing permissions and limitations
  34179. * under the License.
  34180. */
  34181. /*
  34182. * Licensed to the Apache Software Foundation (ASF) under one
  34183. * or more contributor license agreements. See the NOTICE file
  34184. * distributed with this work for additional information
  34185. * regarding copyright ownership. The ASF licenses this file
  34186. * to you under the Apache License, Version 2.0 (the
  34187. * "License"); you may not use this file except in compliance
  34188. * with the License. You may obtain a copy of the License at
  34189. *
  34190. * http://www.apache.org/licenses/LICENSE-2.0
  34191. *
  34192. * Unless required by applicable law or agreed to in writing,
  34193. * software distributed under the License is distributed on an
  34194. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34195. * KIND, either express or implied. See the License for the
  34196. * specific language governing permissions and limitations
  34197. * under the License.
  34198. */
  34199. // Grid view
  34200. extendComponentView({
  34201. type: 'grid',
  34202. render: function (gridModel, ecModel) {
  34203. this.group.removeAll();
  34204. if (gridModel.get('show')) {
  34205. this.group.add(new Rect({
  34206. shape: gridModel.coordinateSystem.getRect(),
  34207. style: defaults({
  34208. fill: gridModel.get('backgroundColor')
  34209. }, gridModel.getItemStyle()),
  34210. silent: true,
  34211. z2: -1
  34212. }));
  34213. }
  34214. }
  34215. });
  34216. registerPreprocessor(function (option) {
  34217. // Only create grid when need
  34218. if (option.xAxis && option.yAxis && !option.grid) {
  34219. option.grid = {};
  34220. }
  34221. });
  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. // In case developer forget to include grid component
  34241. registerVisual(visualSymbol('line', 'circle', 'line'));
  34242. registerLayout(layoutPoints('line')); // Down sample after filter
  34243. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, dataSample('line'));
  34244. exports.version = version;
  34245. exports.dependencies = dependencies;
  34246. exports.PRIORITY = PRIORITY;
  34247. exports.init = init;
  34248. exports.connect = connect;
  34249. exports.disConnect = disConnect;
  34250. exports.disconnect = disconnect;
  34251. exports.dispose = dispose;
  34252. exports.getInstanceByDom = getInstanceByDom;
  34253. exports.getInstanceById = getInstanceById;
  34254. exports.registerTheme = registerTheme;
  34255. exports.registerPreprocessor = registerPreprocessor;
  34256. exports.registerProcessor = registerProcessor;
  34257. exports.registerPostUpdate = registerPostUpdate;
  34258. exports.registerAction = registerAction;
  34259. exports.registerCoordinateSystem = registerCoordinateSystem;
  34260. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  34261. exports.registerLayout = registerLayout;
  34262. exports.registerVisual = registerVisual;
  34263. exports.registerLoading = registerLoading;
  34264. exports.extendComponentModel = extendComponentModel;
  34265. exports.extendComponentView = extendComponentView;
  34266. exports.extendSeriesModel = extendSeriesModel;
  34267. exports.extendChartView = extendChartView;
  34268. exports.setCanvasCreator = setCanvasCreator;
  34269. exports.registerMap = registerMap;
  34270. exports.getMap = getMap;
  34271. exports.dataTool = dataTool;
  34272. exports.zrender = zrender;
  34273. exports.number = number;
  34274. exports.format = format;
  34275. exports.throttle = throttle;
  34276. exports.helper = helper;
  34277. exports.matrix = matrix;
  34278. exports.vector = vector;
  34279. exports.color = color;
  34280. exports.parseGeoJSON = parseGeoJSON;
  34281. exports.parseGeoJson = parseGeoJson;
  34282. exports.util = ecUtil;
  34283. exports.graphic = graphic;
  34284. exports.List = List;
  34285. exports.Model = Model;
  34286. exports.Axis = Axis;
  34287. exports.env = env$1;
  34288. });