echarts.js 2.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. window.layui && layui.define ? layui.define(function(exports){
  5. exports('echarts',factory(exports))}) :
  6. (factory((global.echarts = {})));
  7. }(this, (function (exports) { 'use strict';
  8. // (function (global, factory) {
  9. // typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  10. // typeof define === 'function' && define.amd ? define(['exports'], factory) :
  11. // (factory((global.echarts = {})));
  12. // }(this, (function (exports) { 'use strict';
  13. /*
  14. * Licensed to the Apache Software Foundation (ASF) under one
  15. * or more contributor license agreements. See the NOTICE file
  16. * distributed with this work for additional information
  17. * regarding copyright ownership. The ASF licenses this file
  18. * to you under the Apache License, Version 2.0 (the
  19. * "License"); you may not use this file except in compliance
  20. * with the License. You may obtain a copy of the License at
  21. *
  22. * http://www.apache.org/licenses/LICENSE-2.0
  23. *
  24. * Unless required by applicable law or agreed to in writing,
  25. * software distributed under the License is distributed on an
  26. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27. * KIND, either express or implied. See the License for the
  28. * specific language governing permissions and limitations
  29. * under the License.
  30. */
  31. // (1) The code `if (__DEV__) ...` can be removed by build tool.
  32. // (2) If intend to use `__DEV__`, this module should be imported. Use a global
  33. // variable `__DEV__` may cause that miss the declaration (see #6535), or the
  34. // declaration is behind of the using position (for example in `Model.extent`,
  35. // And tools like rollup can not analysis the dependency if not import).
  36. /**
  37. * zrender: 生成唯一id
  38. *
  39. * @author errorrik (errorrik@gmail.com)
  40. */
  41. var idStart = 0x0907;
  42. var guid = function () {
  43. return idStart++;
  44. };
  45. /**
  46. * echarts设备环境识别
  47. *
  48. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  49. * @author firede[firede@firede.us]
  50. * @desc thanks zepto.
  51. */
  52. /* global wx */
  53. var env = {};
  54. if (typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function') {
  55. // In Weixin Application
  56. env = {
  57. browser: {},
  58. os: {},
  59. node: false,
  60. wxa: true,
  61. // Weixin Application
  62. canvasSupported: true,
  63. svgSupported: false,
  64. touchEventsSupported: true,
  65. domSupported: false
  66. };
  67. } else if (typeof document === 'undefined' && typeof self !== 'undefined') {
  68. // In worker
  69. env = {
  70. browser: {},
  71. os: {},
  72. node: false,
  73. worker: true,
  74. canvasSupported: true,
  75. domSupported: false
  76. };
  77. } else if (typeof navigator === 'undefined') {
  78. // In node
  79. env = {
  80. browser: {},
  81. os: {},
  82. node: true,
  83. worker: false,
  84. // Assume canvas is supported
  85. canvasSupported: true,
  86. svgSupported: true,
  87. domSupported: false
  88. };
  89. } else {
  90. env = detect(navigator.userAgent);
  91. }
  92. var env$1 = env; // Zepto.js
  93. // (c) 2010-2013 Thomas Fuchs
  94. // Zepto.js may be freely distributed under the MIT license.
  95. function detect(ua) {
  96. var os = {};
  97. var browser = {}; // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  98. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  99. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  100. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  101. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  102. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  103. // var touchpad = webos && ua.match(/TouchPad/);
  104. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  105. // var silk = ua.match(/Silk\/([\d._]+)/);
  106. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  107. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  108. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  109. // var playbook = ua.match(/PlayBook/);
  110. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  111. var firefox = ua.match(/Firefox\/([\d.]+)/); // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  112. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  113. var ie = ua.match(/MSIE\s([\d.]+)/) // IE 11 Trident/7.0; rv:11.0
  114. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  115. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  116. var weChat = /micromessenger/i.test(ua); // Todo: clean this up with a better OS/browser seperation:
  117. // - discern (more) between multiple browsers on android
  118. // - decide if kindle fire in silk mode is android or not
  119. // - Firefox on Android doesn't specify the Android version
  120. // - possibly devide in os, device and browser hashes
  121. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  122. // if (android) os.android = true, os.version = android[2];
  123. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  124. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  125. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  126. // if (webos) os.webos = true, os.version = webos[2];
  127. // if (touchpad) os.touchpad = true;
  128. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  129. // if (bb10) os.bb10 = true, os.version = bb10[2];
  130. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  131. // if (playbook) browser.playbook = true;
  132. // if (kindle) os.kindle = true, os.version = kindle[1];
  133. // if (silk) browser.silk = true, browser.version = silk[1];
  134. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  135. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  136. if (firefox) {
  137. browser.firefox = true;
  138. browser.version = firefox[1];
  139. } // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  140. // if (webview) browser.webview = true;
  141. if (ie) {
  142. browser.ie = true;
  143. browser.version = ie[1];
  144. }
  145. if (edge) {
  146. browser.edge = true;
  147. browser.version = edge[1];
  148. } // It is difficult to detect WeChat in Win Phone precisely, because ua can
  149. // not be set on win phone. So we do not consider Win Phone.
  150. if (weChat) {
  151. browser.weChat = true;
  152. } // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  153. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  154. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  155. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  156. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  157. return {
  158. browser: browser,
  159. os: os,
  160. node: false,
  161. // 原生canvas支持,改极端点了
  162. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  163. canvasSupported: !!document.createElement('canvas').getContext,
  164. svgSupported: typeof SVGRect !== 'undefined',
  165. // works on most browsers
  166. // IE10/11 does not support touch event, and MS Edge supports them but not by
  167. // default, so we dont check navigator.maxTouchPoints for them here.
  168. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  169. // <http://caniuse.com/#search=pointer%20event>.
  170. pointerEventsSupported: // (1) Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  171. // events currently. So we dont use that on other browsers unless tested sufficiently.
  172. // For example, in iOS 13 Mobile Chromium 78, if the touching behavior starts page
  173. // scroll, the `pointermove` event can not be fired any more. That will break some
  174. // features like "pan horizontally to move something and pan vertically to page scroll".
  175. // The horizontal pan probably be interrupted by the casually triggered page scroll.
  176. // (2) Although IE 10 supports pointer event, it use old style and is different from the
  177. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  178. 'onpointerdown' in window && (browser.edge || browser.ie && browser.version >= 11),
  179. // passiveSupported: detectPassiveSupport()
  180. domSupported: typeof document !== 'undefined'
  181. };
  182. } // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
  183. // function detectPassiveSupport() {
  184. // // Test via a getter in the options object to see if the passive property is accessed
  185. // var supportsPassive = false;
  186. // try {
  187. // var opts = Object.defineProperty({}, 'passive', {
  188. // get: function() {
  189. // supportsPassive = true;
  190. // }
  191. // });
  192. // window.addEventListener('testPassive', function() {}, opts);
  193. // } catch (e) {
  194. // }
  195. // return supportsPassive;
  196. // }
  197. /**
  198. * @module zrender/core/util
  199. */
  200. // 用于处理merge时无法遍历Date等对象的问题
  201. var BUILTIN_OBJECT = {
  202. '[object Function]': 1,
  203. '[object RegExp]': 1,
  204. '[object Date]': 1,
  205. '[object Error]': 1,
  206. '[object CanvasGradient]': 1,
  207. '[object CanvasPattern]': 1,
  208. // For node-canvas
  209. '[object Image]': 1,
  210. '[object Canvas]': 1
  211. };
  212. var TYPED_ARRAY = {
  213. '[object Int8Array]': 1,
  214. '[object Uint8Array]': 1,
  215. '[object Uint8ClampedArray]': 1,
  216. '[object Int16Array]': 1,
  217. '[object Uint16Array]': 1,
  218. '[object Int32Array]': 1,
  219. '[object Uint32Array]': 1,
  220. '[object Float32Array]': 1,
  221. '[object Float64Array]': 1
  222. };
  223. var objToString = Object.prototype.toString;
  224. var arrayProto = Array.prototype;
  225. var nativeForEach = arrayProto.forEach;
  226. var nativeFilter = arrayProto.filter;
  227. var nativeSlice = arrayProto.slice;
  228. var nativeMap = arrayProto.map;
  229. var nativeReduce = arrayProto.reduce; // Avoid assign to an exported variable, for transforming to cjs.
  230. var methods = {};
  231. function $override(name, fn) {
  232. // Clear ctx instance for different environment
  233. if (name === 'createCanvas') {
  234. _ctx = null;
  235. }
  236. methods[name] = fn;
  237. }
  238. /**
  239. * Those data types can be cloned:
  240. * Plain object, Array, TypedArray, number, string, null, undefined.
  241. * Those data types will be assgined using the orginal data:
  242. * BUILTIN_OBJECT
  243. * Instance of user defined class will be cloned to a plain object, without
  244. * properties in prototype.
  245. * Other data types is not supported (not sure what will happen).
  246. *
  247. * Caution: do not support clone Date, for performance consideration.
  248. * (There might be a large number of date in `series.data`).
  249. * So date should not be modified in and out of echarts.
  250. *
  251. * @param {*} source
  252. * @return {*} new
  253. */
  254. function clone(source) {
  255. if (source == null || typeof source !== 'object') {
  256. return source;
  257. }
  258. var result = source;
  259. var typeStr = objToString.call(source);
  260. if (typeStr === '[object Array]') {
  261. if (!isPrimitive(source)) {
  262. result = [];
  263. for (var i = 0, len = source.length; i < len; i++) {
  264. result[i] = clone(source[i]);
  265. }
  266. }
  267. } else if (TYPED_ARRAY[typeStr]) {
  268. if (!isPrimitive(source)) {
  269. var Ctor = source.constructor;
  270. if (source.constructor.from) {
  271. result = Ctor.from(source);
  272. } else {
  273. result = new Ctor(source.length);
  274. for (var i = 0, len = source.length; i < len; i++) {
  275. result[i] = clone(source[i]);
  276. }
  277. }
  278. }
  279. } else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  280. result = {};
  281. for (var key in source) {
  282. if (source.hasOwnProperty(key)) {
  283. result[key] = clone(source[key]);
  284. }
  285. }
  286. }
  287. return result;
  288. }
  289. /**
  290. * @memberOf module:zrender/core/util
  291. * @param {*} target
  292. * @param {*} source
  293. * @param {boolean} [overwrite=false]
  294. */
  295. function merge(target, source, overwrite) {
  296. // We should escapse that source is string
  297. // and enter for ... in ...
  298. if (!isObject$1(source) || !isObject$1(target)) {
  299. return overwrite ? clone(source) : target;
  300. }
  301. for (var key in source) {
  302. if (source.hasOwnProperty(key)) {
  303. var targetProp = target[key];
  304. var sourceProp = source[key];
  305. if (isObject$1(sourceProp) && isObject$1(targetProp) && !isArray(sourceProp) && !isArray(targetProp) && !isDom(sourceProp) && !isDom(targetProp) && !isBuiltInObject(sourceProp) && !isBuiltInObject(targetProp) && !isPrimitive(sourceProp) && !isPrimitive(targetProp)) {
  306. // 如果需要递归覆盖,就递归调用merge
  307. merge(targetProp, sourceProp, overwrite);
  308. } else if (overwrite || !(key in target)) {
  309. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  310. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  311. target[key] = clone(source[key], true);
  312. }
  313. }
  314. }
  315. return target;
  316. }
  317. /**
  318. * @param {Array} targetAndSources The first item is target, and the rests are source.
  319. * @param {boolean} [overwrite=false]
  320. * @return {*} target
  321. */
  322. function mergeAll(targetAndSources, overwrite) {
  323. var result = targetAndSources[0];
  324. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  325. result = merge(result, targetAndSources[i], overwrite);
  326. }
  327. return result;
  328. }
  329. /**
  330. * @param {*} target
  331. * @param {*} source
  332. * @memberOf module:zrender/core/util
  333. */
  334. function extend(target, source) {
  335. for (var key in source) {
  336. if (source.hasOwnProperty(key)) {
  337. target[key] = source[key];
  338. }
  339. }
  340. return target;
  341. }
  342. /**
  343. * @param {*} target
  344. * @param {*} source
  345. * @param {boolean} [overlay=false]
  346. * @memberOf module:zrender/core/util
  347. */
  348. function defaults(target, source, overlay) {
  349. for (var key in source) {
  350. if (source.hasOwnProperty(key) && (overlay ? source[key] != null : target[key] == null)) {
  351. target[key] = source[key];
  352. }
  353. }
  354. return target;
  355. }
  356. var createCanvas = function () {
  357. return methods.createCanvas();
  358. };
  359. methods.createCanvas = function () {
  360. return document.createElement('canvas');
  361. }; // FIXME
  362. var _ctx;
  363. function getContext() {
  364. if (!_ctx) {
  365. // Use util.createCanvas instead of createCanvas
  366. // because createCanvas may be overwritten in different environment
  367. _ctx = createCanvas().getContext('2d');
  368. }
  369. return _ctx;
  370. }
  371. /**
  372. * 查询数组中元素的index
  373. * @memberOf module:zrender/core/util
  374. */
  375. function indexOf(array, value) {
  376. if (array) {
  377. if (array.indexOf) {
  378. return array.indexOf(value);
  379. }
  380. for (var i = 0, len = array.length; i < len; i++) {
  381. if (array[i] === value) {
  382. return i;
  383. }
  384. }
  385. }
  386. return -1;
  387. }
  388. /**
  389. * 构造类继承关系
  390. *
  391. * @memberOf module:zrender/core/util
  392. * @param {Function} clazz 源类
  393. * @param {Function} baseClazz 基类
  394. */
  395. function inherits(clazz, baseClazz) {
  396. var clazzPrototype = clazz.prototype;
  397. function F() {}
  398. F.prototype = baseClazz.prototype;
  399. clazz.prototype = new F();
  400. for (var prop in clazzPrototype) {
  401. if (clazzPrototype.hasOwnProperty(prop)) {
  402. clazz.prototype[prop] = clazzPrototype[prop];
  403. }
  404. }
  405. clazz.prototype.constructor = clazz;
  406. clazz.superClass = baseClazz;
  407. }
  408. /**
  409. * @memberOf module:zrender/core/util
  410. * @param {Object|Function} target
  411. * @param {Object|Function} sorce
  412. * @param {boolean} overlay
  413. */
  414. function mixin(target, source, overlay) {
  415. target = 'prototype' in target ? target.prototype : target;
  416. source = 'prototype' in source ? source.prototype : source;
  417. defaults(target, source, overlay);
  418. }
  419. /**
  420. * Consider typed array.
  421. * @param {Array|TypedArray} data
  422. */
  423. function isArrayLike(data) {
  424. if (!data) {
  425. return;
  426. }
  427. if (typeof data === 'string') {
  428. return false;
  429. }
  430. return typeof data.length === 'number';
  431. }
  432. /**
  433. * 数组或对象遍历
  434. * @memberOf module:zrender/core/util
  435. * @param {Object|Array} obj
  436. * @param {Function} cb
  437. * @param {*} [context]
  438. */
  439. function each$1(obj, cb, context) {
  440. if (!(obj && cb)) {
  441. return;
  442. }
  443. if (obj.forEach && obj.forEach === nativeForEach) {
  444. obj.forEach(cb, context);
  445. } else if (obj.length === +obj.length) {
  446. for (var i = 0, len = obj.length; i < len; i++) {
  447. cb.call(context, obj[i], i, obj);
  448. }
  449. } else {
  450. for (var key in obj) {
  451. if (obj.hasOwnProperty(key)) {
  452. cb.call(context, obj[key], key, obj);
  453. }
  454. }
  455. }
  456. }
  457. /**
  458. * 数组映射
  459. * @memberOf module:zrender/core/util
  460. * @param {Array} obj
  461. * @param {Function} cb
  462. * @param {*} [context]
  463. * @return {Array}
  464. */
  465. function map(obj, cb, context) {
  466. if (!(obj && cb)) {
  467. return;
  468. }
  469. if (obj.map && obj.map === nativeMap) {
  470. return obj.map(cb, context);
  471. } else {
  472. var result = [];
  473. for (var i = 0, len = obj.length; i < len; i++) {
  474. result.push(cb.call(context, obj[i], i, obj));
  475. }
  476. return result;
  477. }
  478. }
  479. /**
  480. * @memberOf module:zrender/core/util
  481. * @param {Array} obj
  482. * @param {Function} cb
  483. * @param {Object} [memo]
  484. * @param {*} [context]
  485. * @return {Array}
  486. */
  487. function reduce(obj, cb, memo, context) {
  488. if (!(obj && cb)) {
  489. return;
  490. }
  491. if (obj.reduce && obj.reduce === nativeReduce) {
  492. return obj.reduce(cb, memo, context);
  493. } else {
  494. for (var i = 0, len = obj.length; i < len; i++) {
  495. memo = cb.call(context, memo, obj[i], i, obj);
  496. }
  497. return memo;
  498. }
  499. }
  500. /**
  501. * 数组过滤
  502. * @memberOf module:zrender/core/util
  503. * @param {Array} obj
  504. * @param {Function} cb
  505. * @param {*} [context]
  506. * @return {Array}
  507. */
  508. function filter(obj, cb, context) {
  509. if (!(obj && cb)) {
  510. return;
  511. }
  512. if (obj.filter && obj.filter === nativeFilter) {
  513. return obj.filter(cb, context);
  514. } else {
  515. var result = [];
  516. for (var i = 0, len = obj.length; i < len; i++) {
  517. if (cb.call(context, obj[i], i, obj)) {
  518. result.push(obj[i]);
  519. }
  520. }
  521. return result;
  522. }
  523. }
  524. /**
  525. * 数组项查找
  526. * @memberOf module:zrender/core/util
  527. * @param {Array} obj
  528. * @param {Function} cb
  529. * @param {*} [context]
  530. * @return {*}
  531. */
  532. function find(obj, cb, context) {
  533. if (!(obj && cb)) {
  534. return;
  535. }
  536. for (var i = 0, len = obj.length; i < len; i++) {
  537. if (cb.call(context, obj[i], i, obj)) {
  538. return obj[i];
  539. }
  540. }
  541. }
  542. /**
  543. * @memberOf module:zrender/core/util
  544. * @param {Function} func
  545. * @param {*} context
  546. * @return {Function}
  547. */
  548. function bind(func, context) {
  549. var args = nativeSlice.call(arguments, 2);
  550. return function () {
  551. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  552. };
  553. }
  554. /**
  555. * @memberOf module:zrender/core/util
  556. * @param {Function} func
  557. * @return {Function}
  558. */
  559. function curry(func) {
  560. var args = nativeSlice.call(arguments, 1);
  561. return function () {
  562. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  563. };
  564. }
  565. /**
  566. * @memberOf module:zrender/core/util
  567. * @param {*} value
  568. * @return {boolean}
  569. */
  570. function isArray(value) {
  571. return objToString.call(value) === '[object Array]';
  572. }
  573. /**
  574. * @memberOf module:zrender/core/util
  575. * @param {*} value
  576. * @return {boolean}
  577. */
  578. function isFunction$1(value) {
  579. return typeof value === 'function';
  580. }
  581. /**
  582. * @memberOf module:zrender/core/util
  583. * @param {*} value
  584. * @return {boolean}
  585. */
  586. function isString(value) {
  587. return objToString.call(value) === '[object String]';
  588. }
  589. /**
  590. * @memberOf module:zrender/core/util
  591. * @param {*} value
  592. * @return {boolean}
  593. */
  594. function isObject$1(value) {
  595. // Avoid a V8 JIT bug in Chrome 19-20.
  596. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  597. var type = typeof value;
  598. return type === 'function' || !!value && type === 'object';
  599. }
  600. /**
  601. * @memberOf module:zrender/core/util
  602. * @param {*} value
  603. * @return {boolean}
  604. */
  605. function isBuiltInObject(value) {
  606. return !!BUILTIN_OBJECT[objToString.call(value)];
  607. }
  608. /**
  609. * @memberOf module:zrender/core/util
  610. * @param {*} value
  611. * @return {boolean}
  612. */
  613. function isTypedArray(value) {
  614. return !!TYPED_ARRAY[objToString.call(value)];
  615. }
  616. /**
  617. * @memberOf module:zrender/core/util
  618. * @param {*} value
  619. * @return {boolean}
  620. */
  621. function isDom(value) {
  622. return typeof value === 'object' && typeof value.nodeType === 'number' && typeof value.ownerDocument === 'object';
  623. }
  624. /**
  625. * Whether is exactly NaN. Notice isNaN('a') returns true.
  626. * @param {*} value
  627. * @return {boolean}
  628. */
  629. function eqNaN(value) {
  630. /* eslint-disable-next-line no-self-compare */
  631. return value !== value;
  632. }
  633. /**
  634. * If value1 is not null, then return value1, otherwise judget rest of values.
  635. * Low performance.
  636. * @memberOf module:zrender/core/util
  637. * @return {*} Final value
  638. */
  639. function retrieve(values) {
  640. for (var i = 0, len = arguments.length; i < len; i++) {
  641. if (arguments[i] != null) {
  642. return arguments[i];
  643. }
  644. }
  645. }
  646. function retrieve2(value0, value1) {
  647. return value0 != null ? value0 : value1;
  648. }
  649. function retrieve3(value0, value1, value2) {
  650. return value0 != null ? value0 : value1 != null ? value1 : value2;
  651. }
  652. /**
  653. * @memberOf module:zrender/core/util
  654. * @param {Array} arr
  655. * @param {number} startIndex
  656. * @param {number} endIndex
  657. * @return {Array}
  658. */
  659. function slice() {
  660. return Function.call.apply(nativeSlice, arguments);
  661. }
  662. /**
  663. * Normalize css liked array configuration
  664. * e.g.
  665. * 3 => [3, 3, 3, 3]
  666. * [4, 2] => [4, 2, 4, 2]
  667. * [4, 3, 2] => [4, 3, 2, 3]
  668. * @param {number|Array.<number>} val
  669. * @return {Array.<number>}
  670. */
  671. function normalizeCssArray(val) {
  672. if (typeof val === 'number') {
  673. return [val, val, val, val];
  674. }
  675. var len = val.length;
  676. if (len === 2) {
  677. // vertical | horizontal
  678. return [val[0], val[1], val[0], val[1]];
  679. } else if (len === 3) {
  680. // top | horizontal | bottom
  681. return [val[0], val[1], val[2], val[1]];
  682. }
  683. return val;
  684. }
  685. /**
  686. * @memberOf module:zrender/core/util
  687. * @param {boolean} condition
  688. * @param {string} message
  689. */
  690. function assert$1(condition, message) {
  691. if (!condition) {
  692. throw new Error(message);
  693. }
  694. }
  695. /**
  696. * @memberOf module:zrender/core/util
  697. * @param {string} str string to be trimed
  698. * @return {string} trimed string
  699. */
  700. function trim(str) {
  701. if (str == null) {
  702. return null;
  703. } else if (typeof str.trim === 'function') {
  704. return str.trim();
  705. } else {
  706. return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  707. }
  708. }
  709. var primitiveKey = '__ec_primitive__';
  710. /**
  711. * Set an object as primitive to be ignored traversing children in clone or merge
  712. */
  713. function setAsPrimitive(obj) {
  714. obj[primitiveKey] = true;
  715. }
  716. function isPrimitive(obj) {
  717. return obj[primitiveKey];
  718. }
  719. /**
  720. * @constructor
  721. * @param {Object} obj Only apply `ownProperty`.
  722. */
  723. function HashMap(obj) {
  724. var isArr = isArray(obj); // Key should not be set on this, otherwise
  725. // methods get/set/... may be overrided.
  726. this.data = {};
  727. var thisMap = this;
  728. obj instanceof HashMap ? obj.each(visit) : obj && each$1(obj, visit);
  729. function visit(value, key) {
  730. isArr ? thisMap.set(value, key) : thisMap.set(key, value);
  731. }
  732. }
  733. HashMap.prototype = {
  734. constructor: HashMap,
  735. // Do not provide `has` method to avoid defining what is `has`.
  736. // (We usually treat `null` and `undefined` as the same, different
  737. // from ES6 Map).
  738. get: function (key) {
  739. return this.data.hasOwnProperty(key) ? this.data[key] : null;
  740. },
  741. set: function (key, value) {
  742. // Comparing with invocation chaining, `return value` is more commonly
  743. // used in this case: `var someVal = map.set('a', genVal());`
  744. return this.data[key] = value;
  745. },
  746. // Although util.each can be performed on this hashMap directly, user
  747. // should not use the exposed keys, who are prefixed.
  748. each: function (cb, context) {
  749. context !== void 0 && (cb = bind(cb, context));
  750. /* eslint-disable guard-for-in */
  751. for (var key in this.data) {
  752. this.data.hasOwnProperty(key) && cb(this.data[key], key);
  753. }
  754. /* eslint-enable guard-for-in */
  755. },
  756. // Do not use this method if performance sensitive.
  757. removeKey: function (key) {
  758. delete this.data[key];
  759. }
  760. };
  761. function createHashMap(obj) {
  762. return new HashMap(obj);
  763. }
  764. function concatArray(a, b) {
  765. var newArray = new a.constructor(a.length + b.length);
  766. for (var i = 0; i < a.length; i++) {
  767. newArray[i] = a[i];
  768. }
  769. var offset = a.length;
  770. for (i = 0; i < b.length; i++) {
  771. newArray[i + offset] = b[i];
  772. }
  773. return newArray;
  774. }
  775. function noop() {}
  776. var zrUtil = (Object.freeze || Object)({
  777. $override: $override,
  778. clone: clone,
  779. merge: merge,
  780. mergeAll: mergeAll,
  781. extend: extend,
  782. defaults: defaults,
  783. createCanvas: createCanvas,
  784. getContext: getContext,
  785. indexOf: indexOf,
  786. inherits: inherits,
  787. mixin: mixin,
  788. isArrayLike: isArrayLike,
  789. each: each$1,
  790. map: map,
  791. reduce: reduce,
  792. filter: filter,
  793. find: find,
  794. bind: bind,
  795. curry: curry,
  796. isArray: isArray,
  797. isFunction: isFunction$1,
  798. isString: isString,
  799. isObject: isObject$1,
  800. isBuiltInObject: isBuiltInObject,
  801. isTypedArray: isTypedArray,
  802. isDom: isDom,
  803. eqNaN: eqNaN,
  804. retrieve: retrieve,
  805. retrieve2: retrieve2,
  806. retrieve3: retrieve3,
  807. slice: slice,
  808. normalizeCssArray: normalizeCssArray,
  809. assert: assert$1,
  810. trim: trim,
  811. setAsPrimitive: setAsPrimitive,
  812. isPrimitive: isPrimitive,
  813. createHashMap: createHashMap,
  814. concatArray: concatArray,
  815. noop: noop
  816. });
  817. /* global Float32Array */
  818. var ArrayCtor = typeof Float32Array === 'undefined' ? Array : Float32Array;
  819. /**
  820. * 创建一个向量
  821. * @param {number} [x=0]
  822. * @param {number} [y=0]
  823. * @return {Vector2}
  824. */
  825. function create(x, y) {
  826. var out = new ArrayCtor(2);
  827. if (x == null) {
  828. x = 0;
  829. }
  830. if (y == null) {
  831. y = 0;
  832. }
  833. out[0] = x;
  834. out[1] = y;
  835. return out;
  836. }
  837. /**
  838. * 复制向量数据
  839. * @param {Vector2} out
  840. * @param {Vector2} v
  841. * @return {Vector2}
  842. */
  843. function copy(out, v) {
  844. out[0] = v[0];
  845. out[1] = v[1];
  846. return out;
  847. }
  848. /**
  849. * 克隆一个向量
  850. * @param {Vector2} v
  851. * @return {Vector2}
  852. */
  853. function clone$1(v) {
  854. var out = new ArrayCtor(2);
  855. out[0] = v[0];
  856. out[1] = v[1];
  857. return out;
  858. }
  859. /**
  860. * 设置向量的两个项
  861. * @param {Vector2} out
  862. * @param {number} a
  863. * @param {number} b
  864. * @return {Vector2} 结果
  865. */
  866. function set(out, a, b) {
  867. out[0] = a;
  868. out[1] = b;
  869. return out;
  870. }
  871. /**
  872. * 向量相加
  873. * @param {Vector2} out
  874. * @param {Vector2} v1
  875. * @param {Vector2} v2
  876. */
  877. function add(out, v1, v2) {
  878. out[0] = v1[0] + v2[0];
  879. out[1] = v1[1] + v2[1];
  880. return out;
  881. }
  882. /**
  883. * 向量缩放后相加
  884. * @param {Vector2} out
  885. * @param {Vector2} v1
  886. * @param {Vector2} v2
  887. * @param {number} a
  888. */
  889. function scaleAndAdd(out, v1, v2, a) {
  890. out[0] = v1[0] + v2[0] * a;
  891. out[1] = v1[1] + v2[1] * a;
  892. return out;
  893. }
  894. /**
  895. * 向量相减
  896. * @param {Vector2} out
  897. * @param {Vector2} v1
  898. * @param {Vector2} v2
  899. */
  900. function sub(out, v1, v2) {
  901. out[0] = v1[0] - v2[0];
  902. out[1] = v1[1] - v2[1];
  903. return out;
  904. }
  905. /**
  906. * 向量长度
  907. * @param {Vector2} v
  908. * @return {number}
  909. */
  910. function len(v) {
  911. return Math.sqrt(lenSquare(v));
  912. }
  913. var length = len; // jshint ignore:line
  914. /**
  915. * 向量长度平方
  916. * @param {Vector2} v
  917. * @return {number}
  918. */
  919. function lenSquare(v) {
  920. return v[0] * v[0] + v[1] * v[1];
  921. }
  922. var lengthSquare = lenSquare;
  923. /**
  924. * 向量乘法
  925. * @param {Vector2} out
  926. * @param {Vector2} v1
  927. * @param {Vector2} v2
  928. */
  929. function mul(out, v1, v2) {
  930. out[0] = v1[0] * v2[0];
  931. out[1] = v1[1] * v2[1];
  932. return out;
  933. }
  934. /**
  935. * 向量除法
  936. * @param {Vector2} out
  937. * @param {Vector2} v1
  938. * @param {Vector2} v2
  939. */
  940. function div(out, v1, v2) {
  941. out[0] = v1[0] / v2[0];
  942. out[1] = v1[1] / v2[1];
  943. return out;
  944. }
  945. /**
  946. * 向量点乘
  947. * @param {Vector2} v1
  948. * @param {Vector2} v2
  949. * @return {number}
  950. */
  951. function dot(v1, v2) {
  952. return v1[0] * v2[0] + v1[1] * v2[1];
  953. }
  954. /**
  955. * 向量缩放
  956. * @param {Vector2} out
  957. * @param {Vector2} v
  958. * @param {number} s
  959. */
  960. function scale(out, v, s) {
  961. out[0] = v[0] * s;
  962. out[1] = v[1] * s;
  963. return out;
  964. }
  965. /**
  966. * 向量归一化
  967. * @param {Vector2} out
  968. * @param {Vector2} v
  969. */
  970. function normalize(out, v) {
  971. var d = len(v);
  972. if (d === 0) {
  973. out[0] = 0;
  974. out[1] = 0;
  975. } else {
  976. out[0] = v[0] / d;
  977. out[1] = v[1] / d;
  978. }
  979. return out;
  980. }
  981. /**
  982. * 计算向量间距离
  983. * @param {Vector2} v1
  984. * @param {Vector2} v2
  985. * @return {number}
  986. */
  987. function distance(v1, v2) {
  988. return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  989. }
  990. var dist = distance;
  991. /**
  992. * 向量距离平方
  993. * @param {Vector2} v1
  994. * @param {Vector2} v2
  995. * @return {number}
  996. */
  997. function distanceSquare(v1, v2) {
  998. return (v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  999. }
  1000. var distSquare = distanceSquare;
  1001. /**
  1002. * 求负向量
  1003. * @param {Vector2} out
  1004. * @param {Vector2} v
  1005. */
  1006. function negate(out, v) {
  1007. out[0] = -v[0];
  1008. out[1] = -v[1];
  1009. return out;
  1010. }
  1011. /**
  1012. * 插值两个点
  1013. * @param {Vector2} out
  1014. * @param {Vector2} v1
  1015. * @param {Vector2} v2
  1016. * @param {number} t
  1017. */
  1018. function lerp(out, v1, v2, t) {
  1019. out[0] = v1[0] + t * (v2[0] - v1[0]);
  1020. out[1] = v1[1] + t * (v2[1] - v1[1]);
  1021. return out;
  1022. }
  1023. /**
  1024. * 矩阵左乘向量
  1025. * @param {Vector2} out
  1026. * @param {Vector2} v
  1027. * @param {Vector2} m
  1028. */
  1029. function applyTransform(out, v, m) {
  1030. var x = v[0];
  1031. var y = v[1];
  1032. out[0] = m[0] * x + m[2] * y + m[4];
  1033. out[1] = m[1] * x + m[3] * y + m[5];
  1034. return out;
  1035. }
  1036. /**
  1037. * 求两个向量最小值
  1038. * @param {Vector2} out
  1039. * @param {Vector2} v1
  1040. * @param {Vector2} v2
  1041. */
  1042. function min(out, v1, v2) {
  1043. out[0] = Math.min(v1[0], v2[0]);
  1044. out[1] = Math.min(v1[1], v2[1]);
  1045. return out;
  1046. }
  1047. /**
  1048. * 求两个向量最大值
  1049. * @param {Vector2} out
  1050. * @param {Vector2} v1
  1051. * @param {Vector2} v2
  1052. */
  1053. function max(out, v1, v2) {
  1054. out[0] = Math.max(v1[0], v2[0]);
  1055. out[1] = Math.max(v1[1], v2[1]);
  1056. return out;
  1057. }
  1058. var vector = (Object.freeze || Object)({
  1059. create: create,
  1060. copy: copy,
  1061. clone: clone$1,
  1062. set: set,
  1063. add: add,
  1064. scaleAndAdd: scaleAndAdd,
  1065. sub: sub,
  1066. len: len,
  1067. length: length,
  1068. lenSquare: lenSquare,
  1069. lengthSquare: lengthSquare,
  1070. mul: mul,
  1071. div: div,
  1072. dot: dot,
  1073. scale: scale,
  1074. normalize: normalize,
  1075. distance: distance,
  1076. dist: dist,
  1077. distanceSquare: distanceSquare,
  1078. distSquare: distSquare,
  1079. negate: negate,
  1080. lerp: lerp,
  1081. applyTransform: applyTransform,
  1082. min: min,
  1083. max: max
  1084. });
  1085. // TODO Draggable for group
  1086. // FIXME Draggable on element which has parent rotation or scale
  1087. function Draggable() {
  1088. this.on('mousedown', this._dragStart, this);
  1089. this.on('mousemove', this._drag, this);
  1090. this.on('mouseup', this._dragEnd, this); // `mosuemove` and `mouseup` can be continue to fire when dragging.
  1091. // See [Drag outside] in `Handler.js`. So we do not need to trigger
  1092. // `_dragEnd` when globalout. That would brings better user experience.
  1093. // this.on('globalout', this._dragEnd, this);
  1094. // this._dropTarget = null;
  1095. // this._draggingTarget = null;
  1096. // this._x = 0;
  1097. // this._y = 0;
  1098. }
  1099. Draggable.prototype = {
  1100. constructor: Draggable,
  1101. _dragStart: function (e) {
  1102. var draggingTarget = e.target; // Find if there is draggable in the ancestor
  1103. while (draggingTarget && !draggingTarget.draggable) {
  1104. draggingTarget = draggingTarget.parent;
  1105. }
  1106. if (draggingTarget) {
  1107. this._draggingTarget = draggingTarget;
  1108. draggingTarget.dragging = true;
  1109. this._x = e.offsetX;
  1110. this._y = e.offsetY;
  1111. this.dispatchToElement(param(draggingTarget, e), 'dragstart', e.event);
  1112. }
  1113. },
  1114. _drag: function (e) {
  1115. var draggingTarget = this._draggingTarget;
  1116. if (draggingTarget) {
  1117. var x = e.offsetX;
  1118. var y = e.offsetY;
  1119. var dx = x - this._x;
  1120. var dy = y - this._y;
  1121. this._x = x;
  1122. this._y = y;
  1123. draggingTarget.drift(dx, dy, e);
  1124. this.dispatchToElement(param(draggingTarget, e), 'drag', e.event);
  1125. var dropTarget = this.findHover(x, y, draggingTarget).target;
  1126. var lastDropTarget = this._dropTarget;
  1127. this._dropTarget = dropTarget;
  1128. if (draggingTarget !== dropTarget) {
  1129. if (lastDropTarget && dropTarget !== lastDropTarget) {
  1130. this.dispatchToElement(param(lastDropTarget, e), 'dragleave', e.event);
  1131. }
  1132. if (dropTarget && dropTarget !== lastDropTarget) {
  1133. this.dispatchToElement(param(dropTarget, e), 'dragenter', e.event);
  1134. }
  1135. }
  1136. }
  1137. },
  1138. _dragEnd: function (e) {
  1139. var draggingTarget = this._draggingTarget;
  1140. if (draggingTarget) {
  1141. draggingTarget.dragging = false;
  1142. }
  1143. this.dispatchToElement(param(draggingTarget, e), 'dragend', e.event);
  1144. if (this._dropTarget) {
  1145. this.dispatchToElement(param(this._dropTarget, e), 'drop', e.event);
  1146. }
  1147. this._draggingTarget = null;
  1148. this._dropTarget = null;
  1149. }
  1150. };
  1151. function param(target, e) {
  1152. return {
  1153. target: target,
  1154. topTarget: e && e.topTarget
  1155. };
  1156. }
  1157. /**
  1158. * Event Mixin
  1159. * @module zrender/mixin/Eventful
  1160. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  1161. * pissang (https://www.github.com/pissang)
  1162. */
  1163. var arrySlice = Array.prototype.slice;
  1164. /**
  1165. * Event dispatcher.
  1166. *
  1167. * @alias module:zrender/mixin/Eventful
  1168. * @constructor
  1169. * @param {Object} [eventProcessor] The object eventProcessor is the scope when
  1170. * `eventProcessor.xxx` called.
  1171. * @param {Function} [eventProcessor.normalizeQuery]
  1172. * param: {string|Object} Raw query.
  1173. * return: {string|Object} Normalized query.
  1174. * @param {Function} [eventProcessor.filter] Event will be dispatched only
  1175. * if it returns `true`.
  1176. * param: {string} eventType
  1177. * param: {string|Object} query
  1178. * return: {boolean}
  1179. * @param {Function} [eventProcessor.afterTrigger] Called after all handlers called.
  1180. * param: {string} eventType
  1181. */
  1182. var Eventful = function (eventProcessor) {
  1183. this._$handlers = {};
  1184. this._$eventProcessor = eventProcessor;
  1185. };
  1186. Eventful.prototype = {
  1187. constructor: Eventful,
  1188. /**
  1189. * The handler can only be triggered once, then removed.
  1190. *
  1191. * @param {string} event The event name.
  1192. * @param {string|Object} [query] Condition used on event filter.
  1193. * @param {Function} handler The event handler.
  1194. * @param {Object} context
  1195. */
  1196. one: function (event, query, handler, context) {
  1197. return on(this, event, query, handler, context, true);
  1198. },
  1199. /**
  1200. * Bind a handler.
  1201. *
  1202. * @param {string} event The event name.
  1203. * @param {string|Object} [query] Condition used on event filter.
  1204. * @param {Function} handler The event handler.
  1205. * @param {Object} [context]
  1206. */
  1207. on: function (event, query, handler, context) {
  1208. return on(this, event, query, handler, context, false);
  1209. },
  1210. /**
  1211. * Whether any handler has bound.
  1212. *
  1213. * @param {string} event
  1214. * @return {boolean}
  1215. */
  1216. isSilent: function (event) {
  1217. var _h = this._$handlers;
  1218. return !_h[event] || !_h[event].length;
  1219. },
  1220. /**
  1221. * Unbind a event.
  1222. *
  1223. * @param {string} [event] The event name.
  1224. * If no `event` input, "off" all listeners.
  1225. * @param {Function} [handler] The event handler.
  1226. * If no `handler` input, "off" all listeners of the `event`.
  1227. */
  1228. off: function (event, handler) {
  1229. var _h = this._$handlers;
  1230. if (!event) {
  1231. this._$handlers = {};
  1232. return this;
  1233. }
  1234. if (handler) {
  1235. if (_h[event]) {
  1236. var newList = [];
  1237. for (var i = 0, l = _h[event].length; i < l; i++) {
  1238. if (_h[event][i].h !== handler) {
  1239. newList.push(_h[event][i]);
  1240. }
  1241. }
  1242. _h[event] = newList;
  1243. }
  1244. if (_h[event] && _h[event].length === 0) {
  1245. delete _h[event];
  1246. }
  1247. } else {
  1248. delete _h[event];
  1249. }
  1250. return this;
  1251. },
  1252. /**
  1253. * Dispatch a event.
  1254. *
  1255. * @param {string} type The event name.
  1256. */
  1257. trigger: function (type) {
  1258. var _h = this._$handlers[type];
  1259. var eventProcessor = this._$eventProcessor;
  1260. if (_h) {
  1261. var args = arguments;
  1262. var argLen = args.length;
  1263. if (argLen > 3) {
  1264. args = arrySlice.call(args, 1);
  1265. }
  1266. var len = _h.length;
  1267. for (var i = 0; i < len;) {
  1268. var hItem = _h[i];
  1269. if (eventProcessor && eventProcessor.filter && hItem.query != null && !eventProcessor.filter(type, hItem.query)) {
  1270. i++;
  1271. continue;
  1272. } // Optimize advise from backbone
  1273. switch (argLen) {
  1274. case 1:
  1275. hItem.h.call(hItem.ctx);
  1276. break;
  1277. case 2:
  1278. hItem.h.call(hItem.ctx, args[1]);
  1279. break;
  1280. case 3:
  1281. hItem.h.call(hItem.ctx, args[1], args[2]);
  1282. break;
  1283. default:
  1284. // have more than 2 given arguments
  1285. hItem.h.apply(hItem.ctx, args);
  1286. break;
  1287. }
  1288. if (hItem.one) {
  1289. _h.splice(i, 1);
  1290. len--;
  1291. } else {
  1292. i++;
  1293. }
  1294. }
  1295. }
  1296. eventProcessor && eventProcessor.afterTrigger && eventProcessor.afterTrigger(type);
  1297. return this;
  1298. },
  1299. /**
  1300. * Dispatch a event with context, which is specified at the last parameter.
  1301. *
  1302. * @param {string} type The event name.
  1303. */
  1304. triggerWithContext: function (type) {
  1305. var _h = this._$handlers[type];
  1306. var eventProcessor = this._$eventProcessor;
  1307. if (_h) {
  1308. var args = arguments;
  1309. var argLen = args.length;
  1310. if (argLen > 4) {
  1311. args = arrySlice.call(args, 1, args.length - 1);
  1312. }
  1313. var ctx = args[args.length - 1];
  1314. var len = _h.length;
  1315. for (var i = 0; i < len;) {
  1316. var hItem = _h[i];
  1317. if (eventProcessor && eventProcessor.filter && hItem.query != null && !eventProcessor.filter(type, hItem.query)) {
  1318. i++;
  1319. continue;
  1320. } // Optimize advise from backbone
  1321. switch (argLen) {
  1322. case 1:
  1323. hItem.h.call(ctx);
  1324. break;
  1325. case 2:
  1326. hItem.h.call(ctx, args[1]);
  1327. break;
  1328. case 3:
  1329. hItem.h.call(ctx, args[1], args[2]);
  1330. break;
  1331. default:
  1332. // have more than 2 given arguments
  1333. hItem.h.apply(ctx, args);
  1334. break;
  1335. }
  1336. if (hItem.one) {
  1337. _h.splice(i, 1);
  1338. len--;
  1339. } else {
  1340. i++;
  1341. }
  1342. }
  1343. }
  1344. eventProcessor && eventProcessor.afterTrigger && eventProcessor.afterTrigger(type);
  1345. return this;
  1346. }
  1347. };
  1348. function normalizeQuery(host, query) {
  1349. var eventProcessor = host._$eventProcessor;
  1350. if (query != null && eventProcessor && eventProcessor.normalizeQuery) {
  1351. query = eventProcessor.normalizeQuery(query);
  1352. }
  1353. return query;
  1354. }
  1355. function on(eventful, event, query, handler, context, isOnce) {
  1356. var _h = eventful._$handlers;
  1357. if (typeof query === 'function') {
  1358. context = handler;
  1359. handler = query;
  1360. query = null;
  1361. }
  1362. if (!handler || !event) {
  1363. return eventful;
  1364. }
  1365. query = normalizeQuery(eventful, query);
  1366. if (!_h[event]) {
  1367. _h[event] = [];
  1368. }
  1369. for (var i = 0; i < _h[event].length; i++) {
  1370. if (_h[event][i].h === handler) {
  1371. return eventful;
  1372. }
  1373. }
  1374. var wrap = {
  1375. h: handler,
  1376. one: isOnce,
  1377. query: query,
  1378. ctx: context || eventful,
  1379. // FIXME
  1380. // Do not publish this feature util it is proved that it makes sense.
  1381. callAtLast: handler.zrEventfulCallAtLast
  1382. };
  1383. var lastIndex = _h[event].length - 1;
  1384. var lastWrap = _h[event][lastIndex];
  1385. lastWrap && lastWrap.callAtLast ? _h[event].splice(lastIndex, 0, wrap) : _h[event].push(wrap);
  1386. return eventful;
  1387. } // ----------------------
  1388. /**
  1389. * The algoritm is learnt from
  1390. * https://franklinta.com/2014/09/08/computing-css-matrix3d-transforms/
  1391. * And we made some optimization for matrix inversion.
  1392. * Other similar approaches:
  1393. * "cv::getPerspectiveTransform", "Direct Linear Transformation".
  1394. */
  1395. var LN2 = Math.log(2);
  1396. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1397. var cacheKey = rowMask + '-' + colMask;
  1398. var fullRank = rows.length;
  1399. if (detCache.hasOwnProperty(cacheKey)) {
  1400. return detCache[cacheKey];
  1401. }
  1402. if (rank === 1) {
  1403. // In this case the colMask must be like: `11101111`. We can find the place of `0`.
  1404. var colStart = Math.round(Math.log((1 << fullRank) - 1 & ~colMask) / LN2);
  1405. return rows[rowStart][colStart];
  1406. }
  1407. var subRowMask = rowMask | 1 << rowStart;
  1408. var subRowStart = rowStart + 1;
  1409. while (rowMask & 1 << subRowStart) {
  1410. subRowStart++;
  1411. }
  1412. var sum = 0;
  1413. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1414. var colTag = 1 << j;
  1415. if (!(colTag & colMask)) {
  1416. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j] // det(subMatrix(0, j))
  1417. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1418. colLocalIdx++;
  1419. }
  1420. }
  1421. detCache[cacheKey] = sum;
  1422. return sum;
  1423. }
  1424. /**
  1425. * Usage:
  1426. * ```js
  1427. * var transformer = buildTransformer(
  1428. * [10, 44, 100, 44, 100, 300, 10, 300],
  1429. * [50, 54, 130, 14, 140, 330, 14, 220]
  1430. * );
  1431. * var out = [];
  1432. * transformer && transformer([11, 33], out);
  1433. * ```
  1434. *
  1435. * Notice: `buildTransformer` may take more than 10ms in some Android device.
  1436. *
  1437. * @param {Array.<number>} src source four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1438. * @param {Array.<number>} dest destination four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1439. * @return {Function} transformer If fail, return null/undefined.
  1440. */
  1441. function buildTransformer(src, dest) {
  1442. 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]]];
  1443. var detCache = {};
  1444. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1445. if (det === 0) {
  1446. // can not make transformer when and only when
  1447. // any three of the markers are collinear.
  1448. return;
  1449. } // `invert(mA) * dest`, that is, `adj(mA) / det * dest`.
  1450. var vh = [];
  1451. for (var i = 0; i < 8; i++) {
  1452. for (var j = 0; j < 8; j++) {
  1453. vh[j] == null && (vh[j] = 0);
  1454. vh[j] += ((i + j) % 2 ? -1 : 1) * // det(subMatrix(i, j))
  1455. determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache) / det * dest[i];
  1456. }
  1457. }
  1458. return function (out, srcPointX, srcPointY) {
  1459. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1460. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1461. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1462. };
  1463. }
  1464. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1465. var _calcOut$1 = [];
  1466. /**
  1467. * Transform "local coord" from `elFrom` to `elTarget`.
  1468. * "local coord": the coord based on the input `el`. The origin point is at
  1469. * the position of "left: 0; top: 0;" in the `el`.
  1470. *
  1471. * Support when CSS transform is used.
  1472. *
  1473. * Having the `out` (that is, `[outX, outY]`), we can create an DOM element
  1474. * and set the CSS style as "left: outX; top: outY;" and append it to `elTarge`
  1475. * to locate the element.
  1476. *
  1477. * For example, this code below positions a child of `document.body` on the event
  1478. * point, no matter whether `body` has `margin`/`paddin`/`transfrom`/... :
  1479. * ```js
  1480. * transformLocalCoord(out, container, document.body, event.offsetX, event.offsetY);
  1481. * if (!eqNaN(out[0])) {
  1482. * // Then locate the tip element on the event point.
  1483. * var tipEl = document.createElement('div');
  1484. * tipEl.style.cssText = 'position: absolute; left:' + out[0] + ';top:' + out[1] + ';';
  1485. * document.body.appendChild(tipEl);
  1486. * }
  1487. * ```
  1488. *
  1489. * Notice: In some env this method is not supported. If called, `out` will be `[NaN, NaN]`.
  1490. *
  1491. * @param {Array.<number>} out [inX: number, inY: number] The output..
  1492. * If can not transform, `out` will not be modified but return `false`.
  1493. * @param {HTMLElement} elFrom The `[inX, inY]` is based on elFrom.
  1494. * @param {HTMLElement} elTarget The `out` is based on elTarget.
  1495. * @param {number} inX
  1496. * @param {number} inY
  1497. * @return {boolean} Whether transform successfully.
  1498. */
  1499. function transformLocalCoord(out, elFrom, elTarget, inX, inY) {
  1500. return transformCoordWithViewport(_calcOut$1, elFrom, inX, inY, true) && transformCoordWithViewport(out, elTarget, _calcOut$1[0], _calcOut$1[1]);
  1501. }
  1502. /**
  1503. * Transform between a "viewport coord" and a "local coord".
  1504. * "viewport coord": the coord based on the left-top corner of the viewport
  1505. * of the browser.
  1506. * "local coord": the coord based on the input `el`. The origin point is at
  1507. * the position of "left: 0; top: 0;" in the `el`.
  1508. *
  1509. * Support the case when CSS transform is used on el.
  1510. *
  1511. * @param {Array.<number>} out [inX: number, inY: number] The output. If `inverse: false`,
  1512. * it represents "local coord", otherwise "vireport coord".
  1513. * If can not transform, `out` will not be modified but return `false`.
  1514. * @param {HTMLElement} el The "local coord" is based on the `el`, see comment above.
  1515. * @param {number} inX If `inverse: false`,
  1516. * it represents "vireport coord", otherwise "local coord".
  1517. * @param {number} inY If `inverse: false`,
  1518. * it represents "vireport coord", otherwise "local coord".
  1519. * @param {boolean} [inverse=false]
  1520. * `true`: from "viewport coord" to "local coord".
  1521. * `false`: from "local coord" to "viewport coord".
  1522. * @return {boolean} Whether transform successfully.
  1523. */
  1524. function transformCoordWithViewport(out, el, inX, inY, inverse) {
  1525. if (el.getBoundingClientRect && env$1.domSupported && !isCanvasEl(el)) {
  1526. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1527. var markers = prepareCoordMarkers(el, saved);
  1528. var transformer = preparePointerTransformer(markers, saved, inverse);
  1529. if (transformer) {
  1530. transformer(out, inX, inY);
  1531. return true;
  1532. }
  1533. }
  1534. return false;
  1535. }
  1536. function prepareCoordMarkers(el, saved) {
  1537. var markers = saved.markers;
  1538. if (markers) {
  1539. return markers;
  1540. }
  1541. markers = saved.markers = [];
  1542. var propLR = ['left', 'right'];
  1543. var propTB = ['top', 'bottom'];
  1544. for (var i = 0; i < 4; i++) {
  1545. var marker = document.createElement('div');
  1546. var stl = marker.style;
  1547. var idxLR = i % 2;
  1548. var idxTB = (i >> 1) % 2;
  1549. stl.cssText = ['position: absolute', 'visibility: hidden', 'padding: 0', 'margin: 0', 'border-width: 0', 'user-select: none', 'width:0', 'height:0', // 'width: 5px',
  1550. // 'height: 5px',
  1551. propLR[idxLR] + ':0', propTB[idxTB] + ':0', propLR[1 - idxLR] + ':auto', propTB[1 - idxTB] + ':auto', ''].join('!important;');
  1552. el.appendChild(marker);
  1553. markers.push(marker);
  1554. }
  1555. return markers;
  1556. }
  1557. function preparePointerTransformer(markers, saved, inverse) {
  1558. var transformerName = inverse ? 'invTrans' : 'trans';
  1559. var transformer = saved[transformerName];
  1560. var oldSrcCoords = saved.srcCoords;
  1561. var oldCoordTheSame = true;
  1562. var srcCoords = [];
  1563. var destCoords = [];
  1564. for (var i = 0; i < 4; i++) {
  1565. var rect = markers[i].getBoundingClientRect();
  1566. var ii = 2 * i;
  1567. var x = rect.left;
  1568. var y = rect.top;
  1569. srcCoords.push(x, y);
  1570. oldCoordTheSame = oldCoordTheSame && oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1571. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1572. } // Cache to avoid time consuming of `buildTransformer`.
  1573. return oldCoordTheSame && transformer ? transformer : (saved.srcCoords = srcCoords, saved[transformerName] = inverse ? buildTransformer(destCoords, srcCoords) : buildTransformer(srcCoords, destCoords));
  1574. }
  1575. function isCanvasEl(el) {
  1576. return el.nodeName.toUpperCase() === 'CANVAS';
  1577. }
  1578. /**
  1579. * Utilities for mouse or touch events.
  1580. */
  1581. var isDomLevel2 = typeof window !== 'undefined' && !!window.addEventListener;
  1582. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1583. var _calcOut = [];
  1584. /**
  1585. * Get the `zrX` and `zrY`, which are relative to the top-left of
  1586. * the input `el`.
  1587. * CSS transform (2D & 3D) is supported.
  1588. *
  1589. * The strategy to fetch the coords:
  1590. * + If `calculate` is not set as `true`, users of this method should
  1591. * ensure that `el` is the same or the same size & location as `e.target`.
  1592. * Otherwise the result coords are probably not expected. Because we
  1593. * firstly try to get coords from e.offsetX/e.offsetY.
  1594. * + If `calculate` is set as `true`, the input `el` can be any element
  1595. * and we force to calculate the coords based on `el`.
  1596. * + The input `el` should be positionable (not position:static).
  1597. *
  1598. * The force `calculate` can be used in case like:
  1599. * When mousemove event triggered on ec tooltip, `e.target` is not `el`(zr painter.dom).
  1600. *
  1601. * @param {HTMLElement} el DOM element.
  1602. * @param {Event} e Mouse event or touch event.
  1603. * @param {Object} out Get `out.zrX` and `out.zrY` as the result.
  1604. * @param {boolean} [calculate=false] Whether to force calculate
  1605. * the coordinates but not use ones provided by browser.
  1606. */
  1607. function clientToLocal(el, e, out, calculate) {
  1608. out = out || {}; // According to the W3C Working Draft, offsetX and offsetY should be relative
  1609. // to the padding edge of the target element. The only browser using this convention
  1610. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  1611. // not support the properties.
  1612. // (see http://www.jacklmoore.com/notes/mouse-position/)
  1613. // In zr painter.dom, padding edge equals to border edge.
  1614. if (calculate || !env$1.canvasSupported) {
  1615. calculateZrXY(el, e, out);
  1616. } // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  1617. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  1618. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  1619. // zoom-factor, overflow / opacity layers, transforms ...)
  1620. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  1621. // <https://bugs.jquery.com/ticket/8523#comment:14>
  1622. // BTW3, In ff, offsetX/offsetY is always 0.
  1623. else if (env$1.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  1624. out.zrX = e.layerX;
  1625. out.zrY = e.layerY;
  1626. } // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  1627. else if (e.offsetX != null) {
  1628. out.zrX = e.offsetX;
  1629. out.zrY = e.offsetY;
  1630. } // For some other device, e.g., IOS safari.
  1631. else {
  1632. calculateZrXY(el, e, out);
  1633. }
  1634. return out;
  1635. }
  1636. function calculateZrXY(el, e, out) {
  1637. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect.
  1638. if (env$1.domSupported && el.getBoundingClientRect) {
  1639. var ex = e.clientX;
  1640. var ey = e.clientY;
  1641. if (isCanvasEl(el)) {
  1642. // Original approach, which do not support CSS transform.
  1643. // marker can not be locationed in a canvas container
  1644. // (getBoundingClientRect is always 0). We do not support
  1645. // that input a pre-created canvas to zr while using css
  1646. // transform in iOS.
  1647. var box = el.getBoundingClientRect();
  1648. out.zrX = ex - box.left;
  1649. out.zrY = ey - box.top;
  1650. return;
  1651. } else {
  1652. if (transformCoordWithViewport(_calcOut, el, ex, ey)) {
  1653. out.zrX = _calcOut[0];
  1654. out.zrY = _calcOut[1];
  1655. return;
  1656. }
  1657. }
  1658. }
  1659. out.zrX = out.zrY = 0;
  1660. }
  1661. /**
  1662. * Find native event compat for legency IE.
  1663. * Should be called at the begining of a native event listener.
  1664. *
  1665. * @param {Event} [e] Mouse event or touch event or pointer event.
  1666. * For lagency IE, we use `window.event` is used.
  1667. * @return {Event} The native event.
  1668. */
  1669. function getNativeEvent(e) {
  1670. return e || window.event;
  1671. }
  1672. /**
  1673. * Normalize the coordinates of the input event.
  1674. *
  1675. * Get the `e.zrX` and `e.zrY`, which are relative to the top-left of
  1676. * the input `el`.
  1677. * Get `e.zrDelta` if using mouse wheel.
  1678. * Get `e.which`, see the comment inside this function.
  1679. *
  1680. * Do not calculate repeatly if `zrX` and `zrY` already exist.
  1681. *
  1682. * Notice: see comments in `clientToLocal`. check the relationship
  1683. * between the result coords and the parameters `el` and `calculate`.
  1684. *
  1685. * @param {HTMLElement} el DOM element.
  1686. * @param {Event} [e] See `getNativeEvent`.
  1687. * @param {boolean} [calculate=false] Whether to force calculate
  1688. * the coordinates but not use ones provided by browser.
  1689. * @return {UIEvent} The normalized native UIEvent.
  1690. */
  1691. function normalizeEvent(el, e, calculate) {
  1692. e = getNativeEvent(e);
  1693. if (e.zrX != null) {
  1694. return e;
  1695. }
  1696. var eventType = e.type;
  1697. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1698. if (!isTouch) {
  1699. clientToLocal(el, e, e, calculate);
  1700. e.zrDelta = e.wheelDelta ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  1701. } else {
  1702. var touch = eventType !== 'touchend' ? e.targetTouches[0] : e.changedTouches[0];
  1703. touch && clientToLocal(el, touch, e, calculate);
  1704. } // Add which for click: 1 === left; 2 === middle; 3 === right; otherwise: 0;
  1705. // See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
  1706. // If e.which has been defined, it may be readonly,
  1707. // see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
  1708. var button = e.button;
  1709. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1710. e.which = button & 1 ? 1 : button & 2 ? 3 : button & 4 ? 2 : 0;
  1711. } // [Caution]: `e.which` from browser is not always reliable. For example,
  1712. // when press left button and `mousemove (pointermove)` in Edge, the `e.which`
  1713. // is 65536 and the `e.button` is -1. But the `mouseup (pointerup)` and
  1714. // `mousedown (pointerdown)` is the same as Chrome does.
  1715. return e;
  1716. }
  1717. /**
  1718. * @param {HTMLElement} el
  1719. * @param {string} name
  1720. * @param {Function} handler
  1721. * @param {Object|boolean} opt If boolean, means `opt.capture`
  1722. * @param {boolean} [opt.capture=false]
  1723. * @param {boolean} [opt.passive=false]
  1724. */
  1725. function addEventListener(el, name, handler, opt) {
  1726. if (isDomLevel2) {
  1727. // Reproduct the console warning:
  1728. // [Violation] Added non-passive event listener to a scroll-blocking <some> event.
  1729. // Consider marking event handler as 'passive' to make the page more responsive.
  1730. // Just set console log level: verbose in chrome dev tool.
  1731. // then the warning log will be printed when addEventListener called.
  1732. // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  1733. // We have not yet found a neat way to using passive. Because in zrender the dom event
  1734. // listener delegate all of the upper events of element. Some of those events need
  1735. // to prevent default. For example, the feature `preventDefaultMouseMove` of echarts.
  1736. // Before passive can be adopted, these issues should be considered:
  1737. // (1) Whether and how a zrender user specifies an event listener passive. And by default,
  1738. // passive or not.
  1739. // (2) How to tread that some zrender event listener is passive, and some is not. If
  1740. // we use other way but not preventDefault of mousewheel and touchmove, browser
  1741. // compatibility should be handled.
  1742. // var opts = (env.passiveSupported && name === 'mousewheel')
  1743. // ? {passive: true}
  1744. // // By default, the third param of el.addEventListener is `capture: false`.
  1745. // : void 0;
  1746. // el.addEventListener(name, handler /* , opts */);
  1747. el.addEventListener(name, handler, opt);
  1748. } else {
  1749. // For simplicity, do not implement `setCapture` for IE9-.
  1750. el.attachEvent('on' + name, handler);
  1751. }
  1752. }
  1753. /**
  1754. * Parameter are the same as `addEventListener`.
  1755. *
  1756. * Notice that if a listener is registered twice, one with capture and one without,
  1757. * remove each one separately. Removal of a capturing listener does not affect a
  1758. * non-capturing version of the same listener, and vice versa.
  1759. */
  1760. function removeEventListener(el, name, handler, opt) {
  1761. if (isDomLevel2) {
  1762. el.removeEventListener(name, handler, opt);
  1763. } else {
  1764. el.detachEvent('on' + name, handler);
  1765. }
  1766. }
  1767. /**
  1768. * preventDefault and stopPropagation.
  1769. * Notice: do not use this method in zrender. It can only be
  1770. * used by upper applications if necessary.
  1771. *
  1772. * @param {Event} e A mouse or touch event.
  1773. */
  1774. var stop = isDomLevel2 ? function (e) {
  1775. e.preventDefault();
  1776. e.stopPropagation();
  1777. e.cancelBubble = true;
  1778. } : function (e) {
  1779. e.returnValue = false;
  1780. e.cancelBubble = true;
  1781. };
  1782. /**
  1783. * This method only works for mouseup and mousedown. The functionality is restricted
  1784. * for fault tolerance, See the `e.which` compatibility above.
  1785. *
  1786. * @param {MouseEvent} e
  1787. * @return {boolean}
  1788. */
  1789. function isMiddleOrRightButtonOnMouseUpDown(e) {
  1790. return e.which === 2 || e.which === 3;
  1791. }
  1792. /**
  1793. * To be removed.
  1794. * @deprecated
  1795. */
  1796. // For backward compatibility
  1797. /**
  1798. * Only implements needed gestures for mobile.
  1799. */
  1800. var GestureMgr = function () {
  1801. /**
  1802. * @private
  1803. * @type {Array.<Object>}
  1804. */
  1805. this._track = [];
  1806. };
  1807. GestureMgr.prototype = {
  1808. constructor: GestureMgr,
  1809. recognize: function (event, target, root) {
  1810. this._doTrack(event, target, root);
  1811. return this._recognize(event);
  1812. },
  1813. clear: function () {
  1814. this._track.length = 0;
  1815. return this;
  1816. },
  1817. _doTrack: function (event, target, root) {
  1818. var touches = event.touches;
  1819. if (!touches) {
  1820. return;
  1821. }
  1822. var trackItem = {
  1823. points: [],
  1824. touches: [],
  1825. target: target,
  1826. event: event
  1827. };
  1828. for (var i = 0, len = touches.length; i < len; i++) {
  1829. var touch = touches[i];
  1830. var pos = clientToLocal(root, touch, {});
  1831. trackItem.points.push([pos.zrX, pos.zrY]);
  1832. trackItem.touches.push(touch);
  1833. }
  1834. this._track.push(trackItem);
  1835. },
  1836. _recognize: function (event) {
  1837. for (var eventName in recognizers) {
  1838. if (recognizers.hasOwnProperty(eventName)) {
  1839. var gestureInfo = recognizers[eventName](this._track, event);
  1840. if (gestureInfo) {
  1841. return gestureInfo;
  1842. }
  1843. }
  1844. }
  1845. }
  1846. };
  1847. function dist$1(pointPair) {
  1848. var dx = pointPair[1][0] - pointPair[0][0];
  1849. var dy = pointPair[1][1] - pointPair[0][1];
  1850. return Math.sqrt(dx * dx + dy * dy);
  1851. }
  1852. function center(pointPair) {
  1853. return [(pointPair[0][0] + pointPair[1][0]) / 2, (pointPair[0][1] + pointPair[1][1]) / 2];
  1854. }
  1855. var recognizers = {
  1856. pinch: function (track, event) {
  1857. var trackLen = track.length;
  1858. if (!trackLen) {
  1859. return;
  1860. }
  1861. var pinchEnd = (track[trackLen - 1] || {}).points;
  1862. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  1863. if (pinchPre && pinchPre.length > 1 && pinchEnd && pinchEnd.length > 1) {
  1864. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1865. !isFinite(pinchScale) && (pinchScale = 1);
  1866. event.pinchScale = pinchScale;
  1867. var pinchCenter = center(pinchEnd);
  1868. event.pinchX = pinchCenter[0];
  1869. event.pinchY = pinchCenter[1];
  1870. return {
  1871. type: 'pinch',
  1872. target: track[0].target,
  1873. event: event
  1874. };
  1875. }
  1876. } // Only pinch currently.
  1877. };
  1878. /**
  1879. * [The interface between `Handler` and `HandlerProxy`]:
  1880. *
  1881. * The default `HandlerProxy` only support the common standard web environment
  1882. * (e.g., standalone browser, headless browser, embed browser in mobild APP, ...).
  1883. * But `HandlerProxy` can be replaced to support more non-standard environment
  1884. * (e.g., mini app), or to support more feature that the default `HandlerProxy`
  1885. * not provided (like echarts-gl did).
  1886. * So the interface between `Handler` and `HandlerProxy` should be stable. Do not
  1887. * make break changes util inevitable. The interface include the public methods
  1888. * of `Handler` and the events listed in `handlerNames` below, by which `HandlerProxy`
  1889. * drives `Handler`.
  1890. */
  1891. /**
  1892. * [Drag outside]:
  1893. *
  1894. * That is, triggering `mousemove` and `mouseup` event when the pointer is out of the
  1895. * zrender area when dragging. That is important for the improvement of the user experience
  1896. * when dragging something near the boundary without being terminated unexpectedly.
  1897. *
  1898. * We originally consider to introduce new events like `pagemovemove` and `pagemouseup`
  1899. * to resolve this issue. But some drawbacks of it is described in
  1900. * https://github.com/ecomfe/zrender/pull/536#issuecomment-560286899
  1901. *
  1902. * Instead, we referenced the specifications:
  1903. * https://www.w3.org/TR/touch-events/#the-touchmove-event
  1904. * https://www.w3.org/TR/2014/WD-DOM-Level-3-Events-20140925/#event-type-mousemove
  1905. * where the the mousemove/touchmove can be continue to fire if the user began a drag
  1906. * operation and the pointer has left the boundary. (for the mouse event, browsers
  1907. * only do it on `document` and when the pointer has left the boundary of the browser.)
  1908. *
  1909. * So the default `HandlerProxy` supports this feature similarly: if it is in the dragging
  1910. * state (see `pointerCapture` in `HandlerProxy`), the `mousemove` and `mouseup` continue
  1911. * to fire until release the pointer. That is implemented by listen to those event on
  1912. * `document`.
  1913. * If we implement some other `HandlerProxy` only for touch device, that would be easier.
  1914. * The touch event support this feature by default.
  1915. *
  1916. * Note:
  1917. * There might be some cases that the mouse event can not be
  1918. * received on `document`. For example,
  1919. * (A) `useCapture` is not supported and some user defined event listeners on the ancestor
  1920. * of zr dom throw Error .
  1921. * (B) `useCapture` is not supported Some user defined event listeners on the ancestor of
  1922. * zr dom call `stopPropagation`.
  1923. * In these cases, the `mousemove` event might be keep triggered event
  1924. * if the mouse is released. We try to reduce the side-effect in those cases.
  1925. * That is, do nothing (especially, `findHover`) in those cases. See `isOutsideBoundary`.
  1926. *
  1927. * Note:
  1928. * If `HandlerProxy` listens to `document` with `useCapture`, `HandlerProxy` needs to
  1929. * make sure `stopPropagation` and `preventDefault` doing nothing if and only if the event
  1930. * target is not zrender dom. Becuase it is dangerous to enable users to call them in
  1931. * `document` capture phase to prevent the propagation to any listener of the webpage.
  1932. * But they are needed to work when the pointer inside the zrender dom.
  1933. */
  1934. var SILENT = 'silent';
  1935. function makeEventPacket(eveType, targetInfo, event) {
  1936. return {
  1937. type: eveType,
  1938. event: event,
  1939. // target can only be an element that is not silent.
  1940. target: targetInfo.target,
  1941. // topTarget can be a silent element.
  1942. topTarget: targetInfo.topTarget,
  1943. cancelBubble: false,
  1944. offsetX: event.zrX,
  1945. offsetY: event.zrY,
  1946. gestureEvent: event.gestureEvent,
  1947. pinchX: event.pinchX,
  1948. pinchY: event.pinchY,
  1949. pinchScale: event.pinchScale,
  1950. wheelDelta: event.zrDelta,
  1951. zrByTouch: event.zrByTouch,
  1952. which: event.which,
  1953. stop: stopEvent
  1954. };
  1955. }
  1956. function stopEvent() {
  1957. stop(this.event);
  1958. }
  1959. function EmptyProxy() {}
  1960. EmptyProxy.prototype.dispose = function () {};
  1961. var handlerNames = ['click', 'dblclick', 'mousewheel', 'mouseout', 'mouseup', 'mousedown', 'mousemove', 'contextmenu'];
  1962. /**
  1963. * @alias module:zrender/Handler
  1964. * @constructor
  1965. * @extends module:zrender/mixin/Eventful
  1966. * @param {module:zrender/Storage} storage Storage instance.
  1967. * @param {module:zrender/Painter} painter Painter instance.
  1968. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  1969. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  1970. */
  1971. var Handler = function (storage, painter, proxy, painterRoot) {
  1972. Eventful.call(this);
  1973. this.storage = storage;
  1974. this.painter = painter;
  1975. this.painterRoot = painterRoot;
  1976. proxy = proxy || new EmptyProxy();
  1977. /**
  1978. * Proxy of event. can be Dom, WebGLSurface, etc.
  1979. */
  1980. this.proxy = null;
  1981. /**
  1982. * {target, topTarget, x, y}
  1983. * @private
  1984. * @type {Object}
  1985. */
  1986. this._hovered = {};
  1987. /**
  1988. * @private
  1989. * @type {Date}
  1990. */
  1991. this._lastTouchMoment;
  1992. /**
  1993. * @private
  1994. * @type {number}
  1995. */
  1996. this._lastX;
  1997. /**
  1998. * @private
  1999. * @type {number}
  2000. */
  2001. this._lastY;
  2002. /**
  2003. * @private
  2004. * @type {module:zrender/core/GestureMgr}
  2005. */
  2006. this._gestureMgr;
  2007. Draggable.call(this);
  2008. this.setHandlerProxy(proxy);
  2009. };
  2010. Handler.prototype = {
  2011. constructor: Handler,
  2012. setHandlerProxy: function (proxy) {
  2013. if (this.proxy) {
  2014. this.proxy.dispose();
  2015. }
  2016. if (proxy) {
  2017. each$1(handlerNames, function (name) {
  2018. proxy.on && proxy.on(name, this[name], this);
  2019. }, this); // Attach handler
  2020. proxy.handler = this;
  2021. }
  2022. this.proxy = proxy;
  2023. },
  2024. mousemove: function (event) {
  2025. var x = event.zrX;
  2026. var y = event.zrY;
  2027. var isOutside = isOutsideBoundary(this, x, y);
  2028. var lastHovered = this._hovered;
  2029. var lastHoveredTarget = lastHovered.target; // If lastHoveredTarget is removed from zr (detected by '__zr') by some API call
  2030. // (like 'setOption' or 'dispatchAction') in event handlers, we should find
  2031. // lastHovered again here. Otherwise 'mouseout' can not be triggered normally.
  2032. // See #6198.
  2033. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  2034. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  2035. lastHoveredTarget = lastHovered.target;
  2036. }
  2037. var hovered = this._hovered = isOutside ? {
  2038. x: x,
  2039. y: y
  2040. } : this.findHover(x, y);
  2041. var hoveredTarget = hovered.target;
  2042. var proxy = this.proxy;
  2043. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default'); // Mouse out on previous hovered element
  2044. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2045. this.dispatchToElement(lastHovered, 'mouseout', event);
  2046. } // Mouse moving on one element
  2047. this.dispatchToElement(hovered, 'mousemove', event); // Mouse over on a new element
  2048. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2049. this.dispatchToElement(hovered, 'mouseover', event);
  2050. }
  2051. },
  2052. mouseout: function (event) {
  2053. var eventControl = event.zrEventControl;
  2054. var zrIsToLocalDOM = event.zrIsToLocalDOM;
  2055. if (eventControl !== 'only_globalout') {
  2056. this.dispatchToElement(this._hovered, 'mouseout', event);
  2057. }
  2058. if (eventControl !== 'no_globalout') {
  2059. // FIXME: if the pointer moving from the extra doms to realy "outside",
  2060. // the `globalout` should have been triggered. But currently not.
  2061. !zrIsToLocalDOM && this.trigger('globalout', {
  2062. type: 'globalout',
  2063. event: event
  2064. });
  2065. }
  2066. },
  2067. /**
  2068. * Resize
  2069. */
  2070. resize: function (event) {
  2071. this._hovered = {};
  2072. },
  2073. /**
  2074. * Dispatch event
  2075. * @param {string} eventName
  2076. * @param {event=} eventArgs
  2077. */
  2078. dispatch: function (eventName, eventArgs) {
  2079. var handler = this[eventName];
  2080. handler && handler.call(this, eventArgs);
  2081. },
  2082. /**
  2083. * Dispose
  2084. */
  2085. dispose: function () {
  2086. this.proxy.dispose();
  2087. this.storage = this.proxy = this.painter = null;
  2088. },
  2089. /**
  2090. * 设置默认的cursor style
  2091. * @param {string} [cursorStyle='default'] 例如 crosshair
  2092. */
  2093. setCursorStyle: function (cursorStyle) {
  2094. var proxy = this.proxy;
  2095. proxy.setCursor && proxy.setCursor(cursorStyle);
  2096. },
  2097. /**
  2098. * 事件分发代理
  2099. *
  2100. * @private
  2101. * @param {Object} targetInfo {target, topTarget} 目标图形元素
  2102. * @param {string} eventName 事件名称
  2103. * @param {Object} event 事件对象
  2104. */
  2105. dispatchToElement: function (targetInfo, eventName, event) {
  2106. targetInfo = targetInfo || {};
  2107. var el = targetInfo.target;
  2108. if (el && el.silent) {
  2109. return;
  2110. }
  2111. var eventHandler = 'on' + eventName;
  2112. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2113. while (el) {
  2114. el[eventHandler] && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  2115. el.trigger(eventName, eventPacket);
  2116. el = el.parent;
  2117. if (eventPacket.cancelBubble) {
  2118. break;
  2119. }
  2120. }
  2121. if (!eventPacket.cancelBubble) {
  2122. // 冒泡到顶级 zrender 对象
  2123. this.trigger(eventName, eventPacket); // 分发事件到用户自定义层
  2124. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  2125. this.painter && this.painter.eachOtherLayer(function (layer) {
  2126. if (typeof layer[eventHandler] === 'function') {
  2127. layer[eventHandler].call(layer, eventPacket);
  2128. }
  2129. if (layer.trigger) {
  2130. layer.trigger(eventName, eventPacket);
  2131. }
  2132. });
  2133. }
  2134. },
  2135. /**
  2136. * @private
  2137. * @param {number} x
  2138. * @param {number} y
  2139. * @param {module:zrender/graphic/Displayable} exclude
  2140. * @return {model:zrender/Element}
  2141. * @method
  2142. */
  2143. findHover: function (x, y, exclude) {
  2144. var list = this.storage.getDisplayList();
  2145. var out = {
  2146. x: x,
  2147. y: y
  2148. };
  2149. for (var i = list.length - 1; i >= 0; i--) {
  2150. var hoverCheckResult;
  2151. if (list[i] !== exclude // getDisplayList may include ignored item in VML mode
  2152. && !list[i].ignore && (hoverCheckResult = isHover(list[i], x, y))) {
  2153. !out.topTarget && (out.topTarget = list[i]);
  2154. if (hoverCheckResult !== SILENT) {
  2155. out.target = list[i];
  2156. break;
  2157. }
  2158. }
  2159. }
  2160. return out;
  2161. },
  2162. processGesture: function (event, stage) {
  2163. if (!this._gestureMgr) {
  2164. this._gestureMgr = new GestureMgr();
  2165. }
  2166. var gestureMgr = this._gestureMgr;
  2167. stage === 'start' && gestureMgr.clear();
  2168. var gestureInfo = gestureMgr.recognize(event, this.findHover(event.zrX, event.zrY, null).target, this.proxy.dom);
  2169. stage === 'end' && gestureMgr.clear(); // Do not do any preventDefault here. Upper application do that if necessary.
  2170. if (gestureInfo) {
  2171. var type = gestureInfo.type;
  2172. event.gestureEvent = type;
  2173. this.dispatchToElement({
  2174. target: gestureInfo.target
  2175. }, type, gestureInfo.event);
  2176. }
  2177. }
  2178. }; // Common handlers
  2179. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2180. Handler.prototype[name] = function (event) {
  2181. var x = event.zrX;
  2182. var y = event.zrY;
  2183. var isOutside = isOutsideBoundary(this, x, y);
  2184. var hovered;
  2185. var hoveredTarget;
  2186. if (name !== 'mouseup' || !isOutside) {
  2187. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  2188. hovered = this.findHover(x, y);
  2189. hoveredTarget = hovered.target;
  2190. }
  2191. if (name === 'mousedown') {
  2192. this._downEl = hoveredTarget;
  2193. this._downPoint = [event.zrX, event.zrY]; // In case click triggered before mouseup
  2194. this._upEl = hoveredTarget;
  2195. } else if (name === 'mouseup') {
  2196. this._upEl = hoveredTarget;
  2197. } else if (name === 'click') {
  2198. if (this._downEl !== this._upEl // Original click event is triggered on the whole canvas element,
  2199. // including the case that `mousedown` - `mousemove` - `mouseup`,
  2200. // which should be filtered, otherwise it will bring trouble to
  2201. // pan and zoom.
  2202. || !this._downPoint // Arbitrary value
  2203. || dist(this._downPoint, [event.zrX, event.zrY]) > 4) {
  2204. return;
  2205. }
  2206. this._downPoint = null;
  2207. }
  2208. this.dispatchToElement(hovered, name, event);
  2209. };
  2210. });
  2211. function isHover(displayable, x, y) {
  2212. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2213. var el = displayable;
  2214. var isSilent;
  2215. while (el) {
  2216. // If clipped by ancestor.
  2217. // FIXME: If clipPath has neither stroke nor fill,
  2218. // el.clipPath.contain(x, y) will always return false.
  2219. if (el.clipPath && !el.clipPath.contain(x, y)) {
  2220. return false;
  2221. }
  2222. if (el.silent) {
  2223. isSilent = true;
  2224. }
  2225. el = el.parent;
  2226. }
  2227. return isSilent ? SILENT : true;
  2228. }
  2229. return false;
  2230. }
  2231. /**
  2232. * See [Drag outside].
  2233. */
  2234. function isOutsideBoundary(handlerInstance, x, y) {
  2235. var painter = handlerInstance.painter;
  2236. return x < 0 || x > painter.getWidth() || y < 0 || y > painter.getHeight();
  2237. }
  2238. mixin(Handler, Eventful);
  2239. mixin(Handler, Draggable);
  2240. /**
  2241. * 3x2矩阵操作类
  2242. * @exports zrender/tool/matrix
  2243. */
  2244. /* global Float32Array */
  2245. var ArrayCtor$1 = typeof Float32Array === 'undefined' ? Array : Float32Array;
  2246. /**
  2247. * Create a identity matrix.
  2248. * @return {Float32Array|Array.<number>}
  2249. */
  2250. function create$1() {
  2251. var out = new ArrayCtor$1(6);
  2252. identity(out);
  2253. return out;
  2254. }
  2255. /**
  2256. * 设置矩阵为单位矩阵
  2257. * @param {Float32Array|Array.<number>} out
  2258. */
  2259. function identity(out) {
  2260. out[0] = 1;
  2261. out[1] = 0;
  2262. out[2] = 0;
  2263. out[3] = 1;
  2264. out[4] = 0;
  2265. out[5] = 0;
  2266. return out;
  2267. }
  2268. /**
  2269. * 复制矩阵
  2270. * @param {Float32Array|Array.<number>} out
  2271. * @param {Float32Array|Array.<number>} m
  2272. */
  2273. function copy$1(out, m) {
  2274. out[0] = m[0];
  2275. out[1] = m[1];
  2276. out[2] = m[2];
  2277. out[3] = m[3];
  2278. out[4] = m[4];
  2279. out[5] = m[5];
  2280. return out;
  2281. }
  2282. /**
  2283. * 矩阵相乘
  2284. * @param {Float32Array|Array.<number>} out
  2285. * @param {Float32Array|Array.<number>} m1
  2286. * @param {Float32Array|Array.<number>} m2
  2287. */
  2288. function mul$1(out, m1, m2) {
  2289. // Consider matrix.mul(m, m2, m);
  2290. // where out is the same as m2.
  2291. // So use temp variable to escape error.
  2292. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  2293. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  2294. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  2295. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  2296. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  2297. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  2298. out[0] = out0;
  2299. out[1] = out1;
  2300. out[2] = out2;
  2301. out[3] = out3;
  2302. out[4] = out4;
  2303. out[5] = out5;
  2304. return out;
  2305. }
  2306. /**
  2307. * 平移变换
  2308. * @param {Float32Array|Array.<number>} out
  2309. * @param {Float32Array|Array.<number>} a
  2310. * @param {Float32Array|Array.<number>} v
  2311. */
  2312. function translate(out, a, v) {
  2313. out[0] = a[0];
  2314. out[1] = a[1];
  2315. out[2] = a[2];
  2316. out[3] = a[3];
  2317. out[4] = a[4] + v[0];
  2318. out[5] = a[5] + v[1];
  2319. return out;
  2320. }
  2321. /**
  2322. * 旋转变换
  2323. * @param {Float32Array|Array.<number>} out
  2324. * @param {Float32Array|Array.<number>} a
  2325. * @param {number} rad
  2326. */
  2327. function rotate(out, a, rad) {
  2328. var aa = a[0];
  2329. var ac = a[2];
  2330. var atx = a[4];
  2331. var ab = a[1];
  2332. var ad = a[3];
  2333. var aty = a[5];
  2334. var st = Math.sin(rad);
  2335. var ct = Math.cos(rad);
  2336. out[0] = aa * ct + ab * st;
  2337. out[1] = -aa * st + ab * ct;
  2338. out[2] = ac * ct + ad * st;
  2339. out[3] = -ac * st + ct * ad;
  2340. out[4] = ct * atx + st * aty;
  2341. out[5] = ct * aty - st * atx;
  2342. return out;
  2343. }
  2344. /**
  2345. * 缩放变换
  2346. * @param {Float32Array|Array.<number>} out
  2347. * @param {Float32Array|Array.<number>} a
  2348. * @param {Float32Array|Array.<number>} v
  2349. */
  2350. function scale$1(out, a, v) {
  2351. var vx = v[0];
  2352. var vy = v[1];
  2353. out[0] = a[0] * vx;
  2354. out[1] = a[1] * vy;
  2355. out[2] = a[2] * vx;
  2356. out[3] = a[3] * vy;
  2357. out[4] = a[4] * vx;
  2358. out[5] = a[5] * vy;
  2359. return out;
  2360. }
  2361. /**
  2362. * 求逆矩阵
  2363. * @param {Float32Array|Array.<number>} out
  2364. * @param {Float32Array|Array.<number>} a
  2365. */
  2366. function invert(out, a) {
  2367. var aa = a[0];
  2368. var ac = a[2];
  2369. var atx = a[4];
  2370. var ab = a[1];
  2371. var ad = a[3];
  2372. var aty = a[5];
  2373. var det = aa * ad - ab * ac;
  2374. if (!det) {
  2375. return null;
  2376. }
  2377. det = 1.0 / det;
  2378. out[0] = ad * det;
  2379. out[1] = -ab * det;
  2380. out[2] = -ac * det;
  2381. out[3] = aa * det;
  2382. out[4] = (ac * aty - ad * atx) * det;
  2383. out[5] = (ab * atx - aa * aty) * det;
  2384. return out;
  2385. }
  2386. /**
  2387. * Clone a new matrix.
  2388. * @param {Float32Array|Array.<number>} a
  2389. */
  2390. function clone$2(a) {
  2391. var b = create$1();
  2392. copy$1(b, a);
  2393. return b;
  2394. }
  2395. var matrix = (Object.freeze || Object)({
  2396. create: create$1,
  2397. identity: identity,
  2398. copy: copy$1,
  2399. mul: mul$1,
  2400. translate: translate,
  2401. rotate: rotate,
  2402. scale: scale$1,
  2403. invert: invert,
  2404. clone: clone$2
  2405. });
  2406. /**
  2407. * 提供变换扩展
  2408. * @module zrender/mixin/Transformable
  2409. * @author pissang (https://www.github.com/pissang)
  2410. */
  2411. var mIdentity = identity;
  2412. var EPSILON = 5e-5;
  2413. function isNotAroundZero(val) {
  2414. return val > EPSILON || val < -EPSILON;
  2415. }
  2416. /**
  2417. * @alias module:zrender/mixin/Transformable
  2418. * @constructor
  2419. */
  2420. var Transformable = function (opts) {
  2421. opts = opts || {}; // If there are no given position, rotation, scale
  2422. if (!opts.position) {
  2423. /**
  2424. * 平移
  2425. * @type {Array.<number>}
  2426. * @default [0, 0]
  2427. */
  2428. this.position = [0, 0];
  2429. }
  2430. if (opts.rotation == null) {
  2431. /**
  2432. * 旋转
  2433. * @type {Array.<number>}
  2434. * @default 0
  2435. */
  2436. this.rotation = 0;
  2437. }
  2438. if (!opts.scale) {
  2439. /**
  2440. * 缩放
  2441. * @type {Array.<number>}
  2442. * @default [1, 1]
  2443. */
  2444. this.scale = [1, 1];
  2445. }
  2446. /**
  2447. * 旋转和缩放的原点
  2448. * @type {Array.<number>}
  2449. * @default null
  2450. */
  2451. this.origin = this.origin || null;
  2452. };
  2453. var transformableProto = Transformable.prototype;
  2454. transformableProto.transform = null;
  2455. /**
  2456. * 判断是否需要有坐标变换
  2457. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  2458. */
  2459. transformableProto.needLocalTransform = function () {
  2460. return isNotAroundZero(this.rotation) || isNotAroundZero(this.position[0]) || isNotAroundZero(this.position[1]) || isNotAroundZero(this.scale[0] - 1) || isNotAroundZero(this.scale[1] - 1);
  2461. };
  2462. var scaleTmp = [];
  2463. transformableProto.updateTransform = function () {
  2464. var parent = this.parent;
  2465. var parentHasTransform = parent && parent.transform;
  2466. var needLocalTransform = this.needLocalTransform();
  2467. var m = this.transform;
  2468. if (!(needLocalTransform || parentHasTransform)) {
  2469. m && mIdentity(m);
  2470. return;
  2471. }
  2472. m = m || create$1();
  2473. if (needLocalTransform) {
  2474. this.getLocalTransform(m);
  2475. } else {
  2476. mIdentity(m);
  2477. } // 应用父节点变换
  2478. if (parentHasTransform) {
  2479. if (needLocalTransform) {
  2480. mul$1(m, parent.transform, m);
  2481. } else {
  2482. copy$1(m, parent.transform);
  2483. }
  2484. } // 保存这个变换矩阵
  2485. this.transform = m;
  2486. var globalScaleRatio = this.globalScaleRatio;
  2487. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  2488. this.getGlobalScale(scaleTmp);
  2489. var relX = scaleTmp[0] < 0 ? -1 : 1;
  2490. var relY = scaleTmp[1] < 0 ? -1 : 1;
  2491. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  2492. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  2493. m[0] *= sx;
  2494. m[1] *= sx;
  2495. m[2] *= sy;
  2496. m[3] *= sy;
  2497. }
  2498. this.invTransform = this.invTransform || create$1();
  2499. invert(this.invTransform, m);
  2500. };
  2501. transformableProto.getLocalTransform = function (m) {
  2502. return Transformable.getLocalTransform(this, m);
  2503. };
  2504. /**
  2505. * 将自己的transform应用到context上
  2506. * @param {CanvasRenderingContext2D} ctx
  2507. */
  2508. transformableProto.setTransform = function (ctx) {
  2509. var m = this.transform;
  2510. var dpr = ctx.dpr || 1;
  2511. if (m) {
  2512. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  2513. } else {
  2514. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2515. }
  2516. };
  2517. transformableProto.restoreTransform = function (ctx) {
  2518. var dpr = ctx.dpr || 1;
  2519. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2520. };
  2521. var tmpTransform = [];
  2522. var originTransform = create$1();
  2523. transformableProto.setLocalTransform = function (m) {
  2524. if (!m) {
  2525. // TODO return or set identity?
  2526. return;
  2527. }
  2528. var sx = m[0] * m[0] + m[1] * m[1];
  2529. var sy = m[2] * m[2] + m[3] * m[3];
  2530. var position = this.position;
  2531. var scale$$1 = this.scale;
  2532. if (isNotAroundZero(sx - 1)) {
  2533. sx = Math.sqrt(sx);
  2534. }
  2535. if (isNotAroundZero(sy - 1)) {
  2536. sy = Math.sqrt(sy);
  2537. }
  2538. if (m[0] < 0) {
  2539. sx = -sx;
  2540. }
  2541. if (m[3] < 0) {
  2542. sy = -sy;
  2543. }
  2544. position[0] = m[4];
  2545. position[1] = m[5];
  2546. scale$$1[0] = sx;
  2547. scale$$1[1] = sy;
  2548. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  2549. };
  2550. /**
  2551. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  2552. */
  2553. transformableProto.decomposeTransform = function () {
  2554. if (!this.transform) {
  2555. return;
  2556. }
  2557. var parent = this.parent;
  2558. var m = this.transform;
  2559. if (parent && parent.transform) {
  2560. // Get local transform and decompose them to position, scale, rotation
  2561. mul$1(tmpTransform, parent.invTransform, m);
  2562. m = tmpTransform;
  2563. }
  2564. var origin = this.origin;
  2565. if (origin && (origin[0] || origin[1])) {
  2566. originTransform[4] = origin[0];
  2567. originTransform[5] = origin[1];
  2568. mul$1(tmpTransform, m, originTransform);
  2569. tmpTransform[4] -= origin[0];
  2570. tmpTransform[5] -= origin[1];
  2571. m = tmpTransform;
  2572. }
  2573. this.setLocalTransform(m);
  2574. };
  2575. /**
  2576. * Get global scale
  2577. * @return {Array.<number>}
  2578. */
  2579. transformableProto.getGlobalScale = function (out) {
  2580. var m = this.transform;
  2581. out = out || [];
  2582. if (!m) {
  2583. out[0] = 1;
  2584. out[1] = 1;
  2585. return out;
  2586. }
  2587. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  2588. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  2589. if (m[0] < 0) {
  2590. out[0] = -out[0];
  2591. }
  2592. if (m[3] < 0) {
  2593. out[1] = -out[1];
  2594. }
  2595. return out;
  2596. };
  2597. /**
  2598. * 变换坐标位置到 shape 的局部坐标空间
  2599. * @method
  2600. * @param {number} x
  2601. * @param {number} y
  2602. * @return {Array.<number>}
  2603. */
  2604. transformableProto.transformCoordToLocal = function (x, y) {
  2605. var v2 = [x, y];
  2606. var invTransform = this.invTransform;
  2607. if (invTransform) {
  2608. applyTransform(v2, v2, invTransform);
  2609. }
  2610. return v2;
  2611. };
  2612. /**
  2613. * 变换局部坐标位置到全局坐标空间
  2614. * @method
  2615. * @param {number} x
  2616. * @param {number} y
  2617. * @return {Array.<number>}
  2618. */
  2619. transformableProto.transformCoordToGlobal = function (x, y) {
  2620. var v2 = [x, y];
  2621. var transform = this.transform;
  2622. if (transform) {
  2623. applyTransform(v2, v2, transform);
  2624. }
  2625. return v2;
  2626. };
  2627. /**
  2628. * @static
  2629. * @param {Object} target
  2630. * @param {Array.<number>} target.origin
  2631. * @param {number} target.rotation
  2632. * @param {Array.<number>} target.position
  2633. * @param {Array.<number>} [m]
  2634. */
  2635. Transformable.getLocalTransform = function (target, m) {
  2636. m = m || [];
  2637. mIdentity(m);
  2638. var origin = target.origin;
  2639. var scale$$1 = target.scale || [1, 1];
  2640. var rotation = target.rotation || 0;
  2641. var position = target.position || [0, 0];
  2642. if (origin) {
  2643. // Translate to origin
  2644. m[4] -= origin[0];
  2645. m[5] -= origin[1];
  2646. }
  2647. scale$1(m, m, scale$$1);
  2648. if (rotation) {
  2649. rotate(m, m, rotation);
  2650. }
  2651. if (origin) {
  2652. // Translate back from origin
  2653. m[4] += origin[0];
  2654. m[5] += origin[1];
  2655. }
  2656. m[4] += position[0];
  2657. m[5] += position[1];
  2658. return m;
  2659. };
  2660. /**
  2661. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  2662. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  2663. * @exports zrender/animation/easing
  2664. */
  2665. var easing = {
  2666. /**
  2667. * @param {number} k
  2668. * @return {number}
  2669. */
  2670. linear: function (k) {
  2671. return k;
  2672. },
  2673. /**
  2674. * @param {number} k
  2675. * @return {number}
  2676. */
  2677. quadraticIn: function (k) {
  2678. return k * k;
  2679. },
  2680. /**
  2681. * @param {number} k
  2682. * @return {number}
  2683. */
  2684. quadraticOut: function (k) {
  2685. return k * (2 - k);
  2686. },
  2687. /**
  2688. * @param {number} k
  2689. * @return {number}
  2690. */
  2691. quadraticInOut: function (k) {
  2692. if ((k *= 2) < 1) {
  2693. return 0.5 * k * k;
  2694. }
  2695. return -0.5 * (--k * (k - 2) - 1);
  2696. },
  2697. // 三次方的缓动(t^3)
  2698. /**
  2699. * @param {number} k
  2700. * @return {number}
  2701. */
  2702. cubicIn: function (k) {
  2703. return k * k * k;
  2704. },
  2705. /**
  2706. * @param {number} k
  2707. * @return {number}
  2708. */
  2709. cubicOut: function (k) {
  2710. return --k * k * k + 1;
  2711. },
  2712. /**
  2713. * @param {number} k
  2714. * @return {number}
  2715. */
  2716. cubicInOut: function (k) {
  2717. if ((k *= 2) < 1) {
  2718. return 0.5 * k * k * k;
  2719. }
  2720. return 0.5 * ((k -= 2) * k * k + 2);
  2721. },
  2722. // 四次方的缓动(t^4)
  2723. /**
  2724. * @param {number} k
  2725. * @return {number}
  2726. */
  2727. quarticIn: function (k) {
  2728. return k * k * k * k;
  2729. },
  2730. /**
  2731. * @param {number} k
  2732. * @return {number}
  2733. */
  2734. quarticOut: function (k) {
  2735. return 1 - --k * k * k * k;
  2736. },
  2737. /**
  2738. * @param {number} k
  2739. * @return {number}
  2740. */
  2741. quarticInOut: function (k) {
  2742. if ((k *= 2) < 1) {
  2743. return 0.5 * k * k * k * k;
  2744. }
  2745. return -0.5 * ((k -= 2) * k * k * k - 2);
  2746. },
  2747. // 五次方的缓动(t^5)
  2748. /**
  2749. * @param {number} k
  2750. * @return {number}
  2751. */
  2752. quinticIn: function (k) {
  2753. return k * k * k * k * k;
  2754. },
  2755. /**
  2756. * @param {number} k
  2757. * @return {number}
  2758. */
  2759. quinticOut: function (k) {
  2760. return --k * k * k * k * k + 1;
  2761. },
  2762. /**
  2763. * @param {number} k
  2764. * @return {number}
  2765. */
  2766. quinticInOut: function (k) {
  2767. if ((k *= 2) < 1) {
  2768. return 0.5 * k * k * k * k * k;
  2769. }
  2770. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2771. },
  2772. // 正弦曲线的缓动(sin(t))
  2773. /**
  2774. * @param {number} k
  2775. * @return {number}
  2776. */
  2777. sinusoidalIn: function (k) {
  2778. return 1 - Math.cos(k * Math.PI / 2);
  2779. },
  2780. /**
  2781. * @param {number} k
  2782. * @return {number}
  2783. */
  2784. sinusoidalOut: function (k) {
  2785. return Math.sin(k * Math.PI / 2);
  2786. },
  2787. /**
  2788. * @param {number} k
  2789. * @return {number}
  2790. */
  2791. sinusoidalInOut: function (k) {
  2792. return 0.5 * (1 - Math.cos(Math.PI * k));
  2793. },
  2794. // 指数曲线的缓动(2^t)
  2795. /**
  2796. * @param {number} k
  2797. * @return {number}
  2798. */
  2799. exponentialIn: function (k) {
  2800. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2801. },
  2802. /**
  2803. * @param {number} k
  2804. * @return {number}
  2805. */
  2806. exponentialOut: function (k) {
  2807. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2808. },
  2809. /**
  2810. * @param {number} k
  2811. * @return {number}
  2812. */
  2813. exponentialInOut: function (k) {
  2814. if (k === 0) {
  2815. return 0;
  2816. }
  2817. if (k === 1) {
  2818. return 1;
  2819. }
  2820. if ((k *= 2) < 1) {
  2821. return 0.5 * Math.pow(1024, k - 1);
  2822. }
  2823. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2824. },
  2825. // 圆形曲线的缓动(sqrt(1-t^2))
  2826. /**
  2827. * @param {number} k
  2828. * @return {number}
  2829. */
  2830. circularIn: function (k) {
  2831. return 1 - Math.sqrt(1 - k * k);
  2832. },
  2833. /**
  2834. * @param {number} k
  2835. * @return {number}
  2836. */
  2837. circularOut: function (k) {
  2838. return Math.sqrt(1 - --k * k);
  2839. },
  2840. /**
  2841. * @param {number} k
  2842. * @return {number}
  2843. */
  2844. circularInOut: function (k) {
  2845. if ((k *= 2) < 1) {
  2846. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2847. }
  2848. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2849. },
  2850. // 创建类似于弹簧在停止前来回振荡的动画
  2851. /**
  2852. * @param {number} k
  2853. * @return {number}
  2854. */
  2855. elasticIn: function (k) {
  2856. var s;
  2857. var a = 0.1;
  2858. var p = 0.4;
  2859. if (k === 0) {
  2860. return 0;
  2861. }
  2862. if (k === 1) {
  2863. return 1;
  2864. }
  2865. if (!a || a < 1) {
  2866. a = 1;
  2867. s = p / 4;
  2868. } else {
  2869. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2870. }
  2871. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  2872. },
  2873. /**
  2874. * @param {number} k
  2875. * @return {number}
  2876. */
  2877. elasticOut: function (k) {
  2878. var s;
  2879. var a = 0.1;
  2880. var p = 0.4;
  2881. if (k === 0) {
  2882. return 0;
  2883. }
  2884. if (k === 1) {
  2885. return 1;
  2886. }
  2887. if (!a || a < 1) {
  2888. a = 1;
  2889. s = p / 4;
  2890. } else {
  2891. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2892. }
  2893. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  2894. },
  2895. /**
  2896. * @param {number} k
  2897. * @return {number}
  2898. */
  2899. elasticInOut: function (k) {
  2900. var s;
  2901. var a = 0.1;
  2902. var p = 0.4;
  2903. if (k === 0) {
  2904. return 0;
  2905. }
  2906. if (k === 1) {
  2907. return 1;
  2908. }
  2909. if (!a || a < 1) {
  2910. a = 1;
  2911. s = p / 4;
  2912. } else {
  2913. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2914. }
  2915. if ((k *= 2) < 1) {
  2916. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  2917. }
  2918. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  2919. },
  2920. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  2921. /**
  2922. * @param {number} k
  2923. * @return {number}
  2924. */
  2925. backIn: function (k) {
  2926. var s = 1.70158;
  2927. return k * k * ((s + 1) * k - s);
  2928. },
  2929. /**
  2930. * @param {number} k
  2931. * @return {number}
  2932. */
  2933. backOut: function (k) {
  2934. var s = 1.70158;
  2935. return --k * k * ((s + 1) * k + s) + 1;
  2936. },
  2937. /**
  2938. * @param {number} k
  2939. * @return {number}
  2940. */
  2941. backInOut: function (k) {
  2942. var s = 1.70158 * 1.525;
  2943. if ((k *= 2) < 1) {
  2944. return 0.5 * (k * k * ((s + 1) * k - s));
  2945. }
  2946. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2947. },
  2948. // 创建弹跳效果
  2949. /**
  2950. * @param {number} k
  2951. * @return {number}
  2952. */
  2953. bounceIn: function (k) {
  2954. return 1 - easing.bounceOut(1 - k);
  2955. },
  2956. /**
  2957. * @param {number} k
  2958. * @return {number}
  2959. */
  2960. bounceOut: function (k) {
  2961. if (k < 1 / 2.75) {
  2962. return 7.5625 * k * k;
  2963. } else if (k < 2 / 2.75) {
  2964. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  2965. } else if (k < 2.5 / 2.75) {
  2966. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  2967. } else {
  2968. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  2969. }
  2970. },
  2971. /**
  2972. * @param {number} k
  2973. * @return {number}
  2974. */
  2975. bounceInOut: function (k) {
  2976. if (k < 0.5) {
  2977. return easing.bounceIn(k * 2) * 0.5;
  2978. }
  2979. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  2980. }
  2981. };
  2982. /**
  2983. * 动画主控制器
  2984. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  2985. * @config life(1000) 动画时长
  2986. * @config delay(0) 动画延迟时间
  2987. * @config loop(true)
  2988. * @config gap(0) 循环的间隔时间
  2989. * @config onframe
  2990. * @config easing(optional)
  2991. * @config ondestroy(optional)
  2992. * @config onrestart(optional)
  2993. *
  2994. * TODO pause
  2995. */
  2996. function Clip(options) {
  2997. this._target = options.target; // 生命周期
  2998. this._life = options.life || 1000; // 延时
  2999. this._delay = options.delay || 0; // 开始时间
  3000. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  3001. this._initialized = false; // 是否循环
  3002. this.loop = options.loop == null ? false : options.loop;
  3003. this.gap = options.gap || 0;
  3004. this.easing = options.easing || 'Linear';
  3005. this.onframe = options.onframe;
  3006. this.ondestroy = options.ondestroy;
  3007. this.onrestart = options.onrestart;
  3008. this._pausedTime = 0;
  3009. this._paused = false;
  3010. }
  3011. Clip.prototype = {
  3012. constructor: Clip,
  3013. step: function (globalTime, deltaTime) {
  3014. // Set startTime on first step, or _startTime may has milleseconds different between clips
  3015. // PENDING
  3016. if (!this._initialized) {
  3017. this._startTime = globalTime + this._delay;
  3018. this._initialized = true;
  3019. }
  3020. if (this._paused) {
  3021. this._pausedTime += deltaTime;
  3022. return;
  3023. }
  3024. var percent = (globalTime - this._startTime - this._pausedTime) / this._life; // 还没开始
  3025. if (percent < 0) {
  3026. return;
  3027. }
  3028. percent = Math.min(percent, 1);
  3029. var easing$$1 = this.easing;
  3030. var easingFunc = typeof easing$$1 === 'string' ? easing[easing$$1] : easing$$1;
  3031. var schedule = typeof easingFunc === 'function' ? easingFunc(percent) : percent;
  3032. this.fire('frame', schedule); // 结束
  3033. if (percent === 1) {
  3034. if (this.loop) {
  3035. this.restart(globalTime); // 重新开始周期
  3036. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  3037. return 'restart';
  3038. } // 动画完成将这个控制器标识为待删除
  3039. // 在Animation.update中进行批量删除
  3040. this._needsRemove = true;
  3041. return 'destroy';
  3042. }
  3043. return null;
  3044. },
  3045. restart: function (globalTime) {
  3046. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  3047. this._startTime = globalTime - remainder + this.gap;
  3048. this._pausedTime = 0;
  3049. this._needsRemove = false;
  3050. },
  3051. fire: function (eventType, arg) {
  3052. eventType = 'on' + eventType;
  3053. if (this[eventType]) {
  3054. this[eventType](this._target, arg);
  3055. }
  3056. },
  3057. pause: function () {
  3058. this._paused = true;
  3059. },
  3060. resume: function () {
  3061. this._paused = false;
  3062. }
  3063. };
  3064. // Simple LRU cache use doubly linked list
  3065. // @module zrender/core/LRU
  3066. /**
  3067. * Simple double linked list. Compared with array, it has O(1) remove operation.
  3068. * @constructor
  3069. */
  3070. var LinkedList = function () {
  3071. /**
  3072. * @type {module:zrender/core/LRU~Entry}
  3073. */
  3074. this.head = null;
  3075. /**
  3076. * @type {module:zrender/core/LRU~Entry}
  3077. */
  3078. this.tail = null;
  3079. this._len = 0;
  3080. };
  3081. var linkedListProto = LinkedList.prototype;
  3082. /**
  3083. * Insert a new value at the tail
  3084. * @param {} val
  3085. * @return {module:zrender/core/LRU~Entry}
  3086. */
  3087. linkedListProto.insert = function (val) {
  3088. var entry = new Entry(val);
  3089. this.insertEntry(entry);
  3090. return entry;
  3091. };
  3092. /**
  3093. * Insert an entry at the tail
  3094. * @param {module:zrender/core/LRU~Entry} entry
  3095. */
  3096. linkedListProto.insertEntry = function (entry) {
  3097. if (!this.head) {
  3098. this.head = this.tail = entry;
  3099. } else {
  3100. this.tail.next = entry;
  3101. entry.prev = this.tail;
  3102. entry.next = null;
  3103. this.tail = entry;
  3104. }
  3105. this._len++;
  3106. };
  3107. /**
  3108. * Remove entry.
  3109. * @param {module:zrender/core/LRU~Entry} entry
  3110. */
  3111. linkedListProto.remove = function (entry) {
  3112. var prev = entry.prev;
  3113. var next = entry.next;
  3114. if (prev) {
  3115. prev.next = next;
  3116. } else {
  3117. // Is head
  3118. this.head = next;
  3119. }
  3120. if (next) {
  3121. next.prev = prev;
  3122. } else {
  3123. // Is tail
  3124. this.tail = prev;
  3125. }
  3126. entry.next = entry.prev = null;
  3127. this._len--;
  3128. };
  3129. /**
  3130. * @return {number}
  3131. */
  3132. linkedListProto.len = function () {
  3133. return this._len;
  3134. };
  3135. /**
  3136. * Clear list
  3137. */
  3138. linkedListProto.clear = function () {
  3139. this.head = this.tail = null;
  3140. this._len = 0;
  3141. };
  3142. /**
  3143. * @constructor
  3144. * @param {} val
  3145. */
  3146. var Entry = function (val) {
  3147. /**
  3148. * @type {}
  3149. */
  3150. this.value = val;
  3151. /**
  3152. * @type {module:zrender/core/LRU~Entry}
  3153. */
  3154. this.next;
  3155. /**
  3156. * @type {module:zrender/core/LRU~Entry}
  3157. */
  3158. this.prev;
  3159. };
  3160. /**
  3161. * LRU Cache
  3162. * @constructor
  3163. * @alias module:zrender/core/LRU
  3164. */
  3165. var LRU = function (maxSize) {
  3166. this._list = new LinkedList();
  3167. this._map = {};
  3168. this._maxSize = maxSize || 10;
  3169. this._lastRemovedEntry = null;
  3170. };
  3171. var LRUProto = LRU.prototype;
  3172. /**
  3173. * @param {string} key
  3174. * @param {} value
  3175. * @return {} Removed value
  3176. */
  3177. LRUProto.put = function (key, value) {
  3178. var list = this._list;
  3179. var map = this._map;
  3180. var removed = null;
  3181. if (map[key] == null) {
  3182. var len = list.len(); // Reuse last removed entry
  3183. var entry = this._lastRemovedEntry;
  3184. if (len >= this._maxSize && len > 0) {
  3185. // Remove the least recently used
  3186. var leastUsedEntry = list.head;
  3187. list.remove(leastUsedEntry);
  3188. delete map[leastUsedEntry.key];
  3189. removed = leastUsedEntry.value;
  3190. this._lastRemovedEntry = leastUsedEntry;
  3191. }
  3192. if (entry) {
  3193. entry.value = value;
  3194. } else {
  3195. entry = new Entry(value);
  3196. }
  3197. entry.key = key;
  3198. list.insertEntry(entry);
  3199. map[key] = entry;
  3200. }
  3201. return removed;
  3202. };
  3203. /**
  3204. * @param {string} key
  3205. * @return {}
  3206. */
  3207. LRUProto.get = function (key) {
  3208. var entry = this._map[key];
  3209. var list = this._list;
  3210. if (entry != null) {
  3211. // Put the latest used entry in the tail
  3212. if (entry !== list.tail) {
  3213. list.remove(entry);
  3214. list.insertEntry(entry);
  3215. }
  3216. return entry.value;
  3217. }
  3218. };
  3219. /**
  3220. * Clear the cache
  3221. */
  3222. LRUProto.clear = function () {
  3223. this._list.clear();
  3224. this._map = {};
  3225. };
  3226. var kCSSColorTable = {
  3227. 'transparent': [0, 0, 0, 0],
  3228. 'aliceblue': [240, 248, 255, 1],
  3229. 'antiquewhite': [250, 235, 215, 1],
  3230. 'aqua': [0, 255, 255, 1],
  3231. 'aquamarine': [127, 255, 212, 1],
  3232. 'azure': [240, 255, 255, 1],
  3233. 'beige': [245, 245, 220, 1],
  3234. 'bisque': [255, 228, 196, 1],
  3235. 'black': [0, 0, 0, 1],
  3236. 'blanchedalmond': [255, 235, 205, 1],
  3237. 'blue': [0, 0, 255, 1],
  3238. 'blueviolet': [138, 43, 226, 1],
  3239. 'brown': [165, 42, 42, 1],
  3240. 'burlywood': [222, 184, 135, 1],
  3241. 'cadetblue': [95, 158, 160, 1],
  3242. 'chartreuse': [127, 255, 0, 1],
  3243. 'chocolate': [210, 105, 30, 1],
  3244. 'coral': [255, 127, 80, 1],
  3245. 'cornflowerblue': [100, 149, 237, 1],
  3246. 'cornsilk': [255, 248, 220, 1],
  3247. 'crimson': [220, 20, 60, 1],
  3248. 'cyan': [0, 255, 255, 1],
  3249. 'darkblue': [0, 0, 139, 1],
  3250. 'darkcyan': [0, 139, 139, 1],
  3251. 'darkgoldenrod': [184, 134, 11, 1],
  3252. 'darkgray': [169, 169, 169, 1],
  3253. 'darkgreen': [0, 100, 0, 1],
  3254. 'darkgrey': [169, 169, 169, 1],
  3255. 'darkkhaki': [189, 183, 107, 1],
  3256. 'darkmagenta': [139, 0, 139, 1],
  3257. 'darkolivegreen': [85, 107, 47, 1],
  3258. 'darkorange': [255, 140, 0, 1],
  3259. 'darkorchid': [153, 50, 204, 1],
  3260. 'darkred': [139, 0, 0, 1],
  3261. 'darksalmon': [233, 150, 122, 1],
  3262. 'darkseagreen': [143, 188, 143, 1],
  3263. 'darkslateblue': [72, 61, 139, 1],
  3264. 'darkslategray': [47, 79, 79, 1],
  3265. 'darkslategrey': [47, 79, 79, 1],
  3266. 'darkturquoise': [0, 206, 209, 1],
  3267. 'darkviolet': [148, 0, 211, 1],
  3268. 'deeppink': [255, 20, 147, 1],
  3269. 'deepskyblue': [0, 191, 255, 1],
  3270. 'dimgray': [105, 105, 105, 1],
  3271. 'dimgrey': [105, 105, 105, 1],
  3272. 'dodgerblue': [30, 144, 255, 1],
  3273. 'firebrick': [178, 34, 34, 1],
  3274. 'floralwhite': [255, 250, 240, 1],
  3275. 'forestgreen': [34, 139, 34, 1],
  3276. 'fuchsia': [255, 0, 255, 1],
  3277. 'gainsboro': [220, 220, 220, 1],
  3278. 'ghostwhite': [248, 248, 255, 1],
  3279. 'gold': [255, 215, 0, 1],
  3280. 'goldenrod': [218, 165, 32, 1],
  3281. 'gray': [128, 128, 128, 1],
  3282. 'green': [0, 128, 0, 1],
  3283. 'greenyellow': [173, 255, 47, 1],
  3284. 'grey': [128, 128, 128, 1],
  3285. 'honeydew': [240, 255, 240, 1],
  3286. 'hotpink': [255, 105, 180, 1],
  3287. 'indianred': [205, 92, 92, 1],
  3288. 'indigo': [75, 0, 130, 1],
  3289. 'ivory': [255, 255, 240, 1],
  3290. 'khaki': [240, 230, 140, 1],
  3291. 'lavender': [230, 230, 250, 1],
  3292. 'lavenderblush': [255, 240, 245, 1],
  3293. 'lawngreen': [124, 252, 0, 1],
  3294. 'lemonchiffon': [255, 250, 205, 1],
  3295. 'lightblue': [173, 216, 230, 1],
  3296. 'lightcoral': [240, 128, 128, 1],
  3297. 'lightcyan': [224, 255, 255, 1],
  3298. 'lightgoldenrodyellow': [250, 250, 210, 1],
  3299. 'lightgray': [211, 211, 211, 1],
  3300. 'lightgreen': [144, 238, 144, 1],
  3301. 'lightgrey': [211, 211, 211, 1],
  3302. 'lightpink': [255, 182, 193, 1],
  3303. 'lightsalmon': [255, 160, 122, 1],
  3304. 'lightseagreen': [32, 178, 170, 1],
  3305. 'lightskyblue': [135, 206, 250, 1],
  3306. 'lightslategray': [119, 136, 153, 1],
  3307. 'lightslategrey': [119, 136, 153, 1],
  3308. 'lightsteelblue': [176, 196, 222, 1],
  3309. 'lightyellow': [255, 255, 224, 1],
  3310. 'lime': [0, 255, 0, 1],
  3311. 'limegreen': [50, 205, 50, 1],
  3312. 'linen': [250, 240, 230, 1],
  3313. 'magenta': [255, 0, 255, 1],
  3314. 'maroon': [128, 0, 0, 1],
  3315. 'mediumaquamarine': [102, 205, 170, 1],
  3316. 'mediumblue': [0, 0, 205, 1],
  3317. 'mediumorchid': [186, 85, 211, 1],
  3318. 'mediumpurple': [147, 112, 219, 1],
  3319. 'mediumseagreen': [60, 179, 113, 1],
  3320. 'mediumslateblue': [123, 104, 238, 1],
  3321. 'mediumspringgreen': [0, 250, 154, 1],
  3322. 'mediumturquoise': [72, 209, 204, 1],
  3323. 'mediumvioletred': [199, 21, 133, 1],
  3324. 'midnightblue': [25, 25, 112, 1],
  3325. 'mintcream': [245, 255, 250, 1],
  3326. 'mistyrose': [255, 228, 225, 1],
  3327. 'moccasin': [255, 228, 181, 1],
  3328. 'navajowhite': [255, 222, 173, 1],
  3329. 'navy': [0, 0, 128, 1],
  3330. 'oldlace': [253, 245, 230, 1],
  3331. 'olive': [128, 128, 0, 1],
  3332. 'olivedrab': [107, 142, 35, 1],
  3333. 'orange': [255, 165, 0, 1],
  3334. 'orangered': [255, 69, 0, 1],
  3335. 'orchid': [218, 112, 214, 1],
  3336. 'palegoldenrod': [238, 232, 170, 1],
  3337. 'palegreen': [152, 251, 152, 1],
  3338. 'paleturquoise': [175, 238, 238, 1],
  3339. 'palevioletred': [219, 112, 147, 1],
  3340. 'papayawhip': [255, 239, 213, 1],
  3341. 'peachpuff': [255, 218, 185, 1],
  3342. 'peru': [205, 133, 63, 1],
  3343. 'pink': [255, 192, 203, 1],
  3344. 'plum': [221, 160, 221, 1],
  3345. 'powderblue': [176, 224, 230, 1],
  3346. 'purple': [128, 0, 128, 1],
  3347. 'red': [255, 0, 0, 1],
  3348. 'rosybrown': [188, 143, 143, 1],
  3349. 'royalblue': [65, 105, 225, 1],
  3350. 'saddlebrown': [139, 69, 19, 1],
  3351. 'salmon': [250, 128, 114, 1],
  3352. 'sandybrown': [244, 164, 96, 1],
  3353. 'seagreen': [46, 139, 87, 1],
  3354. 'seashell': [255, 245, 238, 1],
  3355. 'sienna': [160, 82, 45, 1],
  3356. 'silver': [192, 192, 192, 1],
  3357. 'skyblue': [135, 206, 235, 1],
  3358. 'slateblue': [106, 90, 205, 1],
  3359. 'slategray': [112, 128, 144, 1],
  3360. 'slategrey': [112, 128, 144, 1],
  3361. 'snow': [255, 250, 250, 1],
  3362. 'springgreen': [0, 255, 127, 1],
  3363. 'steelblue': [70, 130, 180, 1],
  3364. 'tan': [210, 180, 140, 1],
  3365. 'teal': [0, 128, 128, 1],
  3366. 'thistle': [216, 191, 216, 1],
  3367. 'tomato': [255, 99, 71, 1],
  3368. 'turquoise': [64, 224, 208, 1],
  3369. 'violet': [238, 130, 238, 1],
  3370. 'wheat': [245, 222, 179, 1],
  3371. 'white': [255, 255, 255, 1],
  3372. 'whitesmoke': [245, 245, 245, 1],
  3373. 'yellow': [255, 255, 0, 1],
  3374. 'yellowgreen': [154, 205, 50, 1]
  3375. };
  3376. function clampCssByte(i) {
  3377. // Clamp to integer 0 .. 255.
  3378. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3379. return i < 0 ? 0 : i > 255 ? 255 : i;
  3380. }
  3381. function clampCssAngle(i) {
  3382. // Clamp to integer 0 .. 360.
  3383. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3384. return i < 0 ? 0 : i > 360 ? 360 : i;
  3385. }
  3386. function clampCssFloat(f) {
  3387. // Clamp to float 0.0 .. 1.0.
  3388. return f < 0 ? 0 : f > 1 ? 1 : f;
  3389. }
  3390. function parseCssInt(str) {
  3391. // int or percentage.
  3392. if (str.length && str.charAt(str.length - 1) === '%') {
  3393. return clampCssByte(parseFloat(str) / 100 * 255);
  3394. }
  3395. return clampCssByte(parseInt(str, 10));
  3396. }
  3397. function parseCssFloat(str) {
  3398. // float or percentage.
  3399. if (str.length && str.charAt(str.length - 1) === '%') {
  3400. return clampCssFloat(parseFloat(str) / 100);
  3401. }
  3402. return clampCssFloat(parseFloat(str));
  3403. }
  3404. function cssHueToRgb(m1, m2, h) {
  3405. if (h < 0) {
  3406. h += 1;
  3407. } else if (h > 1) {
  3408. h -= 1;
  3409. }
  3410. if (h * 6 < 1) {
  3411. return m1 + (m2 - m1) * h * 6;
  3412. }
  3413. if (h * 2 < 1) {
  3414. return m2;
  3415. }
  3416. if (h * 3 < 2) {
  3417. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3418. }
  3419. return m1;
  3420. }
  3421. function lerpNumber(a, b, p) {
  3422. return a + (b - a) * p;
  3423. }
  3424. function setRgba(out, r, g, b, a) {
  3425. out[0] = r;
  3426. out[1] = g;
  3427. out[2] = b;
  3428. out[3] = a;
  3429. return out;
  3430. }
  3431. function copyRgba(out, a) {
  3432. out[0] = a[0];
  3433. out[1] = a[1];
  3434. out[2] = a[2];
  3435. out[3] = a[3];
  3436. return out;
  3437. }
  3438. var colorCache = new LRU(20);
  3439. var lastRemovedArr = null;
  3440. function putToCache(colorStr, rgbaArr) {
  3441. // Reuse removed array
  3442. if (lastRemovedArr) {
  3443. copyRgba(lastRemovedArr, rgbaArr);
  3444. }
  3445. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || rgbaArr.slice());
  3446. }
  3447. /**
  3448. * @param {string} colorStr
  3449. * @param {Array.<number>} out
  3450. * @return {Array.<number>}
  3451. * @memberOf module:zrender/util/color
  3452. */
  3453. function parse(colorStr, rgbaArr) {
  3454. if (!colorStr) {
  3455. return;
  3456. }
  3457. rgbaArr = rgbaArr || [];
  3458. var cached = colorCache.get(colorStr);
  3459. if (cached) {
  3460. return copyRgba(rgbaArr, cached);
  3461. } // colorStr may be not string
  3462. colorStr = colorStr + ''; // Remove all whitespace, not compliant, but should just be more accepting.
  3463. var str = colorStr.replace(/ /g, '').toLowerCase(); // Color keywords (and transparent) lookup.
  3464. if (str in kCSSColorTable) {
  3465. copyRgba(rgbaArr, kCSSColorTable[str]);
  3466. putToCache(colorStr, rgbaArr);
  3467. return rgbaArr;
  3468. } // #abc and #abc123 syntax.
  3469. if (str.charAt(0) === '#') {
  3470. if (str.length === 4) {
  3471. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3472. if (!(iv >= 0 && iv <= 0xfff)) {
  3473. setRgba(rgbaArr, 0, 0, 0, 1);
  3474. return; // Covers NaN.
  3475. }
  3476. setRgba(rgbaArr, (iv & 0xf00) >> 4 | (iv & 0xf00) >> 8, iv & 0xf0 | (iv & 0xf0) >> 4, iv & 0xf | (iv & 0xf) << 4, 1);
  3477. putToCache(colorStr, rgbaArr);
  3478. return rgbaArr;
  3479. } else if (str.length === 7) {
  3480. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3481. if (!(iv >= 0 && iv <= 0xffffff)) {
  3482. setRgba(rgbaArr, 0, 0, 0, 1);
  3483. return; // Covers NaN.
  3484. }
  3485. setRgba(rgbaArr, (iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, 1);
  3486. putToCache(colorStr, rgbaArr);
  3487. return rgbaArr;
  3488. }
  3489. return;
  3490. }
  3491. var op = str.indexOf('(');
  3492. var ep = str.indexOf(')');
  3493. if (op !== -1 && ep + 1 === str.length) {
  3494. var fname = str.substr(0, op);
  3495. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3496. var alpha = 1; // To allow case fallthrough.
  3497. switch (fname) {
  3498. case 'rgba':
  3499. if (params.length !== 4) {
  3500. setRgba(rgbaArr, 0, 0, 0, 1);
  3501. return;
  3502. }
  3503. alpha = parseCssFloat(params.pop());
  3504. // jshint ignore:line
  3505. // Fall through.
  3506. case 'rgb':
  3507. if (params.length !== 3) {
  3508. setRgba(rgbaArr, 0, 0, 0, 1);
  3509. return;
  3510. }
  3511. setRgba(rgbaArr, parseCssInt(params[0]), parseCssInt(params[1]), parseCssInt(params[2]), alpha);
  3512. putToCache(colorStr, rgbaArr);
  3513. return rgbaArr;
  3514. case 'hsla':
  3515. if (params.length !== 4) {
  3516. setRgba(rgbaArr, 0, 0, 0, 1);
  3517. return;
  3518. }
  3519. params[3] = parseCssFloat(params[3]);
  3520. hsla2rgba(params, rgbaArr);
  3521. putToCache(colorStr, rgbaArr);
  3522. return rgbaArr;
  3523. case 'hsl':
  3524. if (params.length !== 3) {
  3525. setRgba(rgbaArr, 0, 0, 0, 1);
  3526. return;
  3527. }
  3528. hsla2rgba(params, rgbaArr);
  3529. putToCache(colorStr, rgbaArr);
  3530. return rgbaArr;
  3531. default:
  3532. return;
  3533. }
  3534. }
  3535. setRgba(rgbaArr, 0, 0, 0, 1);
  3536. return;
  3537. }
  3538. /**
  3539. * @param {Array.<number>} hsla
  3540. * @param {Array.<number>} rgba
  3541. * @return {Array.<number>} rgba
  3542. */
  3543. function hsla2rgba(hsla, rgba) {
  3544. var h = (parseFloat(hsla[0]) % 360 + 360) % 360 / 360; // 0 .. 1
  3545. // NOTE(deanm): According to the CSS spec s/l should only be
  3546. // percentages, but we don't bother and let float or percentage.
  3547. var s = parseCssFloat(hsla[1]);
  3548. var l = parseCssFloat(hsla[2]);
  3549. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3550. var m1 = l * 2 - m2;
  3551. rgba = rgba || [];
  3552. 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);
  3553. if (hsla.length === 4) {
  3554. rgba[3] = hsla[3];
  3555. }
  3556. return rgba;
  3557. }
  3558. /**
  3559. * @param {Array.<number>} rgba
  3560. * @return {Array.<number>} hsla
  3561. */
  3562. function rgba2hsla(rgba) {
  3563. if (!rgba) {
  3564. return;
  3565. } // RGB from 0 to 255
  3566. var R = rgba[0] / 255;
  3567. var G = rgba[1] / 255;
  3568. var B = rgba[2] / 255;
  3569. var vMin = Math.min(R, G, B); // Min. value of RGB
  3570. var vMax = Math.max(R, G, B); // Max. value of RGB
  3571. var delta = vMax - vMin; // Delta RGB value
  3572. var L = (vMax + vMin) / 2;
  3573. var H;
  3574. var S; // HSL results from 0 to 1
  3575. if (delta === 0) {
  3576. H = 0;
  3577. S = 0;
  3578. } else {
  3579. if (L < 0.5) {
  3580. S = delta / (vMax + vMin);
  3581. } else {
  3582. S = delta / (2 - vMax - vMin);
  3583. }
  3584. var deltaR = ((vMax - R) / 6 + delta / 2) / delta;
  3585. var deltaG = ((vMax - G) / 6 + delta / 2) / delta;
  3586. var deltaB = ((vMax - B) / 6 + delta / 2) / delta;
  3587. if (R === vMax) {
  3588. H = deltaB - deltaG;
  3589. } else if (G === vMax) {
  3590. H = 1 / 3 + deltaR - deltaB;
  3591. } else if (B === vMax) {
  3592. H = 2 / 3 + deltaG - deltaR;
  3593. }
  3594. if (H < 0) {
  3595. H += 1;
  3596. }
  3597. if (H > 1) {
  3598. H -= 1;
  3599. }
  3600. }
  3601. var hsla = [H * 360, S, L];
  3602. if (rgba[3] != null) {
  3603. hsla.push(rgba[3]);
  3604. }
  3605. return hsla;
  3606. }
  3607. /**
  3608. * @param {string} color
  3609. * @param {number} level
  3610. * @return {string}
  3611. * @memberOf module:zrender/util/color
  3612. */
  3613. function lift(color, level) {
  3614. var colorArr = parse(color);
  3615. if (colorArr) {
  3616. for (var i = 0; i < 3; i++) {
  3617. if (level < 0) {
  3618. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3619. } else {
  3620. colorArr[i] = (255 - colorArr[i]) * level + colorArr[i] | 0;
  3621. }
  3622. if (colorArr[i] > 255) {
  3623. colorArr[i] = 255;
  3624. } else if (color[i] < 0) {
  3625. colorArr[i] = 0;
  3626. }
  3627. }
  3628. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3629. }
  3630. }
  3631. /**
  3632. * @param {string} color
  3633. * @return {string}
  3634. * @memberOf module:zrender/util/color
  3635. */
  3636. function toHex(color) {
  3637. var colorArr = parse(color);
  3638. if (colorArr) {
  3639. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + +colorArr[2]).toString(16).slice(1);
  3640. }
  3641. }
  3642. /**
  3643. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  3644. * @param {number} normalizedValue A float between 0 and 1.
  3645. * @param {Array.<Array.<number>>} colors List of rgba color array
  3646. * @param {Array.<number>} [out] Mapped gba color array
  3647. * @return {Array.<number>} will be null/undefined if input illegal.
  3648. */
  3649. function fastLerp(normalizedValue, colors, out) {
  3650. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3651. return;
  3652. }
  3653. out = out || [];
  3654. var value = normalizedValue * (colors.length - 1);
  3655. var leftIndex = Math.floor(value);
  3656. var rightIndex = Math.ceil(value);
  3657. var leftColor = colors[leftIndex];
  3658. var rightColor = colors[rightIndex];
  3659. var dv = value - leftIndex;
  3660. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3661. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3662. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3663. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3664. return out;
  3665. }
  3666. /**
  3667. * @deprecated
  3668. */
  3669. var fastMapToColor = fastLerp;
  3670. /**
  3671. * @param {number} normalizedValue A float between 0 and 1.
  3672. * @param {Array.<string>} colors Color list.
  3673. * @param {boolean=} fullOutput Default false.
  3674. * @return {(string|Object)} Result color. If fullOutput,
  3675. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  3676. * @memberOf module:zrender/util/color
  3677. */
  3678. function lerp$1(normalizedValue, colors, fullOutput) {
  3679. if (!(colors && colors.length) || !(normalizedValue >= 0 && normalizedValue <= 1)) {
  3680. return;
  3681. }
  3682. var value = normalizedValue * (colors.length - 1);
  3683. var leftIndex = Math.floor(value);
  3684. var rightIndex = Math.ceil(value);
  3685. var leftColor = parse(colors[leftIndex]);
  3686. var rightColor = parse(colors[rightIndex]);
  3687. var dv = value - leftIndex;
  3688. 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');
  3689. return fullOutput ? {
  3690. color: color,
  3691. leftIndex: leftIndex,
  3692. rightIndex: rightIndex,
  3693. value: value
  3694. } : color;
  3695. }
  3696. /**
  3697. * @deprecated
  3698. */
  3699. var mapToColor = lerp$1;
  3700. /**
  3701. * @param {string} color
  3702. * @param {number=} h 0 ~ 360, ignore when null.
  3703. * @param {number=} s 0 ~ 1, ignore when null.
  3704. * @param {number=} l 0 ~ 1, ignore when null.
  3705. * @return {string} Color string in rgba format.
  3706. * @memberOf module:zrender/util/color
  3707. */
  3708. function modifyHSL(color, h, s, l) {
  3709. color = parse(color);
  3710. if (color) {
  3711. color = rgba2hsla(color);
  3712. h != null && (color[0] = clampCssAngle(h));
  3713. s != null && (color[1] = parseCssFloat(s));
  3714. l != null && (color[2] = parseCssFloat(l));
  3715. return stringify(hsla2rgba(color), 'rgba');
  3716. }
  3717. }
  3718. /**
  3719. * @param {string} color
  3720. * @param {number=} alpha 0 ~ 1
  3721. * @return {string} Color string in rgba format.
  3722. * @memberOf module:zrender/util/color
  3723. */
  3724. function modifyAlpha(color, alpha) {
  3725. color = parse(color);
  3726. if (color && alpha != null) {
  3727. color[3] = clampCssFloat(alpha);
  3728. return stringify(color, 'rgba');
  3729. }
  3730. }
  3731. /**
  3732. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  3733. * @param {string} type 'rgba', 'hsva', ...
  3734. * @return {string} Result color. (If input illegal, return undefined).
  3735. */
  3736. function stringify(arrColor, type) {
  3737. if (!arrColor || !arrColor.length) {
  3738. return;
  3739. }
  3740. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3741. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3742. colorStr += ',' + arrColor[3];
  3743. }
  3744. return type + '(' + colorStr + ')';
  3745. }
  3746. var color = (Object.freeze || Object)({
  3747. parse: parse,
  3748. lift: lift,
  3749. toHex: toHex,
  3750. fastLerp: fastLerp,
  3751. fastMapToColor: fastMapToColor,
  3752. lerp: lerp$1,
  3753. mapToColor: mapToColor,
  3754. modifyHSL: modifyHSL,
  3755. modifyAlpha: modifyAlpha,
  3756. stringify: stringify
  3757. });
  3758. /**
  3759. * @module echarts/animation/Animator
  3760. */
  3761. var arraySlice = Array.prototype.slice;
  3762. function defaultGetter(target, key) {
  3763. return target[key];
  3764. }
  3765. function defaultSetter(target, key, value) {
  3766. target[key] = value;
  3767. }
  3768. /**
  3769. * @param {number} p0
  3770. * @param {number} p1
  3771. * @param {number} percent
  3772. * @return {number}
  3773. */
  3774. function interpolateNumber(p0, p1, percent) {
  3775. return (p1 - p0) * percent + p0;
  3776. }
  3777. /**
  3778. * @param {string} p0
  3779. * @param {string} p1
  3780. * @param {number} percent
  3781. * @return {string}
  3782. */
  3783. function interpolateString(p0, p1, percent) {
  3784. return percent > 0.5 ? p1 : p0;
  3785. }
  3786. /**
  3787. * @param {Array} p0
  3788. * @param {Array} p1
  3789. * @param {number} percent
  3790. * @param {Array} out
  3791. * @param {number} arrDim
  3792. */
  3793. function interpolateArray(p0, p1, percent, out, arrDim) {
  3794. var len = p0.length;
  3795. if (arrDim === 1) {
  3796. for (var i = 0; i < len; i++) {
  3797. out[i] = interpolateNumber(p0[i], p1[i], percent);
  3798. }
  3799. } else {
  3800. var len2 = len && p0[0].length;
  3801. for (var i = 0; i < len; i++) {
  3802. for (var j = 0; j < len2; j++) {
  3803. out[i][j] = interpolateNumber(p0[i][j], p1[i][j], percent);
  3804. }
  3805. }
  3806. }
  3807. } // arr0 is source array, arr1 is target array.
  3808. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  3809. function fillArr(arr0, arr1, arrDim) {
  3810. var arr0Len = arr0.length;
  3811. var arr1Len = arr1.length;
  3812. if (arr0Len !== arr1Len) {
  3813. // FIXME Not work for TypedArray
  3814. var isPreviousLarger = arr0Len > arr1Len;
  3815. if (isPreviousLarger) {
  3816. // Cut the previous
  3817. arr0.length = arr1Len;
  3818. } else {
  3819. // Fill the previous
  3820. for (var i = arr0Len; i < arr1Len; i++) {
  3821. arr0.push(arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i]));
  3822. }
  3823. }
  3824. } // Handling NaN value
  3825. var len2 = arr0[0] && arr0[0].length;
  3826. for (var i = 0; i < arr0.length; i++) {
  3827. if (arrDim === 1) {
  3828. if (isNaN(arr0[i])) {
  3829. arr0[i] = arr1[i];
  3830. }
  3831. } else {
  3832. for (var j = 0; j < len2; j++) {
  3833. if (isNaN(arr0[i][j])) {
  3834. arr0[i][j] = arr1[i][j];
  3835. }
  3836. }
  3837. }
  3838. }
  3839. }
  3840. /**
  3841. * @param {Array} arr0
  3842. * @param {Array} arr1
  3843. * @param {number} arrDim
  3844. * @return {boolean}
  3845. */
  3846. function isArraySame(arr0, arr1, arrDim) {
  3847. if (arr0 === arr1) {
  3848. return true;
  3849. }
  3850. var len = arr0.length;
  3851. if (len !== arr1.length) {
  3852. return false;
  3853. }
  3854. if (arrDim === 1) {
  3855. for (var i = 0; i < len; i++) {
  3856. if (arr0[i] !== arr1[i]) {
  3857. return false;
  3858. }
  3859. }
  3860. } else {
  3861. var len2 = arr0[0].length;
  3862. for (var i = 0; i < len; i++) {
  3863. for (var j = 0; j < len2; j++) {
  3864. if (arr0[i][j] !== arr1[i][j]) {
  3865. return false;
  3866. }
  3867. }
  3868. }
  3869. }
  3870. return true;
  3871. }
  3872. /**
  3873. * Catmull Rom interpolate array
  3874. * @param {Array} p0
  3875. * @param {Array} p1
  3876. * @param {Array} p2
  3877. * @param {Array} p3
  3878. * @param {number} t
  3879. * @param {number} t2
  3880. * @param {number} t3
  3881. * @param {Array} out
  3882. * @param {number} arrDim
  3883. */
  3884. function catmullRomInterpolateArray(p0, p1, p2, p3, t, t2, t3, out, arrDim) {
  3885. var len = p0.length;
  3886. if (arrDim === 1) {
  3887. for (var i = 0; i < len; i++) {
  3888. out[i] = catmullRomInterpolate(p0[i], p1[i], p2[i], p3[i], t, t2, t3);
  3889. }
  3890. } else {
  3891. var len2 = p0[0].length;
  3892. for (var i = 0; i < len; i++) {
  3893. for (var j = 0; j < len2; j++) {
  3894. out[i][j] = catmullRomInterpolate(p0[i][j], p1[i][j], p2[i][j], p3[i][j], t, t2, t3);
  3895. }
  3896. }
  3897. }
  3898. }
  3899. /**
  3900. * Catmull Rom interpolate number
  3901. * @param {number} p0
  3902. * @param {number} p1
  3903. * @param {number} p2
  3904. * @param {number} p3
  3905. * @param {number} t
  3906. * @param {number} t2
  3907. * @param {number} t3
  3908. * @return {number}
  3909. */
  3910. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  3911. var v0 = (p2 - p0) * 0.5;
  3912. var v1 = (p3 - p1) * 0.5;
  3913. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  3914. }
  3915. function cloneValue(value) {
  3916. if (isArrayLike(value)) {
  3917. var len = value.length;
  3918. if (isArrayLike(value[0])) {
  3919. var ret = [];
  3920. for (var i = 0; i < len; i++) {
  3921. ret.push(arraySlice.call(value[i]));
  3922. }
  3923. return ret;
  3924. }
  3925. return arraySlice.call(value);
  3926. }
  3927. return value;
  3928. }
  3929. function rgba2String(rgba) {
  3930. rgba[0] = Math.floor(rgba[0]);
  3931. rgba[1] = Math.floor(rgba[1]);
  3932. rgba[2] = Math.floor(rgba[2]);
  3933. return 'rgba(' + rgba.join(',') + ')';
  3934. }
  3935. function getArrayDim(keyframes) {
  3936. var lastValue = keyframes[keyframes.length - 1].value;
  3937. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  3938. }
  3939. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  3940. var getter = animator._getter;
  3941. var setter = animator._setter;
  3942. var useSpline = easing === 'spline';
  3943. var trackLen = keyframes.length;
  3944. if (!trackLen) {
  3945. return;
  3946. } // Guess data type
  3947. var firstVal = keyframes[0].value;
  3948. var isValueArray = isArrayLike(firstVal);
  3949. var isValueColor = false;
  3950. var isValueString = false; // For vertices morphing
  3951. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  3952. var trackMaxTime; // Sort keyframe as ascending
  3953. keyframes.sort(function (a, b) {
  3954. return a.time - b.time;
  3955. });
  3956. trackMaxTime = keyframes[trackLen - 1].time; // Percents of each keyframe
  3957. var kfPercents = []; // Value of each keyframe
  3958. var kfValues = [];
  3959. var prevValue = keyframes[0].value;
  3960. var isAllValueEqual = true;
  3961. for (var i = 0; i < trackLen; i++) {
  3962. kfPercents.push(keyframes[i].time / trackMaxTime); // Assume value is a color when it is a string
  3963. var value = keyframes[i].value; // Check if value is equal, deep check if value is array
  3964. if (!(isValueArray && isArraySame(value, prevValue, arrDim) || !isValueArray && value === prevValue)) {
  3965. isAllValueEqual = false;
  3966. }
  3967. prevValue = value; // Try converting a string to a color array
  3968. if (typeof value === 'string') {
  3969. var colorArray = parse(value);
  3970. if (colorArray) {
  3971. value = colorArray;
  3972. isValueColor = true;
  3973. } else {
  3974. isValueString = true;
  3975. }
  3976. }
  3977. kfValues.push(value);
  3978. }
  3979. if (!forceAnimate && isAllValueEqual) {
  3980. return;
  3981. }
  3982. var lastValue = kfValues[trackLen - 1]; // Polyfill array and NaN value
  3983. for (var i = 0; i < trackLen - 1; i++) {
  3984. if (isValueArray) {
  3985. fillArr(kfValues[i], lastValue, arrDim);
  3986. } else {
  3987. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  3988. kfValues[i] = lastValue;
  3989. }
  3990. }
  3991. }
  3992. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim); // Cache the key of last frame to speed up when
  3993. // animation playback is sequency
  3994. var lastFrame = 0;
  3995. var lastFramePercent = 0;
  3996. var start;
  3997. var w;
  3998. var p0;
  3999. var p1;
  4000. var p2;
  4001. var p3;
  4002. if (isValueColor) {
  4003. var rgba = [0, 0, 0, 0];
  4004. }
  4005. var onframe = function (target, percent) {
  4006. // Find the range keyframes
  4007. // kf1-----kf2---------current--------kf3
  4008. // find kf2 and kf3 and do interpolation
  4009. var frame; // In the easing function like elasticOut, percent may less than 0
  4010. if (percent < 0) {
  4011. frame = 0;
  4012. } else if (percent < lastFramePercent) {
  4013. // Start from next key
  4014. // PENDING start from lastFrame ?
  4015. start = Math.min(lastFrame + 1, trackLen - 1);
  4016. for (frame = start; frame >= 0; frame--) {
  4017. if (kfPercents[frame] <= percent) {
  4018. break;
  4019. }
  4020. } // PENDING really need to do this ?
  4021. frame = Math.min(frame, trackLen - 2);
  4022. } else {
  4023. for (frame = lastFrame; frame < trackLen; frame++) {
  4024. if (kfPercents[frame] > percent) {
  4025. break;
  4026. }
  4027. }
  4028. frame = Math.min(frame - 1, trackLen - 2);
  4029. }
  4030. lastFrame = frame;
  4031. lastFramePercent = percent;
  4032. var range = kfPercents[frame + 1] - kfPercents[frame];
  4033. if (range === 0) {
  4034. return;
  4035. } else {
  4036. w = (percent - kfPercents[frame]) / range;
  4037. }
  4038. if (useSpline) {
  4039. p1 = kfValues[frame];
  4040. p0 = kfValues[frame === 0 ? frame : frame - 1];
  4041. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  4042. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  4043. if (isValueArray) {
  4044. catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, getter(target, propName), arrDim);
  4045. } else {
  4046. var value;
  4047. if (isValueColor) {
  4048. value = catmullRomInterpolateArray(p0, p1, p2, p3, w, w * w, w * w * w, rgba, 1);
  4049. value = rgba2String(rgba);
  4050. } else if (isValueString) {
  4051. // String is step(0.5)
  4052. return interpolateString(p1, p2, w);
  4053. } else {
  4054. value = catmullRomInterpolate(p0, p1, p2, p3, w, w * w, w * w * w);
  4055. }
  4056. setter(target, propName, value);
  4057. }
  4058. } else {
  4059. if (isValueArray) {
  4060. interpolateArray(kfValues[frame], kfValues[frame + 1], w, getter(target, propName), arrDim);
  4061. } else {
  4062. var value;
  4063. if (isValueColor) {
  4064. interpolateArray(kfValues[frame], kfValues[frame + 1], w, rgba, 1);
  4065. value = rgba2String(rgba);
  4066. } else if (isValueString) {
  4067. // String is step(0.5)
  4068. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  4069. } else {
  4070. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  4071. }
  4072. setter(target, propName, value);
  4073. }
  4074. }
  4075. };
  4076. var clip = new Clip({
  4077. target: animator._target,
  4078. life: trackMaxTime,
  4079. loop: animator._loop,
  4080. delay: animator._delay,
  4081. onframe: onframe,
  4082. ondestroy: oneTrackDone
  4083. });
  4084. if (easing && easing !== 'spline') {
  4085. clip.easing = easing;
  4086. }
  4087. return clip;
  4088. }
  4089. /**
  4090. * @alias module:zrender/animation/Animator
  4091. * @constructor
  4092. * @param {Object} target
  4093. * @param {boolean} loop
  4094. * @param {Function} getter
  4095. * @param {Function} setter
  4096. */
  4097. var Animator = function (target, loop, getter, setter) {
  4098. this._tracks = {};
  4099. this._target = target;
  4100. this._loop = loop || false;
  4101. this._getter = getter || defaultGetter;
  4102. this._setter = setter || defaultSetter;
  4103. this._clipCount = 0;
  4104. this._delay = 0;
  4105. this._doneList = [];
  4106. this._onframeList = [];
  4107. this._clipList = [];
  4108. };
  4109. Animator.prototype = {
  4110. /**
  4111. * Set Animation keyframe
  4112. * @param {number} time 关键帧时间,单位是ms
  4113. * @param {Object} props 关键帧的属性值,key-value表示
  4114. * @return {module:zrender/animation/Animator}
  4115. */
  4116. when: function (time
  4117. /* ms */
  4118. , props) {
  4119. var tracks = this._tracks;
  4120. for (var propName in props) {
  4121. if (!props.hasOwnProperty(propName)) {
  4122. continue;
  4123. }
  4124. if (!tracks[propName]) {
  4125. tracks[propName] = []; // Invalid value
  4126. var value = this._getter(this._target, propName);
  4127. if (value == null) {
  4128. // zrLog('Invalid property ' + propName);
  4129. continue;
  4130. } // If time is 0
  4131. // Then props is given initialize value
  4132. // Else
  4133. // Initialize value from current prop value
  4134. if (time !== 0) {
  4135. tracks[propName].push({
  4136. time: 0,
  4137. value: cloneValue(value)
  4138. });
  4139. }
  4140. }
  4141. tracks[propName].push({
  4142. time: time,
  4143. value: props[propName]
  4144. });
  4145. }
  4146. return this;
  4147. },
  4148. /**
  4149. * 添加动画每一帧的回调函数
  4150. * @param {Function} callback
  4151. * @return {module:zrender/animation/Animator}
  4152. */
  4153. during: function (callback) {
  4154. this._onframeList.push(callback);
  4155. return this;
  4156. },
  4157. pause: function () {
  4158. for (var i = 0; i < this._clipList.length; i++) {
  4159. this._clipList[i].pause();
  4160. }
  4161. this._paused = true;
  4162. },
  4163. resume: function () {
  4164. for (var i = 0; i < this._clipList.length; i++) {
  4165. this._clipList[i].resume();
  4166. }
  4167. this._paused = false;
  4168. },
  4169. isPaused: function () {
  4170. return !!this._paused;
  4171. },
  4172. _doneCallback: function () {
  4173. // Clear all tracks
  4174. this._tracks = {}; // Clear all clips
  4175. this._clipList.length = 0;
  4176. var doneList = this._doneList;
  4177. var len = doneList.length;
  4178. for (var i = 0; i < len; i++) {
  4179. doneList[i].call(this);
  4180. }
  4181. },
  4182. /**
  4183. * Start the animation
  4184. * @param {string|Function} [easing]
  4185. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  4186. * @param {boolean} forceAnimate
  4187. * @return {module:zrender/animation/Animator}
  4188. */
  4189. start: function (easing, forceAnimate) {
  4190. var self = this;
  4191. var clipCount = 0;
  4192. var oneTrackDone = function () {
  4193. clipCount--;
  4194. if (!clipCount) {
  4195. self._doneCallback();
  4196. }
  4197. };
  4198. var lastClip;
  4199. for (var propName in this._tracks) {
  4200. if (!this._tracks.hasOwnProperty(propName)) {
  4201. continue;
  4202. }
  4203. var clip = createTrackClip(this, easing, oneTrackDone, this._tracks[propName], propName, forceAnimate);
  4204. if (clip) {
  4205. this._clipList.push(clip);
  4206. clipCount++; // If start after added to animation
  4207. if (this.animation) {
  4208. this.animation.addClip(clip);
  4209. }
  4210. lastClip = clip;
  4211. }
  4212. } // Add during callback on the last clip
  4213. if (lastClip) {
  4214. var oldOnFrame = lastClip.onframe;
  4215. lastClip.onframe = function (target, percent) {
  4216. oldOnFrame(target, percent);
  4217. for (var i = 0; i < self._onframeList.length; i++) {
  4218. self._onframeList[i](target, percent);
  4219. }
  4220. };
  4221. } // This optimization will help the case that in the upper application
  4222. // the view may be refreshed frequently, where animation will be
  4223. // called repeatly but nothing changed.
  4224. if (!clipCount) {
  4225. this._doneCallback();
  4226. }
  4227. return this;
  4228. },
  4229. /**
  4230. * Stop animation
  4231. * @param {boolean} forwardToLast If move to last frame before stop
  4232. */
  4233. stop: function (forwardToLast) {
  4234. var clipList = this._clipList;
  4235. var animation = this.animation;
  4236. for (var i = 0; i < clipList.length; i++) {
  4237. var clip = clipList[i];
  4238. if (forwardToLast) {
  4239. // Move to last frame before stop
  4240. clip.onframe(this._target, 1);
  4241. }
  4242. animation && animation.removeClip(clip);
  4243. }
  4244. clipList.length = 0;
  4245. },
  4246. /**
  4247. * Set when animation delay starts
  4248. * @param {number} time 单位ms
  4249. * @return {module:zrender/animation/Animator}
  4250. */
  4251. delay: function (time) {
  4252. this._delay = time;
  4253. return this;
  4254. },
  4255. /**
  4256. * Add callback for animation end
  4257. * @param {Function} cb
  4258. * @return {module:zrender/animation/Animator}
  4259. */
  4260. done: function (cb) {
  4261. if (cb) {
  4262. this._doneList.push(cb);
  4263. }
  4264. return this;
  4265. },
  4266. /**
  4267. * @return {Array.<module:zrender/animation/Clip>}
  4268. */
  4269. getClips: function () {
  4270. return this._clipList;
  4271. }
  4272. };
  4273. var dpr = 1; // If in browser environment
  4274. if (typeof window !== 'undefined') {
  4275. dpr = Math.max(window.devicePixelRatio || 1, 1);
  4276. }
  4277. /**
  4278. * config默认配置项
  4279. * @exports zrender/config
  4280. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  4281. */
  4282. /**
  4283. * Debug log mode:
  4284. * 0: Do nothing, for release.
  4285. * 1: console.error, for debug.
  4286. */
  4287. var debugMode = 0; // retina 屏幕优化
  4288. var devicePixelRatio = dpr;
  4289. var logError = function () {};
  4290. if (debugMode === 1) {
  4291. logError = console.error;
  4292. }
  4293. var logError$1 = logError;
  4294. /**
  4295. * @alias module:zrender/mixin/Animatable
  4296. * @constructor
  4297. */
  4298. var Animatable = function () {
  4299. /**
  4300. * @type {Array.<module:zrender/animation/Animator>}
  4301. * @readOnly
  4302. */
  4303. this.animators = [];
  4304. };
  4305. Animatable.prototype = {
  4306. constructor: Animatable,
  4307. /**
  4308. * 动画
  4309. *
  4310. * @param {string} path The path to fetch value from object, like 'a.b.c'.
  4311. * @param {boolean} [loop] Whether to loop animation.
  4312. * @return {module:zrender/animation/Animator}
  4313. * @example:
  4314. * el.animate('style', false)
  4315. * .when(1000, {x: 10} )
  4316. * .done(function(){ // Animation done })
  4317. * .start()
  4318. */
  4319. animate: function (path, loop) {
  4320. var target;
  4321. var animatingShape = false;
  4322. var el = this;
  4323. var zr = this.__zr;
  4324. if (path) {
  4325. var pathSplitted = path.split('.');
  4326. var prop = el; // If animating shape
  4327. animatingShape = pathSplitted[0] === 'shape';
  4328. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  4329. if (!prop) {
  4330. continue;
  4331. }
  4332. prop = prop[pathSplitted[i]];
  4333. }
  4334. if (prop) {
  4335. target = prop;
  4336. }
  4337. } else {
  4338. target = el;
  4339. }
  4340. if (!target) {
  4341. logError$1('Property "' + path + '" is not existed in element ' + el.id);
  4342. return;
  4343. }
  4344. var animators = el.animators;
  4345. var animator = new Animator(target, loop);
  4346. animator.during(function (target) {
  4347. el.dirty(animatingShape);
  4348. }).done(function () {
  4349. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  4350. animators.splice(indexOf(animators, animator), 1);
  4351. });
  4352. animators.push(animator); // If animate after added to the zrender
  4353. if (zr) {
  4354. zr.animation.addAnimator(animator);
  4355. }
  4356. return animator;
  4357. },
  4358. /**
  4359. * 停止动画
  4360. * @param {boolean} forwardToLast If move to last frame before stop
  4361. */
  4362. stopAnimation: function (forwardToLast) {
  4363. var animators = this.animators;
  4364. var len = animators.length;
  4365. for (var i = 0; i < len; i++) {
  4366. animators[i].stop(forwardToLast);
  4367. }
  4368. animators.length = 0;
  4369. return this;
  4370. },
  4371. /**
  4372. * Caution: this method will stop previous animation.
  4373. * So do not use this method to one element twice before
  4374. * animation starts, unless you know what you are doing.
  4375. * @param {Object} target
  4376. * @param {number} [time=500] Time in ms
  4377. * @param {string} [easing='linear']
  4378. * @param {number} [delay=0]
  4379. * @param {Function} [callback]
  4380. * @param {Function} [forceAnimate] Prevent stop animation and callback
  4381. * immediently when target values are the same as current values.
  4382. *
  4383. * @example
  4384. * // Animate position
  4385. * el.animateTo({
  4386. * position: [10, 10]
  4387. * }, function () { // done })
  4388. *
  4389. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  4390. * el.animateTo({
  4391. * shape: {
  4392. * width: 500
  4393. * },
  4394. * style: {
  4395. * fill: 'red'
  4396. * }
  4397. * position: [10, 10]
  4398. * }, 100, 100, 'cubicOut', function () { // done })
  4399. */
  4400. // TODO Return animation key
  4401. animateTo: function (target, time, delay, easing, callback, forceAnimate) {
  4402. animateTo(this, target, time, delay, easing, callback, forceAnimate);
  4403. },
  4404. /**
  4405. * Animate from the target state to current state.
  4406. * The params and the return value are the same as `this.animateTo`.
  4407. */
  4408. animateFrom: function (target, time, delay, easing, callback, forceAnimate) {
  4409. animateTo(this, target, time, delay, easing, callback, forceAnimate, true);
  4410. }
  4411. };
  4412. function animateTo(animatable, target, time, delay, easing, callback, forceAnimate, reverse) {
  4413. // animateTo(target, time, easing, callback);
  4414. if (isString(delay)) {
  4415. callback = easing;
  4416. easing = delay;
  4417. delay = 0;
  4418. } // animateTo(target, time, delay, callback);
  4419. else if (isFunction$1(easing)) {
  4420. callback = easing;
  4421. easing = 'linear';
  4422. delay = 0;
  4423. } // animateTo(target, time, callback);
  4424. else if (isFunction$1(delay)) {
  4425. callback = delay;
  4426. delay = 0;
  4427. } // animateTo(target, callback)
  4428. else if (isFunction$1(time)) {
  4429. callback = time;
  4430. time = 500;
  4431. } // animateTo(target)
  4432. else if (!time) {
  4433. time = 500;
  4434. } // Stop all previous animations
  4435. animatable.stopAnimation();
  4436. animateToShallow(animatable, '', animatable, target, time, delay, reverse); // Animators may be removed immediately after start
  4437. // if there is nothing to animate
  4438. var animators = animatable.animators.slice();
  4439. var count = animators.length;
  4440. function done() {
  4441. count--;
  4442. if (!count) {
  4443. callback && callback();
  4444. }
  4445. } // No animators. This should be checked before animators[i].start(),
  4446. // because 'done' may be executed immediately if no need to animate.
  4447. if (!count) {
  4448. callback && callback();
  4449. } // Start after all animators created
  4450. // Incase any animator is done immediately when all animation properties are not changed
  4451. for (var i = 0; i < animators.length; i++) {
  4452. animators[i].done(done).start(easing, forceAnimate);
  4453. }
  4454. }
  4455. /**
  4456. * @param {string} path=''
  4457. * @param {Object} source=animatable
  4458. * @param {Object} target
  4459. * @param {number} [time=500]
  4460. * @param {number} [delay=0]
  4461. * @param {boolean} [reverse] If `true`, animate
  4462. * from the `target` to current state.
  4463. *
  4464. * @example
  4465. * // Animate position
  4466. * el._animateToShallow({
  4467. * position: [10, 10]
  4468. * })
  4469. *
  4470. * // Animate shape, style and position in 100ms, delayed 100ms
  4471. * el._animateToShallow({
  4472. * shape: {
  4473. * width: 500
  4474. * },
  4475. * style: {
  4476. * fill: 'red'
  4477. * }
  4478. * position: [10, 10]
  4479. * }, 100, 100)
  4480. */
  4481. function animateToShallow(animatable, path, source, target, time, delay, reverse) {
  4482. var objShallow = {};
  4483. var propertyCount = 0;
  4484. for (var name in target) {
  4485. if (!target.hasOwnProperty(name)) {
  4486. continue;
  4487. }
  4488. if (source[name] != null) {
  4489. if (isObject$1(target[name]) && !isArrayLike(target[name])) {
  4490. animateToShallow(animatable, path ? path + '.' + name : name, source[name], target[name], time, delay, reverse);
  4491. } else {
  4492. if (reverse) {
  4493. objShallow[name] = source[name];
  4494. setAttrByPath(animatable, path, name, target[name]);
  4495. } else {
  4496. objShallow[name] = target[name];
  4497. }
  4498. propertyCount++;
  4499. }
  4500. } else if (target[name] != null && !reverse) {
  4501. setAttrByPath(animatable, path, name, target[name]);
  4502. }
  4503. }
  4504. if (propertyCount > 0) {
  4505. animatable.animate(path, false).when(time == null ? 500 : time, objShallow).delay(delay || 0);
  4506. }
  4507. }
  4508. function setAttrByPath(el, path, name, value) {
  4509. // Attr directly if not has property
  4510. // FIXME, if some property not needed for element ?
  4511. if (!path) {
  4512. el.attr(name, value);
  4513. } else {
  4514. // Only support set shape or style
  4515. var props = {};
  4516. props[path] = {};
  4517. props[path][name] = value;
  4518. el.attr(props);
  4519. }
  4520. }
  4521. /**
  4522. * @alias module:zrender/Element
  4523. * @constructor
  4524. * @extends {module:zrender/mixin/Animatable}
  4525. * @extends {module:zrender/mixin/Transformable}
  4526. * @extends {module:zrender/mixin/Eventful}
  4527. */
  4528. var Element = function (opts) {
  4529. // jshint ignore:line
  4530. Transformable.call(this, opts);
  4531. Eventful.call(this, opts);
  4532. Animatable.call(this, opts);
  4533. /**
  4534. * 画布元素ID
  4535. * @type {string}
  4536. */
  4537. this.id = opts.id || guid();
  4538. };
  4539. Element.prototype = {
  4540. /**
  4541. * 元素类型
  4542. * Element type
  4543. * @type {string}
  4544. */
  4545. type: 'element',
  4546. /**
  4547. * 元素名字
  4548. * Element name
  4549. * @type {string}
  4550. */
  4551. name: '',
  4552. /**
  4553. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  4554. * ZRender instance will be assigned when element is associated with zrender
  4555. * @name module:/zrender/Element#__zr
  4556. * @type {module:zrender/ZRender}
  4557. */
  4558. __zr: null,
  4559. /**
  4560. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  4561. * If ignore drawing and events of the element object
  4562. * @name module:/zrender/Element#ignore
  4563. * @type {boolean}
  4564. * @default false
  4565. */
  4566. ignore: false,
  4567. /**
  4568. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  4569. * 该路径会继承被裁减对象的变换
  4570. * @type {module:zrender/graphic/Path}
  4571. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  4572. * @readOnly
  4573. */
  4574. clipPath: null,
  4575. /**
  4576. * 是否是 Group
  4577. * @type {boolean}
  4578. */
  4579. isGroup: false,
  4580. /**
  4581. * Drift element
  4582. * @param {number} dx dx on the global space
  4583. * @param {number} dy dy on the global space
  4584. */
  4585. drift: function (dx, dy) {
  4586. switch (this.draggable) {
  4587. case 'horizontal':
  4588. dy = 0;
  4589. break;
  4590. case 'vertical':
  4591. dx = 0;
  4592. break;
  4593. }
  4594. var m = this.transform;
  4595. if (!m) {
  4596. m = this.transform = [1, 0, 0, 1, 0, 0];
  4597. }
  4598. m[4] += dx;
  4599. m[5] += dy;
  4600. this.decomposeTransform();
  4601. this.dirty(false);
  4602. },
  4603. /**
  4604. * Hook before update
  4605. */
  4606. beforeUpdate: function () {},
  4607. /**
  4608. * Hook after update
  4609. */
  4610. afterUpdate: function () {},
  4611. /**
  4612. * Update each frame
  4613. */
  4614. update: function () {
  4615. this.updateTransform();
  4616. },
  4617. /**
  4618. * @param {Function} cb
  4619. * @param {} context
  4620. */
  4621. traverse: function (cb, context) {},
  4622. /**
  4623. * @protected
  4624. */
  4625. attrKV: function (key, value) {
  4626. if (key === 'position' || key === 'scale' || key === 'origin') {
  4627. // Copy the array
  4628. if (value) {
  4629. var target = this[key];
  4630. if (!target) {
  4631. target = this[key] = [];
  4632. }
  4633. target[0] = value[0];
  4634. target[1] = value[1];
  4635. }
  4636. } else {
  4637. this[key] = value;
  4638. }
  4639. },
  4640. /**
  4641. * Hide the element
  4642. */
  4643. hide: function () {
  4644. this.ignore = true;
  4645. this.__zr && this.__zr.refresh();
  4646. },
  4647. /**
  4648. * Show the element
  4649. */
  4650. show: function () {
  4651. this.ignore = false;
  4652. this.__zr && this.__zr.refresh();
  4653. },
  4654. /**
  4655. * @param {string|Object} key
  4656. * @param {*} value
  4657. */
  4658. attr: function (key, value) {
  4659. if (typeof key === 'string') {
  4660. this.attrKV(key, value);
  4661. } else if (isObject$1(key)) {
  4662. for (var name in key) {
  4663. if (key.hasOwnProperty(name)) {
  4664. this.attrKV(name, key[name]);
  4665. }
  4666. }
  4667. }
  4668. this.dirty(false);
  4669. return this;
  4670. },
  4671. /**
  4672. * @param {module:zrender/graphic/Path} clipPath
  4673. */
  4674. setClipPath: function (clipPath) {
  4675. var zr = this.__zr;
  4676. if (zr) {
  4677. clipPath.addSelfToZr(zr);
  4678. } // Remove previous clip path
  4679. if (this.clipPath && this.clipPath !== clipPath) {
  4680. this.removeClipPath();
  4681. }
  4682. this.clipPath = clipPath;
  4683. clipPath.__zr = zr;
  4684. clipPath.__clipTarget = this;
  4685. this.dirty(false);
  4686. },
  4687. /**
  4688. */
  4689. removeClipPath: function () {
  4690. var clipPath = this.clipPath;
  4691. if (clipPath) {
  4692. if (clipPath.__zr) {
  4693. clipPath.removeSelfFromZr(clipPath.__zr);
  4694. }
  4695. clipPath.__zr = null;
  4696. clipPath.__clipTarget = null;
  4697. this.clipPath = null;
  4698. this.dirty(false);
  4699. }
  4700. },
  4701. /**
  4702. * Add self from zrender instance.
  4703. * Not recursively because it will be invoked when element added to storage.
  4704. * @param {module:zrender/ZRender} zr
  4705. */
  4706. addSelfToZr: function (zr) {
  4707. this.__zr = zr; // 添加动画
  4708. var animators = this.animators;
  4709. if (animators) {
  4710. for (var i = 0; i < animators.length; i++) {
  4711. zr.animation.addAnimator(animators[i]);
  4712. }
  4713. }
  4714. if (this.clipPath) {
  4715. this.clipPath.addSelfToZr(zr);
  4716. }
  4717. },
  4718. /**
  4719. * Remove self from zrender instance.
  4720. * Not recursively because it will be invoked when element added to storage.
  4721. * @param {module:zrender/ZRender} zr
  4722. */
  4723. removeSelfFromZr: function (zr) {
  4724. this.__zr = null; // 移除动画
  4725. var animators = this.animators;
  4726. if (animators) {
  4727. for (var i = 0; i < animators.length; i++) {
  4728. zr.animation.removeAnimator(animators[i]);
  4729. }
  4730. }
  4731. if (this.clipPath) {
  4732. this.clipPath.removeSelfFromZr(zr);
  4733. }
  4734. }
  4735. };
  4736. mixin(Element, Animatable);
  4737. mixin(Element, Transformable);
  4738. mixin(Element, Eventful);
  4739. /**
  4740. * @module echarts/core/BoundingRect
  4741. */
  4742. var v2ApplyTransform = applyTransform;
  4743. var mathMin = Math.min;
  4744. var mathMax = Math.max;
  4745. /**
  4746. * @alias module:echarts/core/BoundingRect
  4747. */
  4748. function BoundingRect(x, y, width, height) {
  4749. if (width < 0) {
  4750. x = x + width;
  4751. width = -width;
  4752. }
  4753. if (height < 0) {
  4754. y = y + height;
  4755. height = -height;
  4756. }
  4757. /**
  4758. * @type {number}
  4759. */
  4760. this.x = x;
  4761. /**
  4762. * @type {number}
  4763. */
  4764. this.y = y;
  4765. /**
  4766. * @type {number}
  4767. */
  4768. this.width = width;
  4769. /**
  4770. * @type {number}
  4771. */
  4772. this.height = height;
  4773. }
  4774. BoundingRect.prototype = {
  4775. constructor: BoundingRect,
  4776. /**
  4777. * @param {module:echarts/core/BoundingRect} other
  4778. */
  4779. union: function (other) {
  4780. var x = mathMin(other.x, this.x);
  4781. var y = mathMin(other.y, this.y);
  4782. this.width = mathMax(other.x + other.width, this.x + this.width) - x;
  4783. this.height = mathMax(other.y + other.height, this.y + this.height) - y;
  4784. this.x = x;
  4785. this.y = y;
  4786. },
  4787. /**
  4788. * @param {Array.<number>} m
  4789. * @methods
  4790. */
  4791. applyTransform: function () {
  4792. var lt = [];
  4793. var rb = [];
  4794. var lb = [];
  4795. var rt = [];
  4796. return function (m) {
  4797. // In case usage like this
  4798. // el.getBoundingRect().applyTransform(el.transform)
  4799. // And element has no transform
  4800. if (!m) {
  4801. return;
  4802. }
  4803. lt[0] = lb[0] = this.x;
  4804. lt[1] = rt[1] = this.y;
  4805. rb[0] = rt[0] = this.x + this.width;
  4806. rb[1] = lb[1] = this.y + this.height;
  4807. v2ApplyTransform(lt, lt, m);
  4808. v2ApplyTransform(rb, rb, m);
  4809. v2ApplyTransform(lb, lb, m);
  4810. v2ApplyTransform(rt, rt, m);
  4811. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4812. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4813. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4814. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4815. this.width = maxX - this.x;
  4816. this.height = maxY - this.y;
  4817. };
  4818. }(),
  4819. /**
  4820. * Calculate matrix of transforming from self to target rect
  4821. * @param {module:zrender/core/BoundingRect} b
  4822. * @return {Array.<number>}
  4823. */
  4824. calculateTransform: function (b) {
  4825. var a = this;
  4826. var sx = b.width / a.width;
  4827. var sy = b.height / a.height;
  4828. var m = create$1(); // 矩阵右乘
  4829. translate(m, m, [-a.x, -a.y]);
  4830. scale$1(m, m, [sx, sy]);
  4831. translate(m, m, [b.x, b.y]);
  4832. return m;
  4833. },
  4834. /**
  4835. * @param {(module:echarts/core/BoundingRect|Object)} b
  4836. * @return {boolean}
  4837. */
  4838. intersect: function (b) {
  4839. if (!b) {
  4840. return false;
  4841. }
  4842. if (!(b instanceof BoundingRect)) {
  4843. // Normalize negative width/height.
  4844. b = BoundingRect.create(b);
  4845. }
  4846. var a = this;
  4847. var ax0 = a.x;
  4848. var ax1 = a.x + a.width;
  4849. var ay0 = a.y;
  4850. var ay1 = a.y + a.height;
  4851. var bx0 = b.x;
  4852. var bx1 = b.x + b.width;
  4853. var by0 = b.y;
  4854. var by1 = b.y + b.height;
  4855. return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4856. },
  4857. contain: function (x, y) {
  4858. var rect = this;
  4859. return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
  4860. },
  4861. /**
  4862. * @return {module:echarts/core/BoundingRect}
  4863. */
  4864. clone: function () {
  4865. return new BoundingRect(this.x, this.y, this.width, this.height);
  4866. },
  4867. /**
  4868. * Copy from another rect
  4869. */
  4870. copy: function (other) {
  4871. this.x = other.x;
  4872. this.y = other.y;
  4873. this.width = other.width;
  4874. this.height = other.height;
  4875. },
  4876. plain: function () {
  4877. return {
  4878. x: this.x,
  4879. y: this.y,
  4880. width: this.width,
  4881. height: this.height
  4882. };
  4883. }
  4884. };
  4885. /**
  4886. * @param {Object|module:zrender/core/BoundingRect} rect
  4887. * @param {number} rect.x
  4888. * @param {number} rect.y
  4889. * @param {number} rect.width
  4890. * @param {number} rect.height
  4891. * @return {module:zrender/core/BoundingRect}
  4892. */
  4893. BoundingRect.create = function (rect) {
  4894. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4895. };
  4896. /**
  4897. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  4898. * @module zrender/graphic/Group
  4899. * @example
  4900. * var Group = require('zrender/container/Group');
  4901. * var Circle = require('zrender/graphic/shape/Circle');
  4902. * var g = new Group();
  4903. * g.position[0] = 100;
  4904. * g.position[1] = 100;
  4905. * g.add(new Circle({
  4906. * style: {
  4907. * x: 100,
  4908. * y: 100,
  4909. * r: 20,
  4910. * }
  4911. * }));
  4912. * zr.add(g);
  4913. */
  4914. /**
  4915. * @alias module:zrender/graphic/Group
  4916. * @constructor
  4917. * @extends module:zrender/mixin/Transformable
  4918. * @extends module:zrender/mixin/Eventful
  4919. */
  4920. var Group = function (opts) {
  4921. opts = opts || {};
  4922. Element.call(this, opts);
  4923. for (var key in opts) {
  4924. if (opts.hasOwnProperty(key)) {
  4925. this[key] = opts[key];
  4926. }
  4927. }
  4928. this._children = [];
  4929. this.__storage = null;
  4930. this.__dirty = true;
  4931. };
  4932. Group.prototype = {
  4933. constructor: Group,
  4934. isGroup: true,
  4935. /**
  4936. * @type {string}
  4937. */
  4938. type: 'group',
  4939. /**
  4940. * 所有子孙元素是否响应鼠标事件
  4941. * @name module:/zrender/container/Group#silent
  4942. * @type {boolean}
  4943. * @default false
  4944. */
  4945. silent: false,
  4946. /**
  4947. * @return {Array.<module:zrender/Element>}
  4948. */
  4949. children: function () {
  4950. return this._children.slice();
  4951. },
  4952. /**
  4953. * 获取指定 index 的儿子节点
  4954. * @param {number} idx
  4955. * @return {module:zrender/Element}
  4956. */
  4957. childAt: function (idx) {
  4958. return this._children[idx];
  4959. },
  4960. /**
  4961. * 获取指定名字的儿子节点
  4962. * @param {string} name
  4963. * @return {module:zrender/Element}
  4964. */
  4965. childOfName: function (name) {
  4966. var children = this._children;
  4967. for (var i = 0; i < children.length; i++) {
  4968. if (children[i].name === name) {
  4969. return children[i];
  4970. }
  4971. }
  4972. },
  4973. /**
  4974. * @return {number}
  4975. */
  4976. childCount: function () {
  4977. return this._children.length;
  4978. },
  4979. /**
  4980. * 添加子节点到最后
  4981. * @param {module:zrender/Element} child
  4982. */
  4983. add: function (child) {
  4984. if (child && child !== this && child.parent !== this) {
  4985. this._children.push(child);
  4986. this._doAdd(child);
  4987. }
  4988. return this;
  4989. },
  4990. /**
  4991. * 添加子节点在 nextSibling 之前
  4992. * @param {module:zrender/Element} child
  4993. * @param {module:zrender/Element} nextSibling
  4994. */
  4995. addBefore: function (child, nextSibling) {
  4996. if (child && child !== this && child.parent !== this && nextSibling && nextSibling.parent === this) {
  4997. var children = this._children;
  4998. var idx = children.indexOf(nextSibling);
  4999. if (idx >= 0) {
  5000. children.splice(idx, 0, child);
  5001. this._doAdd(child);
  5002. }
  5003. }
  5004. return this;
  5005. },
  5006. _doAdd: function (child) {
  5007. if (child.parent) {
  5008. child.parent.remove(child);
  5009. }
  5010. child.parent = this;
  5011. var storage = this.__storage;
  5012. var zr = this.__zr;
  5013. if (storage && storage !== child.__storage) {
  5014. storage.addToStorage(child);
  5015. if (child instanceof Group) {
  5016. child.addChildrenToStorage(storage);
  5017. }
  5018. }
  5019. zr && zr.refresh();
  5020. },
  5021. /**
  5022. * 移除子节点
  5023. * @param {module:zrender/Element} child
  5024. */
  5025. remove: function (child) {
  5026. var zr = this.__zr;
  5027. var storage = this.__storage;
  5028. var children = this._children;
  5029. var idx = indexOf(children, child);
  5030. if (idx < 0) {
  5031. return this;
  5032. }
  5033. children.splice(idx, 1);
  5034. child.parent = null;
  5035. if (storage) {
  5036. storage.delFromStorage(child);
  5037. if (child instanceof Group) {
  5038. child.delChildrenFromStorage(storage);
  5039. }
  5040. }
  5041. zr && zr.refresh();
  5042. return this;
  5043. },
  5044. /**
  5045. * 移除所有子节点
  5046. */
  5047. removeAll: function () {
  5048. var children = this._children;
  5049. var storage = this.__storage;
  5050. var child;
  5051. var i;
  5052. for (i = 0; i < children.length; i++) {
  5053. child = children[i];
  5054. if (storage) {
  5055. storage.delFromStorage(child);
  5056. if (child instanceof Group) {
  5057. child.delChildrenFromStorage(storage);
  5058. }
  5059. }
  5060. child.parent = null;
  5061. }
  5062. children.length = 0;
  5063. return this;
  5064. },
  5065. /**
  5066. * 遍历所有子节点
  5067. * @param {Function} cb
  5068. * @param {} context
  5069. */
  5070. eachChild: function (cb, context) {
  5071. var children = this._children;
  5072. for (var i = 0; i < children.length; i++) {
  5073. var child = children[i];
  5074. cb.call(context, child, i);
  5075. }
  5076. return this;
  5077. },
  5078. /**
  5079. * 深度优先遍历所有子孙节点
  5080. * @param {Function} cb
  5081. * @param {} context
  5082. */
  5083. traverse: function (cb, context) {
  5084. for (var i = 0; i < this._children.length; i++) {
  5085. var child = this._children[i];
  5086. cb.call(context, child);
  5087. if (child.type === 'group') {
  5088. child.traverse(cb, context);
  5089. }
  5090. }
  5091. return this;
  5092. },
  5093. addChildrenToStorage: function (storage) {
  5094. for (var i = 0; i < this._children.length; i++) {
  5095. var child = this._children[i];
  5096. storage.addToStorage(child);
  5097. if (child instanceof Group) {
  5098. child.addChildrenToStorage(storage);
  5099. }
  5100. }
  5101. },
  5102. delChildrenFromStorage: function (storage) {
  5103. for (var i = 0; i < this._children.length; i++) {
  5104. var child = this._children[i];
  5105. storage.delFromStorage(child);
  5106. if (child instanceof Group) {
  5107. child.delChildrenFromStorage(storage);
  5108. }
  5109. }
  5110. },
  5111. dirty: function () {
  5112. this.__dirty = true;
  5113. this.__zr && this.__zr.refresh();
  5114. return this;
  5115. },
  5116. /**
  5117. * @return {module:zrender/core/BoundingRect}
  5118. */
  5119. getBoundingRect: function (includeChildren) {
  5120. // TODO Caching
  5121. var rect = null;
  5122. var tmpRect = new BoundingRect(0, 0, 0, 0);
  5123. var children = includeChildren || this._children;
  5124. var tmpMat = [];
  5125. for (var i = 0; i < children.length; i++) {
  5126. var child = children[i];
  5127. if (child.ignore || child.invisible) {
  5128. continue;
  5129. }
  5130. var childRect = child.getBoundingRect();
  5131. var transform = child.getLocalTransform(tmpMat); // TODO
  5132. // The boundingRect cacluated by transforming original
  5133. // rect may be bigger than the actual bundingRect when rotation
  5134. // is used. (Consider a circle rotated aginst its center, where
  5135. // the actual boundingRect should be the same as that not be
  5136. // rotated.) But we can not find better approach to calculate
  5137. // actual boundingRect yet, considering performance.
  5138. if (transform) {
  5139. tmpRect.copy(childRect);
  5140. tmpRect.applyTransform(transform);
  5141. rect = rect || tmpRect.clone();
  5142. rect.union(tmpRect);
  5143. } else {
  5144. rect = rect || childRect.clone();
  5145. rect.union(childRect);
  5146. }
  5147. }
  5148. return rect || tmpRect;
  5149. }
  5150. };
  5151. inherits(Group, Element);
  5152. // https://github.com/mziccard/node-timsort
  5153. var DEFAULT_MIN_MERGE = 32;
  5154. var DEFAULT_MIN_GALLOPING = 7;
  5155. function minRunLength(n) {
  5156. var r = 0;
  5157. while (n >= DEFAULT_MIN_MERGE) {
  5158. r |= n & 1;
  5159. n >>= 1;
  5160. }
  5161. return n + r;
  5162. }
  5163. function makeAscendingRun(array, lo, hi, compare) {
  5164. var runHi = lo + 1;
  5165. if (runHi === hi) {
  5166. return 1;
  5167. }
  5168. if (compare(array[runHi++], array[lo]) < 0) {
  5169. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  5170. runHi++;
  5171. }
  5172. reverseRun(array, lo, runHi);
  5173. } else {
  5174. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  5175. runHi++;
  5176. }
  5177. }
  5178. return runHi - lo;
  5179. }
  5180. function reverseRun(array, lo, hi) {
  5181. hi--;
  5182. while (lo < hi) {
  5183. var t = array[lo];
  5184. array[lo++] = array[hi];
  5185. array[hi--] = t;
  5186. }
  5187. }
  5188. function binaryInsertionSort(array, lo, hi, start, compare) {
  5189. if (start === lo) {
  5190. start++;
  5191. }
  5192. for (; start < hi; start++) {
  5193. var pivot = array[start];
  5194. var left = lo;
  5195. var right = start;
  5196. var mid;
  5197. while (left < right) {
  5198. mid = left + right >>> 1;
  5199. if (compare(pivot, array[mid]) < 0) {
  5200. right = mid;
  5201. } else {
  5202. left = mid + 1;
  5203. }
  5204. }
  5205. var n = start - left;
  5206. switch (n) {
  5207. case 3:
  5208. array[left + 3] = array[left + 2];
  5209. case 2:
  5210. array[left + 2] = array[left + 1];
  5211. case 1:
  5212. array[left + 1] = array[left];
  5213. break;
  5214. default:
  5215. while (n > 0) {
  5216. array[left + n] = array[left + n - 1];
  5217. n--;
  5218. }
  5219. }
  5220. array[left] = pivot;
  5221. }
  5222. }
  5223. function gallopLeft(value, array, start, length, hint, compare) {
  5224. var lastOffset = 0;
  5225. var maxOffset = 0;
  5226. var offset = 1;
  5227. if (compare(value, array[start + hint]) > 0) {
  5228. maxOffset = length - hint;
  5229. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  5230. lastOffset = offset;
  5231. offset = (offset << 1) + 1;
  5232. if (offset <= 0) {
  5233. offset = maxOffset;
  5234. }
  5235. }
  5236. if (offset > maxOffset) {
  5237. offset = maxOffset;
  5238. }
  5239. lastOffset += hint;
  5240. offset += hint;
  5241. } else {
  5242. maxOffset = hint + 1;
  5243. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  5244. lastOffset = offset;
  5245. offset = (offset << 1) + 1;
  5246. if (offset <= 0) {
  5247. offset = maxOffset;
  5248. }
  5249. }
  5250. if (offset > maxOffset) {
  5251. offset = maxOffset;
  5252. }
  5253. var tmp = lastOffset;
  5254. lastOffset = hint - offset;
  5255. offset = hint - tmp;
  5256. }
  5257. lastOffset++;
  5258. while (lastOffset < offset) {
  5259. var m = lastOffset + (offset - lastOffset >>> 1);
  5260. if (compare(value, array[start + m]) > 0) {
  5261. lastOffset = m + 1;
  5262. } else {
  5263. offset = m;
  5264. }
  5265. }
  5266. return offset;
  5267. }
  5268. function gallopRight(value, array, start, length, hint, compare) {
  5269. var lastOffset = 0;
  5270. var maxOffset = 0;
  5271. var offset = 1;
  5272. if (compare(value, array[start + hint]) < 0) {
  5273. maxOffset = hint + 1;
  5274. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  5275. lastOffset = offset;
  5276. offset = (offset << 1) + 1;
  5277. if (offset <= 0) {
  5278. offset = maxOffset;
  5279. }
  5280. }
  5281. if (offset > maxOffset) {
  5282. offset = maxOffset;
  5283. }
  5284. var tmp = lastOffset;
  5285. lastOffset = hint - offset;
  5286. offset = hint - tmp;
  5287. } else {
  5288. maxOffset = length - hint;
  5289. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  5290. lastOffset = offset;
  5291. offset = (offset << 1) + 1;
  5292. if (offset <= 0) {
  5293. offset = maxOffset;
  5294. }
  5295. }
  5296. if (offset > maxOffset) {
  5297. offset = maxOffset;
  5298. }
  5299. lastOffset += hint;
  5300. offset += hint;
  5301. }
  5302. lastOffset++;
  5303. while (lastOffset < offset) {
  5304. var m = lastOffset + (offset - lastOffset >>> 1);
  5305. if (compare(value, array[start + m]) < 0) {
  5306. offset = m;
  5307. } else {
  5308. lastOffset = m + 1;
  5309. }
  5310. }
  5311. return offset;
  5312. }
  5313. function TimSort(array, compare) {
  5314. var minGallop = DEFAULT_MIN_GALLOPING;
  5315. var runStart;
  5316. var runLength;
  5317. var stackSize = 0;
  5318. var tmp = [];
  5319. runStart = [];
  5320. runLength = [];
  5321. function pushRun(_runStart, _runLength) {
  5322. runStart[stackSize] = _runStart;
  5323. runLength[stackSize] = _runLength;
  5324. stackSize += 1;
  5325. }
  5326. function mergeRuns() {
  5327. while (stackSize > 1) {
  5328. var n = stackSize - 2;
  5329. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  5330. if (runLength[n - 1] < runLength[n + 1]) {
  5331. n--;
  5332. }
  5333. } else if (runLength[n] > runLength[n + 1]) {
  5334. break;
  5335. }
  5336. mergeAt(n);
  5337. }
  5338. }
  5339. function forceMergeRuns() {
  5340. while (stackSize > 1) {
  5341. var n = stackSize - 2;
  5342. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  5343. n--;
  5344. }
  5345. mergeAt(n);
  5346. }
  5347. }
  5348. function mergeAt(i) {
  5349. var start1 = runStart[i];
  5350. var length1 = runLength[i];
  5351. var start2 = runStart[i + 1];
  5352. var length2 = runLength[i + 1];
  5353. runLength[i] = length1 + length2;
  5354. if (i === stackSize - 3) {
  5355. runStart[i + 1] = runStart[i + 2];
  5356. runLength[i + 1] = runLength[i + 2];
  5357. }
  5358. stackSize--;
  5359. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  5360. start1 += k;
  5361. length1 -= k;
  5362. if (length1 === 0) {
  5363. return;
  5364. }
  5365. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  5366. if (length2 === 0) {
  5367. return;
  5368. }
  5369. if (length1 <= length2) {
  5370. mergeLow(start1, length1, start2, length2);
  5371. } else {
  5372. mergeHigh(start1, length1, start2, length2);
  5373. }
  5374. }
  5375. function mergeLow(start1, length1, start2, length2) {
  5376. var i = 0;
  5377. for (i = 0; i < length1; i++) {
  5378. tmp[i] = array[start1 + i];
  5379. }
  5380. var cursor1 = 0;
  5381. var cursor2 = start2;
  5382. var dest = start1;
  5383. array[dest++] = array[cursor2++];
  5384. if (--length2 === 0) {
  5385. for (i = 0; i < length1; i++) {
  5386. array[dest + i] = tmp[cursor1 + i];
  5387. }
  5388. return;
  5389. }
  5390. if (length1 === 1) {
  5391. for (i = 0; i < length2; i++) {
  5392. array[dest + i] = array[cursor2 + i];
  5393. }
  5394. array[dest + length2] = tmp[cursor1];
  5395. return;
  5396. }
  5397. var _minGallop = minGallop;
  5398. var count1;
  5399. var count2;
  5400. var exit;
  5401. while (1) {
  5402. count1 = 0;
  5403. count2 = 0;
  5404. exit = false;
  5405. do {
  5406. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  5407. array[dest++] = array[cursor2++];
  5408. count2++;
  5409. count1 = 0;
  5410. if (--length2 === 0) {
  5411. exit = true;
  5412. break;
  5413. }
  5414. } else {
  5415. array[dest++] = tmp[cursor1++];
  5416. count1++;
  5417. count2 = 0;
  5418. if (--length1 === 1) {
  5419. exit = true;
  5420. break;
  5421. }
  5422. }
  5423. } while ((count1 | count2) < _minGallop);
  5424. if (exit) {
  5425. break;
  5426. }
  5427. do {
  5428. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  5429. if (count1 !== 0) {
  5430. for (i = 0; i < count1; i++) {
  5431. array[dest + i] = tmp[cursor1 + i];
  5432. }
  5433. dest += count1;
  5434. cursor1 += count1;
  5435. length1 -= count1;
  5436. if (length1 <= 1) {
  5437. exit = true;
  5438. break;
  5439. }
  5440. }
  5441. array[dest++] = array[cursor2++];
  5442. if (--length2 === 0) {
  5443. exit = true;
  5444. break;
  5445. }
  5446. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  5447. if (count2 !== 0) {
  5448. for (i = 0; i < count2; i++) {
  5449. array[dest + i] = array[cursor2 + i];
  5450. }
  5451. dest += count2;
  5452. cursor2 += count2;
  5453. length2 -= count2;
  5454. if (length2 === 0) {
  5455. exit = true;
  5456. break;
  5457. }
  5458. }
  5459. array[dest++] = tmp[cursor1++];
  5460. if (--length1 === 1) {
  5461. exit = true;
  5462. break;
  5463. }
  5464. _minGallop--;
  5465. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5466. if (exit) {
  5467. break;
  5468. }
  5469. if (_minGallop < 0) {
  5470. _minGallop = 0;
  5471. }
  5472. _minGallop += 2;
  5473. }
  5474. minGallop = _minGallop;
  5475. minGallop < 1 && (minGallop = 1);
  5476. if (length1 === 1) {
  5477. for (i = 0; i < length2; i++) {
  5478. array[dest + i] = array[cursor2 + i];
  5479. }
  5480. array[dest + length2] = tmp[cursor1];
  5481. } else if (length1 === 0) {
  5482. throw new Error(); // throw new Error('mergeLow preconditions were not respected');
  5483. } else {
  5484. for (i = 0; i < length1; i++) {
  5485. array[dest + i] = tmp[cursor1 + i];
  5486. }
  5487. }
  5488. }
  5489. function mergeHigh(start1, length1, start2, length2) {
  5490. var i = 0;
  5491. for (i = 0; i < length2; i++) {
  5492. tmp[i] = array[start2 + i];
  5493. }
  5494. var cursor1 = start1 + length1 - 1;
  5495. var cursor2 = length2 - 1;
  5496. var dest = start2 + length2 - 1;
  5497. var customCursor = 0;
  5498. var customDest = 0;
  5499. array[dest--] = array[cursor1--];
  5500. if (--length1 === 0) {
  5501. customCursor = dest - (length2 - 1);
  5502. for (i = 0; i < length2; i++) {
  5503. array[customCursor + i] = tmp[i];
  5504. }
  5505. return;
  5506. }
  5507. if (length2 === 1) {
  5508. dest -= length1;
  5509. cursor1 -= length1;
  5510. customDest = dest + 1;
  5511. customCursor = cursor1 + 1;
  5512. for (i = length1 - 1; i >= 0; i--) {
  5513. array[customDest + i] = array[customCursor + i];
  5514. }
  5515. array[dest] = tmp[cursor2];
  5516. return;
  5517. }
  5518. var _minGallop = minGallop;
  5519. while (true) {
  5520. var count1 = 0;
  5521. var count2 = 0;
  5522. var exit = false;
  5523. do {
  5524. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  5525. array[dest--] = array[cursor1--];
  5526. count1++;
  5527. count2 = 0;
  5528. if (--length1 === 0) {
  5529. exit = true;
  5530. break;
  5531. }
  5532. } else {
  5533. array[dest--] = tmp[cursor2--];
  5534. count2++;
  5535. count1 = 0;
  5536. if (--length2 === 1) {
  5537. exit = true;
  5538. break;
  5539. }
  5540. }
  5541. } while ((count1 | count2) < _minGallop);
  5542. if (exit) {
  5543. break;
  5544. }
  5545. do {
  5546. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  5547. if (count1 !== 0) {
  5548. dest -= count1;
  5549. cursor1 -= count1;
  5550. length1 -= count1;
  5551. customDest = dest + 1;
  5552. customCursor = cursor1 + 1;
  5553. for (i = count1 - 1; i >= 0; i--) {
  5554. array[customDest + i] = array[customCursor + i];
  5555. }
  5556. if (length1 === 0) {
  5557. exit = true;
  5558. break;
  5559. }
  5560. }
  5561. array[dest--] = tmp[cursor2--];
  5562. if (--length2 === 1) {
  5563. exit = true;
  5564. break;
  5565. }
  5566. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  5567. if (count2 !== 0) {
  5568. dest -= count2;
  5569. cursor2 -= count2;
  5570. length2 -= count2;
  5571. customDest = dest + 1;
  5572. customCursor = cursor2 + 1;
  5573. for (i = 0; i < count2; i++) {
  5574. array[customDest + i] = tmp[customCursor + i];
  5575. }
  5576. if (length2 <= 1) {
  5577. exit = true;
  5578. break;
  5579. }
  5580. }
  5581. array[dest--] = array[cursor1--];
  5582. if (--length1 === 0) {
  5583. exit = true;
  5584. break;
  5585. }
  5586. _minGallop--;
  5587. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5588. if (exit) {
  5589. break;
  5590. }
  5591. if (_minGallop < 0) {
  5592. _minGallop = 0;
  5593. }
  5594. _minGallop += 2;
  5595. }
  5596. minGallop = _minGallop;
  5597. if (minGallop < 1) {
  5598. minGallop = 1;
  5599. }
  5600. if (length2 === 1) {
  5601. dest -= length1;
  5602. cursor1 -= length1;
  5603. customDest = dest + 1;
  5604. customCursor = cursor1 + 1;
  5605. for (i = length1 - 1; i >= 0; i--) {
  5606. array[customDest + i] = array[customCursor + i];
  5607. }
  5608. array[dest] = tmp[cursor2];
  5609. } else if (length2 === 0) {
  5610. throw new Error(); // throw new Error('mergeHigh preconditions were not respected');
  5611. } else {
  5612. customCursor = dest - (length2 - 1);
  5613. for (i = 0; i < length2; i++) {
  5614. array[customCursor + i] = tmp[i];
  5615. }
  5616. }
  5617. }
  5618. this.mergeRuns = mergeRuns;
  5619. this.forceMergeRuns = forceMergeRuns;
  5620. this.pushRun = pushRun;
  5621. }
  5622. function sort(array, compare, lo, hi) {
  5623. if (!lo) {
  5624. lo = 0;
  5625. }
  5626. if (!hi) {
  5627. hi = array.length;
  5628. }
  5629. var remaining = hi - lo;
  5630. if (remaining < 2) {
  5631. return;
  5632. }
  5633. var runLength = 0;
  5634. if (remaining < DEFAULT_MIN_MERGE) {
  5635. runLength = makeAscendingRun(array, lo, hi, compare);
  5636. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  5637. return;
  5638. }
  5639. var ts = new TimSort(array, compare);
  5640. var minRun = minRunLength(remaining);
  5641. do {
  5642. runLength = makeAscendingRun(array, lo, hi, compare);
  5643. if (runLength < minRun) {
  5644. var force = remaining;
  5645. if (force > minRun) {
  5646. force = minRun;
  5647. }
  5648. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  5649. runLength = force;
  5650. }
  5651. ts.pushRun(lo, runLength);
  5652. ts.mergeRuns();
  5653. remaining -= runLength;
  5654. lo += runLength;
  5655. } while (remaining !== 0);
  5656. ts.forceMergeRuns();
  5657. }
  5658. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  5659. function shapeCompareFunc(a, b) {
  5660. if (a.zlevel === b.zlevel) {
  5661. if (a.z === b.z) {
  5662. // if (a.z2 === b.z2) {
  5663. // // FIXME Slow has renderidx compare
  5664. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  5665. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  5666. // return a.__renderidx - b.__renderidx;
  5667. // }
  5668. return a.z2 - b.z2;
  5669. }
  5670. return a.z - b.z;
  5671. }
  5672. return a.zlevel - b.zlevel;
  5673. }
  5674. /**
  5675. * 内容仓库 (M)
  5676. * @alias module:zrender/Storage
  5677. * @constructor
  5678. */
  5679. var Storage = function () {
  5680. // jshint ignore:line
  5681. this._roots = [];
  5682. this._displayList = [];
  5683. this._displayListLen = 0;
  5684. };
  5685. Storage.prototype = {
  5686. constructor: Storage,
  5687. /**
  5688. * @param {Function} cb
  5689. *
  5690. */
  5691. traverse: function (cb, context) {
  5692. for (var i = 0; i < this._roots.length; i++) {
  5693. this._roots[i].traverse(cb, context);
  5694. }
  5695. },
  5696. /**
  5697. * 返回所有图形的绘制队列
  5698. * @param {boolean} [update=false] 是否在返回前更新该数组
  5699. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  5700. *
  5701. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  5702. * @return {Array.<module:zrender/graphic/Displayable>}
  5703. */
  5704. getDisplayList: function (update, includeIgnore) {
  5705. includeIgnore = includeIgnore || false;
  5706. if (update) {
  5707. this.updateDisplayList(includeIgnore);
  5708. }
  5709. return this._displayList;
  5710. },
  5711. /**
  5712. * 更新图形的绘制队列。
  5713. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  5714. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  5715. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  5716. */
  5717. updateDisplayList: function (includeIgnore) {
  5718. this._displayListLen = 0;
  5719. var roots = this._roots;
  5720. var displayList = this._displayList;
  5721. for (var i = 0, len = roots.length; i < len; i++) {
  5722. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  5723. }
  5724. displayList.length = this._displayListLen;
  5725. env$1.canvasSupported && sort(displayList, shapeCompareFunc);
  5726. },
  5727. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  5728. if (el.ignore && !includeIgnore) {
  5729. return;
  5730. }
  5731. el.beforeUpdate();
  5732. if (el.__dirty) {
  5733. el.update();
  5734. }
  5735. el.afterUpdate();
  5736. var userSetClipPath = el.clipPath;
  5737. if (userSetClipPath) {
  5738. // FIXME 效率影响
  5739. if (clipPaths) {
  5740. clipPaths = clipPaths.slice();
  5741. } else {
  5742. clipPaths = [];
  5743. }
  5744. var currentClipPath = userSetClipPath;
  5745. var parentClipPath = el; // Recursively add clip path
  5746. while (currentClipPath) {
  5747. // clipPath 的变换是基于使用这个 clipPath 的元素
  5748. currentClipPath.parent = parentClipPath;
  5749. currentClipPath.updateTransform();
  5750. clipPaths.push(currentClipPath);
  5751. parentClipPath = currentClipPath;
  5752. currentClipPath = currentClipPath.clipPath;
  5753. }
  5754. }
  5755. if (el.isGroup) {
  5756. var children = el._children;
  5757. for (var i = 0; i < children.length; i++) {
  5758. var child = children[i]; // Force to mark as dirty if group is dirty
  5759. // FIXME __dirtyPath ?
  5760. if (el.__dirty) {
  5761. child.__dirty = true;
  5762. }
  5763. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  5764. } // Mark group clean here
  5765. el.__dirty = false;
  5766. } else {
  5767. el.__clipPaths = clipPaths;
  5768. this._displayList[this._displayListLen++] = el;
  5769. }
  5770. },
  5771. /**
  5772. * 添加图形(Shape)或者组(Group)到根节点
  5773. * @param {module:zrender/Element} el
  5774. */
  5775. addRoot: function (el) {
  5776. if (el.__storage === this) {
  5777. return;
  5778. }
  5779. if (el instanceof Group) {
  5780. el.addChildrenToStorage(this);
  5781. }
  5782. this.addToStorage(el);
  5783. this._roots.push(el);
  5784. },
  5785. /**
  5786. * 删除指定的图形(Shape)或者组(Group)
  5787. * @param {string|Array.<string>} [el] 如果为空清空整个Storage
  5788. */
  5789. delRoot: function (el) {
  5790. if (el == null) {
  5791. // 不指定el清空
  5792. for (var i = 0; i < this._roots.length; i++) {
  5793. var root = this._roots[i];
  5794. if (root instanceof Group) {
  5795. root.delChildrenFromStorage(this);
  5796. }
  5797. }
  5798. this._roots = [];
  5799. this._displayList = [];
  5800. this._displayListLen = 0;
  5801. return;
  5802. }
  5803. if (el instanceof Array) {
  5804. for (var i = 0, l = el.length; i < l; i++) {
  5805. this.delRoot(el[i]);
  5806. }
  5807. return;
  5808. }
  5809. var idx = indexOf(this._roots, el);
  5810. if (idx >= 0) {
  5811. this.delFromStorage(el);
  5812. this._roots.splice(idx, 1);
  5813. if (el instanceof Group) {
  5814. el.delChildrenFromStorage(this);
  5815. }
  5816. }
  5817. },
  5818. addToStorage: function (el) {
  5819. if (el) {
  5820. el.__storage = this;
  5821. el.dirty(false);
  5822. }
  5823. return this;
  5824. },
  5825. delFromStorage: function (el) {
  5826. if (el) {
  5827. el.__storage = null;
  5828. }
  5829. return this;
  5830. },
  5831. /**
  5832. * 清空并且释放Storage
  5833. */
  5834. dispose: function () {
  5835. this._renderList = this._roots = null;
  5836. },
  5837. displayableSortFunc: shapeCompareFunc
  5838. };
  5839. var SHADOW_PROPS = {
  5840. 'shadowBlur': 1,
  5841. 'shadowOffsetX': 1,
  5842. 'shadowOffsetY': 1,
  5843. 'textShadowBlur': 1,
  5844. 'textShadowOffsetX': 1,
  5845. 'textShadowOffsetY': 1,
  5846. 'textBoxShadowBlur': 1,
  5847. 'textBoxShadowOffsetX': 1,
  5848. 'textBoxShadowOffsetY': 1
  5849. };
  5850. var fixShadow = function (ctx, propName, value) {
  5851. if (SHADOW_PROPS.hasOwnProperty(propName)) {
  5852. return value *= ctx.dpr;
  5853. }
  5854. return value;
  5855. };
  5856. var ContextCachedBy = {
  5857. NONE: 0,
  5858. STYLE_BIND: 1,
  5859. PLAIN_TEXT: 2
  5860. }; // Avoid confused with 0/false.
  5861. var WILL_BE_RESTORED = 9;
  5862. 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);
  5863. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  5864. var Style = function (opts) {
  5865. this.extendFrom(opts, false);
  5866. };
  5867. function createLinearGradient(ctx, obj, rect) {
  5868. var x = obj.x == null ? 0 : obj.x;
  5869. var x2 = obj.x2 == null ? 1 : obj.x2;
  5870. var y = obj.y == null ? 0 : obj.y;
  5871. var y2 = obj.y2 == null ? 0 : obj.y2;
  5872. if (!obj.global) {
  5873. x = x * rect.width + rect.x;
  5874. x2 = x2 * rect.width + rect.x;
  5875. y = y * rect.height + rect.y;
  5876. y2 = y2 * rect.height + rect.y;
  5877. } // Fix NaN when rect is Infinity
  5878. x = isNaN(x) ? 0 : x;
  5879. x2 = isNaN(x2) ? 1 : x2;
  5880. y = isNaN(y) ? 0 : y;
  5881. y2 = isNaN(y2) ? 0 : y2;
  5882. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  5883. return canvasGradient;
  5884. }
  5885. function createRadialGradient(ctx, obj, rect) {
  5886. var width = rect.width;
  5887. var height = rect.height;
  5888. var min = Math.min(width, height);
  5889. var x = obj.x == null ? 0.5 : obj.x;
  5890. var y = obj.y == null ? 0.5 : obj.y;
  5891. var r = obj.r == null ? 0.5 : obj.r;
  5892. if (!obj.global) {
  5893. x = x * width + rect.x;
  5894. y = y * height + rect.y;
  5895. r = r * min;
  5896. }
  5897. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  5898. return canvasGradient;
  5899. }
  5900. Style.prototype = {
  5901. constructor: Style,
  5902. /**
  5903. * @type {string}
  5904. */
  5905. fill: '#000',
  5906. /**
  5907. * @type {string}
  5908. */
  5909. stroke: null,
  5910. /**
  5911. * @type {number}
  5912. */
  5913. opacity: 1,
  5914. /**
  5915. * @type {number}
  5916. */
  5917. fillOpacity: null,
  5918. /**
  5919. * @type {number}
  5920. */
  5921. strokeOpacity: null,
  5922. /**
  5923. * `true` is not supported.
  5924. * `false`/`null`/`undefined` are the same.
  5925. * `false` is used to remove lineDash in some
  5926. * case that `null`/`undefined` can not be set.
  5927. * (e.g., emphasis.lineStyle in echarts)
  5928. * @type {Array.<number>|boolean}
  5929. */
  5930. lineDash: null,
  5931. /**
  5932. * @type {number}
  5933. */
  5934. lineDashOffset: 0,
  5935. /**
  5936. * @type {number}
  5937. */
  5938. shadowBlur: 0,
  5939. /**
  5940. * @type {number}
  5941. */
  5942. shadowOffsetX: 0,
  5943. /**
  5944. * @type {number}
  5945. */
  5946. shadowOffsetY: 0,
  5947. /**
  5948. * @type {number}
  5949. */
  5950. lineWidth: 1,
  5951. /**
  5952. * If stroke ignore scale
  5953. * @type {Boolean}
  5954. */
  5955. strokeNoScale: false,
  5956. // Bounding rect text configuration
  5957. // Not affected by element transform
  5958. /**
  5959. * @type {string}
  5960. */
  5961. text: null,
  5962. /**
  5963. * If `fontSize` or `fontFamily` exists, `font` will be reset by
  5964. * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.
  5965. * So do not visit it directly in upper application (like echarts),
  5966. * but use `contain/text#makeFont` instead.
  5967. * @type {string}
  5968. */
  5969. font: null,
  5970. /**
  5971. * The same as font. Use font please.
  5972. * @deprecated
  5973. * @type {string}
  5974. */
  5975. textFont: null,
  5976. /**
  5977. * It helps merging respectively, rather than parsing an entire font string.
  5978. * @type {string}
  5979. */
  5980. fontStyle: null,
  5981. /**
  5982. * It helps merging respectively, rather than parsing an entire font string.
  5983. * @type {string}
  5984. */
  5985. fontWeight: null,
  5986. /**
  5987. * It helps merging respectively, rather than parsing an entire font string.
  5988. * Should be 12 but not '12px'.
  5989. * @type {number}
  5990. */
  5991. fontSize: null,
  5992. /**
  5993. * It helps merging respectively, rather than parsing an entire font string.
  5994. * @type {string}
  5995. */
  5996. fontFamily: null,
  5997. /**
  5998. * Reserved for special functinality, like 'hr'.
  5999. * @type {string}
  6000. */
  6001. textTag: null,
  6002. /**
  6003. * @type {string}
  6004. */
  6005. textFill: '#000',
  6006. /**
  6007. * @type {string}
  6008. */
  6009. textStroke: null,
  6010. /**
  6011. * @type {number}
  6012. */
  6013. textWidth: null,
  6014. /**
  6015. * Only for textBackground.
  6016. * @type {number}
  6017. */
  6018. textHeight: null,
  6019. /**
  6020. * textStroke may be set as some color as a default
  6021. * value in upper applicaion, where the default value
  6022. * of textStrokeWidth should be 0 to make sure that
  6023. * user can choose to do not use text stroke.
  6024. * @type {number}
  6025. */
  6026. textStrokeWidth: 0,
  6027. /**
  6028. * @type {number}
  6029. */
  6030. textLineHeight: null,
  6031. /**
  6032. * 'inside', 'left', 'right', 'top', 'bottom'
  6033. * [x, y]
  6034. * Based on x, y of rect.
  6035. * @type {string|Array.<number>}
  6036. * @default 'inside'
  6037. */
  6038. textPosition: 'inside',
  6039. /**
  6040. * If not specified, use the boundingRect of a `displayable`.
  6041. * @type {Object}
  6042. */
  6043. textRect: null,
  6044. /**
  6045. * [x, y]
  6046. * @type {Array.<number>}
  6047. */
  6048. textOffset: null,
  6049. /**
  6050. * @type {string}
  6051. */
  6052. textAlign: null,
  6053. /**
  6054. * @type {string}
  6055. */
  6056. textVerticalAlign: null,
  6057. /**
  6058. * @type {number}
  6059. */
  6060. textDistance: 5,
  6061. /**
  6062. * @type {string}
  6063. */
  6064. textShadowColor: 'transparent',
  6065. /**
  6066. * @type {number}
  6067. */
  6068. textShadowBlur: 0,
  6069. /**
  6070. * @type {number}
  6071. */
  6072. textShadowOffsetX: 0,
  6073. /**
  6074. * @type {number}
  6075. */
  6076. textShadowOffsetY: 0,
  6077. /**
  6078. * @type {string}
  6079. */
  6080. textBoxShadowColor: 'transparent',
  6081. /**
  6082. * @type {number}
  6083. */
  6084. textBoxShadowBlur: 0,
  6085. /**
  6086. * @type {number}
  6087. */
  6088. textBoxShadowOffsetX: 0,
  6089. /**
  6090. * @type {number}
  6091. */
  6092. textBoxShadowOffsetY: 0,
  6093. /**
  6094. * Whether transform text.
  6095. * Only available in Path and Image element,
  6096. * where the text is called as `RectText`.
  6097. * @type {boolean}
  6098. */
  6099. transformText: false,
  6100. /**
  6101. * Text rotate around position of Path or Image.
  6102. * The origin of the rotation can be specified by `textOrigin`.
  6103. * Only available in Path and Image element,
  6104. * where the text is called as `RectText`.
  6105. */
  6106. textRotation: 0,
  6107. /**
  6108. * Text origin of text rotation.
  6109. * Useful in the case like label rotation of circular symbol.
  6110. * Only available in Path and Image element, where the text is called
  6111. * as `RectText` and the element is called as "host element".
  6112. * The value can be:
  6113. * + If specified as a coordinate like `[10, 40]`, it is the `[x, y]`
  6114. * base on the left-top corner of the rect of its host element.
  6115. * + If specified as a string `center`, it is the center of the rect of
  6116. * its host element.
  6117. * + By default, this origin is the `textPosition`.
  6118. * @type {string|Array.<number>}
  6119. */
  6120. textOrigin: null,
  6121. /**
  6122. * @type {string}
  6123. */
  6124. textBackgroundColor: null,
  6125. /**
  6126. * @type {string}
  6127. */
  6128. textBorderColor: null,
  6129. /**
  6130. * @type {number}
  6131. */
  6132. textBorderWidth: 0,
  6133. /**
  6134. * @type {number}
  6135. */
  6136. textBorderRadius: 0,
  6137. /**
  6138. * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`
  6139. * @type {number|Array.<number>}
  6140. */
  6141. textPadding: null,
  6142. /**
  6143. * Text styles for rich text.
  6144. * @type {Object}
  6145. */
  6146. rich: null,
  6147. /**
  6148. * {outerWidth, outerHeight, ellipsis, placeholder}
  6149. * @type {Object}
  6150. */
  6151. truncate: null,
  6152. /**
  6153. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  6154. * @type {string}
  6155. */
  6156. blend: null,
  6157. /**
  6158. * @param {CanvasRenderingContext2D} ctx
  6159. */
  6160. bind: function (ctx, el, prevEl) {
  6161. var style = this;
  6162. var prevStyle = prevEl && prevEl.style; // If no prevStyle, it means first draw.
  6163. // Only apply cache if the last time cachced by this function.
  6164. var notCheckCache = !prevStyle || ctx.__attrCachedBy !== ContextCachedBy.STYLE_BIND;
  6165. ctx.__attrCachedBy = ContextCachedBy.STYLE_BIND;
  6166. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6167. var prop = STYLE_COMMON_PROPS[i];
  6168. var styleName = prop[0];
  6169. if (notCheckCache || style[styleName] !== prevStyle[styleName]) {
  6170. // FIXME Invalid property value will cause style leak from previous element.
  6171. ctx[styleName] = fixShadow(ctx, styleName, style[styleName] || prop[1]);
  6172. }
  6173. }
  6174. if (notCheckCache || style.fill !== prevStyle.fill) {
  6175. ctx.fillStyle = style.fill;
  6176. }
  6177. if (notCheckCache || style.stroke !== prevStyle.stroke) {
  6178. ctx.strokeStyle = style.stroke;
  6179. }
  6180. if (notCheckCache || style.opacity !== prevStyle.opacity) {
  6181. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  6182. }
  6183. if (notCheckCache || style.blend !== prevStyle.blend) {
  6184. ctx.globalCompositeOperation = style.blend || 'source-over';
  6185. }
  6186. if (this.hasStroke()) {
  6187. var lineWidth = style.lineWidth;
  6188. ctx.lineWidth = lineWidth / (this.strokeNoScale && el && el.getLineScale ? el.getLineScale() : 1);
  6189. }
  6190. },
  6191. hasFill: function () {
  6192. var fill = this.fill;
  6193. return fill != null && fill !== 'none';
  6194. },
  6195. hasStroke: function () {
  6196. var stroke = this.stroke;
  6197. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  6198. },
  6199. /**
  6200. * Extend from other style
  6201. * @param {zrender/graphic/Style} otherStyle
  6202. * @param {boolean} overwrite true: overwrirte any way.
  6203. * false: overwrite only when !target.hasOwnProperty
  6204. * others: overwrite when property is not null/undefined.
  6205. */
  6206. extendFrom: function (otherStyle, overwrite) {
  6207. if (otherStyle) {
  6208. for (var name in otherStyle) {
  6209. if (otherStyle.hasOwnProperty(name) && (overwrite === true || (overwrite === false ? !this.hasOwnProperty(name) : otherStyle[name] != null))) {
  6210. this[name] = otherStyle[name];
  6211. }
  6212. }
  6213. }
  6214. },
  6215. /**
  6216. * Batch setting style with a given object
  6217. * @param {Object|string} obj
  6218. * @param {*} [obj]
  6219. */
  6220. set: function (obj, value) {
  6221. if (typeof obj === 'string') {
  6222. this[obj] = value;
  6223. } else {
  6224. this.extendFrom(obj, true);
  6225. }
  6226. },
  6227. /**
  6228. * Clone
  6229. * @return {zrender/graphic/Style} [description]
  6230. */
  6231. clone: function () {
  6232. var newStyle = new this.constructor();
  6233. newStyle.extendFrom(this, true);
  6234. return newStyle;
  6235. },
  6236. getGradient: function (ctx, obj, rect) {
  6237. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  6238. var canvasGradient = method(ctx, obj, rect);
  6239. var colorStops = obj.colorStops;
  6240. for (var i = 0; i < colorStops.length; i++) {
  6241. canvasGradient.addColorStop(colorStops[i].offset, colorStops[i].color);
  6242. }
  6243. return canvasGradient;
  6244. }
  6245. };
  6246. var styleProto = Style.prototype;
  6247. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6248. var prop = STYLE_COMMON_PROPS[i];
  6249. if (!(prop[0] in styleProto)) {
  6250. styleProto[prop[0]] = prop[1];
  6251. }
  6252. } // Provide for others
  6253. Style.getGradient = styleProto.getGradient;
  6254. var Pattern = function (image, repeat) {
  6255. // Should do nothing more in this constructor. Because gradient can be
  6256. // declard by `color: {image: ...}`, where this constructor will not be called.
  6257. this.image = image;
  6258. this.repeat = repeat; // Can be cloned
  6259. this.type = 'pattern';
  6260. };
  6261. Pattern.prototype.getCanvasPattern = function (ctx) {
  6262. return ctx.createPattern(this.image, this.repeat || 'repeat');
  6263. };
  6264. /**
  6265. * @module zrender/Layer
  6266. * @author pissang(https://www.github.com/pissang)
  6267. */
  6268. function returnFalse() {
  6269. return false;
  6270. }
  6271. /**
  6272. * 创建dom
  6273. *
  6274. * @inner
  6275. * @param {string} id dom id 待用
  6276. * @param {Painter} painter painter instance
  6277. * @param {number} number
  6278. */
  6279. function createDom(id, painter, dpr) {
  6280. var newDom = createCanvas();
  6281. var width = painter.getWidth();
  6282. var height = painter.getHeight();
  6283. var newDomStyle = newDom.style;
  6284. if (newDomStyle) {
  6285. // In node or some other non-browser environment
  6286. newDomStyle.position = 'absolute';
  6287. newDomStyle.left = 0;
  6288. newDomStyle.top = 0;
  6289. newDomStyle.width = width + 'px';
  6290. newDomStyle.height = height + 'px';
  6291. newDom.setAttribute('data-zr-dom-id', id);
  6292. }
  6293. newDom.width = width * dpr;
  6294. newDom.height = height * dpr;
  6295. return newDom;
  6296. }
  6297. /**
  6298. * @alias module:zrender/Layer
  6299. * @constructor
  6300. * @extends module:zrender/mixin/Transformable
  6301. * @param {string} id
  6302. * @param {module:zrender/Painter} painter
  6303. * @param {number} [dpr]
  6304. */
  6305. var Layer = function (id, painter, dpr) {
  6306. var dom;
  6307. dpr = dpr || devicePixelRatio;
  6308. if (typeof id === 'string') {
  6309. dom = createDom(id, painter, dpr);
  6310. } // Not using isDom because in node it will return false
  6311. else if (isObject$1(id)) {
  6312. dom = id;
  6313. id = dom.id;
  6314. }
  6315. this.id = id;
  6316. this.dom = dom;
  6317. var domStyle = dom.style;
  6318. if (domStyle) {
  6319. // Not in node
  6320. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  6321. domStyle['-webkit-user-select'] = 'none';
  6322. domStyle['user-select'] = 'none';
  6323. domStyle['-webkit-touch-callout'] = 'none';
  6324. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  6325. domStyle['padding'] = 0; // eslint-disable-line dot-notation
  6326. domStyle['margin'] = 0; // eslint-disable-line dot-notation
  6327. domStyle['border-width'] = 0;
  6328. }
  6329. this.domBack = null;
  6330. this.ctxBack = null;
  6331. this.painter = painter;
  6332. this.config = null; // Configs
  6333. /**
  6334. * 每次清空画布的颜色
  6335. * @type {string}
  6336. * @default 0
  6337. */
  6338. this.clearColor = 0;
  6339. /**
  6340. * 是否开启动态模糊
  6341. * @type {boolean}
  6342. * @default false
  6343. */
  6344. this.motionBlur = false;
  6345. /**
  6346. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  6347. * @type {number}
  6348. * @default 0.7
  6349. */
  6350. this.lastFrameAlpha = 0.7;
  6351. /**
  6352. * Layer dpr
  6353. * @type {number}
  6354. */
  6355. this.dpr = dpr;
  6356. };
  6357. Layer.prototype = {
  6358. constructor: Layer,
  6359. __dirty: true,
  6360. __used: false,
  6361. __drawIndex: 0,
  6362. __startIndex: 0,
  6363. __endIndex: 0,
  6364. incremental: false,
  6365. getElementCount: function () {
  6366. return this.__endIndex - this.__startIndex;
  6367. },
  6368. initContext: function () {
  6369. this.ctx = this.dom.getContext('2d');
  6370. this.ctx.dpr = this.dpr;
  6371. },
  6372. createBackBuffer: function () {
  6373. var dpr = this.dpr;
  6374. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  6375. this.ctxBack = this.domBack.getContext('2d');
  6376. if (dpr !== 1) {
  6377. this.ctxBack.scale(dpr, dpr);
  6378. }
  6379. },
  6380. /**
  6381. * @param {number} width
  6382. * @param {number} height
  6383. */
  6384. resize: function (width, height) {
  6385. var dpr = this.dpr;
  6386. var dom = this.dom;
  6387. var domStyle = dom.style;
  6388. var domBack = this.domBack;
  6389. if (domStyle) {
  6390. domStyle.width = width + 'px';
  6391. domStyle.height = height + 'px';
  6392. }
  6393. dom.width = width * dpr;
  6394. dom.height = height * dpr;
  6395. if (domBack) {
  6396. domBack.width = width * dpr;
  6397. domBack.height = height * dpr;
  6398. if (dpr !== 1) {
  6399. this.ctxBack.scale(dpr, dpr);
  6400. }
  6401. }
  6402. },
  6403. /**
  6404. * 清空该层画布
  6405. * @param {boolean} [clearAll]=false Clear all with out motion blur
  6406. * @param {Color} [clearColor]
  6407. */
  6408. clear: function (clearAll, clearColor) {
  6409. var dom = this.dom;
  6410. var ctx = this.ctx;
  6411. var width = dom.width;
  6412. var height = dom.height;
  6413. var clearColor = clearColor || this.clearColor;
  6414. var haveMotionBLur = this.motionBlur && !clearAll;
  6415. var lastFrameAlpha = this.lastFrameAlpha;
  6416. var dpr = this.dpr;
  6417. if (haveMotionBLur) {
  6418. if (!this.domBack) {
  6419. this.createBackBuffer();
  6420. }
  6421. this.ctxBack.globalCompositeOperation = 'copy';
  6422. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  6423. }
  6424. ctx.clearRect(0, 0, width, height);
  6425. if (clearColor && clearColor !== 'transparent') {
  6426. var clearColorGradientOrPattern; // Gradient
  6427. if (clearColor.colorStops) {
  6428. // Cache canvas gradient
  6429. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  6430. x: 0,
  6431. y: 0,
  6432. width: width,
  6433. height: height
  6434. });
  6435. clearColor.__canvasGradient = clearColorGradientOrPattern;
  6436. } // Pattern
  6437. else if (clearColor.image) {
  6438. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  6439. }
  6440. ctx.save();
  6441. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  6442. ctx.fillRect(0, 0, width, height);
  6443. ctx.restore();
  6444. }
  6445. if (haveMotionBLur) {
  6446. var domBack = this.domBack;
  6447. ctx.save();
  6448. ctx.globalAlpha = lastFrameAlpha;
  6449. ctx.drawImage(domBack, 0, 0, width, height);
  6450. ctx.restore();
  6451. }
  6452. }
  6453. };
  6454. var requestAnimationFrame = typeof window !== 'undefined' && (window.requestAnimationFrame && window.requestAnimationFrame.bind(window) || // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  6455. window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window) || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame) || function (func) {
  6456. setTimeout(func, 16);
  6457. };
  6458. var globalImageCache = new LRU(50);
  6459. /**
  6460. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6461. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6462. */
  6463. function findExistImage(newImageOrSrc) {
  6464. if (typeof newImageOrSrc === 'string') {
  6465. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6466. return cachedImgObj && cachedImgObj.image;
  6467. } else {
  6468. return newImageOrSrc;
  6469. }
  6470. }
  6471. /**
  6472. * Caution: User should cache loaded images, but not just count on LRU.
  6473. * Consider if required images more than LRU size, will dead loop occur?
  6474. *
  6475. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6476. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  6477. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  6478. * @param {Function} [cb] params: (image, cbPayload)
  6479. * @param {Object} [cbPayload] Payload on cb calling.
  6480. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6481. */
  6482. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  6483. if (!newImageOrSrc) {
  6484. return image;
  6485. } else if (typeof newImageOrSrc === 'string') {
  6486. // Image should not be loaded repeatly.
  6487. if (image && image.__zrImageSrc === newImageOrSrc || !hostEl) {
  6488. return image;
  6489. } // Only when there is no existent image or existent image src
  6490. // is different, this method is responsible for load.
  6491. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6492. var pendingWrap = {
  6493. hostEl: hostEl,
  6494. cb: cb,
  6495. cbPayload: cbPayload
  6496. };
  6497. if (cachedImgObj) {
  6498. image = cachedImgObj.image;
  6499. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  6500. } else {
  6501. image = new Image();
  6502. image.onload = image.onerror = imageOnLoad;
  6503. globalImageCache.put(newImageOrSrc, image.__cachedImgObj = {
  6504. image: image,
  6505. pending: [pendingWrap]
  6506. });
  6507. image.src = image.__zrImageSrc = newImageOrSrc;
  6508. }
  6509. return image;
  6510. } // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  6511. else {
  6512. return newImageOrSrc;
  6513. }
  6514. }
  6515. function imageOnLoad() {
  6516. var cachedImgObj = this.__cachedImgObj;
  6517. this.onload = this.onerror = this.__cachedImgObj = null;
  6518. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  6519. var pendingWrap = cachedImgObj.pending[i];
  6520. var cb = pendingWrap.cb;
  6521. cb && cb(this, pendingWrap.cbPayload);
  6522. pendingWrap.hostEl.dirty();
  6523. }
  6524. cachedImgObj.pending.length = 0;
  6525. }
  6526. function isImageReady(image) {
  6527. return image && image.width && image.height;
  6528. }
  6529. var textWidthCache = {};
  6530. var textWidthCacheCounter = 0;
  6531. var TEXT_CACHE_MAX = 5000;
  6532. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  6533. var DEFAULT_FONT$1 = '12px sans-serif'; // Avoid assign to an exported variable, for transforming to cjs.
  6534. var methods$1 = {};
  6535. /**
  6536. * @public
  6537. * @param {string} text
  6538. * @param {string} font
  6539. * @return {number} width
  6540. */
  6541. function getWidth(text, font) {
  6542. font = font || DEFAULT_FONT$1;
  6543. var key = text + ':' + font;
  6544. if (textWidthCache[key]) {
  6545. return textWidthCache[key];
  6546. }
  6547. var textLines = (text + '').split('\n');
  6548. var width = 0;
  6549. for (var i = 0, l = textLines.length; i < l; i++) {
  6550. // textContain.measureText may be overrided in SVG or VML
  6551. width = Math.max(measureText(textLines[i], font).width, width);
  6552. }
  6553. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  6554. textWidthCacheCounter = 0;
  6555. textWidthCache = {};
  6556. }
  6557. textWidthCacheCounter++;
  6558. textWidthCache[key] = width;
  6559. return width;
  6560. }
  6561. /**
  6562. * @public
  6563. * @param {string} text
  6564. * @param {string} font
  6565. * @param {string} [textAlign='left']
  6566. * @param {string} [textVerticalAlign='top']
  6567. * @param {Array.<number>} [textPadding]
  6568. * @param {Object} [rich]
  6569. * @param {Object} [truncate]
  6570. * @return {Object} {x, y, width, height, lineHeight}
  6571. */
  6572. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6573. return rich ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate);
  6574. }
  6575. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate) {
  6576. var contentBlock = parsePlainText(text, font, textPadding, textLineHeight, truncate);
  6577. var outerWidth = getWidth(text, font);
  6578. if (textPadding) {
  6579. outerWidth += textPadding[1] + textPadding[3];
  6580. }
  6581. var outerHeight = contentBlock.outerHeight;
  6582. var x = adjustTextX(0, outerWidth, textAlign);
  6583. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6584. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  6585. rect.lineHeight = contentBlock.lineHeight;
  6586. return rect;
  6587. }
  6588. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6589. var contentBlock = parseRichText(text, {
  6590. rich: rich,
  6591. truncate: truncate,
  6592. font: font,
  6593. textAlign: textAlign,
  6594. textPadding: textPadding,
  6595. textLineHeight: textLineHeight
  6596. });
  6597. var outerWidth = contentBlock.outerWidth;
  6598. var outerHeight = contentBlock.outerHeight;
  6599. var x = adjustTextX(0, outerWidth, textAlign);
  6600. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6601. return new BoundingRect(x, y, outerWidth, outerHeight);
  6602. }
  6603. /**
  6604. * @public
  6605. * @param {number} x
  6606. * @param {number} width
  6607. * @param {string} [textAlign='left']
  6608. * @return {number} Adjusted x.
  6609. */
  6610. function adjustTextX(x, width, textAlign) {
  6611. // FIXME Right to left language
  6612. if (textAlign === 'right') {
  6613. x -= width;
  6614. } else if (textAlign === 'center') {
  6615. x -= width / 2;
  6616. }
  6617. return x;
  6618. }
  6619. /**
  6620. * @public
  6621. * @param {number} y
  6622. * @param {number} height
  6623. * @param {string} [textVerticalAlign='top']
  6624. * @return {number} Adjusted y.
  6625. */
  6626. function adjustTextY(y, height, textVerticalAlign) {
  6627. if (textVerticalAlign === 'middle') {
  6628. y -= height / 2;
  6629. } else if (textVerticalAlign === 'bottom') {
  6630. y -= height;
  6631. }
  6632. return y;
  6633. }
  6634. /**
  6635. * Follow same interface to `Displayable.prototype.calculateTextPosition`.
  6636. * @public
  6637. * @param {Obejct} [out] Prepared out object. If not input, auto created in the method.
  6638. * @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited.
  6639. * @param {Object} rect {x, y, width, height} Rect of the host elment, according to which the text positioned.
  6640. * @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign}
  6641. */
  6642. function calculateTextPosition(out, style, rect) {
  6643. var textPosition = style.textPosition;
  6644. var distance = style.textDistance;
  6645. var x = rect.x;
  6646. var y = rect.y;
  6647. distance = distance || 0;
  6648. var height = rect.height;
  6649. var width = rect.width;
  6650. var halfHeight = height / 2;
  6651. var textAlign = 'left';
  6652. var textVerticalAlign = 'top';
  6653. switch (textPosition) {
  6654. case 'left':
  6655. x -= distance;
  6656. y += halfHeight;
  6657. textAlign = 'right';
  6658. textVerticalAlign = 'middle';
  6659. break;
  6660. case 'right':
  6661. x += distance + width;
  6662. y += halfHeight;
  6663. textVerticalAlign = 'middle';
  6664. break;
  6665. case 'top':
  6666. x += width / 2;
  6667. y -= distance;
  6668. textAlign = 'center';
  6669. textVerticalAlign = 'bottom';
  6670. break;
  6671. case 'bottom':
  6672. x += width / 2;
  6673. y += height + distance;
  6674. textAlign = 'center';
  6675. break;
  6676. case 'inside':
  6677. x += width / 2;
  6678. y += halfHeight;
  6679. textAlign = 'center';
  6680. textVerticalAlign = 'middle';
  6681. break;
  6682. case 'insideLeft':
  6683. x += distance;
  6684. y += halfHeight;
  6685. textVerticalAlign = 'middle';
  6686. break;
  6687. case 'insideRight':
  6688. x += width - distance;
  6689. y += halfHeight;
  6690. textAlign = 'right';
  6691. textVerticalAlign = 'middle';
  6692. break;
  6693. case 'insideTop':
  6694. x += width / 2;
  6695. y += distance;
  6696. textAlign = 'center';
  6697. break;
  6698. case 'insideBottom':
  6699. x += width / 2;
  6700. y += height - distance;
  6701. textAlign = 'center';
  6702. textVerticalAlign = 'bottom';
  6703. break;
  6704. case 'insideTopLeft':
  6705. x += distance;
  6706. y += distance;
  6707. break;
  6708. case 'insideTopRight':
  6709. x += width - distance;
  6710. y += distance;
  6711. textAlign = 'right';
  6712. break;
  6713. case 'insideBottomLeft':
  6714. x += distance;
  6715. y += height - distance;
  6716. textVerticalAlign = 'bottom';
  6717. break;
  6718. case 'insideBottomRight':
  6719. x += width - distance;
  6720. y += height - distance;
  6721. textAlign = 'right';
  6722. textVerticalAlign = 'bottom';
  6723. break;
  6724. }
  6725. out = out || {};
  6726. out.x = x;
  6727. out.y = y;
  6728. out.textAlign = textAlign;
  6729. out.textVerticalAlign = textVerticalAlign;
  6730. return out;
  6731. }
  6732. /**
  6733. * To be removed. But still do not remove in case that some one has imported it.
  6734. * @deprecated
  6735. * @public
  6736. * @param {stirng} textPosition
  6737. * @param {Object} rect {x, y, width, height}
  6738. * @param {number} distance
  6739. * @return {Object} {x, y, textAlign, textVerticalAlign}
  6740. */
  6741. /**
  6742. * Show ellipsis if overflow.
  6743. *
  6744. * @public
  6745. * @param {string} text
  6746. * @param {string} containerWidth
  6747. * @param {string} font
  6748. * @param {number} [ellipsis='...']
  6749. * @param {Object} [options]
  6750. * @param {number} [options.maxIterations=3]
  6751. * @param {number} [options.minChar=0] If truncate result are less
  6752. * then minChar, ellipsis will not show, which is
  6753. * better for user hint in some cases.
  6754. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  6755. * @return {string}
  6756. */
  6757. function truncateText(text, containerWidth, font, ellipsis, options) {
  6758. if (!containerWidth) {
  6759. return '';
  6760. }
  6761. var textLines = (text + '').split('\n');
  6762. options = prepareTruncateOptions(containerWidth, font, ellipsis, options); // FIXME
  6763. // It is not appropriate that every line has '...' when truncate multiple lines.
  6764. for (var i = 0, len = textLines.length; i < len; i++) {
  6765. textLines[i] = truncateSingleLine(textLines[i], options);
  6766. }
  6767. return textLines.join('\n');
  6768. }
  6769. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  6770. options = extend({}, options);
  6771. options.font = font;
  6772. var ellipsis = retrieve2(ellipsis, '...');
  6773. options.maxIterations = retrieve2(options.maxIterations, 2);
  6774. var minChar = options.minChar = retrieve2(options.minChar, 0); // FIXME
  6775. // Other languages?
  6776. options.cnCharWidth = getWidth('国', font); // FIXME
  6777. // Consider proportional font?
  6778. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  6779. options.placeholder = retrieve2(options.placeholder, ''); // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  6780. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  6781. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  6782. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  6783. contentWidth -= ascCharWidth;
  6784. }
  6785. var ellipsisWidth = getWidth(ellipsis, font);
  6786. if (ellipsisWidth > contentWidth) {
  6787. ellipsis = '';
  6788. ellipsisWidth = 0;
  6789. }
  6790. contentWidth = containerWidth - ellipsisWidth;
  6791. options.ellipsis = ellipsis;
  6792. options.ellipsisWidth = ellipsisWidth;
  6793. options.contentWidth = contentWidth;
  6794. options.containerWidth = containerWidth;
  6795. return options;
  6796. }
  6797. function truncateSingleLine(textLine, options) {
  6798. var containerWidth = options.containerWidth;
  6799. var font = options.font;
  6800. var contentWidth = options.contentWidth;
  6801. if (!containerWidth) {
  6802. return '';
  6803. }
  6804. var lineWidth = getWidth(textLine, font);
  6805. if (lineWidth <= containerWidth) {
  6806. return textLine;
  6807. }
  6808. for (var j = 0;; j++) {
  6809. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  6810. textLine += options.ellipsis;
  6811. break;
  6812. }
  6813. var subLength = j === 0 ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth) : lineWidth > 0 ? Math.floor(textLine.length * contentWidth / lineWidth) : 0;
  6814. textLine = textLine.substr(0, subLength);
  6815. lineWidth = getWidth(textLine, font);
  6816. }
  6817. if (textLine === '') {
  6818. textLine = options.placeholder;
  6819. }
  6820. return textLine;
  6821. }
  6822. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  6823. var width = 0;
  6824. var i = 0;
  6825. for (var len = text.length; i < len && width < contentWidth; i++) {
  6826. var charCode = text.charCodeAt(i);
  6827. width += 0 <= charCode && charCode <= 127 ? ascCharWidth : cnCharWidth;
  6828. }
  6829. return i;
  6830. }
  6831. /**
  6832. * @public
  6833. * @param {string} font
  6834. * @return {number} line height
  6835. */
  6836. function getLineHeight(font) {
  6837. // FIXME A rough approach.
  6838. return getWidth('国', font);
  6839. }
  6840. /**
  6841. * @public
  6842. * @param {string} text
  6843. * @param {string} font
  6844. * @return {Object} width
  6845. */
  6846. function measureText(text, font) {
  6847. return methods$1.measureText(text, font);
  6848. } // Avoid assign to an exported variable, for transforming to cjs.
  6849. methods$1.measureText = function (text, font) {
  6850. var ctx = getContext();
  6851. ctx.font = font || DEFAULT_FONT$1;
  6852. return ctx.measureText(text);
  6853. };
  6854. /**
  6855. * @public
  6856. * @param {string} text
  6857. * @param {string} font
  6858. * @param {Object} [truncate]
  6859. * @return {Object} block: {lineHeight, lines, height, outerHeight, canCacheByTextString}
  6860. * Notice: for performance, do not calculate outerWidth util needed.
  6861. * `canCacheByTextString` means the result `lines` is only determined by the input `text`.
  6862. * Thus we can simply comparing the `input` text to determin whether the result changed,
  6863. * without travel the result `lines`.
  6864. */
  6865. function parsePlainText(text, font, padding, textLineHeight, truncate) {
  6866. text != null && (text += '');
  6867. var lineHeight = retrieve2(textLineHeight, getLineHeight(font));
  6868. var lines = text ? text.split('\n') : [];
  6869. var height = lines.length * lineHeight;
  6870. var outerHeight = height;
  6871. var canCacheByTextString = true;
  6872. if (padding) {
  6873. outerHeight += padding[0] + padding[2];
  6874. }
  6875. if (text && truncate) {
  6876. canCacheByTextString = false;
  6877. var truncOuterHeight = truncate.outerHeight;
  6878. var truncOuterWidth = truncate.outerWidth;
  6879. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  6880. text = '';
  6881. lines = [];
  6882. } else if (truncOuterWidth != null) {
  6883. var options = prepareTruncateOptions(truncOuterWidth - (padding ? padding[1] + padding[3] : 0), font, truncate.ellipsis, {
  6884. minChar: truncate.minChar,
  6885. placeholder: truncate.placeholder
  6886. }); // FIXME
  6887. // It is not appropriate that every line has '...' when truncate multiple lines.
  6888. for (var i = 0, len = lines.length; i < len; i++) {
  6889. lines[i] = truncateSingleLine(lines[i], options);
  6890. }
  6891. }
  6892. }
  6893. return {
  6894. lines: lines,
  6895. height: height,
  6896. outerHeight: outerHeight,
  6897. lineHeight: lineHeight,
  6898. canCacheByTextString: canCacheByTextString
  6899. };
  6900. }
  6901. /**
  6902. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  6903. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  6904. *
  6905. * @public
  6906. * @param {string} text
  6907. * @param {Object} style
  6908. * @return {Object} block
  6909. * {
  6910. * width,
  6911. * height,
  6912. * lines: [{
  6913. * lineHeight,
  6914. * width,
  6915. * tokens: [[{
  6916. * styleName,
  6917. * text,
  6918. * width, // include textPadding
  6919. * height, // include textPadding
  6920. * textWidth, // pure text width
  6921. * textHeight, // pure text height
  6922. * lineHeihgt,
  6923. * font,
  6924. * textAlign,
  6925. * textVerticalAlign
  6926. * }], [...], ...]
  6927. * }, ...]
  6928. * }
  6929. * If styleName is undefined, it is plain text.
  6930. */
  6931. function parseRichText(text, style) {
  6932. var contentBlock = {
  6933. lines: [],
  6934. width: 0,
  6935. height: 0
  6936. };
  6937. text != null && (text += '');
  6938. if (!text) {
  6939. return contentBlock;
  6940. }
  6941. var lastIndex = STYLE_REG.lastIndex = 0;
  6942. var result;
  6943. while ((result = STYLE_REG.exec(text)) != null) {
  6944. var matchedIndex = result.index;
  6945. if (matchedIndex > lastIndex) {
  6946. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  6947. }
  6948. pushTokens(contentBlock, result[2], result[1]);
  6949. lastIndex = STYLE_REG.lastIndex;
  6950. }
  6951. if (lastIndex < text.length) {
  6952. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  6953. }
  6954. var lines = contentBlock.lines;
  6955. var contentHeight = 0;
  6956. var contentWidth = 0; // For `textWidth: 100%`
  6957. var pendingList = [];
  6958. var stlPadding = style.textPadding;
  6959. var truncate = style.truncate;
  6960. var truncateWidth = truncate && truncate.outerWidth;
  6961. var truncateHeight = truncate && truncate.outerHeight;
  6962. if (stlPadding) {
  6963. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  6964. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  6965. } // Calculate layout info of tokens.
  6966. for (var i = 0; i < lines.length; i++) {
  6967. var line = lines[i];
  6968. var lineHeight = 0;
  6969. var lineWidth = 0;
  6970. for (var j = 0; j < line.tokens.length; j++) {
  6971. var token = line.tokens[j];
  6972. var tokenStyle = token.styleName && style.rich[token.styleName] || {}; // textPadding should not inherit from style.
  6973. var textPadding = token.textPadding = tokenStyle.textPadding; // textFont has been asigned to font by `normalizeStyle`.
  6974. var font = token.font = tokenStyle.font || style.font; // textHeight can be used when textVerticalAlign is specified in token.
  6975. var tokenHeight = token.textHeight = retrieve2( // textHeight should not be inherited, consider it can be specified
  6976. // as box height of the block.
  6977. tokenStyle.textHeight, getLineHeight(font));
  6978. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  6979. token.height = tokenHeight;
  6980. token.lineHeight = retrieve3(tokenStyle.textLineHeight, style.textLineHeight, tokenHeight);
  6981. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  6982. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  6983. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  6984. return {
  6985. lines: [],
  6986. width: 0,
  6987. height: 0
  6988. };
  6989. }
  6990. token.textWidth = getWidth(token.text, font);
  6991. var tokenWidth = tokenStyle.textWidth;
  6992. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto'; // Percent width, can be `100%`, can be used in drawing separate
  6993. // line when box width is needed to be auto.
  6994. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  6995. token.percentWidth = tokenWidth;
  6996. pendingList.push(token);
  6997. tokenWidth = 0; // Do not truncate in this case, because there is no user case
  6998. // and it is too complicated.
  6999. } else {
  7000. if (tokenWidthNotSpecified) {
  7001. tokenWidth = token.textWidth; // FIXME: If image is not loaded and textWidth is not specified, calling
  7002. // `getBoundingRect()` will not get correct result.
  7003. var textBackgroundColor = tokenStyle.textBackgroundColor;
  7004. var bgImg = textBackgroundColor && textBackgroundColor.image; // Use cases:
  7005. // (1) If image is not loaded, it will be loaded at render phase and call
  7006. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  7007. // image, and then the right size will be calculated here at the next tick.
  7008. // See `graphic/helper/text.js`.
  7009. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  7010. // use `imageHelper.findExistImage` to find cached image.
  7011. // `imageHelper.findExistImage` will always be called here before
  7012. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  7013. // which ensures that image will not be rendered before correct size calcualted.
  7014. if (bgImg) {
  7015. bgImg = findExistImage(bgImg);
  7016. if (isImageReady(bgImg)) {
  7017. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  7018. }
  7019. }
  7020. }
  7021. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  7022. tokenWidth += paddingW;
  7023. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  7024. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  7025. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  7026. token.text = '';
  7027. token.textWidth = tokenWidth = 0;
  7028. } else {
  7029. token.text = truncateText(token.text, remianTruncWidth - paddingW, font, truncate.ellipsis, {
  7030. minChar: truncate.minChar
  7031. });
  7032. token.textWidth = getWidth(token.text, font);
  7033. tokenWidth = token.textWidth + paddingW;
  7034. }
  7035. }
  7036. }
  7037. lineWidth += token.width = tokenWidth;
  7038. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  7039. }
  7040. line.width = lineWidth;
  7041. line.lineHeight = lineHeight;
  7042. contentHeight += lineHeight;
  7043. contentWidth = Math.max(contentWidth, lineWidth);
  7044. }
  7045. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  7046. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  7047. if (stlPadding) {
  7048. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  7049. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  7050. }
  7051. for (var i = 0; i < pendingList.length; i++) {
  7052. var token = pendingList[i];
  7053. var percentWidth = token.percentWidth; // Should not base on outerWidth, because token can not be placed out of padding.
  7054. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  7055. }
  7056. return contentBlock;
  7057. }
  7058. function pushTokens(block, str, styleName) {
  7059. var isEmptyStr = str === '';
  7060. var strs = str.split('\n');
  7061. var lines = block.lines;
  7062. for (var i = 0; i < strs.length; i++) {
  7063. var text = strs[i];
  7064. var token = {
  7065. styleName: styleName,
  7066. text: text,
  7067. isLineHolder: !text && !isEmptyStr
  7068. }; // The first token should be appended to the last line.
  7069. if (!i) {
  7070. var tokens = (lines[lines.length - 1] || (lines[0] = {
  7071. tokens: []
  7072. })).tokens; // Consider cases:
  7073. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  7074. // (which is a placeholder) should be replaced by new token.
  7075. // (2) A image backage, where token likes {a|}.
  7076. // (3) A redundant '' will affect textAlign in line.
  7077. // (4) tokens with the same tplName should not be merged, because
  7078. // they should be displayed in different box (with border and padding).
  7079. var tokensLen = tokens.length;
  7080. tokensLen === 1 && tokens[0].isLineHolder ? tokens[0] = token : // Consider text is '', only insert when it is the "lineHolder" or
  7081. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  7082. (text || !tokensLen || isEmptyStr) && tokens.push(token);
  7083. } // Other tokens always start a new line.
  7084. else {
  7085. // If there is '', insert it as a placeholder.
  7086. lines.push({
  7087. tokens: [token]
  7088. });
  7089. }
  7090. }
  7091. }
  7092. function makeFont(style) {
  7093. // FIXME in node-canvas fontWeight is before fontStyle
  7094. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  7095. var font = (style.fontSize || style.fontFamily) && [style.fontStyle, style.fontWeight, (style.fontSize || 12) + 'px', // If font properties are defined, `fontFamily` should not be ignored.
  7096. style.fontFamily || 'sans-serif'].join(' ');
  7097. return font && trim(font) || style.textFont || style.font;
  7098. }
  7099. /**
  7100. * @param {Object} ctx
  7101. * @param {Object} shape
  7102. * @param {number} shape.x
  7103. * @param {number} shape.y
  7104. * @param {number} shape.width
  7105. * @param {number} shape.height
  7106. * @param {number} shape.r
  7107. */
  7108. function buildPath(ctx, shape) {
  7109. var x = shape.x;
  7110. var y = shape.y;
  7111. var width = shape.width;
  7112. var height = shape.height;
  7113. var r = shape.r;
  7114. var r1;
  7115. var r2;
  7116. var r3;
  7117. var r4; // Convert width and height to positive for better borderRadius
  7118. if (width < 0) {
  7119. x = x + width;
  7120. width = -width;
  7121. }
  7122. if (height < 0) {
  7123. y = y + height;
  7124. height = -height;
  7125. }
  7126. if (typeof r === 'number') {
  7127. r1 = r2 = r3 = r4 = r;
  7128. } else if (r instanceof Array) {
  7129. if (r.length === 1) {
  7130. r1 = r2 = r3 = r4 = r[0];
  7131. } else if (r.length === 2) {
  7132. r1 = r3 = r[0];
  7133. r2 = r4 = r[1];
  7134. } else if (r.length === 3) {
  7135. r1 = r[0];
  7136. r2 = r4 = r[1];
  7137. r3 = r[2];
  7138. } else {
  7139. r1 = r[0];
  7140. r2 = r[1];
  7141. r3 = r[2];
  7142. r4 = r[3];
  7143. }
  7144. } else {
  7145. r1 = r2 = r3 = r4 = 0;
  7146. }
  7147. var total;
  7148. if (r1 + r2 > width) {
  7149. total = r1 + r2;
  7150. r1 *= width / total;
  7151. r2 *= width / total;
  7152. }
  7153. if (r3 + r4 > width) {
  7154. total = r3 + r4;
  7155. r3 *= width / total;
  7156. r4 *= width / total;
  7157. }
  7158. if (r2 + r3 > height) {
  7159. total = r2 + r3;
  7160. r2 *= height / total;
  7161. r3 *= height / total;
  7162. }
  7163. if (r1 + r4 > height) {
  7164. total = r1 + r4;
  7165. r1 *= height / total;
  7166. r4 *= height / total;
  7167. }
  7168. ctx.moveTo(x + r1, y);
  7169. ctx.lineTo(x + width - r2, y);
  7170. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  7171. ctx.lineTo(x + width, y + height - r3);
  7172. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  7173. ctx.lineTo(x + r4, y + height);
  7174. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  7175. ctx.lineTo(x, y + r1);
  7176. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  7177. }
  7178. var DEFAULT_FONT = DEFAULT_FONT$1; // TODO: Have not support 'start', 'end' yet.
  7179. var VALID_TEXT_ALIGN = {
  7180. left: 1,
  7181. right: 1,
  7182. center: 1
  7183. };
  7184. var VALID_TEXT_VERTICAL_ALIGN = {
  7185. top: 1,
  7186. bottom: 1,
  7187. middle: 1
  7188. }; // Different from `STYLE_COMMON_PROPS` of `graphic/Style`,
  7189. // the default value of shadowColor is `'transparent'`.
  7190. var SHADOW_STYLE_COMMON_PROPS = [['textShadowBlur', 'shadowBlur', 0], ['textShadowOffsetX', 'shadowOffsetX', 0], ['textShadowOffsetY', 'shadowOffsetY', 0], ['textShadowColor', 'shadowColor', 'transparent']];
  7191. var _tmpTextPositionResult = {};
  7192. var _tmpBoxPositionResult = {};
  7193. /**
  7194. * @param {module:zrender/graphic/Style} style
  7195. * @return {module:zrender/graphic/Style} The input style.
  7196. */
  7197. function normalizeTextStyle(style) {
  7198. normalizeStyle(style);
  7199. each$1(style.rich, normalizeStyle);
  7200. return style;
  7201. }
  7202. function normalizeStyle(style) {
  7203. if (style) {
  7204. style.font = makeFont(style);
  7205. var textAlign = style.textAlign;
  7206. textAlign === 'middle' && (textAlign = 'center');
  7207. style.textAlign = textAlign == null || VALID_TEXT_ALIGN[textAlign] ? textAlign : 'left'; // Compatible with textBaseline.
  7208. var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
  7209. textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
  7210. style.textVerticalAlign = textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign] ? textVerticalAlign : 'top';
  7211. var textPadding = style.textPadding;
  7212. if (textPadding) {
  7213. style.textPadding = normalizeCssArray(style.textPadding);
  7214. }
  7215. }
  7216. }
  7217. /**
  7218. * @param {CanvasRenderingContext2D} ctx
  7219. * @param {string} text
  7220. * @param {module:zrender/graphic/Style} style
  7221. * @param {Object|boolean} [rect] {x, y, width, height}
  7222. * If set false, rect text is not used.
  7223. * @param {Element|module:zrender/graphic/helper/constant.WILL_BE_RESTORED} [prevEl] For ctx prop cache.
  7224. */
  7225. function renderText(hostEl, ctx, text, style, rect, prevEl) {
  7226. style.rich ? renderRichText(hostEl, ctx, text, style, rect, prevEl) : renderPlainText(hostEl, ctx, text, style, rect, prevEl);
  7227. } // Avoid setting to ctx according to prevEl if possible for
  7228. // performance in scenarios of large amount text.
  7229. function renderPlainText(hostEl, ctx, text, style, rect, prevEl) {
  7230. 'use strict';
  7231. var needDrawBg = needDrawBackground(style);
  7232. var prevStyle;
  7233. var checkCache = false;
  7234. var cachedByMe = ctx.__attrCachedBy === ContextCachedBy.PLAIN_TEXT; // Only take and check cache for `Text` el, but not RectText.
  7235. if (prevEl !== WILL_BE_RESTORED) {
  7236. if (prevEl) {
  7237. prevStyle = prevEl.style;
  7238. checkCache = !needDrawBg && cachedByMe && prevStyle;
  7239. } // Prevent from using cache in `Style::bind`, because of the case:
  7240. // ctx property is modified by other properties than `Style::bind`
  7241. // used, and Style::bind is called next.
  7242. ctx.__attrCachedBy = needDrawBg ? ContextCachedBy.NONE : ContextCachedBy.PLAIN_TEXT;
  7243. } // Since this will be restored, prevent from using these props to check cache in the next
  7244. // entering of this method. But do not need to clear other cache like `Style::bind`.
  7245. else if (cachedByMe) {
  7246. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7247. }
  7248. var styleFont = style.font || DEFAULT_FONT; // PENDING
  7249. // Only `Text` el set `font` and keep it (`RectText` will restore). So theoretically
  7250. // we can make font cache on ctx, which can cache for text el that are discontinuous.
  7251. // But layer save/restore needed to be considered.
  7252. // if (styleFont !== ctx.__fontCache) {
  7253. // ctx.font = styleFont;
  7254. // if (prevEl !== WILL_BE_RESTORED) {
  7255. // ctx.__fontCache = styleFont;
  7256. // }
  7257. // }
  7258. if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) {
  7259. ctx.font = styleFont;
  7260. } // Use the final font from context-2d, because the final
  7261. // font might not be the style.font when it is illegal.
  7262. // But get `ctx.font` might be time consuming.
  7263. var computedFont = hostEl.__computedFont;
  7264. if (hostEl.__styleFont !== styleFont) {
  7265. hostEl.__styleFont = styleFont;
  7266. computedFont = hostEl.__computedFont = ctx.font;
  7267. }
  7268. var textPadding = style.textPadding;
  7269. var textLineHeight = style.textLineHeight;
  7270. var contentBlock = hostEl.__textCotentBlock;
  7271. if (!contentBlock || hostEl.__dirtyText) {
  7272. contentBlock = hostEl.__textCotentBlock = parsePlainText(text, computedFont, textPadding, textLineHeight, style.truncate);
  7273. }
  7274. var outerHeight = contentBlock.outerHeight;
  7275. var textLines = contentBlock.lines;
  7276. var lineHeight = contentBlock.lineHeight;
  7277. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7278. var baseX = boxPos.baseX;
  7279. var baseY = boxPos.baseY;
  7280. var textAlign = boxPos.textAlign || 'left';
  7281. var textVerticalAlign = boxPos.textVerticalAlign; // Origin of textRotation should be the base point of text drawing.
  7282. applyTextRotation(ctx, style, rect, baseX, baseY);
  7283. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7284. var textX = baseX;
  7285. var textY = boxY;
  7286. if (needDrawBg || textPadding) {
  7287. // Consider performance, do not call getTextWidth util necessary.
  7288. var textWidth = getWidth(text, computedFont);
  7289. var outerWidth = textWidth;
  7290. textPadding && (outerWidth += textPadding[1] + textPadding[3]);
  7291. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7292. needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  7293. if (textPadding) {
  7294. textX = getTextXForPadding(baseX, textAlign, textPadding);
  7295. textY += textPadding[0];
  7296. }
  7297. } // Always set textAlign and textBase line, because it is difficute to calculate
  7298. // textAlign from prevEl, and we dont sure whether textAlign will be reset if
  7299. // font set happened.
  7300. ctx.textAlign = textAlign; // Force baseline to be "middle". Otherwise, if using "top", the
  7301. // text will offset downward a little bit in font "Microsoft YaHei".
  7302. ctx.textBaseline = 'middle'; // Set text opacity
  7303. ctx.globalAlpha = style.opacity || 1; // Always set shadowBlur and shadowOffset to avoid leak from displayable.
  7304. for (var i = 0; i < SHADOW_STYLE_COMMON_PROPS.length; i++) {
  7305. var propItem = SHADOW_STYLE_COMMON_PROPS[i];
  7306. var styleProp = propItem[0];
  7307. var ctxProp = propItem[1];
  7308. var val = style[styleProp];
  7309. if (!checkCache || val !== prevStyle[styleProp]) {
  7310. ctx[ctxProp] = fixShadow(ctx, ctxProp, val || propItem[2]);
  7311. }
  7312. } // `textBaseline` is set as 'middle'.
  7313. textY += lineHeight / 2;
  7314. var textStrokeWidth = style.textStrokeWidth;
  7315. var textStrokeWidthPrev = checkCache ? prevStyle.textStrokeWidth : null;
  7316. var strokeWidthChanged = !checkCache || textStrokeWidth !== textStrokeWidthPrev;
  7317. var strokeChanged = !checkCache || strokeWidthChanged || style.textStroke !== prevStyle.textStroke;
  7318. var textStroke = getStroke(style.textStroke, textStrokeWidth);
  7319. var textFill = getFill(style.textFill);
  7320. if (textStroke) {
  7321. if (strokeWidthChanged) {
  7322. ctx.lineWidth = textStrokeWidth;
  7323. }
  7324. if (strokeChanged) {
  7325. ctx.strokeStyle = textStroke;
  7326. }
  7327. }
  7328. if (textFill) {
  7329. if (!checkCache || style.textFill !== prevStyle.textFill) {
  7330. ctx.fillStyle = textFill;
  7331. }
  7332. } // Optimize simply, in most cases only one line exists.
  7333. if (textLines.length === 1) {
  7334. // Fill after stroke so the outline will not cover the main part.
  7335. textStroke && ctx.strokeText(textLines[0], textX, textY);
  7336. textFill && ctx.fillText(textLines[0], textX, textY);
  7337. } else {
  7338. for (var i = 0; i < textLines.length; i++) {
  7339. // Fill after stroke so the outline will not cover the main part.
  7340. textStroke && ctx.strokeText(textLines[i], textX, textY);
  7341. textFill && ctx.fillText(textLines[i], textX, textY);
  7342. textY += lineHeight;
  7343. }
  7344. }
  7345. }
  7346. function renderRichText(hostEl, ctx, text, style, rect, prevEl) {
  7347. // Do not do cache for rich text because of the complexity.
  7348. // But `RectText` this will be restored, do not need to clear other cache like `Style::bind`.
  7349. if (prevEl !== WILL_BE_RESTORED) {
  7350. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7351. }
  7352. var contentBlock = hostEl.__textCotentBlock;
  7353. if (!contentBlock || hostEl.__dirtyText) {
  7354. contentBlock = hostEl.__textCotentBlock = parseRichText(text, style);
  7355. }
  7356. drawRichText(hostEl, ctx, contentBlock, style, rect);
  7357. }
  7358. function drawRichText(hostEl, ctx, contentBlock, style, rect) {
  7359. var contentWidth = contentBlock.width;
  7360. var outerWidth = contentBlock.outerWidth;
  7361. var outerHeight = contentBlock.outerHeight;
  7362. var textPadding = style.textPadding;
  7363. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7364. var baseX = boxPos.baseX;
  7365. var baseY = boxPos.baseY;
  7366. var textAlign = boxPos.textAlign;
  7367. var textVerticalAlign = boxPos.textVerticalAlign; // Origin of textRotation should be the base point of text drawing.
  7368. applyTextRotation(ctx, style, rect, baseX, baseY);
  7369. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7370. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7371. var xLeft = boxX;
  7372. var lineTop = boxY;
  7373. if (textPadding) {
  7374. xLeft += textPadding[3];
  7375. lineTop += textPadding[0];
  7376. }
  7377. var xRight = xLeft + contentWidth;
  7378. needDrawBackground(style) && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  7379. for (var i = 0; i < contentBlock.lines.length; i++) {
  7380. var line = contentBlock.lines[i];
  7381. var tokens = line.tokens;
  7382. var tokenCount = tokens.length;
  7383. var lineHeight = line.lineHeight;
  7384. var usedWidth = line.width;
  7385. var leftIndex = 0;
  7386. var lineXLeft = xLeft;
  7387. var lineXRight = xRight;
  7388. var rightIndex = tokenCount - 1;
  7389. var token;
  7390. while (leftIndex < tokenCount && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')) {
  7391. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
  7392. usedWidth -= token.width;
  7393. lineXLeft += token.width;
  7394. leftIndex++;
  7395. }
  7396. while (rightIndex >= 0 && (token = tokens[rightIndex], token.textAlign === 'right')) {
  7397. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
  7398. usedWidth -= token.width;
  7399. lineXRight -= token.width;
  7400. rightIndex--;
  7401. } // The other tokens are placed as textAlign 'center' if there is enough space.
  7402. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
  7403. while (leftIndex <= rightIndex) {
  7404. token = tokens[leftIndex]; // Consider width specified by user, use 'center' rather than 'left'.
  7405. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
  7406. lineXLeft += token.width;
  7407. leftIndex++;
  7408. }
  7409. lineTop += lineHeight;
  7410. }
  7411. }
  7412. function applyTextRotation(ctx, style, rect, x, y) {
  7413. // textRotation only apply in RectText.
  7414. if (rect && style.textRotation) {
  7415. var origin = style.textOrigin;
  7416. if (origin === 'center') {
  7417. x = rect.width / 2 + rect.x;
  7418. y = rect.height / 2 + rect.y;
  7419. } else if (origin) {
  7420. x = origin[0] + rect.x;
  7421. y = origin[1] + rect.y;
  7422. }
  7423. ctx.translate(x, y); // Positive: anticlockwise
  7424. ctx.rotate(-style.textRotation);
  7425. ctx.translate(-x, -y);
  7426. }
  7427. }
  7428. function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
  7429. var tokenStyle = style.rich[token.styleName] || {};
  7430. tokenStyle.text = token.text; // 'ctx.textBaseline' is always set as 'middle', for sake of
  7431. // the bias of "Microsoft YaHei".
  7432. var textVerticalAlign = token.textVerticalAlign;
  7433. var y = lineTop + lineHeight / 2;
  7434. if (textVerticalAlign === 'top') {
  7435. y = lineTop + token.height / 2;
  7436. } else if (textVerticalAlign === 'bottom') {
  7437. y = lineTop + lineHeight - token.height / 2;
  7438. }
  7439. !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);
  7440. var textPadding = token.textPadding;
  7441. if (textPadding) {
  7442. x = getTextXForPadding(x, textAlign, textPadding);
  7443. y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
  7444. }
  7445. setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
  7446. setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
  7447. setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
  7448. setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
  7449. setCtx(ctx, 'textAlign', textAlign); // Force baseline to be "middle". Otherwise, if using "top", the
  7450. // text will offset downward a little bit in font "Microsoft YaHei".
  7451. setCtx(ctx, 'textBaseline', 'middle');
  7452. setCtx(ctx, 'font', token.font || DEFAULT_FONT);
  7453. var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
  7454. var textFill = getFill(tokenStyle.textFill || style.textFill);
  7455. var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth); // Fill after stroke so the outline will not cover the main part.
  7456. if (textStroke) {
  7457. setCtx(ctx, 'lineWidth', textStrokeWidth);
  7458. setCtx(ctx, 'strokeStyle', textStroke);
  7459. ctx.strokeText(token.text, x, y);
  7460. }
  7461. if (textFill) {
  7462. setCtx(ctx, 'fillStyle', textFill);
  7463. ctx.fillText(token.text, x, y);
  7464. }
  7465. }
  7466. function needDrawBackground(style) {
  7467. return !!(style.textBackgroundColor || style.textBorderWidth && style.textBorderColor);
  7468. } // style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius, text}
  7469. // shape: {x, y, width, height}
  7470. function drawBackground(hostEl, ctx, style, x, y, width, height) {
  7471. var textBackgroundColor = style.textBackgroundColor;
  7472. var textBorderWidth = style.textBorderWidth;
  7473. var textBorderColor = style.textBorderColor;
  7474. var isPlainBg = isString(textBackgroundColor);
  7475. setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
  7476. setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
  7477. setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
  7478. setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
  7479. if (isPlainBg || textBorderWidth && textBorderColor) {
  7480. ctx.beginPath();
  7481. var textBorderRadius = style.textBorderRadius;
  7482. if (!textBorderRadius) {
  7483. ctx.rect(x, y, width, height);
  7484. } else {
  7485. buildPath(ctx, {
  7486. x: x,
  7487. y: y,
  7488. width: width,
  7489. height: height,
  7490. r: textBorderRadius
  7491. });
  7492. }
  7493. ctx.closePath();
  7494. }
  7495. if (isPlainBg) {
  7496. setCtx(ctx, 'fillStyle', textBackgroundColor);
  7497. if (style.fillOpacity != null) {
  7498. var originalGlobalAlpha = ctx.globalAlpha;
  7499. ctx.globalAlpha = style.fillOpacity * style.opacity;
  7500. ctx.fill();
  7501. ctx.globalAlpha = originalGlobalAlpha;
  7502. } else {
  7503. ctx.fill();
  7504. }
  7505. } else if (isObject$1(textBackgroundColor)) {
  7506. var image = textBackgroundColor.image;
  7507. image = createOrUpdateImage(image, null, hostEl, onBgImageLoaded, textBackgroundColor);
  7508. if (image && isImageReady(image)) {
  7509. ctx.drawImage(image, x, y, width, height);
  7510. }
  7511. }
  7512. if (textBorderWidth && textBorderColor) {
  7513. setCtx(ctx, 'lineWidth', textBorderWidth);
  7514. setCtx(ctx, 'strokeStyle', textBorderColor);
  7515. if (style.strokeOpacity != null) {
  7516. var originalGlobalAlpha = ctx.globalAlpha;
  7517. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  7518. ctx.stroke();
  7519. ctx.globalAlpha = originalGlobalAlpha;
  7520. } else {
  7521. ctx.stroke();
  7522. }
  7523. }
  7524. }
  7525. function onBgImageLoaded(image, textBackgroundColor) {
  7526. // Replace image, so that `contain/text.js#parseRichText`
  7527. // will get correct result in next tick.
  7528. textBackgroundColor.image = image;
  7529. }
  7530. function getBoxPosition(out, hostEl, style, rect) {
  7531. var baseX = style.x || 0;
  7532. var baseY = style.y || 0;
  7533. var textAlign = style.textAlign;
  7534. var textVerticalAlign = style.textVerticalAlign; // Text position represented by coord
  7535. if (rect) {
  7536. var textPosition = style.textPosition;
  7537. if (textPosition instanceof Array) {
  7538. // Percent
  7539. baseX = rect.x + parsePercent(textPosition[0], rect.width);
  7540. baseY = rect.y + parsePercent(textPosition[1], rect.height);
  7541. } else {
  7542. var res = hostEl && hostEl.calculateTextPosition ? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect) : calculateTextPosition(_tmpTextPositionResult, style, rect);
  7543. baseX = res.x;
  7544. baseY = res.y; // Default align and baseline when has textPosition
  7545. textAlign = textAlign || res.textAlign;
  7546. textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
  7547. } // textOffset is only support in RectText, otherwise
  7548. // we have to adjust boundingRect for textOffset.
  7549. var textOffset = style.textOffset;
  7550. if (textOffset) {
  7551. baseX += textOffset[0];
  7552. baseY += textOffset[1];
  7553. }
  7554. }
  7555. out = out || {};
  7556. out.baseX = baseX;
  7557. out.baseY = baseY;
  7558. out.textAlign = textAlign;
  7559. out.textVerticalAlign = textVerticalAlign;
  7560. return out;
  7561. }
  7562. function setCtx(ctx, prop, value) {
  7563. ctx[prop] = fixShadow(ctx, prop, value);
  7564. return ctx[prop];
  7565. }
  7566. /**
  7567. * @param {string} [stroke] If specified, do not check style.textStroke.
  7568. * @param {string} [lineWidth] If specified, do not check style.textStroke.
  7569. * @param {number} style
  7570. */
  7571. function getStroke(stroke, lineWidth) {
  7572. return stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none' ? null // TODO pattern and gradient?
  7573. : stroke.image || stroke.colorStops ? '#000' : stroke;
  7574. }
  7575. function getFill(fill) {
  7576. return fill == null || fill === 'none' ? null // TODO pattern and gradient?
  7577. : fill.image || fill.colorStops ? '#000' : fill;
  7578. }
  7579. function parsePercent(value, maxValue) {
  7580. if (typeof value === 'string') {
  7581. if (value.lastIndexOf('%') >= 0) {
  7582. return parseFloat(value) / 100 * maxValue;
  7583. }
  7584. return parseFloat(value);
  7585. }
  7586. return value;
  7587. }
  7588. function getTextXForPadding(x, textAlign, textPadding) {
  7589. return textAlign === 'right' ? x - textPadding[1] : textAlign === 'center' ? x + textPadding[3] / 2 - textPadding[1] / 2 : x + textPadding[3];
  7590. }
  7591. /**
  7592. * @param {string} text
  7593. * @param {module:zrender/Style} style
  7594. * @return {boolean}
  7595. */
  7596. function needDrawText(text, style) {
  7597. return text != null && (text || style.textBackgroundColor || style.textBorderWidth && style.textBorderColor || style.textPadding);
  7598. }
  7599. /**
  7600. * Mixin for drawing text in a element bounding rect
  7601. * @module zrender/mixin/RectText
  7602. */
  7603. var tmpRect$1 = new BoundingRect();
  7604. var RectText = function () {};
  7605. RectText.prototype = {
  7606. constructor: RectText,
  7607. /**
  7608. * Draw text in a rect with specified position.
  7609. * @param {CanvasRenderingContext2D} ctx
  7610. * @param {Object} rect Displayable rect
  7611. */
  7612. drawRectText: function (ctx, rect) {
  7613. var style = this.style;
  7614. rect = style.textRect || rect; // Optimize, avoid normalize every time.
  7615. this.__dirty && normalizeTextStyle(style, true);
  7616. var text = style.text; // Convert to string
  7617. text != null && (text += '');
  7618. if (!needDrawText(text, style)) {
  7619. return;
  7620. } // FIXME
  7621. // Do not provide prevEl to `textHelper.renderText` for ctx prop cache,
  7622. // but use `ctx.save()` and `ctx.restore()`. Because the cache for rect
  7623. // text propably break the cache for its host elements.
  7624. ctx.save(); // Transform rect to view space
  7625. var transform = this.transform;
  7626. if (!style.transformText) {
  7627. if (transform) {
  7628. tmpRect$1.copy(rect);
  7629. tmpRect$1.applyTransform(transform);
  7630. rect = tmpRect$1;
  7631. }
  7632. } else {
  7633. this.setTransform(ctx);
  7634. } // transformText and textRotation can not be used at the same time.
  7635. renderText(this, ctx, text, style, rect, WILL_BE_RESTORED);
  7636. ctx.restore();
  7637. }
  7638. };
  7639. /**
  7640. * Base class of all displayable graphic objects
  7641. * @module zrender/graphic/Displayable
  7642. */
  7643. /**
  7644. * @alias module:zrender/graphic/Displayable
  7645. * @extends module:zrender/Element
  7646. * @extends module:zrender/graphic/mixin/RectText
  7647. */
  7648. function Displayable(opts) {
  7649. opts = opts || {};
  7650. Element.call(this, opts); // Extend properties
  7651. for (var name in opts) {
  7652. if (opts.hasOwnProperty(name) && name !== 'style') {
  7653. this[name] = opts[name];
  7654. }
  7655. }
  7656. /**
  7657. * @type {module:zrender/graphic/Style}
  7658. */
  7659. this.style = new Style(opts.style, this);
  7660. this._rect = null; // Shapes for cascade clipping.
  7661. // Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.
  7662. // because it is easy to only using null to check whether clipPaths changed.
  7663. this.__clipPaths = null; // FIXME Stateful must be mixined after style is setted
  7664. // Stateful.call(this, opts);
  7665. }
  7666. Displayable.prototype = {
  7667. constructor: Displayable,
  7668. type: 'displayable',
  7669. /**
  7670. * Dirty flag. From which painter will determine if this displayable object needs brush.
  7671. * @name module:zrender/graphic/Displayable#__dirty
  7672. * @type {boolean}
  7673. */
  7674. __dirty: true,
  7675. /**
  7676. * Whether the displayable object is visible. when it is true, the displayable object
  7677. * is not drawn, but the mouse event can still trigger the object.
  7678. * @name module:/zrender/graphic/Displayable#invisible
  7679. * @type {boolean}
  7680. * @default false
  7681. */
  7682. invisible: false,
  7683. /**
  7684. * @name module:/zrender/graphic/Displayable#z
  7685. * @type {number}
  7686. * @default 0
  7687. */
  7688. z: 0,
  7689. /**
  7690. * @name module:/zrender/graphic/Displayable#z
  7691. * @type {number}
  7692. * @default 0
  7693. */
  7694. z2: 0,
  7695. /**
  7696. * The z level determines the displayable object can be drawn in which layer canvas.
  7697. * @name module:/zrender/graphic/Displayable#zlevel
  7698. * @type {number}
  7699. * @default 0
  7700. */
  7701. zlevel: 0,
  7702. /**
  7703. * Whether it can be dragged.
  7704. * @name module:/zrender/graphic/Displayable#draggable
  7705. * @type {boolean}
  7706. * @default false
  7707. */
  7708. draggable: false,
  7709. /**
  7710. * Whether is it dragging.
  7711. * @name module:/zrender/graphic/Displayable#draggable
  7712. * @type {boolean}
  7713. * @default false
  7714. */
  7715. dragging: false,
  7716. /**
  7717. * Whether to respond to mouse events.
  7718. * @name module:/zrender/graphic/Displayable#silent
  7719. * @type {boolean}
  7720. * @default false
  7721. */
  7722. silent: false,
  7723. /**
  7724. * If enable culling
  7725. * @type {boolean}
  7726. * @default false
  7727. */
  7728. culling: false,
  7729. /**
  7730. * Mouse cursor when hovered
  7731. * @name module:/zrender/graphic/Displayable#cursor
  7732. * @type {string}
  7733. */
  7734. cursor: 'pointer',
  7735. /**
  7736. * If hover area is bounding rect
  7737. * @name module:/zrender/graphic/Displayable#rectHover
  7738. * @type {string}
  7739. */
  7740. rectHover: false,
  7741. /**
  7742. * Render the element progressively when the value >= 0,
  7743. * usefull for large data.
  7744. * @type {boolean}
  7745. */
  7746. progressive: false,
  7747. /**
  7748. * @type {boolean}
  7749. */
  7750. incremental: false,
  7751. /**
  7752. * Scale ratio for global scale.
  7753. * @type {boolean}
  7754. */
  7755. globalScaleRatio: 1,
  7756. beforeBrush: function (ctx) {},
  7757. afterBrush: function (ctx) {},
  7758. /**
  7759. * Graphic drawing method.
  7760. * @param {CanvasRenderingContext2D} ctx
  7761. */
  7762. // Interface
  7763. brush: function (ctx, prevEl) {},
  7764. /**
  7765. * Get the minimum bounding box.
  7766. * @return {module:zrender/core/BoundingRect}
  7767. */
  7768. // Interface
  7769. getBoundingRect: function () {},
  7770. /**
  7771. * If displayable element contain coord x, y
  7772. * @param {number} x
  7773. * @param {number} y
  7774. * @return {boolean}
  7775. */
  7776. contain: function (x, y) {
  7777. return this.rectContain(x, y);
  7778. },
  7779. /**
  7780. * @param {Function} cb
  7781. * @param {} context
  7782. */
  7783. traverse: function (cb, context) {
  7784. cb.call(context, this);
  7785. },
  7786. /**
  7787. * If bounding rect of element contain coord x, y
  7788. * @param {number} x
  7789. * @param {number} y
  7790. * @return {boolean}
  7791. */
  7792. rectContain: function (x, y) {
  7793. var coord = this.transformCoordToLocal(x, y);
  7794. var rect = this.getBoundingRect();
  7795. return rect.contain(coord[0], coord[1]);
  7796. },
  7797. /**
  7798. * Mark displayable element dirty and refresh next frame
  7799. */
  7800. dirty: function () {
  7801. this.__dirty = this.__dirtyText = true;
  7802. this._rect = null;
  7803. this.__zr && this.__zr.refresh();
  7804. },
  7805. /**
  7806. * If displayable object binded any event
  7807. * @return {boolean}
  7808. */
  7809. // TODO, events bound by bind
  7810. // isSilent: function () {
  7811. // return !(
  7812. // this.hoverable || this.draggable
  7813. // || this.onmousemove || this.onmouseover || this.onmouseout
  7814. // || this.onmousedown || this.onmouseup || this.onclick
  7815. // || this.ondragenter || this.ondragover || this.ondragleave
  7816. // || this.ondrop
  7817. // );
  7818. // },
  7819. /**
  7820. * Alias for animate('style')
  7821. * @param {boolean} loop
  7822. */
  7823. animateStyle: function (loop) {
  7824. return this.animate('style', loop);
  7825. },
  7826. attrKV: function (key, value) {
  7827. if (key !== 'style') {
  7828. Element.prototype.attrKV.call(this, key, value);
  7829. } else {
  7830. this.style.set(value);
  7831. }
  7832. },
  7833. /**
  7834. * @param {Object|string} key
  7835. * @param {*} value
  7836. */
  7837. setStyle: function (key, value) {
  7838. this.style.set(key, value);
  7839. this.dirty(false);
  7840. return this;
  7841. },
  7842. /**
  7843. * Use given style object
  7844. * @param {Object} obj
  7845. */
  7846. useStyle: function (obj) {
  7847. this.style = new Style(obj, this);
  7848. this.dirty(false);
  7849. return this;
  7850. },
  7851. /**
  7852. * The string value of `textPosition` needs to be calculated to a real postion.
  7853. * For example, `'inside'` is calculated to `[rect.width/2, rect.height/2]`
  7854. * by default. See `contain/text.js#calculateTextPosition` for more details.
  7855. * But some coutom shapes like "pin", "flag" have center that is not exactly
  7856. * `[width/2, height/2]`. So we provide this hook to customize the calculation
  7857. * for those shapes. It will be called if the `style.textPosition` is a string.
  7858. * @param {Obejct} [out] Prepared out object. If not provided, this method should
  7859. * be responsible for creating one.
  7860. * @param {module:zrender/graphic/Style} style
  7861. * @param {Object} rect {x, y, width, height}
  7862. * @return {Obejct} out The same as the input out.
  7863. * {
  7864. * x: number. mandatory.
  7865. * y: number. mandatory.
  7866. * textAlign: string. optional. use style.textAlign by default.
  7867. * textVerticalAlign: string. optional. use style.textVerticalAlign by default.
  7868. * }
  7869. */
  7870. calculateTextPosition: null
  7871. };
  7872. inherits(Displayable, Element);
  7873. mixin(Displayable, RectText); // zrUtil.mixin(Displayable, Stateful);
  7874. /**
  7875. * @alias zrender/graphic/Image
  7876. * @extends module:zrender/graphic/Displayable
  7877. * @constructor
  7878. * @param {Object} opts
  7879. */
  7880. function ZImage(opts) {
  7881. Displayable.call(this, opts);
  7882. }
  7883. ZImage.prototype = {
  7884. constructor: ZImage,
  7885. type: 'image',
  7886. brush: function (ctx, prevEl) {
  7887. var style = this.style;
  7888. var src = style.image; // Must bind each time
  7889. style.bind(ctx, this, prevEl);
  7890. var image = this._image = createOrUpdateImage(src, this._image, this, this.onload);
  7891. if (!image || !isImageReady(image)) {
  7892. return;
  7893. } // 图片已经加载完成
  7894. // if (image.nodeName.toUpperCase() == 'IMG') {
  7895. // if (!image.complete) {
  7896. // return;
  7897. // }
  7898. // }
  7899. // Else is canvas
  7900. var x = style.x || 0;
  7901. var y = style.y || 0;
  7902. var width = style.width;
  7903. var height = style.height;
  7904. var aspect = image.width / image.height;
  7905. if (width == null && height != null) {
  7906. // Keep image/height ratio
  7907. width = height * aspect;
  7908. } else if (height == null && width != null) {
  7909. height = width / aspect;
  7910. } else if (width == null && height == null) {
  7911. width = image.width;
  7912. height = image.height;
  7913. } // 设置transform
  7914. this.setTransform(ctx);
  7915. if (style.sWidth && style.sHeight) {
  7916. var sx = style.sx || 0;
  7917. var sy = style.sy || 0;
  7918. ctx.drawImage(image, sx, sy, style.sWidth, style.sHeight, x, y, width, height);
  7919. } else if (style.sx && style.sy) {
  7920. var sx = style.sx;
  7921. var sy = style.sy;
  7922. var sWidth = width - sx;
  7923. var sHeight = height - sy;
  7924. ctx.drawImage(image, sx, sy, sWidth, sHeight, x, y, width, height);
  7925. } else {
  7926. ctx.drawImage(image, x, y, width, height);
  7927. } // Draw rect text
  7928. if (style.text != null) {
  7929. // Only restore transform when needs draw text.
  7930. this.restoreTransform(ctx);
  7931. this.drawRectText(ctx, this.getBoundingRect());
  7932. }
  7933. },
  7934. getBoundingRect: function () {
  7935. var style = this.style;
  7936. if (!this._rect) {
  7937. this._rect = new BoundingRect(style.x || 0, style.y || 0, style.width || 0, style.height || 0);
  7938. }
  7939. return this._rect;
  7940. }
  7941. };
  7942. inherits(ZImage, Displayable);
  7943. var HOVER_LAYER_ZLEVEL = 1e5;
  7944. var CANVAS_ZLEVEL = 314159;
  7945. var EL_AFTER_INCREMENTAL_INC = 0.01;
  7946. var INCREMENTAL_INC = 0.001;
  7947. function parseInt10(val) {
  7948. return parseInt(val, 10);
  7949. }
  7950. function isLayerValid(layer) {
  7951. if (!layer) {
  7952. return false;
  7953. }
  7954. if (layer.__builtin__) {
  7955. return true;
  7956. }
  7957. if (typeof layer.resize !== 'function' || typeof layer.refresh !== 'function') {
  7958. return false;
  7959. }
  7960. return true;
  7961. }
  7962. var tmpRect = new BoundingRect(0, 0, 0, 0);
  7963. var viewRect = new BoundingRect(0, 0, 0, 0);
  7964. function isDisplayableCulled(el, width, height) {
  7965. tmpRect.copy(el.getBoundingRect());
  7966. if (el.transform) {
  7967. tmpRect.applyTransform(el.transform);
  7968. }
  7969. viewRect.width = width;
  7970. viewRect.height = height;
  7971. return !tmpRect.intersect(viewRect);
  7972. }
  7973. function isClipPathChanged(clipPaths, prevClipPaths) {
  7974. // displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
  7975. if (clipPaths === prevClipPaths) {
  7976. return false;
  7977. }
  7978. if (!clipPaths || !prevClipPaths || clipPaths.length !== prevClipPaths.length) {
  7979. return true;
  7980. }
  7981. for (var i = 0; i < clipPaths.length; i++) {
  7982. if (clipPaths[i] !== prevClipPaths[i]) {
  7983. return true;
  7984. }
  7985. }
  7986. return false;
  7987. }
  7988. function doClip(clipPaths, ctx) {
  7989. for (var i = 0; i < clipPaths.length; i++) {
  7990. var clipPath = clipPaths[i];
  7991. clipPath.setTransform(ctx);
  7992. ctx.beginPath();
  7993. clipPath.buildPath(ctx, clipPath.shape);
  7994. ctx.clip(); // Transform back
  7995. clipPath.restoreTransform(ctx);
  7996. }
  7997. }
  7998. function createRoot(width, height) {
  7999. var domRoot = document.createElement('div'); // domRoot.onselectstart = returnFalse; // Avoid page selected
  8000. domRoot.style.cssText = ['position:relative', // IOS13 safari probably has a compositing bug (z order of the canvas and the consequent
  8001. // dom does not act as expected) when some of the parent dom has
  8002. // `-webkit-overflow-scrolling: touch;` and the webpage is longer than one screen and
  8003. // the canvas is not at the top part of the page.
  8004. // Check `https://bugs.webkit.org/show_bug.cgi?id=203681` for more details. We remove
  8005. // this `overflow:hidden` to avoid the bug.
  8006. // 'overflow:hidden',
  8007. 'width:' + width + 'px', 'height:' + height + 'px', 'padding:0', 'margin:0', 'border-width:0'].join(';') + ';';
  8008. return domRoot;
  8009. }
  8010. /**
  8011. * @alias module:zrender/Painter
  8012. * @constructor
  8013. * @param {HTMLElement} root 绘图容器
  8014. * @param {module:zrender/Storage} storage
  8015. * @param {Object} opts
  8016. */
  8017. var Painter = function (root, storage, opts) {
  8018. this.type = 'canvas'; // In node environment using node-canvas
  8019. var singleCanvas = !root.nodeName // In node ?
  8020. || root.nodeName.toUpperCase() === 'CANVAS';
  8021. this._opts = opts = extend({}, opts || {});
  8022. /**
  8023. * @type {number}
  8024. */
  8025. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  8026. /**
  8027. * @type {boolean}
  8028. * @private
  8029. */
  8030. this._singleCanvas = singleCanvas;
  8031. /**
  8032. * 绘图容器
  8033. * @type {HTMLElement}
  8034. */
  8035. this.root = root;
  8036. var rootStyle = root.style;
  8037. if (rootStyle) {
  8038. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  8039. rootStyle['-webkit-user-select'] = rootStyle['user-select'] = rootStyle['-webkit-touch-callout'] = 'none';
  8040. root.innerHTML = '';
  8041. }
  8042. /**
  8043. * @type {module:zrender/Storage}
  8044. */
  8045. this.storage = storage;
  8046. /**
  8047. * @type {Array.<number>}
  8048. * @private
  8049. */
  8050. var zlevelList = this._zlevelList = [];
  8051. /**
  8052. * @type {Object.<string, module:zrender/Layer>}
  8053. * @private
  8054. */
  8055. var layers = this._layers = {};
  8056. /**
  8057. * @type {Object.<string, Object>}
  8058. * @private
  8059. */
  8060. this._layerConfig = {};
  8061. /**
  8062. * zrender will do compositing when root is a canvas and have multiple zlevels.
  8063. */
  8064. this._needsManuallyCompositing = false;
  8065. if (!singleCanvas) {
  8066. this._width = this._getSize(0);
  8067. this._height = this._getSize(1);
  8068. var domRoot = this._domRoot = createRoot(this._width, this._height);
  8069. root.appendChild(domRoot);
  8070. } else {
  8071. var width = root.width;
  8072. var height = root.height;
  8073. if (opts.width != null) {
  8074. width = opts.width;
  8075. }
  8076. if (opts.height != null) {
  8077. height = opts.height;
  8078. }
  8079. this.dpr = opts.devicePixelRatio || 1; // Use canvas width and height directly
  8080. root.width = width * this.dpr;
  8081. root.height = height * this.dpr;
  8082. this._width = width;
  8083. this._height = height; // Create layer if only one given canvas
  8084. // Device can be specified to create a high dpi image.
  8085. var mainLayer = new Layer(root, this, this.dpr);
  8086. mainLayer.__builtin__ = true;
  8087. mainLayer.initContext(); // FIXME Use canvas width and height
  8088. // mainLayer.resize(width, height);
  8089. layers[CANVAS_ZLEVEL] = mainLayer;
  8090. mainLayer.zlevel = CANVAS_ZLEVEL; // Not use common zlevel.
  8091. zlevelList.push(CANVAS_ZLEVEL);
  8092. this._domRoot = root;
  8093. }
  8094. /**
  8095. * @type {module:zrender/Layer}
  8096. * @private
  8097. */
  8098. this._hoverlayer = null;
  8099. this._hoverElements = [];
  8100. };
  8101. Painter.prototype = {
  8102. constructor: Painter,
  8103. getType: function () {
  8104. return 'canvas';
  8105. },
  8106. /**
  8107. * If painter use a single canvas
  8108. * @return {boolean}
  8109. */
  8110. isSingleCanvas: function () {
  8111. return this._singleCanvas;
  8112. },
  8113. /**
  8114. * @return {HTMLDivElement}
  8115. */
  8116. getViewportRoot: function () {
  8117. return this._domRoot;
  8118. },
  8119. getViewportRootOffset: function () {
  8120. var viewportRoot = this.getViewportRoot();
  8121. if (viewportRoot) {
  8122. return {
  8123. offsetLeft: viewportRoot.offsetLeft || 0,
  8124. offsetTop: viewportRoot.offsetTop || 0
  8125. };
  8126. }
  8127. },
  8128. /**
  8129. * 刷新
  8130. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  8131. */
  8132. refresh: function (paintAll) {
  8133. var list = this.storage.getDisplayList(true);
  8134. var zlevelList = this._zlevelList;
  8135. this._redrawId = Math.random();
  8136. this._paintList(list, paintAll, this._redrawId); // Paint custum layers
  8137. for (var i = 0; i < zlevelList.length; i++) {
  8138. var z = zlevelList[i];
  8139. var layer = this._layers[z];
  8140. if (!layer.__builtin__ && layer.refresh) {
  8141. var clearColor = i === 0 ? this._backgroundColor : null;
  8142. layer.refresh(clearColor);
  8143. }
  8144. }
  8145. this.refreshHover();
  8146. return this;
  8147. },
  8148. addHover: function (el, hoverStyle) {
  8149. if (el.__hoverMir) {
  8150. return;
  8151. }
  8152. var elMirror = new el.constructor({
  8153. style: el.style,
  8154. shape: el.shape,
  8155. z: el.z,
  8156. z2: el.z2,
  8157. silent: el.silent
  8158. });
  8159. elMirror.__from = el;
  8160. el.__hoverMir = elMirror;
  8161. hoverStyle && elMirror.setStyle(hoverStyle);
  8162. this._hoverElements.push(elMirror);
  8163. return elMirror;
  8164. },
  8165. removeHover: function (el) {
  8166. var elMirror = el.__hoverMir;
  8167. var hoverElements = this._hoverElements;
  8168. var idx = indexOf(hoverElements, elMirror);
  8169. if (idx >= 0) {
  8170. hoverElements.splice(idx, 1);
  8171. }
  8172. el.__hoverMir = null;
  8173. },
  8174. clearHover: function (el) {
  8175. var hoverElements = this._hoverElements;
  8176. for (var i = 0; i < hoverElements.length; i++) {
  8177. var from = hoverElements[i].__from;
  8178. if (from) {
  8179. from.__hoverMir = null;
  8180. }
  8181. }
  8182. hoverElements.length = 0;
  8183. },
  8184. refreshHover: function () {
  8185. var hoverElements = this._hoverElements;
  8186. var len = hoverElements.length;
  8187. var hoverLayer = this._hoverlayer;
  8188. hoverLayer && hoverLayer.clear();
  8189. if (!len) {
  8190. return;
  8191. }
  8192. sort(hoverElements, this.storage.displayableSortFunc); // Use a extream large zlevel
  8193. // FIXME?
  8194. if (!hoverLayer) {
  8195. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  8196. }
  8197. var scope = {};
  8198. hoverLayer.ctx.save();
  8199. for (var i = 0; i < len;) {
  8200. var el = hoverElements[i];
  8201. var originalEl = el.__from; // Original el is removed
  8202. // PENDING
  8203. if (!(originalEl && originalEl.__zr)) {
  8204. hoverElements.splice(i, 1);
  8205. originalEl.__hoverMir = null;
  8206. len--;
  8207. continue;
  8208. }
  8209. i++; // Use transform
  8210. // FIXME style and shape ?
  8211. if (!originalEl.invisible) {
  8212. el.transform = originalEl.transform;
  8213. el.invTransform = originalEl.invTransform;
  8214. el.__clipPaths = originalEl.__clipPaths; // el.
  8215. this._doPaintEl(el, hoverLayer, true, scope);
  8216. }
  8217. }
  8218. hoverLayer.ctx.restore();
  8219. },
  8220. getHoverLayer: function () {
  8221. return this.getLayer(HOVER_LAYER_ZLEVEL);
  8222. },
  8223. _paintList: function (list, paintAll, redrawId) {
  8224. if (this._redrawId !== redrawId) {
  8225. return;
  8226. }
  8227. paintAll = paintAll || false;
  8228. this._updateLayerStatus(list);
  8229. var finished = this._doPaintList(list, paintAll);
  8230. if (this._needsManuallyCompositing) {
  8231. this._compositeManually();
  8232. }
  8233. if (!finished) {
  8234. var self = this;
  8235. requestAnimationFrame(function () {
  8236. self._paintList(list, paintAll, redrawId);
  8237. });
  8238. }
  8239. },
  8240. _compositeManually: function () {
  8241. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  8242. var width = this._domRoot.width;
  8243. var height = this._domRoot.height;
  8244. ctx.clearRect(0, 0, width, height); // PENDING, If only builtin layer?
  8245. this.eachBuiltinLayer(function (layer) {
  8246. if (layer.virtual) {
  8247. ctx.drawImage(layer.dom, 0, 0, width, height);
  8248. }
  8249. });
  8250. },
  8251. _doPaintList: function (list, paintAll) {
  8252. var layerList = [];
  8253. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  8254. var zlevel = this._zlevelList[zi];
  8255. var layer = this._layers[zlevel];
  8256. if (layer.__builtin__ && layer !== this._hoverlayer && (layer.__dirty || paintAll)) {
  8257. layerList.push(layer);
  8258. }
  8259. }
  8260. var finished = true;
  8261. for (var k = 0; k < layerList.length; k++) {
  8262. var layer = layerList[k];
  8263. var ctx = layer.ctx;
  8264. var scope = {};
  8265. ctx.save();
  8266. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  8267. var useTimer = !paintAll && layer.incremental && Date.now;
  8268. var startTime = useTimer && Date.now();
  8269. var clearColor = layer.zlevel === this._zlevelList[0] ? this._backgroundColor : null; // All elements in this layer are cleared.
  8270. if (layer.__startIndex === layer.__endIndex) {
  8271. layer.clear(false, clearColor);
  8272. } else if (start === layer.__startIndex) {
  8273. var firstEl = list[start];
  8274. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  8275. layer.clear(false, clearColor);
  8276. }
  8277. }
  8278. if (start === -1) {
  8279. console.error('For some unknown reason. drawIndex is -1');
  8280. start = layer.__startIndex;
  8281. }
  8282. for (var i = start; i < layer.__endIndex; i++) {
  8283. var el = list[i];
  8284. this._doPaintEl(el, layer, paintAll, scope);
  8285. el.__dirty = el.__dirtyText = false;
  8286. if (useTimer) {
  8287. // Date.now can be executed in 13,025,305 ops/second.
  8288. var dTime = Date.now() - startTime; // Give 15 millisecond to draw.
  8289. // The rest elements will be drawn in the next frame.
  8290. if (dTime > 15) {
  8291. break;
  8292. }
  8293. }
  8294. }
  8295. layer.__drawIndex = i;
  8296. if (layer.__drawIndex < layer.__endIndex) {
  8297. finished = false;
  8298. }
  8299. if (scope.prevElClipPaths) {
  8300. // Needs restore the state. If last drawn element is in the clipping area.
  8301. ctx.restore();
  8302. }
  8303. ctx.restore();
  8304. }
  8305. if (env$1.wxa) {
  8306. // Flush for weixin application
  8307. each$1(this._layers, function (layer) {
  8308. if (layer && layer.ctx && layer.ctx.draw) {
  8309. layer.ctx.draw();
  8310. }
  8311. });
  8312. }
  8313. return finished;
  8314. },
  8315. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  8316. var ctx = currentLayer.ctx;
  8317. var m = el.transform;
  8318. if ((currentLayer.__dirty || forcePaint) && // Ignore invisible element
  8319. !el.invisible // Ignore transparent element
  8320. && el.style.opacity !== 0 // Ignore scale 0 element, in some environment like node-canvas
  8321. // Draw a scale 0 element can cause all following draw wrong
  8322. // And setTransform with scale 0 will cause set back transform failed.
  8323. && !(m && !m[0] && !m[3]) // Ignore culled element
  8324. && !(el.culling && isDisplayableCulled(el, this._width, this._height))) {
  8325. var clipPaths = el.__clipPaths;
  8326. var prevElClipPaths = scope.prevElClipPaths; // Optimize when clipping on group with several elements
  8327. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  8328. // If has previous clipping state, restore from it
  8329. if (prevElClipPaths) {
  8330. ctx.restore();
  8331. scope.prevElClipPaths = null; // Reset prevEl since context has been restored
  8332. scope.prevEl = null;
  8333. } // New clipping state
  8334. if (clipPaths) {
  8335. ctx.save();
  8336. doClip(clipPaths, ctx);
  8337. scope.prevElClipPaths = clipPaths;
  8338. }
  8339. }
  8340. el.beforeBrush && el.beforeBrush(ctx);
  8341. el.brush(ctx, scope.prevEl || null);
  8342. scope.prevEl = el;
  8343. el.afterBrush && el.afterBrush(ctx);
  8344. }
  8345. },
  8346. /**
  8347. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  8348. * @param {number} zlevel
  8349. * @param {boolean} virtual Virtual layer will not be inserted into dom.
  8350. * @return {module:zrender/Layer}
  8351. */
  8352. getLayer: function (zlevel, virtual) {
  8353. if (this._singleCanvas && !this._needsManuallyCompositing) {
  8354. zlevel = CANVAS_ZLEVEL;
  8355. }
  8356. var layer = this._layers[zlevel];
  8357. if (!layer) {
  8358. // Create a new layer
  8359. layer = new Layer('zr_' + zlevel, this, this.dpr);
  8360. layer.zlevel = zlevel;
  8361. layer.__builtin__ = true;
  8362. if (this._layerConfig[zlevel]) {
  8363. merge(layer, this._layerConfig[zlevel], true);
  8364. } // TODO Remove EL_AFTER_INCREMENTAL_INC magic number
  8365. else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  8366. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  8367. }
  8368. if (virtual) {
  8369. layer.virtual = virtual;
  8370. }
  8371. this.insertLayer(zlevel, layer); // Context is created after dom inserted to document
  8372. // Or excanvas will get 0px clientWidth and clientHeight
  8373. layer.initContext();
  8374. }
  8375. return layer;
  8376. },
  8377. insertLayer: function (zlevel, layer) {
  8378. var layersMap = this._layers;
  8379. var zlevelList = this._zlevelList;
  8380. var len = zlevelList.length;
  8381. var prevLayer = null;
  8382. var i = -1;
  8383. var domRoot = this._domRoot;
  8384. if (layersMap[zlevel]) {
  8385. logError$1('ZLevel ' + zlevel + ' has been used already');
  8386. return;
  8387. } // Check if is a valid layer
  8388. if (!isLayerValid(layer)) {
  8389. logError$1('Layer of zlevel ' + zlevel + ' is not valid');
  8390. return;
  8391. }
  8392. if (len > 0 && zlevel > zlevelList[0]) {
  8393. for (i = 0; i < len - 1; i++) {
  8394. if (zlevelList[i] < zlevel && zlevelList[i + 1] > zlevel) {
  8395. break;
  8396. }
  8397. }
  8398. prevLayer = layersMap[zlevelList[i]];
  8399. }
  8400. zlevelList.splice(i + 1, 0, zlevel);
  8401. layersMap[zlevel] = layer; // Vitual layer will not directly show on the screen.
  8402. // (It can be a WebGL layer and assigned to a ZImage element)
  8403. // But it still under management of zrender.
  8404. if (!layer.virtual) {
  8405. if (prevLayer) {
  8406. var prevDom = prevLayer.dom;
  8407. if (prevDom.nextSibling) {
  8408. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  8409. } else {
  8410. domRoot.appendChild(layer.dom);
  8411. }
  8412. } else {
  8413. if (domRoot.firstChild) {
  8414. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  8415. } else {
  8416. domRoot.appendChild(layer.dom);
  8417. }
  8418. }
  8419. }
  8420. },
  8421. // Iterate each layer
  8422. eachLayer: function (cb, context) {
  8423. var zlevelList = this._zlevelList;
  8424. var z;
  8425. var i;
  8426. for (i = 0; i < zlevelList.length; i++) {
  8427. z = zlevelList[i];
  8428. cb.call(context, this._layers[z], z);
  8429. }
  8430. },
  8431. // Iterate each buildin layer
  8432. eachBuiltinLayer: function (cb, context) {
  8433. var zlevelList = this._zlevelList;
  8434. var layer;
  8435. var z;
  8436. var i;
  8437. for (i = 0; i < zlevelList.length; i++) {
  8438. z = zlevelList[i];
  8439. layer = this._layers[z];
  8440. if (layer.__builtin__) {
  8441. cb.call(context, layer, z);
  8442. }
  8443. }
  8444. },
  8445. // Iterate each other layer except buildin layer
  8446. eachOtherLayer: function (cb, context) {
  8447. var zlevelList = this._zlevelList;
  8448. var layer;
  8449. var z;
  8450. var i;
  8451. for (i = 0; i < zlevelList.length; i++) {
  8452. z = zlevelList[i];
  8453. layer = this._layers[z];
  8454. if (!layer.__builtin__) {
  8455. cb.call(context, layer, z);
  8456. }
  8457. }
  8458. },
  8459. /**
  8460. * 获取所有已创建的层
  8461. * @param {Array.<module:zrender/Layer>} [prevLayer]
  8462. */
  8463. getLayers: function () {
  8464. return this._layers;
  8465. },
  8466. _updateLayerStatus: function (list) {
  8467. this.eachBuiltinLayer(function (layer, z) {
  8468. layer.__dirty = layer.__used = false;
  8469. });
  8470. function updatePrevLayer(idx) {
  8471. if (prevLayer) {
  8472. if (prevLayer.__endIndex !== idx) {
  8473. prevLayer.__dirty = true;
  8474. }
  8475. prevLayer.__endIndex = idx;
  8476. }
  8477. }
  8478. if (this._singleCanvas) {
  8479. for (var i = 1; i < list.length; i++) {
  8480. var el = list[i];
  8481. if (el.zlevel !== list[i - 1].zlevel || el.incremental) {
  8482. this._needsManuallyCompositing = true;
  8483. break;
  8484. }
  8485. }
  8486. }
  8487. var prevLayer = null;
  8488. var incrementalLayerCount = 0;
  8489. var prevZlevel;
  8490. for (var i = 0; i < list.length; i++) {
  8491. var el = list[i];
  8492. var zlevel = el.zlevel;
  8493. var layer;
  8494. if (prevZlevel !== zlevel) {
  8495. prevZlevel = zlevel;
  8496. incrementalLayerCount = 0;
  8497. } // TODO Not use magic number on zlevel.
  8498. // Each layer with increment element can be separated to 3 layers.
  8499. // (Other Element drawn after incremental element)
  8500. // -----------------zlevel + EL_AFTER_INCREMENTAL_INC--------------------
  8501. // (Incremental element)
  8502. // ----------------------zlevel + INCREMENTAL_INC------------------------
  8503. // (Element drawn before incremental element)
  8504. // --------------------------------zlevel--------------------------------
  8505. if (el.incremental) {
  8506. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  8507. layer.incremental = true;
  8508. incrementalLayerCount = 1;
  8509. } else {
  8510. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  8511. }
  8512. if (!layer.__builtin__) {
  8513. logError$1('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  8514. }
  8515. if (layer !== prevLayer) {
  8516. layer.__used = true;
  8517. if (layer.__startIndex !== i) {
  8518. layer.__dirty = true;
  8519. }
  8520. layer.__startIndex = i;
  8521. if (!layer.incremental) {
  8522. layer.__drawIndex = i;
  8523. } else {
  8524. // Mark layer draw index needs to update.
  8525. layer.__drawIndex = -1;
  8526. }
  8527. updatePrevLayer(i);
  8528. prevLayer = layer;
  8529. }
  8530. if (el.__dirty) {
  8531. layer.__dirty = true;
  8532. if (layer.incremental && layer.__drawIndex < 0) {
  8533. // Start draw from the first dirty element.
  8534. layer.__drawIndex = i;
  8535. }
  8536. }
  8537. }
  8538. updatePrevLayer(i);
  8539. this.eachBuiltinLayer(function (layer, z) {
  8540. // Used in last frame but not in this frame. Needs clear
  8541. if (!layer.__used && layer.getElementCount() > 0) {
  8542. layer.__dirty = true;
  8543. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  8544. } // For incremental layer. In case start index changed and no elements are dirty.
  8545. if (layer.__dirty && layer.__drawIndex < 0) {
  8546. layer.__drawIndex = layer.__startIndex;
  8547. }
  8548. });
  8549. },
  8550. /**
  8551. * 清除hover层外所有内容
  8552. */
  8553. clear: function () {
  8554. this.eachBuiltinLayer(this._clearLayer);
  8555. return this;
  8556. },
  8557. _clearLayer: function (layer) {
  8558. layer.clear();
  8559. },
  8560. setBackgroundColor: function (backgroundColor) {
  8561. this._backgroundColor = backgroundColor;
  8562. },
  8563. /**
  8564. * 修改指定zlevel的绘制参数
  8565. *
  8566. * @param {string} zlevel
  8567. * @param {Object} config 配置对象
  8568. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  8569. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  8570. * @param {number} [config.lastFrameAlpha=0.7]
  8571. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  8572. */
  8573. configLayer: function (zlevel, config) {
  8574. if (config) {
  8575. var layerConfig = this._layerConfig;
  8576. if (!layerConfig[zlevel]) {
  8577. layerConfig[zlevel] = config;
  8578. } else {
  8579. merge(layerConfig[zlevel], config, true);
  8580. }
  8581. for (var i = 0; i < this._zlevelList.length; i++) {
  8582. var _zlevel = this._zlevelList[i]; // TODO Remove EL_AFTER_INCREMENTAL_INC magic number
  8583. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  8584. var layer = this._layers[_zlevel];
  8585. merge(layer, layerConfig[zlevel], true);
  8586. }
  8587. }
  8588. }
  8589. },
  8590. /**
  8591. * 删除指定层
  8592. * @param {number} zlevel 层所在的zlevel
  8593. */
  8594. delLayer: function (zlevel) {
  8595. var layers = this._layers;
  8596. var zlevelList = this._zlevelList;
  8597. var layer = layers[zlevel];
  8598. if (!layer) {
  8599. return;
  8600. }
  8601. layer.dom.parentNode.removeChild(layer.dom);
  8602. delete layers[zlevel];
  8603. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  8604. },
  8605. /**
  8606. * 区域大小变化后重绘
  8607. */
  8608. resize: function (width, height) {
  8609. if (!this._domRoot.style) {
  8610. // Maybe in node or worker
  8611. if (width == null || height == null) {
  8612. return;
  8613. }
  8614. this._width = width;
  8615. this._height = height;
  8616. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  8617. } else {
  8618. var domRoot = this._domRoot; // FIXME Why ?
  8619. domRoot.style.display = 'none'; // Save input w/h
  8620. var opts = this._opts;
  8621. width != null && (opts.width = width);
  8622. height != null && (opts.height = height);
  8623. width = this._getSize(0);
  8624. height = this._getSize(1);
  8625. domRoot.style.display = ''; // 优化没有实际改变的resize
  8626. if (this._width !== width || height !== this._height) {
  8627. domRoot.style.width = width + 'px';
  8628. domRoot.style.height = height + 'px';
  8629. for (var id in this._layers) {
  8630. if (this._layers.hasOwnProperty(id)) {
  8631. this._layers[id].resize(width, height);
  8632. }
  8633. }
  8634. each$1(this._progressiveLayers, function (layer) {
  8635. layer.resize(width, height);
  8636. });
  8637. this.refresh(true);
  8638. }
  8639. this._width = width;
  8640. this._height = height;
  8641. }
  8642. return this;
  8643. },
  8644. /**
  8645. * 清除单独的一个层
  8646. * @param {number} zlevel
  8647. */
  8648. clearLayer: function (zlevel) {
  8649. var layer = this._layers[zlevel];
  8650. if (layer) {
  8651. layer.clear();
  8652. }
  8653. },
  8654. /**
  8655. * 释放
  8656. */
  8657. dispose: function () {
  8658. this.root.innerHTML = '';
  8659. this.root = this.storage = this._domRoot = this._layers = null;
  8660. },
  8661. /**
  8662. * Get canvas which has all thing rendered
  8663. * @param {Object} opts
  8664. * @param {string} [opts.backgroundColor]
  8665. * @param {number} [opts.pixelRatio]
  8666. */
  8667. getRenderedCanvas: function (opts) {
  8668. opts = opts || {};
  8669. if (this._singleCanvas && !this._compositeManually) {
  8670. return this._layers[CANVAS_ZLEVEL].dom;
  8671. }
  8672. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  8673. imageLayer.initContext();
  8674. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  8675. if (opts.pixelRatio <= this.dpr) {
  8676. this.refresh();
  8677. var width = imageLayer.dom.width;
  8678. var height = imageLayer.dom.height;
  8679. var ctx = imageLayer.ctx;
  8680. this.eachLayer(function (layer) {
  8681. if (layer.__builtin__) {
  8682. ctx.drawImage(layer.dom, 0, 0, width, height);
  8683. } else if (layer.renderToCanvas) {
  8684. imageLayer.ctx.save();
  8685. layer.renderToCanvas(imageLayer.ctx);
  8686. imageLayer.ctx.restore();
  8687. }
  8688. });
  8689. } else {
  8690. // PENDING, echarts-gl and incremental rendering.
  8691. var scope = {};
  8692. var displayList = this.storage.getDisplayList(true);
  8693. for (var i = 0; i < displayList.length; i++) {
  8694. var el = displayList[i];
  8695. this._doPaintEl(el, imageLayer, true, scope);
  8696. }
  8697. }
  8698. return imageLayer.dom;
  8699. },
  8700. /**
  8701. * 获取绘图区域宽度
  8702. */
  8703. getWidth: function () {
  8704. return this._width;
  8705. },
  8706. /**
  8707. * 获取绘图区域高度
  8708. */
  8709. getHeight: function () {
  8710. return this._height;
  8711. },
  8712. _getSize: function (whIdx) {
  8713. var opts = this._opts;
  8714. var wh = ['width', 'height'][whIdx];
  8715. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  8716. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  8717. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  8718. if (opts[wh] != null && opts[wh] !== 'auto') {
  8719. return parseFloat(opts[wh]);
  8720. }
  8721. var root = this.root; // IE8 does not support getComputedStyle, but it use VML.
  8722. var stl = document.defaultView.getComputedStyle(root);
  8723. return (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh])) - (parseInt10(stl[plt]) || 0) - (parseInt10(stl[prb]) || 0) | 0;
  8724. },
  8725. pathToImage: function (path, dpr) {
  8726. dpr = dpr || this.dpr;
  8727. var canvas = document.createElement('canvas');
  8728. var ctx = canvas.getContext('2d');
  8729. var rect = path.getBoundingRect();
  8730. var style = path.style;
  8731. var shadowBlurSize = style.shadowBlur * dpr;
  8732. var shadowOffsetX = style.shadowOffsetX * dpr;
  8733. var shadowOffsetY = style.shadowOffsetY * dpr;
  8734. var lineWidth = style.hasStroke() ? style.lineWidth : 0;
  8735. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  8736. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  8737. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  8738. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  8739. var width = rect.width + leftMargin + rightMargin;
  8740. var height = rect.height + topMargin + bottomMargin;
  8741. canvas.width = width * dpr;
  8742. canvas.height = height * dpr;
  8743. ctx.scale(dpr, dpr);
  8744. ctx.clearRect(0, 0, width, height);
  8745. ctx.dpr = dpr;
  8746. var pathTransform = {
  8747. position: path.position,
  8748. rotation: path.rotation,
  8749. scale: path.scale
  8750. };
  8751. path.position = [leftMargin - rect.x, topMargin - rect.y];
  8752. path.rotation = 0;
  8753. path.scale = [1, 1];
  8754. path.updateTransform();
  8755. if (path) {
  8756. path.brush(ctx);
  8757. }
  8758. var ImageShape = ZImage;
  8759. var imgShape = new ImageShape({
  8760. style: {
  8761. x: 0,
  8762. y: 0,
  8763. image: canvas
  8764. }
  8765. });
  8766. if (pathTransform.position != null) {
  8767. imgShape.position = path.position = pathTransform.position;
  8768. }
  8769. if (pathTransform.rotation != null) {
  8770. imgShape.rotation = path.rotation = pathTransform.rotation;
  8771. }
  8772. if (pathTransform.scale != null) {
  8773. imgShape.scale = path.scale = pathTransform.scale;
  8774. }
  8775. return imgShape;
  8776. }
  8777. };
  8778. /**
  8779. * Animation main class, dispatch and manage all animation controllers
  8780. *
  8781. * @module zrender/animation/Animation
  8782. * @author pissang(https://github.com/pissang)
  8783. */
  8784. // TODO Additive animation
  8785. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  8786. // https://developer.apple.com/videos/wwdc2014/#236
  8787. /**
  8788. * @typedef {Object} IZRenderStage
  8789. * @property {Function} update
  8790. */
  8791. /**
  8792. * @alias module:zrender/animation/Animation
  8793. * @constructor
  8794. * @param {Object} [options]
  8795. * @param {Function} [options.onframe]
  8796. * @param {IZRenderStage} [options.stage]
  8797. * @example
  8798. * var animation = new Animation();
  8799. * var obj = {
  8800. * x: 100,
  8801. * y: 100
  8802. * };
  8803. * animation.animate(node.position)
  8804. * .when(1000, {
  8805. * x: 500,
  8806. * y: 500
  8807. * })
  8808. * .when(2000, {
  8809. * x: 100,
  8810. * y: 100
  8811. * })
  8812. * .start('spline');
  8813. */
  8814. var Animation = function (options) {
  8815. options = options || {};
  8816. this.stage = options.stage || {};
  8817. this.onframe = options.onframe || function () {}; // private properties
  8818. this._clips = [];
  8819. this._running = false;
  8820. this._time;
  8821. this._pausedTime;
  8822. this._pauseStart;
  8823. this._paused = false;
  8824. Eventful.call(this);
  8825. };
  8826. Animation.prototype = {
  8827. constructor: Animation,
  8828. /**
  8829. * Add clip
  8830. * @param {module:zrender/animation/Clip} clip
  8831. */
  8832. addClip: function (clip) {
  8833. this._clips.push(clip);
  8834. },
  8835. /**
  8836. * Add animator
  8837. * @param {module:zrender/animation/Animator} animator
  8838. */
  8839. addAnimator: function (animator) {
  8840. animator.animation = this;
  8841. var clips = animator.getClips();
  8842. for (var i = 0; i < clips.length; i++) {
  8843. this.addClip(clips[i]);
  8844. }
  8845. },
  8846. /**
  8847. * Delete animation clip
  8848. * @param {module:zrender/animation/Clip} clip
  8849. */
  8850. removeClip: function (clip) {
  8851. var idx = indexOf(this._clips, clip);
  8852. if (idx >= 0) {
  8853. this._clips.splice(idx, 1);
  8854. }
  8855. },
  8856. /**
  8857. * Delete animation clip
  8858. * @param {module:zrender/animation/Animator} animator
  8859. */
  8860. removeAnimator: function (animator) {
  8861. var clips = animator.getClips();
  8862. for (var i = 0; i < clips.length; i++) {
  8863. this.removeClip(clips[i]);
  8864. }
  8865. animator.animation = null;
  8866. },
  8867. _update: function () {
  8868. var time = new Date().getTime() - this._pausedTime;
  8869. var delta = time - this._time;
  8870. var clips = this._clips;
  8871. var len = clips.length;
  8872. var deferredEvents = [];
  8873. var deferredClips = [];
  8874. for (var i = 0; i < len; i++) {
  8875. var clip = clips[i];
  8876. var e = clip.step(time, delta); // Throw out the events need to be called after
  8877. // stage.update, like destroy
  8878. if (e) {
  8879. deferredEvents.push(e);
  8880. deferredClips.push(clip);
  8881. }
  8882. } // Remove the finished clip
  8883. for (var i = 0; i < len;) {
  8884. if (clips[i]._needsRemove) {
  8885. clips[i] = clips[len - 1];
  8886. clips.pop();
  8887. len--;
  8888. } else {
  8889. i++;
  8890. }
  8891. }
  8892. len = deferredEvents.length;
  8893. for (var i = 0; i < len; i++) {
  8894. deferredClips[i].fire(deferredEvents[i]);
  8895. }
  8896. this._time = time;
  8897. this.onframe(delta); // 'frame' should be triggered before stage, because upper application
  8898. // depends on the sequence (e.g., echarts-stream and finish
  8899. // event judge)
  8900. this.trigger('frame', delta);
  8901. if (this.stage.update) {
  8902. this.stage.update();
  8903. }
  8904. },
  8905. _startLoop: function () {
  8906. var self = this;
  8907. this._running = true;
  8908. function step() {
  8909. if (self._running) {
  8910. requestAnimationFrame(step);
  8911. !self._paused && self._update();
  8912. }
  8913. }
  8914. requestAnimationFrame(step);
  8915. },
  8916. /**
  8917. * Start animation.
  8918. */
  8919. start: function () {
  8920. this._time = new Date().getTime();
  8921. this._pausedTime = 0;
  8922. this._startLoop();
  8923. },
  8924. /**
  8925. * Stop animation.
  8926. */
  8927. stop: function () {
  8928. this._running = false;
  8929. },
  8930. /**
  8931. * Pause animation.
  8932. */
  8933. pause: function () {
  8934. if (!this._paused) {
  8935. this._pauseStart = new Date().getTime();
  8936. this._paused = true;
  8937. }
  8938. },
  8939. /**
  8940. * Resume animation.
  8941. */
  8942. resume: function () {
  8943. if (this._paused) {
  8944. this._pausedTime += new Date().getTime() - this._pauseStart;
  8945. this._paused = false;
  8946. }
  8947. },
  8948. /**
  8949. * Clear animation.
  8950. */
  8951. clear: function () {
  8952. this._clips = [];
  8953. },
  8954. /**
  8955. * Whether animation finished.
  8956. */
  8957. isFinished: function () {
  8958. return !this._clips.length;
  8959. },
  8960. /**
  8961. * Creat animator for a target, whose props can be animated.
  8962. *
  8963. * @param {Object} target
  8964. * @param {Object} options
  8965. * @param {boolean} [options.loop=false] Whether loop animation.
  8966. * @param {Function} [options.getter=null] Get value from target.
  8967. * @param {Function} [options.setter=null] Set value to target.
  8968. * @return {module:zrender/animation/Animation~Animator}
  8969. */
  8970. // TODO Gap
  8971. animate: function (target, options) {
  8972. options = options || {};
  8973. var animator = new Animator(target, options.loop, options.getter, options.setter);
  8974. this.addAnimator(animator);
  8975. return animator;
  8976. }
  8977. };
  8978. mixin(Animation, Eventful);
  8979. /* global document */
  8980. var TOUCH_CLICK_DELAY = 300;
  8981. var globalEventSupported = env$1.domSupported;
  8982. var localNativeListenerNames = function () {
  8983. var mouseHandlerNames = ['click', 'dblclick', 'mousewheel', 'mouseout', 'mouseup', 'mousedown', 'mousemove', 'contextmenu'];
  8984. var touchHandlerNames = ['touchstart', 'touchend', 'touchmove'];
  8985. var pointerEventNameMap = {
  8986. pointerdown: 1,
  8987. pointerup: 1,
  8988. pointermove: 1,
  8989. pointerout: 1
  8990. };
  8991. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  8992. var nm = name.replace('mouse', 'pointer');
  8993. return pointerEventNameMap.hasOwnProperty(nm) ? nm : name;
  8994. });
  8995. return {
  8996. mouse: mouseHandlerNames,
  8997. touch: touchHandlerNames,
  8998. pointer: pointerHandlerNames
  8999. };
  9000. }();
  9001. var globalNativeListenerNames = {
  9002. mouse: ['mousemove', 'mouseup'],
  9003. pointer: ['pointermove', 'pointerup']
  9004. };
  9005. function eventNameFix(name) {
  9006. return name === 'mousewheel' && env$1.browser.firefox ? 'DOMMouseScroll' : name;
  9007. }
  9008. function isPointerFromTouch(event) {
  9009. var pointerType = event.pointerType;
  9010. return pointerType === 'pen' || pointerType === 'touch';
  9011. } // function useMSGuesture(handlerProxy, event) {
  9012. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  9013. // }
  9014. // function onMSGestureChange(proxy, event) {
  9015. // if (event.translationX || event.translationY) {
  9016. // // mousemove is carried by MSGesture to reduce the sensitivity.
  9017. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  9018. // }
  9019. // if (event.scale !== 1) {
  9020. // event.pinchX = event.offsetX;
  9021. // event.pinchY = event.offsetY;
  9022. // event.pinchScale = event.scale;
  9023. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  9024. // }
  9025. // }
  9026. /**
  9027. * Prevent mouse event from being dispatched after Touch Events action
  9028. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  9029. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  9030. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  9031. * Result: Blocking Mouse Events for 700ms.
  9032. *
  9033. * @param {DOMHandlerScope} scope
  9034. */
  9035. function setTouchTimer(scope) {
  9036. scope.touching = true;
  9037. if (scope.touchTimer != null) {
  9038. clearTimeout(scope.touchTimer);
  9039. scope.touchTimer = null;
  9040. }
  9041. scope.touchTimer = setTimeout(function () {
  9042. scope.touching = false;
  9043. scope.touchTimer = null;
  9044. }, 700);
  9045. } // Mark touch, which is useful in distinguish touch and
  9046. // mouse event in upper applicatoin.
  9047. function markTouch(event) {
  9048. event && (event.zrByTouch = true);
  9049. } // function markTriggeredFromLocal(event) {
  9050. // event && (event.__zrIsFromLocal = true);
  9051. // }
  9052. // function isTriggeredFromLocal(instance, event) {
  9053. // return !!(event && event.__zrIsFromLocal);
  9054. // }
  9055. function normalizeGlobalEvent(instance, event) {
  9056. // offsetX, offsetY still need to be calculated. They are necessary in the event
  9057. // handlers of the upper applications. Set `true` to force calculate them.
  9058. return normalizeEvent(instance.dom, new FakeGlobalEvent(instance, event), true);
  9059. }
  9060. /**
  9061. * Detect whether the given el is in `painterRoot`.
  9062. */
  9063. function isLocalEl(instance, el) {
  9064. var elTmp = el;
  9065. var isLocal = false;
  9066. while (elTmp && elTmp.nodeType !== 9 && !(isLocal = elTmp.domBelongToZr || elTmp !== el && elTmp === instance.painterRoot)) {
  9067. elTmp = elTmp.parentNode;
  9068. }
  9069. return isLocal;
  9070. }
  9071. /**
  9072. * Make a fake event but not change the original event,
  9073. * becuase the global event probably be used by other
  9074. * listeners not belonging to zrender.
  9075. * @class
  9076. */
  9077. function FakeGlobalEvent(instance, event) {
  9078. this.type = event.type;
  9079. this.target = this.currentTarget = instance.dom;
  9080. this.pointerType = event.pointerType; // Necessray for the force calculation of zrX, zrY
  9081. this.clientX = event.clientX;
  9082. this.clientY = event.clientY; // Because we do not mount global listeners to touch events,
  9083. // we do not copy `targetTouches` and `changedTouches` here.
  9084. }
  9085. var fakeGlobalEventProto = FakeGlobalEvent.prototype; // we make the default methods on the event do nothing,
  9086. // otherwise it is dangerous. See more details in
  9087. // [Drag outside] in `Handler.js`.
  9088. fakeGlobalEventProto.stopPropagation = fakeGlobalEventProto.stopImmediatePropagation = fakeGlobalEventProto.preventDefault = noop;
  9089. /**
  9090. * Local DOM Handlers
  9091. * @this {HandlerProxy}
  9092. */
  9093. var localDOMHandlers = {
  9094. mousedown: function (event) {
  9095. event = normalizeEvent(this.dom, event);
  9096. this._mayPointerCapture = [event.zrX, event.zrY];
  9097. this.trigger('mousedown', event);
  9098. },
  9099. mousemove: function (event) {
  9100. event = normalizeEvent(this.dom, event);
  9101. var downPoint = this._mayPointerCapture;
  9102. if (downPoint && (event.zrX !== downPoint[0] || event.zrY !== downPoint[1])) {
  9103. togglePointerCapture(this, true);
  9104. }
  9105. this.trigger('mousemove', event);
  9106. },
  9107. mouseup: function (event) {
  9108. event = normalizeEvent(this.dom, event);
  9109. togglePointerCapture(this, false);
  9110. this.trigger('mouseup', event);
  9111. },
  9112. mouseout: function (event) {
  9113. event = normalizeEvent(this.dom, event); // Similarly to the browser did on `document` and touch event,
  9114. // `globalout` will be delayed to final pointer cature release.
  9115. if (this._pointerCapturing) {
  9116. event.zrEventControl = 'no_globalout';
  9117. } // There might be some doms created by upper layer application
  9118. // at the same level of painter.getViewportRoot() (e.g., tooltip
  9119. // dom created by echarts), where 'globalout' event should not
  9120. // be triggered when mouse enters these doms. (But 'mouseout'
  9121. // should be triggered at the original hovered element as usual).
  9122. var element = event.toElement || event.relatedTarget;
  9123. event.zrIsToLocalDOM = isLocalEl(this, element);
  9124. this.trigger('mouseout', event);
  9125. },
  9126. touchstart: function (event) {
  9127. // Default mouse behaviour should not be disabled here.
  9128. // For example, page may needs to be slided.
  9129. event = normalizeEvent(this.dom, event);
  9130. markTouch(event);
  9131. this._lastTouchMoment = new Date();
  9132. this.handler.processGesture(event, 'start'); // For consistent event listener for both touch device and mouse device,
  9133. // we simulate "mouseover-->mousedown" in touch device. So we trigger
  9134. // `mousemove` here (to trigger `mouseover` inside), and then trigger
  9135. // `mousedown`.
  9136. localDOMHandlers.mousemove.call(this, event);
  9137. localDOMHandlers.mousedown.call(this, event);
  9138. },
  9139. touchmove: function (event) {
  9140. event = normalizeEvent(this.dom, event);
  9141. markTouch(event);
  9142. this.handler.processGesture(event, 'change'); // Mouse move should always be triggered no matter whether
  9143. // there is gestrue event, because mouse move and pinch may
  9144. // be used at the same time.
  9145. localDOMHandlers.mousemove.call(this, event);
  9146. },
  9147. touchend: function (event) {
  9148. event = normalizeEvent(this.dom, event);
  9149. markTouch(event);
  9150. this.handler.processGesture(event, 'end');
  9151. localDOMHandlers.mouseup.call(this, event); // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  9152. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  9153. // we can conveniently implement "hover style" in both PC and touch device just
  9154. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  9155. // to remove "hover style" on an element, without any additional code for
  9156. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  9157. // style" will remain for user view)
  9158. // click event should always be triggered no matter whether
  9159. // there is gestrue event. System click can not be prevented.
  9160. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  9161. localDOMHandlers.click.call(this, event);
  9162. }
  9163. },
  9164. pointerdown: function (event) {
  9165. localDOMHandlers.mousedown.call(this, event); // if (useMSGuesture(this, event)) {
  9166. // this._msGesture.addPointer(event.pointerId);
  9167. // }
  9168. },
  9169. pointermove: function (event) {
  9170. // FIXME
  9171. // pointermove is so sensitive that it always triggered when
  9172. // tap(click) on touch screen, which affect some judgement in
  9173. // upper application. So, we dont support mousemove on MS touch
  9174. // device yet.
  9175. if (!isPointerFromTouch(event)) {
  9176. localDOMHandlers.mousemove.call(this, event);
  9177. }
  9178. },
  9179. pointerup: function (event) {
  9180. localDOMHandlers.mouseup.call(this, event);
  9181. },
  9182. pointerout: function (event) {
  9183. // pointerout will be triggered when tap on touch screen
  9184. // (IE11+/Edge on MS Surface) after click event triggered,
  9185. // which is inconsistent with the mousout behavior we defined
  9186. // in touchend. So we unify them.
  9187. // (check localDOMHandlers.touchend for detailed explanation)
  9188. if (!isPointerFromTouch(event)) {
  9189. localDOMHandlers.mouseout.call(this, event);
  9190. }
  9191. }
  9192. };
  9193. /**
  9194. * Othere DOM UI Event handlers for zr dom.
  9195. * @this {HandlerProxy}
  9196. */
  9197. each$1(['click', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  9198. localDOMHandlers[name] = function (event) {
  9199. event = normalizeEvent(this.dom, event);
  9200. this.trigger(name, event);
  9201. };
  9202. });
  9203. /**
  9204. * DOM UI Event handlers for global page.
  9205. *
  9206. * [Caution]:
  9207. * those handlers should both support in capture phase and bubble phase!
  9208. *
  9209. * @this {HandlerProxy}
  9210. */
  9211. var globalDOMHandlers = {
  9212. pointermove: function (event) {
  9213. // FIXME
  9214. // pointermove is so sensitive that it always triggered when
  9215. // tap(click) on touch screen, which affect some judgement in
  9216. // upper application. So, we dont support mousemove on MS touch
  9217. // device yet.
  9218. if (!isPointerFromTouch(event)) {
  9219. globalDOMHandlers.mousemove.call(this, event);
  9220. }
  9221. },
  9222. pointerup: function (event) {
  9223. globalDOMHandlers.mouseup.call(this, event);
  9224. },
  9225. mousemove: function (event) {
  9226. this.trigger('mousemove', event);
  9227. },
  9228. mouseup: function (event) {
  9229. var pointerCaptureReleasing = this._pointerCapturing;
  9230. togglePointerCapture(this, false);
  9231. this.trigger('mouseup', event);
  9232. if (pointerCaptureReleasing) {
  9233. event.zrEventControl = 'only_globalout';
  9234. this.trigger('mouseout', event);
  9235. }
  9236. }
  9237. };
  9238. /**
  9239. * @param {HandlerProxy} instance
  9240. * @param {DOMHandlerScope} scope
  9241. */
  9242. function mountLocalDOMEventListeners(instance, scope) {
  9243. var domHandlers = scope.domHandlers;
  9244. if (env$1.pointerEventsSupported) {
  9245. // Only IE11+/Edge
  9246. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  9247. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  9248. // at the same time.
  9249. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  9250. // screen, which do not occurs in pointer event.
  9251. // So we use pointer event to both detect touch gesture and mouse behavior.
  9252. each$1(localNativeListenerNames.pointer, function (nativeEventName) {
  9253. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9254. // markTriggeredFromLocal(event);
  9255. domHandlers[nativeEventName].call(instance, event);
  9256. });
  9257. }); // FIXME
  9258. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  9259. // which does not prevent defuault behavior occasionally (which may cause view port
  9260. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  9261. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  9262. // touch screen. And we only support click behavior on MS touch screen now.
  9263. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  9264. // We dont support touch on IE on win7.
  9265. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  9266. // if (typeof MSGesture === 'function') {
  9267. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  9268. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  9269. // }
  9270. } else {
  9271. if (env$1.touchEventsSupported) {
  9272. each$1(localNativeListenerNames.touch, function (nativeEventName) {
  9273. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9274. // markTriggeredFromLocal(event);
  9275. domHandlers[nativeEventName].call(instance, event);
  9276. setTouchTimer(scope);
  9277. });
  9278. }); // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  9279. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  9280. } // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  9281. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  9282. // mouse event can not be handle in those devices.
  9283. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  9284. // mouseevent after touch event triggered, see `setTouchTimer`.
  9285. each$1(localNativeListenerNames.mouse, function (nativeEventName) {
  9286. mountSingleDOMEventListener(scope, nativeEventName, function (event) {
  9287. event = getNativeEvent(event);
  9288. if (!scope.touching) {
  9289. // markTriggeredFromLocal(event);
  9290. domHandlers[nativeEventName].call(instance, event);
  9291. }
  9292. });
  9293. });
  9294. }
  9295. }
  9296. /**
  9297. * @param {HandlerProxy} instance
  9298. * @param {DOMHandlerScope} scope
  9299. */
  9300. function mountGlobalDOMEventListeners(instance, scope) {
  9301. // Only IE11+/Edge. See the comment in `mountLocalDOMEventListeners`.
  9302. if (env$1.pointerEventsSupported) {
  9303. each$1(globalNativeListenerNames.pointer, mount);
  9304. } // Touch event has implemented "drag outside" so we do not mount global listener for touch event.
  9305. // (see https://www.w3.org/TR/touch-events/#the-touchmove-event)
  9306. // We do not consider "both-support-touch-and-mouse device" for this feature (see the comment of
  9307. // `mountLocalDOMEventListeners`) to avoid bugs util some requirements come.
  9308. else if (!env$1.touchEventsSupported) {
  9309. each$1(globalNativeListenerNames.mouse, mount);
  9310. }
  9311. function mount(nativeEventName) {
  9312. function nativeEventListener(event) {
  9313. event = getNativeEvent(event); // See the reason in [Drag outside] in `Handler.js`
  9314. // This checking supports both `useCapture` or not.
  9315. // PENDING: if there is performance issue in some devices,
  9316. // we probably can not use `useCapture` and change a easier
  9317. // to judes whether local (mark).
  9318. if (!isLocalEl(instance, event.target)) {
  9319. event = normalizeGlobalEvent(instance, event);
  9320. scope.domHandlers[nativeEventName].call(instance, event);
  9321. }
  9322. }
  9323. mountSingleDOMEventListener(scope, nativeEventName, nativeEventListener, {
  9324. capture: true // See [Drag Outside] in `Handler.js`
  9325. });
  9326. }
  9327. }
  9328. function mountSingleDOMEventListener(scope, nativeEventName, listener, opt) {
  9329. scope.mounted[nativeEventName] = listener;
  9330. scope.listenerOpts[nativeEventName] = opt;
  9331. addEventListener(scope.domTarget, eventNameFix(nativeEventName), listener, opt);
  9332. }
  9333. function unmountDOMEventListeners(scope) {
  9334. var mounted = scope.mounted;
  9335. for (var nativeEventName in mounted) {
  9336. if (mounted.hasOwnProperty(nativeEventName)) {
  9337. removeEventListener(scope.domTarget, eventNameFix(nativeEventName), mounted[nativeEventName], scope.listenerOpts[nativeEventName]);
  9338. }
  9339. }
  9340. scope.mounted = {};
  9341. }
  9342. /**
  9343. * See [Drag Outside] in `Handler.js`.
  9344. * @implement
  9345. * @param {boolean} isPointerCapturing Should never be `null`/`undefined`.
  9346. * `true`: start to capture pointer if it is not capturing.
  9347. * `false`: end the capture if it is capturing.
  9348. */
  9349. function togglePointerCapture(instance, isPointerCapturing) {
  9350. instance._mayPointerCapture = null;
  9351. if (globalEventSupported && instance._pointerCapturing ^ isPointerCapturing) {
  9352. instance._pointerCapturing = isPointerCapturing;
  9353. var globalHandlerScope = instance._globalHandlerScope;
  9354. isPointerCapturing ? mountGlobalDOMEventListeners(instance, globalHandlerScope) : unmountDOMEventListeners(globalHandlerScope);
  9355. }
  9356. }
  9357. /**
  9358. * @inner
  9359. * @class
  9360. */
  9361. function DOMHandlerScope(domTarget, domHandlers) {
  9362. this.domTarget = domTarget;
  9363. this.domHandlers = domHandlers; // Key: eventName, value: mounted handler funcitons.
  9364. // Used for unmount.
  9365. this.mounted = {};
  9366. this.listenerOpts = {};
  9367. this.touchTimer = null;
  9368. this.touching = false;
  9369. }
  9370. /**
  9371. * @public
  9372. * @class
  9373. */
  9374. function HandlerDomProxy(dom, painterRoot) {
  9375. Eventful.call(this);
  9376. this.dom = dom;
  9377. this.painterRoot = painterRoot;
  9378. this._localHandlerScope = new DOMHandlerScope(dom, localDOMHandlers);
  9379. if (globalEventSupported) {
  9380. this._globalHandlerScope = new DOMHandlerScope(document, globalDOMHandlers);
  9381. }
  9382. /**
  9383. * @type {boolean}
  9384. */
  9385. this._pointerCapturing = false;
  9386. /**
  9387. * @type {Array.<number>} [x, y] or null.
  9388. */
  9389. this._mayPointerCapture = null;
  9390. mountLocalDOMEventListeners(this, this._localHandlerScope);
  9391. }
  9392. var handlerDomProxyProto = HandlerDomProxy.prototype;
  9393. handlerDomProxyProto.dispose = function () {
  9394. unmountDOMEventListeners(this._localHandlerScope);
  9395. if (globalEventSupported) {
  9396. unmountDOMEventListeners(this._globalHandlerScope);
  9397. }
  9398. };
  9399. handlerDomProxyProto.setCursor = function (cursorStyle) {
  9400. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  9401. };
  9402. mixin(HandlerDomProxy, Eventful);
  9403. /*!
  9404. * ZRender, a high performance 2d drawing library.
  9405. *
  9406. * Copyright (c) 2013, Baidu Inc.
  9407. * All rights reserved.
  9408. *
  9409. * LICENSE
  9410. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  9411. */
  9412. var useVML = !env$1.canvasSupported;
  9413. var painterCtors = {
  9414. canvas: Painter
  9415. };
  9416. var instances$1 = {}; // ZRender实例map索引
  9417. /**
  9418. * @type {string}
  9419. */
  9420. var version$1 = '4.3.1';
  9421. /**
  9422. * Initializing a zrender instance
  9423. * @param {HTMLElement} dom
  9424. * @param {Object} [opts]
  9425. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9426. * @param {number} [opts.devicePixelRatio]
  9427. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9428. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9429. * @return {module:zrender/ZRender}
  9430. */
  9431. function init$1(dom, opts) {
  9432. var zr = new ZRender(guid(), dom, opts);
  9433. instances$1[zr.id] = zr;
  9434. return zr;
  9435. }
  9436. /**
  9437. * Dispose zrender instance
  9438. * @param {module:zrender/ZRender} zr
  9439. */
  9440. function dispose$1(zr) {
  9441. if (zr) {
  9442. zr.dispose();
  9443. } else {
  9444. for (var key in instances$1) {
  9445. if (instances$1.hasOwnProperty(key)) {
  9446. instances$1[key].dispose();
  9447. }
  9448. }
  9449. instances$1 = {};
  9450. }
  9451. return this;
  9452. }
  9453. /**
  9454. * Get zrender instance by id
  9455. * @param {string} id zrender instance id
  9456. * @return {module:zrender/ZRender}
  9457. */
  9458. function getInstance(id) {
  9459. return instances$1[id];
  9460. }
  9461. function registerPainter(name, Ctor) {
  9462. painterCtors[name] = Ctor;
  9463. }
  9464. function delInstance(id) {
  9465. delete instances$1[id];
  9466. }
  9467. /**
  9468. * @module zrender/ZRender
  9469. */
  9470. /**
  9471. * @constructor
  9472. * @alias module:zrender/ZRender
  9473. * @param {string} id
  9474. * @param {HTMLElement} dom
  9475. * @param {Object} opts
  9476. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9477. * @param {number} [opts.devicePixelRatio]
  9478. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  9479. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  9480. */
  9481. var ZRender = function (id, dom, opts) {
  9482. opts = opts || {};
  9483. /**
  9484. * @type {HTMLDomElement}
  9485. */
  9486. this.dom = dom;
  9487. /**
  9488. * @type {string}
  9489. */
  9490. this.id = id;
  9491. var self = this;
  9492. var storage = new Storage();
  9493. var rendererType = opts.renderer; // TODO WebGL
  9494. if (useVML) {
  9495. if (!painterCtors.vml) {
  9496. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  9497. }
  9498. rendererType = 'vml';
  9499. } else if (!rendererType || !painterCtors[rendererType]) {
  9500. rendererType = 'canvas';
  9501. }
  9502. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  9503. this.storage = storage;
  9504. this.painter = painter;
  9505. var handerProxy = !env$1.node && !env$1.worker ? new HandlerDomProxy(painter.getViewportRoot(), painter.root) : null;
  9506. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  9507. /**
  9508. * @type {module:zrender/animation/Animation}
  9509. */
  9510. this.animation = new Animation({
  9511. stage: {
  9512. update: bind(this.flush, this)
  9513. }
  9514. });
  9515. this.animation.start();
  9516. /**
  9517. * @type {boolean}
  9518. * @private
  9519. */
  9520. this._needsRefresh; // 修改 storage.delFromStorage, 每次删除元素之前删除动画
  9521. // FIXME 有点ugly
  9522. var oldDelFromStorage = storage.delFromStorage;
  9523. var oldAddToStorage = storage.addToStorage;
  9524. storage.delFromStorage = function (el) {
  9525. oldDelFromStorage.call(storage, el);
  9526. el && el.removeSelfFromZr(self);
  9527. };
  9528. storage.addToStorage = function (el) {
  9529. oldAddToStorage.call(storage, el);
  9530. el.addSelfToZr(self);
  9531. };
  9532. };
  9533. ZRender.prototype = {
  9534. constructor: ZRender,
  9535. /**
  9536. * 获取实例唯一标识
  9537. * @return {string}
  9538. */
  9539. getId: function () {
  9540. return this.id;
  9541. },
  9542. /**
  9543. * 添加元素
  9544. * @param {module:zrender/Element} el
  9545. */
  9546. add: function (el) {
  9547. this.storage.addRoot(el);
  9548. this._needsRefresh = true;
  9549. },
  9550. /**
  9551. * 删除元素
  9552. * @param {module:zrender/Element} el
  9553. */
  9554. remove: function (el) {
  9555. this.storage.delRoot(el);
  9556. this._needsRefresh = true;
  9557. },
  9558. /**
  9559. * Change configuration of layer
  9560. * @param {string} zLevel
  9561. * @param {Object} config
  9562. * @param {string} [config.clearColor=0] Clear color
  9563. * @param {string} [config.motionBlur=false] If enable motion blur
  9564. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  9565. */
  9566. configLayer: function (zLevel, config) {
  9567. if (this.painter.configLayer) {
  9568. this.painter.configLayer(zLevel, config);
  9569. }
  9570. this._needsRefresh = true;
  9571. },
  9572. /**
  9573. * Set background color
  9574. * @param {string} backgroundColor
  9575. */
  9576. setBackgroundColor: function (backgroundColor) {
  9577. if (this.painter.setBackgroundColor) {
  9578. this.painter.setBackgroundColor(backgroundColor);
  9579. }
  9580. this._needsRefresh = true;
  9581. },
  9582. /**
  9583. * Repaint the canvas immediately
  9584. */
  9585. refreshImmediately: function () {
  9586. // var start = new Date();
  9587. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  9588. // Or it will cause zrender refreshes again and again.
  9589. this._needsRefresh = this._needsRefreshHover = false;
  9590. this.painter.refresh(); // Avoid trigger zr.refresh in Element#beforeUpdate hook
  9591. this._needsRefresh = this._needsRefreshHover = false; // var end = new Date();
  9592. // var log = document.getElementById('log');
  9593. // if (log) {
  9594. // log.innerHTML = log.innerHTML + '<br>' + (end - start);
  9595. // }
  9596. },
  9597. /**
  9598. * Mark and repaint the canvas in the next frame of browser
  9599. */
  9600. refresh: function () {
  9601. this._needsRefresh = true;
  9602. },
  9603. /**
  9604. * Perform all refresh
  9605. */
  9606. flush: function () {
  9607. var triggerRendered;
  9608. if (this._needsRefresh) {
  9609. triggerRendered = true;
  9610. this.refreshImmediately();
  9611. }
  9612. if (this._needsRefreshHover) {
  9613. triggerRendered = true;
  9614. this.refreshHoverImmediately();
  9615. }
  9616. triggerRendered && this.trigger('rendered');
  9617. },
  9618. /**
  9619. * Add element to hover layer
  9620. * @param {module:zrender/Element} el
  9621. * @param {Object} style
  9622. */
  9623. addHover: function (el, style) {
  9624. if (this.painter.addHover) {
  9625. var elMirror = this.painter.addHover(el, style);
  9626. this.refreshHover();
  9627. return elMirror;
  9628. }
  9629. },
  9630. /**
  9631. * Add element from hover layer
  9632. * @param {module:zrender/Element} el
  9633. */
  9634. removeHover: function (el) {
  9635. if (this.painter.removeHover) {
  9636. this.painter.removeHover(el);
  9637. this.refreshHover();
  9638. }
  9639. },
  9640. /**
  9641. * Clear all hover elements in hover layer
  9642. * @param {module:zrender/Element} el
  9643. */
  9644. clearHover: function () {
  9645. if (this.painter.clearHover) {
  9646. this.painter.clearHover();
  9647. this.refreshHover();
  9648. }
  9649. },
  9650. /**
  9651. * Refresh hover in next frame
  9652. */
  9653. refreshHover: function () {
  9654. this._needsRefreshHover = true;
  9655. },
  9656. /**
  9657. * Refresh hover immediately
  9658. */
  9659. refreshHoverImmediately: function () {
  9660. this._needsRefreshHover = false;
  9661. this.painter.refreshHover && this.painter.refreshHover();
  9662. },
  9663. /**
  9664. * Resize the canvas.
  9665. * Should be invoked when container size is changed
  9666. * @param {Object} [opts]
  9667. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9668. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9669. */
  9670. resize: function (opts) {
  9671. opts = opts || {};
  9672. this.painter.resize(opts.width, opts.height);
  9673. this.handler.resize();
  9674. },
  9675. /**
  9676. * Stop and clear all animation immediately
  9677. */
  9678. clearAnimation: function () {
  9679. this.animation.clear();
  9680. },
  9681. /**
  9682. * Get container width
  9683. */
  9684. getWidth: function () {
  9685. return this.painter.getWidth();
  9686. },
  9687. /**
  9688. * Get container height
  9689. */
  9690. getHeight: function () {
  9691. return this.painter.getHeight();
  9692. },
  9693. /**
  9694. * Export the canvas as Base64 URL
  9695. * @param {string} type
  9696. * @param {string} [backgroundColor='#fff']
  9697. * @return {string} Base64 URL
  9698. */
  9699. // toDataURL: function(type, backgroundColor) {
  9700. // return this.painter.getRenderedCanvas({
  9701. // backgroundColor: backgroundColor
  9702. // }).toDataURL(type);
  9703. // },
  9704. /**
  9705. * Converting a path to image.
  9706. * It has much better performance of drawing image rather than drawing a vector path.
  9707. * @param {module:zrender/graphic/Path} e
  9708. * @param {number} width
  9709. * @param {number} height
  9710. */
  9711. pathToImage: function (e, dpr) {
  9712. return this.painter.pathToImage(e, dpr);
  9713. },
  9714. /**
  9715. * Set default cursor
  9716. * @param {string} [cursorStyle='default'] 例如 crosshair
  9717. */
  9718. setCursorStyle: function (cursorStyle) {
  9719. this.handler.setCursorStyle(cursorStyle);
  9720. },
  9721. /**
  9722. * Find hovered element
  9723. * @param {number} x
  9724. * @param {number} y
  9725. * @return {Object} {target, topTarget}
  9726. */
  9727. findHover: function (x, y) {
  9728. return this.handler.findHover(x, y);
  9729. },
  9730. /**
  9731. * Bind event
  9732. *
  9733. * @param {string} eventName Event name
  9734. * @param {Function} eventHandler Handler function
  9735. * @param {Object} [context] Context object
  9736. */
  9737. on: function (eventName, eventHandler, context) {
  9738. this.handler.on(eventName, eventHandler, context);
  9739. },
  9740. /**
  9741. * Unbind event
  9742. * @param {string} eventName Event name
  9743. * @param {Function} [eventHandler] Handler function
  9744. */
  9745. off: function (eventName, eventHandler) {
  9746. this.handler.off(eventName, eventHandler);
  9747. },
  9748. /**
  9749. * Trigger event manually
  9750. *
  9751. * @param {string} eventName Event name
  9752. * @param {event=} event Event object
  9753. */
  9754. trigger: function (eventName, event) {
  9755. this.handler.trigger(eventName, event);
  9756. },
  9757. /**
  9758. * Clear all objects and the canvas.
  9759. */
  9760. clear: function () {
  9761. this.storage.delRoot();
  9762. this.painter.clear();
  9763. },
  9764. /**
  9765. * Dispose self.
  9766. */
  9767. dispose: function () {
  9768. this.animation.stop();
  9769. this.clear();
  9770. this.storage.dispose();
  9771. this.painter.dispose();
  9772. this.handler.dispose();
  9773. this.animation = this.storage = this.painter = this.handler = null;
  9774. delInstance(this.id);
  9775. }
  9776. };
  9777. var zrender = (Object.freeze || Object)({
  9778. version: version$1,
  9779. init: init$1,
  9780. dispose: dispose$1,
  9781. getInstance: getInstance,
  9782. registerPainter: registerPainter
  9783. });
  9784. /*
  9785. * Licensed to the Apache Software Foundation (ASF) under one
  9786. * or more contributor license agreements. See the NOTICE file
  9787. * distributed with this work for additional information
  9788. * regarding copyright ownership. The ASF licenses this file
  9789. * to you under the Apache License, Version 2.0 (the
  9790. * "License"); you may not use this file except in compliance
  9791. * with the License. You may obtain a copy of the License at
  9792. *
  9793. * http://www.apache.org/licenses/LICENSE-2.0
  9794. *
  9795. * Unless required by applicable law or agreed to in writing,
  9796. * software distributed under the License is distributed on an
  9797. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  9798. * KIND, either express or implied. See the License for the
  9799. * specific language governing permissions and limitations
  9800. * under the License.
  9801. */
  9802. var each$2 = each$1;
  9803. var isObject$2 = isObject$1;
  9804. var isArray$1 = isArray;
  9805. /**
  9806. * Make the name displayable. But we should
  9807. * make sure it is not duplicated with user
  9808. * specified name, so use '\0';
  9809. */
  9810. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  9811. /**
  9812. * If value is not array, then translate it to array.
  9813. * @param {*} value
  9814. * @return {Array} [value] or value
  9815. */
  9816. function normalizeToArray(value) {
  9817. return value instanceof Array ? value : value == null ? [] : [value];
  9818. }
  9819. /**
  9820. * Sync default option between normal and emphasis like `position` and `show`
  9821. * In case some one will write code like
  9822. * label: {
  9823. * show: false,
  9824. * position: 'outside',
  9825. * fontSize: 18
  9826. * },
  9827. * emphasis: {
  9828. * label: { show: true }
  9829. * }
  9830. * @param {Object} opt
  9831. * @param {string} key
  9832. * @param {Array.<string>} subOpts
  9833. */
  9834. function defaultEmphasis(opt, key, subOpts) {
  9835. // Caution: performance sensitive.
  9836. if (opt) {
  9837. opt[key] = opt[key] || {};
  9838. opt.emphasis = opt.emphasis || {};
  9839. opt.emphasis[key] = opt.emphasis[key] || {}; // Default emphasis option from normal
  9840. for (var i = 0, len = subOpts.length; i < len; i++) {
  9841. var subOptName = subOpts[i];
  9842. if (!opt.emphasis[key].hasOwnProperty(subOptName) && opt[key].hasOwnProperty(subOptName)) {
  9843. opt.emphasis[key][subOptName] = opt[key][subOptName];
  9844. }
  9845. }
  9846. }
  9847. }
  9848. 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([
  9849. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  9850. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  9851. // // FIXME: deprecated, check and remove it.
  9852. // 'textStyle'
  9853. // ]);
  9854. /**
  9855. * The method do not ensure performance.
  9856. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  9857. * This helper method retieves value from data.
  9858. * @param {string|number|Date|Array|Object} dataItem
  9859. * @return {number|string|Date|Array.<number|string|Date>}
  9860. */
  9861. function getDataItemValue(dataItem) {
  9862. return isObject$2(dataItem) && !isArray$1(dataItem) && !(dataItem instanceof Date) ? dataItem.value : dataItem;
  9863. }
  9864. /**
  9865. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  9866. * This helper method determine if dataItem has extra option besides value
  9867. * @param {string|number|Date|Array|Object} dataItem
  9868. */
  9869. function isDataItemOption(dataItem) {
  9870. return isObject$2(dataItem) && !(dataItem instanceof Array); // // markLine data can be array
  9871. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  9872. }
  9873. /**
  9874. * Mapping to exists for merge.
  9875. *
  9876. * @public
  9877. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  9878. * @param {Object|Array.<Object>} newCptOptions
  9879. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  9880. * index of which is the same as exists.
  9881. */
  9882. function mappingToExists(exists, newCptOptions) {
  9883. // Mapping by the order by original option (but not order of
  9884. // new option) in merge mode. Because we should ensure
  9885. // some specified index (like xAxisIndex) is consistent with
  9886. // original option, which is easy to understand, espatially in
  9887. // media query. And in most case, merge option is used to
  9888. // update partial option but not be expected to change order.
  9889. newCptOptions = (newCptOptions || []).slice();
  9890. var result = map(exists || [], function (obj, index) {
  9891. return {
  9892. exist: obj
  9893. };
  9894. }); // Mapping by id or name if specified.
  9895. each$2(newCptOptions, function (cptOption, index) {
  9896. if (!isObject$2(cptOption)) {
  9897. return;
  9898. } // id has highest priority.
  9899. for (var i = 0; i < result.length; i++) {
  9900. if (!result[i].option // Consider name: two map to one.
  9901. && cptOption.id != null && result[i].exist.id === cptOption.id + '') {
  9902. result[i].option = cptOption;
  9903. newCptOptions[index] = null;
  9904. return;
  9905. }
  9906. }
  9907. for (var i = 0; i < result.length; i++) {
  9908. var exist = result[i].exist;
  9909. if (!result[i].option // Consider name: two map to one.
  9910. // Can not match when both ids exist but different.
  9911. && (exist.id == null || cptOption.id == null) && cptOption.name != null && !isIdInner(cptOption) && !isIdInner(exist) && exist.name === cptOption.name + '') {
  9912. result[i].option = cptOption;
  9913. newCptOptions[index] = null;
  9914. return;
  9915. }
  9916. }
  9917. }); // Otherwise mapping by index.
  9918. each$2(newCptOptions, function (cptOption, index) {
  9919. if (!isObject$2(cptOption)) {
  9920. return;
  9921. }
  9922. var i = 0;
  9923. for (; i < result.length; i++) {
  9924. var exist = result[i].exist;
  9925. if (!result[i].option // Existing model that already has id should be able to
  9926. // mapped to (because after mapping performed model may
  9927. // be assigned with a id, whish should not affect next
  9928. // mapping), except those has inner id.
  9929. && !isIdInner(exist) // Caution:
  9930. // Do not overwrite id. But name can be overwritten,
  9931. // because axis use name as 'show label text'.
  9932. // 'exist' always has id and name and we dont
  9933. // need to check it.
  9934. && cptOption.id == null) {
  9935. result[i].option = cptOption;
  9936. break;
  9937. }
  9938. }
  9939. if (i >= result.length) {
  9940. result.push({
  9941. option: cptOption
  9942. });
  9943. }
  9944. });
  9945. return result;
  9946. }
  9947. /**
  9948. * Make id and name for mapping result (result of mappingToExists)
  9949. * into `keyInfo` field.
  9950. *
  9951. * @public
  9952. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  9953. * which order is the same as exists.
  9954. * @return {Array.<Object>} The input.
  9955. */
  9956. function makeIdAndName(mapResult) {
  9957. // We use this id to hash component models and view instances
  9958. // in echarts. id can be specified by user, or auto generated.
  9959. // The id generation rule ensures new view instance are able
  9960. // to mapped to old instance when setOption are called in
  9961. // no-merge mode. So we generate model id by name and plus
  9962. // type in view id.
  9963. // name can be duplicated among components, which is convenient
  9964. // to specify multi components (like series) by one name.
  9965. // Ensure that each id is distinct.
  9966. var idMap = createHashMap();
  9967. each$2(mapResult, function (item, index) {
  9968. var existCpt = item.exist;
  9969. existCpt && idMap.set(existCpt.id, item);
  9970. });
  9971. each$2(mapResult, function (item, index) {
  9972. var opt = item.option;
  9973. assert$1(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
  9974. opt && opt.id != null && idMap.set(opt.id, item);
  9975. !item.keyInfo && (item.keyInfo = {});
  9976. }); // Make name and id.
  9977. each$2(mapResult, function (item, index) {
  9978. var existCpt = item.exist;
  9979. var opt = item.option;
  9980. var keyInfo = item.keyInfo;
  9981. if (!isObject$2(opt)) {
  9982. return;
  9983. } // name can be overwitten. Consider case: axis.name = '20km'.
  9984. // But id generated by name will not be changed, which affect
  9985. // only in that case: setOption with 'not merge mode' and view
  9986. // instance will be recreated, which can be accepted.
  9987. keyInfo.name = opt.name != null ? opt.name + '' : existCpt ? existCpt.name // Avoid diffferent series has the same name,
  9988. // because name may be used like in color pallet.
  9989. : DUMMY_COMPONENT_NAME_PREFIX + index;
  9990. if (existCpt) {
  9991. keyInfo.id = existCpt.id;
  9992. } else if (opt.id != null) {
  9993. keyInfo.id = opt.id + '';
  9994. } else {
  9995. // Consider this situatoin:
  9996. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  9997. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  9998. // Series with the same name between optionA and optionB
  9999. // should be mapped.
  10000. var idNum = 0;
  10001. do {
  10002. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  10003. } while (idMap.get(keyInfo.id));
  10004. }
  10005. idMap.set(keyInfo.id, item);
  10006. });
  10007. }
  10008. function isNameSpecified(componentModel) {
  10009. var name = componentModel.name; // Is specified when `indexOf` get -1 or > 0.
  10010. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  10011. }
  10012. /**
  10013. * @public
  10014. * @param {Object} cptOption
  10015. * @return {boolean}
  10016. */
  10017. function isIdInner(cptOption) {
  10018. return isObject$2(cptOption) && cptOption.id && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  10019. }
  10020. /**
  10021. * A helper for removing duplicate items between batchA and batchB,
  10022. * and in themselves, and categorize by series.
  10023. *
  10024. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10025. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10026. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  10027. */
  10028. /**
  10029. * @param {module:echarts/data/List} data
  10030. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  10031. * each of which can be Array or primary type.
  10032. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  10033. */
  10034. function queryDataIndex(data, payload) {
  10035. if (payload.dataIndexInside != null) {
  10036. return payload.dataIndexInside;
  10037. } else if (payload.dataIndex != null) {
  10038. return isArray(payload.dataIndex) ? map(payload.dataIndex, function (value) {
  10039. return data.indexOfRawIndex(value);
  10040. }) : data.indexOfRawIndex(payload.dataIndex);
  10041. } else if (payload.name != null) {
  10042. return isArray(payload.name) ? map(payload.name, function (value) {
  10043. return data.indexOfName(value);
  10044. }) : data.indexOfName(payload.name);
  10045. }
  10046. }
  10047. /**
  10048. * Enable property storage to any host object.
  10049. * Notice: Serialization is not supported.
  10050. *
  10051. * For example:
  10052. * var inner = zrUitl.makeInner();
  10053. *
  10054. * function some1(hostObj) {
  10055. * inner(hostObj).someProperty = 1212;
  10056. * ...
  10057. * }
  10058. * function some2() {
  10059. * var fields = inner(this);
  10060. * fields.someProperty1 = 1212;
  10061. * fields.someProperty2 = 'xx';
  10062. * ...
  10063. * }
  10064. *
  10065. * @return {Function}
  10066. */
  10067. function makeInner() {
  10068. // Consider different scope by es module import.
  10069. var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
  10070. return function (hostObj) {
  10071. return hostObj[key] || (hostObj[key] = {});
  10072. };
  10073. }
  10074. var innerUniqueIndex = 0;
  10075. /**
  10076. * @param {module:echarts/model/Global} ecModel
  10077. * @param {string|Object} finder
  10078. * If string, e.g., 'geo', means {geoIndex: 0}.
  10079. * If Object, could contain some of these properties below:
  10080. * {
  10081. * seriesIndex, seriesId, seriesName,
  10082. * geoIndex, geoId, geoName,
  10083. * bmapIndex, bmapId, bmapName,
  10084. * xAxisIndex, xAxisId, xAxisName,
  10085. * yAxisIndex, yAxisId, yAxisName,
  10086. * gridIndex, gridId, gridName,
  10087. * ... (can be extended)
  10088. * }
  10089. * Each properties can be number|string|Array.<number>|Array.<string>
  10090. * For example, a finder could be
  10091. * {
  10092. * seriesIndex: 3,
  10093. * geoId: ['aa', 'cc'],
  10094. * gridName: ['xx', 'rr']
  10095. * }
  10096. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  10097. * If nothing or null/undefined specified, return nothing.
  10098. * @param {Object} [opt]
  10099. * @param {string} [opt.defaultMainType]
  10100. * @param {Array.<string>} [opt.includeMainTypes]
  10101. * @return {Object} result like:
  10102. * {
  10103. * seriesModels: [seriesModel1, seriesModel2],
  10104. * seriesModel: seriesModel1, // The first model
  10105. * geoModels: [geoModel1, geoModel2],
  10106. * geoModel: geoModel1, // The first model
  10107. * ...
  10108. * }
  10109. */
  10110. function parseFinder(ecModel, finder, opt) {
  10111. if (isString(finder)) {
  10112. var obj = {};
  10113. obj[finder + 'Index'] = 0;
  10114. finder = obj;
  10115. }
  10116. var defaultMainType = opt && opt.defaultMainType;
  10117. if (defaultMainType && !has(finder, defaultMainType + 'Index') && !has(finder, defaultMainType + 'Id') && !has(finder, defaultMainType + 'Name')) {
  10118. finder[defaultMainType + 'Index'] = 0;
  10119. }
  10120. var result = {};
  10121. each$2(finder, function (value, key) {
  10122. var value = finder[key]; // Exclude 'dataIndex' and other illgal keys.
  10123. if (key === 'dataIndex' || key === 'dataIndexInside') {
  10124. result[key] = value;
  10125. return;
  10126. }
  10127. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  10128. var mainType = parsedKey[1];
  10129. var queryType = (parsedKey[2] || '').toLowerCase();
  10130. if (!mainType || !queryType || value == null || queryType === 'index' && value === 'none' || opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0) {
  10131. return;
  10132. }
  10133. var queryParam = {
  10134. mainType: mainType
  10135. };
  10136. if (queryType !== 'index' || value !== 'all') {
  10137. queryParam[queryType] = value;
  10138. }
  10139. var models = ecModel.queryComponents(queryParam);
  10140. result[mainType + 'Models'] = models;
  10141. result[mainType + 'Model'] = models[0];
  10142. });
  10143. return result;
  10144. }
  10145. function has(obj, prop) {
  10146. return obj && obj.hasOwnProperty(prop);
  10147. }
  10148. function setAttribute(dom, key, value) {
  10149. dom.setAttribute ? dom.setAttribute(key, value) : dom[key] = value;
  10150. }
  10151. function getAttribute(dom, key) {
  10152. return dom.getAttribute ? dom.getAttribute(key) : dom[key];
  10153. }
  10154. function getTooltipRenderMode(renderModeOption) {
  10155. if (renderModeOption === 'auto') {
  10156. // Using html when `document` exists, use richText otherwise
  10157. return env$1.domSupported ? 'html' : 'richText';
  10158. } else {
  10159. return renderModeOption || 'html';
  10160. }
  10161. }
  10162. /**
  10163. * Group a list by key.
  10164. *
  10165. * @param {Array} array
  10166. * @param {Function} getKey
  10167. * param {*} Array item
  10168. * return {string} key
  10169. * @return {Object} Result
  10170. * {Array}: keys,
  10171. * {module:zrender/core/util/HashMap} buckets: {key -> Array}
  10172. */
  10173. /*
  10174. * Licensed to the Apache Software Foundation (ASF) under one
  10175. * or more contributor license agreements. See the NOTICE file
  10176. * distributed with this work for additional information
  10177. * regarding copyright ownership. The ASF licenses this file
  10178. * to you under the Apache License, Version 2.0 (the
  10179. * "License"); you may not use this file except in compliance
  10180. * with the License. You may obtain a copy of the License at
  10181. *
  10182. * http://www.apache.org/licenses/LICENSE-2.0
  10183. *
  10184. * Unless required by applicable law or agreed to in writing,
  10185. * software distributed under the License is distributed on an
  10186. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10187. * KIND, either express or implied. See the License for the
  10188. * specific language governing permissions and limitations
  10189. * under the License.
  10190. */
  10191. var TYPE_DELIMITER = '.';
  10192. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  10193. /**
  10194. * Notice, parseClassType('') should returns {main: '', sub: ''}
  10195. * @public
  10196. */
  10197. function parseClassType$1(componentType) {
  10198. var ret = {
  10199. main: '',
  10200. sub: ''
  10201. };
  10202. if (componentType) {
  10203. componentType = componentType.split(TYPE_DELIMITER);
  10204. ret.main = componentType[0] || '';
  10205. ret.sub = componentType[1] || '';
  10206. }
  10207. return ret;
  10208. }
  10209. /**
  10210. * @public
  10211. */
  10212. function checkClassType(componentType) {
  10213. assert$1(/^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType), 'componentType "' + componentType + '" illegal');
  10214. }
  10215. /**
  10216. * @public
  10217. */
  10218. function enableClassExtend(RootClass, mandatoryMethods) {
  10219. RootClass.$constructor = RootClass;
  10220. RootClass.extend = function (proto) {
  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. Clz.isInstance = function (obj) {
  10248. return !!(obj && obj[classAttr]);
  10249. };
  10250. } // superCall should have class info, which can not be fetch from 'this'.
  10251. // Consider this case:
  10252. // class A has method f,
  10253. // class B inherits class A, overrides method f, f call superApply('f'),
  10254. // class C inherits class B, do not overrides method f,
  10255. // then when method of class C is called, dead loop occured.
  10256. function superCall(context, methodName) {
  10257. var args = slice(arguments, 2);
  10258. return this.superClass.prototype[methodName].apply(context, args);
  10259. }
  10260. function superApply(context, methodName, args) {
  10261. return this.superClass.prototype[methodName].apply(context, args);
  10262. }
  10263. /**
  10264. * @param {Object} entity
  10265. * @param {Object} options
  10266. * @param {boolean} [options.registerWhenExtend]
  10267. * @public
  10268. */
  10269. function enableClassManagement(entity, options) {
  10270. options = options || {};
  10271. /**
  10272. * Component model classes
  10273. * key: componentType,
  10274. * value:
  10275. * componentClass, when componentType is 'xxx'
  10276. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  10277. * @type {Object}
  10278. */
  10279. var storage = {};
  10280. entity.registerClass = function (Clazz, componentType) {
  10281. if (componentType) {
  10282. checkClassType(componentType);
  10283. componentType = parseClassType$1(componentType);
  10284. if (!componentType.sub) {
  10285. storage[componentType.main] = Clazz;
  10286. } else if (componentType.sub !== IS_CONTAINER) {
  10287. var container = makeContainer(componentType);
  10288. container[componentType.sub] = Clazz;
  10289. }
  10290. }
  10291. return Clazz;
  10292. };
  10293. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  10294. var Clazz = storage[componentMainType];
  10295. if (Clazz && Clazz[IS_CONTAINER]) {
  10296. Clazz = subType ? Clazz[subType] : null;
  10297. }
  10298. if (throwWhenNotFound && !Clazz) {
  10299. throw new Error(!subType ? componentMainType + '.' + 'type should be specified.' : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.');
  10300. }
  10301. return Clazz;
  10302. };
  10303. entity.getClassesByMainType = function (componentType) {
  10304. componentType = parseClassType$1(componentType);
  10305. var result = [];
  10306. var obj = storage[componentType.main];
  10307. if (obj && obj[IS_CONTAINER]) {
  10308. each$1(obj, function (o, type) {
  10309. type !== IS_CONTAINER && result.push(o);
  10310. });
  10311. } else {
  10312. result.push(obj);
  10313. }
  10314. return result;
  10315. };
  10316. entity.hasClass = function (componentType) {
  10317. // Just consider componentType.main.
  10318. componentType = parseClassType$1(componentType);
  10319. return !!storage[componentType.main];
  10320. };
  10321. /**
  10322. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  10323. */
  10324. entity.getAllClassMainTypes = function () {
  10325. var types = [];
  10326. each$1(storage, function (obj, type) {
  10327. types.push(type);
  10328. });
  10329. return types;
  10330. };
  10331. /**
  10332. * If a main type is container and has sub types
  10333. * @param {string} mainType
  10334. * @return {boolean}
  10335. */
  10336. entity.hasSubTypes = function (componentType) {
  10337. componentType = parseClassType$1(componentType);
  10338. var obj = storage[componentType.main];
  10339. return obj && obj[IS_CONTAINER];
  10340. };
  10341. entity.parseClassType = parseClassType$1;
  10342. function makeContainer(componentType) {
  10343. var container = storage[componentType.main];
  10344. if (!container || !container[IS_CONTAINER]) {
  10345. container = storage[componentType.main] = {};
  10346. container[IS_CONTAINER] = true;
  10347. }
  10348. return container;
  10349. }
  10350. if (options.registerWhenExtend) {
  10351. var originalExtend = entity.extend;
  10352. if (originalExtend) {
  10353. entity.extend = function (proto) {
  10354. var ExtendedClass = originalExtend.call(this, proto);
  10355. return entity.registerClass(ExtendedClass, proto.type);
  10356. };
  10357. }
  10358. }
  10359. return entity;
  10360. }
  10361. /**
  10362. * @param {string|Array.<string>} properties
  10363. */
  10364. /*
  10365. * Licensed to the Apache Software Foundation (ASF) under one
  10366. * or more contributor license agreements. See the NOTICE file
  10367. * distributed with this work for additional information
  10368. * regarding copyright ownership. The ASF licenses this file
  10369. * to you under the Apache License, Version 2.0 (the
  10370. * "License"); you may not use this file except in compliance
  10371. * with the License. You may obtain a copy of the License at
  10372. *
  10373. * http://www.apache.org/licenses/LICENSE-2.0
  10374. *
  10375. * Unless required by applicable law or agreed to in writing,
  10376. * software distributed under the License is distributed on an
  10377. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10378. * KIND, either express or implied. See the License for the
  10379. * specific language governing permissions and limitations
  10380. * under the License.
  10381. */
  10382. // TODO Parse shadow style
  10383. // TODO Only shallow path support
  10384. var makeStyleMapper = function (properties) {
  10385. // Normalize
  10386. for (var i = 0; i < properties.length; i++) {
  10387. if (!properties[i][1]) {
  10388. properties[i][1] = properties[i][0];
  10389. }
  10390. }
  10391. return function (model, excludes, includes) {
  10392. var style = {};
  10393. for (var i = 0; i < properties.length; i++) {
  10394. var propName = properties[i][1];
  10395. if (excludes && indexOf(excludes, propName) >= 0 || includes && indexOf(includes, propName) < 0) {
  10396. continue;
  10397. }
  10398. var val = model.getShallow(propName);
  10399. if (val != null) {
  10400. style[properties[i][0]] = val;
  10401. }
  10402. }
  10403. return style;
  10404. };
  10405. };
  10406. /*
  10407. * Licensed to the Apache Software Foundation (ASF) under one
  10408. * or more contributor license agreements. See the NOTICE file
  10409. * distributed with this work for additional information
  10410. * regarding copyright ownership. The ASF licenses this file
  10411. * to you under the Apache License, Version 2.0 (the
  10412. * "License"); you may not use this file except in compliance
  10413. * with the License. You may obtain a copy of the License at
  10414. *
  10415. * http://www.apache.org/licenses/LICENSE-2.0
  10416. *
  10417. * Unless required by applicable law or agreed to in writing,
  10418. * software distributed under the License is distributed on an
  10419. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10420. * KIND, either express or implied. See the License for the
  10421. * specific language governing permissions and limitations
  10422. * under the License.
  10423. */
  10424. var getLineStyle = makeStyleMapper([['lineWidth', 'width'], ['stroke', 'color'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor']]);
  10425. var lineStyleMixin = {
  10426. getLineStyle: function (excludes) {
  10427. var style = getLineStyle(this, excludes); // Always set lineDash whether dashed, otherwise we can not
  10428. // erase the previous style when assigning to el.style.
  10429. style.lineDash = this.getLineDash(style.lineWidth);
  10430. return style;
  10431. },
  10432. getLineDash: function (lineWidth) {
  10433. if (lineWidth == null) {
  10434. lineWidth = 1;
  10435. }
  10436. var lineType = this.get('type');
  10437. var dotSize = Math.max(lineWidth, 2);
  10438. var dashSize = lineWidth * 4;
  10439. return lineType === 'solid' || lineType == null ? // Use `false` but not `null` for the solid line here, because `null` might be
  10440. // ignored when assigning to `el.style`. e.g., when setting `lineStyle.type` as
  10441. // `'dashed'` and `emphasis.lineStyle.type` as `'solid'` in graph series, the
  10442. // `lineDash` gotten form the latter one is not able to erase that from the former
  10443. // one if using `null` here according to the emhpsis strategy in `util/graphic.js`.
  10444. false : lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize];
  10445. }
  10446. };
  10447. /*
  10448. * Licensed to the Apache Software Foundation (ASF) under one
  10449. * or more contributor license agreements. See the NOTICE file
  10450. * distributed with this work for additional information
  10451. * regarding copyright ownership. The ASF licenses this file
  10452. * to you under the Apache License, Version 2.0 (the
  10453. * "License"); you may not use this file except in compliance
  10454. * with the License. You may obtain a copy of the License at
  10455. *
  10456. * http://www.apache.org/licenses/LICENSE-2.0
  10457. *
  10458. * Unless required by applicable law or agreed to in writing,
  10459. * software distributed under the License is distributed on an
  10460. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10461. * KIND, either express or implied. See the License for the
  10462. * specific language governing permissions and limitations
  10463. * under the License.
  10464. */
  10465. var getAreaStyle = makeStyleMapper([['fill', 'color'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['opacity'], ['shadowColor']]);
  10466. var areaStyleMixin = {
  10467. getAreaStyle: function (excludes, includes) {
  10468. return getAreaStyle(this, excludes, includes);
  10469. }
  10470. };
  10471. /**
  10472. * 曲线辅助模块
  10473. * @module zrender/core/curve
  10474. * @author pissang(https://www.github.com/pissang)
  10475. */
  10476. var mathPow = Math.pow;
  10477. var mathSqrt$2 = Math.sqrt;
  10478. var EPSILON$1 = 1e-8;
  10479. var EPSILON_NUMERIC = 1e-4;
  10480. var THREE_SQRT = mathSqrt$2(3);
  10481. var ONE_THIRD = 1 / 3; // 临时变量
  10482. var _v0 = create();
  10483. var _v1 = create();
  10484. var _v2 = create();
  10485. function isAroundZero(val) {
  10486. return val > -EPSILON$1 && val < EPSILON$1;
  10487. }
  10488. function isNotAroundZero$1(val) {
  10489. return val > EPSILON$1 || val < -EPSILON$1;
  10490. }
  10491. /**
  10492. * 计算三次贝塞尔值
  10493. * @memberOf module:zrender/core/curve
  10494. * @param {number} p0
  10495. * @param {number} p1
  10496. * @param {number} p2
  10497. * @param {number} p3
  10498. * @param {number} t
  10499. * @return {number}
  10500. */
  10501. function cubicAt(p0, p1, p2, p3, t) {
  10502. var onet = 1 - t;
  10503. return onet * onet * (onet * p0 + 3 * t * p1) + t * t * (t * p3 + 3 * onet * p2);
  10504. }
  10505. /**
  10506. * 计算三次贝塞尔导数值
  10507. * @memberOf module:zrender/core/curve
  10508. * @param {number} p0
  10509. * @param {number} p1
  10510. * @param {number} p2
  10511. * @param {number} p3
  10512. * @param {number} t
  10513. * @return {number}
  10514. */
  10515. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10516. var onet = 1 - t;
  10517. return 3 * (((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet + (p3 - p2) * t * t);
  10518. }
  10519. /**
  10520. * 计算三次贝塞尔方程根,使用盛金公式
  10521. * @memberOf module:zrender/core/curve
  10522. * @param {number} p0
  10523. * @param {number} p1
  10524. * @param {number} p2
  10525. * @param {number} p3
  10526. * @param {number} val
  10527. * @param {Array.<number>} roots
  10528. * @return {number} 有效根数目
  10529. */
  10530. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10531. // Evaluate roots of cubic functions
  10532. var a = p3 + 3 * (p1 - p2) - p0;
  10533. var b = 3 * (p2 - p1 * 2 + p0);
  10534. var c = 3 * (p1 - p0);
  10535. var d = p0 - val;
  10536. var A = b * b - 3 * a * c;
  10537. var B = b * c - 9 * a * d;
  10538. var C = c * c - 3 * b * d;
  10539. var n = 0;
  10540. if (isAroundZero(A) && isAroundZero(B)) {
  10541. if (isAroundZero(b)) {
  10542. roots[0] = 0;
  10543. } else {
  10544. var t1 = -c / b; //t1, t2, t3, b is not zero
  10545. if (t1 >= 0 && t1 <= 1) {
  10546. roots[n++] = t1;
  10547. }
  10548. }
  10549. } else {
  10550. var disc = B * B - 4 * A * C;
  10551. if (isAroundZero(disc)) {
  10552. var K = B / A;
  10553. var t1 = -b / a + K; // t1, a is not zero
  10554. var t2 = -K / 2; // t2, t3
  10555. if (t1 >= 0 && t1 <= 1) {
  10556. roots[n++] = t1;
  10557. }
  10558. if (t2 >= 0 && t2 <= 1) {
  10559. roots[n++] = t2;
  10560. }
  10561. } else if (disc > 0) {
  10562. var discSqrt = mathSqrt$2(disc);
  10563. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10564. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  10565. if (Y1 < 0) {
  10566. Y1 = -mathPow(-Y1, ONE_THIRD);
  10567. } else {
  10568. Y1 = mathPow(Y1, ONE_THIRD);
  10569. }
  10570. if (Y2 < 0) {
  10571. Y2 = -mathPow(-Y2, ONE_THIRD);
  10572. } else {
  10573. Y2 = mathPow(Y2, ONE_THIRD);
  10574. }
  10575. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  10576. if (t1 >= 0 && t1 <= 1) {
  10577. roots[n++] = t1;
  10578. }
  10579. } else {
  10580. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt$2(A * A * A));
  10581. var theta = Math.acos(T) / 3;
  10582. var ASqrt = mathSqrt$2(A);
  10583. var tmp = Math.cos(theta);
  10584. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  10585. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  10586. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  10587. if (t1 >= 0 && t1 <= 1) {
  10588. roots[n++] = t1;
  10589. }
  10590. if (t2 >= 0 && t2 <= 1) {
  10591. roots[n++] = t2;
  10592. }
  10593. if (t3 >= 0 && t3 <= 1) {
  10594. roots[n++] = t3;
  10595. }
  10596. }
  10597. }
  10598. return n;
  10599. }
  10600. /**
  10601. * 计算三次贝塞尔方程极限值的位置
  10602. * @memberOf module:zrender/core/curve
  10603. * @param {number} p0
  10604. * @param {number} p1
  10605. * @param {number} p2
  10606. * @param {number} p3
  10607. * @param {Array.<number>} extrema
  10608. * @return {number} 有效数目
  10609. */
  10610. function cubicExtrema(p0, p1, p2, p3, extrema) {
  10611. var b = 6 * p2 - 12 * p1 + 6 * p0;
  10612. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  10613. var c = 3 * p1 - 3 * p0;
  10614. var n = 0;
  10615. if (isAroundZero(a)) {
  10616. if (isNotAroundZero$1(b)) {
  10617. var t1 = -c / b;
  10618. if (t1 >= 0 && t1 <= 1) {
  10619. extrema[n++] = t1;
  10620. }
  10621. }
  10622. } else {
  10623. var disc = b * b - 4 * a * c;
  10624. if (isAroundZero(disc)) {
  10625. extrema[0] = -b / (2 * a);
  10626. } else if (disc > 0) {
  10627. var discSqrt = mathSqrt$2(disc);
  10628. var t1 = (-b + discSqrt) / (2 * a);
  10629. var t2 = (-b - discSqrt) / (2 * a);
  10630. if (t1 >= 0 && t1 <= 1) {
  10631. extrema[n++] = t1;
  10632. }
  10633. if (t2 >= 0 && t2 <= 1) {
  10634. extrema[n++] = t2;
  10635. }
  10636. }
  10637. }
  10638. return n;
  10639. }
  10640. /**
  10641. * 细分三次贝塞尔曲线
  10642. * @memberOf module:zrender/core/curve
  10643. * @param {number} p0
  10644. * @param {number} p1
  10645. * @param {number} p2
  10646. * @param {number} p3
  10647. * @param {number} t
  10648. * @param {Array.<number>} out
  10649. */
  10650. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  10651. var p01 = (p1 - p0) * t + p0;
  10652. var p12 = (p2 - p1) * t + p1;
  10653. var p23 = (p3 - p2) * t + p2;
  10654. var p012 = (p12 - p01) * t + p01;
  10655. var p123 = (p23 - p12) * t + p12;
  10656. var p0123 = (p123 - p012) * t + p012; // Seg0
  10657. out[0] = p0;
  10658. out[1] = p01;
  10659. out[2] = p012;
  10660. out[3] = p0123; // Seg1
  10661. out[4] = p0123;
  10662. out[5] = p123;
  10663. out[6] = p23;
  10664. out[7] = p3;
  10665. }
  10666. /**
  10667. * 投射点到三次贝塞尔曲线上,返回投射距离。
  10668. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10669. * @param {number} x0
  10670. * @param {number} y0
  10671. * @param {number} x1
  10672. * @param {number} y1
  10673. * @param {number} x2
  10674. * @param {number} y2
  10675. * @param {number} x3
  10676. * @param {number} y3
  10677. * @param {number} x
  10678. * @param {number} y
  10679. * @param {Array.<number>} [out] 投射点
  10680. * @return {number}
  10681. */
  10682. function cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, out) {
  10683. // http://pomax.github.io/bezierinfo/#projections
  10684. var t;
  10685. var interval = 0.005;
  10686. var d = Infinity;
  10687. var prev;
  10688. var next;
  10689. var d1;
  10690. var d2;
  10691. _v0[0] = x;
  10692. _v0[1] = y; // 先粗略估计一下可能的最小距离的 t 值
  10693. // PENDING
  10694. for (var _t = 0; _t < 1; _t += 0.05) {
  10695. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  10696. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  10697. d1 = distSquare(_v0, _v1);
  10698. if (d1 < d) {
  10699. t = _t;
  10700. d = d1;
  10701. }
  10702. }
  10703. d = Infinity; // At most 32 iteration
  10704. for (var i = 0; i < 32; i++) {
  10705. if (interval < EPSILON_NUMERIC) {
  10706. break;
  10707. }
  10708. prev = t - interval;
  10709. next = t + interval; // t - interval
  10710. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  10711. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  10712. d1 = distSquare(_v1, _v0);
  10713. if (prev >= 0 && d1 < d) {
  10714. t = prev;
  10715. d = d1;
  10716. } else {
  10717. // t + interval
  10718. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  10719. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  10720. d2 = distSquare(_v2, _v0);
  10721. if (next <= 1 && d2 < d) {
  10722. t = next;
  10723. d = d2;
  10724. } else {
  10725. interval *= 0.5;
  10726. }
  10727. }
  10728. } // t
  10729. if (out) {
  10730. out[0] = cubicAt(x0, x1, x2, x3, t);
  10731. out[1] = cubicAt(y0, y1, y2, y3, t);
  10732. } // console.log(interval, i);
  10733. return mathSqrt$2(d);
  10734. }
  10735. /**
  10736. * 计算二次方贝塞尔值
  10737. * @param {number} p0
  10738. * @param {number} p1
  10739. * @param {number} p2
  10740. * @param {number} t
  10741. * @return {number}
  10742. */
  10743. function quadraticAt(p0, p1, p2, t) {
  10744. var onet = 1 - t;
  10745. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  10746. }
  10747. /**
  10748. * 计算二次方贝塞尔导数值
  10749. * @param {number} p0
  10750. * @param {number} p1
  10751. * @param {number} p2
  10752. * @param {number} t
  10753. * @return {number}
  10754. */
  10755. function quadraticDerivativeAt(p0, p1, p2, t) {
  10756. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  10757. }
  10758. /**
  10759. * 计算二次方贝塞尔方程根
  10760. * @param {number} p0
  10761. * @param {number} p1
  10762. * @param {number} p2
  10763. * @param {number} t
  10764. * @param {Array.<number>} roots
  10765. * @return {number} 有效根数目
  10766. */
  10767. function quadraticRootAt(p0, p1, p2, val, roots) {
  10768. var a = p0 - 2 * p1 + p2;
  10769. var b = 2 * (p1 - p0);
  10770. var c = p0 - val;
  10771. var n = 0;
  10772. if (isAroundZero(a)) {
  10773. if (isNotAroundZero$1(b)) {
  10774. var t1 = -c / b;
  10775. if (t1 >= 0 && t1 <= 1) {
  10776. roots[n++] = t1;
  10777. }
  10778. }
  10779. } else {
  10780. var disc = b * b - 4 * a * c;
  10781. if (isAroundZero(disc)) {
  10782. var t1 = -b / (2 * a);
  10783. if (t1 >= 0 && t1 <= 1) {
  10784. roots[n++] = t1;
  10785. }
  10786. } else if (disc > 0) {
  10787. var discSqrt = mathSqrt$2(disc);
  10788. var t1 = (-b + discSqrt) / (2 * a);
  10789. var t2 = (-b - discSqrt) / (2 * a);
  10790. if (t1 >= 0 && t1 <= 1) {
  10791. roots[n++] = t1;
  10792. }
  10793. if (t2 >= 0 && t2 <= 1) {
  10794. roots[n++] = t2;
  10795. }
  10796. }
  10797. }
  10798. return n;
  10799. }
  10800. /**
  10801. * 计算二次贝塞尔方程极限值
  10802. * @memberOf module:zrender/core/curve
  10803. * @param {number} p0
  10804. * @param {number} p1
  10805. * @param {number} p2
  10806. * @return {number}
  10807. */
  10808. function quadraticExtremum(p0, p1, p2) {
  10809. var divider = p0 + p2 - 2 * p1;
  10810. if (divider === 0) {
  10811. // p1 is center of p0 and p2
  10812. return 0.5;
  10813. } else {
  10814. return (p0 - p1) / divider;
  10815. }
  10816. }
  10817. /**
  10818. * 细分二次贝塞尔曲线
  10819. * @memberOf module:zrender/core/curve
  10820. * @param {number} p0
  10821. * @param {number} p1
  10822. * @param {number} p2
  10823. * @param {number} t
  10824. * @param {Array.<number>} out
  10825. */
  10826. function quadraticSubdivide(p0, p1, p2, t, out) {
  10827. var p01 = (p1 - p0) * t + p0;
  10828. var p12 = (p2 - p1) * t + p1;
  10829. var p012 = (p12 - p01) * t + p01; // Seg0
  10830. out[0] = p0;
  10831. out[1] = p01;
  10832. out[2] = p012; // Seg1
  10833. out[3] = p012;
  10834. out[4] = p12;
  10835. out[5] = p2;
  10836. }
  10837. /**
  10838. * 投射点到二次贝塞尔曲线上,返回投射距离。
  10839. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  10840. * @param {number} x0
  10841. * @param {number} y0
  10842. * @param {number} x1
  10843. * @param {number} y1
  10844. * @param {number} x2
  10845. * @param {number} y2
  10846. * @param {number} x
  10847. * @param {number} y
  10848. * @param {Array.<number>} out 投射点
  10849. * @return {number}
  10850. */
  10851. function quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, out) {
  10852. // http://pomax.github.io/bezierinfo/#projections
  10853. var t;
  10854. var interval = 0.005;
  10855. var d = Infinity;
  10856. _v0[0] = x;
  10857. _v0[1] = y; // 先粗略估计一下可能的最小距离的 t 值
  10858. // PENDING
  10859. for (var _t = 0; _t < 1; _t += 0.05) {
  10860. _v1[0] = quadraticAt(x0, x1, x2, _t);
  10861. _v1[1] = quadraticAt(y0, y1, y2, _t);
  10862. var d1 = distSquare(_v0, _v1);
  10863. if (d1 < d) {
  10864. t = _t;
  10865. d = d1;
  10866. }
  10867. }
  10868. d = Infinity; // At most 32 iteration
  10869. for (var i = 0; i < 32; i++) {
  10870. if (interval < EPSILON_NUMERIC) {
  10871. break;
  10872. }
  10873. var prev = t - interval;
  10874. var next = t + interval; // t - interval
  10875. _v1[0] = quadraticAt(x0, x1, x2, prev);
  10876. _v1[1] = quadraticAt(y0, y1, y2, prev);
  10877. var d1 = distSquare(_v1, _v0);
  10878. if (prev >= 0 && d1 < d) {
  10879. t = prev;
  10880. d = d1;
  10881. } else {
  10882. // t + interval
  10883. _v2[0] = quadraticAt(x0, x1, x2, next);
  10884. _v2[1] = quadraticAt(y0, y1, y2, next);
  10885. var d2 = distSquare(_v2, _v0);
  10886. if (next <= 1 && d2 < d) {
  10887. t = next;
  10888. d = d2;
  10889. } else {
  10890. interval *= 0.5;
  10891. }
  10892. }
  10893. } // t
  10894. if (out) {
  10895. out[0] = quadraticAt(x0, x1, x2, t);
  10896. out[1] = quadraticAt(y0, y1, y2, t);
  10897. } // console.log(interval, i);
  10898. return mathSqrt$2(d);
  10899. }
  10900. /**
  10901. * @author Yi Shen(https://github.com/pissang)
  10902. */
  10903. var mathMin$3 = Math.min;
  10904. var mathMax$3 = Math.max;
  10905. var mathSin$2 = Math.sin;
  10906. var mathCos$2 = Math.cos;
  10907. var PI2 = Math.PI * 2;
  10908. var start = create();
  10909. var end = create();
  10910. var extremity = create();
  10911. /**
  10912. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  10913. * @module zrender/core/bbox
  10914. * @param {Array<Object>} points 顶点数组
  10915. * @param {number} min
  10916. * @param {number} max
  10917. */
  10918. function fromPoints(points, min$$1, max$$1) {
  10919. if (points.length === 0) {
  10920. return;
  10921. }
  10922. var p = points[0];
  10923. var left = p[0];
  10924. var right = p[0];
  10925. var top = p[1];
  10926. var bottom = p[1];
  10927. var i;
  10928. for (i = 1; i < points.length; i++) {
  10929. p = points[i];
  10930. left = mathMin$3(left, p[0]);
  10931. right = mathMax$3(right, p[0]);
  10932. top = mathMin$3(top, p[1]);
  10933. bottom = mathMax$3(bottom, p[1]);
  10934. }
  10935. min$$1[0] = left;
  10936. min$$1[1] = top;
  10937. max$$1[0] = right;
  10938. max$$1[1] = bottom;
  10939. }
  10940. /**
  10941. * @memberOf module:zrender/core/bbox
  10942. * @param {number} x0
  10943. * @param {number} y0
  10944. * @param {number} x1
  10945. * @param {number} y1
  10946. * @param {Array.<number>} min
  10947. * @param {Array.<number>} max
  10948. */
  10949. function fromLine(x0, y0, x1, y1, min$$1, max$$1) {
  10950. min$$1[0] = mathMin$3(x0, x1);
  10951. min$$1[1] = mathMin$3(y0, y1);
  10952. max$$1[0] = mathMax$3(x0, x1);
  10953. max$$1[1] = mathMax$3(y0, y1);
  10954. }
  10955. var xDim = [];
  10956. var yDim = [];
  10957. /**
  10958. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  10959. * @memberOf module:zrender/core/bbox
  10960. * @param {number} x0
  10961. * @param {number} y0
  10962. * @param {number} x1
  10963. * @param {number} y1
  10964. * @param {number} x2
  10965. * @param {number} y2
  10966. * @param {number} x3
  10967. * @param {number} y3
  10968. * @param {Array.<number>} min
  10969. * @param {Array.<number>} max
  10970. */
  10971. function fromCubic(x0, y0, x1, y1, x2, y2, x3, y3, min$$1, max$$1) {
  10972. var cubicExtrema$$1 = cubicExtrema;
  10973. var cubicAt$$1 = cubicAt;
  10974. var i;
  10975. var n = cubicExtrema$$1(x0, x1, x2, x3, xDim);
  10976. min$$1[0] = Infinity;
  10977. min$$1[1] = Infinity;
  10978. max$$1[0] = -Infinity;
  10979. max$$1[1] = -Infinity;
  10980. for (i = 0; i < n; i++) {
  10981. var x = cubicAt$$1(x0, x1, x2, x3, xDim[i]);
  10982. min$$1[0] = mathMin$3(x, min$$1[0]);
  10983. max$$1[0] = mathMax$3(x, max$$1[0]);
  10984. }
  10985. n = cubicExtrema$$1(y0, y1, y2, y3, yDim);
  10986. for (i = 0; i < n; i++) {
  10987. var y = cubicAt$$1(y0, y1, y2, y3, yDim[i]);
  10988. min$$1[1] = mathMin$3(y, min$$1[1]);
  10989. max$$1[1] = mathMax$3(y, max$$1[1]);
  10990. }
  10991. min$$1[0] = mathMin$3(x0, min$$1[0]);
  10992. max$$1[0] = mathMax$3(x0, max$$1[0]);
  10993. min$$1[0] = mathMin$3(x3, min$$1[0]);
  10994. max$$1[0] = mathMax$3(x3, max$$1[0]);
  10995. min$$1[1] = mathMin$3(y0, min$$1[1]);
  10996. max$$1[1] = mathMax$3(y0, max$$1[1]);
  10997. min$$1[1] = mathMin$3(y3, min$$1[1]);
  10998. max$$1[1] = mathMax$3(y3, max$$1[1]);
  10999. }
  11000. /**
  11001. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  11002. * @memberOf module:zrender/core/bbox
  11003. * @param {number} x0
  11004. * @param {number} y0
  11005. * @param {number} x1
  11006. * @param {number} y1
  11007. * @param {number} x2
  11008. * @param {number} y2
  11009. * @param {Array.<number>} min
  11010. * @param {Array.<number>} max
  11011. */
  11012. function fromQuadratic(x0, y0, x1, y1, x2, y2, min$$1, max$$1) {
  11013. var quadraticExtremum$$1 = quadraticExtremum;
  11014. var quadraticAt$$1 = quadraticAt; // Find extremities, where derivative in x dim or y dim is zero
  11015. var tx = mathMax$3(mathMin$3(quadraticExtremum$$1(x0, x1, x2), 1), 0);
  11016. var ty = mathMax$3(mathMin$3(quadraticExtremum$$1(y0, y1, y2), 1), 0);
  11017. var x = quadraticAt$$1(x0, x1, x2, tx);
  11018. var y = quadraticAt$$1(y0, y1, y2, ty);
  11019. min$$1[0] = mathMin$3(x0, x2, x);
  11020. min$$1[1] = mathMin$3(y0, y2, y);
  11021. max$$1[0] = mathMax$3(x0, x2, x);
  11022. max$$1[1] = mathMax$3(y0, y2, y);
  11023. }
  11024. /**
  11025. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  11026. * @method
  11027. * @memberOf module:zrender/core/bbox
  11028. * @param {number} x
  11029. * @param {number} y
  11030. * @param {number} rx
  11031. * @param {number} ry
  11032. * @param {number} startAngle
  11033. * @param {number} endAngle
  11034. * @param {number} anticlockwise
  11035. * @param {Array.<number>} min
  11036. * @param {Array.<number>} max
  11037. */
  11038. function fromArc(x, y, rx, ry, startAngle, endAngle, anticlockwise, min$$1, max$$1) {
  11039. var vec2Min = min;
  11040. var vec2Max = max;
  11041. var diff = Math.abs(startAngle - endAngle);
  11042. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  11043. // Is a circle
  11044. min$$1[0] = x - rx;
  11045. min$$1[1] = y - ry;
  11046. max$$1[0] = x + rx;
  11047. max$$1[1] = y + ry;
  11048. return;
  11049. }
  11050. start[0] = mathCos$2(startAngle) * rx + x;
  11051. start[1] = mathSin$2(startAngle) * ry + y;
  11052. end[0] = mathCos$2(endAngle) * rx + x;
  11053. end[1] = mathSin$2(endAngle) * ry + y;
  11054. vec2Min(min$$1, start, end);
  11055. vec2Max(max$$1, start, end); // Thresh to [0, Math.PI * 2]
  11056. startAngle = startAngle % PI2;
  11057. if (startAngle < 0) {
  11058. startAngle = startAngle + PI2;
  11059. }
  11060. endAngle = endAngle % PI2;
  11061. if (endAngle < 0) {
  11062. endAngle = endAngle + PI2;
  11063. }
  11064. if (startAngle > endAngle && !anticlockwise) {
  11065. endAngle += PI2;
  11066. } else if (startAngle < endAngle && anticlockwise) {
  11067. startAngle += PI2;
  11068. }
  11069. if (anticlockwise) {
  11070. var tmp = endAngle;
  11071. endAngle = startAngle;
  11072. startAngle = tmp;
  11073. } // var number = 0;
  11074. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  11075. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  11076. if (angle > startAngle) {
  11077. extremity[0] = mathCos$2(angle) * rx + x;
  11078. extremity[1] = mathSin$2(angle) * ry + y;
  11079. vec2Min(min$$1, extremity, min$$1);
  11080. vec2Max(max$$1, extremity, max$$1);
  11081. }
  11082. }
  11083. }
  11084. /**
  11085. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  11086. * 可以用于 isInsidePath 判断以及获取boundingRect
  11087. *
  11088. * @module zrender/core/PathProxy
  11089. * @author Yi Shen (http://www.github.com/pissang)
  11090. */
  11091. // TODO getTotalLength, getPointAtLength
  11092. /* global Float32Array */
  11093. var CMD = {
  11094. M: 1,
  11095. L: 2,
  11096. C: 3,
  11097. Q: 4,
  11098. A: 5,
  11099. Z: 6,
  11100. // Rect
  11101. R: 7
  11102. }; // var CMD_MEM_SIZE = {
  11103. // M: 3,
  11104. // L: 3,
  11105. // C: 7,
  11106. // Q: 5,
  11107. // A: 9,
  11108. // R: 5,
  11109. // Z: 1
  11110. // };
  11111. var min$1 = [];
  11112. var max$1 = [];
  11113. var min2 = [];
  11114. var max2 = [];
  11115. var mathMin$2 = Math.min;
  11116. var mathMax$2 = Math.max;
  11117. var mathCos$1 = Math.cos;
  11118. var mathSin$1 = Math.sin;
  11119. var mathSqrt$1 = Math.sqrt;
  11120. var mathAbs = Math.abs;
  11121. var hasTypedArray = typeof Float32Array !== 'undefined';
  11122. /**
  11123. * @alias module:zrender/core/PathProxy
  11124. * @constructor
  11125. */
  11126. var PathProxy = function (notSaveData) {
  11127. this._saveData = !(notSaveData || false);
  11128. if (this._saveData) {
  11129. /**
  11130. * Path data. Stored as flat array
  11131. * @type {Array.<Object>}
  11132. */
  11133. this.data = [];
  11134. }
  11135. this._ctx = null;
  11136. };
  11137. /**
  11138. * 快速计算Path包围盒(并不是最小包围盒)
  11139. * @return {Object}
  11140. */
  11141. PathProxy.prototype = {
  11142. constructor: PathProxy,
  11143. _xi: 0,
  11144. _yi: 0,
  11145. _x0: 0,
  11146. _y0: 0,
  11147. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  11148. _ux: 0,
  11149. _uy: 0,
  11150. _len: 0,
  11151. _lineDash: null,
  11152. _dashOffset: 0,
  11153. _dashIdx: 0,
  11154. _dashSum: 0,
  11155. /**
  11156. * @readOnly
  11157. */
  11158. setScale: function (sx, sy, segmentIgnoreThreshold) {
  11159. // Compat. Previously there is no segmentIgnoreThreshold.
  11160. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  11161. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  11162. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  11163. },
  11164. getContext: function () {
  11165. return this._ctx;
  11166. },
  11167. /**
  11168. * @param {CanvasRenderingContext2D} ctx
  11169. * @return {module:zrender/core/PathProxy}
  11170. */
  11171. beginPath: function (ctx) {
  11172. this._ctx = ctx;
  11173. ctx && ctx.beginPath();
  11174. ctx && (this.dpr = ctx.dpr); // Reset
  11175. if (this._saveData) {
  11176. this._len = 0;
  11177. }
  11178. if (this._lineDash) {
  11179. this._lineDash = null;
  11180. this._dashOffset = 0;
  11181. }
  11182. return this;
  11183. },
  11184. /**
  11185. * @param {number} x
  11186. * @param {number} y
  11187. * @return {module:zrender/core/PathProxy}
  11188. */
  11189. moveTo: function (x, y) {
  11190. this.addData(CMD.M, x, y);
  11191. this._ctx && this._ctx.moveTo(x, y); // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11192. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11193. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11194. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11195. this._x0 = x;
  11196. this._y0 = y;
  11197. this._xi = x;
  11198. this._yi = y;
  11199. return this;
  11200. },
  11201. /**
  11202. * @param {number} x
  11203. * @param {number} y
  11204. * @return {module:zrender/core/PathProxy}
  11205. */
  11206. lineTo: function (x, y) {
  11207. var exceedUnit = mathAbs(x - this._xi) > this._ux || mathAbs(y - this._yi) > this._uy // Force draw the first segment
  11208. || this._len < 5;
  11209. this.addData(CMD.L, x, y);
  11210. if (this._ctx && exceedUnit) {
  11211. this._needsDash() ? this._dashedLineTo(x, y) : this._ctx.lineTo(x, y);
  11212. }
  11213. if (exceedUnit) {
  11214. this._xi = x;
  11215. this._yi = y;
  11216. }
  11217. return this;
  11218. },
  11219. /**
  11220. * @param {number} x1
  11221. * @param {number} y1
  11222. * @param {number} x2
  11223. * @param {number} y2
  11224. * @param {number} x3
  11225. * @param {number} y3
  11226. * @return {module:zrender/core/PathProxy}
  11227. */
  11228. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11229. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11230. if (this._ctx) {
  11231. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3) : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11232. }
  11233. this._xi = x3;
  11234. this._yi = y3;
  11235. return this;
  11236. },
  11237. /**
  11238. * @param {number} x1
  11239. * @param {number} y1
  11240. * @param {number} x2
  11241. * @param {number} y2
  11242. * @return {module:zrender/core/PathProxy}
  11243. */
  11244. quadraticCurveTo: function (x1, y1, x2, y2) {
  11245. this.addData(CMD.Q, x1, y1, x2, y2);
  11246. if (this._ctx) {
  11247. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2) : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11248. }
  11249. this._xi = x2;
  11250. this._yi = y2;
  11251. return this;
  11252. },
  11253. /**
  11254. * @param {number} cx
  11255. * @param {number} cy
  11256. * @param {number} r
  11257. * @param {number} startAngle
  11258. * @param {number} endAngle
  11259. * @param {boolean} anticlockwise
  11260. * @return {module:zrender/core/PathProxy}
  11261. */
  11262. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11263. this.addData(CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1);
  11264. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11265. this._xi = mathCos$1(endAngle) * r + cx;
  11266. this._yi = mathSin$1(endAngle) * r + cy;
  11267. return this;
  11268. },
  11269. // TODO
  11270. arcTo: function (x1, y1, x2, y2, radius) {
  11271. if (this._ctx) {
  11272. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11273. }
  11274. return this;
  11275. },
  11276. // TODO
  11277. rect: function (x, y, w, h) {
  11278. this._ctx && this._ctx.rect(x, y, w, h);
  11279. this.addData(CMD.R, x, y, w, h);
  11280. return this;
  11281. },
  11282. /**
  11283. * @return {module:zrender/core/PathProxy}
  11284. */
  11285. closePath: function () {
  11286. this.addData(CMD.Z);
  11287. var ctx = this._ctx;
  11288. var x0 = this._x0;
  11289. var y0 = this._y0;
  11290. if (ctx) {
  11291. this._needsDash() && this._dashedLineTo(x0, y0);
  11292. ctx.closePath();
  11293. }
  11294. this._xi = x0;
  11295. this._yi = y0;
  11296. return this;
  11297. },
  11298. /**
  11299. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11300. * stroke 同样
  11301. * @param {CanvasRenderingContext2D} ctx
  11302. * @return {module:zrender/core/PathProxy}
  11303. */
  11304. fill: function (ctx) {
  11305. ctx && ctx.fill();
  11306. this.toStatic();
  11307. },
  11308. /**
  11309. * @param {CanvasRenderingContext2D} ctx
  11310. * @return {module:zrender/core/PathProxy}
  11311. */
  11312. stroke: function (ctx) {
  11313. ctx && ctx.stroke();
  11314. this.toStatic();
  11315. },
  11316. /**
  11317. * 必须在其它绘制命令前调用
  11318. * Must be invoked before all other path drawing methods
  11319. * @return {module:zrender/core/PathProxy}
  11320. */
  11321. setLineDash: function (lineDash) {
  11322. if (lineDash instanceof Array) {
  11323. this._lineDash = lineDash;
  11324. this._dashIdx = 0;
  11325. var lineDashSum = 0;
  11326. for (var i = 0; i < lineDash.length; i++) {
  11327. lineDashSum += lineDash[i];
  11328. }
  11329. this._dashSum = lineDashSum;
  11330. }
  11331. return this;
  11332. },
  11333. /**
  11334. * 必须在其它绘制命令前调用
  11335. * Must be invoked before all other path drawing methods
  11336. * @return {module:zrender/core/PathProxy}
  11337. */
  11338. setLineDashOffset: function (offset) {
  11339. this._dashOffset = offset;
  11340. return this;
  11341. },
  11342. /**
  11343. *
  11344. * @return {boolean}
  11345. */
  11346. len: function () {
  11347. return this._len;
  11348. },
  11349. /**
  11350. * 直接设置 Path 数据
  11351. */
  11352. setData: function (data) {
  11353. var len$$1 = data.length;
  11354. if (!(this.data && this.data.length === len$$1) && hasTypedArray) {
  11355. this.data = new Float32Array(len$$1);
  11356. }
  11357. for (var i = 0; i < len$$1; i++) {
  11358. this.data[i] = data[i];
  11359. }
  11360. this._len = len$$1;
  11361. },
  11362. /**
  11363. * 添加子路径
  11364. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11365. */
  11366. appendPath: function (path) {
  11367. if (!(path instanceof Array)) {
  11368. path = [path];
  11369. }
  11370. var len$$1 = path.length;
  11371. var appendSize = 0;
  11372. var offset = this._len;
  11373. for (var i = 0; i < len$$1; i++) {
  11374. appendSize += path[i].len();
  11375. }
  11376. if (hasTypedArray && this.data instanceof Float32Array) {
  11377. this.data = new Float32Array(offset + appendSize);
  11378. }
  11379. for (var i = 0; i < len$$1; i++) {
  11380. var appendPathData = path[i].data;
  11381. for (var k = 0; k < appendPathData.length; k++) {
  11382. this.data[offset++] = appendPathData[k];
  11383. }
  11384. }
  11385. this._len = offset;
  11386. },
  11387. /**
  11388. * 填充 Path 数据。
  11389. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11390. */
  11391. addData: function (cmd) {
  11392. if (!this._saveData) {
  11393. return;
  11394. }
  11395. var data = this.data;
  11396. if (this._len + arguments.length > data.length) {
  11397. // 因为之前的数组已经转换成静态的 Float32Array
  11398. // 所以不够用时需要扩展一个新的动态数组
  11399. this._expandData();
  11400. data = this.data;
  11401. }
  11402. for (var i = 0; i < arguments.length; i++) {
  11403. data[this._len++] = arguments[i];
  11404. }
  11405. this._prevCmd = cmd;
  11406. },
  11407. _expandData: function () {
  11408. // Only if data is Float32Array
  11409. if (!(this.data instanceof Array)) {
  11410. var newData = [];
  11411. for (var i = 0; i < this._len; i++) {
  11412. newData[i] = this.data[i];
  11413. }
  11414. this.data = newData;
  11415. }
  11416. },
  11417. /**
  11418. * If needs js implemented dashed line
  11419. * @return {boolean}
  11420. * @private
  11421. */
  11422. _needsDash: function () {
  11423. return this._lineDash;
  11424. },
  11425. _dashedLineTo: function (x1, y1) {
  11426. var dashSum = this._dashSum;
  11427. var offset = this._dashOffset;
  11428. var lineDash = this._lineDash;
  11429. var ctx = this._ctx;
  11430. var x0 = this._xi;
  11431. var y0 = this._yi;
  11432. var dx = x1 - x0;
  11433. var dy = y1 - y0;
  11434. var dist$$1 = mathSqrt$1(dx * dx + dy * dy);
  11435. var x = x0;
  11436. var y = y0;
  11437. var dash;
  11438. var nDash = lineDash.length;
  11439. var idx;
  11440. dx /= dist$$1;
  11441. dy /= dist$$1;
  11442. if (offset < 0) {
  11443. // Convert to positive offset
  11444. offset = dashSum + offset;
  11445. }
  11446. offset %= dashSum;
  11447. x -= offset * dx;
  11448. y -= offset * dy;
  11449. while (dx > 0 && x <= x1 || dx < 0 && x >= x1 || dx === 0 && (dy > 0 && y <= y1 || dy < 0 && y >= y1)) {
  11450. idx = this._dashIdx;
  11451. dash = lineDash[idx];
  11452. x += dx * dash;
  11453. y += dy * dash;
  11454. this._dashIdx = (idx + 1) % nDash; // Skip positive offset
  11455. if (dx > 0 && x < x0 || dx < 0 && x > x0 || dy > 0 && y < y0 || dy < 0 && y > y0) {
  11456. continue;
  11457. }
  11458. 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));
  11459. } // Offset for next lineTo
  11460. dx = x - x1;
  11461. dy = y - y1;
  11462. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11463. },
  11464. // Not accurate dashed line to
  11465. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11466. var dashSum = this._dashSum;
  11467. var offset = this._dashOffset;
  11468. var lineDash = this._lineDash;
  11469. var ctx = this._ctx;
  11470. var x0 = this._xi;
  11471. var y0 = this._yi;
  11472. var t;
  11473. var dx;
  11474. var dy;
  11475. var cubicAt$$1 = cubicAt;
  11476. var bezierLen = 0;
  11477. var idx = this._dashIdx;
  11478. var nDash = lineDash.length;
  11479. var x;
  11480. var y;
  11481. var tmpLen = 0;
  11482. if (offset < 0) {
  11483. // Convert to positive offset
  11484. offset = dashSum + offset;
  11485. }
  11486. offset %= dashSum; // Bezier approx length
  11487. for (t = 0; t < 1; t += 0.1) {
  11488. dx = cubicAt$$1(x0, x1, x2, x3, t + 0.1) - cubicAt$$1(x0, x1, x2, x3, t);
  11489. dy = cubicAt$$1(y0, y1, y2, y3, t + 0.1) - cubicAt$$1(y0, y1, y2, y3, t);
  11490. bezierLen += mathSqrt$1(dx * dx + dy * dy);
  11491. } // Find idx after add offset
  11492. for (; idx < nDash; idx++) {
  11493. tmpLen += lineDash[idx];
  11494. if (tmpLen > offset) {
  11495. break;
  11496. }
  11497. }
  11498. t = (tmpLen - offset) / bezierLen;
  11499. while (t <= 1) {
  11500. x = cubicAt$$1(x0, x1, x2, x3, t);
  11501. y = cubicAt$$1(y0, y1, y2, y3, t); // Use line to approximate dashed bezier
  11502. // Bad result if dash is long
  11503. idx % 2 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
  11504. t += lineDash[idx] / bezierLen;
  11505. idx = (idx + 1) % nDash;
  11506. } // Finish the last segment and calculate the new offset
  11507. idx % 2 !== 0 && ctx.lineTo(x3, y3);
  11508. dx = x3 - x;
  11509. dy = y3 - y;
  11510. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11511. },
  11512. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  11513. // Convert quadratic to cubic using degree elevation
  11514. var x3 = x2;
  11515. var y3 = y2;
  11516. x2 = (x2 + 2 * x1) / 3;
  11517. y2 = (y2 + 2 * y1) / 3;
  11518. x1 = (this._xi + 2 * x1) / 3;
  11519. y1 = (this._yi + 2 * y1) / 3;
  11520. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  11521. },
  11522. /**
  11523. * 转成静态的 Float32Array 减少堆内存占用
  11524. * Convert dynamic array to static Float32Array
  11525. */
  11526. toStatic: function () {
  11527. var data = this.data;
  11528. if (data instanceof Array) {
  11529. data.length = this._len;
  11530. if (hasTypedArray) {
  11531. this.data = new Float32Array(data);
  11532. }
  11533. }
  11534. },
  11535. /**
  11536. * @return {module:zrender/core/BoundingRect}
  11537. */
  11538. getBoundingRect: function () {
  11539. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  11540. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  11541. var data = this.data;
  11542. var xi = 0;
  11543. var yi = 0;
  11544. var x0 = 0;
  11545. var y0 = 0;
  11546. for (var i = 0; i < data.length;) {
  11547. var cmd = data[i++];
  11548. if (i === 1) {
  11549. // 如果第一个命令是 L, C, Q
  11550. // 则 previous point 同绘制命令的第一个 point
  11551. //
  11552. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11553. xi = data[i];
  11554. yi = data[i + 1];
  11555. x0 = xi;
  11556. y0 = yi;
  11557. }
  11558. switch (cmd) {
  11559. case CMD.M:
  11560. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11561. // 在 closePath 的时候使用
  11562. x0 = data[i++];
  11563. y0 = data[i++];
  11564. xi = x0;
  11565. yi = y0;
  11566. min2[0] = x0;
  11567. min2[1] = y0;
  11568. max2[0] = x0;
  11569. max2[1] = y0;
  11570. break;
  11571. case CMD.L:
  11572. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  11573. xi = data[i++];
  11574. yi = data[i++];
  11575. break;
  11576. case CMD.C:
  11577. fromCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], min2, max2);
  11578. xi = data[i++];
  11579. yi = data[i++];
  11580. break;
  11581. case CMD.Q:
  11582. fromQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], min2, max2);
  11583. xi = data[i++];
  11584. yi = data[i++];
  11585. break;
  11586. case CMD.A:
  11587. // TODO Arc 判断的开销比较大
  11588. var cx = data[i++];
  11589. var cy = data[i++];
  11590. var rx = data[i++];
  11591. var ry = data[i++];
  11592. var startAngle = data[i++];
  11593. var endAngle = data[i++] + startAngle; // TODO Arc 旋转
  11594. i += 1;
  11595. var anticlockwise = 1 - data[i++];
  11596. if (i === 1) {
  11597. // 直接使用 arc 命令
  11598. // 第一个命令起点还未定义
  11599. x0 = mathCos$1(startAngle) * rx + cx;
  11600. y0 = mathSin$1(startAngle) * ry + cy;
  11601. }
  11602. fromArc(cx, cy, rx, ry, startAngle, endAngle, anticlockwise, min2, max2);
  11603. xi = mathCos$1(endAngle) * rx + cx;
  11604. yi = mathSin$1(endAngle) * ry + cy;
  11605. break;
  11606. case CMD.R:
  11607. x0 = xi = data[i++];
  11608. y0 = yi = data[i++];
  11609. var width = data[i++];
  11610. var height = data[i++]; // Use fromLine
  11611. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  11612. break;
  11613. case CMD.Z:
  11614. xi = x0;
  11615. yi = y0;
  11616. break;
  11617. } // Union
  11618. min(min$1, min$1, min2);
  11619. max(max$1, max$1, max2);
  11620. } // No data
  11621. if (i === 0) {
  11622. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  11623. }
  11624. return new BoundingRect(min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]);
  11625. },
  11626. /**
  11627. * Rebuild path from current data
  11628. * Rebuild path will not consider javascript implemented line dash.
  11629. * @param {CanvasRenderingContext2D} ctx
  11630. */
  11631. rebuildPath: function (ctx) {
  11632. var d = this.data;
  11633. var x0;
  11634. var y0;
  11635. var xi;
  11636. var yi;
  11637. var x;
  11638. var y;
  11639. var ux = this._ux;
  11640. var uy = this._uy;
  11641. var len$$1 = this._len;
  11642. for (var i = 0; i < len$$1;) {
  11643. var cmd = d[i++];
  11644. if (i === 1) {
  11645. // 如果第一个命令是 L, C, Q
  11646. // 则 previous point 同绘制命令的第一个 point
  11647. //
  11648. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11649. xi = d[i];
  11650. yi = d[i + 1];
  11651. x0 = xi;
  11652. y0 = yi;
  11653. }
  11654. switch (cmd) {
  11655. case CMD.M:
  11656. x0 = xi = d[i++];
  11657. y0 = yi = d[i++];
  11658. ctx.moveTo(xi, yi);
  11659. break;
  11660. case CMD.L:
  11661. x = d[i++];
  11662. y = d[i++]; // Not draw too small seg between
  11663. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len$$1 - 1) {
  11664. ctx.lineTo(x, y);
  11665. xi = x;
  11666. yi = y;
  11667. }
  11668. break;
  11669. case CMD.C:
  11670. ctx.bezierCurveTo(d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]);
  11671. xi = d[i - 2];
  11672. yi = d[i - 1];
  11673. break;
  11674. case CMD.Q:
  11675. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  11676. xi = d[i - 2];
  11677. yi = d[i - 1];
  11678. break;
  11679. case CMD.A:
  11680. var cx = d[i++];
  11681. var cy = d[i++];
  11682. var rx = d[i++];
  11683. var ry = d[i++];
  11684. var theta = d[i++];
  11685. var dTheta = d[i++];
  11686. var psi = d[i++];
  11687. var fs = d[i++];
  11688. var r = rx > ry ? rx : ry;
  11689. var scaleX = rx > ry ? 1 : rx / ry;
  11690. var scaleY = rx > ry ? ry / rx : 1;
  11691. var isEllipse = Math.abs(rx - ry) > 1e-3;
  11692. var endAngle = theta + dTheta;
  11693. if (isEllipse) {
  11694. ctx.translate(cx, cy);
  11695. ctx.rotate(psi);
  11696. ctx.scale(scaleX, scaleY);
  11697. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  11698. ctx.scale(1 / scaleX, 1 / scaleY);
  11699. ctx.rotate(-psi);
  11700. ctx.translate(-cx, -cy);
  11701. } else {
  11702. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  11703. }
  11704. if (i === 1) {
  11705. // 直接使用 arc 命令
  11706. // 第一个命令起点还未定义
  11707. x0 = mathCos$1(theta) * rx + cx;
  11708. y0 = mathSin$1(theta) * ry + cy;
  11709. }
  11710. xi = mathCos$1(endAngle) * rx + cx;
  11711. yi = mathSin$1(endAngle) * ry + cy;
  11712. break;
  11713. case CMD.R:
  11714. x0 = xi = d[i];
  11715. y0 = yi = d[i + 1];
  11716. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  11717. break;
  11718. case CMD.Z:
  11719. ctx.closePath();
  11720. xi = x0;
  11721. yi = y0;
  11722. }
  11723. }
  11724. }
  11725. };
  11726. PathProxy.CMD = CMD;
  11727. /**
  11728. * 线段包含判断
  11729. * @param {number} x0
  11730. * @param {number} y0
  11731. * @param {number} x1
  11732. * @param {number} y1
  11733. * @param {number} lineWidth
  11734. * @param {number} x
  11735. * @param {number} y
  11736. * @return {boolean}
  11737. */
  11738. function containStroke$1(x0, y0, x1, y1, lineWidth, x, y) {
  11739. if (lineWidth === 0) {
  11740. return false;
  11741. }
  11742. var _l = lineWidth;
  11743. var _a = 0;
  11744. var _b = x0; // Quick reject
  11745. 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) {
  11746. return false;
  11747. }
  11748. if (x0 !== x1) {
  11749. _a = (y0 - y1) / (x0 - x1);
  11750. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  11751. } else {
  11752. return Math.abs(x - x0) <= _l / 2;
  11753. }
  11754. var tmp = _a * x - y + _b;
  11755. var _s = tmp * tmp / (_a * _a + 1);
  11756. return _s <= _l / 2 * _l / 2;
  11757. }
  11758. /**
  11759. * 三次贝塞尔曲线描边包含判断
  11760. * @param {number} x0
  11761. * @param {number} y0
  11762. * @param {number} x1
  11763. * @param {number} y1
  11764. * @param {number} x2
  11765. * @param {number} y2
  11766. * @param {number} x3
  11767. * @param {number} y3
  11768. * @param {number} lineWidth
  11769. * @param {number} x
  11770. * @param {number} y
  11771. * @return {boolean}
  11772. */
  11773. function containStroke$2(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  11774. if (lineWidth === 0) {
  11775. return false;
  11776. }
  11777. var _l = lineWidth; // Quick reject
  11778. 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) {
  11779. return false;
  11780. }
  11781. var d = cubicProjectPoint(x0, y0, x1, y1, x2, y2, x3, y3, x, y, null);
  11782. return d <= _l / 2;
  11783. }
  11784. /**
  11785. * 二次贝塞尔曲线描边包含判断
  11786. * @param {number} x0
  11787. * @param {number} y0
  11788. * @param {number} x1
  11789. * @param {number} y1
  11790. * @param {number} x2
  11791. * @param {number} y2
  11792. * @param {number} lineWidth
  11793. * @param {number} x
  11794. * @param {number} y
  11795. * @return {boolean}
  11796. */
  11797. function containStroke$3(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  11798. if (lineWidth === 0) {
  11799. return false;
  11800. }
  11801. var _l = lineWidth; // Quick reject
  11802. 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) {
  11803. return false;
  11804. }
  11805. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  11806. return d <= _l / 2;
  11807. }
  11808. var PI2$3 = Math.PI * 2;
  11809. function normalizeRadian(angle) {
  11810. angle %= PI2$3;
  11811. if (angle < 0) {
  11812. angle += PI2$3;
  11813. }
  11814. return angle;
  11815. }
  11816. var PI2$2 = Math.PI * 2;
  11817. /**
  11818. * 圆弧描边包含判断
  11819. * @param {number} cx
  11820. * @param {number} cy
  11821. * @param {number} r
  11822. * @param {number} startAngle
  11823. * @param {number} endAngle
  11824. * @param {boolean} anticlockwise
  11825. * @param {number} lineWidth
  11826. * @param {number} x
  11827. * @param {number} y
  11828. * @return {Boolean}
  11829. */
  11830. function containStroke$4(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  11831. if (lineWidth === 0) {
  11832. return false;
  11833. }
  11834. var _l = lineWidth;
  11835. x -= cx;
  11836. y -= cy;
  11837. var d = Math.sqrt(x * x + y * y);
  11838. if (d - _l > r || d + _l < r) {
  11839. return false;
  11840. }
  11841. if (Math.abs(startAngle - endAngle) % PI2$2 < 1e-4) {
  11842. // Is a circle
  11843. return true;
  11844. }
  11845. if (anticlockwise) {
  11846. var tmp = startAngle;
  11847. startAngle = normalizeRadian(endAngle);
  11848. endAngle = normalizeRadian(tmp);
  11849. } else {
  11850. startAngle = normalizeRadian(startAngle);
  11851. endAngle = normalizeRadian(endAngle);
  11852. }
  11853. if (startAngle > endAngle) {
  11854. endAngle += PI2$2;
  11855. }
  11856. var angle = Math.atan2(y, x);
  11857. if (angle < 0) {
  11858. angle += PI2$2;
  11859. }
  11860. return angle >= startAngle && angle <= endAngle || angle + PI2$2 >= startAngle && angle + PI2$2 <= endAngle;
  11861. }
  11862. function windingLine(x0, y0, x1, y1, x, y) {
  11863. if (y > y0 && y > y1 || y < y0 && y < y1) {
  11864. return 0;
  11865. } // Ignore horizontal line
  11866. if (y1 === y0) {
  11867. return 0;
  11868. }
  11869. var dir = y1 < y0 ? 1 : -1;
  11870. var t = (y - y0) / (y1 - y0); // Avoid winding error when intersection point is the connect point of two line of polygon
  11871. if (t === 1 || t === 0) {
  11872. dir = y1 < y0 ? 0.5 : -0.5;
  11873. }
  11874. var x_ = t * (x1 - x0) + x0; // If (x, y) on the line, considered as "contain".
  11875. return x_ === x ? Infinity : x_ > x ? dir : 0;
  11876. }
  11877. var CMD$1 = PathProxy.CMD;
  11878. var PI2$1 = Math.PI * 2;
  11879. var EPSILON$2 = 1e-4;
  11880. function isAroundEqual(a, b) {
  11881. return Math.abs(a - b) < EPSILON$2;
  11882. } // 临时数组
  11883. var roots = [-1, -1, -1];
  11884. var extrema = [-1, -1];
  11885. function swapExtrema() {
  11886. var tmp = extrema[0];
  11887. extrema[0] = extrema[1];
  11888. extrema[1] = tmp;
  11889. }
  11890. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  11891. // Quick reject
  11892. if (y > y0 && y > y1 && y > y2 && y > y3 || y < y0 && y < y1 && y < y2 && y < y3) {
  11893. return 0;
  11894. }
  11895. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  11896. if (nRoots === 0) {
  11897. return 0;
  11898. } else {
  11899. var w = 0;
  11900. var nExtrema = -1;
  11901. var y0_;
  11902. var y1_;
  11903. for (var i = 0; i < nRoots; i++) {
  11904. var t = roots[i]; // Avoid winding error when intersection point is the connect point of two line of polygon
  11905. var unit = t === 0 || t === 1 ? 0.5 : 1;
  11906. var x_ = cubicAt(x0, x1, x2, x3, t);
  11907. if (x_ < x) {
  11908. // Quick reject
  11909. continue;
  11910. }
  11911. if (nExtrema < 0) {
  11912. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  11913. if (extrema[1] < extrema[0] && nExtrema > 1) {
  11914. swapExtrema();
  11915. }
  11916. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  11917. if (nExtrema > 1) {
  11918. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  11919. }
  11920. }
  11921. if (nExtrema === 2) {
  11922. // 分成三段单调函数
  11923. if (t < extrema[0]) {
  11924. w += y0_ < y0 ? unit : -unit;
  11925. } else if (t < extrema[1]) {
  11926. w += y1_ < y0_ ? unit : -unit;
  11927. } else {
  11928. w += y3 < y1_ ? unit : -unit;
  11929. }
  11930. } else {
  11931. // 分成两段单调函数
  11932. if (t < extrema[0]) {
  11933. w += y0_ < y0 ? unit : -unit;
  11934. } else {
  11935. w += y3 < y0_ ? unit : -unit;
  11936. }
  11937. }
  11938. }
  11939. return w;
  11940. }
  11941. }
  11942. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  11943. // Quick reject
  11944. if (y > y0 && y > y1 && y > y2 || y < y0 && y < y1 && y < y2) {
  11945. return 0;
  11946. }
  11947. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  11948. if (nRoots === 0) {
  11949. return 0;
  11950. } else {
  11951. var t = quadraticExtremum(y0, y1, y2);
  11952. if (t >= 0 && t <= 1) {
  11953. var w = 0;
  11954. var y_ = quadraticAt(y0, y1, y2, t);
  11955. for (var i = 0; i < nRoots; i++) {
  11956. // Remove one endpoint.
  11957. var unit = roots[i] === 0 || roots[i] === 1 ? 0.5 : 1;
  11958. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  11959. if (x_ < x) {
  11960. // Quick reject
  11961. continue;
  11962. }
  11963. if (roots[i] < t) {
  11964. w += y_ < y0 ? unit : -unit;
  11965. } else {
  11966. w += y2 < y_ ? unit : -unit;
  11967. }
  11968. }
  11969. return w;
  11970. } else {
  11971. // Remove one endpoint.
  11972. var unit = roots[0] === 0 || roots[0] === 1 ? 0.5 : 1;
  11973. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  11974. if (x_ < x) {
  11975. // Quick reject
  11976. return 0;
  11977. }
  11978. return y2 < y0 ? unit : -unit;
  11979. }
  11980. }
  11981. } // TODO
  11982. // Arc 旋转
  11983. function windingArc(cx, cy, r, startAngle, endAngle, anticlockwise, x, y) {
  11984. y -= cy;
  11985. if (y > r || y < -r) {
  11986. return 0;
  11987. }
  11988. var tmp = Math.sqrt(r * r - y * y);
  11989. roots[0] = -tmp;
  11990. roots[1] = tmp;
  11991. var diff = Math.abs(startAngle - endAngle);
  11992. if (diff < 1e-4) {
  11993. return 0;
  11994. }
  11995. if (diff % PI2$1 < 1e-4) {
  11996. // Is a circle
  11997. startAngle = 0;
  11998. endAngle = PI2$1;
  11999. var dir = anticlockwise ? 1 : -1;
  12000. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  12001. return dir;
  12002. } else {
  12003. return 0;
  12004. }
  12005. }
  12006. if (anticlockwise) {
  12007. var tmp = startAngle;
  12008. startAngle = normalizeRadian(endAngle);
  12009. endAngle = normalizeRadian(tmp);
  12010. } else {
  12011. startAngle = normalizeRadian(startAngle);
  12012. endAngle = normalizeRadian(endAngle);
  12013. }
  12014. if (startAngle > endAngle) {
  12015. endAngle += PI2$1;
  12016. }
  12017. var w = 0;
  12018. for (var i = 0; i < 2; i++) {
  12019. var x_ = roots[i];
  12020. if (x_ + cx > x) {
  12021. var angle = Math.atan2(y, x_);
  12022. var dir = anticlockwise ? 1 : -1;
  12023. if (angle < 0) {
  12024. angle = PI2$1 + angle;
  12025. }
  12026. if (angle >= startAngle && angle <= endAngle || angle + PI2$1 >= startAngle && angle + PI2$1 <= endAngle) {
  12027. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  12028. dir = -dir;
  12029. }
  12030. w += dir;
  12031. }
  12032. }
  12033. }
  12034. return w;
  12035. }
  12036. function containPath(data, lineWidth, isStroke, x, y) {
  12037. var w = 0;
  12038. var xi = 0;
  12039. var yi = 0;
  12040. var x0 = 0;
  12041. var y0 = 0;
  12042. for (var i = 0; i < data.length;) {
  12043. var cmd = data[i++]; // Begin a new subpath
  12044. if (cmd === CMD$1.M && i > 1) {
  12045. // Close previous subpath
  12046. if (!isStroke) {
  12047. w += windingLine(xi, yi, x0, y0, x, y);
  12048. } // 如果被任何一个 subpath 包含
  12049. // if (w !== 0) {
  12050. // return true;
  12051. // }
  12052. }
  12053. if (i === 1) {
  12054. // 如果第一个命令是 L, C, Q
  12055. // 则 previous point 同绘制命令的第一个 point
  12056. //
  12057. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12058. xi = data[i];
  12059. yi = data[i + 1];
  12060. x0 = xi;
  12061. y0 = yi;
  12062. }
  12063. switch (cmd) {
  12064. case CMD$1.M:
  12065. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  12066. // 在 closePath 的时候使用
  12067. x0 = data[i++];
  12068. y0 = data[i++];
  12069. xi = x0;
  12070. yi = y0;
  12071. break;
  12072. case CMD$1.L:
  12073. if (isStroke) {
  12074. if (containStroke$1(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  12075. return true;
  12076. }
  12077. } else {
  12078. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  12079. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  12080. }
  12081. xi = data[i++];
  12082. yi = data[i++];
  12083. break;
  12084. case CMD$1.C:
  12085. if (isStroke) {
  12086. if (containStroke$2(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  12087. return true;
  12088. }
  12089. } else {
  12090. w += windingCubic(xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  12091. }
  12092. xi = data[i++];
  12093. yi = data[i++];
  12094. break;
  12095. case CMD$1.Q:
  12096. if (isStroke) {
  12097. if (containStroke$3(xi, yi, data[i++], data[i++], data[i], data[i + 1], lineWidth, x, y)) {
  12098. return true;
  12099. }
  12100. } else {
  12101. w += windingQuadratic(xi, yi, data[i++], data[i++], data[i], data[i + 1], x, y) || 0;
  12102. }
  12103. xi = data[i++];
  12104. yi = data[i++];
  12105. break;
  12106. case CMD$1.A:
  12107. // TODO Arc 判断的开销比较大
  12108. var cx = data[i++];
  12109. var cy = data[i++];
  12110. var rx = data[i++];
  12111. var ry = data[i++];
  12112. var theta = data[i++];
  12113. var dTheta = data[i++]; // TODO Arc 旋转
  12114. i += 1;
  12115. var anticlockwise = 1 - data[i++];
  12116. var x1 = Math.cos(theta) * rx + cx;
  12117. var y1 = Math.sin(theta) * ry + cy; // 不是直接使用 arc 命令
  12118. if (i > 1) {
  12119. w += windingLine(xi, yi, x1, y1, x, y);
  12120. } else {
  12121. // 第一个命令起点还未定义
  12122. x0 = x1;
  12123. y0 = y1;
  12124. } // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  12125. var _x = (x - cx) * ry / rx + cx;
  12126. if (isStroke) {
  12127. if (containStroke$4(cx, cy, ry, theta, theta + dTheta, anticlockwise, lineWidth, _x, y)) {
  12128. return true;
  12129. }
  12130. } else {
  12131. w += windingArc(cx, cy, ry, theta, theta + dTheta, anticlockwise, _x, y);
  12132. }
  12133. xi = Math.cos(theta + dTheta) * rx + cx;
  12134. yi = Math.sin(theta + dTheta) * ry + cy;
  12135. break;
  12136. case CMD$1.R:
  12137. x0 = xi = data[i++];
  12138. y0 = yi = data[i++];
  12139. var width = data[i++];
  12140. var height = data[i++];
  12141. var x1 = x0 + width;
  12142. var y1 = y0 + height;
  12143. if (isStroke) {
  12144. 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)) {
  12145. return true;
  12146. }
  12147. } else {
  12148. // FIXME Clockwise ?
  12149. w += windingLine(x1, y0, x1, y1, x, y);
  12150. w += windingLine(x0, y1, x0, y0, x, y);
  12151. }
  12152. break;
  12153. case CMD$1.Z:
  12154. if (isStroke) {
  12155. if (containStroke$1(xi, yi, x0, y0, lineWidth, x, y)) {
  12156. return true;
  12157. }
  12158. } else {
  12159. // Close a subpath
  12160. w += windingLine(xi, yi, x0, y0, x, y); // 如果被任何一个 subpath 包含
  12161. // FIXME subpaths may overlap
  12162. // if (w !== 0) {
  12163. // return true;
  12164. // }
  12165. }
  12166. xi = x0;
  12167. yi = y0;
  12168. break;
  12169. }
  12170. }
  12171. if (!isStroke && !isAroundEqual(yi, y0)) {
  12172. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  12173. }
  12174. return w !== 0;
  12175. }
  12176. function contain(pathData, x, y) {
  12177. return containPath(pathData, 0, false, x, y);
  12178. }
  12179. function containStroke(pathData, lineWidth, x, y) {
  12180. return containPath(pathData, lineWidth, true, x, y);
  12181. }
  12182. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  12183. var abs = Math.abs;
  12184. var pathProxyForDraw = new PathProxy(true);
  12185. /**
  12186. * @alias module:zrender/graphic/Path
  12187. * @extends module:zrender/graphic/Displayable
  12188. * @constructor
  12189. * @param {Object} opts
  12190. */
  12191. function Path(opts) {
  12192. Displayable.call(this, opts);
  12193. /**
  12194. * @type {module:zrender/core/PathProxy}
  12195. * @readOnly
  12196. */
  12197. this.path = null;
  12198. }
  12199. Path.prototype = {
  12200. constructor: Path,
  12201. type: 'path',
  12202. __dirtyPath: true,
  12203. strokeContainThreshold: 5,
  12204. // This item default to be false. But in map series in echarts,
  12205. // in order to improve performance, it should be set to true,
  12206. // so the shorty segment won't draw.
  12207. segmentIgnoreThreshold: 0,
  12208. /**
  12209. * See `module:zrender/src/graphic/helper/subPixelOptimize`.
  12210. * @type {boolean}
  12211. */
  12212. subPixelOptimize: false,
  12213. brush: function (ctx, prevEl) {
  12214. var style = this.style;
  12215. var path = this.path || pathProxyForDraw;
  12216. var hasStroke = style.hasStroke();
  12217. var hasFill = style.hasFill();
  12218. var fill = style.fill;
  12219. var stroke = style.stroke;
  12220. var hasFillGradient = hasFill && !!fill.colorStops;
  12221. var hasStrokeGradient = hasStroke && !!stroke.colorStops;
  12222. var hasFillPattern = hasFill && !!fill.image;
  12223. var hasStrokePattern = hasStroke && !!stroke.image;
  12224. style.bind(ctx, this, prevEl);
  12225. this.setTransform(ctx);
  12226. if (this.__dirty) {
  12227. var rect; // Update gradient because bounding rect may changed
  12228. if (hasFillGradient) {
  12229. rect = rect || this.getBoundingRect();
  12230. this._fillGradient = style.getGradient(ctx, fill, rect);
  12231. }
  12232. if (hasStrokeGradient) {
  12233. rect = rect || this.getBoundingRect();
  12234. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  12235. }
  12236. } // Use the gradient or pattern
  12237. if (hasFillGradient) {
  12238. // PENDING If may have affect the state
  12239. ctx.fillStyle = this._fillGradient;
  12240. } else if (hasFillPattern) {
  12241. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  12242. }
  12243. if (hasStrokeGradient) {
  12244. ctx.strokeStyle = this._strokeGradient;
  12245. } else if (hasStrokePattern) {
  12246. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  12247. }
  12248. var lineDash = style.lineDash;
  12249. var lineDashOffset = style.lineDashOffset;
  12250. var ctxLineDash = !!ctx.setLineDash; // Update path sx, sy
  12251. var scale = this.getGlobalScale();
  12252. path.setScale(scale[0], scale[1], this.segmentIgnoreThreshold); // Proxy context
  12253. // Rebuild path in following 2 cases
  12254. // 1. Path is dirty
  12255. // 2. Path needs javascript implemented lineDash stroking.
  12256. // In this case, lineDash information will not be saved in PathProxy
  12257. if (this.__dirtyPath || lineDash && !ctxLineDash && hasStroke) {
  12258. path.beginPath(ctx); // Setting line dash before build path
  12259. if (lineDash && !ctxLineDash) {
  12260. path.setLineDash(lineDash);
  12261. path.setLineDashOffset(lineDashOffset);
  12262. }
  12263. this.buildPath(path, this.shape, false); // Clear path dirty flag
  12264. if (this.path) {
  12265. this.__dirtyPath = false;
  12266. }
  12267. } else {
  12268. // Replay path building
  12269. ctx.beginPath();
  12270. this.path.rebuildPath(ctx);
  12271. }
  12272. if (hasFill) {
  12273. if (style.fillOpacity != null) {
  12274. var originalGlobalAlpha = ctx.globalAlpha;
  12275. ctx.globalAlpha = style.fillOpacity * style.opacity;
  12276. path.fill(ctx);
  12277. ctx.globalAlpha = originalGlobalAlpha;
  12278. } else {
  12279. path.fill(ctx);
  12280. }
  12281. }
  12282. if (lineDash && ctxLineDash) {
  12283. ctx.setLineDash(lineDash);
  12284. ctx.lineDashOffset = lineDashOffset;
  12285. }
  12286. if (hasStroke) {
  12287. if (style.strokeOpacity != null) {
  12288. var originalGlobalAlpha = ctx.globalAlpha;
  12289. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  12290. path.stroke(ctx);
  12291. ctx.globalAlpha = originalGlobalAlpha;
  12292. } else {
  12293. path.stroke(ctx);
  12294. }
  12295. }
  12296. if (lineDash && ctxLineDash) {
  12297. // PENDING
  12298. // Remove lineDash
  12299. ctx.setLineDash([]);
  12300. } // Draw rect text
  12301. if (style.text != null) {
  12302. // Only restore transform when needs draw text.
  12303. this.restoreTransform(ctx);
  12304. this.drawRectText(ctx, this.getBoundingRect());
  12305. }
  12306. },
  12307. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  12308. // Like in circle
  12309. buildPath: function (ctx, shapeCfg, inBundle) {},
  12310. createPathProxy: function () {
  12311. this.path = new PathProxy();
  12312. },
  12313. getBoundingRect: function () {
  12314. var rect = this._rect;
  12315. var style = this.style;
  12316. var needsUpdateRect = !rect;
  12317. if (needsUpdateRect) {
  12318. var path = this.path;
  12319. if (!path) {
  12320. // Create path on demand.
  12321. path = this.path = new PathProxy();
  12322. }
  12323. if (this.__dirtyPath) {
  12324. path.beginPath();
  12325. this.buildPath(path, this.shape, false);
  12326. }
  12327. rect = path.getBoundingRect();
  12328. }
  12329. this._rect = rect;
  12330. if (style.hasStroke()) {
  12331. // Needs update rect with stroke lineWidth when
  12332. // 1. Element changes scale or lineWidth
  12333. // 2. Shape is changed
  12334. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  12335. if (this.__dirty || needsUpdateRect) {
  12336. rectWithStroke.copy(rect); // FIXME Must after updateTransform
  12337. var w = style.lineWidth; // PENDING, Min line width is needed when line is horizontal or vertical
  12338. var lineScale = style.strokeNoScale ? this.getLineScale() : 1; // Only add extra hover lineWidth when there are no fill
  12339. if (!style.hasFill()) {
  12340. w = Math.max(w, this.strokeContainThreshold || 4);
  12341. } // Consider line width
  12342. // Line scale can't be 0;
  12343. if (lineScale > 1e-10) {
  12344. rectWithStroke.width += w / lineScale;
  12345. rectWithStroke.height += w / lineScale;
  12346. rectWithStroke.x -= w / lineScale / 2;
  12347. rectWithStroke.y -= w / lineScale / 2;
  12348. }
  12349. } // Return rect with stroke
  12350. return rectWithStroke;
  12351. }
  12352. return rect;
  12353. },
  12354. contain: function (x, y) {
  12355. var localPos = this.transformCoordToLocal(x, y);
  12356. var rect = this.getBoundingRect();
  12357. var style = this.style;
  12358. x = localPos[0];
  12359. y = localPos[1];
  12360. if (rect.contain(x, y)) {
  12361. var pathData = this.path.data;
  12362. if (style.hasStroke()) {
  12363. var lineWidth = style.lineWidth;
  12364. var lineScale = style.strokeNoScale ? this.getLineScale() : 1; // Line scale can't be 0;
  12365. if (lineScale > 1e-10) {
  12366. // Only add extra hover lineWidth when there are no fill
  12367. if (!style.hasFill()) {
  12368. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  12369. }
  12370. if (containStroke(pathData, lineWidth / lineScale, x, y)) {
  12371. return true;
  12372. }
  12373. }
  12374. }
  12375. if (style.hasFill()) {
  12376. return contain(pathData, x, y);
  12377. }
  12378. }
  12379. return false;
  12380. },
  12381. /**
  12382. * @param {boolean} dirtyPath
  12383. */
  12384. dirty: function (dirtyPath) {
  12385. if (dirtyPath == null) {
  12386. dirtyPath = true;
  12387. } // Only mark dirty, not mark clean
  12388. if (dirtyPath) {
  12389. this.__dirtyPath = dirtyPath;
  12390. this._rect = null;
  12391. }
  12392. this.__dirty = this.__dirtyText = true;
  12393. this.__zr && this.__zr.refresh(); // Used as a clipping path
  12394. if (this.__clipTarget) {
  12395. this.__clipTarget.dirty();
  12396. }
  12397. },
  12398. /**
  12399. * Alias for animate('shape')
  12400. * @param {boolean} loop
  12401. */
  12402. animateShape: function (loop) {
  12403. return this.animate('shape', loop);
  12404. },
  12405. // Overwrite attrKV
  12406. attrKV: function (key, value) {
  12407. // FIXME
  12408. if (key === 'shape') {
  12409. this.setShape(value);
  12410. this.__dirtyPath = true;
  12411. this._rect = null;
  12412. } else {
  12413. Displayable.prototype.attrKV.call(this, key, value);
  12414. }
  12415. },
  12416. /**
  12417. * @param {Object|string} key
  12418. * @param {*} value
  12419. */
  12420. setShape: function (key, value) {
  12421. var shape = this.shape; // Path from string may not have shape
  12422. if (shape) {
  12423. if (isObject$1(key)) {
  12424. for (var name in key) {
  12425. if (key.hasOwnProperty(name)) {
  12426. shape[name] = key[name];
  12427. }
  12428. }
  12429. } else {
  12430. shape[key] = value;
  12431. }
  12432. this.dirty(true);
  12433. }
  12434. return this;
  12435. },
  12436. getLineScale: function () {
  12437. var m = this.transform; // Get the line scale.
  12438. // Determinant of `m` means how much the area is enlarged by the
  12439. // transformation. So its square root can be used as a scale factor
  12440. // for width.
  12441. 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;
  12442. }
  12443. };
  12444. /**
  12445. * 扩展一个 Path element, 比如星形,圆等。
  12446. * Extend a path element
  12447. * @param {Object} props
  12448. * @param {string} props.type Path type
  12449. * @param {Function} props.init Initialize
  12450. * @param {Function} props.buildPath Overwrite buildPath method
  12451. * @param {Object} [props.style] Extended default style config
  12452. * @param {Object} [props.shape] Extended default shape config
  12453. */
  12454. Path.extend = function (defaults$$1) {
  12455. var Sub = function (opts) {
  12456. Path.call(this, opts);
  12457. if (defaults$$1.style) {
  12458. // Extend default style
  12459. this.style.extendFrom(defaults$$1.style, false);
  12460. } // Extend default shape
  12461. var defaultShape = defaults$$1.shape;
  12462. if (defaultShape) {
  12463. this.shape = this.shape || {};
  12464. var thisShape = this.shape;
  12465. for (var name in defaultShape) {
  12466. if (!thisShape.hasOwnProperty(name) && defaultShape.hasOwnProperty(name)) {
  12467. thisShape[name] = defaultShape[name];
  12468. }
  12469. }
  12470. }
  12471. defaults$$1.init && defaults$$1.init.call(this, opts);
  12472. };
  12473. inherits(Sub, Path); // FIXME 不能 extend position, rotation 等引用对象
  12474. for (var name in defaults$$1) {
  12475. // Extending prototype values and methods
  12476. if (name !== 'style' && name !== 'shape') {
  12477. Sub.prototype[name] = defaults$$1[name];
  12478. }
  12479. }
  12480. return Sub;
  12481. };
  12482. inherits(Path, Displayable);
  12483. var CMD$2 = PathProxy.CMD;
  12484. var points = [[], [], []];
  12485. var mathSqrt$3 = Math.sqrt;
  12486. var mathAtan2 = Math.atan2;
  12487. var transformPath = function (path, m) {
  12488. var data = path.data;
  12489. var cmd;
  12490. var nPoint;
  12491. var i;
  12492. var j;
  12493. var k;
  12494. var p;
  12495. var M = CMD$2.M;
  12496. var C = CMD$2.C;
  12497. var L = CMD$2.L;
  12498. var R = CMD$2.R;
  12499. var A = CMD$2.A;
  12500. var Q = CMD$2.Q;
  12501. for (i = 0, j = 0; i < data.length;) {
  12502. cmd = data[i++];
  12503. j = i;
  12504. nPoint = 0;
  12505. switch (cmd) {
  12506. case M:
  12507. nPoint = 1;
  12508. break;
  12509. case L:
  12510. nPoint = 1;
  12511. break;
  12512. case C:
  12513. nPoint = 3;
  12514. break;
  12515. case Q:
  12516. nPoint = 2;
  12517. break;
  12518. case A:
  12519. var x = m[4];
  12520. var y = m[5];
  12521. var sx = mathSqrt$3(m[0] * m[0] + m[1] * m[1]);
  12522. var sy = mathSqrt$3(m[2] * m[2] + m[3] * m[3]);
  12523. var angle = mathAtan2(-m[1] / sy, m[0] / sx); // cx
  12524. data[i] *= sx;
  12525. data[i++] += x; // cy
  12526. data[i] *= sy;
  12527. data[i++] += y; // Scale rx and ry
  12528. // FIXME Assume psi is 0 here
  12529. data[i++] *= sx;
  12530. data[i++] *= sy; // Start angle
  12531. data[i++] += angle; // end angle
  12532. data[i++] += angle; // FIXME psi
  12533. i += 2;
  12534. j = i;
  12535. break;
  12536. case R:
  12537. // x0, y0
  12538. p[0] = data[i++];
  12539. p[1] = data[i++];
  12540. applyTransform(p, p, m);
  12541. data[j++] = p[0];
  12542. data[j++] = p[1]; // x1, y1
  12543. p[0] += data[i++];
  12544. p[1] += data[i++];
  12545. applyTransform(p, p, m);
  12546. data[j++] = p[0];
  12547. data[j++] = p[1];
  12548. }
  12549. for (k = 0; k < nPoint; k++) {
  12550. var p = points[k];
  12551. p[0] = data[i++];
  12552. p[1] = data[i++];
  12553. applyTransform(p, p, m); // Write back
  12554. data[j++] = p[0];
  12555. data[j++] = p[1];
  12556. }
  12557. }
  12558. };
  12559. // var cc = [
  12560. // 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  12561. // 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  12562. // ];
  12563. var mathSqrt = Math.sqrt;
  12564. var mathSin = Math.sin;
  12565. var mathCos = Math.cos;
  12566. var PI = Math.PI;
  12567. var vMag = function (v) {
  12568. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  12569. };
  12570. var vRatio = function (u, v) {
  12571. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  12572. };
  12573. var vAngle = function (u, v) {
  12574. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
  12575. };
  12576. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  12577. var psi = psiDeg * (PI / 180.0);
  12578. var xp = mathCos(psi) * (x1 - x2) / 2.0 + mathSin(psi) * (y1 - y2) / 2.0;
  12579. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0 + mathCos(psi) * (y1 - y2) / 2.0;
  12580. var lambda = xp * xp / (rx * rx) + yp * yp / (ry * ry);
  12581. if (lambda > 1) {
  12582. rx *= mathSqrt(lambda);
  12583. ry *= mathSqrt(lambda);
  12584. }
  12585. 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;
  12586. var cxp = f * rx * yp / ry;
  12587. var cyp = f * -ry * xp / rx;
  12588. var cx = (x1 + x2) / 2.0 + mathCos(psi) * cxp - mathSin(psi) * cyp;
  12589. var cy = (y1 + y2) / 2.0 + mathSin(psi) * cxp + mathCos(psi) * cyp;
  12590. var theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
  12591. var u = [(xp - cxp) / rx, (yp - cyp) / ry];
  12592. var v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
  12593. var dTheta = vAngle(u, v);
  12594. if (vRatio(u, v) <= -1) {
  12595. dTheta = PI;
  12596. }
  12597. if (vRatio(u, v) >= 1) {
  12598. dTheta = 0;
  12599. }
  12600. if (fs === 0 && dTheta > 0) {
  12601. dTheta = dTheta - 2 * PI;
  12602. }
  12603. if (fs === 1 && dTheta < 0) {
  12604. dTheta = dTheta + 2 * PI;
  12605. }
  12606. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  12607. }
  12608. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig; // Consider case:
  12609. // (1) delimiter can be comma or space, where continuous commas
  12610. // or spaces should be seen as one comma.
  12611. // (2) value can be like:
  12612. // '2e-4', 'l.5.9' (ignore 0), 'M-10-10', 'l-2.43e-1,34.9983',
  12613. // 'l-.5E1,54', '121-23-44-11' (no delimiter)
  12614. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g; // var valueSplitReg = /[\s,]+/;
  12615. function createPathProxyFromString(data) {
  12616. if (!data) {
  12617. return new PathProxy();
  12618. } // var data = data.replace(/-/g, ' -')
  12619. // .replace(/ /g, ' ')
  12620. // .replace(/ /g, ',')
  12621. // .replace(/,,/g, ',');
  12622. // var n;
  12623. // create pipes so that we can split the data
  12624. // for (n = 0; n < cc.length; n++) {
  12625. // cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  12626. // }
  12627. // data = data.replace(/-/g, ',-');
  12628. // create array
  12629. // var arr = cs.split('|');
  12630. // init context point
  12631. var cpx = 0;
  12632. var cpy = 0;
  12633. var subpathX = cpx;
  12634. var subpathY = cpy;
  12635. var prevCmd;
  12636. var path = new PathProxy();
  12637. var CMD = PathProxy.CMD; // commandReg.lastIndex = 0;
  12638. // var cmdResult;
  12639. // while ((cmdResult = commandReg.exec(data)) != null) {
  12640. // var cmdStr = cmdResult[1];
  12641. // var cmdContent = cmdResult[2];
  12642. var cmdList = data.match(commandReg);
  12643. for (var l = 0; l < cmdList.length; l++) {
  12644. var cmdText = cmdList[l];
  12645. var cmdStr = cmdText.charAt(0);
  12646. var cmd; // String#split is faster a little bit than String#replace or RegExp#exec.
  12647. // var p = cmdContent.split(valueSplitReg);
  12648. // var pLen = 0;
  12649. // for (var i = 0; i < p.length; i++) {
  12650. // // '' and other invalid str => NaN
  12651. // var val = parseFloat(p[i]);
  12652. // !isNaN(val) && (p[pLen++] = val);
  12653. // }
  12654. var p = cmdText.match(numberReg) || [];
  12655. var pLen = p.length;
  12656. for (var i = 0; i < pLen; i++) {
  12657. p[i] = parseFloat(p[i]);
  12658. }
  12659. var off = 0;
  12660. while (off < pLen) {
  12661. var ctlPtx;
  12662. var ctlPty;
  12663. var rx;
  12664. var ry;
  12665. var psi;
  12666. var fa;
  12667. var fs;
  12668. var x1 = cpx;
  12669. var y1 = cpy; // convert l, H, h, V, and v to L
  12670. switch (cmdStr) {
  12671. case 'l':
  12672. cpx += p[off++];
  12673. cpy += p[off++];
  12674. cmd = CMD.L;
  12675. path.addData(cmd, cpx, cpy);
  12676. break;
  12677. case 'L':
  12678. cpx = p[off++];
  12679. cpy = p[off++];
  12680. cmd = CMD.L;
  12681. path.addData(cmd, cpx, cpy);
  12682. break;
  12683. case 'm':
  12684. cpx += p[off++];
  12685. cpy += p[off++];
  12686. cmd = CMD.M;
  12687. path.addData(cmd, cpx, cpy);
  12688. subpathX = cpx;
  12689. subpathY = cpy;
  12690. cmdStr = 'l';
  12691. break;
  12692. case 'M':
  12693. cpx = p[off++];
  12694. cpy = p[off++];
  12695. cmd = CMD.M;
  12696. path.addData(cmd, cpx, cpy);
  12697. subpathX = cpx;
  12698. subpathY = cpy;
  12699. cmdStr = 'L';
  12700. break;
  12701. case 'h':
  12702. cpx += p[off++];
  12703. cmd = CMD.L;
  12704. path.addData(cmd, cpx, cpy);
  12705. break;
  12706. case 'H':
  12707. cpx = p[off++];
  12708. cmd = CMD.L;
  12709. path.addData(cmd, cpx, cpy);
  12710. break;
  12711. case 'v':
  12712. cpy += p[off++];
  12713. cmd = CMD.L;
  12714. path.addData(cmd, cpx, cpy);
  12715. break;
  12716. case 'V':
  12717. cpy = p[off++];
  12718. cmd = CMD.L;
  12719. path.addData(cmd, cpx, cpy);
  12720. break;
  12721. case 'C':
  12722. cmd = CMD.C;
  12723. path.addData(cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]);
  12724. cpx = p[off - 2];
  12725. cpy = p[off - 1];
  12726. break;
  12727. case 'c':
  12728. cmd = CMD.C;
  12729. path.addData(cmd, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy, p[off++] + cpx, p[off++] + cpy);
  12730. cpx += p[off - 2];
  12731. cpy += p[off - 1];
  12732. break;
  12733. case 'S':
  12734. ctlPtx = cpx;
  12735. ctlPty = cpy;
  12736. var len = path.len();
  12737. var pathData = path.data;
  12738. if (prevCmd === CMD.C) {
  12739. ctlPtx += cpx - pathData[len - 4];
  12740. ctlPty += cpy - pathData[len - 3];
  12741. }
  12742. cmd = CMD.C;
  12743. x1 = p[off++];
  12744. y1 = p[off++];
  12745. cpx = p[off++];
  12746. cpy = p[off++];
  12747. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12748. break;
  12749. case 's':
  12750. ctlPtx = cpx;
  12751. ctlPty = cpy;
  12752. var len = path.len();
  12753. var pathData = path.data;
  12754. if (prevCmd === CMD.C) {
  12755. ctlPtx += cpx - pathData[len - 4];
  12756. ctlPty += cpy - pathData[len - 3];
  12757. }
  12758. cmd = CMD.C;
  12759. x1 = cpx + p[off++];
  12760. y1 = cpy + p[off++];
  12761. cpx += p[off++];
  12762. cpy += p[off++];
  12763. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  12764. break;
  12765. case 'Q':
  12766. x1 = p[off++];
  12767. y1 = p[off++];
  12768. cpx = p[off++];
  12769. cpy = p[off++];
  12770. cmd = CMD.Q;
  12771. path.addData(cmd, x1, y1, cpx, cpy);
  12772. break;
  12773. case 'q':
  12774. x1 = p[off++] + cpx;
  12775. y1 = p[off++] + cpy;
  12776. cpx += p[off++];
  12777. cpy += p[off++];
  12778. cmd = CMD.Q;
  12779. path.addData(cmd, x1, y1, cpx, cpy);
  12780. break;
  12781. case 'T':
  12782. ctlPtx = cpx;
  12783. ctlPty = cpy;
  12784. var len = path.len();
  12785. var pathData = path.data;
  12786. if (prevCmd === CMD.Q) {
  12787. ctlPtx += cpx - pathData[len - 4];
  12788. ctlPty += cpy - pathData[len - 3];
  12789. }
  12790. cpx = p[off++];
  12791. cpy = p[off++];
  12792. cmd = CMD.Q;
  12793. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12794. break;
  12795. case 't':
  12796. ctlPtx = cpx;
  12797. ctlPty = cpy;
  12798. var len = path.len();
  12799. var pathData = path.data;
  12800. if (prevCmd === CMD.Q) {
  12801. ctlPtx += cpx - pathData[len - 4];
  12802. ctlPty += cpy - pathData[len - 3];
  12803. }
  12804. cpx += p[off++];
  12805. cpy += p[off++];
  12806. cmd = CMD.Q;
  12807. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  12808. break;
  12809. case 'A':
  12810. rx = p[off++];
  12811. ry = p[off++];
  12812. psi = p[off++];
  12813. fa = p[off++];
  12814. fs = p[off++];
  12815. x1 = cpx, y1 = cpy;
  12816. cpx = p[off++];
  12817. cpy = p[off++];
  12818. cmd = CMD.A;
  12819. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  12820. break;
  12821. case 'a':
  12822. rx = p[off++];
  12823. ry = p[off++];
  12824. psi = p[off++];
  12825. fa = p[off++];
  12826. fs = p[off++];
  12827. x1 = cpx, y1 = cpy;
  12828. cpx += p[off++];
  12829. cpy += p[off++];
  12830. cmd = CMD.A;
  12831. processArc(x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path);
  12832. break;
  12833. }
  12834. }
  12835. if (cmdStr === 'z' || cmdStr === 'Z') {
  12836. cmd = CMD.Z;
  12837. path.addData(cmd); // z may be in the middle of the path.
  12838. cpx = subpathX;
  12839. cpy = subpathY;
  12840. }
  12841. prevCmd = cmd;
  12842. }
  12843. path.toStatic();
  12844. return path;
  12845. } // TODO Optimize double memory cost problem
  12846. function createPathOptions(str, opts) {
  12847. var pathProxy = createPathProxyFromString(str);
  12848. opts = opts || {};
  12849. opts.buildPath = function (path) {
  12850. if (path.setData) {
  12851. path.setData(pathProxy.data); // Svg and vml renderer don't have context
  12852. var ctx = path.getContext();
  12853. if (ctx) {
  12854. path.rebuildPath(ctx);
  12855. }
  12856. } else {
  12857. var ctx = path;
  12858. pathProxy.rebuildPath(ctx);
  12859. }
  12860. };
  12861. opts.applyTransform = function (m) {
  12862. transformPath(pathProxy, m);
  12863. this.dirty(true);
  12864. };
  12865. return opts;
  12866. }
  12867. /**
  12868. * Create a Path object from path string data
  12869. * http://www.w3.org/TR/SVG/paths.html#PathData
  12870. * @param {Object} opts Other options
  12871. */
  12872. function createFromString(str, opts) {
  12873. return new Path(createPathOptions(str, opts));
  12874. }
  12875. /**
  12876. * Create a Path class from path string data
  12877. * @param {string} str
  12878. * @param {Object} opts Other options
  12879. */
  12880. function extendFromString(str, opts) {
  12881. return Path.extend(createPathOptions(str, opts));
  12882. }
  12883. /**
  12884. * Merge multiple paths
  12885. */
  12886. // TODO Apply transform
  12887. // TODO stroke dash
  12888. // TODO Optimize double memory cost problem
  12889. function mergePath$1(pathEls, opts) {
  12890. var pathList = [];
  12891. var len = pathEls.length;
  12892. for (var i = 0; i < len; i++) {
  12893. var pathEl = pathEls[i];
  12894. if (!pathEl.path) {
  12895. pathEl.createPathProxy();
  12896. }
  12897. if (pathEl.__dirtyPath) {
  12898. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  12899. }
  12900. pathList.push(pathEl.path);
  12901. }
  12902. var pathBundle = new Path(opts); // Need path proxy.
  12903. pathBundle.createPathProxy();
  12904. pathBundle.buildPath = function (path) {
  12905. path.appendPath(pathList); // Svg and vml renderer don't have context
  12906. var ctx = path.getContext();
  12907. if (ctx) {
  12908. path.rebuildPath(ctx);
  12909. }
  12910. };
  12911. return pathBundle;
  12912. }
  12913. /**
  12914. * @alias zrender/graphic/Text
  12915. * @extends module:zrender/graphic/Displayable
  12916. * @constructor
  12917. * @param {Object} opts
  12918. */
  12919. var Text = function (opts) {
  12920. // jshint ignore:line
  12921. Displayable.call(this, opts);
  12922. };
  12923. Text.prototype = {
  12924. constructor: Text,
  12925. type: 'text',
  12926. brush: function (ctx, prevEl) {
  12927. var style = this.style; // Optimize, avoid normalize every time.
  12928. this.__dirty && normalizeTextStyle(style, true); // Use props with prefix 'text'.
  12929. style.fill = style.stroke = style.shadowBlur = style.shadowColor = style.shadowOffsetX = style.shadowOffsetY = null;
  12930. var text = style.text; // Convert to string
  12931. text != null && (text += ''); // Do not apply style.bind in Text node. Because the real bind job
  12932. // is in textHelper.renderText, and performance of text render should
  12933. // be considered.
  12934. // style.bind(ctx, this, prevEl);
  12935. if (!needDrawText(text, style)) {
  12936. // The current el.style is not applied
  12937. // and should not be used as cache.
  12938. ctx.__attrCachedBy = ContextCachedBy.NONE;
  12939. return;
  12940. }
  12941. this.setTransform(ctx);
  12942. renderText(this, ctx, text, style, null, prevEl);
  12943. this.restoreTransform(ctx);
  12944. },
  12945. getBoundingRect: function () {
  12946. var style = this.style; // Optimize, avoid normalize every time.
  12947. this.__dirty && normalizeTextStyle(style, true);
  12948. if (!this._rect) {
  12949. var text = style.text;
  12950. text != null ? text += '' : text = '';
  12951. var rect = getBoundingRect(style.text + '', style.font, style.textAlign, style.textVerticalAlign, style.textPadding, style.textLineHeight, style.rich);
  12952. rect.x += style.x || 0;
  12953. rect.y += style.y || 0;
  12954. if (getStroke(style.textStroke, style.textStrokeWidth)) {
  12955. var w = style.textStrokeWidth;
  12956. rect.x -= w / 2;
  12957. rect.y -= w / 2;
  12958. rect.width += w;
  12959. rect.height += w;
  12960. }
  12961. this._rect = rect;
  12962. }
  12963. return this._rect;
  12964. }
  12965. };
  12966. inherits(Text, Displayable);
  12967. /**
  12968. * 圆形
  12969. * @module zrender/shape/Circle
  12970. */
  12971. var Circle = Path.extend({
  12972. type: 'circle',
  12973. shape: {
  12974. cx: 0,
  12975. cy: 0,
  12976. r: 0
  12977. },
  12978. buildPath: function (ctx, shape, inBundle) {
  12979. // Better stroking in ShapeBundle
  12980. // Always do it may have performence issue ( fill may be 2x more cost)
  12981. if (inBundle) {
  12982. ctx.moveTo(shape.cx + shape.r, shape.cy);
  12983. } // else {
  12984. // if (ctx.allocate && !ctx.data.length) {
  12985. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  12986. // }
  12987. // }
  12988. // Better stroking in ShapeBundle
  12989. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  12990. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  12991. }
  12992. });
  12993. // where exception "unexpected call to method or property access"
  12994. // might be thrown when calling ctx.fill or ctx.stroke after a path
  12995. // whose area size is zero is drawn and ctx.clip() is called and
  12996. // shadowBlur is set. See #4572, #3112, #5777.
  12997. // (e.g.,
  12998. // ctx.moveTo(10, 10);
  12999. // ctx.lineTo(20, 10);
  13000. // ctx.closePath();
  13001. // ctx.clip();
  13002. // ctx.shadowBlur = 10;
  13003. // ...
  13004. // ctx.fill();
  13005. // )
  13006. var shadowTemp = [['shadowBlur', 0], ['shadowColor', '#000'], ['shadowOffsetX', 0], ['shadowOffsetY', 0]];
  13007. var fixClipWithShadow = function (orignalBrush) {
  13008. // version string can be: '11.0'
  13009. return env$1.browser.ie && env$1.browser.version >= 11 ? function () {
  13010. var clipPaths = this.__clipPaths;
  13011. var style = this.style;
  13012. var modified;
  13013. if (clipPaths) {
  13014. for (var i = 0; i < clipPaths.length; i++) {
  13015. var clipPath = clipPaths[i];
  13016. var shape = clipPath && clipPath.shape;
  13017. var type = clipPath && clipPath.type;
  13018. if (shape && (type === 'sector' && shape.startAngle === shape.endAngle || type === 'rect' && (!shape.width || !shape.height))) {
  13019. for (var j = 0; j < shadowTemp.length; j++) {
  13020. // It is save to put shadowTemp static, because shadowTemp
  13021. // will be all modified each item brush called.
  13022. shadowTemp[j][2] = style[shadowTemp[j][0]];
  13023. style[shadowTemp[j][0]] = shadowTemp[j][1];
  13024. }
  13025. modified = true;
  13026. break;
  13027. }
  13028. }
  13029. }
  13030. orignalBrush.apply(this, arguments);
  13031. if (modified) {
  13032. for (var j = 0; j < shadowTemp.length; j++) {
  13033. style[shadowTemp[j][0]] = shadowTemp[j][2];
  13034. }
  13035. }
  13036. } : orignalBrush;
  13037. };
  13038. /**
  13039. * 扇形
  13040. * @module zrender/graphic/shape/Sector
  13041. */
  13042. var Sector = Path.extend({
  13043. type: 'sector',
  13044. shape: {
  13045. cx: 0,
  13046. cy: 0,
  13047. r0: 0,
  13048. r: 0,
  13049. startAngle: 0,
  13050. endAngle: Math.PI * 2,
  13051. clockwise: true
  13052. },
  13053. brush: fixClipWithShadow(Path.prototype.brush),
  13054. buildPath: function (ctx, shape) {
  13055. var x = shape.cx;
  13056. var y = shape.cy;
  13057. var r0 = Math.max(shape.r0 || 0, 0);
  13058. var r = Math.max(shape.r, 0);
  13059. var startAngle = shape.startAngle;
  13060. var endAngle = shape.endAngle;
  13061. var clockwise = shape.clockwise;
  13062. var unitX = Math.cos(startAngle);
  13063. var unitY = Math.sin(startAngle);
  13064. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  13065. ctx.lineTo(unitX * r + x, unitY * r + y);
  13066. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13067. ctx.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  13068. if (r0 !== 0) {
  13069. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  13070. }
  13071. ctx.closePath();
  13072. }
  13073. });
  13074. /**
  13075. * 圆环
  13076. * @module zrender/graphic/shape/Ring
  13077. */
  13078. var Ring = Path.extend({
  13079. type: 'ring',
  13080. shape: {
  13081. cx: 0,
  13082. cy: 0,
  13083. r: 0,
  13084. r0: 0
  13085. },
  13086. buildPath: function (ctx, shape) {
  13087. var x = shape.cx;
  13088. var y = shape.cy;
  13089. var PI2 = Math.PI * 2;
  13090. ctx.moveTo(x + shape.r, y);
  13091. ctx.arc(x, y, shape.r, 0, PI2, false);
  13092. ctx.moveTo(x + shape.r0, y);
  13093. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13094. }
  13095. });
  13096. /**
  13097. * Catmull-Rom spline 插值折线
  13098. * @module zrender/shape/util/smoothSpline
  13099. * @author pissang (https://www.github.com/pissang)
  13100. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13101. * errorrik (errorrik@gmail.com)
  13102. */
  13103. /**
  13104. * @inner
  13105. */
  13106. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  13107. var v0 = (p2 - p0) * 0.5;
  13108. var v1 = (p3 - p1) * 0.5;
  13109. return (2 * (p1 - p2) + v0 + v1) * t3 + (-3 * (p1 - p2) - 2 * v0 - v1) * t2 + v0 * t + p1;
  13110. }
  13111. /**
  13112. * @alias module:zrender/shape/util/smoothSpline
  13113. * @param {Array} points 线段顶点数组
  13114. * @param {boolean} isLoop
  13115. * @return {Array}
  13116. */
  13117. var smoothSpline = function (points, isLoop) {
  13118. var len$$1 = points.length;
  13119. var ret = [];
  13120. var distance$$1 = 0;
  13121. for (var i = 1; i < len$$1; i++) {
  13122. distance$$1 += distance(points[i - 1], points[i]);
  13123. }
  13124. var segs = distance$$1 / 2;
  13125. segs = segs < len$$1 ? len$$1 : segs;
  13126. for (var i = 0; i < segs; i++) {
  13127. var pos = i / (segs - 1) * (isLoop ? len$$1 : len$$1 - 1);
  13128. var idx = Math.floor(pos);
  13129. var w = pos - idx;
  13130. var p0;
  13131. var p1 = points[idx % len$$1];
  13132. var p2;
  13133. var p3;
  13134. if (!isLoop) {
  13135. p0 = points[idx === 0 ? idx : idx - 1];
  13136. p2 = points[idx > len$$1 - 2 ? len$$1 - 1 : idx + 1];
  13137. p3 = points[idx > len$$1 - 3 ? len$$1 - 1 : idx + 2];
  13138. } else {
  13139. p0 = points[(idx - 1 + len$$1) % len$$1];
  13140. p2 = points[(idx + 1) % len$$1];
  13141. p3 = points[(idx + 2) % len$$1];
  13142. }
  13143. var w2 = w * w;
  13144. var w3 = w * w2;
  13145. 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)]);
  13146. }
  13147. return ret;
  13148. };
  13149. /**
  13150. * 贝塞尔平滑曲线
  13151. * @module zrender/shape/util/smoothBezier
  13152. * @author pissang (https://www.github.com/pissang)
  13153. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13154. * errorrik (errorrik@gmail.com)
  13155. */
  13156. /**
  13157. * 贝塞尔平滑曲线
  13158. * @alias module:zrender/shape/util/smoothBezier
  13159. * @param {Array} points 线段顶点数组
  13160. * @param {number} smooth 平滑等级, 0-1
  13161. * @param {boolean} isLoop
  13162. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  13163. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  13164. * 整个折线的包围盒做一个并集用来约束控制点。
  13165. * @param {Array} 计算出来的控制点数组
  13166. */
  13167. var smoothBezier = function (points, smooth, isLoop, constraint) {
  13168. var cps = [];
  13169. var v = [];
  13170. var v1 = [];
  13171. var v2 = [];
  13172. var prevPoint;
  13173. var nextPoint;
  13174. var min$$1;
  13175. var max$$1;
  13176. if (constraint) {
  13177. min$$1 = [Infinity, Infinity];
  13178. max$$1 = [-Infinity, -Infinity];
  13179. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13180. min(min$$1, min$$1, points[i]);
  13181. max(max$$1, max$$1, points[i]);
  13182. } // 与指定的包围盒做并集
  13183. min(min$$1, min$$1, constraint[0]);
  13184. max(max$$1, max$$1, constraint[1]);
  13185. }
  13186. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13187. var point = points[i];
  13188. if (isLoop) {
  13189. prevPoint = points[i ? i - 1 : len$$1 - 1];
  13190. nextPoint = points[(i + 1) % len$$1];
  13191. } else {
  13192. if (i === 0 || i === len$$1 - 1) {
  13193. cps.push(clone$1(points[i]));
  13194. continue;
  13195. } else {
  13196. prevPoint = points[i - 1];
  13197. nextPoint = points[i + 1];
  13198. }
  13199. }
  13200. sub(v, nextPoint, prevPoint); // use degree to scale the handle length
  13201. scale(v, v, smooth);
  13202. var d0 = distance(point, prevPoint);
  13203. var d1 = distance(point, nextPoint);
  13204. var sum = d0 + d1;
  13205. if (sum !== 0) {
  13206. d0 /= sum;
  13207. d1 /= sum;
  13208. }
  13209. scale(v1, v, -d0);
  13210. scale(v2, v, d1);
  13211. var cp0 = add([], point, v1);
  13212. var cp1 = add([], point, v2);
  13213. if (constraint) {
  13214. max(cp0, cp0, min$$1);
  13215. min(cp0, cp0, max$$1);
  13216. max(cp1, cp1, min$$1);
  13217. min(cp1, cp1, max$$1);
  13218. }
  13219. cps.push(cp0);
  13220. cps.push(cp1);
  13221. }
  13222. if (isLoop) {
  13223. cps.push(cps.shift());
  13224. }
  13225. return cps;
  13226. };
  13227. function buildPath$1(ctx, shape, closePath) {
  13228. var points = shape.points;
  13229. var smooth = shape.smooth;
  13230. if (points && points.length >= 2) {
  13231. if (smooth && smooth !== 'spline') {
  13232. var controlPoints = smoothBezier(points, smooth, closePath, shape.smoothConstraint);
  13233. ctx.moveTo(points[0][0], points[0][1]);
  13234. var len = points.length;
  13235. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13236. var cp1 = controlPoints[i * 2];
  13237. var cp2 = controlPoints[i * 2 + 1];
  13238. var p = points[(i + 1) % len];
  13239. ctx.bezierCurveTo(cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]);
  13240. }
  13241. } else {
  13242. if (smooth === 'spline') {
  13243. points = smoothSpline(points, closePath);
  13244. }
  13245. ctx.moveTo(points[0][0], points[0][1]);
  13246. for (var i = 1, l = points.length; i < l; i++) {
  13247. ctx.lineTo(points[i][0], points[i][1]);
  13248. }
  13249. }
  13250. closePath && ctx.closePath();
  13251. }
  13252. }
  13253. /**
  13254. * 多边形
  13255. * @module zrender/shape/Polygon
  13256. */
  13257. var Polygon = Path.extend({
  13258. type: 'polygon',
  13259. shape: {
  13260. points: null,
  13261. smooth: false,
  13262. smoothConstraint: null
  13263. },
  13264. buildPath: function (ctx, shape) {
  13265. buildPath$1(ctx, shape, true);
  13266. }
  13267. });
  13268. /**
  13269. * @module zrender/graphic/shape/Polyline
  13270. */
  13271. var Polyline = Path.extend({
  13272. type: 'polyline',
  13273. shape: {
  13274. points: null,
  13275. smooth: false,
  13276. smoothConstraint: null
  13277. },
  13278. style: {
  13279. stroke: '#000',
  13280. fill: null
  13281. },
  13282. buildPath: function (ctx, shape) {
  13283. buildPath$1(ctx, shape, false);
  13284. }
  13285. });
  13286. /**
  13287. * Sub-pixel optimize for canvas rendering, prevent from blur
  13288. * when rendering a thin vertical/horizontal line.
  13289. */
  13290. var round = Math.round;
  13291. /**
  13292. * Sub pixel optimize line for canvas
  13293. *
  13294. * @param {Object} outputShape The modification will be performed on `outputShape`.
  13295. * `outputShape` and `inputShape` can be the same object.
  13296. * `outputShape` object can be used repeatly, because all of
  13297. * the `x1`, `x2`, `y1`, `y2` will be assigned in this method.
  13298. * @param {Object} [inputShape]
  13299. * @param {number} [inputShape.x1]
  13300. * @param {number} [inputShape.y1]
  13301. * @param {number} [inputShape.x2]
  13302. * @param {number} [inputShape.y2]
  13303. * @param {Object} [style]
  13304. * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.
  13305. */
  13306. function subPixelOptimizeLine$1(outputShape, inputShape, style) {
  13307. if (!inputShape) {
  13308. return;
  13309. }
  13310. var x1 = inputShape.x1;
  13311. var x2 = inputShape.x2;
  13312. var y1 = inputShape.y1;
  13313. var y2 = inputShape.y2;
  13314. outputShape.x1 = x1;
  13315. outputShape.x2 = x2;
  13316. outputShape.y1 = y1;
  13317. outputShape.y2 = y2;
  13318. var lineWidth = style && style.lineWidth;
  13319. if (!lineWidth) {
  13320. return;
  13321. }
  13322. if (round(x1 * 2) === round(x2 * 2)) {
  13323. outputShape.x1 = outputShape.x2 = subPixelOptimize$1(x1, lineWidth, true);
  13324. }
  13325. if (round(y1 * 2) === round(y2 * 2)) {
  13326. outputShape.y1 = outputShape.y2 = subPixelOptimize$1(y1, lineWidth, true);
  13327. }
  13328. }
  13329. /**
  13330. * Sub pixel optimize rect for canvas
  13331. *
  13332. * @param {Object} outputShape The modification will be performed on `outputShape`.
  13333. * `outputShape` and `inputShape` can be the same object.
  13334. * `outputShape` object can be used repeatly, because all of
  13335. * the `x`, `y`, `width`, `height` will be assigned in this method.
  13336. * @param {Object} [inputShape]
  13337. * @param {number} [inputShape.x]
  13338. * @param {number} [inputShape.y]
  13339. * @param {number} [inputShape.width]
  13340. * @param {number} [inputShape.height]
  13341. * @param {Object} [style]
  13342. * @param {number} [style.lineWidth] If `null`/`undefined`/`0`, do not optimize.
  13343. */
  13344. function subPixelOptimizeRect$1(outputShape, inputShape, style) {
  13345. if (!inputShape) {
  13346. return;
  13347. }
  13348. var originX = inputShape.x;
  13349. var originY = inputShape.y;
  13350. var originWidth = inputShape.width;
  13351. var originHeight = inputShape.height;
  13352. outputShape.x = originX;
  13353. outputShape.y = originY;
  13354. outputShape.width = originWidth;
  13355. outputShape.height = originHeight;
  13356. var lineWidth = style && style.lineWidth;
  13357. if (!lineWidth) {
  13358. return;
  13359. }
  13360. outputShape.x = subPixelOptimize$1(originX, lineWidth, true);
  13361. outputShape.y = subPixelOptimize$1(originY, lineWidth, true);
  13362. outputShape.width = Math.max(subPixelOptimize$1(originX + originWidth, lineWidth, false) - outputShape.x, originWidth === 0 ? 0 : 1);
  13363. outputShape.height = Math.max(subPixelOptimize$1(originY + originHeight, lineWidth, false) - outputShape.y, originHeight === 0 ? 0 : 1);
  13364. }
  13365. /**
  13366. * Sub pixel optimize for canvas
  13367. *
  13368. * @param {number} position Coordinate, such as x, y
  13369. * @param {number} lineWidth If `null`/`undefined`/`0`, do not optimize.
  13370. * @param {boolean=} positiveOrNegative Default false (negative).
  13371. * @return {number} Optimized position.
  13372. */
  13373. function subPixelOptimize$1(position, lineWidth, positiveOrNegative) {
  13374. if (!lineWidth) {
  13375. return position;
  13376. } // Assure that (position + lineWidth / 2) is near integer edge,
  13377. // otherwise line will be fuzzy in canvas.
  13378. var doubledPosition = round(position * 2);
  13379. return (doubledPosition + round(lineWidth)) % 2 === 0 ? doubledPosition / 2 : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  13380. }
  13381. /**
  13382. * 矩形
  13383. * @module zrender/graphic/shape/Rect
  13384. */
  13385. var subPixelOptimizeOutputShape = {};
  13386. var Rect = Path.extend({
  13387. type: 'rect',
  13388. shape: {
  13389. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  13390. // r缩写为1 相当于 [1, 1, 1, 1]
  13391. // r缩写为[1] 相当于 [1, 1, 1, 1]
  13392. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  13393. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  13394. r: 0,
  13395. x: 0,
  13396. y: 0,
  13397. width: 0,
  13398. height: 0
  13399. },
  13400. buildPath: function (ctx, shape) {
  13401. var x;
  13402. var y;
  13403. var width;
  13404. var height;
  13405. if (this.subPixelOptimize) {
  13406. subPixelOptimizeRect$1(subPixelOptimizeOutputShape, shape, this.style);
  13407. x = subPixelOptimizeOutputShape.x;
  13408. y = subPixelOptimizeOutputShape.y;
  13409. width = subPixelOptimizeOutputShape.width;
  13410. height = subPixelOptimizeOutputShape.height;
  13411. subPixelOptimizeOutputShape.r = shape.r;
  13412. shape = subPixelOptimizeOutputShape;
  13413. } else {
  13414. x = shape.x;
  13415. y = shape.y;
  13416. width = shape.width;
  13417. height = shape.height;
  13418. }
  13419. if (!shape.r) {
  13420. ctx.rect(x, y, width, height);
  13421. } else {
  13422. buildPath(ctx, shape);
  13423. }
  13424. ctx.closePath();
  13425. return;
  13426. }
  13427. });
  13428. /**
  13429. * 直线
  13430. * @module zrender/graphic/shape/Line
  13431. */
  13432. var subPixelOptimizeOutputShape$1 = {};
  13433. var Line = Path.extend({
  13434. type: 'line',
  13435. shape: {
  13436. // Start point
  13437. x1: 0,
  13438. y1: 0,
  13439. // End point
  13440. x2: 0,
  13441. y2: 0,
  13442. percent: 1
  13443. },
  13444. style: {
  13445. stroke: '#000',
  13446. fill: null
  13447. },
  13448. buildPath: function (ctx, shape) {
  13449. var x1;
  13450. var y1;
  13451. var x2;
  13452. var y2;
  13453. if (this.subPixelOptimize) {
  13454. subPixelOptimizeLine$1(subPixelOptimizeOutputShape$1, shape, this.style);
  13455. x1 = subPixelOptimizeOutputShape$1.x1;
  13456. y1 = subPixelOptimizeOutputShape$1.y1;
  13457. x2 = subPixelOptimizeOutputShape$1.x2;
  13458. y2 = subPixelOptimizeOutputShape$1.y2;
  13459. } else {
  13460. x1 = shape.x1;
  13461. y1 = shape.y1;
  13462. x2 = shape.x2;
  13463. y2 = shape.y2;
  13464. }
  13465. var percent = shape.percent;
  13466. if (percent === 0) {
  13467. return;
  13468. }
  13469. ctx.moveTo(x1, y1);
  13470. if (percent < 1) {
  13471. x2 = x1 * (1 - percent) + x2 * percent;
  13472. y2 = y1 * (1 - percent) + y2 * percent;
  13473. }
  13474. ctx.lineTo(x2, y2);
  13475. },
  13476. /**
  13477. * Get point at percent
  13478. * @param {number} percent
  13479. * @return {Array.<number>}
  13480. */
  13481. pointAt: function (p) {
  13482. var shape = this.shape;
  13483. return [shape.x1 * (1 - p) + shape.x2 * p, shape.y1 * (1 - p) + shape.y2 * p];
  13484. }
  13485. });
  13486. /**
  13487. * 贝塞尔曲线
  13488. * @module zrender/shape/BezierCurve
  13489. */
  13490. var out = [];
  13491. function someVectorAt(shape, t, isTangent) {
  13492. var cpx2 = shape.cpx2;
  13493. var cpy2 = shape.cpy2;
  13494. if (cpx2 === null || cpy2 === null) {
  13495. 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)];
  13496. } else {
  13497. return [(isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t), (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)];
  13498. }
  13499. }
  13500. var BezierCurve = Path.extend({
  13501. type: 'bezier-curve',
  13502. shape: {
  13503. x1: 0,
  13504. y1: 0,
  13505. x2: 0,
  13506. y2: 0,
  13507. cpx1: 0,
  13508. cpy1: 0,
  13509. // cpx2: 0,
  13510. // cpy2: 0
  13511. // Curve show percent, for animating
  13512. percent: 1
  13513. },
  13514. style: {
  13515. stroke: '#000',
  13516. fill: null
  13517. },
  13518. buildPath: function (ctx, shape) {
  13519. var x1 = shape.x1;
  13520. var y1 = shape.y1;
  13521. var x2 = shape.x2;
  13522. var y2 = shape.y2;
  13523. var cpx1 = shape.cpx1;
  13524. var cpy1 = shape.cpy1;
  13525. var cpx2 = shape.cpx2;
  13526. var cpy2 = shape.cpy2;
  13527. var percent = shape.percent;
  13528. if (percent === 0) {
  13529. return;
  13530. }
  13531. ctx.moveTo(x1, y1);
  13532. if (cpx2 == null || cpy2 == null) {
  13533. if (percent < 1) {
  13534. quadraticSubdivide(x1, cpx1, x2, percent, out);
  13535. cpx1 = out[1];
  13536. x2 = out[2];
  13537. quadraticSubdivide(y1, cpy1, y2, percent, out);
  13538. cpy1 = out[1];
  13539. y2 = out[2];
  13540. }
  13541. ctx.quadraticCurveTo(cpx1, cpy1, x2, y2);
  13542. } else {
  13543. if (percent < 1) {
  13544. cubicSubdivide(x1, cpx1, cpx2, x2, percent, out);
  13545. cpx1 = out[1];
  13546. cpx2 = out[2];
  13547. x2 = out[3];
  13548. cubicSubdivide(y1, cpy1, cpy2, y2, percent, out);
  13549. cpy1 = out[1];
  13550. cpy2 = out[2];
  13551. y2 = out[3];
  13552. }
  13553. ctx.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x2, y2);
  13554. }
  13555. },
  13556. /**
  13557. * Get point at percent
  13558. * @param {number} t
  13559. * @return {Array.<number>}
  13560. */
  13561. pointAt: function (t) {
  13562. return someVectorAt(this.shape, t, false);
  13563. },
  13564. /**
  13565. * Get tangent at percent
  13566. * @param {number} t
  13567. * @return {Array.<number>}
  13568. */
  13569. tangentAt: function (t) {
  13570. var p = someVectorAt(this.shape, t, true);
  13571. return normalize(p, p);
  13572. }
  13573. });
  13574. /**
  13575. * 圆弧
  13576. * @module zrender/graphic/shape/Arc
  13577. */
  13578. var Arc = Path.extend({
  13579. type: 'arc',
  13580. shape: {
  13581. cx: 0,
  13582. cy: 0,
  13583. r: 0,
  13584. startAngle: 0,
  13585. endAngle: Math.PI * 2,
  13586. clockwise: true
  13587. },
  13588. style: {
  13589. stroke: '#000',
  13590. fill: null
  13591. },
  13592. buildPath: function (ctx, shape) {
  13593. var x = shape.cx;
  13594. var y = shape.cy;
  13595. var r = Math.max(shape.r, 0);
  13596. var startAngle = shape.startAngle;
  13597. var endAngle = shape.endAngle;
  13598. var clockwise = shape.clockwise;
  13599. var unitX = Math.cos(startAngle);
  13600. var unitY = Math.sin(startAngle);
  13601. ctx.moveTo(unitX * r + x, unitY * r + y);
  13602. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13603. }
  13604. });
  13605. // CompoundPath to improve performance
  13606. var CompoundPath = Path.extend({
  13607. type: 'compound',
  13608. shape: {
  13609. paths: null
  13610. },
  13611. _updatePathDirty: function () {
  13612. var dirtyPath = this.__dirtyPath;
  13613. var paths = this.shape.paths;
  13614. for (var i = 0; i < paths.length; i++) {
  13615. // Mark as dirty if any subpath is dirty
  13616. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  13617. }
  13618. this.__dirtyPath = dirtyPath;
  13619. this.__dirty = this.__dirty || dirtyPath;
  13620. },
  13621. beforeBrush: function () {
  13622. this._updatePathDirty();
  13623. var paths = this.shape.paths || [];
  13624. var scale = this.getGlobalScale(); // Update path scale
  13625. for (var i = 0; i < paths.length; i++) {
  13626. if (!paths[i].path) {
  13627. paths[i].createPathProxy();
  13628. }
  13629. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  13630. }
  13631. },
  13632. buildPath: function (ctx, shape) {
  13633. var paths = shape.paths || [];
  13634. for (var i = 0; i < paths.length; i++) {
  13635. paths[i].buildPath(ctx, paths[i].shape, true);
  13636. }
  13637. },
  13638. afterBrush: function () {
  13639. var paths = this.shape.paths || [];
  13640. for (var i = 0; i < paths.length; i++) {
  13641. paths[i].__dirtyPath = false;
  13642. }
  13643. },
  13644. getBoundingRect: function () {
  13645. this._updatePathDirty();
  13646. return Path.prototype.getBoundingRect.call(this);
  13647. }
  13648. });
  13649. /**
  13650. * @param {Array.<Object>} colorStops
  13651. */
  13652. var Gradient = function (colorStops) {
  13653. this.colorStops = colorStops || [];
  13654. };
  13655. Gradient.prototype = {
  13656. constructor: Gradient,
  13657. addColorStop: function (offset, color) {
  13658. this.colorStops.push({
  13659. offset: offset,
  13660. color: color
  13661. });
  13662. }
  13663. };
  13664. /**
  13665. * x, y, x2, y2 are all percent from 0 to 1
  13666. * @param {number} [x=0]
  13667. * @param {number} [y=0]
  13668. * @param {number} [x2=1]
  13669. * @param {number} [y2=0]
  13670. * @param {Array.<Object>} colorStops
  13671. * @param {boolean} [globalCoord=false]
  13672. */
  13673. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  13674. // Should do nothing more in this constructor. Because gradient can be
  13675. // declard by `color: {type: 'linear', colorStops: ...}`, where
  13676. // this constructor will not be called.
  13677. this.x = x == null ? 0 : x;
  13678. this.y = y == null ? 0 : y;
  13679. this.x2 = x2 == null ? 1 : x2;
  13680. this.y2 = y2 == null ? 0 : y2; // Can be cloned
  13681. this.type = 'linear'; // If use global coord
  13682. this.global = globalCoord || false;
  13683. Gradient.call(this, colorStops);
  13684. };
  13685. LinearGradient.prototype = {
  13686. constructor: LinearGradient
  13687. };
  13688. inherits(LinearGradient, Gradient);
  13689. /**
  13690. * x, y, r are all percent from 0 to 1
  13691. * @param {number} [x=0.5]
  13692. * @param {number} [y=0.5]
  13693. * @param {number} [r=0.5]
  13694. * @param {Array.<Object>} [colorStops]
  13695. * @param {boolean} [globalCoord=false]
  13696. */
  13697. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  13698. // Should do nothing more in this constructor. Because gradient can be
  13699. // declard by `color: {type: 'radial', colorStops: ...}`, where
  13700. // this constructor will not be called.
  13701. this.x = x == null ? 0.5 : x;
  13702. this.y = y == null ? 0.5 : y;
  13703. this.r = r == null ? 0.5 : r; // Can be cloned
  13704. this.type = 'radial'; // If use global coord
  13705. this.global = globalCoord || false;
  13706. Gradient.call(this, colorStops);
  13707. };
  13708. RadialGradient.prototype = {
  13709. constructor: RadialGradient
  13710. };
  13711. inherits(RadialGradient, Gradient);
  13712. /**
  13713. * Displayable for incremental rendering. It will be rendered in a separate layer
  13714. * IncrementalDisplay have two main methods. `clearDisplayables` and `addDisplayables`
  13715. * addDisplayables will render the added displayables incremetally.
  13716. *
  13717. * It use a not clearFlag to tell the painter don't clear the layer if it's the first element.
  13718. */
  13719. function IncrementalDisplayble(opts) {
  13720. Displayable.call(this, opts);
  13721. this._displayables = [];
  13722. this._temporaryDisplayables = [];
  13723. this._cursor = 0;
  13724. this.notClear = true;
  13725. }
  13726. IncrementalDisplayble.prototype.incremental = true;
  13727. IncrementalDisplayble.prototype.clearDisplaybles = function () {
  13728. this._displayables = [];
  13729. this._temporaryDisplayables = [];
  13730. this._cursor = 0;
  13731. this.dirty();
  13732. this.notClear = false;
  13733. };
  13734. IncrementalDisplayble.prototype.addDisplayable = function (displayable, notPersistent) {
  13735. if (notPersistent) {
  13736. this._temporaryDisplayables.push(displayable);
  13737. } else {
  13738. this._displayables.push(displayable);
  13739. }
  13740. this.dirty();
  13741. };
  13742. IncrementalDisplayble.prototype.addDisplayables = function (displayables, notPersistent) {
  13743. notPersistent = notPersistent || false;
  13744. for (var i = 0; i < displayables.length; i++) {
  13745. this.addDisplayable(displayables[i], notPersistent);
  13746. }
  13747. };
  13748. IncrementalDisplayble.prototype.eachPendingDisplayable = function (cb) {
  13749. for (var i = this._cursor; i < this._displayables.length; i++) {
  13750. cb && cb(this._displayables[i]);
  13751. }
  13752. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13753. cb && cb(this._temporaryDisplayables[i]);
  13754. }
  13755. };
  13756. IncrementalDisplayble.prototype.update = function () {
  13757. this.updateTransform();
  13758. for (var i = this._cursor; i < this._displayables.length; i++) {
  13759. var displayable = this._displayables[i]; // PENDING
  13760. displayable.parent = this;
  13761. displayable.update();
  13762. displayable.parent = null;
  13763. }
  13764. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13765. var displayable = this._temporaryDisplayables[i]; // PENDING
  13766. displayable.parent = this;
  13767. displayable.update();
  13768. displayable.parent = null;
  13769. }
  13770. };
  13771. IncrementalDisplayble.prototype.brush = function (ctx, prevEl) {
  13772. // Render persistant displayables.
  13773. for (var i = this._cursor; i < this._displayables.length; i++) {
  13774. var displayable = this._displayables[i];
  13775. displayable.beforeBrush && displayable.beforeBrush(ctx);
  13776. displayable.brush(ctx, i === this._cursor ? null : this._displayables[i - 1]);
  13777. displayable.afterBrush && displayable.afterBrush(ctx);
  13778. }
  13779. this._cursor = i; // Render temporary displayables.
  13780. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  13781. var displayable = this._temporaryDisplayables[i];
  13782. displayable.beforeBrush && displayable.beforeBrush(ctx);
  13783. displayable.brush(ctx, i === 0 ? null : this._temporaryDisplayables[i - 1]);
  13784. displayable.afterBrush && displayable.afterBrush(ctx);
  13785. }
  13786. this._temporaryDisplayables = [];
  13787. this.notClear = true;
  13788. };
  13789. var m = [];
  13790. IncrementalDisplayble.prototype.getBoundingRect = function () {
  13791. if (!this._rect) {
  13792. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  13793. for (var i = 0; i < this._displayables.length; i++) {
  13794. var displayable = this._displayables[i];
  13795. var childRect = displayable.getBoundingRect().clone();
  13796. if (displayable.needLocalTransform()) {
  13797. childRect.applyTransform(displayable.getLocalTransform(m));
  13798. }
  13799. rect.union(childRect);
  13800. }
  13801. this._rect = rect;
  13802. }
  13803. return this._rect;
  13804. };
  13805. IncrementalDisplayble.prototype.contain = function (x, y) {
  13806. var localPos = this.transformCoordToLocal(x, y);
  13807. var rect = this.getBoundingRect();
  13808. if (rect.contain(localPos[0], localPos[1])) {
  13809. for (var i = 0; i < this._displayables.length; i++) {
  13810. var displayable = this._displayables[i];
  13811. if (displayable.contain(x, y)) {
  13812. return true;
  13813. }
  13814. }
  13815. }
  13816. return false;
  13817. };
  13818. inherits(IncrementalDisplayble, Displayable);
  13819. /*
  13820. * Licensed to the Apache Software Foundation (ASF) under one
  13821. * or more contributor license agreements. See the NOTICE file
  13822. * distributed with this work for additional information
  13823. * regarding copyright ownership. The ASF licenses this file
  13824. * to you under the Apache License, Version 2.0 (the
  13825. * "License"); you may not use this file except in compliance
  13826. * with the License. You may obtain a copy of the License at
  13827. *
  13828. * http://www.apache.org/licenses/LICENSE-2.0
  13829. *
  13830. * Unless required by applicable law or agreed to in writing,
  13831. * software distributed under the License is distributed on an
  13832. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13833. * KIND, either express or implied. See the License for the
  13834. * specific language governing permissions and limitations
  13835. * under the License.
  13836. */
  13837. var mathMax$1 = Math.max;
  13838. var mathMin$1 = Math.min;
  13839. var EMPTY_OBJ = {};
  13840. var Z2_EMPHASIS_LIFT = 1; // key: label model property nane, value: style property name.
  13841. var CACHED_LABEL_STYLE_PROPERTIES = {
  13842. color: 'textFill',
  13843. textBorderColor: 'textStroke',
  13844. textBorderWidth: 'textStrokeWidth'
  13845. };
  13846. var EMPHASIS = 'emphasis';
  13847. var NORMAL = 'normal'; // Reserve 0 as default.
  13848. var _highlightNextDigit = 1;
  13849. var _highlightKeyMap = {};
  13850. var _customShapeMap = {};
  13851. /**
  13852. * Extend shape with parameters
  13853. */
  13854. function extendShape(opts) {
  13855. return Path.extend(opts);
  13856. }
  13857. /**
  13858. * Extend path
  13859. */
  13860. function extendPath(pathData, opts) {
  13861. return extendFromString(pathData, opts);
  13862. }
  13863. /**
  13864. * Register a user defined shape.
  13865. * The shape class can be fetched by `getShapeClass`
  13866. * This method will overwrite the registered shapes, including
  13867. * the registered built-in shapes, if using the same `name`.
  13868. * The shape can be used in `custom series` and
  13869. * `graphic component` by declaring `{type: name}`.
  13870. *
  13871. * @param {string} name
  13872. * @param {Object} ShapeClass Can be generated by `extendShape`.
  13873. */
  13874. function registerShape(name, ShapeClass) {
  13875. _customShapeMap[name] = ShapeClass;
  13876. }
  13877. /**
  13878. * Find shape class registered by `registerShape`. Usually used in
  13879. * fetching user defined shape.
  13880. *
  13881. * [Caution]:
  13882. * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared
  13883. * to use user registered shapes.
  13884. * Because the built-in shape (see `getBuiltInShape`) will be registered by
  13885. * `registerShape` by default. That enables users to get both built-in
  13886. * shapes as well as the shapes belonging to themsleves. But users can overwrite
  13887. * the built-in shapes by using names like 'circle', 'rect' via calling
  13888. * `registerShape`. So the echarts inner featrues should not fetch shapes from here
  13889. * in case that it is overwritten by users, except that some features, like
  13890. * `custom series`, `graphic component`, do it deliberately.
  13891. *
  13892. * (2) In the features like `custom series`, `graphic component`, the user input
  13893. * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic
  13894. * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names
  13895. * are reserved names, that is, if some user register a shape named `'image'`,
  13896. * the shape will not be used. If we intending to add some more reserved names
  13897. * in feature, that might bring break changes (disable some existing user shape
  13898. * names). But that case probably rearly happen. So we dont make more mechanism
  13899. * to resolve this issue here.
  13900. *
  13901. * @param {string} name
  13902. * @return {Object} The shape class. If not found, return nothing.
  13903. */
  13904. function getShapeClass(name) {
  13905. if (_customShapeMap.hasOwnProperty(name)) {
  13906. return _customShapeMap[name];
  13907. }
  13908. }
  13909. /**
  13910. * Create a path element from path data string
  13911. * @param {string} pathData
  13912. * @param {Object} opts
  13913. * @param {module:zrender/core/BoundingRect} rect
  13914. * @param {string} [layout=cover] 'center' or 'cover'
  13915. */
  13916. function makePath(pathData, opts, rect, layout) {
  13917. var path = createFromString(pathData, opts);
  13918. if (rect) {
  13919. if (layout === 'center') {
  13920. rect = centerGraphic(rect, path.getBoundingRect());
  13921. }
  13922. resizePath(path, rect);
  13923. }
  13924. return path;
  13925. }
  13926. /**
  13927. * Create a image element from image url
  13928. * @param {string} imageUrl image url
  13929. * @param {Object} opts options
  13930. * @param {module:zrender/core/BoundingRect} rect constrain rect
  13931. * @param {string} [layout=cover] 'center' or 'cover'
  13932. */
  13933. function makeImage(imageUrl, rect, layout) {
  13934. var path = new ZImage({
  13935. style: {
  13936. image: imageUrl,
  13937. x: rect.x,
  13938. y: rect.y,
  13939. width: rect.width,
  13940. height: rect.height
  13941. },
  13942. onload: function (img) {
  13943. if (layout === 'center') {
  13944. var boundingRect = {
  13945. width: img.width,
  13946. height: img.height
  13947. };
  13948. path.setStyle(centerGraphic(rect, boundingRect));
  13949. }
  13950. }
  13951. });
  13952. return path;
  13953. }
  13954. /**
  13955. * Get position of centered element in bounding box.
  13956. *
  13957. * @param {Object} rect element local bounding box
  13958. * @param {Object} boundingRect constraint bounding box
  13959. * @return {Object} element position containing x, y, width, and height
  13960. */
  13961. function centerGraphic(rect, boundingRect) {
  13962. // Set rect to center, keep width / height ratio.
  13963. var aspect = boundingRect.width / boundingRect.height;
  13964. var width = rect.height * aspect;
  13965. var height;
  13966. if (width <= rect.width) {
  13967. height = rect.height;
  13968. } else {
  13969. width = rect.width;
  13970. height = width / aspect;
  13971. }
  13972. var cx = rect.x + rect.width / 2;
  13973. var cy = rect.y + rect.height / 2;
  13974. return {
  13975. x: cx - width / 2,
  13976. y: cy - height / 2,
  13977. width: width,
  13978. height: height
  13979. };
  13980. }
  13981. var mergePath = mergePath$1;
  13982. /**
  13983. * Resize a path to fit the rect
  13984. * @param {module:zrender/graphic/Path} path
  13985. * @param {Object} rect
  13986. */
  13987. function resizePath(path, rect) {
  13988. if (!path.applyTransform) {
  13989. return;
  13990. }
  13991. var pathRect = path.getBoundingRect();
  13992. var m = pathRect.calculateTransform(rect);
  13993. path.applyTransform(m);
  13994. }
  13995. /**
  13996. * Sub pixel optimize line for canvas
  13997. *
  13998. * @param {Object} param
  13999. * @param {Object} [param.shape]
  14000. * @param {number} [param.shape.x1]
  14001. * @param {number} [param.shape.y1]
  14002. * @param {number} [param.shape.x2]
  14003. * @param {number} [param.shape.y2]
  14004. * @param {Object} [param.style]
  14005. * @param {number} [param.style.lineWidth]
  14006. * @return {Object} Modified param
  14007. */
  14008. function subPixelOptimizeLine(param) {
  14009. subPixelOptimizeLine$1(param.shape, param.shape, param.style);
  14010. return param;
  14011. }
  14012. /**
  14013. * Sub pixel optimize rect for canvas
  14014. *
  14015. * @param {Object} param
  14016. * @param {Object} [param.shape]
  14017. * @param {number} [param.shape.x]
  14018. * @param {number} [param.shape.y]
  14019. * @param {number} [param.shape.width]
  14020. * @param {number} [param.shape.height]
  14021. * @param {Object} [param.style]
  14022. * @param {number} [param.style.lineWidth]
  14023. * @return {Object} Modified param
  14024. */
  14025. function subPixelOptimizeRect(param) {
  14026. subPixelOptimizeRect$1(param.shape, param.shape, param.style);
  14027. return param;
  14028. }
  14029. /**
  14030. * Sub pixel optimize for canvas
  14031. *
  14032. * @param {number} position Coordinate, such as x, y
  14033. * @param {number} lineWidth Should be nonnegative integer.
  14034. * @param {boolean=} positiveOrNegative Default false (negative).
  14035. * @return {number} Optimized position.
  14036. */
  14037. var subPixelOptimize = subPixelOptimize$1;
  14038. function hasFillOrStroke(fillOrStroke) {
  14039. return fillOrStroke != null && fillOrStroke !== 'none';
  14040. } // Most lifted color are duplicated.
  14041. var liftedColorMap = createHashMap();
  14042. var liftedColorCount = 0;
  14043. function liftColor(color) {
  14044. if (typeof color !== 'string') {
  14045. return color;
  14046. }
  14047. var liftedColor = liftedColorMap.get(color);
  14048. if (!liftedColor) {
  14049. liftedColor = lift(color, -0.1);
  14050. if (liftedColorCount < 10000) {
  14051. liftedColorMap.set(color, liftedColor);
  14052. liftedColorCount++;
  14053. }
  14054. }
  14055. return liftedColor;
  14056. }
  14057. function cacheElementStl(el) {
  14058. if (!el.__hoverStlDirty) {
  14059. return;
  14060. }
  14061. el.__hoverStlDirty = false;
  14062. var hoverStyle = el.__hoverStl;
  14063. if (!hoverStyle) {
  14064. el.__cachedNormalStl = el.__cachedNormalZ2 = null;
  14065. return;
  14066. }
  14067. var normalStyle = el.__cachedNormalStl = {};
  14068. el.__cachedNormalZ2 = el.z2;
  14069. var elStyle = el.style;
  14070. for (var name in hoverStyle) {
  14071. // See comment in `singleEnterEmphasis`.
  14072. if (hoverStyle[name] != null) {
  14073. normalStyle[name] = elStyle[name];
  14074. }
  14075. } // Always cache fill and stroke to normalStyle for lifting color.
  14076. normalStyle.fill = elStyle.fill;
  14077. normalStyle.stroke = elStyle.stroke;
  14078. }
  14079. function singleEnterEmphasis(el) {
  14080. var hoverStl = el.__hoverStl;
  14081. if (!hoverStl || el.__highlighted) {
  14082. return;
  14083. }
  14084. var zr = el.__zr;
  14085. var useHoverLayer = el.useHoverLayer && zr && zr.painter.type === 'canvas';
  14086. el.__highlighted = useHoverLayer ? 'layer' : 'plain';
  14087. if (el.isGroup || !zr && el.useHoverLayer) {
  14088. return;
  14089. }
  14090. var elTarget = el;
  14091. var targetStyle = el.style;
  14092. if (useHoverLayer) {
  14093. elTarget = zr.addHover(el);
  14094. targetStyle = elTarget.style;
  14095. }
  14096. rollbackDefaultTextStyle(targetStyle);
  14097. if (!useHoverLayer) {
  14098. cacheElementStl(elTarget);
  14099. } // styles can be:
  14100. // {
  14101. // label: {
  14102. // show: false,
  14103. // position: 'outside',
  14104. // fontSize: 18
  14105. // },
  14106. // emphasis: {
  14107. // label: {
  14108. // show: true
  14109. // }
  14110. // }
  14111. // },
  14112. // where properties of `emphasis` may not appear in `normal`. We previously use
  14113. // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.
  14114. // But consider rich text and setOption in merge mode, it is impossible to cover
  14115. // all properties in merge. So we use merge mode when setting style here.
  14116. // But we choose the merge strategy that only properties that is not `null/undefined`.
  14117. // Because when making a textStyle (espacially rich text), it is not easy to distinguish
  14118. // `hasOwnProperty` and `null/undefined` in code, so we trade them as the same for simplicity.
  14119. // But this strategy brings a trouble that `null/undefined` can not be used to remove
  14120. // style any more in `emphasis`. Users can both set properties directly on normal and
  14121. // emphasis to avoid this issue, or we might support `'none'` for this case if required.
  14122. targetStyle.extendFrom(hoverStl);
  14123. setDefaultHoverFillStroke(targetStyle, hoverStl, 'fill');
  14124. setDefaultHoverFillStroke(targetStyle, hoverStl, 'stroke');
  14125. applyDefaultTextStyle(targetStyle);
  14126. if (!useHoverLayer) {
  14127. el.dirty(false);
  14128. el.z2 += Z2_EMPHASIS_LIFT;
  14129. }
  14130. }
  14131. function setDefaultHoverFillStroke(targetStyle, hoverStyle, prop) {
  14132. if (!hasFillOrStroke(hoverStyle[prop]) && hasFillOrStroke(targetStyle[prop])) {
  14133. targetStyle[prop] = liftColor(targetStyle[prop]);
  14134. }
  14135. }
  14136. function singleEnterNormal(el) {
  14137. var highlighted = el.__highlighted;
  14138. if (!highlighted) {
  14139. return;
  14140. }
  14141. el.__highlighted = false;
  14142. if (el.isGroup) {
  14143. return;
  14144. }
  14145. if (highlighted === 'layer') {
  14146. el.__zr && el.__zr.removeHover(el);
  14147. } else {
  14148. var style = el.style;
  14149. var normalStl = el.__cachedNormalStl;
  14150. if (normalStl) {
  14151. rollbackDefaultTextStyle(style);
  14152. el.setStyle(normalStl);
  14153. applyDefaultTextStyle(style);
  14154. } // `__cachedNormalZ2` will not be reset if calling `setElementHoverStyle`
  14155. // when `el` is on emphasis state. So here by comparing with 1, we try
  14156. // hard to make the bug case rare.
  14157. var normalZ2 = el.__cachedNormalZ2;
  14158. if (normalZ2 != null && el.z2 - normalZ2 === Z2_EMPHASIS_LIFT) {
  14159. el.z2 = normalZ2;
  14160. }
  14161. }
  14162. }
  14163. function traverseUpdate(el, updater, commonParam) {
  14164. // If root is group, also enter updater for `highDownOnUpdate`.
  14165. var fromState = NORMAL;
  14166. var toState = NORMAL;
  14167. var trigger; // See the rule of `highDownOnUpdate` on `graphic.setAsHighDownDispatcher`.
  14168. el.__highlighted && (fromState = EMPHASIS, trigger = true);
  14169. updater(el, commonParam);
  14170. el.__highlighted && (toState = EMPHASIS, trigger = true);
  14171. el.isGroup && el.traverse(function (child) {
  14172. !child.isGroup && updater(child, commonParam);
  14173. });
  14174. trigger && el.__highDownOnUpdate && el.__highDownOnUpdate(fromState, toState);
  14175. }
  14176. /**
  14177. * Set hover style (namely "emphasis style") of element, based on the current
  14178. * style of the given `el`.
  14179. * This method should be called after all of the normal styles have been adopted
  14180. * to the `el`. See the reason on `setHoverStyle`.
  14181. *
  14182. * @param {module:zrender/Element} el Should not be `zrender/container/Group`.
  14183. * @param {Object} [el.hoverStyle] Can be set on el or its descendants,
  14184. * e.g., `el.hoverStyle = ...; graphic.setHoverStyle(el); `.
  14185. * Often used when item group has a label element and it's hoverStyle is different.
  14186. * @param {Object|boolean} [hoverStl] The specified hover style.
  14187. * If set as `false`, disable the hover style.
  14188. * Similarly, The `el.hoverStyle` can alse be set
  14189. * as `false` to disable the hover style.
  14190. * Otherwise, use the default hover style if not provided.
  14191. */
  14192. function setElementHoverStyle(el, hoverStl) {
  14193. // For performance consideration, it might be better to make the "hover style" only the
  14194. // difference properties from the "normal style", but not a entire copy of all styles.
  14195. hoverStl = el.__hoverStl = hoverStl !== false && (el.hoverStyle || hoverStl || {});
  14196. el.__hoverStlDirty = true; // FIXME
  14197. // It is not completely right to save "normal"/"emphasis" flag on elements.
  14198. // It probably should be saved on `data` of series. Consider the cases:
  14199. // (1) A highlighted elements are moved out of the view port and re-enter
  14200. // again by dataZoom.
  14201. // (2) call `setOption` and replace elements totally when they are highlighted.
  14202. if (el.__highlighted) {
  14203. // Consider the case:
  14204. // The styles of a highlighted `el` is being updated. The new "emphasis style"
  14205. // should be adapted to the `el`. Notice here new "normal styles" should have
  14206. // been set outside and the cached "normal style" is out of date.
  14207. el.__cachedNormalStl = null; // Do not clear `__cachedNormalZ2` here, because setting `z2` is not a constraint
  14208. // of this method. In most cases, `z2` is not set and hover style should be able
  14209. // to rollback. Of course, that would bring bug, but only in a rare case, see
  14210. // `doSingleLeaveHover` for details.
  14211. singleEnterNormal(el);
  14212. singleEnterEmphasis(el);
  14213. }
  14214. }
  14215. function onElementMouseOver(e) {
  14216. !shouldSilent(this, e) // "emphasis" event highlight has higher priority than mouse highlight.
  14217. && !this.__highByOuter && traverseUpdate(this, singleEnterEmphasis);
  14218. }
  14219. function onElementMouseOut(e) {
  14220. !shouldSilent(this, e) // "emphasis" event highlight has higher priority than mouse highlight.
  14221. && !this.__highByOuter && traverseUpdate(this, singleEnterNormal);
  14222. }
  14223. function onElementEmphasisEvent(highlightDigit) {
  14224. this.__highByOuter |= 1 << (highlightDigit || 0);
  14225. traverseUpdate(this, singleEnterEmphasis);
  14226. }
  14227. function onElementNormalEvent(highlightDigit) {
  14228. !(this.__highByOuter &= ~(1 << (highlightDigit || 0))) && traverseUpdate(this, singleEnterNormal);
  14229. }
  14230. function shouldSilent(el, e) {
  14231. return el.__highDownSilentOnTouch && e.zrByTouch;
  14232. }
  14233. /**
  14234. * Set hover style (namely "emphasis style") of element,
  14235. * based on the current style of the given `el`.
  14236. *
  14237. * (1)
  14238. * **CONSTRAINTS** for this method:
  14239. * <A> This method MUST be called after all of the normal styles having been adopted
  14240. * to the `el`.
  14241. * <B> The input `hoverStyle` (that is, "emphasis style") MUST be the subset of the
  14242. * "normal style" having been set to the el.
  14243. * <C> `color` MUST be one of the "normal styles" (because color might be lifted as
  14244. * a default hover style).
  14245. *
  14246. * The reason: this method treat the current style of the `el` as the "normal style"
  14247. * and cache them when enter/update the "emphasis style". Consider the case: the `el`
  14248. * is in "emphasis" state and `setOption`/`dispatchAction` trigger the style updating
  14249. * logic, where the el should shift from the original emphasis style to the new
  14250. * "emphasis style" and should be able to "downplay" back to the new "normal style".
  14251. *
  14252. * Indeed, it is error-prone to make a interface has so many constraints, but I have
  14253. * not found a better solution yet to fit the backward compatibility, performance and
  14254. * the current programming style.
  14255. *
  14256. * (2)
  14257. * Call the method for a "root" element once. Do not call it for each descendants.
  14258. * If the descendants elemenets of a group has itself hover style different from the
  14259. * root group, we can simply mount the style on `el.hoverStyle` for them, but should
  14260. * not call this method for them.
  14261. *
  14262. * (3) These input parameters can be set directly on `el`:
  14263. *
  14264. * @param {module:zrender/Element} el
  14265. * @param {Object} [el.hoverStyle] See `graphic.setElementHoverStyle`.
  14266. * @param {boolean} [el.highDownSilentOnTouch=false] See `graphic.setAsHighDownDispatcher`.
  14267. * @param {Function} [el.highDownOnUpdate] See `graphic.setAsHighDownDispatcher`.
  14268. * @param {Object|boolean} [hoverStyle] See `graphic.setElementHoverStyle`.
  14269. */
  14270. function setHoverStyle(el, hoverStyle) {
  14271. setAsHighDownDispatcher(el, true);
  14272. traverseUpdate(el, setElementHoverStyle, hoverStyle);
  14273. }
  14274. /**
  14275. * @param {module:zrender/Element} el
  14276. * @param {Function} [el.highDownOnUpdate] Called when state updated.
  14277. * Since `setHoverStyle` has the constraint that it must be called after
  14278. * all of the normal style updated, `highDownOnUpdate` is not needed to
  14279. * trigger if both `fromState` and `toState` is 'normal', and needed to
  14280. * trigger if both `fromState` and `toState` is 'emphasis', which enables
  14281. * to sync outside style settings to "emphasis" state.
  14282. * @this {string} This dispatcher `el`.
  14283. * @param {string} fromState Can be "normal" or "emphasis".
  14284. * `fromState` might equal to `toState`,
  14285. * for example, when this method is called when `el` is
  14286. * on "emphasis" state.
  14287. * @param {string} toState Can be "normal" or "emphasis".
  14288. *
  14289. * FIXME
  14290. * CAUTION: Do not expose `highDownOnUpdate` outside echarts.
  14291. * Because it is not a complete solution. The update
  14292. * listener should not have been mount in element,
  14293. * and the normal/emphasis state should not have
  14294. * mantained on elements.
  14295. *
  14296. * @param {boolean} [el.highDownSilentOnTouch=false]
  14297. * In touch device, mouseover event will be trigger on touchstart event
  14298. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  14299. * conveniently use hoverStyle when tap on touch screen without additional
  14300. * code for compatibility.
  14301. * But if the chart/component has select feature, which usually also use
  14302. * hoverStyle, there might be conflict between 'select-highlight' and
  14303. * 'hover-highlight' especially when roam is enabled (see geo for example).
  14304. * In this case, `highDownSilentOnTouch` should be used to disable
  14305. * hover-highlight on touch device.
  14306. * @param {boolean} [asDispatcher=true] If `false`, do not set as "highDownDispatcher".
  14307. */
  14308. function setAsHighDownDispatcher(el, asDispatcher) {
  14309. var disable = asDispatcher === false; // Make `highDownSilentOnTouch` and `highDownOnUpdate` only work after
  14310. // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.
  14311. el.__highDownSilentOnTouch = el.highDownSilentOnTouch;
  14312. el.__highDownOnUpdate = el.highDownOnUpdate; // Simple optimize, since this method might be
  14313. // called for each elements of a group in some cases.
  14314. if (!disable || el.__highDownDispatcher) {
  14315. var method = disable ? 'off' : 'on'; // Duplicated function will be auto-ignored, see Eventful.js.
  14316. el[method]('mouseover', onElementMouseOver)[method]('mouseout', onElementMouseOut); // Emphasis, normal can be triggered manually by API or other components like hover link.
  14317. el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent); // Also keep previous record.
  14318. el.__highByOuter = el.__highByOuter || 0;
  14319. el.__highDownDispatcher = !disable;
  14320. }
  14321. }
  14322. /**
  14323. * @param {module:zrender/src/Element} el
  14324. * @return {boolean}
  14325. */
  14326. function isHighDownDispatcher(el) {
  14327. return !!(el && el.__highDownDispatcher);
  14328. }
  14329. /**
  14330. * Support hightlight/downplay record on each elements.
  14331. * For the case: hover highlight/downplay (legend, visualMap, ...) and
  14332. * user triggerred hightlight/downplay should not conflict.
  14333. * Only all of the highlightDigit cleared, return to normal.
  14334. * @param {string} highlightKey
  14335. * @return {number} highlightDigit
  14336. */
  14337. function getHighlightDigit(highlightKey) {
  14338. var highlightDigit = _highlightKeyMap[highlightKey];
  14339. if (highlightDigit == null && _highlightNextDigit <= 32) {
  14340. highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;
  14341. }
  14342. return highlightDigit;
  14343. }
  14344. /**
  14345. * See more info in `setTextStyleCommon`.
  14346. * @param {Object|module:zrender/graphic/Style} normalStyle
  14347. * @param {Object} emphasisStyle
  14348. * @param {module:echarts/model/Model} normalModel
  14349. * @param {module:echarts/model/Model} emphasisModel
  14350. * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.
  14351. * @param {string|Function} [opt.defaultText]
  14352. * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by
  14353. * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14354. * @param {number} [opt.labelDataIndex] Fetch text by
  14355. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14356. * @param {number} [opt.labelDimIndex] Fetch text by
  14357. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14358. * @param {string} [opt.labelProp] Fetch text by
  14359. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex, opt.labelProp)`
  14360. * @param {Object} [normalSpecified]
  14361. * @param {Object} [emphasisSpecified]
  14362. */
  14363. function setLabelStyle(normalStyle, emphasisStyle, normalModel, emphasisModel, opt, normalSpecified, emphasisSpecified) {
  14364. opt = opt || EMPTY_OBJ;
  14365. var labelFetcher = opt.labelFetcher;
  14366. var labelDataIndex = opt.labelDataIndex;
  14367. var labelDimIndex = opt.labelDimIndex;
  14368. var labelProp = opt.labelProp; // This scenario, `label.normal.show = true; label.emphasis.show = false`,
  14369. // is not supported util someone requests.
  14370. var showNormal = normalModel.getShallow('show');
  14371. var showEmphasis = emphasisModel.getShallow('show'); // Consider performance, only fetch label when necessary.
  14372. // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,
  14373. // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.
  14374. var baseText;
  14375. if (showNormal || showEmphasis) {
  14376. if (labelFetcher) {
  14377. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex, labelProp);
  14378. }
  14379. if (baseText == null) {
  14380. baseText = isFunction$1(opt.defaultText) ? opt.defaultText(labelDataIndex, opt) : opt.defaultText;
  14381. }
  14382. }
  14383. var normalStyleText = showNormal ? baseText : null;
  14384. 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.
  14385. if (normalStyleText != null || emphasisStyleText != null) {
  14386. // Always set `textStyle` even if `normalStyle.text` is null, because default
  14387. // values have to be set on `normalStyle`.
  14388. // If we set default values on `emphasisStyle`, consider case:
  14389. // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`
  14390. // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`
  14391. // Then the 'red' will not work on emphasis.
  14392. setTextStyle(normalStyle, normalModel, normalSpecified, opt);
  14393. setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);
  14394. }
  14395. normalStyle.text = normalStyleText;
  14396. emphasisStyle.text = emphasisStyleText;
  14397. }
  14398. /**
  14399. * Modify label style manually.
  14400. * Only works after `setLabelStyle` and `setElementHoverStyle` called.
  14401. *
  14402. * @param {module:zrender/src/Element} el
  14403. * @param {Object} [normalStyleProps] optional
  14404. * @param {Object} [emphasisStyleProps] optional
  14405. */
  14406. function modifyLabelStyle(el, normalStyleProps, emphasisStyleProps) {
  14407. var elStyle = el.style;
  14408. if (normalStyleProps) {
  14409. rollbackDefaultTextStyle(elStyle);
  14410. el.setStyle(normalStyleProps);
  14411. applyDefaultTextStyle(elStyle);
  14412. }
  14413. elStyle = el.__hoverStl;
  14414. if (emphasisStyleProps && elStyle) {
  14415. rollbackDefaultTextStyle(elStyle);
  14416. extend(elStyle, emphasisStyleProps);
  14417. applyDefaultTextStyle(elStyle);
  14418. }
  14419. }
  14420. /**
  14421. * Set basic textStyle properties.
  14422. * See more info in `setTextStyleCommon`.
  14423. * @param {Object|module:zrender/graphic/Style} textStyle
  14424. * @param {module:echarts/model/Model} model
  14425. * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.
  14426. * @param {Object} [opt] See `opt` of `setTextStyleCommon`.
  14427. * @param {boolean} [isEmphasis]
  14428. */
  14429. function setTextStyle(textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis) {
  14430. setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);
  14431. specifiedTextStyle && extend(textStyle, specifiedTextStyle); // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14432. return textStyle;
  14433. }
  14434. /**
  14435. * Set text option in the style.
  14436. * See more info in `setTextStyleCommon`.
  14437. * @deprecated
  14438. * @param {Object} textStyle
  14439. * @param {module:echarts/model/Model} labelModel
  14440. * @param {string|boolean} defaultColor Default text color.
  14441. * If set as false, it will be processed as a emphasis style.
  14442. */
  14443. function setText(textStyle, labelModel, defaultColor) {
  14444. var opt = {
  14445. isRectText: true
  14446. };
  14447. var isEmphasis;
  14448. if (defaultColor === false) {
  14449. isEmphasis = true;
  14450. } else {
  14451. // Support setting color as 'auto' to get visual color.
  14452. opt.autoColor = defaultColor;
  14453. }
  14454. setTextStyleCommon(textStyle, labelModel, opt, isEmphasis); // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  14455. }
  14456. /**
  14457. * The uniform entry of set text style, that is, retrieve style definitions
  14458. * from `model` and set to `textStyle` object.
  14459. *
  14460. * Never in merge mode, but in overwrite mode, that is, all of the text style
  14461. * properties will be set. (Consider the states of normal and emphasis and
  14462. * default value can be adopted, merge would make the logic too complicated
  14463. * to manage.)
  14464. *
  14465. * The `textStyle` object can either be a plain object or an instance of
  14466. * `zrender/src/graphic/Style`, and either be the style of normal or emphasis.
  14467. * After this mothod called, the `textStyle` object can then be used in
  14468. * `el.setStyle(textStyle)` or `el.hoverStyle = textStyle`.
  14469. *
  14470. * Default value will be adopted and `insideRollbackOpt` will be created.
  14471. * See `applyDefaultTextStyle` `rollbackDefaultTextStyle` for more details.
  14472. *
  14473. * opt: {
  14474. * disableBox: boolean, Whether diable drawing box of block (outer most).
  14475. * isRectText: boolean,
  14476. * autoColor: string, specify a color when color is 'auto',
  14477. * for textFill, textStroke, textBackgroundColor, and textBorderColor.
  14478. * If autoColor specified, it is used as default textFill.
  14479. * useInsideStyle:
  14480. * `true`: Use inside style (textFill, textStroke, textStrokeWidth)
  14481. * if `textFill` is not specified.
  14482. * `false`: Do not use inside style.
  14483. * `null/undefined`: use inside style if `isRectText` is true and
  14484. * `textFill` is not specified and textPosition contains `'inside'`.
  14485. * forceRich: boolean
  14486. * }
  14487. */
  14488. function setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {
  14489. // Consider there will be abnormal when merge hover style to normal style if given default value.
  14490. opt = opt || EMPTY_OBJ;
  14491. if (opt.isRectText) {
  14492. var textPosition;
  14493. if (opt.getTextPosition) {
  14494. textPosition = opt.getTextPosition(textStyleModel, isEmphasis);
  14495. } else {
  14496. textPosition = textStyleModel.getShallow('position') || (isEmphasis ? null : 'inside'); // 'outside' is not a valid zr textPostion value, but used
  14497. // in bar series, and magric type should be considered.
  14498. textPosition === 'outside' && (textPosition = 'top');
  14499. }
  14500. textStyle.textPosition = textPosition;
  14501. textStyle.textOffset = textStyleModel.getShallow('offset');
  14502. var labelRotate = textStyleModel.getShallow('rotate');
  14503. labelRotate != null && (labelRotate *= Math.PI / 180);
  14504. textStyle.textRotation = labelRotate;
  14505. textStyle.textDistance = retrieve2(textStyleModel.getShallow('distance'), isEmphasis ? null : 5);
  14506. }
  14507. var ecModel = textStyleModel.ecModel;
  14508. var globalTextStyle = ecModel && ecModel.option.textStyle; // Consider case:
  14509. // {
  14510. // data: [{
  14511. // value: 12,
  14512. // label: {
  14513. // rich: {
  14514. // // no 'a' here but using parent 'a'.
  14515. // }
  14516. // }
  14517. // }],
  14518. // rich: {
  14519. // a: { ... }
  14520. // }
  14521. // }
  14522. var richItemNames = getRichItemNames(textStyleModel);
  14523. var richResult;
  14524. if (richItemNames) {
  14525. richResult = {};
  14526. for (var name in richItemNames) {
  14527. if (richItemNames.hasOwnProperty(name)) {
  14528. // Cascade is supported in rich.
  14529. var richTextStyle = textStyleModel.getModel(['rich', name]); // In rich, never `disableBox`.
  14530. // FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  14531. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  14532. // That might confuses users. So probably we should put `textStyleModel` as the
  14533. // root ancestor of the `richTextStyle`. But that would be a break change.
  14534. setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);
  14535. }
  14536. }
  14537. }
  14538. textStyle.rich = richResult;
  14539. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);
  14540. if (opt.forceRich && !opt.textStyle) {
  14541. opt.textStyle = {};
  14542. }
  14543. return textStyle;
  14544. } // Consider case:
  14545. // {
  14546. // data: [{
  14547. // value: 12,
  14548. // label: {
  14549. // rich: {
  14550. // // no 'a' here but using parent 'a'.
  14551. // }
  14552. // }
  14553. // }],
  14554. // rich: {
  14555. // a: { ... }
  14556. // }
  14557. // }
  14558. function getRichItemNames(textStyleModel) {
  14559. // Use object to remove duplicated names.
  14560. var richItemNameMap;
  14561. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  14562. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  14563. if (rich) {
  14564. richItemNameMap = richItemNameMap || {};
  14565. for (var name in rich) {
  14566. if (rich.hasOwnProperty(name)) {
  14567. richItemNameMap[name] = 1;
  14568. }
  14569. }
  14570. }
  14571. textStyleModel = textStyleModel.parentModel;
  14572. }
  14573. return richItemNameMap;
  14574. }
  14575. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {
  14576. // In merge mode, default value should not be given.
  14577. globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;
  14578. textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt) || globalTextStyle.color;
  14579. textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt) || globalTextStyle.textBorderColor;
  14580. textStyle.textStrokeWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
  14581. if (!isEmphasis) {
  14582. if (isBlock) {
  14583. textStyle.insideRollbackOpt = opt;
  14584. applyDefaultTextStyle(textStyle);
  14585. } // Set default finally.
  14586. if (textStyle.textFill == null) {
  14587. textStyle.textFill = opt.autoColor;
  14588. }
  14589. } // Do not use `getFont` here, because merge should be supported, where
  14590. // part of these properties may be changed in emphasis style, and the
  14591. // others should remain their original value got from normal style.
  14592. textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;
  14593. textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;
  14594. textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;
  14595. textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;
  14596. textStyle.textAlign = textStyleModel.getShallow('align');
  14597. textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign') || textStyleModel.getShallow('baseline');
  14598. textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');
  14599. textStyle.textWidth = textStyleModel.getShallow('width');
  14600. textStyle.textHeight = textStyleModel.getShallow('height');
  14601. textStyle.textTag = textStyleModel.getShallow('tag');
  14602. if (!isBlock || !opt.disableBox) {
  14603. textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);
  14604. textStyle.textPadding = textStyleModel.getShallow('padding');
  14605. textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);
  14606. textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');
  14607. textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');
  14608. textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');
  14609. textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');
  14610. textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');
  14611. textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');
  14612. }
  14613. textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor') || globalTextStyle.textShadowColor;
  14614. textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur') || globalTextStyle.textShadowBlur;
  14615. textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX') || globalTextStyle.textShadowOffsetX;
  14616. textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY') || globalTextStyle.textShadowOffsetY;
  14617. }
  14618. function getAutoColor(color, opt) {
  14619. return color !== 'auto' ? color : opt && opt.autoColor ? opt.autoColor : null;
  14620. }
  14621. /**
  14622. * Give some default value to the input `textStyle` object, based on the current settings
  14623. * in this `textStyle` object.
  14624. *
  14625. * The Scenario:
  14626. * when text position is `inside` and `textFill` is not specified, we show
  14627. * text border by default for better view. But it should be considered that text position
  14628. * might be changed when hovering or being emphasis, where the `insideRollback` is used to
  14629. * restore the style.
  14630. *
  14631. * Usage (& NOTICE):
  14632. * When a style object (eithor plain object or instance of `zrender/src/graphic/Style`) is
  14633. * about to be modified on its text related properties, `rollbackDefaultTextStyle` should
  14634. * be called before the modification and `applyDefaultTextStyle` should be called after that.
  14635. * (For the case that all of the text related properties is reset, like `setTextStyleCommon`
  14636. * does, `rollbackDefaultTextStyle` is not needed to be called).
  14637. */
  14638. function applyDefaultTextStyle(textStyle) {
  14639. var textPosition = textStyle.textPosition;
  14640. var opt = textStyle.insideRollbackOpt;
  14641. var insideRollback;
  14642. if (opt && textStyle.textFill == null) {
  14643. var autoColor = opt.autoColor;
  14644. var isRectText = opt.isRectText;
  14645. var useInsideStyle = opt.useInsideStyle;
  14646. var useInsideStyleCache = useInsideStyle !== false && (useInsideStyle === true || isRectText && textPosition // textPosition can be [10, 30]
  14647. && typeof textPosition === 'string' && textPosition.indexOf('inside') >= 0);
  14648. var useAutoColorCache = !useInsideStyleCache && autoColor != null; // All of the props declared in `CACHED_LABEL_STYLE_PROPERTIES` are to be cached.
  14649. if (useInsideStyleCache || useAutoColorCache) {
  14650. insideRollback = {
  14651. textFill: textStyle.textFill,
  14652. textStroke: textStyle.textStroke,
  14653. textStrokeWidth: textStyle.textStrokeWidth
  14654. };
  14655. }
  14656. if (useInsideStyleCache) {
  14657. textStyle.textFill = '#fff'; // Consider text with #fff overflow its container.
  14658. if (textStyle.textStroke == null) {
  14659. textStyle.textStroke = autoColor;
  14660. textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);
  14661. }
  14662. }
  14663. if (useAutoColorCache) {
  14664. textStyle.textFill = autoColor;
  14665. }
  14666. } // Always set `insideRollback`, so that the previous one can be cleared.
  14667. textStyle.insideRollback = insideRollback;
  14668. }
  14669. /**
  14670. * Consider the case: in a scatter,
  14671. * label: {
  14672. * normal: {position: 'inside'},
  14673. * emphasis: {position: 'top'}
  14674. * }
  14675. * In the normal state, the `textFill` will be set as '#fff' for pretty view (see
  14676. * `applyDefaultTextStyle`), but when switching to emphasis state, the `textFill`
  14677. * should be retured to 'autoColor', but not keep '#fff'.
  14678. */
  14679. function rollbackDefaultTextStyle(style) {
  14680. var insideRollback = style.insideRollback;
  14681. if (insideRollback) {
  14682. // Reset all of the props in `CACHED_LABEL_STYLE_PROPERTIES`.
  14683. style.textFill = insideRollback.textFill;
  14684. style.textStroke = insideRollback.textStroke;
  14685. style.textStrokeWidth = insideRollback.textStrokeWidth;
  14686. style.insideRollback = null;
  14687. }
  14688. }
  14689. function getFont(opt, ecModel) {
  14690. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  14691. return trim([// FIXME in node-canvas fontWeight is before fontStyle
  14692. 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(' '));
  14693. }
  14694. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  14695. if (typeof dataIndex === 'function') {
  14696. cb = dataIndex;
  14697. dataIndex = null;
  14698. } // Do not check 'animation' property directly here. Consider this case:
  14699. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  14700. // but its parent model (`seriesModel`) does.
  14701. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  14702. if (animationEnabled) {
  14703. var postfix = isUpdate ? 'Update' : '';
  14704. var duration = animatableModel.getShallow('animationDuration' + postfix);
  14705. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  14706. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  14707. if (typeof animationDelay === 'function') {
  14708. animationDelay = animationDelay(dataIndex, animatableModel.getAnimationDelayParams ? animatableModel.getAnimationDelayParams(el, dataIndex) : null);
  14709. }
  14710. if (typeof duration === 'function') {
  14711. duration = duration(dataIndex);
  14712. }
  14713. duration > 0 ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb) : (el.stopAnimation(), el.attr(props), cb && cb());
  14714. } else {
  14715. el.stopAnimation();
  14716. el.attr(props);
  14717. cb && cb();
  14718. }
  14719. }
  14720. /**
  14721. * Update graphic element properties with or without animation according to the
  14722. * configuration in series.
  14723. *
  14724. * Caution: this method will stop previous animation.
  14725. * So do not use this method to one element twice before
  14726. * animation starts, unless you know what you are doing.
  14727. *
  14728. * @param {module:zrender/Element} el
  14729. * @param {Object} props
  14730. * @param {module:echarts/model/Model} [animatableModel]
  14731. * @param {number} [dataIndex]
  14732. * @param {Function} [cb]
  14733. * @example
  14734. * graphic.updateProps(el, {
  14735. * position: [100, 100]
  14736. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  14737. * // Or
  14738. * graphic.updateProps(el, {
  14739. * position: [100, 100]
  14740. * }, seriesModel, function () { console.log('Animation done!'); });
  14741. */
  14742. function updateProps(el, props, animatableModel, dataIndex, cb) {
  14743. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  14744. }
  14745. /**
  14746. * Init graphic element properties with or without animation according to the
  14747. * configuration in series.
  14748. *
  14749. * Caution: this method will stop previous animation.
  14750. * So do not use this method to one element twice before
  14751. * animation starts, unless you know what you are doing.
  14752. *
  14753. * @param {module:zrender/Element} el
  14754. * @param {Object} props
  14755. * @param {module:echarts/model/Model} [animatableModel]
  14756. * @param {number} [dataIndex]
  14757. * @param {Function} cb
  14758. */
  14759. function initProps(el, props, animatableModel, dataIndex, cb) {
  14760. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  14761. }
  14762. /**
  14763. * Get transform matrix of target (param target),
  14764. * in coordinate of its ancestor (param ancestor)
  14765. *
  14766. * @param {module:zrender/mixin/Transformable} target
  14767. * @param {module:zrender/mixin/Transformable} [ancestor]
  14768. */
  14769. function getTransform(target, ancestor) {
  14770. var mat = identity([]);
  14771. while (target && target !== ancestor) {
  14772. mul$1(mat, target.getLocalTransform(), mat);
  14773. target = target.parent;
  14774. }
  14775. return mat;
  14776. }
  14777. /**
  14778. * Apply transform to an vertex.
  14779. * @param {Array.<number>} target [x, y]
  14780. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  14781. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  14782. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  14783. * @param {boolean=} invert Whether use invert matrix.
  14784. * @return {Array.<number>} [x, y]
  14785. */
  14786. function applyTransform$1(target, transform, invert$$1) {
  14787. if (transform && !isArrayLike(transform)) {
  14788. transform = Transformable.getLocalTransform(transform);
  14789. }
  14790. if (invert$$1) {
  14791. transform = invert([], transform);
  14792. }
  14793. return applyTransform([], target, transform);
  14794. }
  14795. /**
  14796. * @param {string} direction 'left' 'right' 'top' 'bottom'
  14797. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  14798. * @param {boolean=} invert Whether use invert matrix.
  14799. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  14800. */
  14801. function transformDirection(direction, transform, invert$$1) {
  14802. // Pick a base, ensure that transform result will not be (0, 0).
  14803. var hBase = transform[4] === 0 || transform[5] === 0 || transform[0] === 0 ? 1 : Math.abs(2 * transform[4] / transform[0]);
  14804. var vBase = transform[4] === 0 || transform[5] === 0 || transform[2] === 0 ? 1 : Math.abs(2 * transform[4] / transform[2]);
  14805. var vertex = [direction === 'left' ? -hBase : direction === 'right' ? hBase : 0, direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0];
  14806. vertex = applyTransform$1(vertex, transform, invert$$1);
  14807. return Math.abs(vertex[0]) > Math.abs(vertex[1]) ? vertex[0] > 0 ? 'right' : 'left' : vertex[1] > 0 ? 'bottom' : 'top';
  14808. }
  14809. /**
  14810. * Apply group transition animation from g1 to g2.
  14811. * If no animatableModel, no animation.
  14812. */
  14813. function groupTransition(g1, g2, animatableModel, cb) {
  14814. if (!g1 || !g2) {
  14815. return;
  14816. }
  14817. function getElMap(g) {
  14818. var elMap = {};
  14819. g.traverse(function (el) {
  14820. if (!el.isGroup && el.anid) {
  14821. elMap[el.anid] = el;
  14822. }
  14823. });
  14824. return elMap;
  14825. }
  14826. function getAnimatableProps(el) {
  14827. var obj = {
  14828. position: clone$1(el.position),
  14829. rotation: el.rotation
  14830. };
  14831. if (el.shape) {
  14832. obj.shape = extend({}, el.shape);
  14833. }
  14834. return obj;
  14835. }
  14836. var elMap1 = getElMap(g1);
  14837. g2.traverse(function (el) {
  14838. if (!el.isGroup && el.anid) {
  14839. var oldEl = elMap1[el.anid];
  14840. if (oldEl) {
  14841. var newProp = getAnimatableProps(el);
  14842. el.attr(getAnimatableProps(oldEl));
  14843. updateProps(el, newProp, animatableModel, el.dataIndex);
  14844. } // else {
  14845. // if (el.previousProps) {
  14846. // graphic.updateProps
  14847. // }
  14848. // }
  14849. }
  14850. });
  14851. }
  14852. /**
  14853. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  14854. * @param {Object} rect {x, y, width, height}
  14855. * @return {Array.<Array.<number>>} A new clipped points.
  14856. */
  14857. function clipPointsByRect(points, rect) {
  14858. // FIXME: this way migth be incorrect when grpahic clipped by a corner.
  14859. // and when element have border.
  14860. return map(points, function (point) {
  14861. var x = point[0];
  14862. x = mathMax$1(x, rect.x);
  14863. x = mathMin$1(x, rect.x + rect.width);
  14864. var y = point[1];
  14865. y = mathMax$1(y, rect.y);
  14866. y = mathMin$1(y, rect.y + rect.height);
  14867. return [x, y];
  14868. });
  14869. }
  14870. /**
  14871. * @param {Object} targetRect {x, y, width, height}
  14872. * @param {Object} rect {x, y, width, height}
  14873. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  14874. */
  14875. function clipRectByRect(targetRect, rect) {
  14876. var x = mathMax$1(targetRect.x, rect.x);
  14877. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  14878. var y = mathMax$1(targetRect.y, rect.y);
  14879. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height); // If the total rect is cliped, nothing, including the border,
  14880. // should be painted. So return undefined.
  14881. if (x2 >= x && y2 >= y) {
  14882. return {
  14883. x: x,
  14884. y: y,
  14885. width: x2 - x,
  14886. height: y2 - y
  14887. };
  14888. }
  14889. }
  14890. /**
  14891. * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.
  14892. * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.
  14893. * @param {Object} [rect] {x, y, width, height}
  14894. * @return {module:zrender/Element} Icon path or image element.
  14895. */
  14896. function createIcon(iconStr, opt, rect) {
  14897. opt = extend({
  14898. rectHover: true
  14899. }, opt);
  14900. var style = opt.style = {
  14901. strokeNoScale: true
  14902. };
  14903. rect = rect || {
  14904. x: -1,
  14905. y: -1,
  14906. width: 2,
  14907. height: 2
  14908. };
  14909. if (iconStr) {
  14910. return iconStr.indexOf('image://') === 0 ? (style.image = iconStr.slice(8), defaults(style, rect), new ZImage(opt)) : makePath(iconStr.replace('path://', ''), opt, rect, 'center');
  14911. }
  14912. }
  14913. /**
  14914. * Return `true` if the given line (line `a`) and the given polygon
  14915. * are intersect.
  14916. * Note that we do not count colinear as intersect here because no
  14917. * requirement for that. We could do that if required in future.
  14918. *
  14919. * @param {number} a1x
  14920. * @param {number} a1y
  14921. * @param {number} a2x
  14922. * @param {number} a2y
  14923. * @param {Array.<Array.<number>>} points Points of the polygon.
  14924. * @return {boolean}
  14925. */
  14926. function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {
  14927. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  14928. var p = points[i];
  14929. if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {
  14930. return true;
  14931. }
  14932. p2 = p;
  14933. }
  14934. }
  14935. /**
  14936. * Return `true` if the given two lines (line `a` and line `b`)
  14937. * are intersect.
  14938. * Note that we do not count colinear as intersect here because no
  14939. * requirement for that. We could do that if required in future.
  14940. *
  14941. * @param {number} a1x
  14942. * @param {number} a1y
  14943. * @param {number} a2x
  14944. * @param {number} a2y
  14945. * @param {number} b1x
  14946. * @param {number} b1y
  14947. * @param {number} b2x
  14948. * @param {number} b2y
  14949. * @return {boolean}
  14950. */
  14951. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  14952. // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.
  14953. var mx = a2x - a1x;
  14954. var my = a2y - a1y;
  14955. var nx = b2x - b1x;
  14956. var ny = b2y - b1y; // `vec_m` and `vec_n` are parallel iff
  14957. // exising `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.
  14958. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  14959. if (nearZero(nmCrossProduct)) {
  14960. return false;
  14961. } // `vec_m` and `vec_n` are intersect iff
  14962. // existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,
  14963. // such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`
  14964. // and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.
  14965. var b1a1x = a1x - b1x;
  14966. var b1a1y = a1y - b1y;
  14967. var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;
  14968. if (q < 0 || q > 1) {
  14969. return false;
  14970. }
  14971. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  14972. if (p < 0 || p > 1) {
  14973. return false;
  14974. }
  14975. return true;
  14976. }
  14977. /**
  14978. * Cross product of 2-dimension vector.
  14979. */
  14980. function crossProduct2d(x1, y1, x2, y2) {
  14981. return x1 * y2 - x2 * y1;
  14982. }
  14983. function nearZero(val) {
  14984. return val <= 1e-6 && val >= -1e-6;
  14985. } // Register built-in shapes. These shapes might be overwirtten
  14986. // by users, although we do not recommend that.
  14987. registerShape('circle', Circle);
  14988. registerShape('sector', Sector);
  14989. registerShape('ring', Ring);
  14990. registerShape('polygon', Polygon);
  14991. registerShape('polyline', Polyline);
  14992. registerShape('rect', Rect);
  14993. registerShape('line', Line);
  14994. registerShape('bezierCurve', BezierCurve);
  14995. registerShape('arc', Arc);
  14996. var graphic = (Object.freeze || Object)({
  14997. Z2_EMPHASIS_LIFT: Z2_EMPHASIS_LIFT,
  14998. CACHED_LABEL_STYLE_PROPERTIES: CACHED_LABEL_STYLE_PROPERTIES,
  14999. extendShape: extendShape,
  15000. extendPath: extendPath,
  15001. registerShape: registerShape,
  15002. getShapeClass: getShapeClass,
  15003. makePath: makePath,
  15004. makeImage: makeImage,
  15005. mergePath: mergePath,
  15006. resizePath: resizePath,
  15007. subPixelOptimizeLine: subPixelOptimizeLine,
  15008. subPixelOptimizeRect: subPixelOptimizeRect,
  15009. subPixelOptimize: subPixelOptimize,
  15010. setElementHoverStyle: setElementHoverStyle,
  15011. setHoverStyle: setHoverStyle,
  15012. setAsHighDownDispatcher: setAsHighDownDispatcher,
  15013. isHighDownDispatcher: isHighDownDispatcher,
  15014. getHighlightDigit: getHighlightDigit,
  15015. setLabelStyle: setLabelStyle,
  15016. modifyLabelStyle: modifyLabelStyle,
  15017. setTextStyle: setTextStyle,
  15018. setText: setText,
  15019. getFont: getFont,
  15020. updateProps: updateProps,
  15021. initProps: initProps,
  15022. getTransform: getTransform,
  15023. applyTransform: applyTransform$1,
  15024. transformDirection: transformDirection,
  15025. groupTransition: groupTransition,
  15026. clipPointsByRect: clipPointsByRect,
  15027. clipRectByRect: clipRectByRect,
  15028. createIcon: createIcon,
  15029. linePolygonIntersect: linePolygonIntersect,
  15030. lineLineIntersect: lineLineIntersect,
  15031. Group: Group,
  15032. Image: ZImage,
  15033. Text: Text,
  15034. Circle: Circle,
  15035. Sector: Sector,
  15036. Ring: Ring,
  15037. Polygon: Polygon,
  15038. Polyline: Polyline,
  15039. Rect: Rect,
  15040. Line: Line,
  15041. BezierCurve: BezierCurve,
  15042. Arc: Arc,
  15043. IncrementalDisplayable: IncrementalDisplayble,
  15044. CompoundPath: CompoundPath,
  15045. LinearGradient: LinearGradient,
  15046. RadialGradient: RadialGradient,
  15047. BoundingRect: BoundingRect
  15048. });
  15049. /*
  15050. * Licensed to the Apache Software Foundation (ASF) under one
  15051. * or more contributor license agreements. See the NOTICE file
  15052. * distributed with this work for additional information
  15053. * regarding copyright ownership. The ASF licenses this file
  15054. * to you under the Apache License, Version 2.0 (the
  15055. * "License"); you may not use this file except in compliance
  15056. * with the License. You may obtain a copy of the License at
  15057. *
  15058. * http://www.apache.org/licenses/LICENSE-2.0
  15059. *
  15060. * Unless required by applicable law or agreed to in writing,
  15061. * software distributed under the License is distributed on an
  15062. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15063. * KIND, either express or implied. See the License for the
  15064. * specific language governing permissions and limitations
  15065. * under the License.
  15066. */
  15067. var PATH_COLOR = ['textStyle', 'color'];
  15068. var textStyleMixin = {
  15069. /**
  15070. * Get color property or get color from option.textStyle.color
  15071. * @param {boolean} [isEmphasis]
  15072. * @return {string}
  15073. */
  15074. getTextColor: function (isEmphasis) {
  15075. var ecModel = this.ecModel;
  15076. return this.getShallow('color') || (!isEmphasis && ecModel ? ecModel.get(PATH_COLOR) : null);
  15077. },
  15078. /**
  15079. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  15080. * @return {string}
  15081. */
  15082. getFont: function () {
  15083. return getFont({
  15084. fontStyle: this.getShallow('fontStyle'),
  15085. fontWeight: this.getShallow('fontWeight'),
  15086. fontSize: this.getShallow('fontSize'),
  15087. fontFamily: this.getShallow('fontFamily')
  15088. }, this.ecModel);
  15089. },
  15090. getTextRect: function (text) {
  15091. 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'));
  15092. }
  15093. };
  15094. /*
  15095. * Licensed to the Apache Software Foundation (ASF) under one
  15096. * or more contributor license agreements. See the NOTICE file
  15097. * distributed with this work for additional information
  15098. * regarding copyright ownership. The ASF licenses this file
  15099. * to you under the Apache License, Version 2.0 (the
  15100. * "License"); you may not use this file except in compliance
  15101. * with the License. You may obtain a copy of the License at
  15102. *
  15103. * http://www.apache.org/licenses/LICENSE-2.0
  15104. *
  15105. * Unless required by applicable law or agreed to in writing,
  15106. * software distributed under the License is distributed on an
  15107. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15108. * KIND, either express or implied. See the License for the
  15109. * specific language governing permissions and limitations
  15110. * under the License.
  15111. */
  15112. var getItemStyle = makeStyleMapper([['fill', 'color'], ['stroke', 'borderColor'], ['lineWidth', 'borderWidth'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor'], ['textPosition'], ['textAlign']]);
  15113. var itemStyleMixin = {
  15114. getItemStyle: function (excludes, includes) {
  15115. var style = getItemStyle(this, excludes, includes);
  15116. var lineDash = this.getBorderLineDash();
  15117. lineDash && (style.lineDash = lineDash);
  15118. return style;
  15119. },
  15120. getBorderLineDash: function () {
  15121. var lineType = this.get('borderType');
  15122. return lineType === 'solid' || lineType == null ? null : lineType === 'dashed' ? [5, 5] : [1, 1];
  15123. }
  15124. };
  15125. /*
  15126. * Licensed to the Apache Software Foundation (ASF) under one
  15127. * or more contributor license agreements. See the NOTICE file
  15128. * distributed with this work for additional information
  15129. * regarding copyright ownership. The ASF licenses this file
  15130. * to you under the Apache License, Version 2.0 (the
  15131. * "License"); you may not use this file except in compliance
  15132. * with the License. You may obtain a copy of the License at
  15133. *
  15134. * http://www.apache.org/licenses/LICENSE-2.0
  15135. *
  15136. * Unless required by applicable law or agreed to in writing,
  15137. * software distributed under the License is distributed on an
  15138. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15139. * KIND, either express or implied. See the License for the
  15140. * specific language governing permissions and limitations
  15141. * under the License.
  15142. */
  15143. /**
  15144. * @module echarts/model/Model
  15145. */
  15146. var mixin$1 = mixin;
  15147. var inner = makeInner();
  15148. /**
  15149. * @alias module:echarts/model/Model
  15150. * @constructor
  15151. * @param {Object} [option]
  15152. * @param {module:echarts/model/Model} [parentModel]
  15153. * @param {module:echarts/model/Global} [ecModel]
  15154. */
  15155. function Model(option, parentModel, ecModel) {
  15156. /**
  15157. * @type {module:echarts/model/Model}
  15158. * @readOnly
  15159. */
  15160. this.parentModel = parentModel;
  15161. /**
  15162. * @type {module:echarts/model/Global}
  15163. * @readOnly
  15164. */
  15165. this.ecModel = ecModel;
  15166. /**
  15167. * @type {Object}
  15168. * @protected
  15169. */
  15170. this.option = option; // Simple optimization
  15171. // if (this.init) {
  15172. // if (arguments.length <= 4) {
  15173. // this.init(option, parentModel, ecModel, extraOpt);
  15174. // }
  15175. // else {
  15176. // this.init.apply(this, arguments);
  15177. // }
  15178. // }
  15179. }
  15180. Model.prototype = {
  15181. constructor: Model,
  15182. /**
  15183. * Model 的初始化函数
  15184. * @param {Object} option
  15185. */
  15186. init: null,
  15187. /**
  15188. * 从新的 Option merge
  15189. */
  15190. mergeOption: function (option) {
  15191. merge(this.option, option, true);
  15192. },
  15193. /**
  15194. * @param {string|Array.<string>} path
  15195. * @param {boolean} [ignoreParent=false]
  15196. * @return {*}
  15197. */
  15198. get: function (path, ignoreParent) {
  15199. if (path == null) {
  15200. return this.option;
  15201. }
  15202. return doGet(this.option, this.parsePath(path), !ignoreParent && getParent(this, path));
  15203. },
  15204. /**
  15205. * @param {string} key
  15206. * @param {boolean} [ignoreParent=false]
  15207. * @return {*}
  15208. */
  15209. getShallow: function (key, ignoreParent) {
  15210. var option = this.option;
  15211. var val = option == null ? option : option[key];
  15212. var parentModel = !ignoreParent && getParent(this, key);
  15213. if (val == null && parentModel) {
  15214. val = parentModel.getShallow(key);
  15215. }
  15216. return val;
  15217. },
  15218. /**
  15219. * @param {string|Array.<string>} [path]
  15220. * @param {module:echarts/model/Model} [parentModel]
  15221. * @return {module:echarts/model/Model}
  15222. */
  15223. getModel: function (path, parentModel) {
  15224. var obj = path == null ? this.option : doGet(this.option, path = this.parsePath(path));
  15225. var thisParentModel;
  15226. parentModel = parentModel || (thisParentModel = getParent(this, path)) && thisParentModel.getModel(path);
  15227. return new Model(obj, parentModel, this.ecModel);
  15228. },
  15229. /**
  15230. * If model has option
  15231. */
  15232. isEmpty: function () {
  15233. return this.option == null;
  15234. },
  15235. restoreData: function () {},
  15236. // Pending
  15237. clone: function () {
  15238. var Ctor = this.constructor;
  15239. return new Ctor(clone(this.option));
  15240. },
  15241. setReadOnly: function (properties) {// clazzUtil.setReadOnly(this, properties);
  15242. },
  15243. // If path is null/undefined, return null/undefined.
  15244. parsePath: function (path) {
  15245. if (typeof path === 'string') {
  15246. path = path.split('.');
  15247. }
  15248. return path;
  15249. },
  15250. /**
  15251. * @param {Function} getParentMethod
  15252. * param {Array.<string>|string} path
  15253. * return {module:echarts/model/Model}
  15254. */
  15255. customizeGetParent: function (getParentMethod) {
  15256. inner(this).getParent = getParentMethod;
  15257. },
  15258. isAnimationEnabled: function () {
  15259. if (!env$1.node) {
  15260. if (this.option.animation != null) {
  15261. return !!this.option.animation;
  15262. } else if (this.parentModel) {
  15263. return this.parentModel.isAnimationEnabled();
  15264. }
  15265. }
  15266. }
  15267. };
  15268. function doGet(obj, pathArr, parentModel) {
  15269. for (var i = 0; i < pathArr.length; i++) {
  15270. // Ignore empty
  15271. if (!pathArr[i]) {
  15272. continue;
  15273. } // obj could be number/string/... (like 0)
  15274. obj = obj && typeof obj === 'object' ? obj[pathArr[i]] : null;
  15275. if (obj == null) {
  15276. break;
  15277. }
  15278. }
  15279. if (obj == null && parentModel) {
  15280. obj = parentModel.get(pathArr);
  15281. }
  15282. return obj;
  15283. } // `path` can be null/undefined
  15284. function getParent(model, path) {
  15285. var getParentMethod = inner(model).getParent;
  15286. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  15287. } // Enable Model.extend.
  15288. enableClassExtend(Model);
  15289. enableClassCheck(Model);
  15290. mixin$1(Model, lineStyleMixin);
  15291. mixin$1(Model, areaStyleMixin);
  15292. mixin$1(Model, textStyleMixin);
  15293. mixin$1(Model, itemStyleMixin);
  15294. /*
  15295. * Licensed to the Apache Software Foundation (ASF) under one
  15296. * or more contributor license agreements. See the NOTICE file
  15297. * distributed with this work for additional information
  15298. * regarding copyright ownership. The ASF licenses this file
  15299. * to you under the Apache License, Version 2.0 (the
  15300. * "License"); you may not use this file except in compliance
  15301. * with the License. You may obtain a copy of the License at
  15302. *
  15303. * http://www.apache.org/licenses/LICENSE-2.0
  15304. *
  15305. * Unless required by applicable law or agreed to in writing,
  15306. * software distributed under the License is distributed on an
  15307. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15308. * KIND, either express or implied. See the License for the
  15309. * specific language governing permissions and limitations
  15310. * under the License.
  15311. */
  15312. var base = 0;
  15313. /**
  15314. * @public
  15315. * @param {string} type
  15316. * @return {string}
  15317. */
  15318. function getUID(type) {
  15319. // Considering the case of crossing js context,
  15320. // use Math.random to make id as unique as possible.
  15321. return [type || '', base++, Math.random().toFixed(5)].join('_');
  15322. }
  15323. /**
  15324. * @inner
  15325. */
  15326. function enableSubTypeDefaulter(entity) {
  15327. var subTypeDefaulters = {};
  15328. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  15329. componentType = parseClassType$1(componentType);
  15330. subTypeDefaulters[componentType.main] = defaulter;
  15331. };
  15332. entity.determineSubType = function (componentType, option) {
  15333. var type = option.type;
  15334. if (!type) {
  15335. var componentTypeMain = parseClassType$1(componentType).main;
  15336. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  15337. type = subTypeDefaulters[componentTypeMain](option);
  15338. }
  15339. }
  15340. return type;
  15341. };
  15342. return entity;
  15343. }
  15344. /**
  15345. * Topological travel on Activity Network (Activity On Vertices).
  15346. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  15347. *
  15348. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  15349. *
  15350. * If there is circle dependencey, Error will be thrown.
  15351. *
  15352. */
  15353. function enableTopologicalTravel(entity, dependencyGetter) {
  15354. /**
  15355. * @public
  15356. * @param {Array.<string>} targetNameList Target Component type list.
  15357. * Can be ['aa', 'bb', 'aa.xx']
  15358. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  15359. * @param {Function} callback Params: componentType, dependencies.
  15360. * @param {Object} context Scope of callback.
  15361. */
  15362. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  15363. if (!targetNameList.length) {
  15364. return;
  15365. }
  15366. var result = makeDepndencyGraph(fullNameList);
  15367. var graph = result.graph;
  15368. var stack = result.noEntryList;
  15369. var targetNameSet = {};
  15370. each$1(targetNameList, function (name) {
  15371. targetNameSet[name] = true;
  15372. });
  15373. while (stack.length) {
  15374. var currComponentType = stack.pop();
  15375. var currVertex = graph[currComponentType];
  15376. var isInTargetNameSet = !!targetNameSet[currComponentType];
  15377. if (isInTargetNameSet) {
  15378. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  15379. delete targetNameSet[currComponentType];
  15380. }
  15381. each$1(currVertex.successor, isInTargetNameSet ? removeEdgeAndAdd : removeEdge);
  15382. }
  15383. each$1(targetNameSet, function () {
  15384. throw new Error('Circle dependency may exists');
  15385. });
  15386. function removeEdge(succComponentType) {
  15387. graph[succComponentType].entryCount--;
  15388. if (graph[succComponentType].entryCount === 0) {
  15389. stack.push(succComponentType);
  15390. }
  15391. } // Consider this case: legend depends on series, and we call
  15392. // chart.setOption({series: [...]}), where only series is in option.
  15393. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  15394. // not be called, but only sereis.mergeOption is called. Thus legend
  15395. // have no chance to update its local record about series (like which
  15396. // name of series is available in legend).
  15397. function removeEdgeAndAdd(succComponentType) {
  15398. targetNameSet[succComponentType] = true;
  15399. removeEdge(succComponentType);
  15400. }
  15401. };
  15402. /**
  15403. * DepndencyGraph: {Object}
  15404. * key: conponentType,
  15405. * value: {
  15406. * successor: [conponentTypes...],
  15407. * originalDeps: [conponentTypes...],
  15408. * entryCount: {number}
  15409. * }
  15410. */
  15411. function makeDepndencyGraph(fullNameList) {
  15412. var graph = {};
  15413. var noEntryList = [];
  15414. each$1(fullNameList, function (name) {
  15415. var thisItem = createDependencyGraphItem(graph, name);
  15416. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  15417. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  15418. thisItem.entryCount = availableDeps.length;
  15419. if (thisItem.entryCount === 0) {
  15420. noEntryList.push(name);
  15421. }
  15422. each$1(availableDeps, function (dependentName) {
  15423. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  15424. thisItem.predecessor.push(dependentName);
  15425. }
  15426. var thatItem = createDependencyGraphItem(graph, dependentName);
  15427. if (indexOf(thatItem.successor, dependentName) < 0) {
  15428. thatItem.successor.push(name);
  15429. }
  15430. });
  15431. });
  15432. return {
  15433. graph: graph,
  15434. noEntryList: noEntryList
  15435. };
  15436. }
  15437. function createDependencyGraphItem(graph, name) {
  15438. if (!graph[name]) {
  15439. graph[name] = {
  15440. predecessor: [],
  15441. successor: []
  15442. };
  15443. }
  15444. return graph[name];
  15445. }
  15446. function getAvailableDependencies(originalDeps, fullNameList) {
  15447. var availableDeps = [];
  15448. each$1(originalDeps, function (dep) {
  15449. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  15450. });
  15451. return availableDeps;
  15452. }
  15453. }
  15454. /*
  15455. * Licensed to the Apache Software Foundation (ASF) under one
  15456. * or more contributor license agreements. See the NOTICE file
  15457. * distributed with this work for additional information
  15458. * regarding copyright ownership. The ASF licenses this file
  15459. * to you under the Apache License, Version 2.0 (the
  15460. * "License"); you may not use this file except in compliance
  15461. * with the License. You may obtain a copy of the License at
  15462. *
  15463. * http://www.apache.org/licenses/LICENSE-2.0
  15464. *
  15465. * Unless required by applicable law or agreed to in writing,
  15466. * software distributed under the License is distributed on an
  15467. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15468. * KIND, either express or implied. See the License for the
  15469. * specific language governing permissions and limitations
  15470. * under the License.
  15471. */
  15472. /*
  15473. * A third-party license is embeded for some of the code in this file:
  15474. * The method "quantile" was copied from "d3.js".
  15475. * (See more details in the comment of the method below.)
  15476. * The use of the source code of this file is also subject to the terms
  15477. * and consitions of the license of "d3.js" (BSD-3Clause, see
  15478. * </licenses/LICENSE-d3>).
  15479. */
  15480. var RADIAN_EPSILON = 1e-4;
  15481. function _trim(str) {
  15482. return str.replace(/^\s+|\s+$/g, '');
  15483. }
  15484. /**
  15485. * Linear mapping a value from domain to range
  15486. * @memberOf module:echarts/util/number
  15487. * @param {(number|Array.<number>)} val
  15488. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  15489. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  15490. * @param {boolean} clamp
  15491. * @return {(number|Array.<number>}
  15492. */
  15493. function linearMap(val, domain, range, clamp) {
  15494. var subDomain = domain[1] - domain[0];
  15495. var subRange = range[1] - range[0];
  15496. if (subDomain === 0) {
  15497. return subRange === 0 ? range[0] : (range[0] + range[1]) / 2;
  15498. } // Avoid accuracy problem in edge, such as
  15499. // 146.39 - 62.83 === 83.55999999999999.
  15500. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  15501. // It is a little verbose for efficiency considering this method
  15502. // is a hotspot.
  15503. if (clamp) {
  15504. if (subDomain > 0) {
  15505. if (val <= domain[0]) {
  15506. return range[0];
  15507. } else if (val >= domain[1]) {
  15508. return range[1];
  15509. }
  15510. } else {
  15511. if (val >= domain[0]) {
  15512. return range[0];
  15513. } else if (val <= domain[1]) {
  15514. return range[1];
  15515. }
  15516. }
  15517. } else {
  15518. if (val === domain[0]) {
  15519. return range[0];
  15520. }
  15521. if (val === domain[1]) {
  15522. return range[1];
  15523. }
  15524. }
  15525. return (val - domain[0]) / subDomain * subRange + range[0];
  15526. }
  15527. /**
  15528. * Convert a percent string to absolute number.
  15529. * Returns NaN if percent is not a valid string or number
  15530. * @memberOf module:echarts/util/number
  15531. * @param {string|number} percent
  15532. * @param {number} all
  15533. * @return {number}
  15534. */
  15535. function parsePercent$1(percent, all) {
  15536. switch (percent) {
  15537. case 'center':
  15538. case 'middle':
  15539. percent = '50%';
  15540. break;
  15541. case 'left':
  15542. case 'top':
  15543. percent = '0%';
  15544. break;
  15545. case 'right':
  15546. case 'bottom':
  15547. percent = '100%';
  15548. break;
  15549. }
  15550. if (typeof percent === 'string') {
  15551. if (_trim(percent).match(/%$/)) {
  15552. return parseFloat(percent) / 100 * all;
  15553. }
  15554. return parseFloat(percent);
  15555. }
  15556. return percent == null ? NaN : +percent;
  15557. }
  15558. /**
  15559. * (1) Fix rounding error of float numbers.
  15560. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  15561. *
  15562. * @param {number} x
  15563. * @param {number} [precision]
  15564. * @param {boolean} [returnStr]
  15565. * @return {number|string}
  15566. */
  15567. function round$1(x, precision, returnStr) {
  15568. if (precision == null) {
  15569. precision = 10;
  15570. } // Avoid range error
  15571. precision = Math.min(Math.max(0, precision), 20);
  15572. x = (+x).toFixed(precision);
  15573. return returnStr ? x : +x;
  15574. }
  15575. /**
  15576. * asc sort arr.
  15577. * The input arr will be modified.
  15578. *
  15579. * @param {Array} arr
  15580. * @return {Array} The input arr.
  15581. */
  15582. function asc(arr) {
  15583. arr.sort(function (a, b) {
  15584. return a - b;
  15585. });
  15586. return arr;
  15587. }
  15588. /**
  15589. * Get precision
  15590. * @param {number} val
  15591. */
  15592. function getPrecision(val) {
  15593. val = +val;
  15594. if (isNaN(val)) {
  15595. return 0;
  15596. } // It is much faster than methods converting number to string as follows
  15597. // var tmp = val.toString();
  15598. // return tmp.length - 1 - tmp.indexOf('.');
  15599. // especially when precision is low
  15600. var e = 1;
  15601. var count = 0;
  15602. while (Math.round(val * e) / e !== val) {
  15603. e *= 10;
  15604. count++;
  15605. }
  15606. return count;
  15607. }
  15608. /**
  15609. * @param {string|number} val
  15610. * @return {number}
  15611. */
  15612. function getPrecisionSafe(val) {
  15613. var str = val.toString(); // Consider scientific notation: '3.4e-12' '3.4e+12'
  15614. var eIndex = str.indexOf('e');
  15615. if (eIndex > 0) {
  15616. var precision = +str.slice(eIndex + 1);
  15617. return precision < 0 ? -precision : 0;
  15618. } else {
  15619. var dotIndex = str.indexOf('.');
  15620. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  15621. }
  15622. }
  15623. /**
  15624. * Minimal dicernible data precisioin according to a single pixel.
  15625. *
  15626. * @param {Array.<number>} dataExtent
  15627. * @param {Array.<number>} pixelExtent
  15628. * @return {number} precision
  15629. */
  15630. function getPixelPrecision(dataExtent, pixelExtent) {
  15631. var log = Math.log;
  15632. var LN10 = Math.LN10;
  15633. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  15634. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10); // toFixed() digits argument must be between 0 and 20.
  15635. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  15636. return !isFinite(precision) ? 20 : precision;
  15637. }
  15638. /**
  15639. * Get a data of given precision, assuring the sum of percentages
  15640. * in valueList is 1.
  15641. * The largest remainer method is used.
  15642. * https://en.wikipedia.org/wiki/Largest_remainder_method
  15643. *
  15644. * @param {Array.<number>} valueList a list of all data
  15645. * @param {number} idx index of the data to be processed in valueList
  15646. * @param {number} precision integer number showing digits of precision
  15647. * @return {number} percent ranging from 0 to 100
  15648. */
  15649. function getPercentWithPrecision(valueList, idx, precision) {
  15650. if (!valueList[idx]) {
  15651. return 0;
  15652. }
  15653. var sum = reduce(valueList, function (acc, val) {
  15654. return acc + (isNaN(val) ? 0 : val);
  15655. }, 0);
  15656. if (sum === 0) {
  15657. return 0;
  15658. }
  15659. var digits = Math.pow(10, precision);
  15660. var votesPerQuota = map(valueList, function (val) {
  15661. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  15662. });
  15663. var targetSeats = digits * 100;
  15664. var seats = map(votesPerQuota, function (votes) {
  15665. // Assign automatic seats.
  15666. return Math.floor(votes);
  15667. });
  15668. var currentSum = reduce(seats, function (acc, val) {
  15669. return acc + val;
  15670. }, 0);
  15671. var remainder = map(votesPerQuota, function (votes, idx) {
  15672. return votes - seats[idx];
  15673. }); // Has remainding votes.
  15674. while (currentSum < targetSeats) {
  15675. // Find next largest remainder.
  15676. var max = Number.NEGATIVE_INFINITY;
  15677. var maxId = null;
  15678. for (var i = 0, len = remainder.length; i < len; ++i) {
  15679. if (remainder[i] > max) {
  15680. max = remainder[i];
  15681. maxId = i;
  15682. }
  15683. } // Add a vote to max remainder.
  15684. ++seats[maxId];
  15685. remainder[maxId] = 0;
  15686. ++currentSum;
  15687. }
  15688. return seats[idx] / digits;
  15689. } // Number.MAX_SAFE_INTEGER, ie do not support.
  15690. var MAX_SAFE_INTEGER = 9007199254740991;
  15691. /**
  15692. * To 0 - 2 * PI, considering negative radian.
  15693. * @param {number} radian
  15694. * @return {number}
  15695. */
  15696. function remRadian(radian) {
  15697. var pi2 = Math.PI * 2;
  15698. return (radian % pi2 + pi2) % pi2;
  15699. }
  15700. /**
  15701. * @param {type} radian
  15702. * @return {boolean}
  15703. */
  15704. function isRadianAroundZero(val) {
  15705. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  15706. }
  15707. /* eslint-disable */
  15708. 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
  15709. /* eslint-enable */
  15710. /**
  15711. * @param {string|Date|number} value These values can be accepted:
  15712. * + An instance of Date, represent a time in its own time zone.
  15713. * + Or string in a subset of ISO 8601, only including:
  15714. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  15715. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  15716. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  15717. * all of which will be treated as local time if time zone is not specified
  15718. * (see <https://momentjs.com/>).
  15719. * + Or other string format, including (all of which will be treated as loacal time):
  15720. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  15721. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  15722. * + a timestamp, which represent a time in UTC.
  15723. * @return {Date} date
  15724. */
  15725. function parseDate(value) {
  15726. if (value instanceof Date) {
  15727. return value;
  15728. } else if (typeof value === 'string') {
  15729. // Different browsers parse date in different way, so we parse it manually.
  15730. // Some other issues:
  15731. // new Date('1970-01-01') is UTC,
  15732. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  15733. // See issue #3623
  15734. var match = TIME_REG.exec(value);
  15735. if (!match) {
  15736. // return Invalid Date.
  15737. return new Date(NaN);
  15738. } // Use local time when no timezone offset specifed.
  15739. if (!match[8]) {
  15740. // match[n] can only be string or undefined.
  15741. // But take care of '12' + 1 => '121'.
  15742. return new Date(+match[1], +(match[2] || 1) - 1, +match[3] || 1, +match[4] || 0, +(match[5] || 0), +match[6] || 0, +match[7] || 0);
  15743. } // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  15744. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  15745. // For example, system timezone is set as "Time Zone: America/Toronto",
  15746. // then these code will get different result:
  15747. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  15748. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  15749. // So we should not use `new Date`, but use `Date.UTC`.
  15750. else {
  15751. var hour = +match[4] || 0;
  15752. if (match[8].toUpperCase() !== 'Z') {
  15753. hour -= match[8].slice(0, 3);
  15754. }
  15755. return new Date(Date.UTC(+match[1], +(match[2] || 1) - 1, +match[3] || 1, hour, +(match[5] || 0), +match[6] || 0, +match[7] || 0));
  15756. }
  15757. } else if (value == null) {
  15758. return new Date(NaN);
  15759. }
  15760. return new Date(Math.round(value));
  15761. }
  15762. /**
  15763. * Quantity of a number. e.g. 0.1, 1, 10, 100
  15764. *
  15765. * @param {number} val
  15766. * @return {number}
  15767. */
  15768. function quantity(val) {
  15769. return Math.pow(10, quantityExponent(val));
  15770. }
  15771. /**
  15772. * Exponent of the quantity of a number
  15773. * e.g., 1234 equals to 1.234*10^3, so quantityExponent(1234) is 3
  15774. *
  15775. * @param {number} val non-negative value
  15776. * @return {number}
  15777. */
  15778. function quantityExponent(val) {
  15779. if (val === 0) {
  15780. return 0;
  15781. }
  15782. var exp = Math.floor(Math.log(val) / Math.LN10);
  15783. /**
  15784. * exp is expected to be the rounded-down result of the base-10 log of val.
  15785. * But due to the precision loss with Math.log(val), we need to restore it
  15786. * using 10^exp to make sure we can get val back from exp. #11249
  15787. */
  15788. if (val / Math.pow(10, exp) >= 10) {
  15789. exp++;
  15790. }
  15791. return exp;
  15792. }
  15793. /**
  15794. * find a “nice” number approximately equal to x. Round the number if round = true,
  15795. * take ceiling if round = false. The primary observation is that the “nicest”
  15796. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  15797. *
  15798. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  15799. *
  15800. * @param {number} val Non-negative value.
  15801. * @param {boolean} round
  15802. * @return {number}
  15803. */
  15804. function nice(val, round) {
  15805. var exponent = quantityExponent(val);
  15806. var exp10 = Math.pow(10, exponent);
  15807. var f = val / exp10; // 1 <= f < 10
  15808. var nf;
  15809. if (round) {
  15810. if (f < 1.5) {
  15811. nf = 1;
  15812. } else if (f < 2.5) {
  15813. nf = 2;
  15814. } else if (f < 4) {
  15815. nf = 3;
  15816. } else if (f < 7) {
  15817. nf = 5;
  15818. } else {
  15819. nf = 10;
  15820. }
  15821. } else {
  15822. if (f < 1) {
  15823. nf = 1;
  15824. } else if (f < 2) {
  15825. nf = 2;
  15826. } else if (f < 3) {
  15827. nf = 3;
  15828. } else if (f < 5) {
  15829. nf = 5;
  15830. } else {
  15831. nf = 10;
  15832. }
  15833. }
  15834. val = nf * exp10; // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  15835. // 20 is the uppper bound of toFixed.
  15836. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  15837. }
  15838. /**
  15839. * This code was copied from "d3.js"
  15840. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  15841. * See the license statement at the head of this file.
  15842. * @param {Array.<number>} ascArr
  15843. */
  15844. function quantile(ascArr, p) {
  15845. var H = (ascArr.length - 1) * p + 1;
  15846. var h = Math.floor(H);
  15847. var v = +ascArr[h - 1];
  15848. var e = H - h;
  15849. return e ? v + e * (ascArr[h] - v) : v;
  15850. }
  15851. /**
  15852. * Orders intervals asc, and split them when overlap.
  15853. * expect(numberUtil.reformIntervals([
  15854. * {interval: [18, 62], close: [1, 1]},
  15855. * {interval: [-Infinity, -70], close: [0, 0]},
  15856. * {interval: [-70, -26], close: [1, 1]},
  15857. * {interval: [-26, 18], close: [1, 1]},
  15858. * {interval: [62, 150], close: [1, 1]},
  15859. * {interval: [106, 150], close: [1, 1]},
  15860. * {interval: [150, Infinity], close: [0, 0]}
  15861. * ])).toEqual([
  15862. * {interval: [-Infinity, -70], close: [0, 0]},
  15863. * {interval: [-70, -26], close: [1, 1]},
  15864. * {interval: [-26, 18], close: [0, 1]},
  15865. * {interval: [18, 62], close: [0, 1]},
  15866. * {interval: [62, 150], close: [0, 1]},
  15867. * {interval: [150, Infinity], close: [0, 0]}
  15868. * ]);
  15869. * @param {Array.<Object>} list, where `close` mean open or close
  15870. * of the interval, and Infinity can be used.
  15871. * @return {Array.<Object>} The origin list, which has been reformed.
  15872. */
  15873. function reformIntervals(list) {
  15874. list.sort(function (a, b) {
  15875. return littleThan(a, b, 0) ? -1 : 1;
  15876. });
  15877. var curr = -Infinity;
  15878. var currClose = 1;
  15879. for (var i = 0; i < list.length;) {
  15880. var interval = list[i].interval;
  15881. var close = list[i].close;
  15882. for (var lg = 0; lg < 2; lg++) {
  15883. if (interval[lg] <= curr) {
  15884. interval[lg] = curr;
  15885. close[lg] = !lg ? 1 - currClose : 1;
  15886. }
  15887. curr = interval[lg];
  15888. currClose = close[lg];
  15889. }
  15890. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  15891. list.splice(i, 1);
  15892. } else {
  15893. i++;
  15894. }
  15895. }
  15896. return list;
  15897. function littleThan(a, b, lg) {
  15898. 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));
  15899. }
  15900. }
  15901. /**
  15902. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  15903. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  15904. * subtraction forces infinities to NaN
  15905. *
  15906. * @param {*} v
  15907. * @return {boolean}
  15908. */
  15909. function isNumeric(v) {
  15910. return v - parseFloat(v) >= 0;
  15911. }
  15912. var number = (Object.freeze || Object)({
  15913. linearMap: linearMap,
  15914. parsePercent: parsePercent$1,
  15915. round: round$1,
  15916. asc: asc,
  15917. getPrecision: getPrecision,
  15918. getPrecisionSafe: getPrecisionSafe,
  15919. getPixelPrecision: getPixelPrecision,
  15920. getPercentWithPrecision: getPercentWithPrecision,
  15921. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  15922. remRadian: remRadian,
  15923. isRadianAroundZero: isRadianAroundZero,
  15924. parseDate: parseDate,
  15925. quantity: quantity,
  15926. quantityExponent: quantityExponent,
  15927. nice: nice,
  15928. quantile: quantile,
  15929. reformIntervals: reformIntervals,
  15930. isNumeric: isNumeric
  15931. });
  15932. /*
  15933. * Licensed to the Apache Software Foundation (ASF) under one
  15934. * or more contributor license agreements. See the NOTICE file
  15935. * distributed with this work for additional information
  15936. * regarding copyright ownership. The ASF licenses this file
  15937. * to you under the Apache License, Version 2.0 (the
  15938. * "License"); you may not use this file except in compliance
  15939. * with the License. You may obtain a copy of the License at
  15940. *
  15941. * http://www.apache.org/licenses/LICENSE-2.0
  15942. *
  15943. * Unless required by applicable law or agreed to in writing,
  15944. * software distributed under the License is distributed on an
  15945. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15946. * KIND, either express or implied. See the License for the
  15947. * specific language governing permissions and limitations
  15948. * under the License.
  15949. */
  15950. /**
  15951. * add commas after every three numbers
  15952. * @param {string|number} x
  15953. * @return {string}
  15954. */
  15955. function addCommas(x) {
  15956. if (isNaN(x)) {
  15957. return '-';
  15958. }
  15959. x = (x + '').split('.');
  15960. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,') + (x.length > 1 ? '.' + x[1] : '');
  15961. }
  15962. /**
  15963. * @param {string} str
  15964. * @param {boolean} [upperCaseFirst=false]
  15965. * @return {string} str
  15966. */
  15967. function toCamelCase(str, upperCaseFirst) {
  15968. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  15969. return group1.toUpperCase();
  15970. });
  15971. if (upperCaseFirst && str) {
  15972. str = str.charAt(0).toUpperCase() + str.slice(1);
  15973. }
  15974. return str;
  15975. }
  15976. var normalizeCssArray$1 = normalizeCssArray;
  15977. var replaceReg = /([&<>"'])/g;
  15978. var replaceMap = {
  15979. '&': '&amp;',
  15980. '<': '&lt;',
  15981. '>': '&gt;',
  15982. '"': '&quot;',
  15983. '\'': '&#39;'
  15984. };
  15985. function encodeHTML(source) {
  15986. return source == null ? '' : (source + '').replace(replaceReg, function (str, c) {
  15987. return replaceMap[c];
  15988. });
  15989. }
  15990. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  15991. var wrapVar = function (varName, seriesIdx) {
  15992. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  15993. };
  15994. /**
  15995. * Template formatter
  15996. * @param {string} tpl
  15997. * @param {Array.<Object>|Object} paramsList
  15998. * @param {boolean} [encode=false]
  15999. * @return {string}
  16000. */
  16001. function formatTpl(tpl, paramsList, encode) {
  16002. if (!isArray(paramsList)) {
  16003. paramsList = [paramsList];
  16004. }
  16005. var seriesLen = paramsList.length;
  16006. if (!seriesLen) {
  16007. return '';
  16008. }
  16009. var $vars = paramsList[0].$vars || [];
  16010. for (var i = 0; i < $vars.length; i++) {
  16011. var alias = TPL_VAR_ALIAS[i];
  16012. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  16013. }
  16014. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  16015. for (var k = 0; k < $vars.length; k++) {
  16016. var val = paramsList[seriesIdx][$vars[k]];
  16017. tpl = tpl.replace(wrapVar(TPL_VAR_ALIAS[k], seriesIdx), encode ? encodeHTML(val) : val);
  16018. }
  16019. }
  16020. return tpl;
  16021. }
  16022. /**
  16023. * simple Template formatter
  16024. *
  16025. * @param {string} tpl
  16026. * @param {Object} param
  16027. * @param {boolean} [encode=false]
  16028. * @return {string}
  16029. */
  16030. function formatTplSimple(tpl, param, encode) {
  16031. each$1(param, function (value, key) {
  16032. tpl = tpl.replace('{' + key + '}', encode ? encodeHTML(value) : value);
  16033. });
  16034. return tpl;
  16035. }
  16036. /**
  16037. * @param {Object|string} [opt] If string, means color.
  16038. * @param {string} [opt.color]
  16039. * @param {string} [opt.extraCssText]
  16040. * @param {string} [opt.type='item'] 'item' or 'subItem'
  16041. * @param {string} [opt.renderMode='html'] render mode of tooltip, 'html' or 'richText'
  16042. * @param {string} [opt.markerId='X'] id name for marker. If only one marker is in a rich text, this can be omitted.
  16043. * @return {string}
  16044. */
  16045. function getTooltipMarker(opt, extraCssText) {
  16046. opt = isString(opt) ? {
  16047. color: opt,
  16048. extraCssText: extraCssText
  16049. } : opt || {};
  16050. var color = opt.color;
  16051. var type = opt.type;
  16052. var extraCssText = opt.extraCssText;
  16053. var renderMode = opt.renderMode || 'html';
  16054. var markerId = opt.markerId || 'X';
  16055. if (!color) {
  16056. return '';
  16057. }
  16058. if (renderMode === 'html') {
  16059. 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>';
  16060. } else {
  16061. // Space for rich element marker
  16062. return {
  16063. renderMode: renderMode,
  16064. content: '{marker' + markerId + '|} ',
  16065. style: {
  16066. color: color
  16067. }
  16068. };
  16069. }
  16070. }
  16071. function pad(str, len) {
  16072. str += '';
  16073. return '0000'.substr(0, len - str.length) + str;
  16074. }
  16075. /**
  16076. * ISO Date format
  16077. * @param {string} tpl
  16078. * @param {number} value
  16079. * @param {boolean} [isUTC=false] Default in local time.
  16080. * see `module:echarts/scale/Time`
  16081. * and `module:echarts/util/number#parseDate`.
  16082. * @inner
  16083. */
  16084. function formatTime(tpl, value, isUTC) {
  16085. if (tpl === 'week' || tpl === 'month' || tpl === 'quarter' || tpl === 'half-year' || tpl === 'year') {
  16086. tpl = 'MM-dd\nyyyy';
  16087. }
  16088. var date = parseDate(value);
  16089. var utc = isUTC ? 'UTC' : '';
  16090. var y = date['get' + utc + 'FullYear']();
  16091. var M = date['get' + utc + 'Month']() + 1;
  16092. var d = date['get' + utc + 'Date']();
  16093. var h = date['get' + utc + 'Hours']();
  16094. var m = date['get' + utc + 'Minutes']();
  16095. var s = date['get' + utc + 'Seconds']();
  16096. var S = date['get' + utc + 'Milliseconds']();
  16097. 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));
  16098. return tpl;
  16099. }
  16100. /**
  16101. * Capital first
  16102. * @param {string} str
  16103. * @return {string}
  16104. */
  16105. function capitalFirst(str) {
  16106. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  16107. }
  16108. var truncateText$1 = truncateText;
  16109. /**
  16110. * @public
  16111. * @param {Object} opt
  16112. * @param {string} opt.text
  16113. * @param {string} opt.font
  16114. * @param {string} [opt.textAlign='left']
  16115. * @param {string} [opt.textVerticalAlign='top']
  16116. * @param {Array.<number>} [opt.textPadding]
  16117. * @param {number} [opt.textLineHeight]
  16118. * @param {Object} [opt.rich]
  16119. * @param {Object} [opt.truncate]
  16120. * @return {Object} {x, y, width, height, lineHeight}
  16121. */
  16122. function getTextBoundingRect(opt) {
  16123. return getBoundingRect(opt.text, opt.font, opt.textAlign, opt.textVerticalAlign, opt.textPadding, opt.textLineHeight, opt.rich, opt.truncate);
  16124. }
  16125. /**
  16126. * @deprecated
  16127. * the `textLineHeight` was added later.
  16128. * For backward compatiblility, put it as the last parameter.
  16129. * But deprecated this interface. Please use `getTextBoundingRect` instead.
  16130. */
  16131. function getTextRect(text, font, textAlign, textVerticalAlign, textPadding, rich, truncate, textLineHeight) {
  16132. return getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate);
  16133. }
  16134. /**
  16135. * open new tab
  16136. * @param {string} link url
  16137. * @param {string} target blank or self
  16138. */
  16139. function windowOpen(link, target) {
  16140. if (target === '_blank' || target === 'blank') {
  16141. var blank = window.open();
  16142. blank.opener = null;
  16143. blank.location = link;
  16144. } else {
  16145. window.open(link, target);
  16146. }
  16147. }
  16148. var format = (Object.freeze || Object)({
  16149. addCommas: addCommas,
  16150. toCamelCase: toCamelCase,
  16151. normalizeCssArray: normalizeCssArray$1,
  16152. encodeHTML: encodeHTML,
  16153. formatTpl: formatTpl,
  16154. formatTplSimple: formatTplSimple,
  16155. getTooltipMarker: getTooltipMarker,
  16156. formatTime: formatTime,
  16157. capitalFirst: capitalFirst,
  16158. truncateText: truncateText$1,
  16159. getTextBoundingRect: getTextBoundingRect,
  16160. getTextRect: getTextRect,
  16161. windowOpen: windowOpen
  16162. });
  16163. /*
  16164. * Licensed to the Apache Software Foundation (ASF) under one
  16165. * or more contributor license agreements. See the NOTICE file
  16166. * distributed with this work for additional information
  16167. * regarding copyright ownership. The ASF licenses this file
  16168. * to you under the Apache License, Version 2.0 (the
  16169. * "License"); you may not use this file except in compliance
  16170. * with the License. You may obtain a copy of the License at
  16171. *
  16172. * http://www.apache.org/licenses/LICENSE-2.0
  16173. *
  16174. * Unless required by applicable law or agreed to in writing,
  16175. * software distributed under the License is distributed on an
  16176. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16177. * KIND, either express or implied. See the License for the
  16178. * specific language governing permissions and limitations
  16179. * under the License.
  16180. */
  16181. // Layout helpers for each component positioning
  16182. var each$3 = each$1;
  16183. /**
  16184. * @public
  16185. */
  16186. var LOCATION_PARAMS = ['left', 'right', 'top', 'bottom', 'width', 'height'];
  16187. /**
  16188. * @public
  16189. */
  16190. var HV_NAMES = [['width', 'left', 'right'], ['height', 'top', 'bottom']];
  16191. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  16192. var x = 0;
  16193. var y = 0;
  16194. if (maxWidth == null) {
  16195. maxWidth = Infinity;
  16196. }
  16197. if (maxHeight == null) {
  16198. maxHeight = Infinity;
  16199. }
  16200. var currentLineMaxSize = 0;
  16201. group.eachChild(function (child, idx) {
  16202. var position = child.position;
  16203. var rect = child.getBoundingRect();
  16204. var nextChild = group.childAt(idx + 1);
  16205. var nextChildRect = nextChild && nextChild.getBoundingRect();
  16206. var nextX;
  16207. var nextY;
  16208. if (orient === 'horizontal') {
  16209. var moveX = rect.width + (nextChildRect ? -nextChildRect.x + rect.x : 0);
  16210. nextX = x + moveX; // Wrap when width exceeds maxWidth or meet a `newline` group
  16211. // FIXME compare before adding gap?
  16212. if (nextX > maxWidth || child.newline) {
  16213. x = 0;
  16214. nextX = moveX;
  16215. y += currentLineMaxSize + gap;
  16216. currentLineMaxSize = rect.height;
  16217. } else {
  16218. // FIXME: consider rect.y is not `0`?
  16219. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  16220. }
  16221. } else {
  16222. var moveY = rect.height + (nextChildRect ? -nextChildRect.y + rect.y : 0);
  16223. nextY = y + moveY; // Wrap when width exceeds maxHeight or meet a `newline` group
  16224. if (nextY > maxHeight || child.newline) {
  16225. x += currentLineMaxSize + gap;
  16226. y = 0;
  16227. nextY = moveY;
  16228. currentLineMaxSize = rect.width;
  16229. } else {
  16230. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  16231. }
  16232. }
  16233. if (child.newline) {
  16234. return;
  16235. }
  16236. position[0] = x;
  16237. position[1] = y;
  16238. orient === 'horizontal' ? x = nextX + gap : y = nextY + gap;
  16239. });
  16240. }
  16241. /**
  16242. * VBox or HBox layouting
  16243. * @param {string} orient
  16244. * @param {module:zrender/container/Group} group
  16245. * @param {number} gap
  16246. * @param {number} [width=Infinity]
  16247. * @param {number} [height=Infinity]
  16248. */
  16249. var box = boxLayout;
  16250. /**
  16251. * VBox layouting
  16252. * @param {module:zrender/container/Group} group
  16253. * @param {number} gap
  16254. * @param {number} [width=Infinity]
  16255. * @param {number} [height=Infinity]
  16256. */
  16257. var vbox = curry(boxLayout, 'vertical');
  16258. /**
  16259. * HBox layouting
  16260. * @param {module:zrender/container/Group} group
  16261. * @param {number} gap
  16262. * @param {number} [width=Infinity]
  16263. * @param {number} [height=Infinity]
  16264. */
  16265. var hbox = curry(boxLayout, 'horizontal');
  16266. /**
  16267. * If x or x2 is not specified or 'center' 'left' 'right',
  16268. * the width would be as long as possible.
  16269. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  16270. * the height would be as long as possible.
  16271. *
  16272. * @param {Object} positionInfo
  16273. * @param {number|string} [positionInfo.x]
  16274. * @param {number|string} [positionInfo.y]
  16275. * @param {number|string} [positionInfo.x2]
  16276. * @param {number|string} [positionInfo.y2]
  16277. * @param {Object} containerRect {width, height}
  16278. * @param {string|number} margin
  16279. * @return {Object} {width, height}
  16280. */
  16281. /**
  16282. * Parse position info.
  16283. *
  16284. * @param {Object} positionInfo
  16285. * @param {number|string} [positionInfo.left]
  16286. * @param {number|string} [positionInfo.top]
  16287. * @param {number|string} [positionInfo.right]
  16288. * @param {number|string} [positionInfo.bottom]
  16289. * @param {number|string} [positionInfo.width]
  16290. * @param {number|string} [positionInfo.height]
  16291. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  16292. * @param {Object} containerRect
  16293. * @param {string|number} [margin]
  16294. *
  16295. * @return {module:zrender/core/BoundingRect}
  16296. */
  16297. function getLayoutRect(positionInfo, containerRect, margin) {
  16298. margin = normalizeCssArray$1(margin || 0);
  16299. var containerWidth = containerRect.width;
  16300. var containerHeight = containerRect.height;
  16301. var left = parsePercent$1(positionInfo.left, containerWidth);
  16302. var top = parsePercent$1(positionInfo.top, containerHeight);
  16303. var right = parsePercent$1(positionInfo.right, containerWidth);
  16304. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  16305. var width = parsePercent$1(positionInfo.width, containerWidth);
  16306. var height = parsePercent$1(positionInfo.height, containerHeight);
  16307. var verticalMargin = margin[2] + margin[0];
  16308. var horizontalMargin = margin[1] + margin[3];
  16309. var aspect = positionInfo.aspect; // If width is not specified, calculate width from left and right
  16310. if (isNaN(width)) {
  16311. width = containerWidth - right - horizontalMargin - left;
  16312. }
  16313. if (isNaN(height)) {
  16314. height = containerHeight - bottom - verticalMargin - top;
  16315. }
  16316. if (aspect != null) {
  16317. // If width and height are not given
  16318. // 1. Graph should not exceeds the container
  16319. // 2. Aspect must be keeped
  16320. // 3. Graph should take the space as more as possible
  16321. // FIXME
  16322. // Margin is not considered, because there is no case that both
  16323. // using margin and aspect so far.
  16324. if (isNaN(width) && isNaN(height)) {
  16325. if (aspect > containerWidth / containerHeight) {
  16326. width = containerWidth * 0.8;
  16327. } else {
  16328. height = containerHeight * 0.8;
  16329. }
  16330. } // Calculate width or height with given aspect
  16331. if (isNaN(width)) {
  16332. width = aspect * height;
  16333. }
  16334. if (isNaN(height)) {
  16335. height = width / aspect;
  16336. }
  16337. } // If left is not specified, calculate left from right and width
  16338. if (isNaN(left)) {
  16339. left = containerWidth - right - width - horizontalMargin;
  16340. }
  16341. if (isNaN(top)) {
  16342. top = containerHeight - bottom - height - verticalMargin;
  16343. } // Align left and top
  16344. switch (positionInfo.left || positionInfo.right) {
  16345. case 'center':
  16346. left = containerWidth / 2 - width / 2 - margin[3];
  16347. break;
  16348. case 'right':
  16349. left = containerWidth - width - horizontalMargin;
  16350. break;
  16351. }
  16352. switch (positionInfo.top || positionInfo.bottom) {
  16353. case 'middle':
  16354. case 'center':
  16355. top = containerHeight / 2 - height / 2 - margin[0];
  16356. break;
  16357. case 'bottom':
  16358. top = containerHeight - height - verticalMargin;
  16359. break;
  16360. } // If something is wrong and left, top, width, height are calculated as NaN
  16361. left = left || 0;
  16362. top = top || 0;
  16363. if (isNaN(width)) {
  16364. // Width may be NaN if only one value is given except width
  16365. width = containerWidth - horizontalMargin - left - (right || 0);
  16366. }
  16367. if (isNaN(height)) {
  16368. // Height may be NaN if only one value is given except height
  16369. height = containerHeight - verticalMargin - top - (bottom || 0);
  16370. }
  16371. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  16372. rect.margin = margin;
  16373. return rect;
  16374. }
  16375. /**
  16376. * Position a zr element in viewport
  16377. * Group position is specified by either
  16378. * {left, top}, {right, bottom}
  16379. * If all properties exists, right and bottom will be igonred.
  16380. *
  16381. * Logic:
  16382. * 1. Scale (against origin point in parent coord)
  16383. * 2. Rotate (against origin point in parent coord)
  16384. * 3. Traslate (with el.position by this method)
  16385. * So this method only fixes the last step 'Traslate', which does not affect
  16386. * scaling and rotating.
  16387. *
  16388. * If be called repeatly with the same input el, the same result will be gotten.
  16389. *
  16390. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  16391. * @param {Object} positionInfo
  16392. * @param {number|string} [positionInfo.left]
  16393. * @param {number|string} [positionInfo.top]
  16394. * @param {number|string} [positionInfo.right]
  16395. * @param {number|string} [positionInfo.bottom]
  16396. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  16397. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  16398. * @param {Object} containerRect
  16399. * @param {string|number} margin
  16400. * @param {Object} [opt]
  16401. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  16402. * @param {Array.<number>} [opt.boundingMode='all']
  16403. * Specify how to calculate boundingRect when locating.
  16404. * 'all': Position the boundingRect that is transformed and uioned
  16405. * both itself and its descendants.
  16406. * This mode simplies confine the elements in the bounding
  16407. * of their container (e.g., using 'right: 0').
  16408. * 'raw': Position the boundingRect that is not transformed and only itself.
  16409. * This mode is useful when you want a element can overflow its
  16410. * container. (Consider a rotated circle needs to be located in a corner.)
  16411. * In this mode positionInfo.width/height can only be number.
  16412. */
  16413. function positionElement(el, positionInfo, containerRect, margin, opt) {
  16414. var h = !opt || !opt.hv || opt.hv[0];
  16415. var v = !opt || !opt.hv || opt.hv[1];
  16416. var boundingMode = opt && opt.boundingMode || 'all';
  16417. if (!h && !v) {
  16418. return;
  16419. }
  16420. var rect;
  16421. if (boundingMode === 'raw') {
  16422. rect = el.type === 'group' ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0) : el.getBoundingRect();
  16423. } else {
  16424. rect = el.getBoundingRect();
  16425. if (el.needLocalTransform()) {
  16426. var transform = el.getLocalTransform(); // Notice: raw rect may be inner object of el,
  16427. // which should not be modified.
  16428. rect = rect.clone();
  16429. rect.applyTransform(transform);
  16430. }
  16431. } // The real width and height can not be specified but calculated by the given el.
  16432. positionInfo = getLayoutRect(defaults({
  16433. width: rect.width,
  16434. height: rect.height
  16435. }, positionInfo), containerRect, margin); // Because 'tranlate' is the last step in transform
  16436. // (see zrender/core/Transformable#getLocalTransform),
  16437. // we can just only modify el.position to get final result.
  16438. var elPos = el.position;
  16439. var dx = h ? positionInfo.x - rect.x : 0;
  16440. var dy = v ? positionInfo.y - rect.y : 0;
  16441. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  16442. }
  16443. /**
  16444. * @param {Object} option Contains some of the properties in HV_NAMES.
  16445. * @param {number} hvIdx 0: horizontal; 1: vertical.
  16446. */
  16447. /**
  16448. * Consider Case:
  16449. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  16450. * through setOption or media query, using normal zrUtil.merge will cause
  16451. * {right: 0} does not take effect.
  16452. *
  16453. * @example
  16454. * ComponentModel.extend({
  16455. * init: function () {
  16456. * ...
  16457. * var inputPositionParams = layout.getLayoutParams(option);
  16458. * this.mergeOption(inputPositionParams);
  16459. * },
  16460. * mergeOption: function (newOption) {
  16461. * newOption && zrUtil.merge(thisOption, newOption, true);
  16462. * layout.mergeLayoutParam(thisOption, newOption);
  16463. * }
  16464. * });
  16465. *
  16466. * @param {Object} targetOption
  16467. * @param {Object} newOption
  16468. * @param {Object|string} [opt]
  16469. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  16470. * that width (or height) should not be calculated by left and right (or top and bottom).
  16471. */
  16472. function mergeLayoutParam(targetOption, newOption, opt) {
  16473. !isObject$1(opt) && (opt = {});
  16474. var ignoreSize = opt.ignoreSize;
  16475. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  16476. var hResult = merge$$1(HV_NAMES[0], 0);
  16477. var vResult = merge$$1(HV_NAMES[1], 1);
  16478. copy(HV_NAMES[0], targetOption, hResult);
  16479. copy(HV_NAMES[1], targetOption, vResult);
  16480. function merge$$1(names, hvIdx) {
  16481. var newParams = {};
  16482. var newValueCount = 0;
  16483. var merged = {};
  16484. var mergedValueCount = 0;
  16485. var enoughParamNumber = 2;
  16486. each$3(names, function (name) {
  16487. merged[name] = targetOption[name];
  16488. });
  16489. each$3(names, function (name) {
  16490. // Consider case: newOption.width is null, which is
  16491. // set by user for removing width setting.
  16492. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  16493. hasValue(newParams, name) && newValueCount++;
  16494. hasValue(merged, name) && mergedValueCount++;
  16495. });
  16496. if (ignoreSize[hvIdx]) {
  16497. // Only one of left/right is premitted to exist.
  16498. if (hasValue(newOption, names[1])) {
  16499. merged[names[2]] = null;
  16500. } else if (hasValue(newOption, names[2])) {
  16501. merged[names[1]] = null;
  16502. }
  16503. return merged;
  16504. } // Case: newOption: {width: ..., right: ...},
  16505. // or targetOption: {right: ...} and newOption: {width: ...},
  16506. // There is no conflict when merged only has params count
  16507. // little than enoughParamNumber.
  16508. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  16509. return merged;
  16510. } // Case: newOption: {width: ..., right: ...},
  16511. // Than we can make sure user only want those two, and ignore
  16512. // all origin params in targetOption.
  16513. else if (newValueCount >= enoughParamNumber) {
  16514. return newParams;
  16515. } else {
  16516. // Chose another param from targetOption by priority.
  16517. for (var i = 0; i < names.length; i++) {
  16518. var name = names[i];
  16519. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  16520. newParams[name] = targetOption[name];
  16521. break;
  16522. }
  16523. }
  16524. return newParams;
  16525. }
  16526. }
  16527. function hasProp(obj, name) {
  16528. return obj.hasOwnProperty(name);
  16529. }
  16530. function hasValue(obj, name) {
  16531. return obj[name] != null && obj[name] !== 'auto';
  16532. }
  16533. function copy(names, target, source) {
  16534. each$3(names, function (name) {
  16535. target[name] = source[name];
  16536. });
  16537. }
  16538. }
  16539. /**
  16540. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  16541. * @param {Object} source
  16542. * @return {Object} Result contains those props.
  16543. */
  16544. function getLayoutParams(source) {
  16545. return copyLayoutParams({}, source);
  16546. }
  16547. /**
  16548. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  16549. * @param {Object} source
  16550. * @return {Object} Result contains those props.
  16551. */
  16552. function copyLayoutParams(target, source) {
  16553. source && target && each$3(LOCATION_PARAMS, function (name) {
  16554. source.hasOwnProperty(name) && (target[name] = source[name]);
  16555. });
  16556. return target;
  16557. }
  16558. /*
  16559. * Licensed to the Apache Software Foundation (ASF) under one
  16560. * or more contributor license agreements. See the NOTICE file
  16561. * distributed with this work for additional information
  16562. * regarding copyright ownership. The ASF licenses this file
  16563. * to you under the Apache License, Version 2.0 (the
  16564. * "License"); you may not use this file except in compliance
  16565. * with the License. You may obtain a copy of the License at
  16566. *
  16567. * http://www.apache.org/licenses/LICENSE-2.0
  16568. *
  16569. * Unless required by applicable law or agreed to in writing,
  16570. * software distributed under the License is distributed on an
  16571. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16572. * KIND, either express or implied. See the License for the
  16573. * specific language governing permissions and limitations
  16574. * under the License.
  16575. */
  16576. var boxLayoutMixin = {
  16577. getBoxLayoutParams: function () {
  16578. return {
  16579. left: this.get('left'),
  16580. top: this.get('top'),
  16581. right: this.get('right'),
  16582. bottom: this.get('bottom'),
  16583. width: this.get('width'),
  16584. height: this.get('height')
  16585. };
  16586. }
  16587. };
  16588. /*
  16589. * Licensed to the Apache Software Foundation (ASF) under one
  16590. * or more contributor license agreements. See the NOTICE file
  16591. * distributed with this work for additional information
  16592. * regarding copyright ownership. The ASF licenses this file
  16593. * to you under the Apache License, Version 2.0 (the
  16594. * "License"); you may not use this file except in compliance
  16595. * with the License. You may obtain a copy of the License at
  16596. *
  16597. * http://www.apache.org/licenses/LICENSE-2.0
  16598. *
  16599. * Unless required by applicable law or agreed to in writing,
  16600. * software distributed under the License is distributed on an
  16601. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16602. * KIND, either express or implied. See the License for the
  16603. * specific language governing permissions and limitations
  16604. * under the License.
  16605. */
  16606. /**
  16607. * Component model
  16608. *
  16609. * @module echarts/model/Component
  16610. */
  16611. var inner$1 = makeInner();
  16612. /**
  16613. * @alias module:echarts/model/Component
  16614. * @constructor
  16615. * @param {Object} option
  16616. * @param {module:echarts/model/Model} parentModel
  16617. * @param {module:echarts/model/Model} ecModel
  16618. */
  16619. var ComponentModel = Model.extend({
  16620. type: 'component',
  16621. /**
  16622. * @readOnly
  16623. * @type {string}
  16624. */
  16625. id: '',
  16626. /**
  16627. * Because simplified concept is probably better, series.name (or component.name)
  16628. * has been having too many resposibilities:
  16629. * (1) Generating id (which requires name in option should not be modified).
  16630. * (2) As an index to mapping series when merging option or calling API (a name
  16631. * can refer to more then one components, which is convinient is some case).
  16632. * (3) Display.
  16633. * @readOnly
  16634. */
  16635. name: '',
  16636. /**
  16637. * @readOnly
  16638. * @type {string}
  16639. */
  16640. mainType: '',
  16641. /**
  16642. * @readOnly
  16643. * @type {string}
  16644. */
  16645. subType: '',
  16646. /**
  16647. * @readOnly
  16648. * @type {number}
  16649. */
  16650. componentIndex: 0,
  16651. /**
  16652. * @type {Object}
  16653. * @protected
  16654. */
  16655. defaultOption: null,
  16656. /**
  16657. * @type {module:echarts/model/Global}
  16658. * @readOnly
  16659. */
  16660. ecModel: null,
  16661. /**
  16662. * key: componentType
  16663. * value: Component model list, can not be null.
  16664. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  16665. * @readOnly
  16666. */
  16667. dependentModels: [],
  16668. /**
  16669. * @type {string}
  16670. * @readOnly
  16671. */
  16672. uid: null,
  16673. /**
  16674. * Support merge layout params.
  16675. * Only support 'box' now (left/right/top/bottom/width/height).
  16676. * @type {string|Object} Object can be {ignoreSize: true}
  16677. * @readOnly
  16678. */
  16679. layoutMode: null,
  16680. $constructor: function (option, parentModel, ecModel, extraOpt) {
  16681. Model.call(this, option, parentModel, ecModel, extraOpt);
  16682. this.uid = getUID('ec_cpt_model');
  16683. },
  16684. init: function (option, parentModel, ecModel, extraOpt) {
  16685. this.mergeDefaultAndTheme(option, ecModel);
  16686. },
  16687. mergeDefaultAndTheme: function (option, ecModel) {
  16688. var layoutMode = this.layoutMode;
  16689. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  16690. var themeModel = ecModel.getTheme();
  16691. merge(option, themeModel.get(this.mainType));
  16692. merge(option, this.getDefaultOption());
  16693. if (layoutMode) {
  16694. mergeLayoutParam(option, inputPositionParams, layoutMode);
  16695. }
  16696. },
  16697. mergeOption: function (option, extraOpt) {
  16698. merge(this.option, option, true);
  16699. var layoutMode = this.layoutMode;
  16700. if (layoutMode) {
  16701. mergeLayoutParam(this.option, option, layoutMode);
  16702. }
  16703. },
  16704. // Hooker after init or mergeOption
  16705. optionUpdated: function (newCptOption, isInit) {},
  16706. getDefaultOption: function () {
  16707. var fields = inner$1(this);
  16708. if (!fields.defaultOption) {
  16709. var optList = [];
  16710. var Class = this.constructor;
  16711. while (Class) {
  16712. var opt = Class.prototype.defaultOption;
  16713. opt && optList.push(opt);
  16714. Class = Class.superClass;
  16715. }
  16716. var defaultOption = {};
  16717. for (var i = optList.length - 1; i >= 0; i--) {
  16718. defaultOption = merge(defaultOption, optList[i], true);
  16719. }
  16720. fields.defaultOption = defaultOption;
  16721. }
  16722. return fields.defaultOption;
  16723. },
  16724. getReferringComponents: function (mainType) {
  16725. return this.ecModel.queryComponents({
  16726. mainType: mainType,
  16727. index: this.get(mainType + 'Index', true),
  16728. id: this.get(mainType + 'Id', true)
  16729. });
  16730. }
  16731. }); // Reset ComponentModel.extend, add preConstruct.
  16732. // clazzUtil.enableClassExtend(
  16733. // ComponentModel,
  16734. // function (option, parentModel, ecModel, extraOpt) {
  16735. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  16736. // zrUtil.extend(this, extraOpt);
  16737. // this.uid = componentUtil.getUID('componentModel');
  16738. // // this.setReadOnly([
  16739. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  16740. // // 'dependentModels', 'componentIndex'
  16741. // // ]);
  16742. // }
  16743. // );
  16744. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  16745. enableClassManagement(ComponentModel, {
  16746. registerWhenExtend: true
  16747. });
  16748. enableSubTypeDefaulter(ComponentModel); // Add capability of ComponentModel.topologicalTravel.
  16749. enableTopologicalTravel(ComponentModel, getDependencies);
  16750. function getDependencies(componentType) {
  16751. var deps = [];
  16752. each$1(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  16753. deps = deps.concat(Clazz.prototype.dependencies || []);
  16754. }); // Ensure main type.
  16755. deps = map(deps, function (type) {
  16756. return parseClassType$1(type).main;
  16757. }); // Hack dataset for convenience.
  16758. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  16759. deps.unshift('dataset');
  16760. }
  16761. return deps;
  16762. }
  16763. mixin(ComponentModel, boxLayoutMixin);
  16764. /*
  16765. * Licensed to the Apache Software Foundation (ASF) under one
  16766. * or more contributor license agreements. See the NOTICE file
  16767. * distributed with this work for additional information
  16768. * regarding copyright ownership. The ASF licenses this file
  16769. * to you under the Apache License, Version 2.0 (the
  16770. * "License"); you may not use this file except in compliance
  16771. * with the License. You may obtain a copy of the License at
  16772. *
  16773. * http://www.apache.org/licenses/LICENSE-2.0
  16774. *
  16775. * Unless required by applicable law or agreed to in writing,
  16776. * software distributed under the License is distributed on an
  16777. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16778. * KIND, either express or implied. See the License for the
  16779. * specific language governing permissions and limitations
  16780. * under the License.
  16781. */
  16782. var platform = ''; // Navigator not exists in node
  16783. if (typeof navigator !== 'undefined') {
  16784. platform = navigator.platform || '';
  16785. }
  16786. var globalDefault = {
  16787. // backgroundColor: 'rgba(0,0,0,0)',
  16788. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  16789. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  16790. // Light colors:
  16791. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  16792. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  16793. // Dark colors:
  16794. color: ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
  16795. gradientColor: ['#f6efa6', '#d88273', '#bf444c'],
  16796. // If xAxis and yAxis declared, grid is created by default.
  16797. // grid: {},
  16798. textStyle: {
  16799. // color: '#000',
  16800. // decoration: 'none',
  16801. // PENDING
  16802. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  16803. // fontFamily: 'Arial, Verdana, sans-serif',
  16804. fontSize: 12,
  16805. fontStyle: 'normal',
  16806. fontWeight: 'normal'
  16807. },
  16808. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  16809. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  16810. // Default is source-over
  16811. blendMode: null,
  16812. animation: 'auto',
  16813. animationDuration: 1000,
  16814. animationDurationUpdate: 300,
  16815. animationEasing: 'exponentialOut',
  16816. animationEasingUpdate: 'cubicOut',
  16817. animationThreshold: 2000,
  16818. // Configuration for progressive/incremental rendering
  16819. progressiveThreshold: 3000,
  16820. progressive: 400,
  16821. // Threshold of if use single hover layer to optimize.
  16822. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  16823. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  16824. // which is unexpected.
  16825. // see example <echarts/test/heatmap-large.html>.
  16826. hoverLayerThreshold: 3000,
  16827. // See: module:echarts/scale/Time
  16828. useUTC: false
  16829. };
  16830. /*
  16831. * Licensed to the Apache Software Foundation (ASF) under one
  16832. * or more contributor license agreements. See the NOTICE file
  16833. * distributed with this work for additional information
  16834. * regarding copyright ownership. The ASF licenses this file
  16835. * to you under the Apache License, Version 2.0 (the
  16836. * "License"); you may not use this file except in compliance
  16837. * with the License. You may obtain a copy of the License at
  16838. *
  16839. * http://www.apache.org/licenses/LICENSE-2.0
  16840. *
  16841. * Unless required by applicable law or agreed to in writing,
  16842. * software distributed under the License is distributed on an
  16843. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16844. * KIND, either express or implied. See the License for the
  16845. * specific language governing permissions and limitations
  16846. * under the License.
  16847. */
  16848. var inner$2 = makeInner();
  16849. function getNearestColorPalette(colors, requestColorNum) {
  16850. var paletteNum = colors.length; // TODO colors must be in order
  16851. for (var i = 0; i < paletteNum; i++) {
  16852. if (colors[i].length > requestColorNum) {
  16853. return colors[i];
  16854. }
  16855. }
  16856. return colors[paletteNum - 1];
  16857. }
  16858. var colorPaletteMixin = {
  16859. clearColorPalette: function () {
  16860. inner$2(this).colorIdx = 0;
  16861. inner$2(this).colorNameMap = {};
  16862. },
  16863. /**
  16864. * @param {string} name MUST NOT be null/undefined. Otherwise call this function
  16865. * twise with the same parameters will get different result.
  16866. * @param {Object} [scope=this]
  16867. * @param {Object} [requestColorNum]
  16868. * @return {string} color string.
  16869. */
  16870. getColorFromPalette: function (name, scope, requestColorNum) {
  16871. scope = scope || this;
  16872. var scopeFields = inner$2(scope);
  16873. var colorIdx = scopeFields.colorIdx || 0;
  16874. var colorNameMap = scopeFields.colorNameMap = scopeFields.colorNameMap || {}; // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  16875. if (colorNameMap.hasOwnProperty(name)) {
  16876. return colorNameMap[name];
  16877. }
  16878. var defaultColorPalette = normalizeToArray(this.get('color', true));
  16879. var layeredColorPalette = this.get('colorLayer', true);
  16880. var colorPalette = requestColorNum == null || !layeredColorPalette ? defaultColorPalette : getNearestColorPalette(layeredColorPalette, requestColorNum); // In case can't find in layered color palette.
  16881. colorPalette = colorPalette || defaultColorPalette;
  16882. if (!colorPalette || !colorPalette.length) {
  16883. return;
  16884. }
  16885. var color = colorPalette[colorIdx];
  16886. if (name) {
  16887. colorNameMap[name] = color;
  16888. }
  16889. scopeFields.colorIdx = (colorIdx + 1) % colorPalette.length;
  16890. return color;
  16891. }
  16892. };
  16893. /*
  16894. * Licensed to the Apache Software Foundation (ASF) under one
  16895. * or more contributor license agreements. See the NOTICE file
  16896. * distributed with this work for additional information
  16897. * regarding copyright ownership. The ASF licenses this file
  16898. * to you under the Apache License, Version 2.0 (the
  16899. * "License"); you may not use this file except in compliance
  16900. * with the License. You may obtain a copy of the License at
  16901. *
  16902. * http://www.apache.org/licenses/LICENSE-2.0
  16903. *
  16904. * Unless required by applicable law or agreed to in writing,
  16905. * software distributed under the License is distributed on an
  16906. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16907. * KIND, either express or implied. See the License for the
  16908. * specific language governing permissions and limitations
  16909. * under the License.
  16910. */
  16911. // Avoid typo.
  16912. var SOURCE_FORMAT_ORIGINAL = 'original';
  16913. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  16914. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  16915. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  16916. var SOURCE_FORMAT_UNKNOWN = 'unknown'; // ??? CHANGE A NAME
  16917. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  16918. var SERIES_LAYOUT_BY_COLUMN = 'column';
  16919. var SERIES_LAYOUT_BY_ROW = 'row';
  16920. /*
  16921. * Licensed to the Apache Software Foundation (ASF) under one
  16922. * or more contributor license agreements. See the NOTICE file
  16923. * distributed with this work for additional information
  16924. * regarding copyright ownership. The ASF licenses this file
  16925. * to you under the Apache License, Version 2.0 (the
  16926. * "License"); you may not use this file except in compliance
  16927. * with the License. You may obtain a copy of the License at
  16928. *
  16929. * http://www.apache.org/licenses/LICENSE-2.0
  16930. *
  16931. * Unless required by applicable law or agreed to in writing,
  16932. * software distributed under the License is distributed on an
  16933. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16934. * KIND, either express or implied. See the License for the
  16935. * specific language governing permissions and limitations
  16936. * under the License.
  16937. */
  16938. /**
  16939. * [sourceFormat]
  16940. *
  16941. * + "original":
  16942. * This format is only used in series.data, where
  16943. * itemStyle can be specified in data item.
  16944. *
  16945. * + "arrayRows":
  16946. * [
  16947. * ['product', 'score', 'amount'],
  16948. * ['Matcha Latte', 89.3, 95.8],
  16949. * ['Milk Tea', 92.1, 89.4],
  16950. * ['Cheese Cocoa', 94.4, 91.2],
  16951. * ['Walnut Brownie', 85.4, 76.9]
  16952. * ]
  16953. *
  16954. * + "objectRows":
  16955. * [
  16956. * {product: 'Matcha Latte', score: 89.3, amount: 95.8},
  16957. * {product: 'Milk Tea', score: 92.1, amount: 89.4},
  16958. * {product: 'Cheese Cocoa', score: 94.4, amount: 91.2},
  16959. * {product: 'Walnut Brownie', score: 85.4, amount: 76.9}
  16960. * ]
  16961. *
  16962. * + "keyedColumns":
  16963. * {
  16964. * 'product': ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
  16965. * 'count': [823, 235, 1042, 988],
  16966. * 'score': [95.8, 81.4, 91.2, 76.9]
  16967. * }
  16968. *
  16969. * + "typedArray"
  16970. *
  16971. * + "unknown"
  16972. */
  16973. /**
  16974. * @constructor
  16975. * @param {Object} fields
  16976. * @param {string} fields.sourceFormat
  16977. * @param {Array|Object} fields.fromDataset
  16978. * @param {Array|Object} [fields.data]
  16979. * @param {string} [seriesLayoutBy='column']
  16980. * @param {Array.<Object|string>} [dimensionsDefine]
  16981. * @param {Objet|HashMap} [encodeDefine]
  16982. * @param {number} [startIndex=0]
  16983. * @param {number} [dimensionsDetectCount]
  16984. */
  16985. function Source(fields) {
  16986. /**
  16987. * @type {boolean}
  16988. */
  16989. this.fromDataset = fields.fromDataset;
  16990. /**
  16991. * Not null/undefined.
  16992. * @type {Array|Object}
  16993. */
  16994. this.data = fields.data || (fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []);
  16995. /**
  16996. * See also "detectSourceFormat".
  16997. * Not null/undefined.
  16998. * @type {string}
  16999. */
  17000. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
  17001. /**
  17002. * 'row' or 'column'
  17003. * Not null/undefined.
  17004. * @type {string} seriesLayoutBy
  17005. */
  17006. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  17007. /**
  17008. * dimensions definition in option.
  17009. * can be null/undefined.
  17010. * @type {Array.<Object|string>}
  17011. */
  17012. this.dimensionsDefine = fields.dimensionsDefine;
  17013. /**
  17014. * encode definition in option.
  17015. * can be null/undefined.
  17016. * @type {Objet|HashMap}
  17017. */
  17018. this.encodeDefine = fields.encodeDefine && createHashMap(fields.encodeDefine);
  17019. /**
  17020. * Not null/undefined, uint.
  17021. * @type {number}
  17022. */
  17023. this.startIndex = fields.startIndex || 0;
  17024. /**
  17025. * Can be null/undefined (when unknown), uint.
  17026. * @type {number}
  17027. */
  17028. this.dimensionsDetectCount = fields.dimensionsDetectCount;
  17029. }
  17030. /**
  17031. * Wrap original series data for some compatibility cases.
  17032. */
  17033. Source.seriesDataToSource = function (data) {
  17034. return new Source({
  17035. data: data,
  17036. sourceFormat: isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL,
  17037. fromDataset: false
  17038. });
  17039. };
  17040. enableClassCheck(Source);
  17041. /*
  17042. * Licensed to the Apache Software Foundation (ASF) under one
  17043. * or more contributor license agreements. See the NOTICE file
  17044. * distributed with this work for additional information
  17045. * regarding copyright ownership. The ASF licenses this file
  17046. * to you under the Apache License, Version 2.0 (the
  17047. * "License"); you may not use this file except in compliance
  17048. * with the License. You may obtain a copy of the License at
  17049. *
  17050. * http://www.apache.org/licenses/LICENSE-2.0
  17051. *
  17052. * Unless required by applicable law or agreed to in writing,
  17053. * software distributed under the License is distributed on an
  17054. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17055. * KIND, either express or implied. See the License for the
  17056. * specific language governing permissions and limitations
  17057. * under the License.
  17058. */
  17059. var BE_ORDINAL = {
  17060. Must: 1,
  17061. // Encounter string but not '-' and not number-like.
  17062. Might: 2,
  17063. // Encounter string but number-like.
  17064. Not: 3 // Other cases
  17065. };
  17066. var inner$3 = makeInner();
  17067. /**
  17068. * @see {module:echarts/data/Source}
  17069. * @param {module:echarts/component/dataset/DatasetModel} datasetModel
  17070. * @return {string} sourceFormat
  17071. */
  17072. function detectSourceFormat(datasetModel) {
  17073. var data = datasetModel.option.source;
  17074. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  17075. if (isTypedArray(data)) {
  17076. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  17077. } else if (isArray(data)) {
  17078. // FIXME Whether tolerate null in top level array?
  17079. if (data.length === 0) {
  17080. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17081. }
  17082. for (var i = 0, len = data.length; i < len; i++) {
  17083. var item = data[i];
  17084. if (item == null) {
  17085. continue;
  17086. } else if (isArray(item)) {
  17087. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  17088. break;
  17089. } else if (isObject$1(item)) {
  17090. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  17091. break;
  17092. }
  17093. }
  17094. } else if (isObject$1(data)) {
  17095. for (var key in data) {
  17096. if (data.hasOwnProperty(key) && isArrayLike(data[key])) {
  17097. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  17098. break;
  17099. }
  17100. }
  17101. } else if (data != null) {
  17102. throw new Error('Invalid data');
  17103. }
  17104. inner$3(datasetModel).sourceFormat = sourceFormat;
  17105. }
  17106. /**
  17107. * [Scenarios]:
  17108. * (1) Provide source data directly:
  17109. * series: {
  17110. * encode: {...},
  17111. * dimensions: [...]
  17112. * seriesLayoutBy: 'row',
  17113. * data: [[...]]
  17114. * }
  17115. * (2) Refer to datasetModel.
  17116. * series: [{
  17117. * encode: {...}
  17118. * // Ignore datasetIndex means `datasetIndex: 0`
  17119. * // and the dimensions defination in dataset is used
  17120. * }, {
  17121. * encode: {...},
  17122. * seriesLayoutBy: 'column',
  17123. * datasetIndex: 1
  17124. * }]
  17125. *
  17126. * Get data from series itself or datset.
  17127. * @return {module:echarts/data/Source} source
  17128. */
  17129. function getSource(seriesModel) {
  17130. return inner$3(seriesModel).source;
  17131. }
  17132. /**
  17133. * MUST be called before mergeOption of all series.
  17134. * @param {module:echarts/model/Global} ecModel
  17135. */
  17136. function resetSourceDefaulter(ecModel) {
  17137. // `datasetMap` is used to make default encode.
  17138. inner$3(ecModel).datasetMap = createHashMap();
  17139. }
  17140. /**
  17141. * [Caution]:
  17142. * MUST be called after series option merged and
  17143. * before "series.getInitailData()" called.
  17144. *
  17145. * [The rule of making default encode]:
  17146. * Category axis (if exists) alway map to the first dimension.
  17147. * Each other axis occupies a subsequent dimension.
  17148. *
  17149. * [Why make default encode]:
  17150. * Simplify the typing of encode in option, avoiding the case like that:
  17151. * series: [{encode: {x: 0, y: 1}}, {encode: {x: 0, y: 2}}, {encode: {x: 0, y: 3}}],
  17152. * where the "y" have to be manually typed as "1, 2, 3, ...".
  17153. *
  17154. * @param {module:echarts/model/Series} seriesModel
  17155. */
  17156. function prepareSource(seriesModel) {
  17157. var seriesOption = seriesModel.option;
  17158. var data = seriesOption.data;
  17159. var sourceFormat = isTypedArray(data) ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  17160. var fromDataset = false;
  17161. var seriesLayoutBy = seriesOption.seriesLayoutBy;
  17162. var sourceHeader = seriesOption.sourceHeader;
  17163. var dimensionsDefine = seriesOption.dimensions;
  17164. var datasetModel = getDatasetModel(seriesModel);
  17165. if (datasetModel) {
  17166. var datasetOption = datasetModel.option;
  17167. data = datasetOption.source;
  17168. sourceFormat = inner$3(datasetModel).sourceFormat;
  17169. fromDataset = true; // These settings from series has higher priority.
  17170. seriesLayoutBy = seriesLayoutBy || datasetOption.seriesLayoutBy;
  17171. sourceHeader == null && (sourceHeader = datasetOption.sourceHeader);
  17172. dimensionsDefine = dimensionsDefine || datasetOption.dimensions;
  17173. }
  17174. var completeResult = completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine);
  17175. inner$3(seriesModel).source = new Source({
  17176. data: data,
  17177. fromDataset: fromDataset,
  17178. seriesLayoutBy: seriesLayoutBy,
  17179. sourceFormat: sourceFormat,
  17180. dimensionsDefine: completeResult.dimensionsDefine,
  17181. startIndex: completeResult.startIndex,
  17182. dimensionsDetectCount: completeResult.dimensionsDetectCount,
  17183. // Note: dataset option does not have `encode`.
  17184. encodeDefine: seriesOption.encode
  17185. });
  17186. } // return {startIndex, dimensionsDefine, dimensionsCount}
  17187. function completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine) {
  17188. if (!data) {
  17189. return {
  17190. dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine)
  17191. };
  17192. }
  17193. var dimensionsDetectCount;
  17194. var startIndex;
  17195. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  17196. // Rule: Most of the first line are string: it is header.
  17197. // Caution: consider a line with 5 string and 1 number,
  17198. // it still can not be sure it is a head, because the
  17199. // 5 string may be 5 values of category columns.
  17200. if (sourceHeader === 'auto' || sourceHeader == null) {
  17201. arrayRowsTravelFirst(function (val) {
  17202. // '-' is regarded as null/undefined.
  17203. if (val != null && val !== '-') {
  17204. if (isString(val)) {
  17205. startIndex == null && (startIndex = 1);
  17206. } else {
  17207. startIndex = 0;
  17208. }
  17209. } // 10 is an experience number, avoid long loop.
  17210. }, seriesLayoutBy, data, 10);
  17211. } else {
  17212. startIndex = sourceHeader ? 1 : 0;
  17213. }
  17214. if (!dimensionsDefine && startIndex === 1) {
  17215. dimensionsDefine = [];
  17216. arrayRowsTravelFirst(function (val, index) {
  17217. dimensionsDefine[index] = val != null ? val : '';
  17218. }, seriesLayoutBy, data);
  17219. }
  17220. dimensionsDetectCount = dimensionsDefine ? dimensionsDefine.length : seriesLayoutBy === SERIES_LAYOUT_BY_ROW ? data.length : data[0] ? data[0].length : null;
  17221. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  17222. if (!dimensionsDefine) {
  17223. dimensionsDefine = objectRowsCollectDimensions(data);
  17224. }
  17225. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17226. if (!dimensionsDefine) {
  17227. dimensionsDefine = [];
  17228. each$1(data, function (colArr, key) {
  17229. dimensionsDefine.push(key);
  17230. });
  17231. }
  17232. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  17233. var value0 = getDataItemValue(data[0]);
  17234. dimensionsDetectCount = isArray(value0) && value0.length || 1;
  17235. } else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {}
  17236. return {
  17237. startIndex: startIndex,
  17238. dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine),
  17239. dimensionsDetectCount: dimensionsDetectCount
  17240. };
  17241. } // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  17242. // which is reasonable. But dimension name is duplicated.
  17243. // Returns undefined or an array contains only object without null/undefiend or string.
  17244. function normalizeDimensionsDefine(dimensionsDefine) {
  17245. if (!dimensionsDefine) {
  17246. // The meaning of null/undefined is different from empty array.
  17247. return;
  17248. }
  17249. var nameMap = createHashMap();
  17250. return map(dimensionsDefine, function (item, index) {
  17251. item = extend({}, isObject$1(item) ? item : {
  17252. name: item
  17253. }); // User can set null in dimensions.
  17254. // We dont auto specify name, othewise a given name may
  17255. // cause it be refered unexpectedly.
  17256. if (item.name == null) {
  17257. return item;
  17258. } // Also consider number form like 2012.
  17259. item.name += ''; // User may also specify displayName.
  17260. // displayName will always exists except user not
  17261. // specified or dim name is not specified or detected.
  17262. // (A auto generated dim name will not be used as
  17263. // displayName).
  17264. if (item.displayName == null) {
  17265. item.displayName = item.name;
  17266. }
  17267. var exist = nameMap.get(item.name);
  17268. if (!exist) {
  17269. nameMap.set(item.name, {
  17270. count: 1
  17271. });
  17272. } else {
  17273. item.name += '-' + exist.count++;
  17274. }
  17275. return item;
  17276. });
  17277. }
  17278. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  17279. maxLoop == null && (maxLoop = Infinity);
  17280. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  17281. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17282. cb(data[i] ? data[i][0] : null, i);
  17283. }
  17284. } else {
  17285. var value0 = data[0] || [];
  17286. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  17287. cb(value0[i], i);
  17288. }
  17289. }
  17290. }
  17291. function objectRowsCollectDimensions(data) {
  17292. var firstIndex = 0;
  17293. var obj;
  17294. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  17295. if (obj) {
  17296. var dimensions = [];
  17297. each$1(obj, function (value, key) {
  17298. dimensions.push(key);
  17299. });
  17300. return dimensions;
  17301. }
  17302. }
  17303. /**
  17304. * [The strategy of the arrengment of data dimensions for dataset]:
  17305. * "value way": all axes are non-category axes. So series one by one take
  17306. * several (the number is coordSysDims.length) dimensions from dataset.
  17307. * The result of data arrengment of data dimensions like:
  17308. * | ser0_x | ser0_y | ser1_x | ser1_y | ser2_x | ser2_y |
  17309. * "category way": at least one axis is category axis. So the the first data
  17310. * dimension is always mapped to the first category axis and shared by
  17311. * all of the series. The other data dimensions are taken by series like
  17312. * "value way" does.
  17313. * The result of data arrengment of data dimensions like:
  17314. * | ser_shared_x | ser0_y | ser1_y | ser2_y |
  17315. *
  17316. * @param {Array.<Object|string>} coordDimensions [{name: <string>, type: <string>, dimsDef: <Array>}, ...]
  17317. * @param {module:model/Series} seriesModel
  17318. * @param {module:data/Source} source
  17319. * @return {Object} encode Never be `null/undefined`.
  17320. */
  17321. function makeSeriesEncodeForAxisCoordSys(coordDimensions, seriesModel, source) {
  17322. var encode = {};
  17323. var datasetModel = getDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur.
  17324. if (!datasetModel || !coordDimensions) {
  17325. return encode;
  17326. }
  17327. var encodeItemName = [];
  17328. var encodeSeriesName = [];
  17329. var ecModel = seriesModel.ecModel;
  17330. var datasetMap = inner$3(ecModel).datasetMap;
  17331. var key = datasetModel.uid + '_' + source.seriesLayoutBy;
  17332. var baseCategoryDimIndex;
  17333. var categoryWayValueDimStart;
  17334. coordDimensions = coordDimensions.slice();
  17335. each$1(coordDimensions, function (coordDimInfo, coordDimIdx) {
  17336. !isObject$1(coordDimInfo) && (coordDimensions[coordDimIdx] = {
  17337. name: coordDimInfo
  17338. });
  17339. if (coordDimInfo.type === 'ordinal' && baseCategoryDimIndex == null) {
  17340. baseCategoryDimIndex = coordDimIdx;
  17341. categoryWayValueDimStart = getDataDimCountOnCoordDim(coordDimensions[coordDimIdx]);
  17342. }
  17343. encode[coordDimInfo.name] = [];
  17344. });
  17345. var datasetRecord = datasetMap.get(key) || datasetMap.set(key, {
  17346. categoryWayDim: categoryWayValueDimStart,
  17347. valueWayDim: 0
  17348. }); // TODO
  17349. // Auto detect first time axis and do arrangement.
  17350. each$1(coordDimensions, function (coordDimInfo, coordDimIdx) {
  17351. var coordDimName = coordDimInfo.name;
  17352. var count = getDataDimCountOnCoordDim(coordDimInfo); // In value way.
  17353. if (baseCategoryDimIndex == null) {
  17354. var start = datasetRecord.valueWayDim;
  17355. pushDim(encode[coordDimName], start, count);
  17356. pushDim(encodeSeriesName, start, count);
  17357. datasetRecord.valueWayDim += count; // ??? TODO give a better default series name rule?
  17358. // especially when encode x y specified.
  17359. // consider: when mutiple series share one dimension
  17360. // category axis, series name should better use
  17361. // the other dimsion name. On the other hand, use
  17362. // both dimensions name.
  17363. } // In category way, the first category axis.
  17364. else if (baseCategoryDimIndex === coordDimIdx) {
  17365. pushDim(encode[coordDimName], 0, count);
  17366. pushDim(encodeItemName, 0, count);
  17367. } // In category way, the other axis.
  17368. else {
  17369. var start = datasetRecord.categoryWayDim;
  17370. pushDim(encode[coordDimName], start, count);
  17371. pushDim(encodeSeriesName, start, count);
  17372. datasetRecord.categoryWayDim += count;
  17373. }
  17374. });
  17375. function pushDim(dimIdxArr, idxFrom, idxCount) {
  17376. for (var i = 0; i < idxCount; i++) {
  17377. dimIdxArr.push(idxFrom + i);
  17378. }
  17379. }
  17380. function getDataDimCountOnCoordDim(coordDimInfo) {
  17381. var dimsDef = coordDimInfo.dimsDef;
  17382. return dimsDef ? dimsDef.length : 1;
  17383. }
  17384. encodeItemName.length && (encode.itemName = encodeItemName);
  17385. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  17386. return encode;
  17387. }
  17388. /**
  17389. * Work for data like [{name: ..., value: ...}, ...].
  17390. *
  17391. * @param {module:model/Series} seriesModel
  17392. * @param {module:data/Source} source
  17393. * @return {Object} encode Never be `null/undefined`.
  17394. */
  17395. function makeSeriesEncodeForNameBased(seriesModel, source, dimCount) {
  17396. var encode = {};
  17397. var datasetModel = getDatasetModel(seriesModel); // Currently only make default when using dataset, util more reqirements occur.
  17398. if (!datasetModel) {
  17399. return encode;
  17400. }
  17401. var sourceFormat = source.sourceFormat;
  17402. var dimensionsDefine = source.dimensionsDefine;
  17403. var potentialNameDimIndex;
  17404. if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS || sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17405. each$1(dimensionsDefine, function (dim, idx) {
  17406. if ((isObject$1(dim) ? dim.name : dim) === 'name') {
  17407. potentialNameDimIndex = idx;
  17408. }
  17409. });
  17410. } // idxResult: {v, n}.
  17411. var idxResult = function () {
  17412. var idxRes0 = {};
  17413. var idxRes1 = {};
  17414. var guessRecords = []; // 5 is an experience value.
  17415. for (var i = 0, len = Math.min(5, dimCount); i < len; i++) {
  17416. var guessResult = doGuessOrdinal(source.data, sourceFormat, source.seriesLayoutBy, dimensionsDefine, source.startIndex, i);
  17417. guessRecords.push(guessResult);
  17418. var isPureNumber = guessResult === BE_ORDINAL.Not; // [Strategy of idxRes0]: find the first BE_ORDINAL.Not as the value dim,
  17419. // and then find a name dim with the priority:
  17420. // "BE_ORDINAL.Might|BE_ORDINAL.Must" > "other dim" > "the value dim itself".
  17421. if (isPureNumber && idxRes0.v == null && i !== potentialNameDimIndex) {
  17422. idxRes0.v = i;
  17423. }
  17424. if (idxRes0.n == null || idxRes0.n === idxRes0.v || !isPureNumber && guessRecords[idxRes0.n] === BE_ORDINAL.Not) {
  17425. idxRes0.n = i;
  17426. }
  17427. if (fulfilled(idxRes0) && guessRecords[idxRes0.n] !== BE_ORDINAL.Not) {
  17428. return idxRes0;
  17429. } // [Strategy of idxRes1]: if idxRes0 not satisfied (that is, no BE_ORDINAL.Not),
  17430. // find the first BE_ORDINAL.Might as the value dim,
  17431. // and then find a name dim with the priority:
  17432. // "other dim" > "the value dim itself".
  17433. // That is for backward compat: number-like (e.g., `'3'`, `'55'`) can be
  17434. // treated as number.
  17435. if (!isPureNumber) {
  17436. if (guessResult === BE_ORDINAL.Might && idxRes1.v == null && i !== potentialNameDimIndex) {
  17437. idxRes1.v = i;
  17438. }
  17439. if (idxRes1.n == null || idxRes1.n === idxRes1.v) {
  17440. idxRes1.n = i;
  17441. }
  17442. }
  17443. }
  17444. function fulfilled(idxResult) {
  17445. return idxResult.v != null && idxResult.n != null;
  17446. }
  17447. return fulfilled(idxRes0) ? idxRes0 : fulfilled(idxRes1) ? idxRes1 : null;
  17448. }();
  17449. if (idxResult) {
  17450. encode.value = idxResult.v; // `potentialNameDimIndex` has highest priority.
  17451. var nameDimIndex = potentialNameDimIndex != null ? potentialNameDimIndex : idxResult.n; // By default, label use itemName in charts.
  17452. // So we dont set encodeLabel here.
  17453. encode.itemName = [nameDimIndex];
  17454. encode.seriesName = [nameDimIndex];
  17455. }
  17456. return encode;
  17457. }
  17458. /**
  17459. * If return null/undefined, indicate that should not use datasetModel.
  17460. */
  17461. function getDatasetModel(seriesModel) {
  17462. var option = seriesModel.option; // Caution: consider the scenario:
  17463. // A dataset is declared and a series is not expected to use the dataset,
  17464. // and at the beginning `setOption({series: { noData })` (just prepare other
  17465. // option but no data), then `setOption({series: {data: [...]}); In this case,
  17466. // the user should set an empty array to avoid that dataset is used by default.
  17467. var thisData = option.data;
  17468. if (!thisData) {
  17469. return seriesModel.ecModel.getComponent('dataset', option.datasetIndex || 0);
  17470. }
  17471. }
  17472. /**
  17473. * The rule should not be complex, otherwise user might not
  17474. * be able to known where the data is wrong.
  17475. * The code is ugly, but how to make it neat?
  17476. *
  17477. * @param {module:echars/data/Source} source
  17478. * @param {number} dimIndex
  17479. * @return {BE_ORDINAL} guess result.
  17480. */
  17481. function guessOrdinal(source, dimIndex) {
  17482. return doGuessOrdinal(source.data, source.sourceFormat, source.seriesLayoutBy, source.dimensionsDefine, source.startIndex, dimIndex);
  17483. } // dimIndex may be overflow source data.
  17484. // return {BE_ORDINAL}
  17485. function doGuessOrdinal(data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex) {
  17486. var result; // Experience value.
  17487. var maxLoop = 5;
  17488. if (isTypedArray(data)) {
  17489. return BE_ORDINAL.Not;
  17490. } // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  17491. // always exists in source.
  17492. var dimName;
  17493. var dimType;
  17494. if (dimensionsDefine) {
  17495. var dimDefItem = dimensionsDefine[dimIndex];
  17496. if (isObject$1(dimDefItem)) {
  17497. dimName = dimDefItem.name;
  17498. dimType = dimDefItem.type;
  17499. } else if (isString(dimDefItem)) {
  17500. dimName = dimDefItem;
  17501. }
  17502. }
  17503. if (dimType != null) {
  17504. return dimType === 'ordinal' ? BE_ORDINAL.Must : BE_ORDINAL.Not;
  17505. }
  17506. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  17507. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  17508. var sample = data[dimIndex];
  17509. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  17510. if ((result = detectValue(sample[startIndex + i])) != null) {
  17511. return result;
  17512. }
  17513. }
  17514. } else {
  17515. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17516. var row = data[startIndex + i];
  17517. if (row && (result = detectValue(row[dimIndex])) != null) {
  17518. return result;
  17519. }
  17520. }
  17521. }
  17522. } else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  17523. if (!dimName) {
  17524. return BE_ORDINAL.Not;
  17525. }
  17526. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17527. var item = data[i];
  17528. if (item && (result = detectValue(item[dimName])) != null) {
  17529. return result;
  17530. }
  17531. }
  17532. } else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  17533. if (!dimName) {
  17534. return BE_ORDINAL.Not;
  17535. }
  17536. var sample = data[dimName];
  17537. if (!sample || isTypedArray(sample)) {
  17538. return BE_ORDINAL.Not;
  17539. }
  17540. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  17541. if ((result = detectValue(sample[i])) != null) {
  17542. return result;
  17543. }
  17544. }
  17545. } else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  17546. for (var i = 0; i < data.length && i < maxLoop; i++) {
  17547. var item = data[i];
  17548. var val = getDataItemValue(item);
  17549. if (!isArray(val)) {
  17550. return BE_ORDINAL.Not;
  17551. }
  17552. if ((result = detectValue(val[dimIndex])) != null) {
  17553. return result;
  17554. }
  17555. }
  17556. }
  17557. function detectValue(val) {
  17558. var beStr = isString(val); // Consider usage convenience, '1', '2' will be treated as "number".
  17559. // `isFinit('')` get `true`.
  17560. if (val != null && isFinite(val) && val !== '') {
  17561. return beStr ? BE_ORDINAL.Might : BE_ORDINAL.Not;
  17562. } else if (beStr && val !== '-') {
  17563. return BE_ORDINAL.Must;
  17564. }
  17565. }
  17566. return BE_ORDINAL.Not;
  17567. }
  17568. /*
  17569. * Licensed to the Apache Software Foundation (ASF) under one
  17570. * or more contributor license agreements. See the NOTICE file
  17571. * distributed with this work for additional information
  17572. * regarding copyright ownership. The ASF licenses this file
  17573. * to you under the Apache License, Version 2.0 (the
  17574. * "License"); you may not use this file except in compliance
  17575. * with the License. You may obtain a copy of the License at
  17576. *
  17577. * http://www.apache.org/licenses/LICENSE-2.0
  17578. *
  17579. * Unless required by applicable law or agreed to in writing,
  17580. * software distributed under the License is distributed on an
  17581. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17582. * KIND, either express or implied. See the License for the
  17583. * specific language governing permissions and limitations
  17584. * under the License.
  17585. */
  17586. /**
  17587. * ECharts global model
  17588. *
  17589. * @module {echarts/model/Global}
  17590. */
  17591. /**
  17592. * Caution: If the mechanism should be changed some day, these cases
  17593. * should be considered:
  17594. *
  17595. * (1) In `merge option` mode, if using the same option to call `setOption`
  17596. * many times, the result should be the same (try our best to ensure that).
  17597. * (2) In `merge option` mode, if a component has no id/name specified, it
  17598. * will be merged by index, and the result sequence of the components is
  17599. * consistent to the original sequence.
  17600. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  17601. * `mergeOption` in module:echarts/model/OptionManager.
  17602. */
  17603. var OPTION_INNER_KEY = '\0_ec_inner';
  17604. /**
  17605. * @alias module:echarts/model/Global
  17606. *
  17607. * @param {Object} option
  17608. * @param {module:echarts/model/Model} parentModel
  17609. * @param {Object} theme
  17610. */
  17611. var GlobalModel = Model.extend({
  17612. init: function (option, parentModel, theme, optionManager) {
  17613. theme = theme || {};
  17614. this.option = null; // Mark as not initialized.
  17615. /**
  17616. * @type {module:echarts/model/Model}
  17617. * @private
  17618. */
  17619. this._theme = new Model(theme);
  17620. /**
  17621. * @type {module:echarts/model/OptionManager}
  17622. */
  17623. this._optionManager = optionManager;
  17624. },
  17625. setOption: function (option, optionPreprocessorFuncs) {
  17626. assert$1(!(OPTION_INNER_KEY in option), 'please use chart.getOption()');
  17627. this._optionManager.setOption(option, optionPreprocessorFuncs);
  17628. this.resetOption(null);
  17629. },
  17630. /**
  17631. * @param {string} type null/undefined: reset all.
  17632. * 'recreate': force recreate all.
  17633. * 'timeline': only reset timeline option
  17634. * 'media': only reset media query option
  17635. * @return {boolean} Whether option changed.
  17636. */
  17637. resetOption: function (type) {
  17638. var optionChanged = false;
  17639. var optionManager = this._optionManager;
  17640. if (!type || type === 'recreate') {
  17641. var baseOption = optionManager.mountOption(type === 'recreate');
  17642. if (!this.option || type === 'recreate') {
  17643. initBase.call(this, baseOption);
  17644. } else {
  17645. this.restoreData();
  17646. this.mergeOption(baseOption);
  17647. }
  17648. optionChanged = true;
  17649. }
  17650. if (type === 'timeline' || type === 'media') {
  17651. this.restoreData();
  17652. }
  17653. if (!type || type === 'recreate' || type === 'timeline') {
  17654. var timelineOption = optionManager.getTimelineOption(this);
  17655. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  17656. }
  17657. if (!type || type === 'recreate' || type === 'media') {
  17658. var mediaOptions = optionManager.getMediaOption(this, this._api);
  17659. if (mediaOptions.length) {
  17660. each$1(mediaOptions, function (mediaOption) {
  17661. this.mergeOption(mediaOption, optionChanged = true);
  17662. }, this);
  17663. }
  17664. }
  17665. return optionChanged;
  17666. },
  17667. /**
  17668. * @protected
  17669. */
  17670. mergeOption: function (newOption) {
  17671. var option = this.option;
  17672. var componentsMap = this._componentsMap;
  17673. var newCptTypes = [];
  17674. resetSourceDefaulter(this); // If no component class, merge directly.
  17675. // For example: color, animaiton options, etc.
  17676. each$1(newOption, function (componentOption, mainType) {
  17677. if (componentOption == null) {
  17678. return;
  17679. }
  17680. if (!ComponentModel.hasClass(mainType)) {
  17681. // globalSettingTask.dirty();
  17682. option[mainType] = option[mainType] == null ? clone(componentOption) : merge(option[mainType], componentOption, true);
  17683. } else if (mainType) {
  17684. newCptTypes.push(mainType);
  17685. }
  17686. });
  17687. ComponentModel.topologicalTravel(newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this);
  17688. function visitComponent(mainType, dependencies) {
  17689. var newCptOptionList = normalizeToArray(newOption[mainType]);
  17690. var mapResult = mappingToExists(componentsMap.get(mainType), newCptOptionList);
  17691. makeIdAndName(mapResult); // Set mainType and complete subType.
  17692. each$1(mapResult, function (item, index) {
  17693. var opt = item.option;
  17694. if (isObject$1(opt)) {
  17695. item.keyInfo.mainType = mainType;
  17696. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  17697. }
  17698. });
  17699. var dependentModels = getComponentsByTypes(componentsMap, dependencies);
  17700. option[mainType] = [];
  17701. componentsMap.set(mainType, []);
  17702. each$1(mapResult, function (resultItem, index) {
  17703. var componentModel = resultItem.exist;
  17704. var newCptOption = resultItem.option;
  17705. assert$1(isObject$1(newCptOption) || componentModel, 'Empty component definition'); // Consider where is no new option and should be merged using {},
  17706. // see removeEdgeAndAdd in topologicalTravel and
  17707. // ComponentModel.getAllClassMainTypes.
  17708. if (!newCptOption) {
  17709. componentModel.mergeOption({}, this);
  17710. componentModel.optionUpdated({}, false);
  17711. } else {
  17712. var ComponentModelClass = ComponentModel.getClass(mainType, resultItem.keyInfo.subType, true);
  17713. if (componentModel && componentModel.constructor === ComponentModelClass) {
  17714. componentModel.name = resultItem.keyInfo.name; // componentModel.settingTask && componentModel.settingTask.dirty();
  17715. componentModel.mergeOption(newCptOption, this);
  17716. componentModel.optionUpdated(newCptOption, false);
  17717. } else {
  17718. // PENDING Global as parent ?
  17719. var extraOpt = extend({
  17720. dependentModels: dependentModels,
  17721. componentIndex: index
  17722. }, resultItem.keyInfo);
  17723. componentModel = new ComponentModelClass(newCptOption, this, this, extraOpt);
  17724. extend(componentModel, extraOpt);
  17725. componentModel.init(newCptOption, this, this, extraOpt); // Call optionUpdated after init.
  17726. // newCptOption has been used as componentModel.option
  17727. // and may be merged with theme and default, so pass null
  17728. // to avoid confusion.
  17729. componentModel.optionUpdated(null, true);
  17730. }
  17731. }
  17732. componentsMap.get(mainType)[index] = componentModel;
  17733. option[mainType][index] = componentModel.option;
  17734. }, this); // Backup series for filtering.
  17735. if (mainType === 'series') {
  17736. createSeriesIndices(this, componentsMap.get('series'));
  17737. }
  17738. }
  17739. this._seriesIndicesMap = createHashMap(this._seriesIndices = this._seriesIndices || []);
  17740. },
  17741. /**
  17742. * Get option for output (cloned option and inner info removed)
  17743. * @public
  17744. * @return {Object}
  17745. */
  17746. getOption: function () {
  17747. var option = clone(this.option);
  17748. each$1(option, function (opts, mainType) {
  17749. if (ComponentModel.hasClass(mainType)) {
  17750. var opts = normalizeToArray(opts);
  17751. for (var i = opts.length - 1; i >= 0; i--) {
  17752. // Remove options with inner id.
  17753. if (isIdInner(opts[i])) {
  17754. opts.splice(i, 1);
  17755. }
  17756. }
  17757. option[mainType] = opts;
  17758. }
  17759. });
  17760. delete option[OPTION_INNER_KEY];
  17761. return option;
  17762. },
  17763. /**
  17764. * @return {module:echarts/model/Model}
  17765. */
  17766. getTheme: function () {
  17767. return this._theme;
  17768. },
  17769. /**
  17770. * @param {string} mainType
  17771. * @param {number} [idx=0]
  17772. * @return {module:echarts/model/Component}
  17773. */
  17774. getComponent: function (mainType, idx) {
  17775. var list = this._componentsMap.get(mainType);
  17776. if (list) {
  17777. return list[idx || 0];
  17778. }
  17779. },
  17780. /**
  17781. * If none of index and id and name used, return all components with mainType.
  17782. * @param {Object} condition
  17783. * @param {string} condition.mainType
  17784. * @param {string} [condition.subType] If ignore, only query by mainType
  17785. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  17786. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  17787. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  17788. * @return {Array.<module:echarts/model/Component>}
  17789. */
  17790. queryComponents: function (condition) {
  17791. var mainType = condition.mainType;
  17792. if (!mainType) {
  17793. return [];
  17794. }
  17795. var index = condition.index;
  17796. var id = condition.id;
  17797. var name = condition.name;
  17798. var cpts = this._componentsMap.get(mainType);
  17799. if (!cpts || !cpts.length) {
  17800. return [];
  17801. }
  17802. var result;
  17803. if (index != null) {
  17804. if (!isArray(index)) {
  17805. index = [index];
  17806. }
  17807. result = filter(map(index, function (idx) {
  17808. return cpts[idx];
  17809. }), function (val) {
  17810. return !!val;
  17811. });
  17812. } else if (id != null) {
  17813. var isIdArray = isArray(id);
  17814. result = filter(cpts, function (cpt) {
  17815. return isIdArray && indexOf(id, cpt.id) >= 0 || !isIdArray && cpt.id === id;
  17816. });
  17817. } else if (name != null) {
  17818. var isNameArray = isArray(name);
  17819. result = filter(cpts, function (cpt) {
  17820. return isNameArray && indexOf(name, cpt.name) >= 0 || !isNameArray && cpt.name === name;
  17821. });
  17822. } else {
  17823. // Return all components with mainType
  17824. result = cpts.slice();
  17825. }
  17826. return filterBySubType(result, condition);
  17827. },
  17828. /**
  17829. * The interface is different from queryComponents,
  17830. * which is convenient for inner usage.
  17831. *
  17832. * @usage
  17833. * var result = findComponents(
  17834. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  17835. * );
  17836. * var result = findComponents(
  17837. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  17838. * );
  17839. * var result = findComponents(
  17840. * {mainType: 'series',
  17841. * filter: function (model, index) {...}}
  17842. * );
  17843. * // result like [component0, componnet1, ...]
  17844. *
  17845. * @param {Object} condition
  17846. * @param {string} condition.mainType Mandatory.
  17847. * @param {string} [condition.subType] Optional.
  17848. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  17849. * where xxx is mainType.
  17850. * If query attribute is null/undefined or has no index/id/name,
  17851. * do not filtering by query conditions, which is convenient for
  17852. * no-payload situations or when target of action is global.
  17853. * @param {Function} [condition.filter] parameter: component, return boolean.
  17854. * @return {Array.<module:echarts/model/Component>}
  17855. */
  17856. findComponents: function (condition) {
  17857. var query = condition.query;
  17858. var mainType = condition.mainType;
  17859. var queryCond = getQueryCond(query);
  17860. var result = queryCond ? this.queryComponents(queryCond) : this._componentsMap.get(mainType);
  17861. return doFilter(filterBySubType(result, condition));
  17862. function getQueryCond(q) {
  17863. var indexAttr = mainType + 'Index';
  17864. var idAttr = mainType + 'Id';
  17865. var nameAttr = mainType + 'Name';
  17866. return q && (q[indexAttr] != null || q[idAttr] != null || q[nameAttr] != null) ? {
  17867. mainType: mainType,
  17868. // subType will be filtered finally.
  17869. index: q[indexAttr],
  17870. id: q[idAttr],
  17871. name: q[nameAttr]
  17872. } : null;
  17873. }
  17874. function doFilter(res) {
  17875. return condition.filter ? filter(res, condition.filter) : res;
  17876. }
  17877. },
  17878. /**
  17879. * @usage
  17880. * eachComponent('legend', function (legendModel, index) {
  17881. * ...
  17882. * });
  17883. * eachComponent(function (componentType, model, index) {
  17884. * // componentType does not include subType
  17885. * // (componentType is 'xxx' but not 'xxx.aa')
  17886. * });
  17887. * eachComponent(
  17888. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  17889. * function (model, index) {...}
  17890. * );
  17891. * eachComponent(
  17892. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  17893. * function (model, index) {...}
  17894. * );
  17895. *
  17896. * @param {string|Object=} mainType When mainType is object, the definition
  17897. * is the same as the method 'findComponents'.
  17898. * @param {Function} cb
  17899. * @param {*} context
  17900. */
  17901. eachComponent: function (mainType, cb, context) {
  17902. var componentsMap = this._componentsMap;
  17903. if (typeof mainType === 'function') {
  17904. context = cb;
  17905. cb = mainType;
  17906. componentsMap.each(function (components, componentType) {
  17907. each$1(components, function (component, index) {
  17908. cb.call(context, componentType, component, index);
  17909. });
  17910. });
  17911. } else if (isString(mainType)) {
  17912. each$1(componentsMap.get(mainType), cb, context);
  17913. } else if (isObject$1(mainType)) {
  17914. var queryResult = this.findComponents(mainType);
  17915. each$1(queryResult, cb, context);
  17916. }
  17917. },
  17918. /**
  17919. * @param {string} name
  17920. * @return {Array.<module:echarts/model/Series>}
  17921. */
  17922. getSeriesByName: function (name) {
  17923. var series = this._componentsMap.get('series');
  17924. return filter(series, function (oneSeries) {
  17925. return oneSeries.name === name;
  17926. });
  17927. },
  17928. /**
  17929. * @param {number} seriesIndex
  17930. * @return {module:echarts/model/Series}
  17931. */
  17932. getSeriesByIndex: function (seriesIndex) {
  17933. return this._componentsMap.get('series')[seriesIndex];
  17934. },
  17935. /**
  17936. * Get series list before filtered by type.
  17937. * FIXME: rename to getRawSeriesByType?
  17938. *
  17939. * @param {string} subType
  17940. * @return {Array.<module:echarts/model/Series>}
  17941. */
  17942. getSeriesByType: function (subType) {
  17943. var series = this._componentsMap.get('series');
  17944. return filter(series, function (oneSeries) {
  17945. return oneSeries.subType === subType;
  17946. });
  17947. },
  17948. /**
  17949. * @return {Array.<module:echarts/model/Series>}
  17950. */
  17951. getSeries: function () {
  17952. return this._componentsMap.get('series').slice();
  17953. },
  17954. /**
  17955. * @return {number}
  17956. */
  17957. getSeriesCount: function () {
  17958. return this._componentsMap.get('series').length;
  17959. },
  17960. /**
  17961. * After filtering, series may be different
  17962. * frome raw series.
  17963. *
  17964. * @param {Function} cb
  17965. * @param {*} context
  17966. */
  17967. eachSeries: function (cb, context) {
  17968. each$1(this._seriesIndices, function (rawSeriesIndex) {
  17969. var series = this._componentsMap.get('series')[rawSeriesIndex];
  17970. cb.call(context, series, rawSeriesIndex);
  17971. }, this);
  17972. },
  17973. /**
  17974. * Iterate raw series before filtered.
  17975. *
  17976. * @param {Function} cb
  17977. * @param {*} context
  17978. */
  17979. eachRawSeries: function (cb, context) {
  17980. each$1(this._componentsMap.get('series'), cb, context);
  17981. },
  17982. /**
  17983. * After filtering, series may be different.
  17984. * frome raw series.
  17985. *
  17986. * @param {string} subType.
  17987. * @param {Function} cb
  17988. * @param {*} context
  17989. */
  17990. eachSeriesByType: function (subType, cb, context) {
  17991. each$1(this._seriesIndices, function (rawSeriesIndex) {
  17992. var series = this._componentsMap.get('series')[rawSeriesIndex];
  17993. if (series.subType === subType) {
  17994. cb.call(context, series, rawSeriesIndex);
  17995. }
  17996. }, this);
  17997. },
  17998. /**
  17999. * Iterate raw series before filtered of given type.
  18000. *
  18001. * @parma {string} subType
  18002. * @param {Function} cb
  18003. * @param {*} context
  18004. */
  18005. eachRawSeriesByType: function (subType, cb, context) {
  18006. return each$1(this.getSeriesByType(subType), cb, context);
  18007. },
  18008. /**
  18009. * @param {module:echarts/model/Series} seriesModel
  18010. */
  18011. isSeriesFiltered: function (seriesModel) {
  18012. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  18013. },
  18014. /**
  18015. * @return {Array.<number>}
  18016. */
  18017. getCurrentSeriesIndices: function () {
  18018. return (this._seriesIndices || []).slice();
  18019. },
  18020. /**
  18021. * @param {Function} cb
  18022. * @param {*} context
  18023. */
  18024. filterSeries: function (cb, context) {
  18025. var filteredSeries = filter(this._componentsMap.get('series'), cb, context);
  18026. createSeriesIndices(this, filteredSeries);
  18027. },
  18028. restoreData: function (payload) {
  18029. var componentsMap = this._componentsMap;
  18030. createSeriesIndices(this, componentsMap.get('series'));
  18031. var componentTypes = [];
  18032. componentsMap.each(function (components, componentType) {
  18033. componentTypes.push(componentType);
  18034. });
  18035. ComponentModel.topologicalTravel(componentTypes, ComponentModel.getAllClassMainTypes(), function (componentType, dependencies) {
  18036. each$1(componentsMap.get(componentType), function (component) {
  18037. (componentType !== 'series' || !isNotTargetSeries(component, payload)) && component.restoreData();
  18038. });
  18039. });
  18040. }
  18041. });
  18042. function isNotTargetSeries(seriesModel, payload) {
  18043. if (payload) {
  18044. var index = payload.seiresIndex;
  18045. var id = payload.seriesId;
  18046. var name = payload.seriesName;
  18047. return index != null && seriesModel.componentIndex !== index || id != null && seriesModel.id !== id || name != null && seriesModel.name !== name;
  18048. }
  18049. }
  18050. /**
  18051. * @inner
  18052. */
  18053. function mergeTheme(option, theme) {
  18054. // PENDING
  18055. // NOT use `colorLayer` in theme if option has `color`
  18056. var notMergeColorLayer = option.color && !option.colorLayer;
  18057. each$1(theme, function (themeItem, name) {
  18058. if (name === 'colorLayer' && notMergeColorLayer) {
  18059. return;
  18060. } // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  18061. if (!ComponentModel.hasClass(name)) {
  18062. if (typeof themeItem === 'object') {
  18063. option[name] = !option[name] ? clone(themeItem) : merge(option[name], themeItem, false);
  18064. } else {
  18065. if (option[name] == null) {
  18066. option[name] = themeItem;
  18067. }
  18068. }
  18069. }
  18070. });
  18071. }
  18072. function initBase(baseOption) {
  18073. baseOption = baseOption; // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  18074. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  18075. this.option = {};
  18076. this.option[OPTION_INNER_KEY] = 1;
  18077. /**
  18078. * Init with series: [], in case of calling findSeries method
  18079. * before series initialized.
  18080. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  18081. * @private
  18082. */
  18083. this._componentsMap = createHashMap({
  18084. series: []
  18085. });
  18086. /**
  18087. * Mapping between filtered series list and raw series list.
  18088. * key: filtered series indices, value: raw series indices.
  18089. * @type {Array.<nubmer>}
  18090. * @private
  18091. */
  18092. this._seriesIndices;
  18093. this._seriesIndicesMap;
  18094. mergeTheme(baseOption, this._theme.option); // TODO Needs clone when merging to the unexisted property
  18095. merge(baseOption, globalDefault, false);
  18096. this.mergeOption(baseOption);
  18097. }
  18098. /**
  18099. * @inner
  18100. * @param {Array.<string>|string} types model types
  18101. * @return {Object} key: {string} type, value: {Array.<Object>} models
  18102. */
  18103. function getComponentsByTypes(componentsMap, types) {
  18104. if (!isArray(types)) {
  18105. types = types ? [types] : [];
  18106. }
  18107. var ret = {};
  18108. each$1(types, function (type) {
  18109. ret[type] = (componentsMap.get(type) || []).slice();
  18110. });
  18111. return ret;
  18112. }
  18113. /**
  18114. * @inner
  18115. */
  18116. function determineSubType(mainType, newCptOption, existComponent) {
  18117. var subType = newCptOption.type ? newCptOption.type : existComponent ? existComponent.subType // Use determineSubType only when there is no existComponent.
  18118. : ComponentModel.determineSubType(mainType, newCptOption); // tooltip, markline, markpoint may always has no subType
  18119. return subType;
  18120. }
  18121. /**
  18122. * @inner
  18123. */
  18124. function createSeriesIndices(ecModel, seriesModels) {
  18125. ecModel._seriesIndicesMap = createHashMap(ecModel._seriesIndices = map(seriesModels, function (series) {
  18126. return series.componentIndex;
  18127. }) || []);
  18128. }
  18129. /**
  18130. * @inner
  18131. */
  18132. function filterBySubType(components, condition) {
  18133. // Using hasOwnProperty for restrict. Consider
  18134. // subType is undefined in user payload.
  18135. return condition.hasOwnProperty('subType') ? filter(components, function (cpt) {
  18136. return cpt.subType === condition.subType;
  18137. }) : components;
  18138. }
  18139. mixin(GlobalModel, colorPaletteMixin);
  18140. /*
  18141. * Licensed to the Apache Software Foundation (ASF) under one
  18142. * or more contributor license agreements. See the NOTICE file
  18143. * distributed with this work for additional information
  18144. * regarding copyright ownership. The ASF licenses this file
  18145. * to you under the Apache License, Version 2.0 (the
  18146. * "License"); you may not use this file except in compliance
  18147. * with the License. You may obtain a copy of the License at
  18148. *
  18149. * http://www.apache.org/licenses/LICENSE-2.0
  18150. *
  18151. * Unless required by applicable law or agreed to in writing,
  18152. * software distributed under the License is distributed on an
  18153. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18154. * KIND, either express or implied. See the License for the
  18155. * specific language governing permissions and limitations
  18156. * under the License.
  18157. */
  18158. 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
  18159. function ExtensionAPI(chartInstance) {
  18160. each$1(echartsAPIList, function (name) {
  18161. this[name] = bind(chartInstance[name], chartInstance);
  18162. }, this);
  18163. }
  18164. /*
  18165. * Licensed to the Apache Software Foundation (ASF) under one
  18166. * or more contributor license agreements. See the NOTICE file
  18167. * distributed with this work for additional information
  18168. * regarding copyright ownership. The ASF licenses this file
  18169. * to you under the Apache License, Version 2.0 (the
  18170. * "License"); you may not use this file except in compliance
  18171. * with the License. You may obtain a copy of the License at
  18172. *
  18173. * http://www.apache.org/licenses/LICENSE-2.0
  18174. *
  18175. * Unless required by applicable law or agreed to in writing,
  18176. * software distributed under the License is distributed on an
  18177. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18178. * KIND, either express or implied. See the License for the
  18179. * specific language governing permissions and limitations
  18180. * under the License.
  18181. */
  18182. var coordinateSystemCreators = {};
  18183. function CoordinateSystemManager() {
  18184. this._coordinateSystems = [];
  18185. }
  18186. CoordinateSystemManager.prototype = {
  18187. constructor: CoordinateSystemManager,
  18188. create: function (ecModel, api) {
  18189. var coordinateSystems = [];
  18190. each$1(coordinateSystemCreators, function (creater, type) {
  18191. var list = creater.create(ecModel, api);
  18192. coordinateSystems = coordinateSystems.concat(list || []);
  18193. });
  18194. this._coordinateSystems = coordinateSystems;
  18195. },
  18196. update: function (ecModel, api) {
  18197. each$1(this._coordinateSystems, function (coordSys) {
  18198. coordSys.update && coordSys.update(ecModel, api);
  18199. });
  18200. },
  18201. getCoordinateSystems: function () {
  18202. return this._coordinateSystems.slice();
  18203. }
  18204. };
  18205. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  18206. coordinateSystemCreators[type] = coordinateSystemCreator;
  18207. };
  18208. CoordinateSystemManager.get = function (type) {
  18209. return coordinateSystemCreators[type];
  18210. };
  18211. /*
  18212. * Licensed to the Apache Software Foundation (ASF) under one
  18213. * or more contributor license agreements. See the NOTICE file
  18214. * distributed with this work for additional information
  18215. * regarding copyright ownership. The ASF licenses this file
  18216. * to you under the Apache License, Version 2.0 (the
  18217. * "License"); you may not use this file except in compliance
  18218. * with the License. You may obtain a copy of the License at
  18219. *
  18220. * http://www.apache.org/licenses/LICENSE-2.0
  18221. *
  18222. * Unless required by applicable law or agreed to in writing,
  18223. * software distributed under the License is distributed on an
  18224. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18225. * KIND, either express or implied. See the License for the
  18226. * specific language governing permissions and limitations
  18227. * under the License.
  18228. */
  18229. /**
  18230. * ECharts option manager
  18231. *
  18232. * @module {echarts/model/OptionManager}
  18233. */
  18234. var each$4 = each$1;
  18235. var clone$3 = clone;
  18236. var map$1 = map;
  18237. var merge$1 = merge;
  18238. var QUERY_REG = /^(min|max)?(.+)$/;
  18239. /**
  18240. * TERM EXPLANATIONS:
  18241. *
  18242. * [option]:
  18243. *
  18244. * An object that contains definitions of components. For example:
  18245. * var option = {
  18246. * title: {...},
  18247. * legend: {...},
  18248. * visualMap: {...},
  18249. * series: [
  18250. * {data: [...]},
  18251. * {data: [...]},
  18252. * ...
  18253. * ]
  18254. * };
  18255. *
  18256. * [rawOption]:
  18257. *
  18258. * An object input to echarts.setOption. 'rawOption' may be an
  18259. * 'option', or may be an object contains multi-options. For example:
  18260. * var option = {
  18261. * baseOption: {
  18262. * title: {...},
  18263. * legend: {...},
  18264. * series: [
  18265. * {data: [...]},
  18266. * {data: [...]},
  18267. * ...
  18268. * ]
  18269. * },
  18270. * timeline: {...},
  18271. * options: [
  18272. * {title: {...}, series: {data: [...]}},
  18273. * {title: {...}, series: {data: [...]}},
  18274. * ...
  18275. * ],
  18276. * media: [
  18277. * {
  18278. * query: {maxWidth: 320},
  18279. * option: {series: {x: 20}, visualMap: {show: false}}
  18280. * },
  18281. * {
  18282. * query: {minWidth: 320, maxWidth: 720},
  18283. * option: {series: {x: 500}, visualMap: {show: true}}
  18284. * },
  18285. * {
  18286. * option: {series: {x: 1200}, visualMap: {show: true}}
  18287. * }
  18288. * ]
  18289. * };
  18290. *
  18291. * @alias module:echarts/model/OptionManager
  18292. * @param {module:echarts/ExtensionAPI} api
  18293. */
  18294. function OptionManager(api) {
  18295. /**
  18296. * @private
  18297. * @type {module:echarts/ExtensionAPI}
  18298. */
  18299. this._api = api;
  18300. /**
  18301. * @private
  18302. * @type {Array.<number>}
  18303. */
  18304. this._timelineOptions = [];
  18305. /**
  18306. * @private
  18307. * @type {Array.<Object>}
  18308. */
  18309. this._mediaList = [];
  18310. /**
  18311. * @private
  18312. * @type {Object}
  18313. */
  18314. this._mediaDefault;
  18315. /**
  18316. * -1, means default.
  18317. * empty means no media.
  18318. * @private
  18319. * @type {Array.<number>}
  18320. */
  18321. this._currentMediaIndices = [];
  18322. /**
  18323. * @private
  18324. * @type {Object}
  18325. */
  18326. this._optionBackup;
  18327. /**
  18328. * @private
  18329. * @type {Object}
  18330. */
  18331. this._newBaseOption;
  18332. } // timeline.notMerge is not supported in ec3. Firstly there is rearly
  18333. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  18334. // rawOption cloned and backuped when timeline changed, which does no
  18335. // good to performance. What's more, that both timeline and setOption
  18336. // method supply 'notMerge' brings complex and some problems.
  18337. // Consider this case:
  18338. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  18339. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  18340. OptionManager.prototype = {
  18341. constructor: OptionManager,
  18342. /**
  18343. * @public
  18344. * @param {Object} rawOption Raw option.
  18345. * @param {module:echarts/model/Global} ecModel
  18346. * @param {Array.<Function>} optionPreprocessorFuncs
  18347. * @return {Object} Init option
  18348. */
  18349. setOption: function (rawOption, optionPreprocessorFuncs) {
  18350. if (rawOption) {
  18351. // That set dat primitive is dangerous if user reuse the data when setOption again.
  18352. each$1(normalizeToArray(rawOption.series), function (series) {
  18353. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  18354. });
  18355. } // Caution: some series modify option data, if do not clone,
  18356. // it should ensure that the repeat modify correctly
  18357. // (create a new object when modify itself).
  18358. rawOption = clone$3(rawOption); // FIXME
  18359. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  18360. var oldOptionBackup = this._optionBackup;
  18361. var newParsedOption = parseRawOption.call(this, rawOption, optionPreprocessorFuncs, !oldOptionBackup);
  18362. this._newBaseOption = newParsedOption.baseOption; // For setOption at second time (using merge mode);
  18363. if (oldOptionBackup) {
  18364. // Only baseOption can be merged.
  18365. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption); // For simplicity, timeline options and media options do not support merge,
  18366. // that is, if you `setOption` twice and both has timeline options, the latter
  18367. // timeline opitons will not be merged to the formers, but just substitude them.
  18368. if (newParsedOption.timelineOptions.length) {
  18369. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  18370. }
  18371. if (newParsedOption.mediaList.length) {
  18372. oldOptionBackup.mediaList = newParsedOption.mediaList;
  18373. }
  18374. if (newParsedOption.mediaDefault) {
  18375. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  18376. }
  18377. } else {
  18378. this._optionBackup = newParsedOption;
  18379. }
  18380. },
  18381. /**
  18382. * @param {boolean} isRecreate
  18383. * @return {Object}
  18384. */
  18385. mountOption: function (isRecreate) {
  18386. var optionBackup = this._optionBackup; // TODO
  18387. // 如果没有reset功能则不clone。
  18388. this._timelineOptions = map$1(optionBackup.timelineOptions, clone$3);
  18389. this._mediaList = map$1(optionBackup.mediaList, clone$3);
  18390. this._mediaDefault = clone$3(optionBackup.mediaDefault);
  18391. this._currentMediaIndices = [];
  18392. return clone$3(isRecreate // this._optionBackup.baseOption, which is created at the first `setOption`
  18393. // called, and is merged into every new option by inner method `mergeOption`
  18394. // each time `setOption` called, can be only used in `isRecreate`, because
  18395. // its reliability is under suspicion. In other cases option merge is
  18396. // performed by `model.mergeOption`.
  18397. ? optionBackup.baseOption : this._newBaseOption);
  18398. },
  18399. /**
  18400. * @param {module:echarts/model/Global} ecModel
  18401. * @return {Object}
  18402. */
  18403. getTimelineOption: function (ecModel) {
  18404. var option;
  18405. var timelineOptions = this._timelineOptions;
  18406. if (timelineOptions.length) {
  18407. // getTimelineOption can only be called after ecModel inited,
  18408. // so we can get currentIndex from timelineModel.
  18409. var timelineModel = ecModel.getComponent('timeline');
  18410. if (timelineModel) {
  18411. option = clone$3(timelineOptions[timelineModel.getCurrentIndex()], true);
  18412. }
  18413. }
  18414. return option;
  18415. },
  18416. /**
  18417. * @param {module:echarts/model/Global} ecModel
  18418. * @return {Array.<Object>}
  18419. */
  18420. getMediaOption: function (ecModel) {
  18421. var ecWidth = this._api.getWidth();
  18422. var ecHeight = this._api.getHeight();
  18423. var mediaList = this._mediaList;
  18424. var mediaDefault = this._mediaDefault;
  18425. var indices = [];
  18426. var result = []; // No media defined.
  18427. if (!mediaList.length && !mediaDefault) {
  18428. return result;
  18429. } // Multi media may be applied, the latter defined media has higher priority.
  18430. for (var i = 0, len = mediaList.length; i < len; i++) {
  18431. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  18432. indices.push(i);
  18433. }
  18434. } // FIXME
  18435. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  18436. if (!indices.length && mediaDefault) {
  18437. indices = [-1];
  18438. }
  18439. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  18440. result = map$1(indices, function (index) {
  18441. return clone$3(index === -1 ? mediaDefault.option : mediaList[index].option);
  18442. });
  18443. } // Otherwise return nothing.
  18444. this._currentMediaIndices = indices;
  18445. return result;
  18446. }
  18447. };
  18448. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  18449. var timelineOptions = [];
  18450. var mediaList = [];
  18451. var mediaDefault;
  18452. var baseOption; // Compatible with ec2.
  18453. var timelineOpt = rawOption.timeline;
  18454. if (rawOption.baseOption) {
  18455. baseOption = rawOption.baseOption;
  18456. } // For timeline
  18457. if (timelineOpt || rawOption.options) {
  18458. baseOption = baseOption || {};
  18459. timelineOptions = (rawOption.options || []).slice();
  18460. } // For media query
  18461. if (rawOption.media) {
  18462. baseOption = baseOption || {};
  18463. var media = rawOption.media;
  18464. each$4(media, function (singleMedia) {
  18465. if (singleMedia && singleMedia.option) {
  18466. if (singleMedia.query) {
  18467. mediaList.push(singleMedia);
  18468. } else if (!mediaDefault) {
  18469. // Use the first media default.
  18470. mediaDefault = singleMedia;
  18471. }
  18472. }
  18473. });
  18474. } // For normal option
  18475. if (!baseOption) {
  18476. baseOption = rawOption;
  18477. } // Set timelineOpt to baseOption in ec3,
  18478. // which is convenient for merge option.
  18479. if (!baseOption.timeline) {
  18480. baseOption.timeline = timelineOpt;
  18481. } // Preprocess.
  18482. each$4([baseOption].concat(timelineOptions).concat(map(mediaList, function (media) {
  18483. return media.option;
  18484. })), function (option) {
  18485. each$4(optionPreprocessorFuncs, function (preProcess) {
  18486. preProcess(option, isNew);
  18487. });
  18488. });
  18489. return {
  18490. baseOption: baseOption,
  18491. timelineOptions: timelineOptions,
  18492. mediaDefault: mediaDefault,
  18493. mediaList: mediaList
  18494. };
  18495. }
  18496. /**
  18497. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  18498. * Support: width, height, aspectRatio
  18499. * Can use max or min as prefix.
  18500. */
  18501. function applyMediaQuery(query, ecWidth, ecHeight) {
  18502. var realMap = {
  18503. width: ecWidth,
  18504. height: ecHeight,
  18505. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  18506. };
  18507. var applicatable = true;
  18508. each$1(query, function (value, attr) {
  18509. var matched = attr.match(QUERY_REG);
  18510. if (!matched || !matched[1] || !matched[2]) {
  18511. return;
  18512. }
  18513. var operator = matched[1];
  18514. var realAttr = matched[2].toLowerCase();
  18515. if (!compare(realMap[realAttr], value, operator)) {
  18516. applicatable = false;
  18517. }
  18518. });
  18519. return applicatable;
  18520. }
  18521. function compare(real, expect, operator) {
  18522. if (operator === 'min') {
  18523. return real >= expect;
  18524. } else if (operator === 'max') {
  18525. return real <= expect;
  18526. } else {
  18527. // Equals
  18528. return real === expect;
  18529. }
  18530. }
  18531. function indicesEquals(indices1, indices2) {
  18532. // indices is always order by asc and has only finite number.
  18533. return indices1.join(',') === indices2.join(',');
  18534. }
  18535. /**
  18536. * Consider case:
  18537. * `chart.setOption(opt1);`
  18538. * Then user do some interaction like dataZoom, dataView changing.
  18539. * `chart.setOption(opt2);`
  18540. * Then user press 'reset button' in toolbox.
  18541. *
  18542. * After doing that all of the interaction effects should be reset, the
  18543. * chart should be the same as the result of invoke
  18544. * `chart.setOption(opt1); chart.setOption(opt2);`.
  18545. *
  18546. * Although it is not able ensure that
  18547. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  18548. * `chart.setOption(merge(opt1, opt2));` exactly,
  18549. * this might be the only simple way to implement that feature.
  18550. *
  18551. * MEMO: We've considered some other approaches:
  18552. * 1. Each model handle its self restoration but not uniform treatment.
  18553. * (Too complex in logic and error-prone)
  18554. * 2. Use a shadow ecModel. (Performace expensive)
  18555. */
  18556. function mergeOption(oldOption, newOption) {
  18557. newOption = newOption || {};
  18558. each$4(newOption, function (newCptOpt, mainType) {
  18559. if (newCptOpt == null) {
  18560. return;
  18561. }
  18562. var oldCptOpt = oldOption[mainType];
  18563. if (!ComponentModel.hasClass(mainType)) {
  18564. oldOption[mainType] = merge$1(oldCptOpt, newCptOpt, true);
  18565. } else {
  18566. newCptOpt = normalizeToArray(newCptOpt);
  18567. oldCptOpt = normalizeToArray(oldCptOpt);
  18568. var mapResult = mappingToExists(oldCptOpt, newCptOpt);
  18569. oldOption[mainType] = map$1(mapResult, function (item) {
  18570. return item.option && item.exist ? merge$1(item.exist, item.option, true) : item.exist || item.option;
  18571. });
  18572. }
  18573. });
  18574. }
  18575. /*
  18576. * Licensed to the Apache Software Foundation (ASF) under one
  18577. * or more contributor license agreements. See the NOTICE file
  18578. * distributed with this work for additional information
  18579. * regarding copyright ownership. The ASF licenses this file
  18580. * to you under the Apache License, Version 2.0 (the
  18581. * "License"); you may not use this file except in compliance
  18582. * with the License. You may obtain a copy of the License at
  18583. *
  18584. * http://www.apache.org/licenses/LICENSE-2.0
  18585. *
  18586. * Unless required by applicable law or agreed to in writing,
  18587. * software distributed under the License is distributed on an
  18588. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18589. * KIND, either express or implied. See the License for the
  18590. * specific language governing permissions and limitations
  18591. * under the License.
  18592. */
  18593. var each$5 = each$1;
  18594. var isObject$3 = isObject$1;
  18595. var POSSIBLE_STYLES = ['areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle', 'chordStyle', 'label', 'labelLine'];
  18596. function compatEC2ItemStyle(opt) {
  18597. var itemStyleOpt = opt && opt.itemStyle;
  18598. if (!itemStyleOpt) {
  18599. return;
  18600. }
  18601. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  18602. var styleName = POSSIBLE_STYLES[i];
  18603. var normalItemStyleOpt = itemStyleOpt.normal;
  18604. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  18605. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  18606. opt[styleName] = opt[styleName] || {};
  18607. if (!opt[styleName].normal) {
  18608. opt[styleName].normal = normalItemStyleOpt[styleName];
  18609. } else {
  18610. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  18611. }
  18612. normalItemStyleOpt[styleName] = null;
  18613. }
  18614. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  18615. opt[styleName] = opt[styleName] || {};
  18616. if (!opt[styleName].emphasis) {
  18617. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  18618. } else {
  18619. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  18620. }
  18621. emphasisItemStyleOpt[styleName] = null;
  18622. }
  18623. }
  18624. }
  18625. function convertNormalEmphasis(opt, optType, useExtend) {
  18626. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  18627. var normalOpt = opt[optType].normal;
  18628. var emphasisOpt = opt[optType].emphasis;
  18629. if (normalOpt) {
  18630. // Timeline controlStyle has other properties besides normal and emphasis
  18631. if (useExtend) {
  18632. opt[optType].normal = opt[optType].emphasis = null;
  18633. defaults(opt[optType], normalOpt);
  18634. } else {
  18635. opt[optType] = normalOpt;
  18636. }
  18637. }
  18638. if (emphasisOpt) {
  18639. opt.emphasis = opt.emphasis || {};
  18640. opt.emphasis[optType] = emphasisOpt;
  18641. }
  18642. }
  18643. }
  18644. function removeEC3NormalStatus(opt) {
  18645. convertNormalEmphasis(opt, 'itemStyle');
  18646. convertNormalEmphasis(opt, 'lineStyle');
  18647. convertNormalEmphasis(opt, 'areaStyle');
  18648. convertNormalEmphasis(opt, 'label');
  18649. convertNormalEmphasis(opt, 'labelLine'); // treemap
  18650. convertNormalEmphasis(opt, 'upperLabel'); // graph
  18651. convertNormalEmphasis(opt, 'edgeLabel');
  18652. }
  18653. function compatTextStyle(opt, propName) {
  18654. // Check whether is not object (string\null\undefined ...)
  18655. var labelOptSingle = isObject$3(opt) && opt[propName];
  18656. var textStyle = isObject$3(labelOptSingle) && labelOptSingle.textStyle;
  18657. if (textStyle) {
  18658. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  18659. var propName = TEXT_STYLE_OPTIONS[i];
  18660. if (textStyle.hasOwnProperty(propName)) {
  18661. labelOptSingle[propName] = textStyle[propName];
  18662. }
  18663. }
  18664. }
  18665. }
  18666. function compatEC3CommonStyles(opt) {
  18667. if (opt) {
  18668. removeEC3NormalStatus(opt);
  18669. compatTextStyle(opt, 'label');
  18670. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  18671. }
  18672. }
  18673. function processSeries(seriesOpt) {
  18674. if (!isObject$3(seriesOpt)) {
  18675. return;
  18676. }
  18677. compatEC2ItemStyle(seriesOpt);
  18678. removeEC3NormalStatus(seriesOpt);
  18679. compatTextStyle(seriesOpt, 'label'); // treemap
  18680. compatTextStyle(seriesOpt, 'upperLabel'); // graph
  18681. compatTextStyle(seriesOpt, 'edgeLabel');
  18682. if (seriesOpt.emphasis) {
  18683. compatTextStyle(seriesOpt.emphasis, 'label'); // treemap
  18684. compatTextStyle(seriesOpt.emphasis, 'upperLabel'); // graph
  18685. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  18686. }
  18687. var markPoint = seriesOpt.markPoint;
  18688. if (markPoint) {
  18689. compatEC2ItemStyle(markPoint);
  18690. compatEC3CommonStyles(markPoint);
  18691. }
  18692. var markLine = seriesOpt.markLine;
  18693. if (markLine) {
  18694. compatEC2ItemStyle(markLine);
  18695. compatEC3CommonStyles(markLine);
  18696. }
  18697. var markArea = seriesOpt.markArea;
  18698. if (markArea) {
  18699. compatEC3CommonStyles(markArea);
  18700. }
  18701. var data = seriesOpt.data; // Break with ec3: if `setOption` again, there may be no `type` in option,
  18702. // then the backward compat based on option type will not be performed.
  18703. if (seriesOpt.type === 'graph') {
  18704. data = data || seriesOpt.nodes;
  18705. var edgeData = seriesOpt.links || seriesOpt.edges;
  18706. if (edgeData && !isTypedArray(edgeData)) {
  18707. for (var i = 0; i < edgeData.length; i++) {
  18708. compatEC3CommonStyles(edgeData[i]);
  18709. }
  18710. }
  18711. each$1(seriesOpt.categories, function (opt) {
  18712. removeEC3NormalStatus(opt);
  18713. });
  18714. }
  18715. if (data && !isTypedArray(data)) {
  18716. for (var i = 0; i < data.length; i++) {
  18717. compatEC3CommonStyles(data[i]);
  18718. }
  18719. } // mark point data
  18720. var markPoint = seriesOpt.markPoint;
  18721. if (markPoint && markPoint.data) {
  18722. var mpData = markPoint.data;
  18723. for (var i = 0; i < mpData.length; i++) {
  18724. compatEC3CommonStyles(mpData[i]);
  18725. }
  18726. } // mark line data
  18727. var markLine = seriesOpt.markLine;
  18728. if (markLine && markLine.data) {
  18729. var mlData = markLine.data;
  18730. for (var i = 0; i < mlData.length; i++) {
  18731. if (isArray(mlData[i])) {
  18732. compatEC3CommonStyles(mlData[i][0]);
  18733. compatEC3CommonStyles(mlData[i][1]);
  18734. } else {
  18735. compatEC3CommonStyles(mlData[i]);
  18736. }
  18737. }
  18738. } // Series
  18739. if (seriesOpt.type === 'gauge') {
  18740. compatTextStyle(seriesOpt, 'axisLabel');
  18741. compatTextStyle(seriesOpt, 'title');
  18742. compatTextStyle(seriesOpt, 'detail');
  18743. } else if (seriesOpt.type === 'treemap') {
  18744. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  18745. each$1(seriesOpt.levels, function (opt) {
  18746. removeEC3NormalStatus(opt);
  18747. });
  18748. } else if (seriesOpt.type === 'tree') {
  18749. removeEC3NormalStatus(seriesOpt.leaves);
  18750. } // sunburst starts from ec4, so it does not need to compat levels.
  18751. }
  18752. function toArr(o) {
  18753. return isArray(o) ? o : o ? [o] : [];
  18754. }
  18755. function toObj(o) {
  18756. return (isArray(o) ? o[0] : o) || {};
  18757. }
  18758. var compatStyle = function (option, isTheme) {
  18759. each$5(toArr(option.series), function (seriesOpt) {
  18760. isObject$3(seriesOpt) && processSeries(seriesOpt);
  18761. });
  18762. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  18763. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  18764. each$5(axes, function (axisName) {
  18765. each$5(toArr(option[axisName]), function (axisOpt) {
  18766. if (axisOpt) {
  18767. compatTextStyle(axisOpt, 'axisLabel');
  18768. compatTextStyle(axisOpt.axisPointer, 'label');
  18769. }
  18770. });
  18771. });
  18772. each$5(toArr(option.parallel), function (parallelOpt) {
  18773. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  18774. compatTextStyle(parallelAxisDefault, 'axisLabel');
  18775. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  18776. });
  18777. each$5(toArr(option.calendar), function (calendarOpt) {
  18778. convertNormalEmphasis(calendarOpt, 'itemStyle');
  18779. compatTextStyle(calendarOpt, 'dayLabel');
  18780. compatTextStyle(calendarOpt, 'monthLabel');
  18781. compatTextStyle(calendarOpt, 'yearLabel');
  18782. }); // radar.name.textStyle
  18783. each$5(toArr(option.radar), function (radarOpt) {
  18784. compatTextStyle(radarOpt, 'name');
  18785. });
  18786. each$5(toArr(option.geo), function (geoOpt) {
  18787. if (isObject$3(geoOpt)) {
  18788. compatEC3CommonStyles(geoOpt);
  18789. each$5(toArr(geoOpt.regions), function (regionObj) {
  18790. compatEC3CommonStyles(regionObj);
  18791. });
  18792. }
  18793. });
  18794. each$5(toArr(option.timeline), function (timelineOpt) {
  18795. compatEC3CommonStyles(timelineOpt);
  18796. convertNormalEmphasis(timelineOpt, 'label');
  18797. convertNormalEmphasis(timelineOpt, 'itemStyle');
  18798. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  18799. var data = timelineOpt.data;
  18800. isArray(data) && each$1(data, function (item) {
  18801. if (isObject$1(item)) {
  18802. convertNormalEmphasis(item, 'label');
  18803. convertNormalEmphasis(item, 'itemStyle');
  18804. }
  18805. });
  18806. });
  18807. each$5(toArr(option.toolbox), function (toolboxOpt) {
  18808. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  18809. each$5(toolboxOpt.feature, function (featureOpt) {
  18810. convertNormalEmphasis(featureOpt, 'iconStyle');
  18811. });
  18812. });
  18813. compatTextStyle(toObj(option.axisPointer), 'label');
  18814. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  18815. };
  18816. /*
  18817. * Licensed to the Apache Software Foundation (ASF) under one
  18818. * or more contributor license agreements. See the NOTICE file
  18819. * distributed with this work for additional information
  18820. * regarding copyright ownership. The ASF licenses this file
  18821. * to you under the Apache License, Version 2.0 (the
  18822. * "License"); you may not use this file except in compliance
  18823. * with the License. You may obtain a copy of the License at
  18824. *
  18825. * http://www.apache.org/licenses/LICENSE-2.0
  18826. *
  18827. * Unless required by applicable law or agreed to in writing,
  18828. * software distributed under the License is distributed on an
  18829. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18830. * KIND, either express or implied. See the License for the
  18831. * specific language governing permissions and limitations
  18832. * under the License.
  18833. */
  18834. // Compatitable with 2.0
  18835. function get(opt, path) {
  18836. path = path.split(',');
  18837. var obj = opt;
  18838. for (var i = 0; i < path.length; i++) {
  18839. obj = obj && obj[path[i]];
  18840. if (obj == null) {
  18841. break;
  18842. }
  18843. }
  18844. return obj;
  18845. }
  18846. function set$1(opt, path, val, overwrite) {
  18847. path = path.split(',');
  18848. var obj = opt;
  18849. var key;
  18850. for (var i = 0; i < path.length - 1; i++) {
  18851. key = path[i];
  18852. if (obj[key] == null) {
  18853. obj[key] = {};
  18854. }
  18855. obj = obj[key];
  18856. }
  18857. if (overwrite || obj[path[i]] == null) {
  18858. obj[path[i]] = val;
  18859. }
  18860. }
  18861. function compatLayoutProperties(option) {
  18862. each$1(LAYOUT_PROPERTIES, function (prop) {
  18863. if (prop[0] in option && !(prop[1] in option)) {
  18864. option[prop[1]] = option[prop[0]];
  18865. }
  18866. });
  18867. }
  18868. var LAYOUT_PROPERTIES = [['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']];
  18869. var COMPATITABLE_COMPONENTS = ['grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'];
  18870. var backwardCompat = function (option, isTheme) {
  18871. compatStyle(option, isTheme); // Make sure series array for model initialization.
  18872. option.series = normalizeToArray(option.series);
  18873. each$1(option.series, function (seriesOpt) {
  18874. if (!isObject$1(seriesOpt)) {
  18875. return;
  18876. }
  18877. var seriesType = seriesOpt.type;
  18878. if (seriesType === 'line') {
  18879. if (seriesOpt.clipOverflow != null) {
  18880. seriesOpt.clip = seriesOpt.clipOverflow;
  18881. }
  18882. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  18883. if (seriesOpt.clockWise != null) {
  18884. seriesOpt.clockwise = seriesOpt.clockWise;
  18885. }
  18886. } else if (seriesType === 'gauge') {
  18887. var pointerColor = get(seriesOpt, 'pointer.color');
  18888. pointerColor != null && set$1(seriesOpt, 'itemStyle.color', pointerColor);
  18889. }
  18890. compatLayoutProperties(seriesOpt);
  18891. }); // dataRange has changed to visualMap
  18892. if (option.dataRange) {
  18893. option.visualMap = option.dataRange;
  18894. }
  18895. each$1(COMPATITABLE_COMPONENTS, function (componentName) {
  18896. var options = option[componentName];
  18897. if (options) {
  18898. if (!isArray(options)) {
  18899. options = [options];
  18900. }
  18901. each$1(options, function (option) {
  18902. compatLayoutProperties(option);
  18903. });
  18904. }
  18905. });
  18906. };
  18907. /*
  18908. * Licensed to the Apache Software Foundation (ASF) under one
  18909. * or more contributor license agreements. See the NOTICE file
  18910. * distributed with this work for additional information
  18911. * regarding copyright ownership. The ASF licenses this file
  18912. * to you under the Apache License, Version 2.0 (the
  18913. * "License"); you may not use this file except in compliance
  18914. * with the License. You may obtain a copy of the License at
  18915. *
  18916. * http://www.apache.org/licenses/LICENSE-2.0
  18917. *
  18918. * Unless required by applicable law or agreed to in writing,
  18919. * software distributed under the License is distributed on an
  18920. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18921. * KIND, either express or implied. See the License for the
  18922. * specific language governing permissions and limitations
  18923. * under the License.
  18924. */
  18925. // data processing stage is blocked in stream.
  18926. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  18927. // (2) Only register once when import repeatly.
  18928. // Should be executed after series filtered and before stack calculation.
  18929. var dataStack = function (ecModel) {
  18930. var stackInfoMap = createHashMap();
  18931. ecModel.eachSeries(function (seriesModel) {
  18932. var stack = seriesModel.get('stack'); // Compatibal: when `stack` is set as '', do not stack.
  18933. if (stack) {
  18934. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  18935. var data = seriesModel.getData();
  18936. var stackInfo = {
  18937. // Used for calculate axis extent automatically.
  18938. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  18939. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  18940. stackedDimension: data.getCalculationInfo('stackedDimension'),
  18941. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  18942. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  18943. data: data,
  18944. seriesModel: seriesModel
  18945. }; // If stacked on axis that do not support data stack.
  18946. if (!stackInfo.stackedDimension || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)) {
  18947. return;
  18948. }
  18949. stackInfoList.length && data.setCalculationInfo('stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel);
  18950. stackInfoList.push(stackInfo);
  18951. }
  18952. });
  18953. stackInfoMap.each(calculateStack);
  18954. };
  18955. function calculateStack(stackInfoList) {
  18956. each$1(stackInfoList, function (targetStackInfo, idxInStack) {
  18957. var resultVal = [];
  18958. var resultNaN = [NaN, NaN];
  18959. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  18960. var targetData = targetStackInfo.data;
  18961. var isStackedByIndex = targetStackInfo.isStackedByIndex; // Should not write on raw data, because stack series model list changes
  18962. // depending on legend selection.
  18963. var newData = targetData.map(dims, function (v0, v1, dataIndex) {
  18964. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex); // Consider `connectNulls` of line area, if value is NaN, stackedOver
  18965. // should also be NaN, to draw a appropriate belt area.
  18966. if (isNaN(sum)) {
  18967. return resultNaN;
  18968. }
  18969. var byValue;
  18970. var stackedDataRawIndex;
  18971. if (isStackedByIndex) {
  18972. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  18973. } else {
  18974. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  18975. } // If stackOver is NaN, chart view will render point on value start.
  18976. var stackedOver = NaN;
  18977. for (var j = idxInStack - 1; j >= 0; j--) {
  18978. var stackInfo = stackInfoList[j]; // Has been optimized by inverted indices on `stackedByDimension`.
  18979. if (!isStackedByIndex) {
  18980. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  18981. }
  18982. if (stackedDataRawIndex >= 0) {
  18983. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex); // Considering positive stack, negative stack and empty data
  18984. if (sum >= 0 && val > 0 || // Positive stack
  18985. sum <= 0 && val < 0 // Negative stack
  18986. ) {
  18987. sum += val;
  18988. stackedOver = val;
  18989. break;
  18990. }
  18991. }
  18992. }
  18993. resultVal[0] = sum;
  18994. resultVal[1] = stackedOver;
  18995. return resultVal;
  18996. });
  18997. targetData.hostModel.setData(newData); // Update for consequent calculation
  18998. targetStackInfo.data = newData;
  18999. });
  19000. }
  19001. /*
  19002. * Licensed to the Apache Software Foundation (ASF) under one
  19003. * or more contributor license agreements. See the NOTICE file
  19004. * distributed with this work for additional information
  19005. * regarding copyright ownership. The ASF licenses this file
  19006. * to you under the Apache License, Version 2.0 (the
  19007. * "License"); you may not use this file except in compliance
  19008. * with the License. You may obtain a copy of the License at
  19009. *
  19010. * http://www.apache.org/licenses/LICENSE-2.0
  19011. *
  19012. * Unless required by applicable law or agreed to in writing,
  19013. * software distributed under the License is distributed on an
  19014. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19015. * KIND, either express or implied. See the License for the
  19016. * specific language governing permissions and limitations
  19017. * under the License.
  19018. */
  19019. // TODO
  19020. // ??? refactor? check the outer usage of data provider.
  19021. // merge with defaultDimValueGetter?
  19022. /**
  19023. * If normal array used, mutable chunk size is supported.
  19024. * If typed array used, chunk size must be fixed.
  19025. */
  19026. function DefaultDataProvider(source, dimSize) {
  19027. if (!Source.isInstance(source)) {
  19028. source = Source.seriesDataToSource(source);
  19029. }
  19030. this._source = source;
  19031. var data = this._data = source.data;
  19032. var sourceFormat = source.sourceFormat; // Typed array. TODO IE10+?
  19033. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  19034. this._offset = 0;
  19035. this._dimSize = dimSize;
  19036. this._data = data;
  19037. }
  19038. var methods = providerMethods[sourceFormat === SOURCE_FORMAT_ARRAY_ROWS ? sourceFormat + '_' + source.seriesLayoutBy : sourceFormat];
  19039. extend(this, methods);
  19040. }
  19041. var providerProto = DefaultDataProvider.prototype; // If data is pure without style configuration
  19042. providerProto.pure = false; // If data is persistent and will not be released after use.
  19043. providerProto.persistent = true; // ???! FIXME legacy data provider do not has method getSource
  19044. providerProto.getSource = function () {
  19045. return this._source;
  19046. };
  19047. var providerMethods = {
  19048. 'arrayRows_column': {
  19049. pure: true,
  19050. count: function () {
  19051. return Math.max(0, this._data.length - this._source.startIndex);
  19052. },
  19053. getItem: function (idx) {
  19054. return this._data[idx + this._source.startIndex];
  19055. },
  19056. appendData: appendDataSimply
  19057. },
  19058. 'arrayRows_row': {
  19059. pure: true,
  19060. count: function () {
  19061. var row = this._data[0];
  19062. return row ? Math.max(0, row.length - this._source.startIndex) : 0;
  19063. },
  19064. getItem: function (idx) {
  19065. idx += this._source.startIndex;
  19066. var item = [];
  19067. var data = this._data;
  19068. for (var i = 0; i < data.length; i++) {
  19069. var row = data[i];
  19070. item.push(row ? row[idx] : null);
  19071. }
  19072. return item;
  19073. },
  19074. appendData: function () {
  19075. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  19076. }
  19077. },
  19078. 'objectRows': {
  19079. pure: true,
  19080. count: countSimply,
  19081. getItem: getItemSimply,
  19082. appendData: appendDataSimply
  19083. },
  19084. 'keyedColumns': {
  19085. pure: true,
  19086. count: function () {
  19087. var dimName = this._source.dimensionsDefine[0].name;
  19088. var col = this._data[dimName];
  19089. return col ? col.length : 0;
  19090. },
  19091. getItem: function (idx) {
  19092. var item = [];
  19093. var dims = this._source.dimensionsDefine;
  19094. for (var i = 0; i < dims.length; i++) {
  19095. var col = this._data[dims[i].name];
  19096. item.push(col ? col[idx] : null);
  19097. }
  19098. return item;
  19099. },
  19100. appendData: function (newData) {
  19101. var data = this._data;
  19102. each$1(newData, function (newCol, key) {
  19103. var oldCol = data[key] || (data[key] = []);
  19104. for (var i = 0; i < (newCol || []).length; i++) {
  19105. oldCol.push(newCol[i]);
  19106. }
  19107. });
  19108. }
  19109. },
  19110. 'original': {
  19111. count: countSimply,
  19112. getItem: getItemSimply,
  19113. appendData: appendDataSimply
  19114. },
  19115. 'typedArray': {
  19116. persistent: false,
  19117. pure: true,
  19118. count: function () {
  19119. return this._data ? this._data.length / this._dimSize : 0;
  19120. },
  19121. getItem: function (idx, out) {
  19122. idx = idx - this._offset;
  19123. out = out || [];
  19124. var offset = this._dimSize * idx;
  19125. for (var i = 0; i < this._dimSize; i++) {
  19126. out[i] = this._data[offset + i];
  19127. }
  19128. return out;
  19129. },
  19130. appendData: function (newData) {
  19131. this._data = newData;
  19132. },
  19133. // Clean self if data is already used.
  19134. clean: function () {
  19135. // PENDING
  19136. this._offset += this.count();
  19137. this._data = null;
  19138. }
  19139. }
  19140. };
  19141. function countSimply() {
  19142. return this._data.length;
  19143. }
  19144. function getItemSimply(idx) {
  19145. return this._data[idx];
  19146. }
  19147. function appendDataSimply(newData) {
  19148. for (var i = 0; i < newData.length; i++) {
  19149. this._data.push(newData[i]);
  19150. }
  19151. }
  19152. var rawValueGetters = {
  19153. arrayRows: getRawValueSimply,
  19154. objectRows: function (dataItem, dataIndex, dimIndex, dimName) {
  19155. return dimIndex != null ? dataItem[dimName] : dataItem;
  19156. },
  19157. keyedColumns: getRawValueSimply,
  19158. original: function (dataItem, dataIndex, dimIndex, dimName) {
  19159. // FIXME
  19160. // In some case (markpoint in geo (geo-map.html)), dataItem
  19161. // is {coord: [...]}
  19162. var value = getDataItemValue(dataItem);
  19163. return dimIndex == null || !(value instanceof Array) ? value : value[dimIndex];
  19164. },
  19165. typedArray: getRawValueSimply
  19166. };
  19167. function getRawValueSimply(dataItem, dataIndex, dimIndex, dimName) {
  19168. return dimIndex != null ? dataItem[dimIndex] : dataItem;
  19169. }
  19170. var defaultDimValueGetters = {
  19171. arrayRows: getDimValueSimply,
  19172. objectRows: function (dataItem, dimName, dataIndex, dimIndex) {
  19173. return converDataValue(dataItem[dimName], this._dimensionInfos[dimName]);
  19174. },
  19175. keyedColumns: getDimValueSimply,
  19176. original: function (dataItem, dimName, dataIndex, dimIndex) {
  19177. // Performance sensitive, do not use modelUtil.getDataItemValue.
  19178. // If dataItem is an plain object with no value field, the var `value`
  19179. // will be assigned with the object, but it will be tread correctly
  19180. // in the `convertDataValue`.
  19181. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value); // If any dataItem is like { value: 10 }
  19182. if (!this._rawData.pure && isDataItemOption(dataItem)) {
  19183. this.hasItemOption = true;
  19184. }
  19185. return converDataValue(value instanceof Array ? value[dimIndex] // If value is a single number or something else not array.
  19186. : value, this._dimensionInfos[dimName]);
  19187. },
  19188. typedArray: function (dataItem, dimName, dataIndex, dimIndex) {
  19189. return dataItem[dimIndex];
  19190. }
  19191. };
  19192. function getDimValueSimply(dataItem, dimName, dataIndex, dimIndex) {
  19193. return converDataValue(dataItem[dimIndex], this._dimensionInfos[dimName]);
  19194. }
  19195. /**
  19196. * This helper method convert value in data.
  19197. * @param {string|number|Date} value
  19198. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  19199. * If "dimInfo.ordinalParseAndSave", ordinal value can be parsed.
  19200. */
  19201. function converDataValue(value, dimInfo) {
  19202. // Performance sensitive.
  19203. var dimType = dimInfo && dimInfo.type;
  19204. if (dimType === 'ordinal') {
  19205. // If given value is a category string
  19206. var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
  19207. return ordinalMeta ? ordinalMeta.parseAndCollect(value) : value;
  19208. }
  19209. if (dimType === 'time' // spead up when using timestamp
  19210. && typeof value !== 'number' && value != null && value !== '-') {
  19211. value = +parseDate(value);
  19212. } // dimType defaults 'number'.
  19213. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  19214. // parse to NaN.
  19215. return value == null || value === '' ? NaN // If string (like '-'), using '+' parse to NaN
  19216. // If object, also parse to NaN
  19217. : +value;
  19218. } // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  19219. // Consider persistent.
  19220. // Caution: why use raw value to display on label or tooltip?
  19221. // A reason is to avoid format. For example time value we do not know
  19222. // how to format is expected. More over, if stack is used, calculated
  19223. // value may be 0.91000000001, which have brings trouble to display.
  19224. // TODO: consider how to treat null/undefined/NaN when display?
  19225. /**
  19226. * @param {module:echarts/data/List} data
  19227. * @param {number} dataIndex
  19228. * @param {string|number} [dim] dimName or dimIndex
  19229. * @return {Array.<number>|string|number} can be null/undefined.
  19230. */
  19231. function retrieveRawValue(data, dataIndex, dim) {
  19232. if (!data) {
  19233. return;
  19234. } // Consider data may be not persistent.
  19235. var dataItem = data.getRawDataItem(dataIndex);
  19236. if (dataItem == null) {
  19237. return;
  19238. }
  19239. var sourceFormat = data.getProvider().getSource().sourceFormat;
  19240. var dimName;
  19241. var dimIndex;
  19242. var dimInfo = data.getDimensionInfo(dim);
  19243. if (dimInfo) {
  19244. dimName = dimInfo.name;
  19245. dimIndex = dimInfo.index;
  19246. }
  19247. return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);
  19248. }
  19249. /**
  19250. * Compatible with some cases (in pie, map) like:
  19251. * data: [{name: 'xx', value: 5, selected: true}, ...]
  19252. * where only sourceFormat is 'original' and 'objectRows' supported.
  19253. *
  19254. * ??? TODO
  19255. * Supported detail options in data item when using 'arrayRows'.
  19256. *
  19257. * @param {module:echarts/data/List} data
  19258. * @param {number} dataIndex
  19259. * @param {string} attr like 'selected'
  19260. */
  19261. function retrieveRawAttr(data, dataIndex, attr) {
  19262. if (!data) {
  19263. return;
  19264. }
  19265. var sourceFormat = data.getProvider().getSource().sourceFormat;
  19266. if (sourceFormat !== SOURCE_FORMAT_ORIGINAL && sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS) {
  19267. return;
  19268. }
  19269. var dataItem = data.getRawDataItem(dataIndex);
  19270. if (sourceFormat === SOURCE_FORMAT_ORIGINAL && !isObject$1(dataItem)) {
  19271. dataItem = null;
  19272. }
  19273. if (dataItem) {
  19274. return dataItem[attr];
  19275. }
  19276. }
  19277. /*
  19278. * Licensed to the Apache Software Foundation (ASF) under one
  19279. * or more contributor license agreements. See the NOTICE file
  19280. * distributed with this work for additional information
  19281. * regarding copyright ownership. The ASF licenses this file
  19282. * to you under the Apache License, Version 2.0 (the
  19283. * "License"); you may not use this file except in compliance
  19284. * with the License. You may obtain a copy of the License at
  19285. *
  19286. * http://www.apache.org/licenses/LICENSE-2.0
  19287. *
  19288. * Unless required by applicable law or agreed to in writing,
  19289. * software distributed under the License is distributed on an
  19290. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19291. * KIND, either express or implied. See the License for the
  19292. * specific language governing permissions and limitations
  19293. * under the License.
  19294. */
  19295. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g; // PENDING A little ugly
  19296. var dataFormatMixin = {
  19297. /**
  19298. * Get params for formatter
  19299. * @param {number} dataIndex
  19300. * @param {string} [dataType]
  19301. * @return {Object}
  19302. */
  19303. getDataParams: function (dataIndex, dataType) {
  19304. var data = this.getData(dataType);
  19305. var rawValue = this.getRawValue(dataIndex, dataType);
  19306. var rawDataIndex = data.getRawIndex(dataIndex);
  19307. var name = data.getName(dataIndex);
  19308. var itemOpt = data.getRawDataItem(dataIndex);
  19309. var color = data.getItemVisual(dataIndex, 'color');
  19310. var borderColor = data.getItemVisual(dataIndex, 'borderColor');
  19311. var tooltipModel = this.ecModel.getComponent('tooltip');
  19312. var renderModeOption = tooltipModel && tooltipModel.get('renderMode');
  19313. var renderMode = getTooltipRenderMode(renderModeOption);
  19314. var mainType = this.mainType;
  19315. var isSeries = mainType === 'series';
  19316. var userOutput = data.userOutput;
  19317. return {
  19318. componentType: mainType,
  19319. componentSubType: this.subType,
  19320. componentIndex: this.componentIndex,
  19321. seriesType: isSeries ? this.subType : null,
  19322. seriesIndex: this.seriesIndex,
  19323. seriesId: isSeries ? this.id : null,
  19324. seriesName: isSeries ? this.name : null,
  19325. name: name,
  19326. dataIndex: rawDataIndex,
  19327. data: itemOpt,
  19328. dataType: dataType,
  19329. value: rawValue,
  19330. color: color,
  19331. borderColor: borderColor,
  19332. dimensionNames: userOutput ? userOutput.dimensionNames : null,
  19333. encode: userOutput ? userOutput.encode : null,
  19334. marker: getTooltipMarker({
  19335. color: color,
  19336. renderMode: renderMode
  19337. }),
  19338. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  19339. $vars: ['seriesName', 'name', 'value']
  19340. };
  19341. },
  19342. /**
  19343. * Format label
  19344. * @param {number} dataIndex
  19345. * @param {string} [status='normal'] 'normal' or 'emphasis'
  19346. * @param {string} [dataType]
  19347. * @param {number} [dimIndex] Only used in some chart that
  19348. * use formatter in different dimensions, like radar.
  19349. * @param {string} [labelProp='label']
  19350. * @return {string} If not formatter, return null/undefined
  19351. */
  19352. getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {
  19353. status = status || 'normal';
  19354. var data = this.getData(dataType);
  19355. var itemModel = data.getItemModel(dataIndex);
  19356. var params = this.getDataParams(dataIndex, dataType);
  19357. if (dimIndex != null && params.value instanceof Array) {
  19358. params.value = params.value[dimIndex];
  19359. }
  19360. var formatter = itemModel.get(status === 'normal' ? [labelProp || 'label', 'formatter'] : [status, labelProp || 'label', 'formatter']);
  19361. if (typeof formatter === 'function') {
  19362. params.status = status;
  19363. params.dimensionIndex = dimIndex;
  19364. return formatter(params);
  19365. } else if (typeof formatter === 'string') {
  19366. var str = formatTpl(formatter, params); // Support 'aaa{@[3]}bbb{@product}ccc'.
  19367. // Do not support '}' in dim name util have to.
  19368. return str.replace(DIMENSION_LABEL_REG, function (origin, dim) {
  19369. var len = dim.length;
  19370. if (dim.charAt(0) === '[' && dim.charAt(len - 1) === ']') {
  19371. dim = +dim.slice(1, len - 1); // Also: '[]' => 0
  19372. }
  19373. return retrieveRawValue(data, dataIndex, dim);
  19374. });
  19375. }
  19376. },
  19377. /**
  19378. * Get raw value in option
  19379. * @param {number} idx
  19380. * @param {string} [dataType]
  19381. * @return {Array|number|string}
  19382. */
  19383. getRawValue: function (idx, dataType) {
  19384. return retrieveRawValue(this.getData(dataType), idx);
  19385. },
  19386. /**
  19387. * Should be implemented.
  19388. * @param {number} dataIndex
  19389. * @param {boolean} [multipleSeries=false]
  19390. * @param {number} [dataType]
  19391. * @return {string} tooltip string
  19392. */
  19393. formatTooltip: function () {// Empty function
  19394. }
  19395. };
  19396. /*
  19397. * Licensed to the Apache Software Foundation (ASF) under one
  19398. * or more contributor license agreements. See the NOTICE file
  19399. * distributed with this work for additional information
  19400. * regarding copyright ownership. The ASF licenses this file
  19401. * to you under the Apache License, Version 2.0 (the
  19402. * "License"); you may not use this file except in compliance
  19403. * with the License. You may obtain a copy of the License at
  19404. *
  19405. * http://www.apache.org/licenses/LICENSE-2.0
  19406. *
  19407. * Unless required by applicable law or agreed to in writing,
  19408. * software distributed under the License is distributed on an
  19409. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19410. * KIND, either express or implied. See the License for the
  19411. * specific language governing permissions and limitations
  19412. * under the License.
  19413. */
  19414. /**
  19415. * @param {Object} define
  19416. * @return See the return of `createTask`.
  19417. */
  19418. function createTask(define) {
  19419. return new Task(define);
  19420. }
  19421. /**
  19422. * @constructor
  19423. * @param {Object} define
  19424. * @param {Function} define.reset Custom reset
  19425. * @param {Function} [define.plan] Returns 'reset' indicate reset immediately.
  19426. * @param {Function} [define.count] count is used to determin data task.
  19427. * @param {Function} [define.onDirty] count is used to determin data task.
  19428. */
  19429. function Task(define) {
  19430. define = define || {};
  19431. this._reset = define.reset;
  19432. this._plan = define.plan;
  19433. this._count = define.count;
  19434. this._onDirty = define.onDirty;
  19435. this._dirty = true; // Context must be specified implicitly, to
  19436. // avoid miss update context when model changed.
  19437. this.context;
  19438. }
  19439. var taskProto = Task.prototype;
  19440. /**
  19441. * @param {Object} performArgs
  19442. * @param {number} [performArgs.step] Specified step.
  19443. * @param {number} [performArgs.skip] Skip customer perform call.
  19444. * @param {number} [performArgs.modBy] Sampling window size.
  19445. * @param {number} [performArgs.modDataCount] Sampling count.
  19446. */
  19447. taskProto.perform = function (performArgs) {
  19448. var upTask = this._upstream;
  19449. var skip = performArgs && performArgs.skip; // TODO some refactor.
  19450. // Pull data. Must pull data each time, because context.data
  19451. // may be updated by Series.setData.
  19452. if (this._dirty && upTask) {
  19453. var context = this.context;
  19454. context.data = context.outputData = upTask.context.outputData;
  19455. }
  19456. if (this.__pipeline) {
  19457. this.__pipeline.currentTask = this;
  19458. }
  19459. var planResult;
  19460. if (this._plan && !skip) {
  19461. planResult = this._plan(this.context);
  19462. } // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  19463. // elements uniformed distributed when progress, especially when moving or zooming.
  19464. var lastModBy = normalizeModBy(this._modBy);
  19465. var lastModDataCount = this._modDataCount || 0;
  19466. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  19467. var modDataCount = performArgs && performArgs.modDataCount || 0;
  19468. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  19469. planResult = 'reset';
  19470. }
  19471. function normalizeModBy(val) {
  19472. !(val >= 1) && (val = 1); // jshint ignore:line
  19473. return val;
  19474. }
  19475. var forceFirstProgress;
  19476. if (this._dirty || planResult === 'reset') {
  19477. this._dirty = false;
  19478. forceFirstProgress = reset(this, skip);
  19479. }
  19480. this._modBy = modBy;
  19481. this._modDataCount = modDataCount;
  19482. var step = performArgs && performArgs.step;
  19483. if (upTask) {
  19484. this._dueEnd = upTask._outputDueEnd;
  19485. } // DataTask or overallTask
  19486. else {
  19487. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  19488. } // Note: Stubs, that its host overall task let it has progress, has progress.
  19489. // If no progress, pass index from upstream to downstream each time plan called.
  19490. if (this._progress) {
  19491. var start = this._dueIndex;
  19492. var end = Math.min(step != null ? this._dueIndex + step : Infinity, this._dueEnd);
  19493. if (!skip && (forceFirstProgress || start < end)) {
  19494. var progress = this._progress;
  19495. if (isArray(progress)) {
  19496. for (var i = 0; i < progress.length; i++) {
  19497. doProgress(this, progress[i], start, end, modBy, modDataCount);
  19498. }
  19499. } else {
  19500. doProgress(this, progress, start, end, modBy, modDataCount);
  19501. }
  19502. }
  19503. this._dueIndex = end; // If no `outputDueEnd`, assume that output data and
  19504. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  19505. var outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : end;
  19506. this._outputDueEnd = outputDueEnd;
  19507. } else {
  19508. // (1) Some overall task has no progress.
  19509. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  19510. // This should always be performed so it can be passed to downstream.
  19511. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null ? this._settedOutputEnd : this._dueEnd;
  19512. }
  19513. return this.unfinished();
  19514. };
  19515. var iterator = function () {
  19516. var end;
  19517. var current;
  19518. var modBy;
  19519. var modDataCount;
  19520. var winCount;
  19521. var it = {
  19522. reset: function (s, e, sStep, sCount) {
  19523. current = s;
  19524. end = e;
  19525. modBy = sStep;
  19526. modDataCount = sCount;
  19527. winCount = Math.ceil(modDataCount / modBy);
  19528. it.next = modBy > 1 && modDataCount > 0 ? modNext : sequentialNext;
  19529. }
  19530. };
  19531. return it;
  19532. function sequentialNext() {
  19533. return current < end ? current++ : null;
  19534. }
  19535. function modNext() {
  19536. var dataIndex = current % winCount * modBy + Math.ceil(current / winCount);
  19537. var result = current >= end ? null : dataIndex < modDataCount ? dataIndex // If modDataCount is smaller than data.count() (consider `appendData` case),
  19538. // Use normal linear rendering mode.
  19539. : current;
  19540. current++;
  19541. return result;
  19542. }
  19543. }();
  19544. taskProto.dirty = function () {
  19545. this._dirty = true;
  19546. this._onDirty && this._onDirty(this.context);
  19547. };
  19548. function doProgress(taskIns, progress, start, end, modBy, modDataCount) {
  19549. iterator.reset(start, end, modBy, modDataCount);
  19550. taskIns._callingProgress = progress;
  19551. taskIns._callingProgress({
  19552. start: start,
  19553. end: end,
  19554. count: end - start,
  19555. next: iterator.next
  19556. }, taskIns.context);
  19557. }
  19558. function reset(taskIns, skip) {
  19559. taskIns._dueIndex = taskIns._outputDueEnd = taskIns._dueEnd = 0;
  19560. taskIns._settedOutputEnd = null;
  19561. var progress;
  19562. var forceFirstProgress;
  19563. if (!skip && taskIns._reset) {
  19564. progress = taskIns._reset(taskIns.context);
  19565. if (progress && progress.progress) {
  19566. forceFirstProgress = progress.forceFirstProgress;
  19567. progress = progress.progress;
  19568. } // To simplify no progress checking, array must has item.
  19569. if (isArray(progress) && !progress.length) {
  19570. progress = null;
  19571. }
  19572. }
  19573. taskIns._progress = progress;
  19574. taskIns._modBy = taskIns._modDataCount = null;
  19575. var downstream = taskIns._downstream;
  19576. downstream && downstream.dirty();
  19577. return forceFirstProgress;
  19578. }
  19579. /**
  19580. * @return {boolean}
  19581. */
  19582. taskProto.unfinished = function () {
  19583. return this._progress && this._dueIndex < this._dueEnd;
  19584. };
  19585. /**
  19586. * @param {Object} downTask The downstream task.
  19587. * @return {Object} The downstream task.
  19588. */
  19589. taskProto.pipe = function (downTask) {
  19590. // If already downstream, do not dirty downTask.
  19591. if (this._downstream !== downTask || this._dirty) {
  19592. this._downstream = downTask;
  19593. downTask._upstream = this;
  19594. downTask.dirty();
  19595. }
  19596. };
  19597. taskProto.dispose = function () {
  19598. if (this._disposed) {
  19599. return;
  19600. }
  19601. this._upstream && (this._upstream._downstream = null);
  19602. this._downstream && (this._downstream._upstream = null);
  19603. this._dirty = false;
  19604. this._disposed = true;
  19605. };
  19606. taskProto.getUpstream = function () {
  19607. return this._upstream;
  19608. };
  19609. taskProto.getDownstream = function () {
  19610. return this._downstream;
  19611. };
  19612. taskProto.setOutputEnd = function (end) {
  19613. // This only happend in dataTask, dataZoom, map, currently.
  19614. // where dataZoom do not set end each time, but only set
  19615. // when reset. So we should record the setted end, in case
  19616. // that the stub of dataZoom perform again and earse the
  19617. // setted end by upstream.
  19618. this._outputDueEnd = this._settedOutputEnd = end;
  19619. }; ///////////////////////////////////////////////////////////
  19620. // For stream debug (Should be commented out after used!)
  19621. // Usage: printTask(this, 'begin');
  19622. // Usage: printTask(this, null, {someExtraProp});
  19623. // function printTask(task, prefix, extra) {
  19624. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  19625. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  19626. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  19627. // var props = [];
  19628. // if (task.__pipeline) {
  19629. // var val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  19630. // props.push({text: 'idx', value: val});
  19631. // } else {
  19632. // var stubCount = 0;
  19633. // task.agentStubMap.each(() => stubCount++);
  19634. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  19635. // }
  19636. // props.push({text: 'uid', value: task.uidDebug});
  19637. // if (task.__pipeline) {
  19638. // props.push({text: 'pid', value: task.__pipeline.id});
  19639. // task.agent && props.push(
  19640. // {text: 'stubFor', value: task.agent.uidDebug}
  19641. // );
  19642. // }
  19643. // props.push(
  19644. // {text: 'dirty', value: task._dirty},
  19645. // {text: 'dueIndex', value: task._dueIndex},
  19646. // {text: 'dueEnd', value: task._dueEnd},
  19647. // {text: 'outputDueEnd', value: task._outputDueEnd}
  19648. // );
  19649. // if (extra) {
  19650. // Object.keys(extra).forEach(key => {
  19651. // props.push({text: key, value: extra[key]});
  19652. // });
  19653. // }
  19654. // var args = ['color: blue'];
  19655. // var msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  19656. // args.push('color: black', 'color: red'),
  19657. // `${item.text}: %c${item.value}`
  19658. // )).join('%c, ');
  19659. // console.log.apply(console, [msg].concat(args));
  19660. // // console.log(this);
  19661. // }
  19662. /*
  19663. * Licensed to the Apache Software Foundation (ASF) under one
  19664. * or more contributor license agreements. See the NOTICE file
  19665. * distributed with this work for additional information
  19666. * regarding copyright ownership. The ASF licenses this file
  19667. * to you under the Apache License, Version 2.0 (the
  19668. * "License"); you may not use this file except in compliance
  19669. * with the License. You may obtain a copy of the License at
  19670. *
  19671. * http://www.apache.org/licenses/LICENSE-2.0
  19672. *
  19673. * Unless required by applicable law or agreed to in writing,
  19674. * software distributed under the License is distributed on an
  19675. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19676. * KIND, either express or implied. See the License for the
  19677. * specific language governing permissions and limitations
  19678. * under the License.
  19679. */
  19680. var inner$4 = makeInner();
  19681. var SeriesModel = ComponentModel.extend({
  19682. type: 'series.__base__',
  19683. /**
  19684. * @readOnly
  19685. */
  19686. seriesIndex: 0,
  19687. // coodinateSystem will be injected in the echarts/CoordinateSystem
  19688. coordinateSystem: null,
  19689. /**
  19690. * @type {Object}
  19691. * @protected
  19692. */
  19693. defaultOption: null,
  19694. /**
  19695. * legend visual provider to the legend component
  19696. * @type {Object}
  19697. */
  19698. // PENDING
  19699. legendVisualProvider: null,
  19700. /**
  19701. * Access path of color for visual
  19702. */
  19703. visualColorAccessPath: 'itemStyle.color',
  19704. /**
  19705. * Access path of borderColor for visual
  19706. */
  19707. visualBorderColorAccessPath: 'itemStyle.borderColor',
  19708. /**
  19709. * Support merge layout params.
  19710. * Only support 'box' now (left/right/top/bottom/width/height).
  19711. * @type {string|Object} Object can be {ignoreSize: true}
  19712. * @readOnly
  19713. */
  19714. layoutMode: null,
  19715. init: function (option, parentModel, ecModel, extraOpt) {
  19716. /**
  19717. * @type {number}
  19718. * @readOnly
  19719. */
  19720. this.seriesIndex = this.componentIndex;
  19721. this.dataTask = createTask({
  19722. count: dataTaskCount,
  19723. reset: dataTaskReset
  19724. });
  19725. this.dataTask.context = {
  19726. model: this
  19727. };
  19728. this.mergeDefaultAndTheme(option, ecModel);
  19729. prepareSource(this);
  19730. var data = this.getInitialData(option, ecModel);
  19731. wrapData(data, this);
  19732. this.dataTask.context.data = data;
  19733. /**
  19734. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  19735. * @private
  19736. */
  19737. inner$4(this).dataBeforeProcessed = data; // If we reverse the order (make data firstly, and then make
  19738. // dataBeforeProcessed by cloneShallow), cloneShallow will
  19739. // cause data.graph.data !== data when using
  19740. // module:echarts/data/Graph or module:echarts/data/Tree.
  19741. // See module:echarts/data/helper/linkList
  19742. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  19743. // init or merge stage, because the data can be restored. So we do not `restoreData`
  19744. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  19745. // Call `seriesModel.getRawData()` instead.
  19746. // this.restoreData();
  19747. autoSeriesName(this);
  19748. },
  19749. /**
  19750. * Util for merge default and theme to option
  19751. * @param {Object} option
  19752. * @param {module:echarts/model/Global} ecModel
  19753. */
  19754. mergeDefaultAndTheme: function (option, ecModel) {
  19755. var layoutMode = this.layoutMode;
  19756. var inputPositionParams = layoutMode ? getLayoutParams(option) : {}; // Backward compat: using subType on theme.
  19757. // But if name duplicate between series subType
  19758. // (for example: parallel) add component mainType,
  19759. // add suffix 'Series'.
  19760. var themeSubType = this.subType;
  19761. if (ComponentModel.hasClass(themeSubType)) {
  19762. themeSubType += 'Series';
  19763. }
  19764. merge(option, ecModel.getTheme().get(this.subType));
  19765. merge(option, this.getDefaultOption()); // Default label emphasis `show`
  19766. defaultEmphasis(option, 'label', ['show']);
  19767. this.fillDataTextStyle(option.data);
  19768. if (layoutMode) {
  19769. mergeLayoutParam(option, inputPositionParams, layoutMode);
  19770. }
  19771. },
  19772. mergeOption: function (newSeriesOption, ecModel) {
  19773. // this.settingTask.dirty();
  19774. newSeriesOption = merge(this.option, newSeriesOption, true);
  19775. this.fillDataTextStyle(newSeriesOption.data);
  19776. var layoutMode = this.layoutMode;
  19777. if (layoutMode) {
  19778. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  19779. }
  19780. prepareSource(this);
  19781. var data = this.getInitialData(newSeriesOption, ecModel);
  19782. wrapData(data, this);
  19783. this.dataTask.dirty();
  19784. this.dataTask.context.data = data;
  19785. inner$4(this).dataBeforeProcessed = data;
  19786. autoSeriesName(this);
  19787. },
  19788. fillDataTextStyle: function (data) {
  19789. // Default data label emphasis `show`
  19790. // FIXME Tree structure data ?
  19791. // FIXME Performance ?
  19792. if (data && !isTypedArray(data)) {
  19793. var props = ['show'];
  19794. for (var i = 0; i < data.length; i++) {
  19795. if (data[i] && data[i].label) {
  19796. defaultEmphasis(data[i], 'label', props);
  19797. }
  19798. }
  19799. }
  19800. },
  19801. /**
  19802. * Init a data structure from data related option in series
  19803. * Must be overwritten
  19804. */
  19805. getInitialData: function () {},
  19806. /**
  19807. * Append data to list
  19808. * @param {Object} params
  19809. * @param {Array|TypedArray} params.data
  19810. */
  19811. appendData: function (params) {
  19812. // FIXME ???
  19813. // (1) If data from dataset, forbidden append.
  19814. // (2) support append data of dataset.
  19815. var data = this.getRawData();
  19816. data.appendData(params.data);
  19817. },
  19818. /**
  19819. * Consider some method like `filter`, `map` need make new data,
  19820. * We should make sure that `seriesModel.getData()` get correct
  19821. * data in the stream procedure. So we fetch data from upstream
  19822. * each time `task.perform` called.
  19823. * @param {string} [dataType]
  19824. * @return {module:echarts/data/List}
  19825. */
  19826. getData: function (dataType) {
  19827. var task = getCurrentTask(this);
  19828. if (task) {
  19829. var data = task.context.data;
  19830. return dataType == null ? data : data.getLinkedData(dataType);
  19831. } else {
  19832. // When series is not alive (that may happen when click toolbox
  19833. // restore or setOption with not merge mode), series data may
  19834. // be still need to judge animation or something when graphic
  19835. // elements want to know whether fade out.
  19836. return inner$4(this).data;
  19837. }
  19838. },
  19839. /**
  19840. * @param {module:echarts/data/List} data
  19841. */
  19842. setData: function (data) {
  19843. var task = getCurrentTask(this);
  19844. if (task) {
  19845. var context = task.context; // Consider case: filter, data sample.
  19846. if (context.data !== data && task.modifyOutputEnd) {
  19847. task.setOutputEnd(data.count());
  19848. }
  19849. context.outputData = data; // Caution: setData should update context.data,
  19850. // Because getData may be called multiply in a
  19851. // single stage and expect to get the data just
  19852. // set. (For example, AxisProxy, x y both call
  19853. // getData and setDate sequentially).
  19854. // So the context.data should be fetched from
  19855. // upstream each time when a stage starts to be
  19856. // performed.
  19857. if (task !== this.dataTask) {
  19858. context.data = data;
  19859. }
  19860. }
  19861. inner$4(this).data = data;
  19862. },
  19863. /**
  19864. * @see {module:echarts/data/helper/sourceHelper#getSource}
  19865. * @return {module:echarts/data/Source} source
  19866. */
  19867. getSource: function () {
  19868. return getSource(this);
  19869. },
  19870. /**
  19871. * Get data before processed
  19872. * @return {module:echarts/data/List}
  19873. */
  19874. getRawData: function () {
  19875. return inner$4(this).dataBeforeProcessed;
  19876. },
  19877. /**
  19878. * Get base axis if has coordinate system and has axis.
  19879. * By default use coordSys.getBaseAxis();
  19880. * Can be overrided for some chart.
  19881. * @return {type} description
  19882. */
  19883. getBaseAxis: function () {
  19884. var coordSys = this.coordinateSystem;
  19885. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  19886. },
  19887. // FIXME
  19888. /**
  19889. * Default tooltip formatter
  19890. *
  19891. * @param {number} dataIndex
  19892. * @param {boolean} [multipleSeries=false]
  19893. * @param {number} [dataType]
  19894. * @param {string} [renderMode='html'] valid values: 'html' and 'richText'.
  19895. * 'html' is used for rendering tooltip in extra DOM form, and the result
  19896. * string is used as DOM HTML content.
  19897. * 'richText' is used for rendering tooltip in rich text form, for those where
  19898. * DOM operation is not supported.
  19899. * @return {Object} formatted tooltip with `html` and `markers`
  19900. */
  19901. formatTooltip: function (dataIndex, multipleSeries, dataType, renderMode) {
  19902. var series = this;
  19903. renderMode = renderMode || 'html';
  19904. var newLine = renderMode === 'html' ? '<br/>' : '\n';
  19905. var isRichText = renderMode === 'richText';
  19906. var markers = {};
  19907. var markerId = 0;
  19908. function formatArrayValue(value) {
  19909. // ??? TODO refactor these logic.
  19910. // check: category-no-encode-has-axis-data in dataset.html
  19911. var vertially = reduce(value, function (vertially, val, idx) {
  19912. var dimItem = data.getDimensionInfo(idx);
  19913. return vertially |= dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  19914. }, 0);
  19915. var result = [];
  19916. tooltipDims.length ? each$1(tooltipDims, function (dim) {
  19917. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  19918. }) // By default, all dims is used on tooltip.
  19919. : each$1(value, setEachItem);
  19920. function setEachItem(val, dim) {
  19921. var dimInfo = data.getDimensionInfo(dim); // If `dimInfo.tooltip` is not set, show tooltip.
  19922. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  19923. return;
  19924. }
  19925. var dimType = dimInfo.type;
  19926. var markName = 'sub' + series.seriesIndex + 'at' + markerId;
  19927. var dimHead = getTooltipMarker({
  19928. color: color,
  19929. type: 'subItem',
  19930. renderMode: renderMode,
  19931. markerId: markName
  19932. });
  19933. var dimHeadStr = typeof dimHead === 'string' ? dimHead : dimHead.content;
  19934. var valStr = (vertially ? dimHeadStr + encodeHTML(dimInfo.displayName || '-') + ': ' : '') + // FIXME should not format time for raw data?
  19935. encodeHTML(dimType === 'ordinal' ? val + '' : dimType === 'time' ? multipleSeries ? '' : formatTime('yyyy/MM/dd hh:mm:ss', val) : addCommas(val));
  19936. valStr && result.push(valStr);
  19937. if (isRichText) {
  19938. markers[markName] = color;
  19939. ++markerId;
  19940. }
  19941. }
  19942. var newLine = vertially ? isRichText ? '\n' : '<br/>' : '';
  19943. var content = newLine + result.join(newLine || ', ');
  19944. return {
  19945. renderMode: renderMode,
  19946. content: content,
  19947. style: markers
  19948. };
  19949. }
  19950. function formatSingleValue(val) {
  19951. // return encodeHTML(addCommas(val));
  19952. return {
  19953. renderMode: renderMode,
  19954. content: encodeHTML(addCommas(val)),
  19955. style: markers
  19956. };
  19957. }
  19958. var data = this.getData();
  19959. var tooltipDims = data.mapDimension('defaultedTooltip', true);
  19960. var tooltipDimLen = tooltipDims.length;
  19961. var value = this.getRawValue(dataIndex);
  19962. var isValueArr = isArray(value);
  19963. var color = data.getItemVisual(dataIndex, 'color');
  19964. if (isObject$1(color) && color.colorStops) {
  19965. color = (color.colorStops[0] || {}).color;
  19966. }
  19967. color = color || 'transparent'; // Complicated rule for pretty tooltip.
  19968. var formattedValue = tooltipDimLen > 1 || isValueArr && !tooltipDimLen ? formatArrayValue(value) : tooltipDimLen ? formatSingleValue(retrieveRawValue(data, dataIndex, tooltipDims[0])) : formatSingleValue(isValueArr ? value[0] : value);
  19969. var content = formattedValue.content;
  19970. var markName = series.seriesIndex + 'at' + markerId;
  19971. var colorEl = getTooltipMarker({
  19972. color: color,
  19973. type: 'item',
  19974. renderMode: renderMode,
  19975. markerId: markName
  19976. });
  19977. markers[markName] = color;
  19978. ++markerId;
  19979. var name = data.getName(dataIndex);
  19980. var seriesName = this.name;
  19981. if (!isNameSpecified(this)) {
  19982. seriesName = '';
  19983. }
  19984. seriesName = seriesName ? encodeHTML(seriesName) + (!multipleSeries ? newLine : ': ') : '';
  19985. var colorStr = typeof colorEl === 'string' ? colorEl : colorEl.content;
  19986. var html = !multipleSeries ? seriesName + colorStr + (name ? encodeHTML(name) + ': ' + content : content) : colorStr + seriesName + content;
  19987. return {
  19988. html: html,
  19989. markers: markers
  19990. };
  19991. },
  19992. /**
  19993. * @return {boolean}
  19994. */
  19995. isAnimationEnabled: function () {
  19996. if (env$1.node) {
  19997. return false;
  19998. }
  19999. var animationEnabled = this.getShallow('animation');
  20000. if (animationEnabled) {
  20001. if (this.getData().count() > this.getShallow('animationThreshold')) {
  20002. animationEnabled = false;
  20003. }
  20004. }
  20005. return animationEnabled;
  20006. },
  20007. restoreData: function () {
  20008. this.dataTask.dirty();
  20009. },
  20010. getColorFromPalette: function (name, scope, requestColorNum) {
  20011. var ecModel = this.ecModel; // PENDING
  20012. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope, requestColorNum);
  20013. if (!color) {
  20014. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  20015. }
  20016. return color;
  20017. },
  20018. /**
  20019. * Use `data.mapDimension(coordDim, true)` instead.
  20020. * @deprecated
  20021. */
  20022. coordDimToDataDim: function (coordDim) {
  20023. return this.getRawData().mapDimension(coordDim, true);
  20024. },
  20025. /**
  20026. * Get progressive rendering count each step
  20027. * @return {number}
  20028. */
  20029. getProgressive: function () {
  20030. return this.get('progressive');
  20031. },
  20032. /**
  20033. * Get progressive rendering count each step
  20034. * @return {number}
  20035. */
  20036. getProgressiveThreshold: function () {
  20037. return this.get('progressiveThreshold');
  20038. },
  20039. /**
  20040. * Get data indices for show tooltip content. See tooltip.
  20041. * @abstract
  20042. * @param {Array.<string>|string} dim
  20043. * @param {Array.<number>} value
  20044. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  20045. * @return {Object} {dataIndices, nestestValue}.
  20046. */
  20047. getAxisTooltipData: null,
  20048. /**
  20049. * See tooltip.
  20050. * @abstract
  20051. * @param {number} dataIndex
  20052. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  20053. */
  20054. getTooltipPosition: null,
  20055. /**
  20056. * @see {module:echarts/stream/Scheduler}
  20057. */
  20058. pipeTask: null,
  20059. /**
  20060. * Convinient for override in extended class.
  20061. * @protected
  20062. * @type {Function}
  20063. */
  20064. preventIncremental: null,
  20065. /**
  20066. * @public
  20067. * @readOnly
  20068. * @type {Object}
  20069. */
  20070. pipelineContext: null
  20071. });
  20072. mixin(SeriesModel, dataFormatMixin);
  20073. mixin(SeriesModel, colorPaletteMixin);
  20074. /**
  20075. * MUST be called after `prepareSource` called
  20076. * Here we need to make auto series, especially for auto legend. But we
  20077. * do not modify series.name in option to avoid side effects.
  20078. */
  20079. function autoSeriesName(seriesModel) {
  20080. // User specified name has higher priority, otherwise it may cause
  20081. // series can not be queried unexpectedly.
  20082. var name = seriesModel.name;
  20083. if (!isNameSpecified(seriesModel)) {
  20084. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  20085. }
  20086. }
  20087. function getSeriesAutoName(seriesModel) {
  20088. var data = seriesModel.getRawData();
  20089. var dataDims = data.mapDimension('seriesName', true);
  20090. var nameArr = [];
  20091. each$1(dataDims, function (dataDim) {
  20092. var dimInfo = data.getDimensionInfo(dataDim);
  20093. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  20094. });
  20095. return nameArr.join(' ');
  20096. }
  20097. function dataTaskCount(context) {
  20098. return context.model.getRawData().count();
  20099. }
  20100. function dataTaskReset(context) {
  20101. var seriesModel = context.model;
  20102. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  20103. return dataTaskProgress;
  20104. }
  20105. function dataTaskProgress(param, context) {
  20106. // Avoid repead cloneShallow when data just created in reset.
  20107. if (context.outputData && param.end > context.outputData.count()) {
  20108. context.model.getRawData().cloneShallow(context.outputData);
  20109. }
  20110. } // TODO refactor
  20111. function wrapData(data, seriesModel) {
  20112. each$1(data.CHANGABLE_METHODS, function (methodName) {
  20113. data.wrapMethod(methodName, curry(onDataSelfChange, seriesModel));
  20114. });
  20115. }
  20116. function onDataSelfChange(seriesModel) {
  20117. var task = getCurrentTask(seriesModel);
  20118. if (task) {
  20119. // Consider case: filter, selectRange
  20120. task.setOutputEnd(this.count());
  20121. }
  20122. }
  20123. function getCurrentTask(seriesModel) {
  20124. var scheduler = (seriesModel.ecModel || {}).scheduler;
  20125. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  20126. if (pipeline) {
  20127. // When pipline finished, the currrentTask keep the last
  20128. // task (renderTask).
  20129. var task = pipeline.currentTask;
  20130. if (task) {
  20131. var agentStubMap = task.agentStubMap;
  20132. if (agentStubMap) {
  20133. task = agentStubMap.get(seriesModel.uid);
  20134. }
  20135. }
  20136. return task;
  20137. }
  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. var Component$1 = function () {
  20158. /**
  20159. * @type {module:zrender/container/Group}
  20160. * @readOnly
  20161. */
  20162. this.group = new Group();
  20163. /**
  20164. * @type {string}
  20165. * @readOnly
  20166. */
  20167. this.uid = getUID('viewComponent');
  20168. };
  20169. Component$1.prototype = {
  20170. constructor: Component$1,
  20171. init: function (ecModel, api) {},
  20172. render: function (componentModel, ecModel, api, payload) {},
  20173. dispose: function () {},
  20174. /**
  20175. * @param {string} eventType
  20176. * @param {Object} query
  20177. * @param {module:zrender/Element} targetEl
  20178. * @param {Object} packedEvent
  20179. * @return {boolen} Pass only when return `true`.
  20180. */
  20181. filterForExposedEvent: null
  20182. };
  20183. var componentProto = Component$1.prototype;
  20184. componentProto.updateView = componentProto.updateLayout = componentProto.updateVisual = function (seriesModel, ecModel, api, payload) {// Do nothing;
  20185. }; // Enable Component.extend.
  20186. enableClassExtend(Component$1); // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  20187. enableClassManagement(Component$1, {
  20188. registerWhenExtend: true
  20189. });
  20190. /*
  20191. * Licensed to the Apache Software Foundation (ASF) under one
  20192. * or more contributor license agreements. See the NOTICE file
  20193. * distributed with this work for additional information
  20194. * regarding copyright ownership. The ASF licenses this file
  20195. * to you under the Apache License, Version 2.0 (the
  20196. * "License"); you may not use this file except in compliance
  20197. * with the License. You may obtain a copy of the License at
  20198. *
  20199. * http://www.apache.org/licenses/LICENSE-2.0
  20200. *
  20201. * Unless required by applicable law or agreed to in writing,
  20202. * software distributed under the License is distributed on an
  20203. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20204. * KIND, either express or implied. See the License for the
  20205. * specific language governing permissions and limitations
  20206. * under the License.
  20207. */
  20208. /**
  20209. * @return {string} If large mode changed, return string 'reset';
  20210. */
  20211. var createRenderPlanner = function () {
  20212. var inner = makeInner();
  20213. return function (seriesModel) {
  20214. var fields = inner(seriesModel);
  20215. var pipelineContext = seriesModel.pipelineContext;
  20216. var originalLarge = fields.large;
  20217. var originalProgressive = fields.progressiveRender; // FIXME: if the planner works on a filtered series, `pipelineContext` does not
  20218. // exists. See #11611 . Probably we need to modify this structure, see the comment
  20219. // on `performRawSeries` in `Schedular.js`.
  20220. var large = fields.large = pipelineContext && pipelineContext.large;
  20221. var progressive = fields.progressiveRender = pipelineContext && pipelineContext.progressiveRender;
  20222. return !!(originalLarge ^ large || originalProgressive ^ progressive) && 'reset';
  20223. };
  20224. };
  20225. /*
  20226. * Licensed to the Apache Software Foundation (ASF) under one
  20227. * or more contributor license agreements. See the NOTICE file
  20228. * distributed with this work for additional information
  20229. * regarding copyright ownership. The ASF licenses this file
  20230. * to you under the Apache License, Version 2.0 (the
  20231. * "License"); you may not use this file except in compliance
  20232. * with the License. You may obtain a copy of the License at
  20233. *
  20234. * http://www.apache.org/licenses/LICENSE-2.0
  20235. *
  20236. * Unless required by applicable law or agreed to in writing,
  20237. * software distributed under the License is distributed on an
  20238. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20239. * KIND, either express or implied. See the License for the
  20240. * specific language governing permissions and limitations
  20241. * under the License.
  20242. */
  20243. var inner$5 = makeInner();
  20244. var renderPlanner = createRenderPlanner();
  20245. function Chart() {
  20246. /**
  20247. * @type {module:zrender/container/Group}
  20248. * @readOnly
  20249. */
  20250. this.group = new Group();
  20251. /**
  20252. * @type {string}
  20253. * @readOnly
  20254. */
  20255. this.uid = getUID('viewChart');
  20256. this.renderTask = createTask({
  20257. plan: renderTaskPlan,
  20258. reset: renderTaskReset
  20259. });
  20260. this.renderTask.context = {
  20261. view: this
  20262. };
  20263. }
  20264. Chart.prototype = {
  20265. type: 'chart',
  20266. /**
  20267. * Init the chart.
  20268. * @param {module:echarts/model/Global} ecModel
  20269. * @param {module:echarts/ExtensionAPI} api
  20270. */
  20271. init: function (ecModel, api) {},
  20272. /**
  20273. * Render the chart.
  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. render: function (seriesModel, ecModel, api, payload) {},
  20280. /**
  20281. * Highlight series or specified data item.
  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. */
  20287. highlight: function (seriesModel, ecModel, api, payload) {
  20288. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  20289. },
  20290. /**
  20291. * Downplay series or specified data item.
  20292. * @param {module:echarts/model/Series} seriesModel
  20293. * @param {module:echarts/model/Global} ecModel
  20294. * @param {module:echarts/ExtensionAPI} api
  20295. * @param {Object} payload
  20296. */
  20297. downplay: function (seriesModel, ecModel, api, payload) {
  20298. toggleHighlight(seriesModel.getData(), payload, 'normal');
  20299. },
  20300. /**
  20301. * Remove self.
  20302. * @param {module:echarts/model/Global} ecModel
  20303. * @param {module:echarts/ExtensionAPI} api
  20304. */
  20305. remove: function (ecModel, api) {
  20306. this.group.removeAll();
  20307. },
  20308. /**
  20309. * Dispose self.
  20310. * @param {module:echarts/model/Global} ecModel
  20311. * @param {module:echarts/ExtensionAPI} api
  20312. */
  20313. dispose: function () {},
  20314. /**
  20315. * Rendering preparation in progressive mode.
  20316. * @param {module:echarts/model/Series} seriesModel
  20317. * @param {module:echarts/model/Global} ecModel
  20318. * @param {module:echarts/ExtensionAPI} api
  20319. * @param {Object} payload
  20320. */
  20321. incrementalPrepareRender: null,
  20322. /**
  20323. * Render in progressive mode.
  20324. * @param {Object} params See taskParams in `stream/task.js`
  20325. * @param {module:echarts/model/Series} seriesModel
  20326. * @param {module:echarts/model/Global} ecModel
  20327. * @param {module:echarts/ExtensionAPI} api
  20328. * @param {Object} payload
  20329. */
  20330. incrementalRender: null,
  20331. /**
  20332. * Update transform directly.
  20333. * @param {module:echarts/model/Series} seriesModel
  20334. * @param {module:echarts/model/Global} ecModel
  20335. * @param {module:echarts/ExtensionAPI} api
  20336. * @param {Object} payload
  20337. * @return {Object} {update: true}
  20338. */
  20339. updateTransform: null,
  20340. /**
  20341. * The view contains the given point.
  20342. * @interface
  20343. * @param {Array.<number>} point
  20344. * @return {boolean}
  20345. */
  20346. // containPoint: function () {}
  20347. /**
  20348. * @param {string} eventType
  20349. * @param {Object} query
  20350. * @param {module:zrender/Element} targetEl
  20351. * @param {Object} packedEvent
  20352. * @return {boolen} Pass only when return `true`.
  20353. */
  20354. filterForExposedEvent: null
  20355. };
  20356. var chartProto = Chart.prototype;
  20357. chartProto.updateView = chartProto.updateLayout = chartProto.updateVisual = function (seriesModel, ecModel, api, payload) {
  20358. this.render(seriesModel, ecModel, api, payload);
  20359. };
  20360. /**
  20361. * Set state of single element
  20362. * @param {module:zrender/Element} el
  20363. * @param {string} state 'normal'|'emphasis'
  20364. * @param {number} highlightDigit
  20365. */
  20366. function elSetState(el, state, highlightDigit) {
  20367. if (el) {
  20368. el.trigger(state, highlightDigit);
  20369. if (el.isGroup // Simple optimize.
  20370. && !isHighDownDispatcher(el)) {
  20371. for (var i = 0, len = el.childCount(); i < len; i++) {
  20372. elSetState(el.childAt(i), state, highlightDigit);
  20373. }
  20374. }
  20375. }
  20376. }
  20377. /**
  20378. * @param {module:echarts/data/List} data
  20379. * @param {Object} payload
  20380. * @param {string} state 'normal'|'emphasis'
  20381. */
  20382. function toggleHighlight(data, payload, state) {
  20383. var dataIndex = queryDataIndex(data, payload);
  20384. var highlightDigit = payload && payload.highlightKey != null ? getHighlightDigit(payload.highlightKey) : null;
  20385. if (dataIndex != null) {
  20386. each$1(normalizeToArray(dataIndex), function (dataIdx) {
  20387. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  20388. });
  20389. } else {
  20390. data.eachItemGraphicEl(function (el) {
  20391. elSetState(el, state, highlightDigit);
  20392. });
  20393. }
  20394. } // Enable Chart.extend.
  20395. enableClassExtend(Chart, ['dispose']); // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  20396. enableClassManagement(Chart, {
  20397. registerWhenExtend: true
  20398. });
  20399. Chart.markUpdateMethod = function (payload, methodName) {
  20400. inner$5(payload).updateMethod = methodName;
  20401. };
  20402. function renderTaskPlan(context) {
  20403. return renderPlanner(context.model);
  20404. }
  20405. function renderTaskReset(context) {
  20406. var seriesModel = context.model;
  20407. var ecModel = context.ecModel;
  20408. var api = context.api;
  20409. var payload = context.payload; // ???! remove updateView updateVisual
  20410. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  20411. var view = context.view;
  20412. var updateMethod = payload && inner$5(payload).updateMethod;
  20413. var methodName = progressiveRender ? 'incrementalPrepareRender' : updateMethod && view[updateMethod] ? updateMethod // `appendData` is also supported when data amount
  20414. // is less than progressive threshold.
  20415. : 'render';
  20416. if (methodName !== 'render') {
  20417. view[methodName](seriesModel, ecModel, api, payload);
  20418. }
  20419. return progressMethodMap[methodName];
  20420. }
  20421. var progressMethodMap = {
  20422. incrementalPrepareRender: {
  20423. progress: function (params, context) {
  20424. context.view.incrementalRender(params, context.model, context.ecModel, context.api, context.payload);
  20425. }
  20426. },
  20427. render: {
  20428. // Put view.render in `progress` to support appendData. But in this case
  20429. // view.render should not be called in reset, otherwise it will be called
  20430. // twise. Use `forceFirstProgress` to make sure that view.render is called
  20431. // in any cases.
  20432. forceFirstProgress: true,
  20433. progress: function (params, context) {
  20434. context.view.render(context.model, context.ecModel, context.api, context.payload);
  20435. }
  20436. }
  20437. };
  20438. /*
  20439. * Licensed to the Apache Software Foundation (ASF) under one
  20440. * or more contributor license agreements. See the NOTICE file
  20441. * distributed with this work for additional information
  20442. * regarding copyright ownership. The ASF licenses this file
  20443. * to you under the Apache License, Version 2.0 (the
  20444. * "License"); you may not use this file except in compliance
  20445. * with the License. You may obtain a copy of the License at
  20446. *
  20447. * http://www.apache.org/licenses/LICENSE-2.0
  20448. *
  20449. * Unless required by applicable law or agreed to in writing,
  20450. * software distributed under the License is distributed on an
  20451. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20452. * KIND, either express or implied. See the License for the
  20453. * specific language governing permissions and limitations
  20454. * under the License.
  20455. */
  20456. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  20457. var RATE = '\0__throttleRate';
  20458. var THROTTLE_TYPE = '\0__throttleType';
  20459. /**
  20460. * @public
  20461. * @param {(Function)} fn
  20462. * @param {number} [delay=0] Unit: ms.
  20463. * @param {boolean} [debounce=false]
  20464. * true: If call interval less than `delay`, only the last call works.
  20465. * false: If call interval less than `delay, call works on fixed rate.
  20466. * @return {(Function)} throttled fn.
  20467. */
  20468. function throttle(fn, delay, debounce) {
  20469. var currCall;
  20470. var lastCall = 0;
  20471. var lastExec = 0;
  20472. var timer = null;
  20473. var diff;
  20474. var scope;
  20475. var args;
  20476. var debounceNextCall;
  20477. delay = delay || 0;
  20478. function exec() {
  20479. lastExec = new Date().getTime();
  20480. timer = null;
  20481. fn.apply(scope, args || []);
  20482. }
  20483. var cb = function () {
  20484. currCall = new Date().getTime();
  20485. scope = this;
  20486. args = arguments;
  20487. var thisDelay = debounceNextCall || delay;
  20488. var thisDebounce = debounceNextCall || debounce;
  20489. debounceNextCall = null;
  20490. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  20491. clearTimeout(timer); // Here we should make sure that: the `exec` SHOULD NOT be called later
  20492. // than a new call of `cb`, that is, preserving the command order. Consider
  20493. // calculating "scale rate" when roaming as an example. When a call of `cb`
  20494. // happens, either the `exec` is called dierectly, or the call is delayed.
  20495. // But the delayed call should never be later than next call of `cb`. Under
  20496. // this assurance, we can simply update view state each time `dispatchAction`
  20497. // triggered by user roaming, but not need to add extra code to avoid the
  20498. // state being "rolled-back".
  20499. if (thisDebounce) {
  20500. timer = setTimeout(exec, thisDelay);
  20501. } else {
  20502. if (diff >= 0) {
  20503. exec();
  20504. } else {
  20505. timer = setTimeout(exec, -diff);
  20506. }
  20507. }
  20508. lastCall = currCall;
  20509. };
  20510. /**
  20511. * Clear throttle.
  20512. * @public
  20513. */
  20514. cb.clear = function () {
  20515. if (timer) {
  20516. clearTimeout(timer);
  20517. timer = null;
  20518. }
  20519. };
  20520. /**
  20521. * Enable debounce once.
  20522. */
  20523. cb.debounceNextCall = function (debounceDelay) {
  20524. debounceNextCall = debounceDelay;
  20525. };
  20526. return cb;
  20527. }
  20528. /**
  20529. * Create throttle method or update throttle rate.
  20530. *
  20531. * @example
  20532. * ComponentView.prototype.render = function () {
  20533. * ...
  20534. * throttle.createOrUpdate(
  20535. * this,
  20536. * '_dispatchAction',
  20537. * this.model.get('throttle'),
  20538. * 'fixRate'
  20539. * );
  20540. * };
  20541. * ComponentView.prototype.remove = function () {
  20542. * throttle.clear(this, '_dispatchAction');
  20543. * };
  20544. * ComponentView.prototype.dispose = function () {
  20545. * throttle.clear(this, '_dispatchAction');
  20546. * };
  20547. *
  20548. * @public
  20549. * @param {Object} obj
  20550. * @param {string} fnAttr
  20551. * @param {number} [rate]
  20552. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  20553. * @return {Function} throttled function.
  20554. */
  20555. function createOrUpdate(obj, fnAttr, rate, throttleType) {
  20556. var fn = obj[fnAttr];
  20557. if (!fn) {
  20558. return;
  20559. }
  20560. var originFn = fn[ORIGIN_METHOD] || fn;
  20561. var lastThrottleType = fn[THROTTLE_TYPE];
  20562. var lastRate = fn[RATE];
  20563. if (lastRate !== rate || lastThrottleType !== throttleType) {
  20564. if (rate == null || !throttleType) {
  20565. return obj[fnAttr] = originFn;
  20566. }
  20567. fn = obj[fnAttr] = throttle(originFn, rate, throttleType === 'debounce');
  20568. fn[ORIGIN_METHOD] = originFn;
  20569. fn[THROTTLE_TYPE] = throttleType;
  20570. fn[RATE] = rate;
  20571. }
  20572. return fn;
  20573. }
  20574. /**
  20575. * Clear throttle. Example see throttle.createOrUpdate.
  20576. *
  20577. * @public
  20578. * @param {Object} obj
  20579. * @param {string} fnAttr
  20580. */
  20581. function clear(obj, fnAttr) {
  20582. var fn = obj[fnAttr];
  20583. if (fn && fn[ORIGIN_METHOD]) {
  20584. obj[fnAttr] = fn[ORIGIN_METHOD];
  20585. }
  20586. }
  20587. /*
  20588. * Licensed to the Apache Software Foundation (ASF) under one
  20589. * or more contributor license agreements. See the NOTICE file
  20590. * distributed with this work for additional information
  20591. * regarding copyright ownership. The ASF licenses this file
  20592. * to you under the Apache License, Version 2.0 (the
  20593. * "License"); you may not use this file except in compliance
  20594. * with the License. You may obtain a copy of the License at
  20595. *
  20596. * http://www.apache.org/licenses/LICENSE-2.0
  20597. *
  20598. * Unless required by applicable law or agreed to in writing,
  20599. * software distributed under the License is distributed on an
  20600. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20601. * KIND, either express or implied. See the License for the
  20602. * specific language governing permissions and limitations
  20603. * under the License.
  20604. */
  20605. var seriesColor = {
  20606. createOnAllSeries: true,
  20607. performRawSeries: true,
  20608. reset: function (seriesModel, ecModel) {
  20609. var data = seriesModel.getData();
  20610. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.color').split('.'); // Set in itemStyle
  20611. var color = seriesModel.get(colorAccessPath);
  20612. var colorCallback = isFunction$1(color) && !(color instanceof Gradient) ? color : null; // Default color
  20613. if (!color || colorCallback) {
  20614. color = seriesModel.getColorFromPalette( // TODO series count changed.
  20615. seriesModel.name, null, ecModel.getSeriesCount());
  20616. }
  20617. data.setVisual('color', color);
  20618. var borderColorAccessPath = (seriesModel.visualBorderColorAccessPath || 'itemStyle.borderColor').split('.');
  20619. var borderColor = seriesModel.get(borderColorAccessPath);
  20620. data.setVisual('borderColor', borderColor); // Only visible series has each data be visual encoded
  20621. if (!ecModel.isSeriesFiltered(seriesModel)) {
  20622. if (colorCallback) {
  20623. data.each(function (idx) {
  20624. data.setItemVisual(idx, 'color', colorCallback(seriesModel.getDataParams(idx)));
  20625. });
  20626. } // itemStyle in each data item
  20627. var dataEach = function (data, idx) {
  20628. var itemModel = data.getItemModel(idx);
  20629. var color = itemModel.get(colorAccessPath, true);
  20630. var borderColor = itemModel.get(borderColorAccessPath, true);
  20631. if (color != null) {
  20632. data.setItemVisual(idx, 'color', color);
  20633. }
  20634. if (borderColor != null) {
  20635. data.setItemVisual(idx, 'borderColor', borderColor);
  20636. }
  20637. };
  20638. return {
  20639. dataEach: data.hasItemOption ? dataEach : null
  20640. };
  20641. }
  20642. }
  20643. };
  20644. /*
  20645. * Licensed to the Apache Software Foundation (ASF) under one
  20646. * or more contributor license agreements. See the NOTICE file
  20647. * distributed with this work for additional information
  20648. * regarding copyright ownership. The ASF licenses this file
  20649. * to you under the Apache License, Version 2.0 (the
  20650. * "License"); you may not use this file except in compliance
  20651. * with the License. You may obtain a copy of the License at
  20652. *
  20653. * http://www.apache.org/licenses/LICENSE-2.0
  20654. *
  20655. * Unless required by applicable law or agreed to in writing,
  20656. * software distributed under the License is distributed on an
  20657. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20658. * KIND, either express or implied. See the License for the
  20659. * specific language governing permissions and limitations
  20660. * under the License.
  20661. */
  20662. /**
  20663. * Language: (Simplified) Chinese.
  20664. */
  20665. var lang = {
  20666. legend: {
  20667. selector: {
  20668. all: '全选',
  20669. inverse: '反选'
  20670. }
  20671. },
  20672. toolbox: {
  20673. brush: {
  20674. title: {
  20675. rect: '矩形选择',
  20676. polygon: '圈选',
  20677. lineX: '横向选择',
  20678. lineY: '纵向选择',
  20679. keep: '保持选择',
  20680. clear: '清除选择'
  20681. }
  20682. },
  20683. dataView: {
  20684. title: '数据视图',
  20685. lang: ['数据视图', '关闭', '刷新']
  20686. },
  20687. dataZoom: {
  20688. title: {
  20689. zoom: '区域缩放',
  20690. back: '区域缩放还原'
  20691. }
  20692. },
  20693. magicType: {
  20694. title: {
  20695. line: '切换为折线图',
  20696. bar: '切换为柱状图',
  20697. stack: '切换为堆叠',
  20698. tiled: '切换为平铺'
  20699. }
  20700. },
  20701. restore: {
  20702. title: '还原'
  20703. },
  20704. saveAsImage: {
  20705. title: '保存为图片',
  20706. lang: ['右键另存为图片']
  20707. }
  20708. },
  20709. series: {
  20710. typeNames: {
  20711. pie: '饼图',
  20712. bar: '柱状图',
  20713. line: '折线图',
  20714. scatter: '散点图',
  20715. effectScatter: '涟漪散点图',
  20716. radar: '雷达图',
  20717. tree: '树图',
  20718. treemap: '矩形树图',
  20719. boxplot: '箱型图',
  20720. candlestick: 'K线图',
  20721. k: 'K线图',
  20722. heatmap: '热力图',
  20723. map: '地图',
  20724. parallel: '平行坐标图',
  20725. lines: '线图',
  20726. graph: '关系图',
  20727. sankey: '桑基图',
  20728. funnel: '漏斗图',
  20729. gauge: '仪表盘图',
  20730. pictorialBar: '象形柱图',
  20731. themeRiver: '主题河流图',
  20732. sunburst: '旭日图'
  20733. }
  20734. },
  20735. aria: {
  20736. general: {
  20737. withTitle: '这是一个关于“{title}”的图表。',
  20738. withoutTitle: '这是一个图表,'
  20739. },
  20740. series: {
  20741. single: {
  20742. prefix: '',
  20743. withName: '图表类型是{seriesType},表示{seriesName}。',
  20744. withoutName: '图表类型是{seriesType}。'
  20745. },
  20746. multiple: {
  20747. prefix: '它由{seriesCount}个图表系列组成。',
  20748. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  20749. withoutName: '第{seriesId}个系列是一个{seriesType},',
  20750. separator: {
  20751. middle: ';',
  20752. end: '。'
  20753. }
  20754. }
  20755. },
  20756. data: {
  20757. allData: '其数据是——',
  20758. partialData: '其中,前{displayCnt}项是——',
  20759. withName: '{name}的数据是{value}',
  20760. withoutName: '{value}',
  20761. separator: {
  20762. middle: ',',
  20763. end: ''
  20764. }
  20765. }
  20766. }
  20767. };
  20768. /*
  20769. * Licensed to the Apache Software Foundation (ASF) under one
  20770. * or more contributor license agreements. See the NOTICE file
  20771. * distributed with this work for additional information
  20772. * regarding copyright ownership. The ASF licenses this file
  20773. * to you under the Apache License, Version 2.0 (the
  20774. * "License"); you may not use this file except in compliance
  20775. * with the License. You may obtain a copy of the License at
  20776. *
  20777. * http://www.apache.org/licenses/LICENSE-2.0
  20778. *
  20779. * Unless required by applicable law or agreed to in writing,
  20780. * software distributed under the License is distributed on an
  20781. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20782. * KIND, either express or implied. See the License for the
  20783. * specific language governing permissions and limitations
  20784. * under the License.
  20785. */
  20786. var aria = function (dom, ecModel) {
  20787. var ariaModel = ecModel.getModel('aria');
  20788. if (!ariaModel.get('show')) {
  20789. return;
  20790. } else if (ariaModel.get('description')) {
  20791. dom.setAttribute('aria-label', ariaModel.get('description'));
  20792. return;
  20793. }
  20794. var seriesCnt = 0;
  20795. ecModel.eachSeries(function (seriesModel, idx) {
  20796. ++seriesCnt;
  20797. }, this);
  20798. var maxDataCnt = ariaModel.get('data.maxCount') || 10;
  20799. var maxSeriesCnt = ariaModel.get('series.maxCount') || 10;
  20800. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  20801. var ariaLabel;
  20802. if (seriesCnt < 1) {
  20803. // No series, no aria label
  20804. return;
  20805. } else {
  20806. var title = getTitle();
  20807. if (title) {
  20808. ariaLabel = replace(getConfig('general.withTitle'), {
  20809. title: title
  20810. });
  20811. } else {
  20812. ariaLabel = getConfig('general.withoutTitle');
  20813. }
  20814. var seriesLabels = [];
  20815. var prefix = seriesCnt > 1 ? 'series.multiple.prefix' : 'series.single.prefix';
  20816. ariaLabel += replace(getConfig(prefix), {
  20817. seriesCount: seriesCnt
  20818. });
  20819. ecModel.eachSeries(function (seriesModel, idx) {
  20820. if (idx < displaySeriesCnt) {
  20821. var seriesLabel;
  20822. var seriesName = seriesModel.get('name');
  20823. var seriesTpl = 'series.' + (seriesCnt > 1 ? 'multiple' : 'single') + '.';
  20824. seriesLabel = getConfig(seriesName ? seriesTpl + 'withName' : seriesTpl + 'withoutName');
  20825. seriesLabel = replace(seriesLabel, {
  20826. seriesId: seriesModel.seriesIndex,
  20827. seriesName: seriesModel.get('name'),
  20828. seriesType: getSeriesTypeName(seriesModel.subType)
  20829. });
  20830. var data = seriesModel.getData();
  20831. window.data = data;
  20832. if (data.count() > maxDataCnt) {
  20833. // Show part of data
  20834. seriesLabel += replace(getConfig('data.partialData'), {
  20835. displayCnt: maxDataCnt
  20836. });
  20837. } else {
  20838. seriesLabel += getConfig('data.allData');
  20839. }
  20840. var dataLabels = [];
  20841. for (var i = 0; i < data.count(); i++) {
  20842. if (i < maxDataCnt) {
  20843. var name = data.getName(i);
  20844. var value = retrieveRawValue(data, i);
  20845. dataLabels.push(replace(name ? getConfig('data.withName') : getConfig('data.withoutName'), {
  20846. name: name,
  20847. value: value
  20848. }));
  20849. }
  20850. }
  20851. seriesLabel += dataLabels.join(getConfig('data.separator.middle')) + getConfig('data.separator.end');
  20852. seriesLabels.push(seriesLabel);
  20853. }
  20854. });
  20855. ariaLabel += seriesLabels.join(getConfig('series.multiple.separator.middle')) + getConfig('series.multiple.separator.end');
  20856. dom.setAttribute('aria-label', ariaLabel);
  20857. }
  20858. function replace(str, keyValues) {
  20859. if (typeof str !== 'string') {
  20860. return str;
  20861. }
  20862. var result = str;
  20863. each$1(keyValues, function (value, key) {
  20864. result = result.replace(new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'), value);
  20865. });
  20866. return result;
  20867. }
  20868. function getConfig(path) {
  20869. var userConfig = ariaModel.get(path);
  20870. if (userConfig == null) {
  20871. var pathArr = path.split('.');
  20872. var result = lang.aria;
  20873. for (var i = 0; i < pathArr.length; ++i) {
  20874. result = result[pathArr[i]];
  20875. }
  20876. return result;
  20877. } else {
  20878. return userConfig;
  20879. }
  20880. }
  20881. function getTitle() {
  20882. var title = ecModel.getModel('title').option;
  20883. if (title && title.length) {
  20884. title = title[0];
  20885. }
  20886. return title && title.text;
  20887. }
  20888. function getSeriesTypeName(type) {
  20889. return lang.series.typeNames[type] || '自定义图';
  20890. }
  20891. };
  20892. /*
  20893. * Licensed to the Apache Software Foundation (ASF) under one
  20894. * or more contributor license agreements. See the NOTICE file
  20895. * distributed with this work for additional information
  20896. * regarding copyright ownership. The ASF licenses this file
  20897. * to you under the Apache License, Version 2.0 (the
  20898. * "License"); you may not use this file except in compliance
  20899. * with the License. You may obtain a copy of the License at
  20900. *
  20901. * http://www.apache.org/licenses/LICENSE-2.0
  20902. *
  20903. * Unless required by applicable law or agreed to in writing,
  20904. * software distributed under the License is distributed on an
  20905. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20906. * KIND, either express or implied. See the License for the
  20907. * specific language governing permissions and limitations
  20908. * under the License.
  20909. */
  20910. var PI$1 = Math.PI;
  20911. /**
  20912. * @param {module:echarts/ExtensionAPI} api
  20913. * @param {Object} [opts]
  20914. * @param {string} [opts.text]
  20915. * @param {string} [opts.color]
  20916. * @param {string} [opts.textColor]
  20917. * @return {module:zrender/Element}
  20918. */
  20919. var loadingDefault = function (api, opts) {
  20920. opts = opts || {};
  20921. defaults(opts, {
  20922. text: 'loading',
  20923. textColor: '#000',
  20924. fontSize: '12px',
  20925. maskColor: 'rgba(255, 255, 255, 0.8)',
  20926. showSpinner: true,
  20927. color: '#c23531',
  20928. spinnerRadius: 10,
  20929. lineWidth: 5,
  20930. zlevel: 0
  20931. });
  20932. var group = new Group();
  20933. var mask = new Rect({
  20934. style: {
  20935. fill: opts.maskColor
  20936. },
  20937. zlevel: opts.zlevel,
  20938. z: 10000
  20939. });
  20940. group.add(mask);
  20941. var font = opts.fontSize + ' sans-serif';
  20942. var labelRect = new Rect({
  20943. style: {
  20944. fill: 'none',
  20945. text: opts.text,
  20946. font: font,
  20947. textPosition: 'right',
  20948. textDistance: 10,
  20949. textFill: opts.textColor
  20950. },
  20951. zlevel: opts.zlevel,
  20952. z: 10001
  20953. });
  20954. group.add(labelRect);
  20955. if (opts.showSpinner) {
  20956. var arc = new Arc({
  20957. shape: {
  20958. startAngle: -PI$1 / 2,
  20959. endAngle: -PI$1 / 2 + 0.1,
  20960. r: opts.spinnerRadius
  20961. },
  20962. style: {
  20963. stroke: opts.color,
  20964. lineCap: 'round',
  20965. lineWidth: opts.lineWidth
  20966. },
  20967. zlevel: opts.zlevel,
  20968. z: 10001
  20969. });
  20970. arc.animateShape(true).when(1000, {
  20971. endAngle: PI$1 * 3 / 2
  20972. }).start('circularInOut');
  20973. arc.animateShape(true).when(1000, {
  20974. startAngle: PI$1 * 3 / 2
  20975. }).delay(300).start('circularInOut');
  20976. group.add(arc);
  20977. } // Inject resize
  20978. group.resize = function () {
  20979. var textWidth = getWidth(opts.text, font);
  20980. var r = opts.showSpinner ? opts.spinnerRadius : 0; // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  20981. // textDistance needs to be calculated when both animation and text exist
  20982. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2 // only show the text
  20983. - (opts.showSpinner ? 0 : textWidth / 2);
  20984. var cy = api.getHeight() / 2;
  20985. opts.showSpinner && arc.setShape({
  20986. cx: cx,
  20987. cy: cy
  20988. });
  20989. labelRect.setShape({
  20990. x: cx - r,
  20991. y: cy - r,
  20992. width: r * 2,
  20993. height: r * 2
  20994. });
  20995. mask.setShape({
  20996. x: 0,
  20997. y: 0,
  20998. width: api.getWidth(),
  20999. height: api.getHeight()
  21000. });
  21001. };
  21002. group.resize();
  21003. return group;
  21004. };
  21005. /*
  21006. * Licensed to the Apache Software Foundation (ASF) under one
  21007. * or more contributor license agreements. See the NOTICE file
  21008. * distributed with this work for additional information
  21009. * regarding copyright ownership. The ASF licenses this file
  21010. * to you under the Apache License, Version 2.0 (the
  21011. * "License"); you may not use this file except in compliance
  21012. * with the License. You may obtain a copy of the License at
  21013. *
  21014. * http://www.apache.org/licenses/LICENSE-2.0
  21015. *
  21016. * Unless required by applicable law or agreed to in writing,
  21017. * software distributed under the License is distributed on an
  21018. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21019. * KIND, either express or implied. See the License for the
  21020. * specific language governing permissions and limitations
  21021. * under the License.
  21022. */
  21023. /**
  21024. * @module echarts/stream/Scheduler
  21025. */
  21026. /**
  21027. * @constructor
  21028. */
  21029. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  21030. this.ecInstance = ecInstance;
  21031. this.api = api;
  21032. this.unfinished; // Fix current processors in case that in some rear cases that
  21033. // processors might be registered after echarts instance created.
  21034. // Register processors incrementally for a echarts instance is
  21035. // not supported by this stream architecture.
  21036. var dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  21037. var visualHandlers = this._visualHandlers = visualHandlers.slice();
  21038. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  21039. /**
  21040. * @private
  21041. * @type {
  21042. * [handlerUID: string]: {
  21043. * seriesTaskMap?: {
  21044. * [seriesUID: string]: Task
  21045. * },
  21046. * overallTask?: Task
  21047. * }
  21048. * }
  21049. */
  21050. this._stageTaskMap = createHashMap();
  21051. }
  21052. var proto = Scheduler.prototype;
  21053. /**
  21054. * @param {module:echarts/model/Global} ecModel
  21055. * @param {Object} payload
  21056. */
  21057. proto.restoreData = function (ecModel, payload) {
  21058. // TODO: Only restroe needed series and components, but not all components.
  21059. // Currently `restoreData` of all of the series and component will be called.
  21060. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  21061. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  21062. // and some components like coordinate system, axes, dataZoom, visualMap only
  21063. // need their target series refresh.
  21064. // (1) If we are implementing this feature some day, we should consider these cases:
  21065. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  21066. // on the settings of `dataZoom`), it should be re-performed if the component
  21067. // is modified by `setOption`.
  21068. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  21069. // it should be re-performed when the result array of `getTargetSeries` changed.
  21070. // We use `dependencies` to cover these issues.
  21071. // (3) How to update target series when coordinate system related components modified.
  21072. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  21073. // and this case all of the tasks will be set as dirty.
  21074. ecModel.restoreData(payload); // Theoretically an overall task not only depends on each of its target series, but also
  21075. // depends on all of the series.
  21076. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  21077. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  21078. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  21079. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  21080. // probably cause state chaos (consider `dataZoomProcessor`).
  21081. this._stageTaskMap.each(function (taskRecord) {
  21082. var overallTask = taskRecord.overallTask;
  21083. overallTask && overallTask.dirty();
  21084. });
  21085. }; // If seriesModel provided, incremental threshold is check by series data.
  21086. proto.getPerformArgs = function (task, isBlock) {
  21087. // For overall task
  21088. if (!task.__pipeline) {
  21089. return;
  21090. }
  21091. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  21092. var pCtx = pipeline.context;
  21093. var incremental = !isBlock && pipeline.progressiveEnabled && (!pCtx || pCtx.progressiveRender) && task.__idxInPipeline > pipeline.blockIndex;
  21094. var step = incremental ? pipeline.step : null;
  21095. var modDataCount = pCtx && pCtx.modDataCount;
  21096. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  21097. return {
  21098. step: step,
  21099. modBy: modBy,
  21100. modDataCount: modDataCount
  21101. };
  21102. };
  21103. proto.getPipeline = function (pipelineId) {
  21104. return this._pipelineMap.get(pipelineId);
  21105. };
  21106. /**
  21107. * Current, progressive rendering starts from visual and layout.
  21108. * Always detect render mode in the same stage, avoiding that incorrect
  21109. * detection caused by data filtering.
  21110. * Caution:
  21111. * `updateStreamModes` use `seriesModel.getData()`.
  21112. */
  21113. proto.updateStreamModes = function (seriesModel, view) {
  21114. var pipeline = this._pipelineMap.get(seriesModel.uid);
  21115. var data = seriesModel.getData();
  21116. var dataLen = data.count(); // `progressiveRender` means that can render progressively in each
  21117. // animation frame. Note that some types of series do not provide
  21118. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  21119. // use the term `incremental` but not `progressive` to describe the
  21120. // case that `chart.appendData`.
  21121. var progressiveRender = pipeline.progressiveEnabled && view.incrementalPrepareRender && dataLen >= pipeline.threshold;
  21122. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold'); // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  21123. // see `test/candlestick-large3.html`
  21124. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  21125. seriesModel.pipelineContext = pipeline.context = {
  21126. progressiveRender: progressiveRender,
  21127. modDataCount: modDataCount,
  21128. large: large
  21129. };
  21130. };
  21131. proto.restorePipelines = function (ecModel) {
  21132. var scheduler = this;
  21133. var pipelineMap = scheduler._pipelineMap = createHashMap();
  21134. ecModel.eachSeries(function (seriesModel) {
  21135. var progressive = seriesModel.getProgressive();
  21136. var pipelineId = seriesModel.uid;
  21137. pipelineMap.set(pipelineId, {
  21138. id: pipelineId,
  21139. head: null,
  21140. tail: null,
  21141. threshold: seriesModel.getProgressiveThreshold(),
  21142. progressiveEnabled: progressive && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  21143. blockIndex: -1,
  21144. step: Math.round(progressive || 700),
  21145. count: 0
  21146. });
  21147. pipe(scheduler, seriesModel, seriesModel.dataTask);
  21148. });
  21149. };
  21150. proto.prepareStageTasks = function () {
  21151. var stageTaskMap = this._stageTaskMap;
  21152. var ecModel = this.ecInstance.getModel();
  21153. var api = this.api;
  21154. each$1(this._allHandlers, function (handler) {
  21155. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, []);
  21156. handler.reset && createSeriesStageTask(this, handler, record, ecModel, api);
  21157. handler.overallReset && createOverallStageTask(this, handler, record, ecModel, api);
  21158. }, this);
  21159. };
  21160. proto.prepareView = function (view, model, ecModel, api) {
  21161. var renderTask = view.renderTask;
  21162. var context = renderTask.context;
  21163. context.model = model;
  21164. context.ecModel = ecModel;
  21165. context.api = api;
  21166. renderTask.__block = !view.incrementalPrepareRender;
  21167. pipe(this, model, renderTask);
  21168. };
  21169. proto.performDataProcessorTasks = function (ecModel, payload) {
  21170. // If we do not use `block` here, it should be considered when to update modes.
  21171. performStageTasks(this, this._dataProcessorHandlers, ecModel, payload, {
  21172. block: true
  21173. });
  21174. }; // opt
  21175. // opt.visualType: 'visual' or 'layout'
  21176. // opt.setDirty
  21177. proto.performVisualTasks = function (ecModel, payload, opt) {
  21178. performStageTasks(this, this._visualHandlers, ecModel, payload, opt);
  21179. };
  21180. function performStageTasks(scheduler, stageHandlers, ecModel, payload, opt) {
  21181. opt = opt || {};
  21182. var unfinished;
  21183. each$1(stageHandlers, function (stageHandler, idx) {
  21184. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  21185. return;
  21186. }
  21187. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  21188. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  21189. var overallTask = stageHandlerRecord.overallTask;
  21190. if (overallTask) {
  21191. var overallNeedDirty;
  21192. var agentStubMap = overallTask.agentStubMap;
  21193. agentStubMap.each(function (stub) {
  21194. if (needSetDirty(opt, stub)) {
  21195. stub.dirty();
  21196. overallNeedDirty = true;
  21197. }
  21198. });
  21199. overallNeedDirty && overallTask.dirty();
  21200. updatePayload(overallTask, payload);
  21201. var performArgs = scheduler.getPerformArgs(overallTask, opt.block); // Execute stubs firstly, which may set the overall task dirty,
  21202. // then execute the overall task. And stub will call seriesModel.setData,
  21203. // which ensures that in the overallTask seriesModel.getData() will not
  21204. // return incorrect data.
  21205. agentStubMap.each(function (stub) {
  21206. stub.perform(performArgs);
  21207. });
  21208. unfinished |= overallTask.perform(performArgs);
  21209. } else if (seriesTaskMap) {
  21210. seriesTaskMap.each(function (task, pipelineId) {
  21211. if (needSetDirty(opt, task)) {
  21212. task.dirty();
  21213. }
  21214. var performArgs = scheduler.getPerformArgs(task, opt.block); // FIXME
  21215. // if intending to decalare `performRawSeries` in handlers, only
  21216. // stream-independent (specifically, data item independent) operations can be
  21217. // performed. Because is a series is filtered, most of the tasks will not
  21218. // be performed. A stream-dependent operation probably cause wrong biz logic.
  21219. // Perhaps we should not provide a separate callback for this case instead
  21220. // of providing the config `performRawSeries`. The stream-dependent operaions
  21221. // and stream-independent operations should better not be mixed.
  21222. performArgs.skip = !stageHandler.performRawSeries && ecModel.isSeriesFiltered(task.context.model);
  21223. updatePayload(task, payload);
  21224. unfinished |= task.perform(performArgs);
  21225. });
  21226. }
  21227. });
  21228. function needSetDirty(opt, task) {
  21229. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  21230. }
  21231. scheduler.unfinished |= unfinished;
  21232. }
  21233. proto.performSeriesTasks = function (ecModel) {
  21234. var unfinished;
  21235. ecModel.eachSeries(function (seriesModel) {
  21236. // Progress to the end for dataInit and dataRestore.
  21237. unfinished |= seriesModel.dataTask.perform();
  21238. });
  21239. this.unfinished |= unfinished;
  21240. };
  21241. proto.plan = function () {
  21242. // Travel pipelines, check block.
  21243. this._pipelineMap.each(function (pipeline) {
  21244. var task = pipeline.tail;
  21245. do {
  21246. if (task.__block) {
  21247. pipeline.blockIndex = task.__idxInPipeline;
  21248. break;
  21249. }
  21250. task = task.getUpstream();
  21251. } while (task);
  21252. });
  21253. };
  21254. var updatePayload = proto.updatePayload = function (task, payload) {
  21255. payload !== 'remain' && (task.context.payload = payload);
  21256. };
  21257. function createSeriesStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  21258. var seriesTaskMap = stageHandlerRecord.seriesTaskMap || (stageHandlerRecord.seriesTaskMap = createHashMap());
  21259. var seriesType = stageHandler.seriesType;
  21260. var getTargetSeries = stageHandler.getTargetSeries; // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  21261. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  21262. // it works but it may cause other irrelevant charts blocked.
  21263. if (stageHandler.createOnAllSeries) {
  21264. ecModel.eachRawSeries(create);
  21265. } else if (seriesType) {
  21266. ecModel.eachRawSeriesByType(seriesType, create);
  21267. } else if (getTargetSeries) {
  21268. getTargetSeries(ecModel, api).each(create);
  21269. }
  21270. function create(seriesModel) {
  21271. var pipelineId = seriesModel.uid; // Init tasks for each seriesModel only once.
  21272. // Reuse original task instance.
  21273. var task = seriesTaskMap.get(pipelineId) || seriesTaskMap.set(pipelineId, createTask({
  21274. plan: seriesTaskPlan,
  21275. reset: seriesTaskReset,
  21276. count: seriesTaskCount
  21277. }));
  21278. task.context = {
  21279. model: seriesModel,
  21280. ecModel: ecModel,
  21281. api: api,
  21282. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  21283. plan: stageHandler.plan,
  21284. reset: stageHandler.reset,
  21285. scheduler: scheduler
  21286. };
  21287. pipe(scheduler, seriesModel, task);
  21288. } // Clear unused series tasks.
  21289. var pipelineMap = scheduler._pipelineMap;
  21290. seriesTaskMap.each(function (task, pipelineId) {
  21291. if (!pipelineMap.get(pipelineId)) {
  21292. task.dispose();
  21293. seriesTaskMap.removeKey(pipelineId);
  21294. }
  21295. });
  21296. }
  21297. function createOverallStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  21298. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask // For overall task, the function only be called on reset stage.
  21299. || createTask({
  21300. reset: overallTaskReset
  21301. });
  21302. overallTask.context = {
  21303. ecModel: ecModel,
  21304. api: api,
  21305. overallReset: stageHandler.overallReset,
  21306. scheduler: scheduler
  21307. }; // Reuse orignal stubs.
  21308. var agentStubMap = overallTask.agentStubMap = overallTask.agentStubMap || createHashMap();
  21309. var seriesType = stageHandler.seriesType;
  21310. var getTargetSeries = stageHandler.getTargetSeries;
  21311. var overallProgress = true;
  21312. var modifyOutputEnd = stageHandler.modifyOutputEnd; // An overall task with seriesType detected or has `getTargetSeries`, we add
  21313. // stub in each pipelines, it will set the overall task dirty when the pipeline
  21314. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  21315. // we set the pipeline block.
  21316. if (seriesType) {
  21317. ecModel.eachRawSeriesByType(seriesType, createStub);
  21318. } else if (getTargetSeries) {
  21319. getTargetSeries(ecModel, api).each(createStub);
  21320. } // Otherwise, (usually it is legancy case), the overall task will only be
  21321. // executed when upstream dirty. Otherwise the progressive rendering of all
  21322. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  21323. // dirty info from upsteam.
  21324. else {
  21325. overallProgress = false;
  21326. each$1(ecModel.getSeries(), createStub);
  21327. }
  21328. function createStub(seriesModel) {
  21329. var pipelineId = seriesModel.uid;
  21330. var stub = agentStubMap.get(pipelineId);
  21331. if (!stub) {
  21332. stub = agentStubMap.set(pipelineId, createTask({
  21333. reset: stubReset,
  21334. onDirty: stubOnDirty
  21335. })); // When the result of `getTargetSeries` changed, the overallTask
  21336. // should be set as dirty and re-performed.
  21337. overallTask.dirty();
  21338. }
  21339. stub.context = {
  21340. model: seriesModel,
  21341. overallProgress: overallProgress,
  21342. modifyOutputEnd: modifyOutputEnd
  21343. };
  21344. stub.agent = overallTask;
  21345. stub.__block = overallProgress;
  21346. pipe(scheduler, seriesModel, stub);
  21347. } // Clear unused stubs.
  21348. var pipelineMap = scheduler._pipelineMap;
  21349. agentStubMap.each(function (stub, pipelineId) {
  21350. if (!pipelineMap.get(pipelineId)) {
  21351. stub.dispose(); // When the result of `getTargetSeries` changed, the overallTask
  21352. // should be set as dirty and re-performed.
  21353. overallTask.dirty();
  21354. agentStubMap.removeKey(pipelineId);
  21355. }
  21356. });
  21357. }
  21358. function overallTaskReset(context) {
  21359. context.overallReset(context.ecModel, context.api, context.payload);
  21360. }
  21361. function stubReset(context, upstreamContext) {
  21362. return context.overallProgress && stubProgress;
  21363. }
  21364. function stubProgress() {
  21365. this.agent.dirty();
  21366. this.getDownstream().dirty();
  21367. }
  21368. function stubOnDirty() {
  21369. this.agent && this.agent.dirty();
  21370. }
  21371. function seriesTaskPlan(context) {
  21372. return context.plan && context.plan(context.model, context.ecModel, context.api, context.payload);
  21373. }
  21374. function seriesTaskReset(context) {
  21375. if (context.useClearVisual) {
  21376. context.data.clearAllVisual();
  21377. }
  21378. var resetDefines = context.resetDefines = normalizeToArray(context.reset(context.model, context.ecModel, context.api, context.payload));
  21379. return resetDefines.length > 1 ? map(resetDefines, function (v, idx) {
  21380. return makeSeriesTaskProgress(idx);
  21381. }) : singleSeriesTaskProgress;
  21382. }
  21383. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  21384. function makeSeriesTaskProgress(resetDefineIdx) {
  21385. return function (params, context) {
  21386. var data = context.data;
  21387. var resetDefine = context.resetDefines[resetDefineIdx];
  21388. if (resetDefine && resetDefine.dataEach) {
  21389. for (var i = params.start; i < params.end; i++) {
  21390. resetDefine.dataEach(data, i);
  21391. }
  21392. } else if (resetDefine && resetDefine.progress) {
  21393. resetDefine.progress(params, data);
  21394. }
  21395. };
  21396. }
  21397. function seriesTaskCount(context) {
  21398. return context.data.count();
  21399. }
  21400. function pipe(scheduler, seriesModel, task) {
  21401. var pipelineId = seriesModel.uid;
  21402. var pipeline = scheduler._pipelineMap.get(pipelineId);
  21403. !pipeline.head && (pipeline.head = task);
  21404. pipeline.tail && pipeline.tail.pipe(task);
  21405. pipeline.tail = task;
  21406. task.__idxInPipeline = pipeline.count++;
  21407. task.__pipeline = pipeline;
  21408. }
  21409. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  21410. if (isFunction$1(stageHandler)) {
  21411. stageHandler = {
  21412. overallReset: stageHandler,
  21413. seriesType: detectSeriseType(stageHandler)
  21414. };
  21415. }
  21416. stageHandler.uid = getUID('stageHandler');
  21417. visualType && (stageHandler.visualType = visualType);
  21418. return stageHandler;
  21419. };
  21420. /**
  21421. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  21422. * To ensure that they can work normally, they should work in block mode, that is,
  21423. * they should not be started util the previous tasks finished. So they cause the
  21424. * progressive rendering disabled. We try to detect the series type, to narrow down
  21425. * the block range to only the series type they concern, but not all series.
  21426. */
  21427. function detectSeriseType(legacyFunc) {
  21428. seriesType = null;
  21429. try {
  21430. // Assume there is no async when calling `eachSeriesByType`.
  21431. legacyFunc(ecModelMock, apiMock);
  21432. } catch (e) {}
  21433. return seriesType;
  21434. }
  21435. var ecModelMock = {};
  21436. var apiMock = {};
  21437. var seriesType;
  21438. mockMethods(ecModelMock, GlobalModel);
  21439. mockMethods(apiMock, ExtensionAPI);
  21440. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  21441. seriesType = type;
  21442. };
  21443. ecModelMock.eachComponent = function (cond) {
  21444. if (cond.mainType === 'series' && cond.subType) {
  21445. seriesType = cond.subType;
  21446. }
  21447. };
  21448. function mockMethods(target, Clz) {
  21449. /* eslint-disable */
  21450. for (var name in Clz.prototype) {
  21451. // Do not use hasOwnProperty
  21452. target[name] = noop;
  21453. }
  21454. /* eslint-enable */
  21455. }
  21456. /*
  21457. * Licensed to the Apache Software Foundation (ASF) under one
  21458. * or more contributor license agreements. See the NOTICE file
  21459. * distributed with this work for additional information
  21460. * regarding copyright ownership. The ASF licenses this file
  21461. * to you under the Apache License, Version 2.0 (the
  21462. * "License"); you may not use this file except in compliance
  21463. * with the License. You may obtain a copy of the License at
  21464. *
  21465. * http://www.apache.org/licenses/LICENSE-2.0
  21466. *
  21467. * Unless required by applicable law or agreed to in writing,
  21468. * software distributed under the License is distributed on an
  21469. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21470. * KIND, either express or implied. See the License for the
  21471. * specific language governing permissions and limitations
  21472. * under the License.
  21473. */
  21474. var colorAll = ['#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'];
  21475. var lightTheme = {
  21476. color: colorAll,
  21477. colorLayer: [['#37A2DA', '#ffd85c', '#fd7b5f'], ['#37A2DA', '#67E0E3', '#FFDB5C', '#ff9f7f', '#E062AE', '#9d96f5'], ['#37A2DA', '#32C5E9', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#e7bcf3', '#8378EA', '#96BFFF'], colorAll]
  21478. };
  21479. /*
  21480. * Licensed to the Apache Software Foundation (ASF) under one
  21481. * or more contributor license agreements. See the NOTICE file
  21482. * distributed with this work for additional information
  21483. * regarding copyright ownership. The ASF licenses this file
  21484. * to you under the Apache License, Version 2.0 (the
  21485. * "License"); you may not use this file except in compliance
  21486. * with the License. You may obtain a copy of the License at
  21487. *
  21488. * http://www.apache.org/licenses/LICENSE-2.0
  21489. *
  21490. * Unless required by applicable law or agreed to in writing,
  21491. * software distributed under the License is distributed on an
  21492. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21493. * KIND, either express or implied. See the License for the
  21494. * specific language governing permissions and limitations
  21495. * under the License.
  21496. */
  21497. var contrastColor = '#eee';
  21498. var axisCommon = function () {
  21499. return {
  21500. axisLine: {
  21501. lineStyle: {
  21502. color: contrastColor
  21503. }
  21504. },
  21505. axisTick: {
  21506. lineStyle: {
  21507. color: contrastColor
  21508. }
  21509. },
  21510. axisLabel: {
  21511. textStyle: {
  21512. color: contrastColor
  21513. }
  21514. },
  21515. splitLine: {
  21516. lineStyle: {
  21517. type: 'dashed',
  21518. color: '#aaa'
  21519. }
  21520. },
  21521. splitArea: {
  21522. areaStyle: {
  21523. color: contrastColor
  21524. }
  21525. }
  21526. };
  21527. };
  21528. var colorPalette = ['#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53', '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42'];
  21529. var theme = {
  21530. color: colorPalette,
  21531. backgroundColor: '#333',
  21532. tooltip: {
  21533. axisPointer: {
  21534. lineStyle: {
  21535. color: contrastColor
  21536. },
  21537. crossStyle: {
  21538. color: contrastColor
  21539. },
  21540. label: {
  21541. color: '#000'
  21542. }
  21543. }
  21544. },
  21545. legend: {
  21546. textStyle: {
  21547. color: contrastColor
  21548. }
  21549. },
  21550. textStyle: {
  21551. color: contrastColor
  21552. },
  21553. title: {
  21554. textStyle: {
  21555. color: contrastColor
  21556. }
  21557. },
  21558. toolbox: {
  21559. iconStyle: {
  21560. normal: {
  21561. borderColor: contrastColor
  21562. }
  21563. }
  21564. },
  21565. dataZoom: {
  21566. textStyle: {
  21567. color: contrastColor
  21568. }
  21569. },
  21570. visualMap: {
  21571. textStyle: {
  21572. color: contrastColor
  21573. }
  21574. },
  21575. timeline: {
  21576. lineStyle: {
  21577. color: contrastColor
  21578. },
  21579. itemStyle: {
  21580. normal: {
  21581. color: colorPalette[1]
  21582. }
  21583. },
  21584. label: {
  21585. normal: {
  21586. textStyle: {
  21587. color: contrastColor
  21588. }
  21589. }
  21590. },
  21591. controlStyle: {
  21592. normal: {
  21593. color: contrastColor,
  21594. borderColor: contrastColor
  21595. }
  21596. }
  21597. },
  21598. timeAxis: axisCommon(),
  21599. logAxis: axisCommon(),
  21600. valueAxis: axisCommon(),
  21601. categoryAxis: axisCommon(),
  21602. line: {
  21603. symbol: 'circle'
  21604. },
  21605. graph: {
  21606. color: colorPalette
  21607. },
  21608. gauge: {
  21609. title: {
  21610. textStyle: {
  21611. color: contrastColor
  21612. }
  21613. }
  21614. },
  21615. candlestick: {
  21616. itemStyle: {
  21617. normal: {
  21618. color: '#FD1050',
  21619. color0: '#0CF49B',
  21620. borderColor: '#FD1050',
  21621. borderColor0: '#0CF49B'
  21622. }
  21623. }
  21624. }
  21625. };
  21626. theme.categoryAxis.splitLine.show = false;
  21627. /*
  21628. * Licensed to the Apache Software Foundation (ASF) under one
  21629. * or more contributor license agreements. See the NOTICE file
  21630. * distributed with this work for additional information
  21631. * regarding copyright ownership. The ASF licenses this file
  21632. * to you under the Apache License, Version 2.0 (the
  21633. * "License"); you may not use this file except in compliance
  21634. * with the License. You may obtain a copy of the License at
  21635. *
  21636. * http://www.apache.org/licenses/LICENSE-2.0
  21637. *
  21638. * Unless required by applicable law or agreed to in writing,
  21639. * software distributed under the License is distributed on an
  21640. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21641. * KIND, either express or implied. See the License for the
  21642. * specific language governing permissions and limitations
  21643. * under the License.
  21644. */
  21645. /**
  21646. * This module is imported by echarts directly.
  21647. *
  21648. * Notice:
  21649. * Always keep this file exists for backward compatibility.
  21650. * Because before 4.1.0, dataset is an optional component,
  21651. * some users may import this module manually.
  21652. */
  21653. ComponentModel.extend({
  21654. type: 'dataset',
  21655. /**
  21656. * @protected
  21657. */
  21658. defaultOption: {
  21659. // 'row', 'column'
  21660. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  21661. // null/'auto': auto detect header, see "module:echarts/data/helper/sourceHelper"
  21662. sourceHeader: null,
  21663. dimensions: null,
  21664. source: null
  21665. },
  21666. optionUpdated: function () {
  21667. detectSourceFormat(this);
  21668. }
  21669. });
  21670. Component$1.extend({
  21671. type: 'dataset'
  21672. });
  21673. /**
  21674. * 椭圆形状
  21675. * @module zrender/graphic/shape/Ellipse
  21676. */
  21677. var Ellipse = Path.extend({
  21678. type: 'ellipse',
  21679. shape: {
  21680. cx: 0,
  21681. cy: 0,
  21682. rx: 0,
  21683. ry: 0
  21684. },
  21685. buildPath: function (ctx, shape) {
  21686. var k = 0.5522848;
  21687. var x = shape.cx;
  21688. var y = shape.cy;
  21689. var a = shape.rx;
  21690. var b = shape.ry;
  21691. var ox = a * k; // 水平控制点偏移量
  21692. var oy = b * k; // 垂直控制点偏移量
  21693. // 从椭圆的左端点开始顺时针绘制四条三次贝塞尔曲线
  21694. ctx.moveTo(x - a, y);
  21695. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  21696. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  21697. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  21698. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  21699. ctx.closePath();
  21700. }
  21701. });
  21702. // import Pattern from '../graphic/Pattern';
  21703. var DILIMITER_REG = /[\s,]+/;
  21704. /**
  21705. * For big svg string, this method might be time consuming.
  21706. *
  21707. * @param {string} svg xml string
  21708. * @return {Object} xml root.
  21709. */
  21710. function parseXML(svg) {
  21711. if (isString(svg)) {
  21712. var parser = new DOMParser();
  21713. svg = parser.parseFromString(svg, 'text/xml');
  21714. } // Document node. If using $.get, doc node may be input.
  21715. if (svg.nodeType === 9) {
  21716. svg = svg.firstChild;
  21717. } // nodeName of <!DOCTYPE svg> is also 'svg'.
  21718. while (svg.nodeName.toLowerCase() !== 'svg' || svg.nodeType !== 1) {
  21719. svg = svg.nextSibling;
  21720. }
  21721. return svg;
  21722. }
  21723. function SVGParser() {
  21724. this._defs = {};
  21725. this._root = null;
  21726. this._isDefine = false;
  21727. this._isText = false;
  21728. }
  21729. SVGParser.prototype.parse = function (xml, opt) {
  21730. opt = opt || {};
  21731. var svg = parseXML(xml);
  21732. if (!svg) {
  21733. throw new Error('Illegal svg');
  21734. }
  21735. var root = new Group();
  21736. this._root = root; // parse view port
  21737. var viewBox = svg.getAttribute('viewBox') || ''; // If width/height not specified, means "100%" of `opt.width/height`.
  21738. // TODO: Other percent value not supported yet.
  21739. var width = parseFloat(svg.getAttribute('width') || opt.width);
  21740. var height = parseFloat(svg.getAttribute('height') || opt.height); // If width/height not specified, set as null for output.
  21741. isNaN(width) && (width = null);
  21742. isNaN(height) && (height = null); // Apply inline style on svg element.
  21743. parseAttributes(svg, root, null, true);
  21744. var child = svg.firstChild;
  21745. while (child) {
  21746. this._parseNode(child, root);
  21747. child = child.nextSibling;
  21748. }
  21749. var viewBoxRect;
  21750. var viewBoxTransform;
  21751. if (viewBox) {
  21752. var viewBoxArr = trim(viewBox).split(DILIMITER_REG); // Some invalid case like viewBox: 'none'.
  21753. if (viewBoxArr.length >= 4) {
  21754. viewBoxRect = {
  21755. x: parseFloat(viewBoxArr[0] || 0),
  21756. y: parseFloat(viewBoxArr[1] || 0),
  21757. width: parseFloat(viewBoxArr[2]),
  21758. height: parseFloat(viewBoxArr[3])
  21759. };
  21760. }
  21761. }
  21762. if (viewBoxRect && width != null && height != null) {
  21763. viewBoxTransform = makeViewBoxTransform(viewBoxRect, width, height);
  21764. if (!opt.ignoreViewBox) {
  21765. // If set transform on the output group, it probably bring trouble when
  21766. // some users only intend to show the clipped content inside the viewBox,
  21767. // but not intend to transform the output group. So we keep the output
  21768. // group no transform. If the user intend to use the viewBox as a
  21769. // camera, just set `opt.ignoreViewBox` as `true` and set transfrom
  21770. // manually according to the viewBox info in the output of this method.
  21771. var elRoot = root;
  21772. root = new Group();
  21773. root.add(elRoot);
  21774. elRoot.scale = viewBoxTransform.scale.slice();
  21775. elRoot.position = viewBoxTransform.position.slice();
  21776. }
  21777. } // Some shapes might be overflow the viewport, which should be
  21778. // clipped despite whether the viewBox is used, as the SVG does.
  21779. if (!opt.ignoreRootClip && width != null && height != null) {
  21780. root.setClipPath(new Rect({
  21781. shape: {
  21782. x: 0,
  21783. y: 0,
  21784. width: width,
  21785. height: height
  21786. }
  21787. }));
  21788. } // Set width/height on group just for output the viewport size.
  21789. return {
  21790. root: root,
  21791. width: width,
  21792. height: height,
  21793. viewBoxRect: viewBoxRect,
  21794. viewBoxTransform: viewBoxTransform
  21795. };
  21796. };
  21797. SVGParser.prototype._parseNode = function (xmlNode, parentGroup) {
  21798. var nodeName = xmlNode.nodeName.toLowerCase(); // TODO
  21799. // support <style>...</style> in svg, where nodeName is 'style',
  21800. // CSS classes is defined globally wherever the style tags are declared.
  21801. if (nodeName === 'defs') {
  21802. // define flag
  21803. this._isDefine = true;
  21804. } else if (nodeName === 'text') {
  21805. this._isText = true;
  21806. }
  21807. var el;
  21808. if (this._isDefine) {
  21809. var parser = defineParsers[nodeName];
  21810. if (parser) {
  21811. var def = parser.call(this, xmlNode);
  21812. var id = xmlNode.getAttribute('id');
  21813. if (id) {
  21814. this._defs[id] = def;
  21815. }
  21816. }
  21817. } else {
  21818. var parser = nodeParsers[nodeName];
  21819. if (parser) {
  21820. el = parser.call(this, xmlNode, parentGroup);
  21821. parentGroup.add(el);
  21822. }
  21823. }
  21824. var child = xmlNode.firstChild;
  21825. while (child) {
  21826. if (child.nodeType === 1) {
  21827. this._parseNode(child, el);
  21828. } // Is text
  21829. if (child.nodeType === 3 && this._isText) {
  21830. this._parseText(child, el);
  21831. }
  21832. child = child.nextSibling;
  21833. } // Quit define
  21834. if (nodeName === 'defs') {
  21835. this._isDefine = false;
  21836. } else if (nodeName === 'text') {
  21837. this._isText = false;
  21838. }
  21839. };
  21840. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  21841. if (xmlNode.nodeType === 1) {
  21842. var dx = xmlNode.getAttribute('dx') || 0;
  21843. var dy = xmlNode.getAttribute('dy') || 0;
  21844. this._textX += parseFloat(dx);
  21845. this._textY += parseFloat(dy);
  21846. }
  21847. var text = new Text({
  21848. style: {
  21849. text: xmlNode.textContent,
  21850. transformText: true
  21851. },
  21852. position: [this._textX || 0, this._textY || 0]
  21853. });
  21854. inheritStyle(parentGroup, text);
  21855. parseAttributes(xmlNode, text, this._defs);
  21856. var fontSize = text.style.fontSize;
  21857. if (fontSize && fontSize < 9) {
  21858. // PENDING
  21859. text.style.fontSize = 9;
  21860. text.scale = text.scale || [1, 1];
  21861. text.scale[0] *= fontSize / 9;
  21862. text.scale[1] *= fontSize / 9;
  21863. }
  21864. var rect = text.getBoundingRect();
  21865. this._textX += rect.width;
  21866. parentGroup.add(text);
  21867. return text;
  21868. };
  21869. var nodeParsers = {
  21870. 'g': function (xmlNode, parentGroup) {
  21871. var g = new Group();
  21872. inheritStyle(parentGroup, g);
  21873. parseAttributes(xmlNode, g, this._defs);
  21874. return g;
  21875. },
  21876. 'rect': function (xmlNode, parentGroup) {
  21877. var rect = new Rect();
  21878. inheritStyle(parentGroup, rect);
  21879. parseAttributes(xmlNode, rect, this._defs);
  21880. rect.setShape({
  21881. x: parseFloat(xmlNode.getAttribute('x') || 0),
  21882. y: parseFloat(xmlNode.getAttribute('y') || 0),
  21883. width: parseFloat(xmlNode.getAttribute('width') || 0),
  21884. height: parseFloat(xmlNode.getAttribute('height') || 0)
  21885. }); // console.log(xmlNode.getAttribute('transform'));
  21886. // console.log(rect.transform);
  21887. return rect;
  21888. },
  21889. 'circle': function (xmlNode, parentGroup) {
  21890. var circle = new Circle();
  21891. inheritStyle(parentGroup, circle);
  21892. parseAttributes(xmlNode, circle, this._defs);
  21893. circle.setShape({
  21894. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  21895. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  21896. r: parseFloat(xmlNode.getAttribute('r') || 0)
  21897. });
  21898. return circle;
  21899. },
  21900. 'line': function (xmlNode, parentGroup) {
  21901. var line = new Line();
  21902. inheritStyle(parentGroup, line);
  21903. parseAttributes(xmlNode, line, this._defs);
  21904. line.setShape({
  21905. x1: parseFloat(xmlNode.getAttribute('x1') || 0),
  21906. y1: parseFloat(xmlNode.getAttribute('y1') || 0),
  21907. x2: parseFloat(xmlNode.getAttribute('x2') || 0),
  21908. y2: parseFloat(xmlNode.getAttribute('y2') || 0)
  21909. });
  21910. return line;
  21911. },
  21912. 'ellipse': function (xmlNode, parentGroup) {
  21913. var ellipse = new Ellipse();
  21914. inheritStyle(parentGroup, ellipse);
  21915. parseAttributes(xmlNode, ellipse, this._defs);
  21916. ellipse.setShape({
  21917. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  21918. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  21919. rx: parseFloat(xmlNode.getAttribute('rx') || 0),
  21920. ry: parseFloat(xmlNode.getAttribute('ry') || 0)
  21921. });
  21922. return ellipse;
  21923. },
  21924. 'polygon': function (xmlNode, parentGroup) {
  21925. var points = xmlNode.getAttribute('points');
  21926. if (points) {
  21927. points = parsePoints(points);
  21928. }
  21929. var polygon = new Polygon({
  21930. shape: {
  21931. points: points || []
  21932. }
  21933. });
  21934. inheritStyle(parentGroup, polygon);
  21935. parseAttributes(xmlNode, polygon, this._defs);
  21936. return polygon;
  21937. },
  21938. 'polyline': function (xmlNode, parentGroup) {
  21939. var path = new Path();
  21940. inheritStyle(parentGroup, path);
  21941. parseAttributes(xmlNode, path, this._defs);
  21942. var points = xmlNode.getAttribute('points');
  21943. if (points) {
  21944. points = parsePoints(points);
  21945. }
  21946. var polyline = new Polyline({
  21947. shape: {
  21948. points: points || []
  21949. }
  21950. });
  21951. return polyline;
  21952. },
  21953. 'image': function (xmlNode, parentGroup) {
  21954. var img = new ZImage();
  21955. inheritStyle(parentGroup, img);
  21956. parseAttributes(xmlNode, img, this._defs);
  21957. img.setStyle({
  21958. image: xmlNode.getAttribute('xlink:href'),
  21959. x: xmlNode.getAttribute('x'),
  21960. y: xmlNode.getAttribute('y'),
  21961. width: xmlNode.getAttribute('width'),
  21962. height: xmlNode.getAttribute('height')
  21963. });
  21964. return img;
  21965. },
  21966. 'text': function (xmlNode, parentGroup) {
  21967. var x = xmlNode.getAttribute('x') || 0;
  21968. var y = xmlNode.getAttribute('y') || 0;
  21969. var dx = xmlNode.getAttribute('dx') || 0;
  21970. var dy = xmlNode.getAttribute('dy') || 0;
  21971. this._textX = parseFloat(x) + parseFloat(dx);
  21972. this._textY = parseFloat(y) + parseFloat(dy);
  21973. var g = new Group();
  21974. inheritStyle(parentGroup, g);
  21975. parseAttributes(xmlNode, g, this._defs);
  21976. return g;
  21977. },
  21978. 'tspan': function (xmlNode, parentGroup) {
  21979. var x = xmlNode.getAttribute('x');
  21980. var y = xmlNode.getAttribute('y');
  21981. if (x != null) {
  21982. // new offset x
  21983. this._textX = parseFloat(x);
  21984. }
  21985. if (y != null) {
  21986. // new offset y
  21987. this._textY = parseFloat(y);
  21988. }
  21989. var dx = xmlNode.getAttribute('dx') || 0;
  21990. var dy = xmlNode.getAttribute('dy') || 0;
  21991. var g = new Group();
  21992. inheritStyle(parentGroup, g);
  21993. parseAttributes(xmlNode, g, this._defs);
  21994. this._textX += dx;
  21995. this._textY += dy;
  21996. return g;
  21997. },
  21998. 'path': function (xmlNode, parentGroup) {
  21999. // TODO svg fill rule
  22000. // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
  22001. // path.style.globalCompositeOperation = 'xor';
  22002. var d = xmlNode.getAttribute('d') || ''; // Performance sensitive.
  22003. var path = createFromString(d);
  22004. inheritStyle(parentGroup, path);
  22005. parseAttributes(xmlNode, path, this._defs);
  22006. return path;
  22007. }
  22008. };
  22009. var defineParsers = {
  22010. 'lineargradient': function (xmlNode) {
  22011. var x1 = parseInt(xmlNode.getAttribute('x1') || 0, 10);
  22012. var y1 = parseInt(xmlNode.getAttribute('y1') || 0, 10);
  22013. var x2 = parseInt(xmlNode.getAttribute('x2') || 10, 10);
  22014. var y2 = parseInt(xmlNode.getAttribute('y2') || 0, 10);
  22015. var gradient = new LinearGradient(x1, y1, x2, y2);
  22016. _parseGradientColorStops(xmlNode, gradient);
  22017. return gradient;
  22018. },
  22019. 'radialgradient': function (xmlNode) {}
  22020. };
  22021. function _parseGradientColorStops(xmlNode, gradient) {
  22022. var stop = xmlNode.firstChild;
  22023. while (stop) {
  22024. if (stop.nodeType === 1) {
  22025. var offset = stop.getAttribute('offset');
  22026. if (offset.indexOf('%') > 0) {
  22027. // percentage
  22028. offset = parseInt(offset, 10) / 100;
  22029. } else if (offset) {
  22030. // number from 0 to 1
  22031. offset = parseFloat(offset);
  22032. } else {
  22033. offset = 0;
  22034. }
  22035. var stopColor = stop.getAttribute('stop-color') || '#000000';
  22036. gradient.addColorStop(offset, stopColor);
  22037. }
  22038. stop = stop.nextSibling;
  22039. }
  22040. }
  22041. function inheritStyle(parent, child) {
  22042. if (parent && parent.__inheritedStyle) {
  22043. if (!child.__inheritedStyle) {
  22044. child.__inheritedStyle = {};
  22045. }
  22046. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  22047. }
  22048. }
  22049. function parsePoints(pointsString) {
  22050. var list = trim(pointsString).split(DILIMITER_REG);
  22051. var points = [];
  22052. for (var i = 0; i < list.length; i += 2) {
  22053. var x = parseFloat(list[i]);
  22054. var y = parseFloat(list[i + 1]);
  22055. points.push([x, y]);
  22056. }
  22057. return points;
  22058. }
  22059. var attributesMap = {
  22060. 'fill': 'fill',
  22061. 'stroke': 'stroke',
  22062. 'stroke-width': 'lineWidth',
  22063. 'opacity': 'opacity',
  22064. 'fill-opacity': 'fillOpacity',
  22065. 'stroke-opacity': 'strokeOpacity',
  22066. 'stroke-dasharray': 'lineDash',
  22067. 'stroke-dashoffset': 'lineDashOffset',
  22068. 'stroke-linecap': 'lineCap',
  22069. 'stroke-linejoin': 'lineJoin',
  22070. 'stroke-miterlimit': 'miterLimit',
  22071. 'font-family': 'fontFamily',
  22072. 'font-size': 'fontSize',
  22073. 'font-style': 'fontStyle',
  22074. 'font-weight': 'fontWeight',
  22075. 'text-align': 'textAlign',
  22076. 'alignment-baseline': 'textBaseline'
  22077. };
  22078. function parseAttributes(xmlNode, el, defs, onlyInlineStyle) {
  22079. var zrStyle = el.__inheritedStyle || {};
  22080. var isTextEl = el.type === 'text'; // TODO Shadow
  22081. if (xmlNode.nodeType === 1) {
  22082. parseTransformAttribute(xmlNode, el);
  22083. extend(zrStyle, parseStyleAttribute(xmlNode));
  22084. if (!onlyInlineStyle) {
  22085. for (var svgAttrName in attributesMap) {
  22086. if (attributesMap.hasOwnProperty(svgAttrName)) {
  22087. var attrValue = xmlNode.getAttribute(svgAttrName);
  22088. if (attrValue != null) {
  22089. zrStyle[attributesMap[svgAttrName]] = attrValue;
  22090. }
  22091. }
  22092. }
  22093. }
  22094. }
  22095. var elFillProp = isTextEl ? 'textFill' : 'fill';
  22096. var elStrokeProp = isTextEl ? 'textStroke' : 'stroke';
  22097. el.style = el.style || new Style();
  22098. var elStyle = el.style;
  22099. zrStyle.fill != null && elStyle.set(elFillProp, getPaint(zrStyle.fill, defs));
  22100. zrStyle.stroke != null && elStyle.set(elStrokeProp, getPaint(zrStyle.stroke, defs));
  22101. each$1(['lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'], function (propName) {
  22102. var elPropName = propName === 'lineWidth' && isTextEl ? 'textStrokeWidth' : propName;
  22103. zrStyle[propName] != null && elStyle.set(elPropName, parseFloat(zrStyle[propName]));
  22104. });
  22105. if (!zrStyle.textBaseline || zrStyle.textBaseline === 'auto') {
  22106. zrStyle.textBaseline = 'alphabetic';
  22107. }
  22108. if (zrStyle.textBaseline === 'alphabetic') {
  22109. zrStyle.textBaseline = 'bottom';
  22110. }
  22111. if (zrStyle.textAlign === 'start') {
  22112. zrStyle.textAlign = 'left';
  22113. }
  22114. if (zrStyle.textAlign === 'end') {
  22115. zrStyle.textAlign = 'right';
  22116. }
  22117. each$1(['lineDashOffset', 'lineCap', 'lineJoin', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'textBaseline'], function (propName) {
  22118. zrStyle[propName] != null && elStyle.set(propName, zrStyle[propName]);
  22119. });
  22120. if (zrStyle.lineDash) {
  22121. el.style.lineDash = trim(zrStyle.lineDash).split(DILIMITER_REG);
  22122. }
  22123. if (elStyle[elStrokeProp] && elStyle[elStrokeProp] !== 'none') {
  22124. // enable stroke
  22125. el[elStrokeProp] = true;
  22126. }
  22127. el.__inheritedStyle = zrStyle;
  22128. }
  22129. var urlRegex = /url\(\s*#(.*?)\)/;
  22130. function getPaint(str, defs) {
  22131. // if (str === 'none') {
  22132. // return;
  22133. // }
  22134. var urlMatch = defs && str && str.match(urlRegex);
  22135. if (urlMatch) {
  22136. var url = trim(urlMatch[1]);
  22137. var def = defs[url];
  22138. return def;
  22139. }
  22140. return str;
  22141. }
  22142. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.e,]*)\)/g;
  22143. function parseTransformAttribute(xmlNode, node) {
  22144. var transform = xmlNode.getAttribute('transform');
  22145. if (transform) {
  22146. transform = transform.replace(/,/g, ' ');
  22147. var m = null;
  22148. var transformOps = [];
  22149. transform.replace(transformRegex, function (str, type, value) {
  22150. transformOps.push(type, value);
  22151. });
  22152. for (var i = transformOps.length - 1; i > 0; i -= 2) {
  22153. var value = transformOps[i];
  22154. var type = transformOps[i - 1];
  22155. m = m || create$1();
  22156. switch (type) {
  22157. case 'translate':
  22158. value = trim(value).split(DILIMITER_REG);
  22159. translate(m, m, [parseFloat(value[0]), parseFloat(value[1] || 0)]);
  22160. break;
  22161. case 'scale':
  22162. value = trim(value).split(DILIMITER_REG);
  22163. scale$1(m, m, [parseFloat(value[0]), parseFloat(value[1] || value[0])]);
  22164. break;
  22165. case 'rotate':
  22166. value = trim(value).split(DILIMITER_REG);
  22167. rotate(m, m, parseFloat(value[0]));
  22168. break;
  22169. case 'skew':
  22170. value = trim(value).split(DILIMITER_REG);
  22171. console.warn('Skew transform is not supported yet');
  22172. break;
  22173. case 'matrix':
  22174. var value = trim(value).split(DILIMITER_REG);
  22175. m[0] = parseFloat(value[0]);
  22176. m[1] = parseFloat(value[1]);
  22177. m[2] = parseFloat(value[2]);
  22178. m[3] = parseFloat(value[3]);
  22179. m[4] = parseFloat(value[4]);
  22180. m[5] = parseFloat(value[5]);
  22181. break;
  22182. }
  22183. }
  22184. node.setLocalTransform(m);
  22185. }
  22186. } // Value may contain space.
  22187. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  22188. function parseStyleAttribute(xmlNode) {
  22189. var style = xmlNode.getAttribute('style');
  22190. var result = {};
  22191. if (!style) {
  22192. return result;
  22193. }
  22194. var styleList = {};
  22195. styleRegex.lastIndex = 0;
  22196. var styleRegResult;
  22197. while ((styleRegResult = styleRegex.exec(style)) != null) {
  22198. styleList[styleRegResult[1]] = styleRegResult[2];
  22199. }
  22200. for (var svgAttrName in attributesMap) {
  22201. if (attributesMap.hasOwnProperty(svgAttrName) && styleList[svgAttrName] != null) {
  22202. result[attributesMap[svgAttrName]] = styleList[svgAttrName];
  22203. }
  22204. }
  22205. return result;
  22206. }
  22207. /**
  22208. * @param {Array.<number>} viewBoxRect
  22209. * @param {number} width
  22210. * @param {number} height
  22211. * @return {Object} {scale, position}
  22212. */
  22213. function makeViewBoxTransform(viewBoxRect, width, height) {
  22214. var scaleX = width / viewBoxRect.width;
  22215. var scaleY = height / viewBoxRect.height;
  22216. var scale = Math.min(scaleX, scaleY); // preserveAspectRatio 'xMidYMid'
  22217. var viewBoxScale = [scale, scale];
  22218. var viewBoxPosition = [-(viewBoxRect.x + viewBoxRect.width / 2) * scale + width / 2, -(viewBoxRect.y + viewBoxRect.height / 2) * scale + height / 2];
  22219. return {
  22220. scale: viewBoxScale,
  22221. position: viewBoxPosition
  22222. };
  22223. }
  22224. /**
  22225. * @param {string|XMLElement} xml
  22226. * @param {Object} [opt]
  22227. * @param {number} [opt.width] Default width if svg width not specified or is a percent value.
  22228. * @param {number} [opt.height] Default height if svg height not specified or is a percent value.
  22229. * @param {boolean} [opt.ignoreViewBox]
  22230. * @param {boolean} [opt.ignoreRootClip]
  22231. * @return {Object} result:
  22232. * {
  22233. * root: Group, The root of the the result tree of zrender shapes,
  22234. * width: number, the viewport width of the SVG,
  22235. * height: number, the viewport height of the SVG,
  22236. * viewBoxRect: {x, y, width, height}, the declared viewBox rect of the SVG, if exists,
  22237. * viewBoxTransform: the {scale, position} calculated by viewBox and viewport, is exists.
  22238. * }
  22239. */
  22240. function parseSVG(xml, opt) {
  22241. var parser = new SVGParser();
  22242. return parser.parse(xml, opt);
  22243. }
  22244. /*
  22245. * Licensed to the Apache Software Foundation (ASF) under one
  22246. * or more contributor license agreements. See the NOTICE file
  22247. * distributed with this work for additional information
  22248. * regarding copyright ownership. The ASF licenses this file
  22249. * to you under the Apache License, Version 2.0 (the
  22250. * "License"); you may not use this file except in compliance
  22251. * with the License. You may obtain a copy of the License at
  22252. *
  22253. * http://www.apache.org/licenses/LICENSE-2.0
  22254. *
  22255. * Unless required by applicable law or agreed to in writing,
  22256. * software distributed under the License is distributed on an
  22257. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22258. * KIND, either express or implied. See the License for the
  22259. * specific language governing permissions and limitations
  22260. * under the License.
  22261. */
  22262. var storage = createHashMap(); // For minimize the code size of common echarts package,
  22263. // do not put too much logic in this module.
  22264. var mapDataStorage = {
  22265. // The format of record: see `echarts.registerMap`.
  22266. // Compatible with previous `echarts.registerMap`.
  22267. registerMap: function (mapName, rawGeoJson, rawSpecialAreas) {
  22268. var records;
  22269. if (isArray(rawGeoJson)) {
  22270. records = rawGeoJson;
  22271. } else if (rawGeoJson.svg) {
  22272. records = [{
  22273. type: 'svg',
  22274. source: rawGeoJson.svg,
  22275. specialAreas: rawGeoJson.specialAreas
  22276. }];
  22277. } else {
  22278. // Backward compatibility.
  22279. if (rawGeoJson.geoJson && !rawGeoJson.features) {
  22280. rawSpecialAreas = rawGeoJson.specialAreas;
  22281. rawGeoJson = rawGeoJson.geoJson;
  22282. }
  22283. records = [{
  22284. type: 'geoJSON',
  22285. source: rawGeoJson,
  22286. specialAreas: rawSpecialAreas
  22287. }];
  22288. }
  22289. each$1(records, function (record) {
  22290. var type = record.type;
  22291. type === 'geoJson' && (type = record.type = 'geoJSON');
  22292. var parse = parsers[type];
  22293. parse(record);
  22294. });
  22295. return storage.set(mapName, records);
  22296. },
  22297. retrieveMap: function (mapName) {
  22298. return storage.get(mapName);
  22299. }
  22300. };
  22301. var parsers = {
  22302. geoJSON: function (record) {
  22303. var source = record.source;
  22304. record.geoJSON = !isString(source) ? source : typeof JSON !== 'undefined' && JSON.parse ? JSON.parse(source) : new Function('return (' + source + ');')();
  22305. },
  22306. // Only perform parse to XML object here, which might be time
  22307. // consiming for large SVG.
  22308. // Although convert XML to zrender element is also time consiming,
  22309. // if we do it here, the clone of zrender elements has to be
  22310. // required. So we do it once for each geo instance, util real
  22311. // performance issues call for optimizing it.
  22312. svg: function (record) {
  22313. record.svgXML = parseXML(record.source);
  22314. }
  22315. };
  22316. /*
  22317. * Licensed to the Apache Software Foundation (ASF) under one
  22318. * or more contributor license agreements. See the NOTICE file
  22319. * distributed with this work for additional information
  22320. * regarding copyright ownership. The ASF licenses this file
  22321. * to you under the Apache License, Version 2.0 (the
  22322. * "License"); you may not use this file except in compliance
  22323. * with the License. You may obtain a copy of the License at
  22324. *
  22325. * http://www.apache.org/licenses/LICENSE-2.0
  22326. *
  22327. * Unless required by applicable law or agreed to in writing,
  22328. * software distributed under the License is distributed on an
  22329. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22330. * KIND, either express or implied. See the License for the
  22331. * specific language governing permissions and limitations
  22332. * under the License.
  22333. */
  22334. var assert = assert$1;
  22335. var each = each$1;
  22336. var isFunction = isFunction$1;
  22337. var isObject = isObject$1;
  22338. var parseClassType = ComponentModel.parseClassType;
  22339. var version = '4.8.0';
  22340. var dependencies = {
  22341. zrender: '4.3.1'
  22342. };
  22343. var TEST_FRAME_REMAIN_TIME = 1;
  22344. var PRIORITY_PROCESSOR_FILTER = 1000;
  22345. var PRIORITY_PROCESSOR_SERIES_FILTER = 800;
  22346. var PRIORITY_PROCESSOR_DATASTACK = 900;
  22347. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  22348. var PRIORITY_VISUAL_LAYOUT = 1000;
  22349. var PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;
  22350. var PRIORITY_VISUAL_GLOBAL = 2000;
  22351. var PRIORITY_VISUAL_CHART = 3000;
  22352. var PRIORITY_VISUAL_POST_CHART_LAYOUT = 3500;
  22353. var PRIORITY_VISUAL_COMPONENT = 4000; // FIXME
  22354. // necessary?
  22355. var PRIORITY_VISUAL_BRUSH = 5000;
  22356. var PRIORITY = {
  22357. PROCESSOR: {
  22358. FILTER: PRIORITY_PROCESSOR_FILTER,
  22359. SERIES_FILTER: PRIORITY_PROCESSOR_SERIES_FILTER,
  22360. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  22361. },
  22362. VISUAL: {
  22363. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  22364. PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,
  22365. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  22366. CHART: PRIORITY_VISUAL_CHART,
  22367. POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,
  22368. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  22369. BRUSH: PRIORITY_VISUAL_BRUSH
  22370. }
  22371. }; // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  22372. // where they must not be invoked nestedly, except the only case: invoke
  22373. // dispatchAction with updateMethod "none" in main process.
  22374. // This flag is used to carry out this rule.
  22375. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  22376. var IN_MAIN_PROCESS = '__flagInMainProcess';
  22377. var OPTION_UPDATED = '__optionUpdated';
  22378. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  22379. function createRegisterEventWithLowercaseName(method, ignoreDisposed) {
  22380. return function (eventName, handler, context) {
  22381. if (!ignoreDisposed && this._disposed) {
  22382. return;
  22383. } // Event name is all lowercase
  22384. eventName = eventName && eventName.toLowerCase();
  22385. Eventful.prototype[method].call(this, eventName, handler, context);
  22386. };
  22387. }
  22388. /**
  22389. * @module echarts~MessageCenter
  22390. */
  22391. function MessageCenter() {
  22392. Eventful.call(this);
  22393. }
  22394. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on', true);
  22395. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off', true);
  22396. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one', true);
  22397. mixin(MessageCenter, Eventful);
  22398. /**
  22399. * @module echarts~ECharts
  22400. */
  22401. function ECharts(dom, theme$$1, opts) {
  22402. opts = opts || {}; // Get theme by name
  22403. if (typeof theme$$1 === 'string') {
  22404. theme$$1 = themeStorage[theme$$1];
  22405. }
  22406. /**
  22407. * @type {string}
  22408. */
  22409. this.id;
  22410. /**
  22411. * Group id
  22412. * @type {string}
  22413. */
  22414. this.group;
  22415. /**
  22416. * @type {HTMLElement}
  22417. * @private
  22418. */
  22419. this._dom = dom;
  22420. var defaultRenderer = 'canvas';
  22421. /**
  22422. * @type {module:zrender/ZRender}
  22423. * @private
  22424. */
  22425. var zr = this._zr = init$1(dom, {
  22426. renderer: opts.renderer || defaultRenderer,
  22427. devicePixelRatio: opts.devicePixelRatio,
  22428. width: opts.width,
  22429. height: opts.height
  22430. });
  22431. /**
  22432. * Expect 60 fps.
  22433. * @type {Function}
  22434. * @private
  22435. */
  22436. this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  22437. var theme$$1 = clone(theme$$1);
  22438. theme$$1 && backwardCompat(theme$$1, true);
  22439. /**
  22440. * @type {Object}
  22441. * @private
  22442. */
  22443. this._theme = theme$$1;
  22444. /**
  22445. * @type {Array.<module:echarts/view/Chart>}
  22446. * @private
  22447. */
  22448. this._chartsViews = [];
  22449. /**
  22450. * @type {Object.<string, module:echarts/view/Chart>}
  22451. * @private
  22452. */
  22453. this._chartsMap = {};
  22454. /**
  22455. * @type {Array.<module:echarts/view/Component>}
  22456. * @private
  22457. */
  22458. this._componentsViews = [];
  22459. /**
  22460. * @type {Object.<string, module:echarts/view/Component>}
  22461. * @private
  22462. */
  22463. this._componentsMap = {};
  22464. /**
  22465. * @type {module:echarts/CoordinateSystem}
  22466. * @private
  22467. */
  22468. this._coordSysMgr = new CoordinateSystemManager();
  22469. /**
  22470. * @type {module:echarts/ExtensionAPI}
  22471. * @private
  22472. */
  22473. var api = this._api = createExtensionAPI(this); // Sort on demand
  22474. function prioritySortFunc(a, b) {
  22475. return a.__prio - b.__prio;
  22476. }
  22477. sort(visualFuncs, prioritySortFunc);
  22478. sort(dataProcessorFuncs, prioritySortFunc);
  22479. /**
  22480. * @type {module:echarts/stream/Scheduler}
  22481. */
  22482. this._scheduler = new Scheduler(this, api, dataProcessorFuncs, visualFuncs);
  22483. Eventful.call(this, this._ecEventProcessor = new EventProcessor());
  22484. /**
  22485. * @type {module:echarts~MessageCenter}
  22486. * @private
  22487. */
  22488. this._messageCenter = new MessageCenter(); // Init mouse events
  22489. this._initEvents(); // In case some people write `window.onresize = chart.resize`
  22490. this.resize = bind(this.resize, this); // Can't dispatch action during rendering procedure
  22491. this._pendingActions = [];
  22492. zr.animation.on('frame', this._onframe, this);
  22493. bindRenderedEvent(zr, this); // ECharts instance can be used as value.
  22494. setAsPrimitive(this);
  22495. }
  22496. var echartsProto = ECharts.prototype;
  22497. echartsProto._onframe = function () {
  22498. if (this._disposed) {
  22499. return;
  22500. }
  22501. var scheduler = this._scheduler; // Lazy update
  22502. if (this[OPTION_UPDATED]) {
  22503. var silent = this[OPTION_UPDATED].silent;
  22504. this[IN_MAIN_PROCESS] = true;
  22505. prepare(this);
  22506. updateMethods.update.call(this);
  22507. this[IN_MAIN_PROCESS] = false;
  22508. this[OPTION_UPDATED] = false;
  22509. flushPendingActions.call(this, silent);
  22510. triggerUpdatedEvent.call(this, silent);
  22511. } // Avoid do both lazy update and progress in one frame.
  22512. else if (scheduler.unfinished) {
  22513. // Stream progress.
  22514. var remainTime = TEST_FRAME_REMAIN_TIME;
  22515. var ecModel = this._model;
  22516. var api = this._api;
  22517. scheduler.unfinished = false;
  22518. do {
  22519. var startTime = +new Date();
  22520. scheduler.performSeriesTasks(ecModel); // Currently dataProcessorFuncs do not check threshold.
  22521. scheduler.performDataProcessorTasks(ecModel);
  22522. updateStreamModes(this, ecModel); // Do not update coordinate system here. Because that coord system update in
  22523. // each frame is not a good user experience. So we follow the rule that
  22524. // the extent of the coordinate system is determin in the first frame (the
  22525. // frame is executed immedietely after task reset.
  22526. // this._coordSysMgr.update(ecModel, api);
  22527. // console.log('--- ec frame visual ---', remainTime);
  22528. scheduler.performVisualTasks(ecModel);
  22529. renderSeries(this, this._model, api, 'remain');
  22530. remainTime -= +new Date() - startTime;
  22531. } while (remainTime > 0 && scheduler.unfinished); // Call flush explicitly for trigger finished event.
  22532. if (!scheduler.unfinished) {
  22533. this._zr.flush();
  22534. } // Else, zr flushing be ensue within the same frame,
  22535. // because zr flushing is after onframe event.
  22536. }
  22537. };
  22538. /**
  22539. * @return {HTMLElement}
  22540. */
  22541. echartsProto.getDom = function () {
  22542. return this._dom;
  22543. };
  22544. /**
  22545. * @return {module:zrender~ZRender}
  22546. */
  22547. echartsProto.getZr = function () {
  22548. return this._zr;
  22549. };
  22550. /**
  22551. * Usage:
  22552. * chart.setOption(option, notMerge, lazyUpdate);
  22553. * chart.setOption(option, {
  22554. * notMerge: ...,
  22555. * lazyUpdate: ...,
  22556. * silent: ...
  22557. * });
  22558. *
  22559. * @param {Object} option
  22560. * @param {Object|boolean} [opts] opts or notMerge.
  22561. * @param {boolean} [opts.notMerge=false]
  22562. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  22563. */
  22564. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  22565. if (this._disposed) {
  22566. return;
  22567. }
  22568. var silent;
  22569. if (isObject(notMerge)) {
  22570. lazyUpdate = notMerge.lazyUpdate;
  22571. silent = notMerge.silent;
  22572. notMerge = notMerge.notMerge;
  22573. }
  22574. this[IN_MAIN_PROCESS] = true;
  22575. if (!this._model || notMerge) {
  22576. var optionManager = new OptionManager(this._api);
  22577. var theme$$1 = this._theme;
  22578. var ecModel = this._model = new GlobalModel();
  22579. ecModel.scheduler = this._scheduler;
  22580. ecModel.init(null, null, theme$$1, optionManager);
  22581. }
  22582. this._model.setOption(option, optionPreprocessorFuncs);
  22583. if (lazyUpdate) {
  22584. this[OPTION_UPDATED] = {
  22585. silent: silent
  22586. };
  22587. this[IN_MAIN_PROCESS] = false;
  22588. } else {
  22589. prepare(this);
  22590. updateMethods.update.call(this); // Ensure zr refresh sychronously, and then pixel in canvas can be
  22591. // fetched after `setOption`.
  22592. this._zr.flush();
  22593. this[OPTION_UPDATED] = false;
  22594. this[IN_MAIN_PROCESS] = false;
  22595. flushPendingActions.call(this, silent);
  22596. triggerUpdatedEvent.call(this, silent);
  22597. }
  22598. };
  22599. /**
  22600. * @DEPRECATED
  22601. */
  22602. echartsProto.setTheme = function () {
  22603. console.error('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  22604. };
  22605. /**
  22606. * @return {module:echarts/model/Global}
  22607. */
  22608. echartsProto.getModel = function () {
  22609. return this._model;
  22610. };
  22611. /**
  22612. * @return {Object}
  22613. */
  22614. echartsProto.getOption = function () {
  22615. return this._model && this._model.getOption();
  22616. };
  22617. /**
  22618. * @return {number}
  22619. */
  22620. echartsProto.getWidth = function () {
  22621. return this._zr.getWidth();
  22622. };
  22623. /**
  22624. * @return {number}
  22625. */
  22626. echartsProto.getHeight = function () {
  22627. return this._zr.getHeight();
  22628. };
  22629. /**
  22630. * @return {number}
  22631. */
  22632. echartsProto.getDevicePixelRatio = function () {
  22633. return this._zr.painter.dpr || window.devicePixelRatio || 1;
  22634. };
  22635. /**
  22636. * Get canvas which has all thing rendered
  22637. * @param {Object} opts
  22638. * @param {string} [opts.backgroundColor]
  22639. * @return {string}
  22640. */
  22641. echartsProto.getRenderedCanvas = function (opts) {
  22642. if (!env$1.canvasSupported) {
  22643. return;
  22644. }
  22645. opts = opts || {};
  22646. opts.pixelRatio = opts.pixelRatio || 1;
  22647. opts.backgroundColor = opts.backgroundColor || this._model.get('backgroundColor');
  22648. var zr = this._zr; // var list = zr.storage.getDisplayList();
  22649. // Stop animations
  22650. // Never works before in init animation, so remove it.
  22651. // zrUtil.each(list, function (el) {
  22652. // el.stopAnimation(true);
  22653. // });
  22654. return zr.painter.getRenderedCanvas(opts);
  22655. };
  22656. /**
  22657. * Get svg data url
  22658. * @return {string}
  22659. */
  22660. echartsProto.getSvgDataURL = function () {
  22661. if (!env$1.svgSupported) {
  22662. return;
  22663. }
  22664. var zr = this._zr;
  22665. var list = zr.storage.getDisplayList(); // Stop animations
  22666. each$1(list, function (el) {
  22667. el.stopAnimation(true);
  22668. });
  22669. return zr.painter.toDataURL();
  22670. };
  22671. /**
  22672. * @return {string}
  22673. * @param {Object} opts
  22674. * @param {string} [opts.type='png']
  22675. * @param {string} [opts.pixelRatio=1]
  22676. * @param {string} [opts.backgroundColor]
  22677. * @param {string} [opts.excludeComponents]
  22678. */
  22679. echartsProto.getDataURL = function (opts) {
  22680. if (this._disposed) {
  22681. return;
  22682. }
  22683. opts = opts || {};
  22684. var excludeComponents = opts.excludeComponents;
  22685. var ecModel = this._model;
  22686. var excludesComponentViews = [];
  22687. var self = this;
  22688. each(excludeComponents, function (componentType) {
  22689. ecModel.eachComponent({
  22690. mainType: componentType
  22691. }, function (component) {
  22692. var view = self._componentsMap[component.__viewId];
  22693. if (!view.group.ignore) {
  22694. excludesComponentViews.push(view);
  22695. view.group.ignore = true;
  22696. }
  22697. });
  22698. });
  22699. var url = this._zr.painter.getType() === 'svg' ? this.getSvgDataURL() : this.getRenderedCanvas(opts).toDataURL('image/' + (opts && opts.type || 'png'));
  22700. each(excludesComponentViews, function (view) {
  22701. view.group.ignore = false;
  22702. });
  22703. return url;
  22704. };
  22705. /**
  22706. * @return {string}
  22707. * @param {Object} opts
  22708. * @param {string} [opts.type='png']
  22709. * @param {string} [opts.pixelRatio=1]
  22710. * @param {string} [opts.backgroundColor]
  22711. */
  22712. echartsProto.getConnectedDataURL = function (opts) {
  22713. if (this._disposed) {
  22714. return;
  22715. }
  22716. if (!env$1.canvasSupported) {
  22717. return;
  22718. }
  22719. var isSvg = opts.type === 'svg';
  22720. var groupId = this.group;
  22721. var mathMin = Math.min;
  22722. var mathMax = Math.max;
  22723. var MAX_NUMBER = Infinity;
  22724. if (connectedGroups[groupId]) {
  22725. var left = MAX_NUMBER;
  22726. var top = MAX_NUMBER;
  22727. var right = -MAX_NUMBER;
  22728. var bottom = -MAX_NUMBER;
  22729. var canvasList = [];
  22730. var dpr = opts && opts.pixelRatio || 1;
  22731. each$1(instances, function (chart, id) {
  22732. if (chart.group === groupId) {
  22733. var canvas = isSvg ? chart.getZr().painter.getSvgDom().innerHTML : chart.getRenderedCanvas(clone(opts));
  22734. var boundingRect = chart.getDom().getBoundingClientRect();
  22735. left = mathMin(boundingRect.left, left);
  22736. top = mathMin(boundingRect.top, top);
  22737. right = mathMax(boundingRect.right, right);
  22738. bottom = mathMax(boundingRect.bottom, bottom);
  22739. canvasList.push({
  22740. dom: canvas,
  22741. left: boundingRect.left,
  22742. top: boundingRect.top
  22743. });
  22744. }
  22745. });
  22746. left *= dpr;
  22747. top *= dpr;
  22748. right *= dpr;
  22749. bottom *= dpr;
  22750. var width = right - left;
  22751. var height = bottom - top;
  22752. var targetCanvas = createCanvas();
  22753. var zr = init$1(targetCanvas, {
  22754. renderer: isSvg ? 'svg' : 'canvas'
  22755. });
  22756. zr.resize({
  22757. width: width,
  22758. height: height
  22759. });
  22760. if (isSvg) {
  22761. var content = '';
  22762. each(canvasList, function (item) {
  22763. var x = item.left - left;
  22764. var y = item.top - top;
  22765. content += '<g transform="translate(' + x + ',' + y + ')">' + item.dom + '</g>';
  22766. });
  22767. zr.painter.getSvgRoot().innerHTML = content;
  22768. if (opts.connectedBackgroundColor) {
  22769. zr.painter.setBackgroundColor(opts.connectedBackgroundColor);
  22770. }
  22771. zr.refreshImmediately();
  22772. return zr.painter.toDataURL();
  22773. } else {
  22774. // Background between the charts
  22775. if (opts.connectedBackgroundColor) {
  22776. zr.add(new Rect({
  22777. shape: {
  22778. x: 0,
  22779. y: 0,
  22780. width: width,
  22781. height: height
  22782. },
  22783. style: {
  22784. fill: opts.connectedBackgroundColor
  22785. }
  22786. }));
  22787. }
  22788. each(canvasList, function (item) {
  22789. var img = new ZImage({
  22790. style: {
  22791. x: item.left * dpr - left,
  22792. y: item.top * dpr - top,
  22793. image: item.dom
  22794. }
  22795. });
  22796. zr.add(img);
  22797. });
  22798. zr.refreshImmediately();
  22799. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  22800. }
  22801. } else {
  22802. return this.getDataURL(opts);
  22803. }
  22804. };
  22805. /**
  22806. * Convert from logical coordinate system to pixel coordinate system.
  22807. * See CoordinateSystem#convertToPixel.
  22808. * @param {string|Object} finder
  22809. * If string, e.g., 'geo', means {geoIndex: 0}.
  22810. * If Object, could contain some of these properties below:
  22811. * {
  22812. * seriesIndex / seriesId / seriesName,
  22813. * geoIndex / geoId, geoName,
  22814. * bmapIndex / bmapId / bmapName,
  22815. * xAxisIndex / xAxisId / xAxisName,
  22816. * yAxisIndex / yAxisId / yAxisName,
  22817. * gridIndex / gridId / gridName,
  22818. * ... (can be extended)
  22819. * }
  22820. * @param {Array|number} value
  22821. * @return {Array|number} result
  22822. */
  22823. echartsProto.convertToPixel = curry(doConvertPixel, 'convertToPixel');
  22824. /**
  22825. * Convert from pixel coordinate system to logical coordinate system.
  22826. * See CoordinateSystem#convertFromPixel.
  22827. * @param {string|Object} finder
  22828. * If string, e.g., 'geo', means {geoIndex: 0}.
  22829. * If Object, could contain some of these properties below:
  22830. * {
  22831. * seriesIndex / seriesId / seriesName,
  22832. * geoIndex / geoId / geoName,
  22833. * bmapIndex / bmapId / bmapName,
  22834. * xAxisIndex / xAxisId / xAxisName,
  22835. * yAxisIndex / yAxisId / yAxisName
  22836. * gridIndex / gridId / gridName,
  22837. * ... (can be extended)
  22838. * }
  22839. * @param {Array|number} value
  22840. * @return {Array|number} result
  22841. */
  22842. echartsProto.convertFromPixel = curry(doConvertPixel, 'convertFromPixel');
  22843. function doConvertPixel(methodName, finder, value) {
  22844. if (this._disposed) {
  22845. return;
  22846. }
  22847. var ecModel = this._model;
  22848. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  22849. var result;
  22850. finder = parseFinder(ecModel, finder);
  22851. for (var i = 0; i < coordSysList.length; i++) {
  22852. var coordSys = coordSysList[i];
  22853. if (coordSys[methodName] && (result = coordSys[methodName](ecModel, finder, value)) != null) {
  22854. return result;
  22855. }
  22856. }
  22857. }
  22858. /**
  22859. * Is the specified coordinate systems or components contain the given pixel point.
  22860. * @param {string|Object} finder
  22861. * If string, e.g., 'geo', means {geoIndex: 0}.
  22862. * If Object, could contain some of these properties below:
  22863. * {
  22864. * seriesIndex / seriesId / seriesName,
  22865. * geoIndex / geoId / geoName,
  22866. * bmapIndex / bmapId / bmapName,
  22867. * xAxisIndex / xAxisId / xAxisName,
  22868. * yAxisIndex / yAxisId / yAxisName,
  22869. * gridIndex / gridId / gridName,
  22870. * ... (can be extended)
  22871. * }
  22872. * @param {Array|number} value
  22873. * @return {boolean} result
  22874. */
  22875. echartsProto.containPixel = function (finder, value) {
  22876. if (this._disposed) {
  22877. return;
  22878. }
  22879. var ecModel = this._model;
  22880. var result;
  22881. finder = parseFinder(ecModel, finder);
  22882. each$1(finder, function (models, key) {
  22883. key.indexOf('Models') >= 0 && each$1(models, function (model) {
  22884. var coordSys = model.coordinateSystem;
  22885. if (coordSys && coordSys.containPoint) {
  22886. result |= !!coordSys.containPoint(value);
  22887. } else if (key === 'seriesModels') {
  22888. var view = this._chartsMap[model.__viewId];
  22889. if (view && view.containPoint) {
  22890. result |= view.containPoint(value, model);
  22891. } else {}
  22892. } else {}
  22893. }, this);
  22894. }, this);
  22895. return !!result;
  22896. };
  22897. /**
  22898. * Get visual from series or data.
  22899. * @param {string|Object} finder
  22900. * If string, e.g., 'series', means {seriesIndex: 0}.
  22901. * If Object, could contain some of these properties below:
  22902. * {
  22903. * seriesIndex / seriesId / seriesName,
  22904. * dataIndex / dataIndexInside
  22905. * }
  22906. * If dataIndex is not specified, series visual will be fetched,
  22907. * but not data item visual.
  22908. * If all of seriesIndex, seriesId, seriesName are not specified,
  22909. * visual will be fetched from first series.
  22910. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  22911. */
  22912. echartsProto.getVisual = function (finder, visualType) {
  22913. var ecModel = this._model;
  22914. finder = parseFinder(ecModel, finder, {
  22915. defaultMainType: 'series'
  22916. });
  22917. var seriesModel = finder.seriesModel;
  22918. var data = seriesModel.getData();
  22919. var dataIndexInside = finder.hasOwnProperty('dataIndexInside') ? finder.dataIndexInside : finder.hasOwnProperty('dataIndex') ? data.indexOfRawIndex(finder.dataIndex) : null;
  22920. return dataIndexInside != null ? data.getItemVisual(dataIndexInside, visualType) : data.getVisual(visualType);
  22921. };
  22922. /**
  22923. * Get view of corresponding component model
  22924. * @param {module:echarts/model/Component} componentModel
  22925. * @return {module:echarts/view/Component}
  22926. */
  22927. echartsProto.getViewOfComponentModel = function (componentModel) {
  22928. return this._componentsMap[componentModel.__viewId];
  22929. };
  22930. /**
  22931. * Get view of corresponding series model
  22932. * @param {module:echarts/model/Series} seriesModel
  22933. * @return {module:echarts/view/Chart}
  22934. */
  22935. echartsProto.getViewOfSeriesModel = function (seriesModel) {
  22936. return this._chartsMap[seriesModel.__viewId];
  22937. };
  22938. var updateMethods = {
  22939. prepareAndUpdate: function (payload) {
  22940. prepare(this);
  22941. updateMethods.update.call(this, payload);
  22942. },
  22943. /**
  22944. * @param {Object} payload
  22945. * @private
  22946. */
  22947. update: function (payload) {
  22948. // console.profile && console.profile('update');
  22949. var ecModel = this._model;
  22950. var api = this._api;
  22951. var zr = this._zr;
  22952. var coordSysMgr = this._coordSysMgr;
  22953. var scheduler = this._scheduler; // update before setOption
  22954. if (!ecModel) {
  22955. return;
  22956. }
  22957. scheduler.restoreData(ecModel, payload);
  22958. scheduler.performSeriesTasks(ecModel); // TODO
  22959. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  22960. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  22961. // Create new coordinate system each update
  22962. // In LineView may save the old coordinate system and use it to get the orignal point
  22963. coordSysMgr.create(ecModel, api);
  22964. scheduler.performDataProcessorTasks(ecModel, payload); // Current stream render is not supported in data process. So we can update
  22965. // stream modes after data processing, where the filtered data is used to
  22966. // deteming whether use progressive rendering.
  22967. updateStreamModes(this, ecModel); // We update stream modes before coordinate system updated, then the modes info
  22968. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  22969. // the drawback is the full coord info can not be fetched. Fortunately this full
  22970. // coord is not requied in stream mode updater currently.
  22971. coordSysMgr.update(ecModel, api);
  22972. clearColorPalette(ecModel);
  22973. scheduler.performVisualTasks(ecModel, payload);
  22974. render(this, ecModel, api, payload); // Set background
  22975. var backgroundColor = ecModel.get('backgroundColor') || 'transparent'; // In IE8
  22976. if (!env$1.canvasSupported) {
  22977. var colorArr = parse(backgroundColor);
  22978. backgroundColor = stringify(colorArr, 'rgb');
  22979. if (colorArr[3] === 0) {
  22980. backgroundColor = 'transparent';
  22981. }
  22982. } else {
  22983. zr.setBackgroundColor(backgroundColor);
  22984. }
  22985. performPostUpdateFuncs(ecModel, api); // console.profile && console.profileEnd('update');
  22986. },
  22987. /**
  22988. * @param {Object} payload
  22989. * @private
  22990. */
  22991. updateTransform: function (payload) {
  22992. var ecModel = this._model;
  22993. var ecIns = this;
  22994. var api = this._api; // update before setOption
  22995. if (!ecModel) {
  22996. return;
  22997. } // ChartView.markUpdateMethod(payload, 'updateTransform');
  22998. var componentDirtyList = [];
  22999. ecModel.eachComponent(function (componentType, componentModel) {
  23000. var componentView = ecIns.getViewOfComponentModel(componentModel);
  23001. if (componentView && componentView.__alive) {
  23002. if (componentView.updateTransform) {
  23003. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  23004. result && result.update && componentDirtyList.push(componentView);
  23005. } else {
  23006. componentDirtyList.push(componentView);
  23007. }
  23008. }
  23009. });
  23010. var seriesDirtyMap = createHashMap();
  23011. ecModel.eachSeries(function (seriesModel) {
  23012. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  23013. if (chartView.updateTransform) {
  23014. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  23015. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  23016. } else {
  23017. seriesDirtyMap.set(seriesModel.uid, 1);
  23018. }
  23019. });
  23020. clearColorPalette(ecModel); // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  23021. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  23022. this._scheduler.performVisualTasks(ecModel, payload, {
  23023. setDirty: true,
  23024. dirtyMap: seriesDirtyMap
  23025. }); // Currently, not call render of components. Geo render cost a lot.
  23026. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  23027. renderSeries(ecIns, ecModel, api, payload, seriesDirtyMap);
  23028. performPostUpdateFuncs(ecModel, this._api);
  23029. },
  23030. /**
  23031. * @param {Object} payload
  23032. * @private
  23033. */
  23034. updateView: function (payload) {
  23035. var ecModel = this._model; // update before setOption
  23036. if (!ecModel) {
  23037. return;
  23038. }
  23039. Chart.markUpdateMethod(payload, 'updateView');
  23040. clearColorPalette(ecModel); // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  23041. this._scheduler.performVisualTasks(ecModel, payload, {
  23042. setDirty: true
  23043. });
  23044. render(this, this._model, this._api, payload);
  23045. performPostUpdateFuncs(ecModel, this._api);
  23046. },
  23047. /**
  23048. * @param {Object} payload
  23049. * @private
  23050. */
  23051. updateVisual: function (payload) {
  23052. updateMethods.update.call(this, payload); // var ecModel = this._model;
  23053. // // update before setOption
  23054. // if (!ecModel) {
  23055. // return;
  23056. // }
  23057. // ChartView.markUpdateMethod(payload, 'updateVisual');
  23058. // clearColorPalette(ecModel);
  23059. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  23060. // this._scheduler.performVisualTasks(ecModel, payload, {visualType: 'visual', setDirty: true});
  23061. // render(this, this._model, this._api, payload);
  23062. // performPostUpdateFuncs(ecModel, this._api);
  23063. },
  23064. /**
  23065. * @param {Object} payload
  23066. * @private
  23067. */
  23068. updateLayout: function (payload) {
  23069. updateMethods.update.call(this, payload); // var ecModel = this._model;
  23070. // // update before setOption
  23071. // if (!ecModel) {
  23072. // return;
  23073. // }
  23074. // ChartView.markUpdateMethod(payload, 'updateLayout');
  23075. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  23076. // // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  23077. // this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  23078. // render(this, this._model, this._api, payload);
  23079. // performPostUpdateFuncs(ecModel, this._api);
  23080. }
  23081. };
  23082. function prepare(ecIns) {
  23083. var ecModel = ecIns._model;
  23084. var scheduler = ecIns._scheduler;
  23085. scheduler.restorePipelines(ecModel);
  23086. scheduler.prepareStageTasks();
  23087. prepareView(ecIns, 'component', ecModel, scheduler);
  23088. prepareView(ecIns, 'chart', ecModel, scheduler);
  23089. scheduler.plan();
  23090. }
  23091. /**
  23092. * @private
  23093. */
  23094. function updateDirectly(ecIns, method, payload, mainType, subType) {
  23095. var ecModel = ecIns._model; // broadcast
  23096. if (!mainType) {
  23097. // FIXME
  23098. // Chart will not be update directly here, except set dirty.
  23099. // But there is no such scenario now.
  23100. each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
  23101. return;
  23102. }
  23103. var query = {};
  23104. query[mainType + 'Id'] = payload[mainType + 'Id'];
  23105. query[mainType + 'Index'] = payload[mainType + 'Index'];
  23106. query[mainType + 'Name'] = payload[mainType + 'Name'];
  23107. var condition = {
  23108. mainType: mainType,
  23109. query: query
  23110. };
  23111. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  23112. var excludeSeriesId = payload.excludeSeriesId;
  23113. if (excludeSeriesId != null) {
  23114. excludeSeriesId = createHashMap(normalizeToArray(excludeSeriesId));
  23115. } // If dispatchAction before setOption, do nothing.
  23116. ecModel && ecModel.eachComponent(condition, function (model) {
  23117. if (!excludeSeriesId || excludeSeriesId.get(model.id) == null) {
  23118. callView(ecIns[mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId]);
  23119. }
  23120. }, ecIns);
  23121. function callView(view) {
  23122. view && view.__alive && view[method] && view[method](view.__model, ecModel, ecIns._api, payload);
  23123. }
  23124. }
  23125. /**
  23126. * Resize the chart
  23127. * @param {Object} opts
  23128. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  23129. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  23130. * @param {boolean} [opts.silent=false]
  23131. */
  23132. echartsProto.resize = function (opts) {
  23133. if (this._disposed) {
  23134. return;
  23135. }
  23136. this._zr.resize(opts);
  23137. var ecModel = this._model; // Resize loading effect
  23138. this._loadingFX && this._loadingFX.resize();
  23139. if (!ecModel) {
  23140. return;
  23141. }
  23142. var optionChanged = ecModel.resetOption('media');
  23143. var silent = opts && opts.silent;
  23144. this[IN_MAIN_PROCESS] = true;
  23145. optionChanged && prepare(this);
  23146. updateMethods.update.call(this);
  23147. this[IN_MAIN_PROCESS] = false;
  23148. flushPendingActions.call(this, silent);
  23149. triggerUpdatedEvent.call(this, silent);
  23150. };
  23151. function updateStreamModes(ecIns, ecModel) {
  23152. var chartsMap = ecIns._chartsMap;
  23153. var scheduler = ecIns._scheduler;
  23154. ecModel.eachSeries(function (seriesModel) {
  23155. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  23156. });
  23157. }
  23158. /**
  23159. * Show loading effect
  23160. * @param {string} [name='default']
  23161. * @param {Object} [cfg]
  23162. */
  23163. echartsProto.showLoading = function (name, cfg) {
  23164. if (this._disposed) {
  23165. return;
  23166. }
  23167. if (isObject(name)) {
  23168. cfg = name;
  23169. name = '';
  23170. }
  23171. name = name || 'default';
  23172. this.hideLoading();
  23173. if (!loadingEffects[name]) {
  23174. return;
  23175. }
  23176. var el = loadingEffects[name](this._api, cfg);
  23177. var zr = this._zr;
  23178. this._loadingFX = el;
  23179. zr.add(el);
  23180. };
  23181. /**
  23182. * Hide loading effect
  23183. */
  23184. echartsProto.hideLoading = function () {
  23185. if (this._disposed) {
  23186. return;
  23187. }
  23188. this._loadingFX && this._zr.remove(this._loadingFX);
  23189. this._loadingFX = null;
  23190. };
  23191. /**
  23192. * @param {Object} eventObj
  23193. * @return {Object}
  23194. */
  23195. echartsProto.makeActionFromEvent = function (eventObj) {
  23196. var payload = extend({}, eventObj);
  23197. payload.type = eventActionMap[eventObj.type];
  23198. return payload;
  23199. };
  23200. /**
  23201. * @pubilc
  23202. * @param {Object} payload
  23203. * @param {string} [payload.type] Action type
  23204. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  23205. * @param {boolean} [opt.silent=false] Whether trigger events.
  23206. * @param {boolean} [opt.flush=undefined]
  23207. * true: Flush immediately, and then pixel in canvas can be fetched
  23208. * immediately. Caution: it might affect performance.
  23209. * false: Not flush.
  23210. * undefined: Auto decide whether perform flush.
  23211. */
  23212. echartsProto.dispatchAction = function (payload, opt) {
  23213. if (this._disposed) {
  23214. return;
  23215. }
  23216. if (!isObject(opt)) {
  23217. opt = {
  23218. silent: !!opt
  23219. };
  23220. }
  23221. if (!actions[payload.type]) {
  23222. return;
  23223. } // Avoid dispatch action before setOption. Especially in `connect`.
  23224. if (!this._model) {
  23225. return;
  23226. } // May dispatchAction in rendering procedure
  23227. if (this[IN_MAIN_PROCESS]) {
  23228. this._pendingActions.push(payload);
  23229. return;
  23230. }
  23231. doDispatchAction.call(this, payload, opt.silent);
  23232. if (opt.flush) {
  23233. this._zr.flush(true);
  23234. } else if (opt.flush !== false && env$1.browser.weChat) {
  23235. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  23236. // hang when sliding page (on touch event), which cause that zr does not
  23237. // refresh util user interaction finished, which is not expected.
  23238. // But `dispatchAction` may be called too frequently when pan on touch
  23239. // screen, which impacts performance if do not throttle them.
  23240. this._throttledZrFlush();
  23241. }
  23242. flushPendingActions.call(this, opt.silent);
  23243. triggerUpdatedEvent.call(this, opt.silent);
  23244. };
  23245. function doDispatchAction(payload, silent) {
  23246. var payloadType = payload.type;
  23247. var escapeConnect = payload.escapeConnect;
  23248. var actionWrap = actions[payloadType];
  23249. var actionInfo = actionWrap.actionInfo;
  23250. var cptType = (actionInfo.update || 'update').split(':');
  23251. var updateMethod = cptType.pop();
  23252. cptType = cptType[0] != null && parseClassType(cptType[0]);
  23253. this[IN_MAIN_PROCESS] = true;
  23254. var payloads = [payload];
  23255. var batched = false; // Batch action
  23256. if (payload.batch) {
  23257. batched = true;
  23258. payloads = map(payload.batch, function (item) {
  23259. item = defaults(extend({}, item), payload);
  23260. item.batch = null;
  23261. return item;
  23262. });
  23263. }
  23264. var eventObjBatch = [];
  23265. var eventObj;
  23266. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  23267. each(payloads, function (batchItem) {
  23268. // Action can specify the event by return it.
  23269. eventObj = actionWrap.action(batchItem, this._model, this._api); // Emit event outside
  23270. eventObj = eventObj || extend({}, batchItem); // Convert type to eventType
  23271. eventObj.type = actionInfo.event || eventObj.type;
  23272. eventObjBatch.push(eventObj); // light update does not perform data process, layout and visual.
  23273. if (isHighDown) {
  23274. // method, payload, mainType, subType
  23275. updateDirectly(this, updateMethod, batchItem, 'series');
  23276. } else if (cptType) {
  23277. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  23278. }
  23279. }, this);
  23280. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  23281. // Still dirty
  23282. if (this[OPTION_UPDATED]) {
  23283. // FIXME Pass payload ?
  23284. prepare(this);
  23285. updateMethods.update.call(this, payload);
  23286. this[OPTION_UPDATED] = false;
  23287. } else {
  23288. updateMethods[updateMethod].call(this, payload);
  23289. }
  23290. } // Follow the rule of action batch
  23291. if (batched) {
  23292. eventObj = {
  23293. type: actionInfo.event || payloadType,
  23294. escapeConnect: escapeConnect,
  23295. batch: eventObjBatch
  23296. };
  23297. } else {
  23298. eventObj = eventObjBatch[0];
  23299. }
  23300. this[IN_MAIN_PROCESS] = false;
  23301. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  23302. }
  23303. function flushPendingActions(silent) {
  23304. var pendingActions = this._pendingActions;
  23305. while (pendingActions.length) {
  23306. var payload = pendingActions.shift();
  23307. doDispatchAction.call(this, payload, silent);
  23308. }
  23309. }
  23310. function triggerUpdatedEvent(silent) {
  23311. !silent && this.trigger('updated');
  23312. }
  23313. /**
  23314. * Event `rendered` is triggered when zr
  23315. * rendered. It is useful for realtime
  23316. * snapshot (reflect animation).
  23317. *
  23318. * Event `finished` is triggered when:
  23319. * (1) zrender rendering finished.
  23320. * (2) initial animation finished.
  23321. * (3) progressive rendering finished.
  23322. * (4) no pending action.
  23323. * (5) no delayed setOption needs to be processed.
  23324. */
  23325. function bindRenderedEvent(zr, ecIns) {
  23326. zr.on('rendered', function () {
  23327. ecIns.trigger('rendered'); // The `finished` event should not be triggered repeatly,
  23328. // so it should only be triggered when rendering indeed happend
  23329. // in zrender. (Consider the case that dipatchAction is keep
  23330. // triggering when mouse move).
  23331. if ( // Although zr is dirty if initial animation is not finished
  23332. // and this checking is called on frame, we also check
  23333. // animation finished for robustness.
  23334. zr.animation.isFinished() && !ecIns[OPTION_UPDATED] && !ecIns._scheduler.unfinished && !ecIns._pendingActions.length) {
  23335. ecIns.trigger('finished');
  23336. }
  23337. });
  23338. }
  23339. /**
  23340. * @param {Object} params
  23341. * @param {number} params.seriesIndex
  23342. * @param {Array|TypedArray} params.data
  23343. */
  23344. echartsProto.appendData = function (params) {
  23345. if (this._disposed) {
  23346. return;
  23347. }
  23348. var seriesIndex = params.seriesIndex;
  23349. var ecModel = this.getModel();
  23350. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  23351. seriesModel.appendData(params); // Note: `appendData` does not support that update extent of coordinate
  23352. // system, util some scenario require that. In the expected usage of
  23353. // `appendData`, the initial extent of coordinate system should better
  23354. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  23355. // the extent changed while `appendData`, the location of the painted
  23356. // graphic elements have to be changed, which make the usage of
  23357. // `appendData` meaningless.
  23358. this._scheduler.unfinished = true;
  23359. };
  23360. /**
  23361. * Register event
  23362. * @method
  23363. */
  23364. echartsProto.on = createRegisterEventWithLowercaseName('on', false);
  23365. echartsProto.off = createRegisterEventWithLowercaseName('off', false);
  23366. echartsProto.one = createRegisterEventWithLowercaseName('one', false);
  23367. /**
  23368. * Prepare view instances of charts and components
  23369. * @param {module:echarts/model/Global} ecModel
  23370. * @private
  23371. */
  23372. function prepareView(ecIns, type, ecModel, scheduler) {
  23373. var isComponent = type === 'component';
  23374. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  23375. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  23376. var zr = ecIns._zr;
  23377. var api = ecIns._api;
  23378. for (var i = 0; i < viewList.length; i++) {
  23379. viewList[i].__alive = false;
  23380. }
  23381. isComponent ? ecModel.eachComponent(function (componentType, model) {
  23382. componentType !== 'series' && doPrepare(model);
  23383. }) : ecModel.eachSeries(doPrepare);
  23384. function doPrepare(model) {
  23385. // Consider: id same and type changed.
  23386. var viewId = '_ec_' + model.id + '_' + model.type;
  23387. var view = viewMap[viewId];
  23388. if (!view) {
  23389. var classType = parseClassType(model.type);
  23390. var Clazz = isComponent ? Component$1.getClass(classType.main, classType.sub) : Chart.getClass(classType.sub);
  23391. view = new Clazz();
  23392. view.init(ecModel, api);
  23393. viewMap[viewId] = view;
  23394. viewList.push(view);
  23395. zr.add(view.group);
  23396. }
  23397. model.__viewId = view.__id = viewId;
  23398. view.__alive = true;
  23399. view.__model = model;
  23400. view.group.__ecComponentInfo = {
  23401. mainType: model.mainType,
  23402. index: model.componentIndex
  23403. };
  23404. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  23405. }
  23406. for (var i = 0; i < viewList.length;) {
  23407. var view = viewList[i];
  23408. if (!view.__alive) {
  23409. !isComponent && view.renderTask.dispose();
  23410. zr.remove(view.group);
  23411. view.dispose(ecModel, api);
  23412. viewList.splice(i, 1);
  23413. delete viewMap[view.__id];
  23414. view.__id = view.group.__ecComponentInfo = null;
  23415. } else {
  23416. i++;
  23417. }
  23418. }
  23419. } // /**
  23420. // * Encode visual infomation from data after data processing
  23421. // *
  23422. // * @param {module:echarts/model/Global} ecModel
  23423. // * @param {object} layout
  23424. // * @param {boolean} [layoutFilter] `true`: only layout,
  23425. // * `false`: only not layout,
  23426. // * `null`/`undefined`: all.
  23427. // * @param {string} taskBaseTag
  23428. // * @private
  23429. // */
  23430. // function startVisualEncoding(ecIns, ecModel, api, payload, layoutFilter) {
  23431. // each(visualFuncs, function (visual, index) {
  23432. // var isLayout = visual.isLayout;
  23433. // if (layoutFilter == null
  23434. // || (layoutFilter === false && !isLayout)
  23435. // || (layoutFilter === true && isLayout)
  23436. // ) {
  23437. // visual.func(ecModel, api, payload);
  23438. // }
  23439. // });
  23440. // }
  23441. function clearColorPalette(ecModel) {
  23442. ecModel.clearColorPalette();
  23443. ecModel.eachSeries(function (seriesModel) {
  23444. seriesModel.clearColorPalette();
  23445. });
  23446. }
  23447. function render(ecIns, ecModel, api, payload) {
  23448. renderComponents(ecIns, ecModel, api, payload);
  23449. each(ecIns._chartsViews, function (chart) {
  23450. chart.__alive = false;
  23451. });
  23452. renderSeries(ecIns, ecModel, api, payload); // Remove groups of unrendered charts
  23453. each(ecIns._chartsViews, function (chart) {
  23454. if (!chart.__alive) {
  23455. chart.remove(ecModel, api);
  23456. }
  23457. });
  23458. }
  23459. function renderComponents(ecIns, ecModel, api, payload, dirtyList) {
  23460. each(dirtyList || ecIns._componentsViews, function (componentView) {
  23461. var componentModel = componentView.__model;
  23462. componentView.render(componentModel, ecModel, api, payload);
  23463. updateZ(componentModel, componentView);
  23464. });
  23465. }
  23466. /**
  23467. * Render each chart and component
  23468. * @private
  23469. */
  23470. function renderSeries(ecIns, ecModel, api, payload, dirtyMap) {
  23471. // Render all charts
  23472. var scheduler = ecIns._scheduler;
  23473. var unfinished;
  23474. ecModel.eachSeries(function (seriesModel) {
  23475. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  23476. chartView.__alive = true;
  23477. var renderTask = chartView.renderTask;
  23478. scheduler.updatePayload(renderTask, payload);
  23479. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  23480. renderTask.dirty();
  23481. }
  23482. unfinished |= renderTask.perform(scheduler.getPerformArgs(renderTask));
  23483. chartView.group.silent = !!seriesModel.get('silent');
  23484. updateZ(seriesModel, chartView);
  23485. updateBlend(seriesModel, chartView);
  23486. });
  23487. scheduler.unfinished |= unfinished; // If use hover layer
  23488. updateHoverLayerStatus(ecIns, ecModel); // Add aria
  23489. aria(ecIns._zr.dom, ecModel);
  23490. }
  23491. function performPostUpdateFuncs(ecModel, api) {
  23492. each(postUpdateFuncs, function (func) {
  23493. func(ecModel, api);
  23494. });
  23495. }
  23496. var MOUSE_EVENT_NAMES = ['click', 'dblclick', 'mouseover', 'mouseout', 'mousemove', 'mousedown', 'mouseup', 'globalout', 'contextmenu'];
  23497. /**
  23498. * @private
  23499. */
  23500. echartsProto._initEvents = function () {
  23501. each(MOUSE_EVENT_NAMES, function (eveName) {
  23502. var handler = function (e) {
  23503. var ecModel = this.getModel();
  23504. var el = e.target;
  23505. var params;
  23506. var isGlobalOut = eveName === 'globalout'; // no e.target when 'globalout'.
  23507. if (isGlobalOut) {
  23508. params = {};
  23509. } else if (el && el.dataIndex != null) {
  23510. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  23511. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType, el) || {};
  23512. } // If element has custom eventData of components
  23513. else if (el && el.eventData) {
  23514. params = extend({}, el.eventData);
  23515. } // Contract: if params prepared in mouse event,
  23516. // these properties must be specified:
  23517. // {
  23518. // componentType: string (component main type)
  23519. // componentIndex: number
  23520. // }
  23521. // Otherwise event query can not work.
  23522. if (params) {
  23523. var componentType = params.componentType;
  23524. var componentIndex = params.componentIndex; // Special handling for historic reason: when trigger by
  23525. // markLine/markPoint/markArea, the componentType is
  23526. // 'markLine'/'markPoint'/'markArea', but we should better
  23527. // enable them to be queried by seriesIndex, since their
  23528. // option is set in each series.
  23529. if (componentType === 'markLine' || componentType === 'markPoint' || componentType === 'markArea') {
  23530. componentType = 'series';
  23531. componentIndex = params.seriesIndex;
  23532. }
  23533. var model = componentType && componentIndex != null && ecModel.getComponent(componentType, componentIndex);
  23534. var view = model && this[model.mainType === 'series' ? '_chartsMap' : '_componentsMap'][model.__viewId];
  23535. params.event = e;
  23536. params.type = eveName;
  23537. this._ecEventProcessor.eventInfo = {
  23538. targetEl: el,
  23539. packedEvent: params,
  23540. model: model,
  23541. view: view
  23542. };
  23543. this.trigger(eveName, params);
  23544. }
  23545. }; // Consider that some component (like tooltip, brush, ...)
  23546. // register zr event handler, but user event handler might
  23547. // do anything, such as call `setOption` or `dispatchAction`,
  23548. // which probably update any of the content and probably
  23549. // cause problem if it is called previous other inner handlers.
  23550. handler.zrEventfulCallAtLast = true;
  23551. this._zr.on(eveName, handler, this);
  23552. }, this);
  23553. each(eventActionMap, function (actionType, eventType) {
  23554. this._messageCenter.on(eventType, function (event) {
  23555. this.trigger(eventType, event);
  23556. }, this);
  23557. }, this);
  23558. };
  23559. /**
  23560. * @return {boolean}
  23561. */
  23562. echartsProto.isDisposed = function () {
  23563. return this._disposed;
  23564. };
  23565. /**
  23566. * Clear
  23567. */
  23568. echartsProto.clear = function () {
  23569. if (this._disposed) {
  23570. return;
  23571. }
  23572. this.setOption({
  23573. series: []
  23574. }, true);
  23575. };
  23576. /**
  23577. * Dispose instance
  23578. */
  23579. echartsProto.dispose = function () {
  23580. if (this._disposed) {
  23581. return;
  23582. }
  23583. this._disposed = true;
  23584. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  23585. var api = this._api;
  23586. var ecModel = this._model;
  23587. each(this._componentsViews, function (component) {
  23588. component.dispose(ecModel, api);
  23589. });
  23590. each(this._chartsViews, function (chart) {
  23591. chart.dispose(ecModel, api);
  23592. }); // Dispose after all views disposed
  23593. this._zr.dispose();
  23594. delete instances[this.id];
  23595. };
  23596. mixin(ECharts, Eventful);
  23597. function updateHoverLayerStatus(ecIns, ecModel) {
  23598. var zr = ecIns._zr;
  23599. var storage = zr.storage;
  23600. var elCount = 0;
  23601. storage.traverse(function (el) {
  23602. elCount++;
  23603. });
  23604. if (elCount > ecModel.get('hoverLayerThreshold') && !env$1.node) {
  23605. ecModel.eachSeries(function (seriesModel) {
  23606. if (seriesModel.preventUsingHoverLayer) {
  23607. return;
  23608. }
  23609. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  23610. if (chartView.__alive) {
  23611. chartView.group.traverse(function (el) {
  23612. // Don't switch back.
  23613. el.useHoverLayer = true;
  23614. });
  23615. }
  23616. });
  23617. }
  23618. }
  23619. /**
  23620. * Update chart progressive and blend.
  23621. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  23622. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  23623. */
  23624. function updateBlend(seriesModel, chartView) {
  23625. var blendMode = seriesModel.get('blendMode') || null;
  23626. chartView.group.traverse(function (el) {
  23627. // FIXME marker and other components
  23628. if (!el.isGroup) {
  23629. // Only set if blendMode is changed. In case element is incremental and don't wan't to rerender.
  23630. if (el.style.blend !== blendMode) {
  23631. el.setStyle('blend', blendMode);
  23632. }
  23633. }
  23634. if (el.eachPendingDisplayable) {
  23635. el.eachPendingDisplayable(function (displayable) {
  23636. displayable.setStyle('blend', blendMode);
  23637. });
  23638. }
  23639. });
  23640. }
  23641. /**
  23642. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  23643. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  23644. */
  23645. function updateZ(model, view) {
  23646. var z = model.get('z');
  23647. var zlevel = model.get('zlevel'); // Set z and zlevel
  23648. view.group.traverse(function (el) {
  23649. if (el.type !== 'group') {
  23650. z != null && (el.z = z);
  23651. zlevel != null && (el.zlevel = zlevel);
  23652. }
  23653. });
  23654. }
  23655. function createExtensionAPI(ecInstance) {
  23656. var coordSysMgr = ecInstance._coordSysMgr;
  23657. return extend(new ExtensionAPI(ecInstance), {
  23658. // Inject methods
  23659. getCoordinateSystems: bind(coordSysMgr.getCoordinateSystems, coordSysMgr),
  23660. getComponentByElement: function (el) {
  23661. while (el) {
  23662. var modelInfo = el.__ecComponentInfo;
  23663. if (modelInfo != null) {
  23664. return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
  23665. }
  23666. el = el.parent;
  23667. }
  23668. }
  23669. });
  23670. }
  23671. /**
  23672. * @class
  23673. * Usage of query:
  23674. * `chart.on('click', query, handler);`
  23675. * The `query` can be:
  23676. * + The component type query string, only `mainType` or `mainType.subType`,
  23677. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  23678. * + The component query object, like:
  23679. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  23680. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  23681. * + The data query object, like:
  23682. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  23683. * + The other query object (cmponent customized query), like:
  23684. * `{element: 'some'}` (only available in custom series).
  23685. *
  23686. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  23687. * same as there is no such prop in the `query` object.
  23688. */
  23689. function EventProcessor() {
  23690. // These info required: targetEl, packedEvent, model, view
  23691. this.eventInfo;
  23692. }
  23693. EventProcessor.prototype = {
  23694. constructor: EventProcessor,
  23695. normalizeQuery: function (query) {
  23696. var cptQuery = {};
  23697. var dataQuery = {};
  23698. var otherQuery = {}; // `query` is `mainType` or `mainType.subType` of component.
  23699. if (isString(query)) {
  23700. var condCptType = parseClassType(query); // `.main` and `.sub` may be ''.
  23701. cptQuery.mainType = condCptType.main || null;
  23702. cptQuery.subType = condCptType.sub || null;
  23703. } // `query` is an object, convert to {mainType, index, name, id}.
  23704. else {
  23705. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  23706. // can not be used in `compomentModel.filterForExposedEvent`.
  23707. var suffixes = ['Index', 'Name', 'Id'];
  23708. var dataKeys = {
  23709. name: 1,
  23710. dataIndex: 1,
  23711. dataType: 1
  23712. };
  23713. each$1(query, function (val, key) {
  23714. var reserved = false;
  23715. for (var i = 0; i < suffixes.length; i++) {
  23716. var propSuffix = suffixes[i];
  23717. var suffixPos = key.lastIndexOf(propSuffix);
  23718. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  23719. var mainType = key.slice(0, suffixPos); // Consider `dataIndex`.
  23720. if (mainType !== 'data') {
  23721. cptQuery.mainType = mainType;
  23722. cptQuery[propSuffix.toLowerCase()] = val;
  23723. reserved = true;
  23724. }
  23725. }
  23726. }
  23727. if (dataKeys.hasOwnProperty(key)) {
  23728. dataQuery[key] = val;
  23729. reserved = true;
  23730. }
  23731. if (!reserved) {
  23732. otherQuery[key] = val;
  23733. }
  23734. });
  23735. }
  23736. return {
  23737. cptQuery: cptQuery,
  23738. dataQuery: dataQuery,
  23739. otherQuery: otherQuery
  23740. };
  23741. },
  23742. filter: function (eventType, query, args) {
  23743. // They should be assigned before each trigger call.
  23744. var eventInfo = this.eventInfo;
  23745. if (!eventInfo) {
  23746. return true;
  23747. }
  23748. var targetEl = eventInfo.targetEl;
  23749. var packedEvent = eventInfo.packedEvent;
  23750. var model = eventInfo.model;
  23751. var view = eventInfo.view; // For event like 'globalout'.
  23752. if (!model || !view) {
  23753. return true;
  23754. }
  23755. var cptQuery = query.cptQuery;
  23756. var dataQuery = query.dataQuery;
  23757. 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));
  23758. function check(query, host, prop, propOnHost) {
  23759. return query[prop] == null || host[propOnHost || prop] === query[prop];
  23760. }
  23761. },
  23762. afterTrigger: function () {
  23763. // Make sure the eventInfo wont be used in next trigger.
  23764. this.eventInfo = null;
  23765. }
  23766. };
  23767. /**
  23768. * @type {Object} key: actionType.
  23769. * @inner
  23770. */
  23771. var actions = {};
  23772. /**
  23773. * Map eventType to actionType
  23774. * @type {Object}
  23775. */
  23776. var eventActionMap = {};
  23777. /**
  23778. * Data processor functions of each stage
  23779. * @type {Array.<Object.<string, Function>>}
  23780. * @inner
  23781. */
  23782. var dataProcessorFuncs = [];
  23783. /**
  23784. * @type {Array.<Function>}
  23785. * @inner
  23786. */
  23787. var optionPreprocessorFuncs = [];
  23788. /**
  23789. * @type {Array.<Function>}
  23790. * @inner
  23791. */
  23792. var postUpdateFuncs = [];
  23793. /**
  23794. * Visual encoding functions of each stage
  23795. * @type {Array.<Object.<string, Function>>}
  23796. */
  23797. var visualFuncs = [];
  23798. /**
  23799. * Theme storage
  23800. * @type {Object.<key, Object>}
  23801. */
  23802. var themeStorage = {};
  23803. /**
  23804. * Loading effects
  23805. */
  23806. var loadingEffects = {};
  23807. var instances = {};
  23808. var connectedGroups = {};
  23809. var idBase = new Date() - 0;
  23810. var groupIdBase = new Date() - 0;
  23811. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  23812. function enableConnect(chart) {
  23813. var STATUS_PENDING = 0;
  23814. var STATUS_UPDATING = 1;
  23815. var STATUS_UPDATED = 2;
  23816. var STATUS_KEY = '__connectUpdateStatus';
  23817. function updateConnectedChartsStatus(charts, status) {
  23818. for (var i = 0; i < charts.length; i++) {
  23819. var otherChart = charts[i];
  23820. otherChart[STATUS_KEY] = status;
  23821. }
  23822. }
  23823. each(eventActionMap, function (actionType, eventType) {
  23824. chart._messageCenter.on(eventType, function (event) {
  23825. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  23826. if (event && event.escapeConnect) {
  23827. return;
  23828. }
  23829. var action = chart.makeActionFromEvent(event);
  23830. var otherCharts = [];
  23831. each(instances, function (otherChart) {
  23832. if (otherChart !== chart && otherChart.group === chart.group) {
  23833. otherCharts.push(otherChart);
  23834. }
  23835. });
  23836. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  23837. each(otherCharts, function (otherChart) {
  23838. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  23839. otherChart.dispatchAction(action);
  23840. }
  23841. });
  23842. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  23843. }
  23844. });
  23845. });
  23846. }
  23847. /**
  23848. * @param {HTMLElement} dom
  23849. * @param {Object} [theme]
  23850. * @param {Object} opts
  23851. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  23852. * @param {string} [opts.renderer] Can choose 'canvas' or 'svg' to render the chart.
  23853. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  23854. * Can be 'auto' (the same as null/undefined)
  23855. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  23856. * Can be 'auto' (the same as null/undefined)
  23857. */
  23858. function init(dom, theme$$1, opts) {
  23859. var existInstance = getInstanceByDom(dom);
  23860. if (existInstance) {
  23861. return existInstance;
  23862. }
  23863. var chart = new ECharts(dom, theme$$1, opts);
  23864. chart.id = 'ec_' + idBase++;
  23865. instances[chart.id] = chart;
  23866. setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  23867. enableConnect(chart);
  23868. return chart;
  23869. }
  23870. /**
  23871. * @return {string|Array.<module:echarts~ECharts>} groupId
  23872. */
  23873. function connect(groupId) {
  23874. // Is array of charts
  23875. if (isArray(groupId)) {
  23876. var charts = groupId;
  23877. groupId = null; // If any chart has group
  23878. each(charts, function (chart) {
  23879. if (chart.group != null) {
  23880. groupId = chart.group;
  23881. }
  23882. });
  23883. groupId = groupId || 'g_' + groupIdBase++;
  23884. each(charts, function (chart) {
  23885. chart.group = groupId;
  23886. });
  23887. }
  23888. connectedGroups[groupId] = true;
  23889. return groupId;
  23890. }
  23891. /**
  23892. * @DEPRECATED
  23893. * @return {string} groupId
  23894. */
  23895. function disConnect(groupId) {
  23896. connectedGroups[groupId] = false;
  23897. }
  23898. /**
  23899. * @return {string} groupId
  23900. */
  23901. var disconnect = disConnect;
  23902. /**
  23903. * Dispose a chart instance
  23904. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  23905. */
  23906. function dispose(chart) {
  23907. if (typeof chart === 'string') {
  23908. chart = instances[chart];
  23909. } else if (!(chart instanceof ECharts)) {
  23910. // Try to treat as dom
  23911. chart = getInstanceByDom(chart);
  23912. }
  23913. if (chart instanceof ECharts && !chart.isDisposed()) {
  23914. chart.dispose();
  23915. }
  23916. }
  23917. /**
  23918. * @param {HTMLElement} dom
  23919. * @return {echarts~ECharts}
  23920. */
  23921. function getInstanceByDom(dom) {
  23922. return instances[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  23923. }
  23924. /**
  23925. * @param {string} key
  23926. * @return {echarts~ECharts}
  23927. */
  23928. function getInstanceById(key) {
  23929. return instances[key];
  23930. }
  23931. /**
  23932. * Register theme
  23933. */
  23934. function registerTheme(name, theme$$1) {
  23935. themeStorage[name] = theme$$1;
  23936. }
  23937. /**
  23938. * Register option preprocessor
  23939. * @param {Function} preprocessorFunc
  23940. */
  23941. function registerPreprocessor(preprocessorFunc) {
  23942. optionPreprocessorFuncs.push(preprocessorFunc);
  23943. }
  23944. /**
  23945. * @param {number} [priority=1000]
  23946. * @param {Object|Function} processor
  23947. */
  23948. function registerProcessor(priority, processor) {
  23949. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_FILTER);
  23950. }
  23951. /**
  23952. * Register postUpdater
  23953. * @param {Function} postUpdateFunc
  23954. */
  23955. function registerPostUpdate(postUpdateFunc) {
  23956. postUpdateFuncs.push(postUpdateFunc);
  23957. }
  23958. /**
  23959. * Usage:
  23960. * registerAction('someAction', 'someEvent', function () { ... });
  23961. * registerAction('someAction', function () { ... });
  23962. * registerAction(
  23963. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  23964. * function () { ... }
  23965. * );
  23966. *
  23967. * @param {(string|Object)} actionInfo
  23968. * @param {string} actionInfo.type
  23969. * @param {string} [actionInfo.event]
  23970. * @param {string} [actionInfo.update]
  23971. * @param {string} [eventName]
  23972. * @param {Function} action
  23973. */
  23974. function registerAction(actionInfo, eventName, action) {
  23975. if (typeof eventName === 'function') {
  23976. action = eventName;
  23977. eventName = '';
  23978. }
  23979. var actionType = isObject(actionInfo) ? actionInfo.type : [actionInfo, actionInfo = {
  23980. event: eventName
  23981. }][0]; // Event name is all lowercase
  23982. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  23983. eventName = actionInfo.event; // Validate action type and event name.
  23984. assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  23985. if (!actions[actionType]) {
  23986. actions[actionType] = {
  23987. action: action,
  23988. actionInfo: actionInfo
  23989. };
  23990. }
  23991. eventActionMap[eventName] = actionType;
  23992. }
  23993. /**
  23994. * @param {string} type
  23995. * @param {*} CoordinateSystem
  23996. */
  23997. function registerCoordinateSystem(type, CoordinateSystem$$1) {
  23998. CoordinateSystemManager.register(type, CoordinateSystem$$1);
  23999. }
  24000. /**
  24001. * Get dimensions of specified coordinate system.
  24002. * @param {string} type
  24003. * @return {Array.<string|Object>}
  24004. */
  24005. function getCoordinateSystemDimensions(type) {
  24006. var coordSysCreator = CoordinateSystemManager.get(type);
  24007. if (coordSysCreator) {
  24008. return coordSysCreator.getDimensionsInfo ? coordSysCreator.getDimensionsInfo() : coordSysCreator.dimensions.slice();
  24009. }
  24010. }
  24011. /**
  24012. * Layout is a special stage of visual encoding
  24013. * Most visual encoding like color are common for different chart
  24014. * But each chart has it's own layout algorithm
  24015. *
  24016. * @param {number} [priority=1000]
  24017. * @param {Function} layoutTask
  24018. */
  24019. function registerLayout(priority, layoutTask) {
  24020. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  24021. }
  24022. /**
  24023. * @param {number} [priority=3000]
  24024. * @param {module:echarts/stream/Task} visualTask
  24025. */
  24026. function registerVisual(priority, visualTask) {
  24027. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  24028. }
  24029. /**
  24030. * @param {Object|Function} fn: {seriesType, createOnAllSeries, performRawSeries, reset}
  24031. */
  24032. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  24033. if (isFunction(priority) || isObject(priority)) {
  24034. fn = priority;
  24035. priority = defaultPriority;
  24036. }
  24037. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  24038. stageHandler.__prio = priority;
  24039. stageHandler.__raw = fn;
  24040. targetList.push(stageHandler);
  24041. return stageHandler;
  24042. }
  24043. /**
  24044. * @param {string} name
  24045. */
  24046. function registerLoading(name, loadingFx) {
  24047. loadingEffects[name] = loadingFx;
  24048. }
  24049. /**
  24050. * @param {Object} opts
  24051. * @param {string} [superClass]
  24052. */
  24053. function extendComponentModel(opts
  24054. /*, superClass*/
  24055. ) {
  24056. // var Clazz = ComponentModel;
  24057. // if (superClass) {
  24058. // var classType = parseClassType(superClass);
  24059. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  24060. // }
  24061. return ComponentModel.extend(opts);
  24062. }
  24063. /**
  24064. * @param {Object} opts
  24065. * @param {string} [superClass]
  24066. */
  24067. function extendComponentView(opts
  24068. /*, superClass*/
  24069. ) {
  24070. // var Clazz = ComponentView;
  24071. // if (superClass) {
  24072. // var classType = parseClassType(superClass);
  24073. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  24074. // }
  24075. return Component$1.extend(opts);
  24076. }
  24077. /**
  24078. * @param {Object} opts
  24079. * @param {string} [superClass]
  24080. */
  24081. function extendSeriesModel(opts
  24082. /*, superClass*/
  24083. ) {
  24084. // var Clazz = SeriesModel;
  24085. // if (superClass) {
  24086. // superClass = 'series.' + superClass.replace('series.', '');
  24087. // var classType = parseClassType(superClass);
  24088. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  24089. // }
  24090. return SeriesModel.extend(opts);
  24091. }
  24092. /**
  24093. * @param {Object} opts
  24094. * @param {string} [superClass]
  24095. */
  24096. function extendChartView(opts
  24097. /*, superClass*/
  24098. ) {
  24099. // var Clazz = ChartView;
  24100. // if (superClass) {
  24101. // superClass = superClass.replace('series.', '');
  24102. // var classType = parseClassType(superClass);
  24103. // Clazz = ChartView.getClass(classType.main, true);
  24104. // }
  24105. return Chart.extend(opts);
  24106. }
  24107. /**
  24108. * ZRender need a canvas context to do measureText.
  24109. * But in node environment canvas may be created by node-canvas.
  24110. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  24111. *
  24112. * Be careful of using it in the browser.
  24113. *
  24114. * @param {Function} creator
  24115. * @example
  24116. * var Canvas = require('canvas');
  24117. * var echarts = require('echarts');
  24118. * echarts.setCanvasCreator(function () {
  24119. * // Small size is enough.
  24120. * return new Canvas(32, 32);
  24121. * });
  24122. */
  24123. function setCanvasCreator(creator) {
  24124. $override('createCanvas', creator);
  24125. }
  24126. /**
  24127. * @param {string} mapName
  24128. * @param {Array.<Object>|Object|string} geoJson
  24129. * @param {Object} [specialAreas]
  24130. *
  24131. * @example GeoJSON
  24132. * $.get('USA.json', function (geoJson) {
  24133. * echarts.registerMap('USA', geoJson);
  24134. * // Or
  24135. * echarts.registerMap('USA', {
  24136. * geoJson: geoJson,
  24137. * specialAreas: {}
  24138. * })
  24139. * });
  24140. *
  24141. * $.get('airport.svg', function (svg) {
  24142. * echarts.registerMap('airport', {
  24143. * svg: svg
  24144. * }
  24145. * });
  24146. *
  24147. * echarts.registerMap('eu', [
  24148. * {svg: eu-topographic.svg},
  24149. * {geoJSON: eu.json}
  24150. * ])
  24151. */
  24152. function registerMap(mapName, geoJson, specialAreas) {
  24153. mapDataStorage.registerMap(mapName, geoJson, specialAreas);
  24154. }
  24155. /**
  24156. * @param {string} mapName
  24157. * @return {Object}
  24158. */
  24159. function getMap(mapName) {
  24160. // For backward compatibility, only return the first one.
  24161. var records = mapDataStorage.retrieveMap(mapName);
  24162. return records && records[0] && {
  24163. geoJson: records[0].geoJSON,
  24164. specialAreas: records[0].specialAreas
  24165. };
  24166. }
  24167. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);
  24168. registerPreprocessor(backwardCompat);
  24169. registerProcessor(PRIORITY_PROCESSOR_DATASTACK, dataStack);
  24170. registerLoading('default', loadingDefault); // Default actions
  24171. registerAction({
  24172. type: 'highlight',
  24173. event: 'highlight',
  24174. update: 'highlight'
  24175. }, noop);
  24176. registerAction({
  24177. type: 'downplay',
  24178. event: 'downplay',
  24179. update: 'downplay'
  24180. }, noop); // Default theme
  24181. registerTheme('light', lightTheme);
  24182. registerTheme('dark', theme); // For backward compatibility, where the namespace `dataTool` will
  24183. // be mounted on `echarts` is the extension `dataTool` is imported.
  24184. var dataTool = {};
  24185. /*
  24186. * Licensed to the Apache Software Foundation (ASF) under one
  24187. * or more contributor license agreements. See the NOTICE file
  24188. * distributed with this work for additional information
  24189. * regarding copyright ownership. The ASF licenses this file
  24190. * to you under the Apache License, Version 2.0 (the
  24191. * "License"); you may not use this file except in compliance
  24192. * with the License. You may obtain a copy of the License at
  24193. *
  24194. * http://www.apache.org/licenses/LICENSE-2.0
  24195. *
  24196. * Unless required by applicable law or agreed to in writing,
  24197. * software distributed under the License is distributed on an
  24198. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24199. * KIND, either express or implied. See the License for the
  24200. * specific language governing permissions and limitations
  24201. * under the License.
  24202. */
  24203. function defaultKeyGetter(item) {
  24204. return item;
  24205. }
  24206. /**
  24207. * @param {Array} oldArr
  24208. * @param {Array} newArr
  24209. * @param {Function} oldKeyGetter
  24210. * @param {Function} newKeyGetter
  24211. * @param {Object} [context] Can be visited by this.context in callback.
  24212. */
  24213. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {
  24214. this._old = oldArr;
  24215. this._new = newArr;
  24216. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  24217. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  24218. this.context = context;
  24219. }
  24220. DataDiffer.prototype = {
  24221. constructor: DataDiffer,
  24222. /**
  24223. * Callback function when add a data
  24224. */
  24225. add: function (func) {
  24226. this._add = func;
  24227. return this;
  24228. },
  24229. /**
  24230. * Callback function when update a data
  24231. */
  24232. update: function (func) {
  24233. this._update = func;
  24234. return this;
  24235. },
  24236. /**
  24237. * Callback function when remove a data
  24238. */
  24239. remove: function (func) {
  24240. this._remove = func;
  24241. return this;
  24242. },
  24243. execute: function () {
  24244. var oldArr = this._old;
  24245. var newArr = this._new;
  24246. var oldDataIndexMap = {};
  24247. var newDataIndexMap = {};
  24248. var oldDataKeyArr = [];
  24249. var newDataKeyArr = [];
  24250. var i;
  24251. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);
  24252. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);
  24253. for (i = 0; i < oldArr.length; i++) {
  24254. var key = oldDataKeyArr[i];
  24255. var idx = newDataIndexMap[key]; // idx can never be empty array here. see 'set null' logic below.
  24256. if (idx != null) {
  24257. // Consider there is duplicate key (for example, use dataItem.name as key).
  24258. // We should make sure every item in newArr and oldArr can be visited.
  24259. var len = idx.length;
  24260. if (len) {
  24261. len === 1 && (newDataIndexMap[key] = null);
  24262. idx = idx.shift();
  24263. } else {
  24264. newDataIndexMap[key] = null;
  24265. }
  24266. this._update && this._update(idx, i);
  24267. } else {
  24268. this._remove && this._remove(i);
  24269. }
  24270. }
  24271. for (var i = 0; i < newDataKeyArr.length; i++) {
  24272. var key = newDataKeyArr[i];
  24273. if (newDataIndexMap.hasOwnProperty(key)) {
  24274. var idx = newDataIndexMap[key];
  24275. if (idx == null) {
  24276. continue;
  24277. } // idx can never be empty array here. see 'set null' logic above.
  24278. if (!idx.length) {
  24279. this._add && this._add(idx);
  24280. } else {
  24281. for (var j = 0, len = idx.length; j < len; j++) {
  24282. this._add && this._add(idx[j]);
  24283. }
  24284. }
  24285. }
  24286. }
  24287. }
  24288. };
  24289. function initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {
  24290. for (var i = 0; i < arr.length; i++) {
  24291. // Add prefix to avoid conflict with Object.prototype.
  24292. var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);
  24293. var existence = map[key];
  24294. if (existence == null) {
  24295. keyArr.push(key);
  24296. map[key] = i;
  24297. } else {
  24298. if (!existence.length) {
  24299. map[key] = existence = [existence];
  24300. }
  24301. existence.push(i);
  24302. }
  24303. }
  24304. }
  24305. /*
  24306. * Licensed to the Apache Software Foundation (ASF) under one
  24307. * or more contributor license agreements. See the NOTICE file
  24308. * distributed with this work for additional information
  24309. * regarding copyright ownership. The ASF licenses this file
  24310. * to you under the Apache License, Version 2.0 (the
  24311. * "License"); you may not use this file except in compliance
  24312. * with the License. You may obtain a copy of the License at
  24313. *
  24314. * http://www.apache.org/licenses/LICENSE-2.0
  24315. *
  24316. * Unless required by applicable law or agreed to in writing,
  24317. * software distributed under the License is distributed on an
  24318. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24319. * KIND, either express or implied. See the License for the
  24320. * specific language governing permissions and limitations
  24321. * under the License.
  24322. */
  24323. var OTHER_DIMENSIONS = createHashMap(['tooltip', 'label', 'itemName', 'itemId', 'seriesName']);
  24324. function summarizeDimensions(data) {
  24325. var summary = {};
  24326. var encode = summary.encode = {};
  24327. var notExtraCoordDimMap = createHashMap();
  24328. var defaultedLabel = [];
  24329. var defaultedTooltip = []; // See the comment of `List.js#userOutput`.
  24330. var userOutput = summary.userOutput = {
  24331. dimensionNames: data.dimensions.slice(),
  24332. encode: {}
  24333. };
  24334. each$1(data.dimensions, function (dimName) {
  24335. var dimItem = data.getDimensionInfo(dimName);
  24336. var coordDim = dimItem.coordDim;
  24337. if (coordDim) {
  24338. var coordDimIndex = dimItem.coordDimIndex;
  24339. getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
  24340. if (!dimItem.isExtraCoord) {
  24341. notExtraCoordDimMap.set(coordDim, 1); // Use the last coord dim (and label friendly) as default label,
  24342. // because when dataset is used, it is hard to guess which dimension
  24343. // can be value dimension. If both show x, y on label is not look good,
  24344. // and conventionally y axis is focused more.
  24345. if (mayLabelDimType(dimItem.type)) {
  24346. defaultedLabel[0] = dimName;
  24347. } // User output encode do not contain generated coords.
  24348. // And it only has index. User can use index to retrieve value from the raw item array.
  24349. getOrCreateEncodeArr(userOutput.encode, coordDim)[coordDimIndex] = dimItem.index;
  24350. }
  24351. if (dimItem.defaultTooltip) {
  24352. defaultedTooltip.push(dimName);
  24353. }
  24354. }
  24355. OTHER_DIMENSIONS.each(function (v, otherDim) {
  24356. var encodeArr = getOrCreateEncodeArr(encode, otherDim);
  24357. var dimIndex = dimItem.otherDims[otherDim];
  24358. if (dimIndex != null && dimIndex !== false) {
  24359. encodeArr[dimIndex] = dimItem.name;
  24360. }
  24361. });
  24362. });
  24363. var dataDimsOnCoord = [];
  24364. var encodeFirstDimNotExtra = {};
  24365. notExtraCoordDimMap.each(function (v, coordDim) {
  24366. var dimArr = encode[coordDim]; // ??? FIXME extra coord should not be set in dataDimsOnCoord.
  24367. // But should fix the case that radar axes: simplify the logic
  24368. // of `completeDimension`, remove `extraPrefix`.
  24369. encodeFirstDimNotExtra[coordDim] = dimArr[0]; // Not necessary to remove duplicate, because a data
  24370. // dim canot on more than one coordDim.
  24371. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  24372. });
  24373. summary.dataDimsOnCoord = dataDimsOnCoord;
  24374. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  24375. var encodeLabel = encode.label; // FIXME `encode.label` is not recommanded, because formatter can not be set
  24376. // in this way. Use label.formatter instead. May be remove this approach someday.
  24377. if (encodeLabel && encodeLabel.length) {
  24378. defaultedLabel = encodeLabel.slice();
  24379. }
  24380. var encodeTooltip = encode.tooltip;
  24381. if (encodeTooltip && encodeTooltip.length) {
  24382. defaultedTooltip = encodeTooltip.slice();
  24383. } else if (!defaultedTooltip.length) {
  24384. defaultedTooltip = defaultedLabel.slice();
  24385. }
  24386. encode.defaultedLabel = defaultedLabel;
  24387. encode.defaultedTooltip = defaultedTooltip;
  24388. return summary;
  24389. }
  24390. function getOrCreateEncodeArr(encode, dim) {
  24391. if (!encode.hasOwnProperty(dim)) {
  24392. encode[dim] = [];
  24393. }
  24394. return encode[dim];
  24395. }
  24396. function getDimensionTypeByAxis(axisType) {
  24397. return axisType === 'category' ? 'ordinal' : axisType === 'time' ? 'time' : 'float';
  24398. }
  24399. function mayLabelDimType(dimType) {
  24400. // In most cases, ordinal and time do not suitable for label.
  24401. // Ordinal info can be displayed on axis. Time is too long.
  24402. return !(dimType === 'ordinal' || dimType === 'time');
  24403. } // function findTheLastDimMayLabel(data) {
  24404. // // Get last value dim
  24405. // var dimensions = data.dimensions.slice();
  24406. // var valueType;
  24407. // var valueDim;
  24408. // while (dimensions.length && (
  24409. // valueDim = dimensions.pop(),
  24410. // valueType = data.getDimensionInfo(valueDim).type,
  24411. // valueType === 'ordinal' || valueType === 'time'
  24412. // )) {} // jshint ignore:line
  24413. // return valueDim;
  24414. // }
  24415. /*
  24416. * Licensed to the Apache Software Foundation (ASF) under one
  24417. * or more contributor license agreements. See the NOTICE file
  24418. * distributed with this work for additional information
  24419. * regarding copyright ownership. The ASF licenses this file
  24420. * to you under the Apache License, Version 2.0 (the
  24421. * "License"); you may not use this file except in compliance
  24422. * with the License. You may obtain a copy of the License at
  24423. *
  24424. * http://www.apache.org/licenses/LICENSE-2.0
  24425. *
  24426. * Unless required by applicable law or agreed to in writing,
  24427. * software distributed under the License is distributed on an
  24428. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24429. * KIND, either express or implied. See the License for the
  24430. * specific language governing permissions and limitations
  24431. * under the License.
  24432. */
  24433. /**
  24434. * @class
  24435. * @param {Object|DataDimensionInfo} [opt] All of the fields will be shallow copied.
  24436. */
  24437. function DataDimensionInfo(opt) {
  24438. if (opt != null) {
  24439. extend(this, opt);
  24440. }
  24441. /**
  24442. * Dimension name.
  24443. * Mandatory.
  24444. * @type {string}
  24445. */
  24446. // this.name;
  24447. /**
  24448. * The origin name in dimsDef, see source helper.
  24449. * If displayName given, the tooltip will displayed vertically.
  24450. * Optional.
  24451. * @type {string}
  24452. */
  24453. // this.displayName;
  24454. /**
  24455. * Which coordSys dimension this dimension mapped to.
  24456. * A `coordDim` can be a "coordSysDim" that the coordSys required
  24457. * (for example, an item in `coordSysDims` of `model/referHelper#CoordSysInfo`),
  24458. * or an generated "extra coord name" if does not mapped to any "coordSysDim"
  24459. * (That is determined by whether `isExtraCoord` is `true`).
  24460. * Mandatory.
  24461. * @type {string}
  24462. */
  24463. // this.coordDim;
  24464. /**
  24465. * The index of this dimension in `series.encode[coordDim]`.
  24466. * Mandatory.
  24467. * @type {number}
  24468. */
  24469. // this.coordDimIndex;
  24470. /**
  24471. * Dimension type. The enumerable values are the key of
  24472. * `dataCtors` of `data/List`.
  24473. * Optional.
  24474. * @type {string}
  24475. */
  24476. // this.type;
  24477. /**
  24478. * This index of this dimension info in `data/List#_dimensionInfos`.
  24479. * Mandatory after added to `data/List`.
  24480. * @type {number}
  24481. */
  24482. // this.index;
  24483. /**
  24484. * The format of `otherDims` is:
  24485. * ```js
  24486. * {
  24487. * tooltip: number optional,
  24488. * label: number optional,
  24489. * itemName: number optional,
  24490. * seriesName: number optional,
  24491. * }
  24492. * ```
  24493. *
  24494. * A `series.encode` can specified these fields:
  24495. * ```js
  24496. * encode: {
  24497. * // "3, 1, 5" is the index of data dimension.
  24498. * tooltip: [3, 1, 5],
  24499. * label: [0, 3],
  24500. * ...
  24501. * }
  24502. * ```
  24503. * `otherDims` is the parse result of the `series.encode` above, like:
  24504. * ```js
  24505. * // Suppose the index of this data dimension is `3`.
  24506. * this.otherDims = {
  24507. * // `3` is at the index `0` of the `encode.tooltip`
  24508. * tooltip: 0,
  24509. * // `3` is at the index `1` of the `encode.tooltip`
  24510. * label: 1
  24511. * };
  24512. * ```
  24513. *
  24514. * This prop should never be `null`/`undefined` after initialized.
  24515. * @type {Object}
  24516. */
  24517. this.otherDims = {};
  24518. /**
  24519. * Be `true` if this dimension is not mapped to any "coordSysDim" that the
  24520. * "coordSys" required.
  24521. * Mandatory.
  24522. * @type {boolean}
  24523. */
  24524. // this.isExtraCoord;
  24525. /**
  24526. * @type {module:data/OrdinalMeta}
  24527. */
  24528. // this.ordinalMeta;
  24529. /**
  24530. * Whether to create inverted indices.
  24531. * @type {boolean}
  24532. */
  24533. // this.createInvertedIndices;
  24534. }
  24535. /*
  24536. * Licensed to the Apache Software Foundation (ASF) under one
  24537. * or more contributor license agreements. See the NOTICE file
  24538. * distributed with this work for additional information
  24539. * regarding copyright ownership. The ASF licenses this file
  24540. * to you under the Apache License, Version 2.0 (the
  24541. * "License"); you may not use this file except in compliance
  24542. * with the License. You may obtain a copy of the License at
  24543. *
  24544. * http://www.apache.org/licenses/LICENSE-2.0
  24545. *
  24546. * Unless required by applicable law or agreed to in writing,
  24547. * software distributed under the License is distributed on an
  24548. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  24549. * KIND, either express or implied. See the License for the
  24550. * specific language governing permissions and limitations
  24551. * under the License.
  24552. */
  24553. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  24554. /**
  24555. * List for data storage
  24556. * @module echarts/data/List
  24557. */
  24558. var isObject$4 = isObject$1;
  24559. var UNDEFINED = 'undefined';
  24560. var INDEX_NOT_FOUND = -1; // Use prefix to avoid index to be the same as otherIdList[idx],
  24561. // which will cause weird udpate animation.
  24562. var ID_PREFIX = 'e\0\0';
  24563. var dataCtors = {
  24564. 'float': typeof Float64Array === UNDEFINED ? Array : Float64Array,
  24565. 'int': typeof Int32Array === UNDEFINED ? Array : Int32Array,
  24566. // Ordinal data type can be string or int
  24567. 'ordinal': Array,
  24568. 'number': Array,
  24569. 'time': Array
  24570. }; // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  24571. // different from the Ctor of typed array.
  24572. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  24573. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  24574. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  24575. function getIndicesCtor(list) {
  24576. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  24577. return list._rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  24578. }
  24579. function cloneChunk(originalChunk) {
  24580. var Ctor = originalChunk.constructor; // Only shallow clone is enough when Array.
  24581. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  24582. }
  24583. var TRANSFERABLE_PROPERTIES = ['hasItemOption', '_nameList', '_idList', '_invertedIndicesMap', '_rawData', '_chunkSize', '_chunkCount', '_dimValueGetter', '_count', '_rawCount', '_nameDimIdx', '_idDimIdx'];
  24584. var CLONE_PROPERTIES = ['_extent', '_approximateExtent', '_rawExtent'];
  24585. function transferProperties(target, source) {
  24586. each$1(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  24587. if (source.hasOwnProperty(propName)) {
  24588. target[propName] = source[propName];
  24589. }
  24590. });
  24591. target.__wrappedMethods = source.__wrappedMethods;
  24592. each$1(CLONE_PROPERTIES, function (propName) {
  24593. target[propName] = clone(source[propName]);
  24594. });
  24595. target._calculationInfo = extend(source._calculationInfo);
  24596. }
  24597. /**
  24598. * @constructor
  24599. * @alias module:echarts/data/List
  24600. *
  24601. * @param {Array.<string|Object|module:data/DataDimensionInfo>} dimensions
  24602. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  24603. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  24604. * @param {module:echarts/model/Model} hostModel
  24605. */
  24606. var List = function (dimensions, hostModel) {
  24607. dimensions = dimensions || ['x', 'y'];
  24608. var dimensionInfos = {};
  24609. var dimensionNames = [];
  24610. var invertedIndicesMap = {};
  24611. for (var i = 0; i < dimensions.length; i++) {
  24612. // Use the original dimensions[i], where other flag props may exists.
  24613. var dimensionInfo = dimensions[i];
  24614. if (isString(dimensionInfo)) {
  24615. dimensionInfo = new DataDimensionInfo({
  24616. name: dimensionInfo
  24617. });
  24618. } else if (!(dimensionInfo instanceof DataDimensionInfo)) {
  24619. dimensionInfo = new DataDimensionInfo(dimensionInfo);
  24620. }
  24621. var dimensionName = dimensionInfo.name;
  24622. dimensionInfo.type = dimensionInfo.type || 'float';
  24623. if (!dimensionInfo.coordDim) {
  24624. dimensionInfo.coordDim = dimensionName;
  24625. dimensionInfo.coordDimIndex = 0;
  24626. }
  24627. dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  24628. dimensionNames.push(dimensionName);
  24629. dimensionInfos[dimensionName] = dimensionInfo;
  24630. dimensionInfo.index = i;
  24631. if (dimensionInfo.createInvertedIndices) {
  24632. invertedIndicesMap[dimensionName] = [];
  24633. }
  24634. }
  24635. /**
  24636. * @readOnly
  24637. * @type {Array.<string>}
  24638. */
  24639. this.dimensions = dimensionNames;
  24640. /**
  24641. * Infomation of each data dimension, like data type.
  24642. * @type {Object}
  24643. */
  24644. this._dimensionInfos = dimensionInfos;
  24645. /**
  24646. * @type {module:echarts/model/Model}
  24647. */
  24648. this.hostModel = hostModel;
  24649. /**
  24650. * @type {module:echarts/model/Model}
  24651. */
  24652. this.dataType;
  24653. /**
  24654. * Indices stores the indices of data subset after filtered.
  24655. * This data subset will be used in chart.
  24656. * @type {Array.<number>}
  24657. * @readOnly
  24658. */
  24659. this._indices = null;
  24660. this._count = 0;
  24661. this._rawCount = 0;
  24662. /**
  24663. * Data storage
  24664. * @type {Object.<key, Array.<TypedArray|Array>>}
  24665. * @private
  24666. */
  24667. this._storage = {};
  24668. /**
  24669. * @type {Array.<string>}
  24670. */
  24671. this._nameList = [];
  24672. /**
  24673. * @type {Array.<string>}
  24674. */
  24675. this._idList = [];
  24676. /**
  24677. * Models of data option is stored sparse for optimizing memory cost
  24678. * @type {Array.<module:echarts/model/Model>}
  24679. * @private
  24680. */
  24681. this._optionModels = [];
  24682. /**
  24683. * Global visual properties after visual coding
  24684. * @type {Object}
  24685. * @private
  24686. */
  24687. this._visual = {};
  24688. /**
  24689. * Globel layout properties.
  24690. * @type {Object}
  24691. * @private
  24692. */
  24693. this._layout = {};
  24694. /**
  24695. * Item visual properties after visual coding
  24696. * @type {Array.<Object>}
  24697. * @private
  24698. */
  24699. this._itemVisuals = [];
  24700. /**
  24701. * Key: visual type, Value: boolean
  24702. * @type {Object}
  24703. * @readOnly
  24704. */
  24705. this.hasItemVisual = {};
  24706. /**
  24707. * Item layout properties after layout
  24708. * @type {Array.<Object>}
  24709. * @private
  24710. */
  24711. this._itemLayouts = [];
  24712. /**
  24713. * Graphic elemnents
  24714. * @type {Array.<module:zrender/Element>}
  24715. * @private
  24716. */
  24717. this._graphicEls = [];
  24718. /**
  24719. * Max size of each chunk.
  24720. * @type {number}
  24721. * @private
  24722. */
  24723. this._chunkSize = 1e5;
  24724. /**
  24725. * @type {number}
  24726. * @private
  24727. */
  24728. this._chunkCount = 0;
  24729. /**
  24730. * @type {Array.<Array|Object>}
  24731. * @private
  24732. */
  24733. this._rawData;
  24734. /**
  24735. * Raw extent will not be cloned, but only transfered.
  24736. * It will not be calculated util needed.
  24737. * key: dim,
  24738. * value: {end: number, extent: Array.<number>}
  24739. * @type {Object}
  24740. * @private
  24741. */
  24742. this._rawExtent = {};
  24743. /**
  24744. * @type {Object}
  24745. * @private
  24746. */
  24747. this._extent = {};
  24748. /**
  24749. * key: dim
  24750. * value: extent
  24751. * @type {Object}
  24752. * @private
  24753. */
  24754. this._approximateExtent = {};
  24755. /**
  24756. * Cache summary info for fast visit. See "dimensionHelper".
  24757. * @type {Object}
  24758. * @private
  24759. */
  24760. this._dimensionsSummary = summarizeDimensions(this);
  24761. /**
  24762. * @type {Object.<Array|TypedArray>}
  24763. * @private
  24764. */
  24765. this._invertedIndicesMap = invertedIndicesMap;
  24766. /**
  24767. * @type {Object}
  24768. * @private
  24769. */
  24770. this._calculationInfo = {};
  24771. /**
  24772. * User output info of this data.
  24773. * DO NOT use it in other places!
  24774. *
  24775. * When preparing user params for user callbacks, we have
  24776. * to clone these inner data structures to prevent users
  24777. * from modifying them to effect built-in logic. And for
  24778. * performance consideration we make this `userOutput` to
  24779. * avoid clone them too many times.
  24780. *
  24781. * @type {Object}
  24782. * @readOnly
  24783. */
  24784. this.userOutput = this._dimensionsSummary.userOutput;
  24785. };
  24786. var listProto = List.prototype;
  24787. listProto.type = 'list';
  24788. /**
  24789. * If each data item has it's own option
  24790. * @type {boolean}
  24791. */
  24792. listProto.hasItemOption = true;
  24793. /**
  24794. * The meanings of the input parameter `dim`:
  24795. *
  24796. * + If dim is a number (e.g., `1`), it means the index of the dimension.
  24797. * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.
  24798. * + If dim is a number-like string (e.g., `"1"`):
  24799. * + If there is the same concrete dim name defined in `this.dimensions`, it means that concrete name.
  24800. * + If not, it will be converted to a number, which means the index of the dimension.
  24801. * (why? because of the backward compatbility. We have been tolerating number-like string in
  24802. * dimension setting, although now it seems that it is not a good idea.)
  24803. * For example, `visualMap[i].dimension: "1"` is the same meaning as `visualMap[i].dimension: 1`,
  24804. * if no dimension name is defined as `"1"`.
  24805. * + If dim is a not-number-like string, it means the concrete dim name.
  24806. * For example, it can be be default name `"x"`, `"y"`, `"z"`, `"lng"`, `"lat"`, `"angle"`, `"radius"`,
  24807. * or customized in `dimensions` property of option like `"age"`.
  24808. *
  24809. * Get dimension name
  24810. * @param {string|number} dim See above.
  24811. * @return {string} Concrete dim name.
  24812. */
  24813. listProto.getDimension = function (dim) {
  24814. if (typeof dim === 'number' // If being a number-like string but not being defined a dimension name.
  24815. || !isNaN(dim) && !this._dimensionInfos.hasOwnProperty(dim)) {
  24816. dim = this.dimensions[dim];
  24817. }
  24818. return dim;
  24819. };
  24820. /**
  24821. * Get type and calculation info of particular dimension
  24822. * @param {string|number} dim
  24823. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  24824. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  24825. */
  24826. listProto.getDimensionInfo = function (dim) {
  24827. // Do not clone, because there may be categories in dimInfo.
  24828. return this._dimensionInfos[this.getDimension(dim)];
  24829. };
  24830. /**
  24831. * @return {Array.<string>} concrete dimension name list on coord.
  24832. */
  24833. listProto.getDimensionsOnCoord = function () {
  24834. return this._dimensionsSummary.dataDimsOnCoord.slice();
  24835. };
  24836. /**
  24837. * @param {string} coordDim
  24838. * @param {number} [idx] A coordDim may map to more than one data dim.
  24839. * If idx is `true`, return a array of all mapped dims.
  24840. * If idx is not specified, return the first dim not extra.
  24841. * @return {string|Array.<string>} concrete data dim.
  24842. * If idx is number, and not found, return null/undefined.
  24843. * If idx is `true`, and not found, return empty array (always return array).
  24844. */
  24845. listProto.mapDimension = function (coordDim, idx) {
  24846. var dimensionsSummary = this._dimensionsSummary;
  24847. if (idx == null) {
  24848. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  24849. }
  24850. var dims = dimensionsSummary.encode[coordDim];
  24851. return idx === true // always return array if idx is `true`
  24852. ? (dims || []).slice() : dims && dims[idx];
  24853. };
  24854. /**
  24855. * Initialize from data
  24856. * @param {Array.<Object|number|Array>} data source or data or data provider.
  24857. * @param {Array.<string>} [nameLIst] The name of a datum is used on data diff and
  24858. * defualt label/tooltip.
  24859. * A name can be specified in encode.itemName,
  24860. * or dataItem.name (only for series option data),
  24861. * or provided in nameList from outside.
  24862. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  24863. */
  24864. listProto.initData = function (data, nameList, dimValueGetter) {
  24865. var notProvider = Source.isInstance(data) || isArrayLike(data);
  24866. if (notProvider) {
  24867. data = new DefaultDataProvider(data, this.dimensions.length);
  24868. }
  24869. this._rawData = data; // Clear
  24870. this._storage = {};
  24871. this._indices = null;
  24872. this._nameList = nameList || [];
  24873. this._idList = [];
  24874. this._nameRepeatCount = {};
  24875. if (!dimValueGetter) {
  24876. this.hasItemOption = false;
  24877. }
  24878. /**
  24879. * @readOnly
  24880. */
  24881. this.defaultDimValueGetter = defaultDimValueGetters[this._rawData.getSource().sourceFormat]; // Default dim value getter
  24882. this._dimValueGetter = dimValueGetter = dimValueGetter || this.defaultDimValueGetter;
  24883. this._dimValueGetterArrayRows = defaultDimValueGetters.arrayRows; // Reset raw extent.
  24884. this._rawExtent = {};
  24885. this._initDataFromProvider(0, data.count()); // If data has no item option.
  24886. if (data.pure) {
  24887. this.hasItemOption = false;
  24888. }
  24889. };
  24890. listProto.getProvider = function () {
  24891. return this._rawData;
  24892. };
  24893. /**
  24894. * Caution: Can be only called on raw data (before `this._indices` created).
  24895. */
  24896. listProto.appendData = function (data) {
  24897. var rawData = this._rawData;
  24898. var start = this.count();
  24899. rawData.appendData(data);
  24900. var end = rawData.count();
  24901. if (!rawData.persistent) {
  24902. end += start;
  24903. }
  24904. this._initDataFromProvider(start, end);
  24905. };
  24906. /**
  24907. * Caution: Can be only called on raw data (before `this._indices` created).
  24908. * This method does not modify `rawData` (`dataProvider`), but only
  24909. * add values to storage.
  24910. *
  24911. * The final count will be increased by `Math.max(values.length, names.length)`.
  24912. *
  24913. * @param {Array.<Array.<*>>} values That is the SourceType: 'arrayRows', like
  24914. * [
  24915. * [12, 33, 44],
  24916. * [NaN, 43, 1],
  24917. * ['-', 'asdf', 0]
  24918. * ]
  24919. * Each item is exaclty cooresponding to a dimension.
  24920. * @param {Array.<string>} [names]
  24921. */
  24922. listProto.appendValues = function (values, names) {
  24923. var chunkSize = this._chunkSize;
  24924. var storage = this._storage;
  24925. var dimensions = this.dimensions;
  24926. var dimLen = dimensions.length;
  24927. var rawExtent = this._rawExtent;
  24928. var start = this.count();
  24929. var end = start + Math.max(values.length, names ? names.length : 0);
  24930. var originalChunkCount = this._chunkCount;
  24931. for (var i = 0; i < dimLen; i++) {
  24932. var dim = dimensions[i];
  24933. if (!rawExtent[dim]) {
  24934. rawExtent[dim] = getInitialExtent();
  24935. }
  24936. if (!storage[dim]) {
  24937. storage[dim] = [];
  24938. }
  24939. prepareChunks(storage, this._dimensionInfos[dim], chunkSize, originalChunkCount, end);
  24940. this._chunkCount = storage[dim].length;
  24941. }
  24942. var emptyDataItem = new Array(dimLen);
  24943. for (var idx = start; idx < end; idx++) {
  24944. var sourceIdx = idx - start;
  24945. var chunkIndex = Math.floor(idx / chunkSize);
  24946. var chunkOffset = idx % chunkSize; // Store the data by dimensions
  24947. for (var k = 0; k < dimLen; k++) {
  24948. var dim = dimensions[k];
  24949. var val = this._dimValueGetterArrayRows(values[sourceIdx] || emptyDataItem, dim, sourceIdx, k);
  24950. storage[dim][chunkIndex][chunkOffset] = val;
  24951. var dimRawExtent = rawExtent[dim];
  24952. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  24953. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  24954. }
  24955. if (names) {
  24956. this._nameList[idx] = names[sourceIdx];
  24957. }
  24958. }
  24959. this._rawCount = this._count = end; // Reset data extent
  24960. this._extent = {};
  24961. prepareInvertedIndex(this);
  24962. };
  24963. listProto._initDataFromProvider = function (start, end) {
  24964. // Optimize.
  24965. if (start >= end) {
  24966. return;
  24967. }
  24968. var chunkSize = this._chunkSize;
  24969. var rawData = this._rawData;
  24970. var storage = this._storage;
  24971. var dimensions = this.dimensions;
  24972. var dimLen = dimensions.length;
  24973. var dimensionInfoMap = this._dimensionInfos;
  24974. var nameList = this._nameList;
  24975. var idList = this._idList;
  24976. var rawExtent = this._rawExtent;
  24977. var nameRepeatCount = this._nameRepeatCount = {};
  24978. var nameDimIdx;
  24979. var originalChunkCount = this._chunkCount;
  24980. for (var i = 0; i < dimLen; i++) {
  24981. var dim = dimensions[i];
  24982. if (!rawExtent[dim]) {
  24983. rawExtent[dim] = getInitialExtent();
  24984. }
  24985. var dimInfo = dimensionInfoMap[dim];
  24986. if (dimInfo.otherDims.itemName === 0) {
  24987. nameDimIdx = this._nameDimIdx = i;
  24988. }
  24989. if (dimInfo.otherDims.itemId === 0) {
  24990. this._idDimIdx = i;
  24991. }
  24992. if (!storage[dim]) {
  24993. storage[dim] = [];
  24994. }
  24995. prepareChunks(storage, dimInfo, chunkSize, originalChunkCount, end);
  24996. this._chunkCount = storage[dim].length;
  24997. }
  24998. var dataItem = new Array(dimLen);
  24999. for (var idx = start; idx < end; idx++) {
  25000. // NOTICE: Try not to write things into dataItem
  25001. dataItem = rawData.getItem(idx, dataItem); // Each data item is value
  25002. // [1, 2]
  25003. // 2
  25004. // Bar chart, line chart which uses category axis
  25005. // only gives the 'y' value. 'x' value is the indices of category
  25006. // Use a tempValue to normalize the value to be a (x, y) value
  25007. var chunkIndex = Math.floor(idx / chunkSize);
  25008. var chunkOffset = idx % chunkSize; // Store the data by dimensions
  25009. for (var k = 0; k < dimLen; k++) {
  25010. var dim = dimensions[k];
  25011. var dimStorage = storage[dim][chunkIndex]; // PENDING NULL is empty or zero
  25012. var val = this._dimValueGetter(dataItem, dim, idx, k);
  25013. dimStorage[chunkOffset] = val;
  25014. var dimRawExtent = rawExtent[dim];
  25015. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  25016. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  25017. } // ??? FIXME not check by pure but sourceFormat?
  25018. // TODO refactor these logic.
  25019. if (!rawData.pure) {
  25020. var name = nameList[idx];
  25021. if (dataItem && name == null) {
  25022. // If dataItem is {name: ...}, it has highest priority.
  25023. // That is appropriate for many common cases.
  25024. if (dataItem.name != null) {
  25025. // There is no other place to persistent dataItem.name,
  25026. // so save it to nameList.
  25027. nameList[idx] = name = dataItem.name;
  25028. } else if (nameDimIdx != null) {
  25029. var nameDim = dimensions[nameDimIdx];
  25030. var nameDimChunk = storage[nameDim][chunkIndex];
  25031. if (nameDimChunk) {
  25032. name = nameDimChunk[chunkOffset];
  25033. var ordinalMeta = dimensionInfoMap[nameDim].ordinalMeta;
  25034. if (ordinalMeta && ordinalMeta.categories.length) {
  25035. name = ordinalMeta.categories[name];
  25036. }
  25037. }
  25038. }
  25039. } // Try using the id in option
  25040. // id or name is used on dynamical data, mapping old and new items.
  25041. var id = dataItem == null ? null : dataItem.id;
  25042. if (id == null && name != null) {
  25043. // Use name as id and add counter to avoid same name
  25044. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  25045. id = name;
  25046. if (nameRepeatCount[name] > 0) {
  25047. id += '__ec__' + nameRepeatCount[name];
  25048. }
  25049. nameRepeatCount[name]++;
  25050. }
  25051. id != null && (idList[idx] = id);
  25052. }
  25053. }
  25054. if (!rawData.persistent && rawData.clean) {
  25055. // Clean unused data if data source is typed array.
  25056. rawData.clean();
  25057. }
  25058. this._rawCount = this._count = end; // Reset data extent
  25059. this._extent = {};
  25060. prepareInvertedIndex(this);
  25061. };
  25062. function prepareChunks(storage, dimInfo, chunkSize, chunkCount, end) {
  25063. var DataCtor = dataCtors[dimInfo.type];
  25064. var lastChunkIndex = chunkCount - 1;
  25065. var dim = dimInfo.name;
  25066. var resizeChunkArray = storage[dim][lastChunkIndex];
  25067. if (resizeChunkArray && resizeChunkArray.length < chunkSize) {
  25068. var newStore = new DataCtor(Math.min(end - lastChunkIndex * chunkSize, chunkSize)); // The cost of the copy is probably inconsiderable
  25069. // within the initial chunkSize.
  25070. for (var j = 0; j < resizeChunkArray.length; j++) {
  25071. newStore[j] = resizeChunkArray[j];
  25072. }
  25073. storage[dim][lastChunkIndex] = newStore;
  25074. } // Create new chunks.
  25075. for (var k = chunkCount * chunkSize; k < end; k += chunkSize) {
  25076. storage[dim].push(new DataCtor(Math.min(end - k, chunkSize)));
  25077. }
  25078. }
  25079. function prepareInvertedIndex(list) {
  25080. var invertedIndicesMap = list._invertedIndicesMap;
  25081. each$1(invertedIndicesMap, function (invertedIndices, dim) {
  25082. var dimInfo = list._dimensionInfos[dim]; // Currently, only dimensions that has ordinalMeta can create inverted indices.
  25083. var ordinalMeta = dimInfo.ordinalMeta;
  25084. if (ordinalMeta) {
  25085. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array(ordinalMeta.categories.length); // The default value of TypedArray is 0. To avoid miss
  25086. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  25087. for (var i = 0; i < invertedIndices.length; i++) {
  25088. invertedIndices[i] = INDEX_NOT_FOUND;
  25089. }
  25090. for (var i = 0; i < list._count; i++) {
  25091. // Only support the case that all values are distinct.
  25092. invertedIndices[list.get(dim, i)] = i;
  25093. }
  25094. }
  25095. });
  25096. }
  25097. function getRawValueFromStore(list, dimIndex, rawIndex) {
  25098. var val;
  25099. if (dimIndex != null) {
  25100. var chunkSize = list._chunkSize;
  25101. var chunkIndex = Math.floor(rawIndex / chunkSize);
  25102. var chunkOffset = rawIndex % chunkSize;
  25103. var dim = list.dimensions[dimIndex];
  25104. var chunk = list._storage[dim][chunkIndex];
  25105. if (chunk) {
  25106. val = chunk[chunkOffset];
  25107. var ordinalMeta = list._dimensionInfos[dim].ordinalMeta;
  25108. if (ordinalMeta && ordinalMeta.categories.length) {
  25109. val = ordinalMeta.categories[val];
  25110. }
  25111. }
  25112. }
  25113. return val;
  25114. }
  25115. /**
  25116. * @return {number}
  25117. */
  25118. listProto.count = function () {
  25119. return this._count;
  25120. };
  25121. listProto.getIndices = function () {
  25122. var newIndices;
  25123. var indices = this._indices;
  25124. if (indices) {
  25125. var Ctor = indices.constructor;
  25126. var thisCount = this._count; // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  25127. if (Ctor === Array) {
  25128. newIndices = new Ctor(thisCount);
  25129. for (var i = 0; i < thisCount; i++) {
  25130. newIndices[i] = indices[i];
  25131. }
  25132. } else {
  25133. newIndices = new Ctor(indices.buffer, 0, thisCount);
  25134. }
  25135. } else {
  25136. var Ctor = getIndicesCtor(this);
  25137. var newIndices = new Ctor(this.count());
  25138. for (var i = 0; i < newIndices.length; i++) {
  25139. newIndices[i] = i;
  25140. }
  25141. }
  25142. return newIndices;
  25143. };
  25144. /**
  25145. * Get value. Return NaN if idx is out of range.
  25146. * @param {string} dim Dim must be concrete name.
  25147. * @param {number} idx
  25148. * @param {boolean} stack
  25149. * @return {number}
  25150. */
  25151. listProto.get = function (dim, idx
  25152. /*, stack */
  25153. ) {
  25154. if (!(idx >= 0 && idx < this._count)) {
  25155. return NaN;
  25156. }
  25157. var storage = this._storage;
  25158. if (!storage[dim]) {
  25159. // TODO Warn ?
  25160. return NaN;
  25161. }
  25162. idx = this.getRawIndex(idx);
  25163. var chunkIndex = Math.floor(idx / this._chunkSize);
  25164. var chunkOffset = idx % this._chunkSize;
  25165. var chunkStore = storage[dim][chunkIndex];
  25166. var value = chunkStore[chunkOffset]; // FIXME ordinal data type is not stackable
  25167. // if (stack) {
  25168. // var dimensionInfo = this._dimensionInfos[dim];
  25169. // if (dimensionInfo && dimensionInfo.stackable) {
  25170. // var stackedOn = this.stackedOn;
  25171. // while (stackedOn) {
  25172. // // Get no stacked data of stacked on
  25173. // var stackedValue = stackedOn.get(dim, idx);
  25174. // // Considering positive stack, negative stack and empty data
  25175. // if ((value >= 0 && stackedValue > 0) // Positive stack
  25176. // || (value <= 0 && stackedValue < 0) // Negative stack
  25177. // ) {
  25178. // value += stackedValue;
  25179. // }
  25180. // stackedOn = stackedOn.stackedOn;
  25181. // }
  25182. // }
  25183. // }
  25184. return value;
  25185. };
  25186. /**
  25187. * @param {string} dim concrete dim
  25188. * @param {number} rawIndex
  25189. * @return {number|string}
  25190. */
  25191. listProto.getByRawIndex = function (dim, rawIdx) {
  25192. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  25193. return NaN;
  25194. }
  25195. var dimStore = this._storage[dim];
  25196. if (!dimStore) {
  25197. // TODO Warn ?
  25198. return NaN;
  25199. }
  25200. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  25201. var chunkOffset = rawIdx % this._chunkSize;
  25202. var chunkStore = dimStore[chunkIndex];
  25203. return chunkStore[chunkOffset];
  25204. };
  25205. /**
  25206. * FIXME Use `get` on chrome maybe slow(in filterSelf and selectRange).
  25207. * Hack a much simpler _getFast
  25208. * @private
  25209. */
  25210. listProto._getFast = function (dim, rawIdx) {
  25211. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  25212. var chunkOffset = rawIdx % this._chunkSize;
  25213. var chunkStore = this._storage[dim][chunkIndex];
  25214. return chunkStore[chunkOffset];
  25215. };
  25216. /**
  25217. * Get value for multi dimensions.
  25218. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  25219. * @param {number} idx
  25220. * @return {number}
  25221. */
  25222. listProto.getValues = function (dimensions, idx
  25223. /*, stack */
  25224. ) {
  25225. var values = [];
  25226. if (!isArray(dimensions)) {
  25227. // stack = idx;
  25228. idx = dimensions;
  25229. dimensions = this.dimensions;
  25230. }
  25231. for (var i = 0, len = dimensions.length; i < len; i++) {
  25232. values.push(this.get(dimensions[i], idx
  25233. /*, stack */
  25234. ));
  25235. }
  25236. return values;
  25237. };
  25238. /**
  25239. * If value is NaN. Inlcuding '-'
  25240. * Only check the coord dimensions.
  25241. * @param {string} dim
  25242. * @param {number} idx
  25243. * @return {number}
  25244. */
  25245. listProto.hasValue = function (idx) {
  25246. var dataDimsOnCoord = this._dimensionsSummary.dataDimsOnCoord;
  25247. for (var i = 0, len = dataDimsOnCoord.length; i < len; i++) {
  25248. // Ordinal type originally can be string or number.
  25249. // But when an ordinal type is used on coord, it can
  25250. // not be string but only number. So we can also use isNaN.
  25251. if (isNaN(this.get(dataDimsOnCoord[i], idx))) {
  25252. return false;
  25253. }
  25254. }
  25255. return true;
  25256. };
  25257. /**
  25258. * Get extent of data in one dimension
  25259. * @param {string} dim
  25260. * @param {boolean} stack
  25261. */
  25262. listProto.getDataExtent = function (dim
  25263. /*, stack */
  25264. ) {
  25265. // Make sure use concrete dim as cache name.
  25266. dim = this.getDimension(dim);
  25267. var dimData = this._storage[dim];
  25268. var initialExtent = getInitialExtent(); // stack = !!((stack || false) && this.getCalculationInfo(dim));
  25269. if (!dimData) {
  25270. return initialExtent;
  25271. } // Make more strict checkings to ensure hitting cache.
  25272. var currEnd = this.count(); // var cacheName = [dim, !!stack].join('_');
  25273. // var cacheName = dim;
  25274. // Consider the most cases when using data zoom, `getDataExtent`
  25275. // happened before filtering. We cache raw extent, which is not
  25276. // necessary to be cleared and recalculated when restore data.
  25277. var useRaw = !this._indices; // && !stack;
  25278. var dimExtent;
  25279. if (useRaw) {
  25280. return this._rawExtent[dim].slice();
  25281. }
  25282. dimExtent = this._extent[dim];
  25283. if (dimExtent) {
  25284. return dimExtent.slice();
  25285. }
  25286. dimExtent = initialExtent;
  25287. var min = dimExtent[0];
  25288. var max = dimExtent[1];
  25289. for (var i = 0; i < currEnd; i++) {
  25290. // var value = stack ? this.get(dim, i, true) : this._getFast(dim, this.getRawIndex(i));
  25291. var value = this._getFast(dim, this.getRawIndex(i));
  25292. value < min && (min = value);
  25293. value > max && (max = value);
  25294. }
  25295. dimExtent = [min, max];
  25296. this._extent[dim] = dimExtent;
  25297. return dimExtent;
  25298. };
  25299. /**
  25300. * Optimize for the scenario that data is filtered by a given extent.
  25301. * Consider that if data amount is more than hundreds of thousand,
  25302. * extent calculation will cost more than 10ms and the cache will
  25303. * be erased because of the filtering.
  25304. */
  25305. listProto.getApproximateExtent = function (dim
  25306. /*, stack */
  25307. ) {
  25308. dim = this.getDimension(dim);
  25309. return this._approximateExtent[dim] || this.getDataExtent(dim
  25310. /*, stack */
  25311. );
  25312. };
  25313. listProto.setApproximateExtent = function (extent, dim
  25314. /*, stack */
  25315. ) {
  25316. dim = this.getDimension(dim);
  25317. this._approximateExtent[dim] = extent.slice();
  25318. };
  25319. /**
  25320. * @param {string} key
  25321. * @return {*}
  25322. */
  25323. listProto.getCalculationInfo = function (key) {
  25324. return this._calculationInfo[key];
  25325. };
  25326. /**
  25327. * @param {string|Object} key or k-v object
  25328. * @param {*} [value]
  25329. */
  25330. listProto.setCalculationInfo = function (key, value) {
  25331. isObject$4(key) ? extend(this._calculationInfo, key) : this._calculationInfo[key] = value;
  25332. };
  25333. /**
  25334. * Get sum of data in one dimension
  25335. * @param {string} dim
  25336. */
  25337. listProto.getSum = function (dim
  25338. /*, stack */
  25339. ) {
  25340. var dimData = this._storage[dim];
  25341. var sum = 0;
  25342. if (dimData) {
  25343. for (var i = 0, len = this.count(); i < len; i++) {
  25344. var value = this.get(dim, i
  25345. /*, stack */
  25346. );
  25347. if (!isNaN(value)) {
  25348. sum += value;
  25349. }
  25350. }
  25351. }
  25352. return sum;
  25353. };
  25354. /**
  25355. * Get median of data in one dimension
  25356. * @param {string} dim
  25357. */
  25358. listProto.getMedian = function (dim
  25359. /*, stack */
  25360. ) {
  25361. var dimDataArray = []; // map all data of one dimension
  25362. this.each(dim, function (val, idx) {
  25363. if (!isNaN(val)) {
  25364. dimDataArray.push(val);
  25365. }
  25366. }); // TODO
  25367. // Use quick select?
  25368. // immutability & sort
  25369. var sortedDimDataArray = [].concat(dimDataArray).sort(function (a, b) {
  25370. return a - b;
  25371. });
  25372. var len = this.count(); // calculate median
  25373. return len === 0 ? 0 : len % 2 === 1 ? sortedDimDataArray[(len - 1) / 2] : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  25374. }; // /**
  25375. // * Retreive the index with given value
  25376. // * @param {string} dim Concrete dimension.
  25377. // * @param {number} value
  25378. // * @return {number}
  25379. // */
  25380. // Currently incorrect: should return dataIndex but not rawIndex.
  25381. // Do not fix it until this method is to be used somewhere.
  25382. // FIXME Precision of float value
  25383. // listProto.indexOf = function (dim, value) {
  25384. // var storage = this._storage;
  25385. // var dimData = storage[dim];
  25386. // var chunkSize = this._chunkSize;
  25387. // if (dimData) {
  25388. // for (var i = 0, len = this.count(); i < len; i++) {
  25389. // var chunkIndex = Math.floor(i / chunkSize);
  25390. // var chunkOffset = i % chunkSize;
  25391. // if (dimData[chunkIndex][chunkOffset] === value) {
  25392. // return i;
  25393. // }
  25394. // }
  25395. // }
  25396. // return -1;
  25397. // };
  25398. /**
  25399. * Only support the dimension which inverted index created.
  25400. * Do not support other cases until required.
  25401. * @param {string} concrete dim
  25402. * @param {number|string} value
  25403. * @return {number} rawIndex
  25404. */
  25405. listProto.rawIndexOf = function (dim, value) {
  25406. var invertedIndices = dim && this._invertedIndicesMap[dim];
  25407. var rawIndex = invertedIndices[value];
  25408. if (rawIndex == null || isNaN(rawIndex)) {
  25409. return INDEX_NOT_FOUND;
  25410. }
  25411. return rawIndex;
  25412. };
  25413. /**
  25414. * Retreive the index with given name
  25415. * @param {number} idx
  25416. * @param {number} name
  25417. * @return {number}
  25418. */
  25419. listProto.indexOfName = function (name) {
  25420. for (var i = 0, len = this.count(); i < len; i++) {
  25421. if (this.getName(i) === name) {
  25422. return i;
  25423. }
  25424. }
  25425. return -1;
  25426. };
  25427. /**
  25428. * Retreive the index with given raw data index
  25429. * @param {number} idx
  25430. * @param {number} name
  25431. * @return {number}
  25432. */
  25433. listProto.indexOfRawIndex = function (rawIndex) {
  25434. if (rawIndex >= this._rawCount || rawIndex < 0) {
  25435. return -1;
  25436. }
  25437. if (!this._indices) {
  25438. return rawIndex;
  25439. } // Indices are ascending
  25440. var indices = this._indices; // If rawIndex === dataIndex
  25441. var rawDataIndex = indices[rawIndex];
  25442. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  25443. return rawIndex;
  25444. }
  25445. var left = 0;
  25446. var right = this._count - 1;
  25447. while (left <= right) {
  25448. var mid = (left + right) / 2 | 0;
  25449. if (indices[mid] < rawIndex) {
  25450. left = mid + 1;
  25451. } else if (indices[mid] > rawIndex) {
  25452. right = mid - 1;
  25453. } else {
  25454. return mid;
  25455. }
  25456. }
  25457. return -1;
  25458. };
  25459. /**
  25460. * Retreive the index of nearest value
  25461. * @param {string} dim
  25462. * @param {number} value
  25463. * @param {number} [maxDistance=Infinity]
  25464. * @return {Array.<number>} If and only if multiple indices has
  25465. * the same value, they are put to the result.
  25466. */
  25467. listProto.indicesOfNearest = function (dim, value, maxDistance) {
  25468. var storage = this._storage;
  25469. var dimData = storage[dim];
  25470. var nearestIndices = [];
  25471. if (!dimData) {
  25472. return nearestIndices;
  25473. }
  25474. if (maxDistance == null) {
  25475. maxDistance = Infinity;
  25476. }
  25477. var minDist = Infinity;
  25478. var minDiff = -1;
  25479. var nearestIndicesLen = 0; // Check the test case of `test/ut/spec/data/List.js`.
  25480. for (var i = 0, len = this.count(); i < len; i++) {
  25481. var diff = value - this.get(dim, i);
  25482. var dist = Math.abs(diff);
  25483. if (dist <= maxDistance) {
  25484. // When the `value` is at the middle of `this.get(dim, i)` and `this.get(dim, i+1)`,
  25485. // we'd better not push both of them to `nearestIndices`, otherwise it is easy to
  25486. // get more than one item in `nearestIndices` (more specifically, in `tooltip`).
  25487. // So we chose the one that `diff >= 0` in this csae.
  25488. // But if `this.get(dim, i)` and `this.get(dim, j)` get the same value, both of them
  25489. // should be push to `nearestIndices`.
  25490. if (dist < minDist || dist === minDist && diff >= 0 && minDiff < 0) {
  25491. minDist = dist;
  25492. minDiff = diff;
  25493. nearestIndicesLen = 0;
  25494. }
  25495. if (diff === minDiff) {
  25496. nearestIndices[nearestIndicesLen++] = i;
  25497. }
  25498. }
  25499. }
  25500. nearestIndices.length = nearestIndicesLen;
  25501. return nearestIndices;
  25502. };
  25503. /**
  25504. * Get raw data index
  25505. * @param {number} idx
  25506. * @return {number}
  25507. */
  25508. listProto.getRawIndex = getRawIndexWithoutIndices;
  25509. function getRawIndexWithoutIndices(idx) {
  25510. return idx;
  25511. }
  25512. function getRawIndexWithIndices(idx) {
  25513. if (idx < this._count && idx >= 0) {
  25514. return this._indices[idx];
  25515. }
  25516. return -1;
  25517. }
  25518. /**
  25519. * Get raw data item
  25520. * @param {number} idx
  25521. * @return {number}
  25522. */
  25523. listProto.getRawDataItem = function (idx) {
  25524. if (!this._rawData.persistent) {
  25525. var val = [];
  25526. for (var i = 0; i < this.dimensions.length; i++) {
  25527. var dim = this.dimensions[i];
  25528. val.push(this.get(dim, idx));
  25529. }
  25530. return val;
  25531. } else {
  25532. return this._rawData.getItem(this.getRawIndex(idx));
  25533. }
  25534. };
  25535. /**
  25536. * @param {number} idx
  25537. * @param {boolean} [notDefaultIdx=false]
  25538. * @return {string}
  25539. */
  25540. listProto.getName = function (idx) {
  25541. var rawIndex = this.getRawIndex(idx);
  25542. return this._nameList[rawIndex] || getRawValueFromStore(this, this._nameDimIdx, rawIndex) || '';
  25543. };
  25544. /**
  25545. * @param {number} idx
  25546. * @param {boolean} [notDefaultIdx=false]
  25547. * @return {string}
  25548. */
  25549. listProto.getId = function (idx) {
  25550. return getId(this, this.getRawIndex(idx));
  25551. };
  25552. function getId(list, rawIndex) {
  25553. var id = list._idList[rawIndex];
  25554. if (id == null) {
  25555. id = getRawValueFromStore(list, list._idDimIdx, rawIndex);
  25556. }
  25557. if (id == null) {
  25558. // FIXME Check the usage in graph, should not use prefix.
  25559. id = ID_PREFIX + rawIndex;
  25560. }
  25561. return id;
  25562. }
  25563. function normalizeDimensions(dimensions) {
  25564. if (!isArray(dimensions)) {
  25565. dimensions = [dimensions];
  25566. }
  25567. return dimensions;
  25568. }
  25569. /**
  25570. * Data iteration
  25571. * @param {string|Array.<string>}
  25572. * @param {Function} cb
  25573. * @param {*} [context=this]
  25574. *
  25575. * @example
  25576. * list.each('x', function (x, idx) {});
  25577. * list.each(['x', 'y'], function (x, y, idx) {});
  25578. * list.each(function (idx) {})
  25579. */
  25580. listProto.each = function (dims, cb, context, contextCompat) {
  25581. 'use strict';
  25582. if (!this._count) {
  25583. return;
  25584. }
  25585. if (typeof dims === 'function') {
  25586. contextCompat = context;
  25587. context = cb;
  25588. cb = dims;
  25589. dims = [];
  25590. } // contextCompat just for compat echarts3
  25591. context = context || contextCompat || this;
  25592. dims = map(normalizeDimensions(dims), this.getDimension, this);
  25593. var dimSize = dims.length;
  25594. for (var i = 0; i < this.count(); i++) {
  25595. // Simple optimization
  25596. switch (dimSize) {
  25597. case 0:
  25598. cb.call(context, i);
  25599. break;
  25600. case 1:
  25601. cb.call(context, this.get(dims[0], i), i);
  25602. break;
  25603. case 2:
  25604. cb.call(context, this.get(dims[0], i), this.get(dims[1], i), i);
  25605. break;
  25606. default:
  25607. var k = 0;
  25608. var value = [];
  25609. for (; k < dimSize; k++) {
  25610. value[k] = this.get(dims[k], i);
  25611. } // Index
  25612. value[k] = i;
  25613. cb.apply(context, value);
  25614. }
  25615. }
  25616. };
  25617. /**
  25618. * Data filter
  25619. * @param {string|Array.<string>}
  25620. * @param {Function} cb
  25621. * @param {*} [context=this]
  25622. */
  25623. listProto.filterSelf = function (dimensions, cb, context, contextCompat) {
  25624. 'use strict';
  25625. if (!this._count) {
  25626. return;
  25627. }
  25628. if (typeof dimensions === 'function') {
  25629. contextCompat = context;
  25630. context = cb;
  25631. cb = dimensions;
  25632. dimensions = [];
  25633. } // contextCompat just for compat echarts3
  25634. context = context || contextCompat || this;
  25635. dimensions = map(normalizeDimensions(dimensions), this.getDimension, this);
  25636. var count = this.count();
  25637. var Ctor = getIndicesCtor(this);
  25638. var newIndices = new Ctor(count);
  25639. var value = [];
  25640. var dimSize = dimensions.length;
  25641. var offset = 0;
  25642. var dim0 = dimensions[0];
  25643. for (var i = 0; i < count; i++) {
  25644. var keep;
  25645. var rawIdx = this.getRawIndex(i); // Simple optimization
  25646. if (dimSize === 0) {
  25647. keep = cb.call(context, i);
  25648. } else if (dimSize === 1) {
  25649. var val = this._getFast(dim0, rawIdx);
  25650. keep = cb.call(context, val, i);
  25651. } else {
  25652. for (var k = 0; k < dimSize; k++) {
  25653. value[k] = this._getFast(dim0, rawIdx);
  25654. }
  25655. value[k] = i;
  25656. keep = cb.apply(context, value);
  25657. }
  25658. if (keep) {
  25659. newIndices[offset++] = rawIdx;
  25660. }
  25661. } // Set indices after filtered.
  25662. if (offset < count) {
  25663. this._indices = newIndices;
  25664. }
  25665. this._count = offset; // Reset data extent
  25666. this._extent = {};
  25667. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  25668. return this;
  25669. };
  25670. /**
  25671. * Select data in range. (For optimization of filter)
  25672. * (Manually inline code, support 5 million data filtering in data zoom.)
  25673. */
  25674. listProto.selectRange = function (range) {
  25675. 'use strict';
  25676. if (!this._count) {
  25677. return;
  25678. }
  25679. var dimensions = [];
  25680. for (var dim in range) {
  25681. if (range.hasOwnProperty(dim)) {
  25682. dimensions.push(dim);
  25683. }
  25684. }
  25685. var dimSize = dimensions.length;
  25686. if (!dimSize) {
  25687. return;
  25688. }
  25689. var originalCount = this.count();
  25690. var Ctor = getIndicesCtor(this);
  25691. var newIndices = new Ctor(originalCount);
  25692. var offset = 0;
  25693. var dim0 = dimensions[0];
  25694. var min = range[dim0][0];
  25695. var max = range[dim0][1];
  25696. var quickFinished = false;
  25697. if (!this._indices) {
  25698. // Extreme optimization for common case. About 2x faster in chrome.
  25699. var idx = 0;
  25700. if (dimSize === 1) {
  25701. var dimStorage = this._storage[dimensions[0]];
  25702. for (var k = 0; k < this._chunkCount; k++) {
  25703. var chunkStorage = dimStorage[k];
  25704. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  25705. for (var i = 0; i < len; i++) {
  25706. var val = chunkStorage[i]; // NaN will not be filtered. Consider the case, in line chart, empty
  25707. // value indicates the line should be broken. But for the case like
  25708. // scatter plot, a data item with empty value will not be rendered,
  25709. // but the axis extent may be effected if some other dim of the data
  25710. // item has value. Fortunately it is not a significant negative effect.
  25711. if (val >= min && val <= max || isNaN(val)) {
  25712. newIndices[offset++] = idx;
  25713. }
  25714. idx++;
  25715. }
  25716. }
  25717. quickFinished = true;
  25718. } else if (dimSize === 2) {
  25719. var dimStorage = this._storage[dim0];
  25720. var dimStorage2 = this._storage[dimensions[1]];
  25721. var min2 = range[dimensions[1]][0];
  25722. var max2 = range[dimensions[1]][1];
  25723. for (var k = 0; k < this._chunkCount; k++) {
  25724. var chunkStorage = dimStorage[k];
  25725. var chunkStorage2 = dimStorage2[k];
  25726. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  25727. for (var i = 0; i < len; i++) {
  25728. var val = chunkStorage[i];
  25729. var val2 = chunkStorage2[i]; // Do not filter NaN, see comment above.
  25730. if ((val >= min && val <= max || isNaN(val)) && (val2 >= min2 && val2 <= max2 || isNaN(val2))) {
  25731. newIndices[offset++] = idx;
  25732. }
  25733. idx++;
  25734. }
  25735. }
  25736. quickFinished = true;
  25737. }
  25738. }
  25739. if (!quickFinished) {
  25740. if (dimSize === 1) {
  25741. for (var i = 0; i < originalCount; i++) {
  25742. var rawIndex = this.getRawIndex(i);
  25743. var val = this._getFast(dim0, rawIndex); // Do not filter NaN, see comment above.
  25744. if (val >= min && val <= max || isNaN(val)) {
  25745. newIndices[offset++] = rawIndex;
  25746. }
  25747. }
  25748. } else {
  25749. for (var i = 0; i < originalCount; i++) {
  25750. var keep = true;
  25751. var rawIndex = this.getRawIndex(i);
  25752. for (var k = 0; k < dimSize; k++) {
  25753. var dimk = dimensions[k];
  25754. var val = this._getFast(dim, rawIndex); // Do not filter NaN, see comment above.
  25755. if (val < range[dimk][0] || val > range[dimk][1]) {
  25756. keep = false;
  25757. }
  25758. }
  25759. if (keep) {
  25760. newIndices[offset++] = this.getRawIndex(i);
  25761. }
  25762. }
  25763. }
  25764. } // Set indices after filtered.
  25765. if (offset < originalCount) {
  25766. this._indices = newIndices;
  25767. }
  25768. this._count = offset; // Reset data extent
  25769. this._extent = {};
  25770. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  25771. return this;
  25772. };
  25773. /**
  25774. * Data mapping to a plain array
  25775. * @param {string|Array.<string>} [dimensions]
  25776. * @param {Function} cb
  25777. * @param {*} [context=this]
  25778. * @return {Array}
  25779. */
  25780. listProto.mapArray = function (dimensions, cb, context, contextCompat) {
  25781. 'use strict';
  25782. if (typeof dimensions === 'function') {
  25783. contextCompat = context;
  25784. context = cb;
  25785. cb = dimensions;
  25786. dimensions = [];
  25787. } // contextCompat just for compat echarts3
  25788. context = context || contextCompat || this;
  25789. var result = [];
  25790. this.each(dimensions, function () {
  25791. result.push(cb && cb.apply(this, arguments));
  25792. }, context);
  25793. return result;
  25794. }; // Data in excludeDimensions is copied, otherwise transfered.
  25795. function cloneListForMapAndSample(original, excludeDimensions) {
  25796. var allDimensions = original.dimensions;
  25797. var list = new List(map(allDimensions, original.getDimensionInfo, original), original.hostModel); // FIXME If needs stackedOn, value may already been stacked
  25798. transferProperties(list, original);
  25799. var storage = list._storage = {};
  25800. var originalStorage = original._storage; // Init storage
  25801. for (var i = 0; i < allDimensions.length; i++) {
  25802. var dim = allDimensions[i];
  25803. if (originalStorage[dim]) {
  25804. // Notice that we do not reset invertedIndicesMap here, becuase
  25805. // there is no scenario of mapping or sampling ordinal dimension.
  25806. if (indexOf(excludeDimensions, dim) >= 0) {
  25807. storage[dim] = cloneDimStore(originalStorage[dim]);
  25808. list._rawExtent[dim] = getInitialExtent();
  25809. list._extent[dim] = null;
  25810. } else {
  25811. // Direct reference for other dimensions
  25812. storage[dim] = originalStorage[dim];
  25813. }
  25814. }
  25815. }
  25816. return list;
  25817. }
  25818. function cloneDimStore(originalDimStore) {
  25819. var newDimStore = new Array(originalDimStore.length);
  25820. for (var j = 0; j < originalDimStore.length; j++) {
  25821. newDimStore[j] = cloneChunk(originalDimStore[j]);
  25822. }
  25823. return newDimStore;
  25824. }
  25825. function getInitialExtent() {
  25826. return [Infinity, -Infinity];
  25827. }
  25828. /**
  25829. * Data mapping to a new List with given dimensions
  25830. * @param {string|Array.<string>} dimensions
  25831. * @param {Function} cb
  25832. * @param {*} [context=this]
  25833. * @return {Array}
  25834. */
  25835. listProto.map = function (dimensions, cb, context, contextCompat) {
  25836. 'use strict'; // contextCompat just for compat echarts3
  25837. context = context || contextCompat || this;
  25838. dimensions = map(normalizeDimensions(dimensions), this.getDimension, this);
  25839. var list = cloneListForMapAndSample(this, dimensions); // Following properties are all immutable.
  25840. // So we can reference to the same value
  25841. list._indices = this._indices;
  25842. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  25843. var storage = list._storage;
  25844. var tmpRetValue = [];
  25845. var chunkSize = this._chunkSize;
  25846. var dimSize = dimensions.length;
  25847. var dataCount = this.count();
  25848. var values = [];
  25849. var rawExtent = list._rawExtent;
  25850. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  25851. for (var dimIndex = 0; dimIndex < dimSize; dimIndex++) {
  25852. values[dimIndex] = this.get(dimensions[dimIndex], dataIndex
  25853. /*, stack */
  25854. );
  25855. }
  25856. values[dimSize] = dataIndex;
  25857. var retValue = cb && cb.apply(context, values);
  25858. if (retValue != null) {
  25859. // a number or string (in oridinal dimension)?
  25860. if (typeof retValue !== 'object') {
  25861. tmpRetValue[0] = retValue;
  25862. retValue = tmpRetValue;
  25863. }
  25864. var rawIndex = this.getRawIndex(dataIndex);
  25865. var chunkIndex = Math.floor(rawIndex / chunkSize);
  25866. var chunkOffset = rawIndex % chunkSize;
  25867. for (var i = 0; i < retValue.length; i++) {
  25868. var dim = dimensions[i];
  25869. var val = retValue[i];
  25870. var rawExtentOnDim = rawExtent[dim];
  25871. var dimStore = storage[dim];
  25872. if (dimStore) {
  25873. dimStore[chunkIndex][chunkOffset] = val;
  25874. }
  25875. if (val < rawExtentOnDim[0]) {
  25876. rawExtentOnDim[0] = val;
  25877. }
  25878. if (val > rawExtentOnDim[1]) {
  25879. rawExtentOnDim[1] = val;
  25880. }
  25881. }
  25882. }
  25883. }
  25884. return list;
  25885. };
  25886. /**
  25887. * Large data down sampling on given dimension
  25888. * @param {string} dimension
  25889. * @param {number} rate
  25890. * @param {Function} sampleValue
  25891. * @param {Function} sampleIndex Sample index for name and id
  25892. */
  25893. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  25894. var list = cloneListForMapAndSample(this, [dimension]);
  25895. var targetStorage = list._storage;
  25896. var frameValues = [];
  25897. var frameSize = Math.floor(1 / rate);
  25898. var dimStore = targetStorage[dimension];
  25899. var len = this.count();
  25900. var chunkSize = this._chunkSize;
  25901. var rawExtentOnDim = list._rawExtent[dimension];
  25902. var newIndices = new (getIndicesCtor(this))(len);
  25903. var offset = 0;
  25904. for (var i = 0; i < len; i += frameSize) {
  25905. // Last frame
  25906. if (frameSize > len - i) {
  25907. frameSize = len - i;
  25908. frameValues.length = frameSize;
  25909. }
  25910. for (var k = 0; k < frameSize; k++) {
  25911. var dataIdx = this.getRawIndex(i + k);
  25912. var originalChunkIndex = Math.floor(dataIdx / chunkSize);
  25913. var originalChunkOffset = dataIdx % chunkSize;
  25914. frameValues[k] = dimStore[originalChunkIndex][originalChunkOffset];
  25915. }
  25916. var value = sampleValue(frameValues);
  25917. var sampleFrameIdx = this.getRawIndex(Math.min(i + sampleIndex(frameValues, value) || 0, len - 1));
  25918. var sampleChunkIndex = Math.floor(sampleFrameIdx / chunkSize);
  25919. var sampleChunkOffset = sampleFrameIdx % chunkSize; // Only write value on the filtered data
  25920. dimStore[sampleChunkIndex][sampleChunkOffset] = value;
  25921. if (value < rawExtentOnDim[0]) {
  25922. rawExtentOnDim[0] = value;
  25923. }
  25924. if (value > rawExtentOnDim[1]) {
  25925. rawExtentOnDim[1] = value;
  25926. }
  25927. newIndices[offset++] = sampleFrameIdx;
  25928. }
  25929. list._count = offset;
  25930. list._indices = newIndices;
  25931. list.getRawIndex = getRawIndexWithIndices;
  25932. return list;
  25933. };
  25934. /**
  25935. * Get model of one data item.
  25936. *
  25937. * @param {number} idx
  25938. */
  25939. // FIXME Model proxy ?
  25940. listProto.getItemModel = function (idx) {
  25941. var hostModel = this.hostModel;
  25942. return new Model(this.getRawDataItem(idx), hostModel, hostModel && hostModel.ecModel);
  25943. };
  25944. /**
  25945. * Create a data differ
  25946. * @param {module:echarts/data/List} otherList
  25947. * @return {module:echarts/data/DataDiffer}
  25948. */
  25949. listProto.diff = function (otherList) {
  25950. var thisList = this;
  25951. return new DataDiffer(otherList ? otherList.getIndices() : [], this.getIndices(), function (idx) {
  25952. return getId(otherList, idx);
  25953. }, function (idx) {
  25954. return getId(thisList, idx);
  25955. });
  25956. };
  25957. /**
  25958. * Get visual property.
  25959. * @param {string} key
  25960. */
  25961. listProto.getVisual = function (key) {
  25962. var visual = this._visual;
  25963. return visual && visual[key];
  25964. };
  25965. /**
  25966. * Set visual property
  25967. * @param {string|Object} key
  25968. * @param {*} [value]
  25969. *
  25970. * @example
  25971. * setVisual('color', color);
  25972. * setVisual({
  25973. * 'color': color
  25974. * });
  25975. */
  25976. listProto.setVisual = function (key, val) {
  25977. if (isObject$4(key)) {
  25978. for (var name in key) {
  25979. if (key.hasOwnProperty(name)) {
  25980. this.setVisual(name, key[name]);
  25981. }
  25982. }
  25983. return;
  25984. }
  25985. this._visual = this._visual || {};
  25986. this._visual[key] = val;
  25987. };
  25988. /**
  25989. * Set layout property.
  25990. * @param {string|Object} key
  25991. * @param {*} [val]
  25992. */
  25993. listProto.setLayout = function (key, val) {
  25994. if (isObject$4(key)) {
  25995. for (var name in key) {
  25996. if (key.hasOwnProperty(name)) {
  25997. this.setLayout(name, key[name]);
  25998. }
  25999. }
  26000. return;
  26001. }
  26002. this._layout[key] = val;
  26003. };
  26004. /**
  26005. * Get layout property.
  26006. * @param {string} key.
  26007. * @return {*}
  26008. */
  26009. listProto.getLayout = function (key) {
  26010. return this._layout[key];
  26011. };
  26012. /**
  26013. * Get layout of single data item
  26014. * @param {number} idx
  26015. */
  26016. listProto.getItemLayout = function (idx) {
  26017. return this._itemLayouts[idx];
  26018. };
  26019. /**
  26020. * Set layout of single data item
  26021. * @param {number} idx
  26022. * @param {Object} layout
  26023. * @param {boolean=} [merge=false]
  26024. */
  26025. listProto.setItemLayout = function (idx, layout, merge$$1) {
  26026. this._itemLayouts[idx] = merge$$1 ? extend(this._itemLayouts[idx] || {}, layout) : layout;
  26027. };
  26028. /**
  26029. * Clear all layout of single data item
  26030. */
  26031. listProto.clearItemLayouts = function () {
  26032. this._itemLayouts.length = 0;
  26033. };
  26034. /**
  26035. * Get visual property of single data item
  26036. * @param {number} idx
  26037. * @param {string} key
  26038. * @param {boolean} [ignoreParent=false]
  26039. */
  26040. listProto.getItemVisual = function (idx, key, ignoreParent) {
  26041. var itemVisual = this._itemVisuals[idx];
  26042. var val = itemVisual && itemVisual[key];
  26043. if (val == null && !ignoreParent) {
  26044. // Use global visual property
  26045. return this.getVisual(key);
  26046. }
  26047. return val;
  26048. };
  26049. /**
  26050. * Set visual property of single data item
  26051. *
  26052. * @param {number} idx
  26053. * @param {string|Object} key
  26054. * @param {*} [value]
  26055. *
  26056. * @example
  26057. * setItemVisual(0, 'color', color);
  26058. * setItemVisual(0, {
  26059. * 'color': color
  26060. * });
  26061. */
  26062. listProto.setItemVisual = function (idx, key, value) {
  26063. var itemVisual = this._itemVisuals[idx] || {};
  26064. var hasItemVisual = this.hasItemVisual;
  26065. this._itemVisuals[idx] = itemVisual;
  26066. if (isObject$4(key)) {
  26067. for (var name in key) {
  26068. if (key.hasOwnProperty(name)) {
  26069. itemVisual[name] = key[name];
  26070. hasItemVisual[name] = true;
  26071. }
  26072. }
  26073. return;
  26074. }
  26075. itemVisual[key] = value;
  26076. hasItemVisual[key] = true;
  26077. };
  26078. /**
  26079. * Clear itemVisuals and list visual.
  26080. */
  26081. listProto.clearAllVisual = function () {
  26082. this._visual = {};
  26083. this._itemVisuals = [];
  26084. this.hasItemVisual = {};
  26085. };
  26086. var setItemDataAndSeriesIndex = function (child) {
  26087. child.seriesIndex = this.seriesIndex;
  26088. child.dataIndex = this.dataIndex;
  26089. child.dataType = this.dataType;
  26090. };
  26091. /**
  26092. * Set graphic element relative to data. It can be set as null
  26093. * @param {number} idx
  26094. * @param {module:zrender/Element} [el]
  26095. */
  26096. listProto.setItemGraphicEl = function (idx, el) {
  26097. var hostModel = this.hostModel;
  26098. if (el) {
  26099. // Add data index and series index for indexing the data by element
  26100. // Useful in tooltip
  26101. el.dataIndex = idx;
  26102. el.dataType = this.dataType;
  26103. el.seriesIndex = hostModel && hostModel.seriesIndex;
  26104. if (el.type === 'group') {
  26105. el.traverse(setItemDataAndSeriesIndex, el);
  26106. }
  26107. }
  26108. this._graphicEls[idx] = el;
  26109. };
  26110. /**
  26111. * @param {number} idx
  26112. * @return {module:zrender/Element}
  26113. */
  26114. listProto.getItemGraphicEl = function (idx) {
  26115. return this._graphicEls[idx];
  26116. };
  26117. /**
  26118. * @param {Function} cb
  26119. * @param {*} context
  26120. */
  26121. listProto.eachItemGraphicEl = function (cb, context) {
  26122. each$1(this._graphicEls, function (el, idx) {
  26123. if (el) {
  26124. cb && cb.call(context, el, idx);
  26125. }
  26126. });
  26127. };
  26128. /**
  26129. * Shallow clone a new list except visual and layout properties, and graph elements.
  26130. * New list only change the indices.
  26131. */
  26132. listProto.cloneShallow = function (list) {
  26133. if (!list) {
  26134. var dimensionInfoList = map(this.dimensions, this.getDimensionInfo, this);
  26135. list = new List(dimensionInfoList, this.hostModel);
  26136. } // FIXME
  26137. list._storage = this._storage;
  26138. transferProperties(list, this); // Clone will not change the data extent and indices
  26139. if (this._indices) {
  26140. var Ctor = this._indices.constructor;
  26141. list._indices = new Ctor(this._indices);
  26142. } else {
  26143. list._indices = null;
  26144. }
  26145. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  26146. return list;
  26147. };
  26148. /**
  26149. * Wrap some method to add more feature
  26150. * @param {string} methodName
  26151. * @param {Function} injectFunction
  26152. */
  26153. listProto.wrapMethod = function (methodName, injectFunction) {
  26154. var originalMethod = this[methodName];
  26155. if (typeof originalMethod !== 'function') {
  26156. return;
  26157. }
  26158. this.__wrappedMethods = this.__wrappedMethods || [];
  26159. this.__wrappedMethods.push(methodName);
  26160. this[methodName] = function () {
  26161. var res = originalMethod.apply(this, arguments);
  26162. return injectFunction.apply(this, [res].concat(slice(arguments)));
  26163. };
  26164. }; // Methods that create a new list based on this list should be listed here.
  26165. // Notice that those method should `RETURN` the new list.
  26166. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map']; // Methods that change indices of this list should be listed here.
  26167. listProto.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  26168. /*
  26169. * Licensed to the Apache Software Foundation (ASF) under one
  26170. * or more contributor license agreements. See the NOTICE file
  26171. * distributed with this work for additional information
  26172. * regarding copyright ownership. The ASF licenses this file
  26173. * to you under the Apache License, Version 2.0 (the
  26174. * "License"); you may not use this file except in compliance
  26175. * with the License. You may obtain a copy of the License at
  26176. *
  26177. * http://www.apache.org/licenses/LICENSE-2.0
  26178. *
  26179. * Unless required by applicable law or agreed to in writing,
  26180. * software distributed under the License is distributed on an
  26181. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26182. * KIND, either express or implied. See the License for the
  26183. * specific language governing permissions and limitations
  26184. * under the License.
  26185. */
  26186. /**
  26187. * @deprecated
  26188. * Use `echarts/data/helper/createDimensions` instead.
  26189. */
  26190. /**
  26191. * @see {module:echarts/test/ut/spec/data/completeDimensions}
  26192. *
  26193. * This method builds the relationship between:
  26194. * + "what the coord sys or series requires (see `sysDims`)",
  26195. * + "what the user defines (in `encode` and `dimensions`, see `opt.dimsDef` and `opt.encodeDef`)"
  26196. * + "what the data source provids (see `source`)".
  26197. *
  26198. * Some guess strategy will be adapted if user does not define something.
  26199. * If no 'value' dimension specified, the first no-named dimension will be
  26200. * named as 'value'.
  26201. *
  26202. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  26203. * provides not only dim template, but also default order.
  26204. * properties: 'name', 'type', 'displayName'.
  26205. * `name` of each item provides default coord name.
  26206. * [{dimsDef: [string|Object, ...]}, ...] dimsDef of sysDim item provides default dim name, and
  26207. * provide dims count that the sysDim required.
  26208. * [{ordinalMeta}] can be specified.
  26209. * @param {module:echarts/data/Source|Array|Object} source or data (for compatibal with pervious)
  26210. * @param {Object} [opt]
  26211. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  26212. * For example: ['asdf', {name, type}, ...].
  26213. * @param {Object|HashMap} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  26214. * @param {Function} [opt.encodeDefaulter] Called if no `opt.encodeDef` exists.
  26215. * If not specified, auto find the next available data dim.
  26216. * param source {module:data/Source}
  26217. * param dimCount {number}
  26218. * return {Object} encode Never be `null/undefined`.
  26219. * @param {string} [opt.generateCoord] Generate coord dim with the given name.
  26220. * If not specified, extra dim names will be:
  26221. * 'value', 'value0', 'value1', ...
  26222. * @param {number} [opt.generateCoordCount] By default, the generated dim name is `generateCoord`.
  26223. * If `generateCoordCount` specified, the generated dim names will be:
  26224. * `generateCoord` + 0, `generateCoord` + 1, ...
  26225. * can be Infinity, indicate that use all of the remain columns.
  26226. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  26227. * @return {Array.<module:data/DataDimensionInfo>}
  26228. */
  26229. function completeDimensions(sysDims, source, opt) {
  26230. if (!Source.isInstance(source)) {
  26231. source = Source.seriesDataToSource(source);
  26232. }
  26233. opt = opt || {};
  26234. sysDims = (sysDims || []).slice();
  26235. var dimsDef = (opt.dimsDef || []).slice();
  26236. var dataDimNameMap = createHashMap();
  26237. var coordDimNameMap = createHashMap(); // var valueCandidate;
  26238. var result = [];
  26239. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimCount); // Apply user defined dims (`name` and `type`) and init result.
  26240. for (var i = 0; i < dimCount; i++) {
  26241. var dimDefItem = dimsDef[i] = extend({}, isObject$1(dimsDef[i]) ? dimsDef[i] : {
  26242. name: dimsDef[i]
  26243. });
  26244. var userDimName = dimDefItem.name;
  26245. var resultItem = result[i] = new DataDimensionInfo(); // Name will be applied later for avoiding duplication.
  26246. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  26247. // Only if `series.dimensions` is defined in option
  26248. // displayName, will be set, and dimension will be diplayed vertically in
  26249. // tooltip by default.
  26250. resultItem.name = resultItem.displayName = userDimName;
  26251. dataDimNameMap.set(userDimName, i);
  26252. }
  26253. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  26254. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  26255. }
  26256. var encodeDef = opt.encodeDef;
  26257. if (!encodeDef && opt.encodeDefaulter) {
  26258. encodeDef = opt.encodeDefaulter(source, dimCount);
  26259. }
  26260. encodeDef = createHashMap(encodeDef); // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  26261. encodeDef.each(function (dataDims, coordDim) {
  26262. dataDims = normalizeToArray(dataDims).slice(); // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  26263. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  26264. // this case.
  26265. if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
  26266. encodeDef.set(coordDim, false);
  26267. return;
  26268. }
  26269. var validDataDims = encodeDef.set(coordDim, []);
  26270. each$1(dataDims, function (resultDimIdx, idx) {
  26271. // The input resultDimIdx can be dim name or index.
  26272. isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  26273. if (resultDimIdx != null && resultDimIdx < dimCount) {
  26274. validDataDims[idx] = resultDimIdx;
  26275. applyDim(result[resultDimIdx], coordDim, idx);
  26276. }
  26277. });
  26278. }); // Apply templetes and default order from `sysDims`.
  26279. var availDimIdx = 0;
  26280. each$1(sysDims, function (sysDimItem, sysDimIndex) {
  26281. var coordDim;
  26282. var sysDimItem;
  26283. var sysDimItemDimsDef;
  26284. var sysDimItemOtherDims;
  26285. if (isString(sysDimItem)) {
  26286. coordDim = sysDimItem;
  26287. sysDimItem = {};
  26288. } else {
  26289. coordDim = sysDimItem.name;
  26290. var ordinalMeta = sysDimItem.ordinalMeta;
  26291. sysDimItem.ordinalMeta = null;
  26292. sysDimItem = clone(sysDimItem);
  26293. sysDimItem.ordinalMeta = ordinalMeta; // `coordDimIndex` should not be set directly.
  26294. sysDimItemDimsDef = sysDimItem.dimsDef;
  26295. sysDimItemOtherDims = sysDimItem.otherDims;
  26296. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  26297. }
  26298. var dataDims = encodeDef.get(coordDim); // negative resultDimIdx means no need to mapping.
  26299. if (dataDims === false) {
  26300. return;
  26301. }
  26302. var dataDims = normalizeToArray(dataDims); // dimensions provides default dim sequences.
  26303. if (!dataDims.length) {
  26304. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  26305. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  26306. availDimIdx++;
  26307. }
  26308. availDimIdx < result.length && dataDims.push(availDimIdx++);
  26309. }
  26310. } // Apply templates.
  26311. each$1(dataDims, function (resultDimIdx, coordDimIndex) {
  26312. var resultItem = result[resultDimIdx];
  26313. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  26314. if (resultItem.name == null && sysDimItemDimsDef) {
  26315. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  26316. !isObject$1(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {
  26317. name: sysDimItemDimsDefItem
  26318. });
  26319. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  26320. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  26321. } // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  26322. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  26323. });
  26324. });
  26325. function applyDim(resultItem, coordDim, coordDimIndex) {
  26326. if (OTHER_DIMENSIONS.get(coordDim) != null) {
  26327. resultItem.otherDims[coordDim] = coordDimIndex;
  26328. } else {
  26329. resultItem.coordDim = coordDim;
  26330. resultItem.coordDimIndex = coordDimIndex;
  26331. coordDimNameMap.set(coordDim, true);
  26332. }
  26333. } // Make sure the first extra dim is 'value'.
  26334. var generateCoord = opt.generateCoord;
  26335. var generateCoordCount = opt.generateCoordCount;
  26336. var fromZero = generateCoordCount != null;
  26337. generateCoordCount = generateCoord ? generateCoordCount || 1 : 0;
  26338. var extra = generateCoord || 'value'; // Set dim `name` and other `coordDim` and other props.
  26339. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  26340. var resultItem = result[resultDimIdx] = result[resultDimIdx] || new DataDimensionInfo();
  26341. var coordDim = resultItem.coordDim;
  26342. if (coordDim == null) {
  26343. resultItem.coordDim = genName(extra, coordDimNameMap, fromZero);
  26344. resultItem.coordDimIndex = 0;
  26345. if (!generateCoord || generateCoordCount <= 0) {
  26346. resultItem.isExtraCoord = true;
  26347. }
  26348. generateCoordCount--;
  26349. }
  26350. resultItem.name == null && (resultItem.name = genName(resultItem.coordDim, dataDimNameMap));
  26351. if (resultItem.type == null && (guessOrdinal(source, resultDimIdx, resultItem.name) === BE_ORDINAL.Must // Consider the case:
  26352. // {
  26353. // dataset: {source: [
  26354. // ['2001', 123],
  26355. // ['2002', 456],
  26356. // ...
  26357. // ['The others', 987],
  26358. // ]},
  26359. // series: {type: 'pie'}
  26360. // }
  26361. // The first colum should better be treated as a "ordinal" although it
  26362. // might not able to be detected as an "ordinal" by `guessOrdinal`.
  26363. || resultItem.isExtraCoord && (resultItem.otherDims.itemName != null || resultItem.otherDims.seriesName != null))) {
  26364. resultItem.type = 'ordinal';
  26365. }
  26366. }
  26367. return result;
  26368. } // ??? TODO
  26369. // Originally detect dimCount by data[0]. Should we
  26370. // optimize it to only by sysDims and dimensions and encode.
  26371. // So only necessary dims will be initialized.
  26372. // But
  26373. // (1) custom series should be considered. where other dims
  26374. // may be visited.
  26375. // (2) sometimes user need to calcualte bubble size or use visualMap
  26376. // on other dimensions besides coordSys needed.
  26377. // So, dims that is not used by system, should be shared in storage?
  26378. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  26379. // Note that the result dimCount should not small than columns count
  26380. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  26381. var dimCount = Math.max(source.dimensionsDetectCount || 1, sysDims.length, dimsDef.length, optDimCount || 0);
  26382. each$1(sysDims, function (sysDimItem) {
  26383. var sysDimItemDimsDef = sysDimItem.dimsDef;
  26384. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  26385. });
  26386. return dimCount;
  26387. }
  26388. function genName(name, map$$1, fromZero) {
  26389. if (fromZero || map$$1.get(name) != null) {
  26390. var i = 0;
  26391. while (map$$1.get(name + i) != null) {
  26392. i++;
  26393. }
  26394. name += i;
  26395. }
  26396. map$$1.set(name, true);
  26397. return name;
  26398. }
  26399. /*
  26400. * Licensed to the Apache Software Foundation (ASF) under one
  26401. * or more contributor license agreements. See the NOTICE file
  26402. * distributed with this work for additional information
  26403. * regarding copyright ownership. The ASF licenses this file
  26404. * to you under the Apache License, Version 2.0 (the
  26405. * "License"); you may not use this file except in compliance
  26406. * with the License. You may obtain a copy of the License at
  26407. *
  26408. * http://www.apache.org/licenses/LICENSE-2.0
  26409. *
  26410. * Unless required by applicable law or agreed to in writing,
  26411. * software distributed under the License is distributed on an
  26412. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26413. * KIND, either express or implied. See the License for the
  26414. * specific language governing permissions and limitations
  26415. * under the License.
  26416. */
  26417. /**
  26418. * Substitute `completeDimensions`.
  26419. * `completeDimensions` is to be deprecated.
  26420. */
  26421. /**
  26422. * @param {module:echarts/data/Source|module:echarts/data/List} source or data.
  26423. * @param {Object|Array} [opt]
  26424. * @param {Array.<string|Object>} [opt.coordDimensions=[]]
  26425. * @param {number} [opt.dimensionsCount]
  26426. * @param {string} [opt.generateCoord]
  26427. * @param {string} [opt.generateCoordCount]
  26428. * @param {Array.<string|Object>} [opt.dimensionsDefine=source.dimensionsDefine] Overwrite source define.
  26429. * @param {Object|HashMap} [opt.encodeDefine=source.encodeDefine] Overwrite source define.
  26430. * @param {Function} [opt.encodeDefaulter] Make default encode if user not specified.
  26431. * @return {Array.<Object>} dimensionsInfo
  26432. */
  26433. var createDimensions = function (source, opt) {
  26434. opt = opt || {};
  26435. return completeDimensions(opt.coordDimensions || [], source, {
  26436. dimsDef: opt.dimensionsDefine || source.dimensionsDefine,
  26437. encodeDef: opt.encodeDefine || source.encodeDefine,
  26438. dimCount: opt.dimensionsCount,
  26439. encodeDefaulter: opt.encodeDefaulter,
  26440. generateCoord: opt.generateCoord,
  26441. generateCoordCount: opt.generateCoordCount
  26442. });
  26443. };
  26444. /*
  26445. * Licensed to the Apache Software Foundation (ASF) under one
  26446. * or more contributor license agreements. See the NOTICE file
  26447. * distributed with this work for additional information
  26448. * regarding copyright ownership. The ASF licenses this file
  26449. * to you under the Apache License, Version 2.0 (the
  26450. * "License"); you may not use this file except in compliance
  26451. * with the License. You may obtain a copy of the License at
  26452. *
  26453. * http://www.apache.org/licenses/LICENSE-2.0
  26454. *
  26455. * Unless required by applicable law or agreed to in writing,
  26456. * software distributed under the License is distributed on an
  26457. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26458. * KIND, either express or implied. See the License for the
  26459. * specific language governing permissions and limitations
  26460. * under the License.
  26461. */
  26462. /**
  26463. * Helper for model references.
  26464. * There are many manners to refer axis/coordSys.
  26465. */
  26466. // TODO
  26467. // merge relevant logic to this file?
  26468. // check: "modelHelper" of tooltip and "BrushTargetManager".
  26469. /**
  26470. * @class
  26471. * For example:
  26472. * {
  26473. * coordSysName: 'cartesian2d',
  26474. * coordSysDims: ['x', 'y', ...],
  26475. * axisMap: HashMap({
  26476. * x: xAxisModel,
  26477. * y: yAxisModel
  26478. * }),
  26479. * categoryAxisMap: HashMap({
  26480. * x: xAxisModel,
  26481. * y: undefined
  26482. * }),
  26483. * // The index of the first category axis in `coordSysDims`.
  26484. * // `null/undefined` means no category axis exists.
  26485. * firstCategoryDimIndex: 1,
  26486. * // To replace user specified encode.
  26487. * }
  26488. */
  26489. function CoordSysInfo(coordSysName) {
  26490. /**
  26491. * @type {string}
  26492. */
  26493. this.coordSysName = coordSysName;
  26494. /**
  26495. * @type {Array.<string>}
  26496. */
  26497. this.coordSysDims = [];
  26498. /**
  26499. * @type {module:zrender/core/util#HashMap}
  26500. */
  26501. this.axisMap = createHashMap();
  26502. /**
  26503. * @type {module:zrender/core/util#HashMap}
  26504. */
  26505. this.categoryAxisMap = createHashMap();
  26506. /**
  26507. * @type {number}
  26508. */
  26509. this.firstCategoryDimIndex = null;
  26510. }
  26511. /**
  26512. * @return {module:model/referHelper#CoordSysInfo}
  26513. */
  26514. function getCoordSysInfoBySeries(seriesModel) {
  26515. var coordSysName = seriesModel.get('coordinateSystem');
  26516. var result = new CoordSysInfo(coordSysName);
  26517. var fetch = fetchers[coordSysName];
  26518. if (fetch) {
  26519. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  26520. return result;
  26521. }
  26522. }
  26523. var fetchers = {
  26524. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  26525. var xAxisModel = seriesModel.getReferringComponents('xAxis')[0];
  26526. var yAxisModel = seriesModel.getReferringComponents('yAxis')[0];
  26527. result.coordSysDims = ['x', 'y'];
  26528. axisMap.set('x', xAxisModel);
  26529. axisMap.set('y', yAxisModel);
  26530. if (isCategory(xAxisModel)) {
  26531. categoryAxisMap.set('x', xAxisModel);
  26532. result.firstCategoryDimIndex = 0;
  26533. }
  26534. if (isCategory(yAxisModel)) {
  26535. categoryAxisMap.set('y', yAxisModel);
  26536. result.firstCategoryDimIndex == null & (result.firstCategoryDimIndex = 1);
  26537. }
  26538. },
  26539. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  26540. var singleAxisModel = seriesModel.getReferringComponents('singleAxis')[0];
  26541. result.coordSysDims = ['single'];
  26542. axisMap.set('single', singleAxisModel);
  26543. if (isCategory(singleAxisModel)) {
  26544. categoryAxisMap.set('single', singleAxisModel);
  26545. result.firstCategoryDimIndex = 0;
  26546. }
  26547. },
  26548. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  26549. var polarModel = seriesModel.getReferringComponents('polar')[0];
  26550. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  26551. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  26552. result.coordSysDims = ['radius', 'angle'];
  26553. axisMap.set('radius', radiusAxisModel);
  26554. axisMap.set('angle', angleAxisModel);
  26555. if (isCategory(radiusAxisModel)) {
  26556. categoryAxisMap.set('radius', radiusAxisModel);
  26557. result.firstCategoryDimIndex = 0;
  26558. }
  26559. if (isCategory(angleAxisModel)) {
  26560. categoryAxisMap.set('angle', angleAxisModel);
  26561. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  26562. }
  26563. },
  26564. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  26565. result.coordSysDims = ['lng', 'lat'];
  26566. },
  26567. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  26568. var ecModel = seriesModel.ecModel;
  26569. var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  26570. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  26571. each$1(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  26572. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  26573. var axisDim = coordSysDims[index];
  26574. axisMap.set(axisDim, axisModel);
  26575. if (isCategory(axisModel) && result.firstCategoryDimIndex == null) {
  26576. categoryAxisMap.set(axisDim, axisModel);
  26577. result.firstCategoryDimIndex = index;
  26578. }
  26579. });
  26580. }
  26581. };
  26582. function isCategory(axisModel) {
  26583. return axisModel.get('type') === 'category';
  26584. }
  26585. /*
  26586. * Licensed to the Apache Software Foundation (ASF) under one
  26587. * or more contributor license agreements. See the NOTICE file
  26588. * distributed with this work for additional information
  26589. * regarding copyright ownership. The ASF licenses this file
  26590. * to you under the Apache License, Version 2.0 (the
  26591. * "License"); you may not use this file except in compliance
  26592. * with the License. You may obtain a copy of the License at
  26593. *
  26594. * http://www.apache.org/licenses/LICENSE-2.0
  26595. *
  26596. * Unless required by applicable law or agreed to in writing,
  26597. * software distributed under the License is distributed on an
  26598. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26599. * KIND, either express or implied. See the License for the
  26600. * specific language governing permissions and limitations
  26601. * under the License.
  26602. */
  26603. /**
  26604. * Note that it is too complicated to support 3d stack by value
  26605. * (have to create two-dimension inverted index), so in 3d case
  26606. * we just support that stacked by index.
  26607. *
  26608. * @param {module:echarts/model/Series} seriesModel
  26609. * @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
  26610. * The input dimensionInfoList will be modified.
  26611. * @param {Object} [opt]
  26612. * @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
  26613. * @param {boolean} [opt.byIndex=false]
  26614. * @return {Object} calculationInfo
  26615. * {
  26616. * stackedDimension: string
  26617. * stackedByDimension: string
  26618. * isStackedByIndex: boolean
  26619. * stackedOverDimension: string
  26620. * stackResultDimension: string
  26621. * }
  26622. */
  26623. function enableDataStack(seriesModel, dimensionInfoList, opt) {
  26624. opt = opt || {};
  26625. var byIndex = opt.byIndex;
  26626. var stackedCoordDimension = opt.stackedCoordDimension; // Compatibal: when `stack` is set as '', do not stack.
  26627. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  26628. var stackedByDimInfo;
  26629. var stackedDimInfo;
  26630. var stackResultDimension;
  26631. var stackedOverDimension;
  26632. each$1(dimensionInfoList, function (dimensionInfo, index) {
  26633. if (isString(dimensionInfo)) {
  26634. dimensionInfoList[index] = dimensionInfo = {
  26635. name: dimensionInfo
  26636. };
  26637. }
  26638. if (mayStack && !dimensionInfo.isExtraCoord) {
  26639. // Find the first ordinal dimension as the stackedByDimInfo.
  26640. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  26641. stackedByDimInfo = dimensionInfo;
  26642. } // Find the first stackable dimension as the stackedDimInfo.
  26643. if (!stackedDimInfo && dimensionInfo.type !== 'ordinal' && dimensionInfo.type !== 'time' && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)) {
  26644. stackedDimInfo = dimensionInfo;
  26645. }
  26646. }
  26647. });
  26648. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  26649. // Compatible with previous design, value axis (time axis) only stack by index.
  26650. // It may make sense if the user provides elaborately constructed data.
  26651. byIndex = true;
  26652. } // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  26653. // That put stack logic in List is for using conveniently in echarts extensions, but it
  26654. // might not be a good way.
  26655. if (stackedDimInfo) {
  26656. // Use a weird name that not duplicated with other names.
  26657. stackResultDimension = '__\0ecstackresult';
  26658. stackedOverDimension = '__\0ecstackedover'; // Create inverted index to fast query index by value.
  26659. if (stackedByDimInfo) {
  26660. stackedByDimInfo.createInvertedIndices = true;
  26661. }
  26662. var stackedDimCoordDim = stackedDimInfo.coordDim;
  26663. var stackedDimType = stackedDimInfo.type;
  26664. var stackedDimCoordIndex = 0;
  26665. each$1(dimensionInfoList, function (dimensionInfo) {
  26666. if (dimensionInfo.coordDim === stackedDimCoordDim) {
  26667. stackedDimCoordIndex++;
  26668. }
  26669. });
  26670. dimensionInfoList.push({
  26671. name: stackResultDimension,
  26672. coordDim: stackedDimCoordDim,
  26673. coordDimIndex: stackedDimCoordIndex,
  26674. type: stackedDimType,
  26675. isExtraCoord: true,
  26676. isCalculationCoord: true
  26677. });
  26678. stackedDimCoordIndex++;
  26679. dimensionInfoList.push({
  26680. name: stackedOverDimension,
  26681. // This dimension contains stack base (generally, 0), so do not set it as
  26682. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  26683. coordDim: stackedOverDimension,
  26684. coordDimIndex: stackedDimCoordIndex,
  26685. type: stackedDimType,
  26686. isExtraCoord: true,
  26687. isCalculationCoord: true
  26688. });
  26689. }
  26690. return {
  26691. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  26692. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  26693. isStackedByIndex: byIndex,
  26694. stackedOverDimension: stackedOverDimension,
  26695. stackResultDimension: stackResultDimension
  26696. };
  26697. }
  26698. /**
  26699. * @param {module:echarts/data/List} data
  26700. * @param {string} stackedDim
  26701. */
  26702. function isDimensionStacked(data, stackedDim
  26703. /*, stackedByDim*/
  26704. ) {
  26705. // Each single series only maps to one pair of axis. So we do not need to
  26706. // check stackByDim, whatever stacked by a dimension or stacked by index.
  26707. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension'); // && (
  26708. // stackedByDim != null
  26709. // ? stackedByDim === data.getCalculationInfo('stackedByDimension')
  26710. // : data.getCalculationInfo('isStackedByIndex')
  26711. // );
  26712. }
  26713. /**
  26714. * @param {module:echarts/data/List} data
  26715. * @param {string} targetDim
  26716. * @param {string} [stackedByDim] If not input this parameter, check whether
  26717. * stacked by index.
  26718. * @return {string} dimension
  26719. */
  26720. function getStackedDimension(data, targetDim) {
  26721. return isDimensionStacked(data, targetDim) ? data.getCalculationInfo('stackResultDimension') : targetDim;
  26722. }
  26723. /*
  26724. * Licensed to the Apache Software Foundation (ASF) under one
  26725. * or more contributor license agreements. See the NOTICE file
  26726. * distributed with this work for additional information
  26727. * regarding copyright ownership. The ASF licenses this file
  26728. * to you under the Apache License, Version 2.0 (the
  26729. * "License"); you may not use this file except in compliance
  26730. * with the License. You may obtain a copy of the License at
  26731. *
  26732. * http://www.apache.org/licenses/LICENSE-2.0
  26733. *
  26734. * Unless required by applicable law or agreed to in writing,
  26735. * software distributed under the License is distributed on an
  26736. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26737. * KIND, either express or implied. See the License for the
  26738. * specific language governing permissions and limitations
  26739. * under the License.
  26740. */
  26741. /**
  26742. * @param {module:echarts/data/Source|Array} source Or raw data.
  26743. * @param {module:echarts/model/Series} seriesModel
  26744. * @param {Object} [opt]
  26745. * @param {string} [opt.generateCoord]
  26746. * @param {boolean} [opt.useEncodeDefaulter]
  26747. */
  26748. function createListFromArray(source, seriesModel, opt) {
  26749. opt = opt || {};
  26750. if (!Source.isInstance(source)) {
  26751. source = Source.seriesDataToSource(source);
  26752. }
  26753. var coordSysName = seriesModel.get('coordinateSystem');
  26754. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  26755. var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
  26756. var coordSysDimDefs;
  26757. if (coordSysInfo) {
  26758. coordSysDimDefs = map(coordSysInfo.coordSysDims, function (dim) {
  26759. var dimInfo = {
  26760. name: dim
  26761. };
  26762. var axisModel = coordSysInfo.axisMap.get(dim);
  26763. if (axisModel) {
  26764. var axisType = axisModel.get('type');
  26765. dimInfo.type = getDimensionTypeByAxis(axisType); // dimInfo.stackable = isStackable(axisType);
  26766. }
  26767. return dimInfo;
  26768. });
  26769. }
  26770. if (!coordSysDimDefs) {
  26771. // Get dimensions from registered coordinate system
  26772. coordSysDimDefs = registeredCoordSys && (registeredCoordSys.getDimensionsInfo ? registeredCoordSys.getDimensionsInfo() : registeredCoordSys.dimensions.slice()) || ['x', 'y'];
  26773. }
  26774. var dimInfoList = createDimensions(source, {
  26775. coordDimensions: coordSysDimDefs,
  26776. generateCoord: opt.generateCoord,
  26777. encodeDefaulter: opt.useEncodeDefaulter ? curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null
  26778. });
  26779. var firstCategoryDimIndex;
  26780. var hasNameEncode;
  26781. coordSysInfo && each$1(dimInfoList, function (dimInfo, dimIndex) {
  26782. var coordDim = dimInfo.coordDim;
  26783. var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
  26784. if (categoryAxisModel) {
  26785. if (firstCategoryDimIndex == null) {
  26786. firstCategoryDimIndex = dimIndex;
  26787. }
  26788. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  26789. }
  26790. if (dimInfo.otherDims.itemName != null) {
  26791. hasNameEncode = true;
  26792. }
  26793. });
  26794. if (!hasNameEncode && firstCategoryDimIndex != null) {
  26795. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  26796. }
  26797. var stackCalculationInfo = enableDataStack(seriesModel, dimInfoList);
  26798. var list = new List(dimInfoList, seriesModel);
  26799. list.setCalculationInfo(stackCalculationInfo);
  26800. var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source) ? function (itemOpt, dimName, dataIndex, dimIndex) {
  26801. // Use dataIndex as ordinal value in categoryAxis
  26802. return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  26803. } : null;
  26804. list.hasItemOption = false;
  26805. list.initData(source, null, dimValueGetter);
  26806. return list;
  26807. }
  26808. function isNeedCompleteOrdinalData(source) {
  26809. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  26810. var sampleItem = firstDataNotNull(source.data || []);
  26811. return sampleItem != null && !isArray(getDataItemValue(sampleItem));
  26812. }
  26813. }
  26814. function firstDataNotNull(data) {
  26815. var i = 0;
  26816. while (i < data.length && data[i] == null) {
  26817. i++;
  26818. }
  26819. return data[i];
  26820. }
  26821. /*
  26822. * Licensed to the Apache Software Foundation (ASF) under one
  26823. * or more contributor license agreements. See the NOTICE file
  26824. * distributed with this work for additional information
  26825. * regarding copyright ownership. The ASF licenses this file
  26826. * to you under the Apache License, Version 2.0 (the
  26827. * "License"); you may not use this file except in compliance
  26828. * with the License. You may obtain a copy of the License at
  26829. *
  26830. * http://www.apache.org/licenses/LICENSE-2.0
  26831. *
  26832. * Unless required by applicable law or agreed to in writing,
  26833. * software distributed under the License is distributed on an
  26834. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26835. * KIND, either express or implied. See the License for the
  26836. * specific language governing permissions and limitations
  26837. * under the License.
  26838. */
  26839. /**
  26840. * // Scale class management
  26841. * @module echarts/scale/Scale
  26842. */
  26843. /**
  26844. * @param {Object} [setting]
  26845. */
  26846. function Scale(setting) {
  26847. this._setting = setting || {};
  26848. /**
  26849. * Extent
  26850. * @type {Array.<number>}
  26851. * @protected
  26852. */
  26853. this._extent = [Infinity, -Infinity];
  26854. /**
  26855. * Step is calculated in adjustExtent
  26856. * @type {Array.<number>}
  26857. * @protected
  26858. */
  26859. this._interval = 0;
  26860. this.init && this.init.apply(this, arguments);
  26861. }
  26862. /**
  26863. * Parse input val to valid inner number.
  26864. * @param {*} val
  26865. * @return {number}
  26866. */
  26867. Scale.prototype.parse = function (val) {
  26868. // Notice: This would be a trap here, If the implementation
  26869. // of this method depends on extent, and this method is used
  26870. // before extent set (like in dataZoom), it would be wrong.
  26871. // Nevertheless, parse does not depend on extent generally.
  26872. return val;
  26873. };
  26874. Scale.prototype.getSetting = function (name) {
  26875. return this._setting[name];
  26876. };
  26877. Scale.prototype.contain = function (val) {
  26878. var extent = this._extent;
  26879. return val >= extent[0] && val <= extent[1];
  26880. };
  26881. /**
  26882. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  26883. * @param {number} val
  26884. * @return {number}
  26885. */
  26886. Scale.prototype.normalize = function (val) {
  26887. var extent = this._extent;
  26888. if (extent[1] === extent[0]) {
  26889. return 0.5;
  26890. }
  26891. return (val - extent[0]) / (extent[1] - extent[0]);
  26892. };
  26893. /**
  26894. * Scale normalized value
  26895. * @param {number} val
  26896. * @return {number}
  26897. */
  26898. Scale.prototype.scale = function (val) {
  26899. var extent = this._extent;
  26900. return val * (extent[1] - extent[0]) + extent[0];
  26901. };
  26902. /**
  26903. * Set extent from data
  26904. * @param {Array.<number>} other
  26905. */
  26906. Scale.prototype.unionExtent = function (other) {
  26907. var extent = this._extent;
  26908. other[0] < extent[0] && (extent[0] = other[0]);
  26909. other[1] > extent[1] && (extent[1] = other[1]); // not setExtent because in log axis it may transformed to power
  26910. // this.setExtent(extent[0], extent[1]);
  26911. };
  26912. /**
  26913. * Set extent from data
  26914. * @param {module:echarts/data/List} data
  26915. * @param {string} dim
  26916. */
  26917. Scale.prototype.unionExtentFromData = function (data, dim) {
  26918. this.unionExtent(data.getApproximateExtent(dim));
  26919. };
  26920. /**
  26921. * Get extent
  26922. * @return {Array.<number>}
  26923. */
  26924. Scale.prototype.getExtent = function () {
  26925. return this._extent.slice();
  26926. };
  26927. /**
  26928. * Set extent
  26929. * @param {number} start
  26930. * @param {number} end
  26931. */
  26932. Scale.prototype.setExtent = function (start, end) {
  26933. var thisExtent = this._extent;
  26934. if (!isNaN(start)) {
  26935. thisExtent[0] = start;
  26936. }
  26937. if (!isNaN(end)) {
  26938. thisExtent[1] = end;
  26939. }
  26940. };
  26941. /**
  26942. * When axis extent depends on data and no data exists,
  26943. * axis ticks should not be drawn, which is named 'blank'.
  26944. */
  26945. Scale.prototype.isBlank = function () {
  26946. return this._isBlank;
  26947. },
  26948. /**
  26949. * When axis extent depends on data and no data exists,
  26950. * axis ticks should not be drawn, which is named 'blank'.
  26951. */
  26952. Scale.prototype.setBlank = function (isBlank) {
  26953. this._isBlank = isBlank;
  26954. };
  26955. /**
  26956. * @abstract
  26957. * @param {*} tick
  26958. * @return {string} label of the tick.
  26959. */
  26960. Scale.prototype.getLabel = null;
  26961. enableClassExtend(Scale);
  26962. enableClassManagement(Scale, {
  26963. registerWhenExtend: true
  26964. });
  26965. /*
  26966. * Licensed to the Apache Software Foundation (ASF) under one
  26967. * or more contributor license agreements. See the NOTICE file
  26968. * distributed with this work for additional information
  26969. * regarding copyright ownership. The ASF licenses this file
  26970. * to you under the Apache License, Version 2.0 (the
  26971. * "License"); you may not use this file except in compliance
  26972. * with the License. You may obtain a copy of the License at
  26973. *
  26974. * http://www.apache.org/licenses/LICENSE-2.0
  26975. *
  26976. * Unless required by applicable law or agreed to in writing,
  26977. * software distributed under the License is distributed on an
  26978. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26979. * KIND, either express or implied. See the License for the
  26980. * specific language governing permissions and limitations
  26981. * under the License.
  26982. */
  26983. /**
  26984. * @constructor
  26985. * @param {Object} [opt]
  26986. * @param {Object} [opt.categories=[]]
  26987. * @param {Object} [opt.needCollect=false]
  26988. * @param {Object} [opt.deduplication=false]
  26989. */
  26990. function OrdinalMeta(opt) {
  26991. /**
  26992. * @readOnly
  26993. * @type {Array.<string>}
  26994. */
  26995. this.categories = opt.categories || [];
  26996. /**
  26997. * @private
  26998. * @type {boolean}
  26999. */
  27000. this._needCollect = opt.needCollect;
  27001. /**
  27002. * @private
  27003. * @type {boolean}
  27004. */
  27005. this._deduplication = opt.deduplication;
  27006. /**
  27007. * @private
  27008. * @type {boolean}
  27009. */
  27010. this._map;
  27011. }
  27012. /**
  27013. * @param {module:echarts/model/Model} axisModel
  27014. * @return {module:echarts/data/OrdinalMeta}
  27015. */
  27016. OrdinalMeta.createByAxisModel = function (axisModel) {
  27017. var option = axisModel.option;
  27018. var data = option.data;
  27019. var categories = data && map(data, getName);
  27020. return new OrdinalMeta({
  27021. categories: categories,
  27022. needCollect: !categories,
  27023. // deduplication is default in axis.
  27024. deduplication: option.dedplication !== false
  27025. });
  27026. };
  27027. var proto$1 = OrdinalMeta.prototype;
  27028. /**
  27029. * @param {string} category
  27030. * @return {number} ordinal
  27031. */
  27032. proto$1.getOrdinal = function (category) {
  27033. return getOrCreateMap(this).get(category);
  27034. };
  27035. /**
  27036. * @param {*} category
  27037. * @return {number} The ordinal. If not found, return NaN.
  27038. */
  27039. proto$1.parseAndCollect = function (category) {
  27040. var index;
  27041. var needCollect = this._needCollect; // The value of category dim can be the index of the given category set.
  27042. // This feature is only supported when !needCollect, because we should
  27043. // consider a common case: a value is 2017, which is a number but is
  27044. // expected to be tread as a category. This case usually happen in dataset,
  27045. // where it happent to be no need of the index feature.
  27046. if (typeof category !== 'string' && !needCollect) {
  27047. return category;
  27048. } // Optimize for the scenario:
  27049. // category is ['2012-01-01', '2012-01-02', ...], where the input
  27050. // data has been ensured not duplicate and is large data.
  27051. // Notice, if a dataset dimension provide categroies, usually echarts
  27052. // should remove duplication except user tell echarts dont do that
  27053. // (set axis.deduplication = false), because echarts do not know whether
  27054. // the values in the category dimension has duplication (consider the
  27055. // parallel-aqi example)
  27056. if (needCollect && !this._deduplication) {
  27057. index = this.categories.length;
  27058. this.categories[index] = category;
  27059. return index;
  27060. }
  27061. var map$$1 = getOrCreateMap(this);
  27062. index = map$$1.get(category);
  27063. if (index == null) {
  27064. if (needCollect) {
  27065. index = this.categories.length;
  27066. this.categories[index] = category;
  27067. map$$1.set(category, index);
  27068. } else {
  27069. index = NaN;
  27070. }
  27071. }
  27072. return index;
  27073. }; // Consider big data, do not create map until needed.
  27074. function getOrCreateMap(ordinalMeta) {
  27075. return ordinalMeta._map || (ordinalMeta._map = createHashMap(ordinalMeta.categories));
  27076. }
  27077. function getName(obj) {
  27078. if (isObject$1(obj) && obj.value != null) {
  27079. return obj.value;
  27080. } else {
  27081. return obj + '';
  27082. }
  27083. }
  27084. /*
  27085. * Licensed to the Apache Software Foundation (ASF) under one
  27086. * or more contributor license agreements. See the NOTICE file
  27087. * distributed with this work for additional information
  27088. * regarding copyright ownership. The ASF licenses this file
  27089. * to you under the Apache License, Version 2.0 (the
  27090. * "License"); you may not use this file except in compliance
  27091. * with the License. You may obtain a copy of the License at
  27092. *
  27093. * http://www.apache.org/licenses/LICENSE-2.0
  27094. *
  27095. * Unless required by applicable law or agreed to in writing,
  27096. * software distributed under the License is distributed on an
  27097. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27098. * KIND, either express or implied. See the License for the
  27099. * specific language governing permissions and limitations
  27100. * under the License.
  27101. */
  27102. /**
  27103. * Linear continuous scale
  27104. * @module echarts/coord/scale/Ordinal
  27105. *
  27106. * http://en.wikipedia.org/wiki/Level_of_measurement
  27107. */
  27108. // FIXME only one data
  27109. var scaleProto = Scale.prototype;
  27110. var OrdinalScale = Scale.extend({
  27111. type: 'ordinal',
  27112. /**
  27113. * @param {module:echarts/data/OrdianlMeta|Array.<string>} ordinalMeta
  27114. */
  27115. init: function (ordinalMeta, extent) {
  27116. // Caution: Should not use instanceof, consider ec-extensions using
  27117. // import approach to get OrdinalMeta class.
  27118. if (!ordinalMeta || isArray(ordinalMeta)) {
  27119. ordinalMeta = new OrdinalMeta({
  27120. categories: ordinalMeta
  27121. });
  27122. }
  27123. this._ordinalMeta = ordinalMeta;
  27124. this._extent = extent || [0, ordinalMeta.categories.length - 1];
  27125. },
  27126. parse: function (val) {
  27127. return typeof val === 'string' ? this._ordinalMeta.getOrdinal(val) // val might be float.
  27128. : Math.round(val);
  27129. },
  27130. contain: function (rank) {
  27131. rank = this.parse(rank);
  27132. return scaleProto.contain.call(this, rank) && this._ordinalMeta.categories[rank] != null;
  27133. },
  27134. /**
  27135. * Normalize given rank or name to linear [0, 1]
  27136. * @param {number|string} [val]
  27137. * @return {number}
  27138. */
  27139. normalize: function (val) {
  27140. return scaleProto.normalize.call(this, this.parse(val));
  27141. },
  27142. scale: function (val) {
  27143. return Math.round(scaleProto.scale.call(this, val));
  27144. },
  27145. /**
  27146. * @return {Array}
  27147. */
  27148. getTicks: function () {
  27149. var ticks = [];
  27150. var extent = this._extent;
  27151. var rank = extent[0];
  27152. while (rank <= extent[1]) {
  27153. ticks.push(rank);
  27154. rank++;
  27155. }
  27156. return ticks;
  27157. },
  27158. /**
  27159. * Get item on rank n
  27160. * @param {number} n
  27161. * @return {string}
  27162. */
  27163. getLabel: function (n) {
  27164. if (!this.isBlank()) {
  27165. // Note that if no data, ordinalMeta.categories is an empty array.
  27166. return this._ordinalMeta.categories[n];
  27167. }
  27168. },
  27169. /**
  27170. * @return {number}
  27171. */
  27172. count: function () {
  27173. return this._extent[1] - this._extent[0] + 1;
  27174. },
  27175. /**
  27176. * @override
  27177. */
  27178. unionExtentFromData: function (data, dim) {
  27179. this.unionExtent(data.getApproximateExtent(dim));
  27180. },
  27181. getOrdinalMeta: function () {
  27182. return this._ordinalMeta;
  27183. },
  27184. niceTicks: noop,
  27185. niceExtent: noop
  27186. });
  27187. /**
  27188. * @return {module:echarts/scale/Time}
  27189. */
  27190. OrdinalScale.create = function () {
  27191. return new OrdinalScale();
  27192. };
  27193. /*
  27194. * Licensed to the Apache Software Foundation (ASF) under one
  27195. * or more contributor license agreements. See the NOTICE file
  27196. * distributed with this work for additional information
  27197. * regarding copyright ownership. The ASF licenses this file
  27198. * to you under the Apache License, Version 2.0 (the
  27199. * "License"); you may not use this file except in compliance
  27200. * with the License. You may obtain a copy of the License at
  27201. *
  27202. * http://www.apache.org/licenses/LICENSE-2.0
  27203. *
  27204. * Unless required by applicable law or agreed to in writing,
  27205. * software distributed under the License is distributed on an
  27206. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27207. * KIND, either express or implied. See the License for the
  27208. * specific language governing permissions and limitations
  27209. * under the License.
  27210. */
  27211. /**
  27212. * For testable.
  27213. */
  27214. var roundNumber$1 = round$1;
  27215. /**
  27216. * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
  27217. * Should be extent[0] < extent[1].
  27218. * @param {number} splitNumber splitNumber should be >= 1.
  27219. * @param {number} [minInterval]
  27220. * @param {number} [maxInterval]
  27221. * @return {Object} {interval, intervalPrecision, niceTickExtent}
  27222. */
  27223. function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
  27224. var result = {};
  27225. var span = extent[1] - extent[0];
  27226. var interval = result.interval = nice(span / splitNumber, true);
  27227. if (minInterval != null && interval < minInterval) {
  27228. interval = result.interval = minInterval;
  27229. }
  27230. if (maxInterval != null && interval > maxInterval) {
  27231. interval = result.interval = maxInterval;
  27232. } // Tow more digital for tick.
  27233. var precision = result.intervalPrecision = getIntervalPrecision(interval); // Niced extent inside original extent
  27234. var niceTickExtent = result.niceTickExtent = [roundNumber$1(Math.ceil(extent[0] / interval) * interval, precision), roundNumber$1(Math.floor(extent[1] / interval) * interval, precision)];
  27235. fixExtent(niceTickExtent, extent);
  27236. return result;
  27237. }
  27238. /**
  27239. * @param {number} interval
  27240. * @return {number} interval precision
  27241. */
  27242. function getIntervalPrecision(interval) {
  27243. // Tow more digital for tick.
  27244. return getPrecisionSafe(interval) + 2;
  27245. }
  27246. function clamp(niceTickExtent, idx, extent) {
  27247. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  27248. } // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  27249. function fixExtent(niceTickExtent, extent) {
  27250. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  27251. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  27252. clamp(niceTickExtent, 0, extent);
  27253. clamp(niceTickExtent, 1, extent);
  27254. if (niceTickExtent[0] > niceTickExtent[1]) {
  27255. niceTickExtent[0] = niceTickExtent[1];
  27256. }
  27257. }
  27258. /*
  27259. * Licensed to the Apache Software Foundation (ASF) under one
  27260. * or more contributor license agreements. See the NOTICE file
  27261. * distributed with this work for additional information
  27262. * regarding copyright ownership. The ASF licenses this file
  27263. * to you under the Apache License, Version 2.0 (the
  27264. * "License"); you may not use this file except in compliance
  27265. * with the License. You may obtain a copy of the License at
  27266. *
  27267. * http://www.apache.org/licenses/LICENSE-2.0
  27268. *
  27269. * Unless required by applicable law or agreed to in writing,
  27270. * software distributed under the License is distributed on an
  27271. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27272. * KIND, either express or implied. See the License for the
  27273. * specific language governing permissions and limitations
  27274. * under the License.
  27275. */
  27276. /**
  27277. * Interval scale
  27278. * @module echarts/scale/Interval
  27279. */
  27280. var roundNumber = round$1;
  27281. /**
  27282. * @alias module:echarts/coord/scale/Interval
  27283. * @constructor
  27284. */
  27285. var IntervalScale = Scale.extend({
  27286. type: 'interval',
  27287. _interval: 0,
  27288. _intervalPrecision: 2,
  27289. setExtent: function (start, end) {
  27290. var thisExtent = this._extent; //start,end may be a Number like '25',so...
  27291. if (!isNaN(start)) {
  27292. thisExtent[0] = parseFloat(start);
  27293. }
  27294. if (!isNaN(end)) {
  27295. thisExtent[1] = parseFloat(end);
  27296. }
  27297. },
  27298. unionExtent: function (other) {
  27299. var extent = this._extent;
  27300. other[0] < extent[0] && (extent[0] = other[0]);
  27301. other[1] > extent[1] && (extent[1] = other[1]); // unionExtent may called by it's sub classes
  27302. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  27303. },
  27304. /**
  27305. * Get interval
  27306. */
  27307. getInterval: function () {
  27308. return this._interval;
  27309. },
  27310. /**
  27311. * Set interval
  27312. */
  27313. setInterval: function (interval) {
  27314. this._interval = interval; // Dropped auto calculated niceExtent and use user setted extent
  27315. // We assume user wan't to set both interval, min, max to get a better result
  27316. this._niceExtent = this._extent.slice();
  27317. this._intervalPrecision = getIntervalPrecision(interval);
  27318. },
  27319. /**
  27320. * @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
  27321. * @return {Array.<number>}
  27322. */
  27323. getTicks: function (expandToNicedExtent) {
  27324. var interval = this._interval;
  27325. var extent = this._extent;
  27326. var niceTickExtent = this._niceExtent;
  27327. var intervalPrecision = this._intervalPrecision;
  27328. var ticks = []; // If interval is 0, return [];
  27329. if (!interval) {
  27330. return ticks;
  27331. } // Consider this case: using dataZoom toolbox, zoom and zoom.
  27332. var safeLimit = 10000;
  27333. if (extent[0] < niceTickExtent[0]) {
  27334. if (expandToNicedExtent) {
  27335. ticks.push(roundNumber(niceTickExtent[0] - interval, intervalPrecision));
  27336. } else {
  27337. ticks.push(extent[0]);
  27338. }
  27339. }
  27340. var tick = niceTickExtent[0];
  27341. while (tick <= niceTickExtent[1]) {
  27342. ticks.push(tick); // Avoid rounding error
  27343. tick = roundNumber(tick + interval, intervalPrecision);
  27344. if (tick === ticks[ticks.length - 1]) {
  27345. // Consider out of safe float point, e.g.,
  27346. // -3711126.9907707 + 2e-10 === -3711126.9907707
  27347. break;
  27348. }
  27349. if (ticks.length > safeLimit) {
  27350. return [];
  27351. }
  27352. } // Consider this case: the last item of ticks is smaller
  27353. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  27354. var lastNiceTick = ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1];
  27355. if (extent[1] > lastNiceTick) {
  27356. if (expandToNicedExtent) {
  27357. ticks.push(roundNumber(lastNiceTick + interval, intervalPrecision));
  27358. } else {
  27359. ticks.push(extent[1]);
  27360. }
  27361. }
  27362. return ticks;
  27363. },
  27364. /**
  27365. * @param {number} [splitNumber=5]
  27366. * @return {Array.<Array.<number>>}
  27367. */
  27368. getMinorTicks: function (splitNumber) {
  27369. var ticks = this.getTicks(true);
  27370. var minorTicks = [];
  27371. var extent = this.getExtent();
  27372. for (var i = 1; i < ticks.length; i++) {
  27373. var nextTick = ticks[i];
  27374. var prevTick = ticks[i - 1];
  27375. var count = 0;
  27376. var minorTicksGroup = [];
  27377. var interval = nextTick - prevTick;
  27378. var minorInterval = interval / splitNumber;
  27379. while (count < splitNumber - 1) {
  27380. var minorTick = round$1(prevTick + (count + 1) * minorInterval); // For the first and last interval. The count may be less than splitNumber.
  27381. if (minorTick > extent[0] && minorTick < extent[1]) {
  27382. minorTicksGroup.push(minorTick);
  27383. }
  27384. count++;
  27385. }
  27386. minorTicks.push(minorTicksGroup);
  27387. }
  27388. return minorTicks;
  27389. },
  27390. /**
  27391. * @param {number} data
  27392. * @param {Object} [opt]
  27393. * @param {number|string} [opt.precision] If 'auto', use nice presision.
  27394. * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
  27395. * @return {string}
  27396. */
  27397. getLabel: function (data, opt) {
  27398. if (data == null) {
  27399. return '';
  27400. }
  27401. var precision = opt && opt.precision;
  27402. if (precision == null) {
  27403. precision = getPrecisionSafe(data) || 0;
  27404. } else if (precision === 'auto') {
  27405. // Should be more precise then tick.
  27406. precision = this._intervalPrecision;
  27407. } // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  27408. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  27409. data = roundNumber(data, precision, true);
  27410. return addCommas(data);
  27411. },
  27412. /**
  27413. * Update interval and extent of intervals for nice ticks
  27414. *
  27415. * @param {number} [splitNumber = 5] Desired number of ticks
  27416. * @param {number} [minInterval]
  27417. * @param {number} [maxInterval]
  27418. */
  27419. niceTicks: function (splitNumber, minInterval, maxInterval) {
  27420. splitNumber = splitNumber || 5;
  27421. var extent = this._extent;
  27422. var span = extent[1] - extent[0];
  27423. if (!isFinite(span)) {
  27424. return;
  27425. } // User may set axis min 0 and data are all negative
  27426. // FIXME If it needs to reverse ?
  27427. if (span < 0) {
  27428. span = -span;
  27429. extent.reverse();
  27430. }
  27431. var result = intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval);
  27432. this._intervalPrecision = result.intervalPrecision;
  27433. this._interval = result.interval;
  27434. this._niceExtent = result.niceTickExtent;
  27435. },
  27436. /**
  27437. * Nice extent.
  27438. * @param {Object} opt
  27439. * @param {number} [opt.splitNumber = 5] Given approx tick number
  27440. * @param {boolean} [opt.fixMin=false]
  27441. * @param {boolean} [opt.fixMax=false]
  27442. * @param {boolean} [opt.minInterval]
  27443. * @param {boolean} [opt.maxInterval]
  27444. */
  27445. niceExtent: function (opt) {
  27446. var extent = this._extent; // If extent start and end are same, expand them
  27447. if (extent[0] === extent[1]) {
  27448. if (extent[0] !== 0) {
  27449. // Expand extent
  27450. var expandSize = extent[0]; // In the fowllowing case
  27451. // Axis has been fixed max 100
  27452. // Plus data are all 100 and axis extent are [100, 100].
  27453. // Extend to the both side will cause expanded max is larger than fixed max.
  27454. // So only expand to the smaller side.
  27455. if (!opt.fixMax) {
  27456. extent[1] += expandSize / 2;
  27457. extent[0] -= expandSize / 2;
  27458. } else {
  27459. extent[0] -= expandSize / 2;
  27460. }
  27461. } else {
  27462. extent[1] = 1;
  27463. }
  27464. }
  27465. var span = extent[1] - extent[0]; // If there are no data and extent are [Infinity, -Infinity]
  27466. if (!isFinite(span)) {
  27467. extent[0] = 0;
  27468. extent[1] = 1;
  27469. }
  27470. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent;
  27471. var interval = this._interval;
  27472. if (!opt.fixMin) {
  27473. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
  27474. }
  27475. if (!opt.fixMax) {
  27476. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
  27477. }
  27478. }
  27479. });
  27480. /**
  27481. * @return {module:echarts/scale/Time}
  27482. */
  27483. IntervalScale.create = function () {
  27484. return new IntervalScale();
  27485. };
  27486. /*
  27487. * Licensed to the Apache Software Foundation (ASF) under one
  27488. * or more contributor license agreements. See the NOTICE file
  27489. * distributed with this work for additional information
  27490. * regarding copyright ownership. The ASF licenses this file
  27491. * to you under the Apache License, Version 2.0 (the
  27492. * "License"); you may not use this file except in compliance
  27493. * with the License. You may obtain a copy of the License at
  27494. *
  27495. * http://www.apache.org/licenses/LICENSE-2.0
  27496. *
  27497. * Unless required by applicable law or agreed to in writing,
  27498. * software distributed under the License is distributed on an
  27499. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27500. * KIND, either express or implied. See the License for the
  27501. * specific language governing permissions and limitations
  27502. * under the License.
  27503. */
  27504. /* global Float32Array */
  27505. var STACK_PREFIX = '__ec_stack_';
  27506. var LARGE_BAR_MIN_WIDTH = 0.5;
  27507. var LargeArr = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  27508. function getSeriesStackId(seriesModel) {
  27509. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  27510. }
  27511. function getAxisKey(axis) {
  27512. return axis.dim + axis.index;
  27513. }
  27514. /**
  27515. * @param {Object} opt
  27516. * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
  27517. * @param {number} opt.count Positive interger.
  27518. * @param {number} [opt.barWidth]
  27519. * @param {number} [opt.barMaxWidth]
  27520. * @param {number} [opt.barMinWidth]
  27521. * @param {number} [opt.barGap]
  27522. * @param {number} [opt.barCategoryGap]
  27523. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  27524. */
  27525. function getLayoutOnAxis(opt) {
  27526. var params = [];
  27527. var baseAxis = opt.axis;
  27528. var axisKey = 'axis0';
  27529. if (baseAxis.type !== 'category') {
  27530. return;
  27531. }
  27532. var bandWidth = baseAxis.getBandWidth();
  27533. for (var i = 0; i < opt.count || 0; i++) {
  27534. params.push(defaults({
  27535. bandWidth: bandWidth,
  27536. axisKey: axisKey,
  27537. stackId: STACK_PREFIX + i
  27538. }, opt));
  27539. }
  27540. var widthAndOffsets = doCalBarWidthAndOffset(params);
  27541. var result = [];
  27542. for (var i = 0; i < opt.count; i++) {
  27543. var item = widthAndOffsets[axisKey][STACK_PREFIX + i];
  27544. item.offsetCenter = item.offset + item.width / 2;
  27545. result.push(item);
  27546. }
  27547. return result;
  27548. }
  27549. function prepareLayoutBarSeries(seriesType, ecModel) {
  27550. var seriesModels = [];
  27551. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  27552. // Check series coordinate, do layout for cartesian2d only
  27553. if (isOnCartesian(seriesModel) && !isInLargeMode(seriesModel)) {
  27554. seriesModels.push(seriesModel);
  27555. }
  27556. });
  27557. return seriesModels;
  27558. }
  27559. /**
  27560. * Map from (baseAxis.dim + '_' + baseAxis.index) to min gap of two adjacent
  27561. * values.
  27562. * This works for time axes, value axes, and log axes.
  27563. * For a single time axis, return value is in the form like
  27564. * {'x_0': [1000000]}.
  27565. * The value of 1000000 is in milliseconds.
  27566. */
  27567. function getValueAxesMinGaps(barSeries) {
  27568. /**
  27569. * Map from axis.index to values.
  27570. * For a single time axis, axisValues is in the form like
  27571. * {'x_0': [1495555200000, 1495641600000, 1495728000000]}.
  27572. * Items in axisValues[x], e.g. 1495555200000, are time values of all
  27573. * series.
  27574. */
  27575. var axisValues = {};
  27576. each$1(barSeries, function (seriesModel) {
  27577. var cartesian = seriesModel.coordinateSystem;
  27578. var baseAxis = cartesian.getBaseAxis();
  27579. if (baseAxis.type !== 'time' && baseAxis.type !== 'value') {
  27580. return;
  27581. }
  27582. var data = seriesModel.getData();
  27583. var key = baseAxis.dim + '_' + baseAxis.index;
  27584. var dim = data.mapDimension(baseAxis.dim);
  27585. for (var i = 0, cnt = data.count(); i < cnt; ++i) {
  27586. var value = data.get(dim, i);
  27587. if (!axisValues[key]) {
  27588. // No previous data for the axis
  27589. axisValues[key] = [value];
  27590. } else {
  27591. // No value in previous series
  27592. axisValues[key].push(value);
  27593. } // Ignore duplicated time values in the same axis
  27594. }
  27595. });
  27596. var axisMinGaps = [];
  27597. for (var key in axisValues) {
  27598. if (axisValues.hasOwnProperty(key)) {
  27599. var valuesInAxis = axisValues[key];
  27600. if (valuesInAxis) {
  27601. // Sort axis values into ascending order to calculate gaps
  27602. valuesInAxis.sort(function (a, b) {
  27603. return a - b;
  27604. });
  27605. var min = null;
  27606. for (var j = 1; j < valuesInAxis.length; ++j) {
  27607. var delta = valuesInAxis[j] - valuesInAxis[j - 1];
  27608. if (delta > 0) {
  27609. // Ignore 0 delta because they are of the same axis value
  27610. min = min === null ? delta : Math.min(min, delta);
  27611. }
  27612. } // Set to null if only have one data
  27613. axisMinGaps[key] = min;
  27614. }
  27615. }
  27616. }
  27617. return axisMinGaps;
  27618. }
  27619. function makeColumnLayout(barSeries) {
  27620. var axisMinGaps = getValueAxesMinGaps(barSeries);
  27621. var seriesInfoList = [];
  27622. each$1(barSeries, function (seriesModel) {
  27623. var cartesian = seriesModel.coordinateSystem;
  27624. var baseAxis = cartesian.getBaseAxis();
  27625. var axisExtent = baseAxis.getExtent();
  27626. var bandWidth;
  27627. if (baseAxis.type === 'category') {
  27628. bandWidth = baseAxis.getBandWidth();
  27629. } else if (baseAxis.type === 'value' || baseAxis.type === 'time') {
  27630. var key = baseAxis.dim + '_' + baseAxis.index;
  27631. var minGap = axisMinGaps[key];
  27632. var extentSpan = Math.abs(axisExtent[1] - axisExtent[0]);
  27633. var scale = baseAxis.scale.getExtent();
  27634. var scaleSpan = Math.abs(scale[1] - scale[0]);
  27635. bandWidth = minGap ? extentSpan / scaleSpan * minGap : extentSpan; // When there is only one data value
  27636. } else {
  27637. var data = seriesModel.getData();
  27638. bandWidth = Math.abs(axisExtent[1] - axisExtent[0]) / data.count();
  27639. }
  27640. var barWidth = parsePercent$1(seriesModel.get('barWidth'), bandWidth);
  27641. var barMaxWidth = parsePercent$1(seriesModel.get('barMaxWidth'), bandWidth);
  27642. var barMinWidth = parsePercent$1( // barMinWidth by default is 1 in cartesian. Because in value axis,
  27643. // the auto-calculated bar width might be less than 1.
  27644. seriesModel.get('barMinWidth') || 1, bandWidth);
  27645. var barGap = seriesModel.get('barGap');
  27646. var barCategoryGap = seriesModel.get('barCategoryGap');
  27647. seriesInfoList.push({
  27648. bandWidth: bandWidth,
  27649. barWidth: barWidth,
  27650. barMaxWidth: barMaxWidth,
  27651. barMinWidth: barMinWidth,
  27652. barGap: barGap,
  27653. barCategoryGap: barCategoryGap,
  27654. axisKey: getAxisKey(baseAxis),
  27655. stackId: getSeriesStackId(seriesModel)
  27656. });
  27657. });
  27658. return doCalBarWidthAndOffset(seriesInfoList);
  27659. }
  27660. function doCalBarWidthAndOffset(seriesInfoList) {
  27661. // Columns info on each category axis. Key is cartesian name
  27662. var columnsMap = {};
  27663. each$1(seriesInfoList, function (seriesInfo, idx) {
  27664. var axisKey = seriesInfo.axisKey;
  27665. var bandWidth = seriesInfo.bandWidth;
  27666. var columnsOnAxis = columnsMap[axisKey] || {
  27667. bandWidth: bandWidth,
  27668. remainedWidth: bandWidth,
  27669. autoWidthCount: 0,
  27670. categoryGap: '20%',
  27671. gap: '30%',
  27672. stacks: {}
  27673. };
  27674. var stacks = columnsOnAxis.stacks;
  27675. columnsMap[axisKey] = columnsOnAxis;
  27676. var stackId = seriesInfo.stackId;
  27677. if (!stacks[stackId]) {
  27678. columnsOnAxis.autoWidthCount++;
  27679. }
  27680. stacks[stackId] = stacks[stackId] || {
  27681. width: 0,
  27682. maxWidth: 0
  27683. }; // Caution: In a single coordinate system, these barGrid attributes
  27684. // will be shared by series. Consider that they have default values,
  27685. // only the attributes set on the last series will work.
  27686. // Do not change this fact unless there will be a break change.
  27687. var barWidth = seriesInfo.barWidth;
  27688. if (barWidth && !stacks[stackId].width) {
  27689. // See #6312, do not restrict width.
  27690. stacks[stackId].width = barWidth;
  27691. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  27692. columnsOnAxis.remainedWidth -= barWidth;
  27693. }
  27694. var barMaxWidth = seriesInfo.barMaxWidth;
  27695. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  27696. var barMinWidth = seriesInfo.barMinWidth;
  27697. barMinWidth && (stacks[stackId].minWidth = barMinWidth);
  27698. var barGap = seriesInfo.barGap;
  27699. barGap != null && (columnsOnAxis.gap = barGap);
  27700. var barCategoryGap = seriesInfo.barCategoryGap;
  27701. barCategoryGap != null && (columnsOnAxis.categoryGap = barCategoryGap);
  27702. });
  27703. var result = {};
  27704. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  27705. result[coordSysName] = {};
  27706. var stacks = columnsOnAxis.stacks;
  27707. var bandWidth = columnsOnAxis.bandWidth;
  27708. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  27709. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  27710. var remainedWidth = columnsOnAxis.remainedWidth;
  27711. var autoWidthCount = columnsOnAxis.autoWidthCount;
  27712. var autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  27713. autoWidth = Math.max(autoWidth, 0); // Find if any auto calculated bar exceeded maxBarWidth
  27714. each$1(stacks, function (column) {
  27715. var maxWidth = column.maxWidth;
  27716. var minWidth = column.minWidth;
  27717. if (!column.width) {
  27718. var finalWidth = autoWidth;
  27719. if (maxWidth && maxWidth < finalWidth) {
  27720. finalWidth = Math.min(maxWidth, remainedWidth);
  27721. } // `minWidth` has higher priority. `minWidth` decide that wheter the
  27722. // bar is able to be visible. So `minWidth` should not be restricted
  27723. // by `maxWidth` or `remainedWidth` (which is from `bandWidth`). In
  27724. // the extreme cases for `value` axis, bars are allowed to overlap
  27725. // with each other if `minWidth` specified.
  27726. if (minWidth && minWidth > finalWidth) {
  27727. finalWidth = minWidth;
  27728. }
  27729. if (finalWidth !== autoWidth) {
  27730. column.width = finalWidth;
  27731. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  27732. autoWidthCount--;
  27733. }
  27734. } else {
  27735. // `barMinWidth/barMaxWidth` has higher priority than `barWidth`, as
  27736. // CSS does. Becuase barWidth can be a percent value, where
  27737. // `barMaxWidth` can be used to restrict the final width.
  27738. var finalWidth = column.width;
  27739. if (maxWidth) {
  27740. finalWidth = Math.min(finalWidth, maxWidth);
  27741. } // `minWidth` has higher priority, as described above
  27742. if (minWidth) {
  27743. finalWidth = Math.max(finalWidth, minWidth);
  27744. }
  27745. column.width = finalWidth;
  27746. remainedWidth -= finalWidth + barGapPercent * finalWidth;
  27747. autoWidthCount--;
  27748. }
  27749. }); // Recalculate width again
  27750. autoWidth = (remainedWidth - categoryGap) / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  27751. autoWidth = Math.max(autoWidth, 0);
  27752. var widthSum = 0;
  27753. var lastColumn;
  27754. each$1(stacks, function (column, idx) {
  27755. if (!column.width) {
  27756. column.width = autoWidth;
  27757. }
  27758. lastColumn = column;
  27759. widthSum += column.width * (1 + barGapPercent);
  27760. });
  27761. if (lastColumn) {
  27762. widthSum -= lastColumn.width * barGapPercent;
  27763. }
  27764. var offset = -widthSum / 2;
  27765. each$1(stacks, function (column, stackId) {
  27766. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  27767. bandWidth: bandWidth,
  27768. offset: offset,
  27769. width: column.width
  27770. };
  27771. offset += column.width * (1 + barGapPercent);
  27772. });
  27773. });
  27774. return result;
  27775. }
  27776. /**
  27777. * @param {Object} barWidthAndOffset The result of makeColumnLayout
  27778. * @param {module:echarts/coord/Axis} axis
  27779. * @param {module:echarts/model/Series} [seriesModel] If not provided, return all.
  27780. * @return {Object} {stackId: {offset, width}} or {offset, width} if seriesModel provided.
  27781. */
  27782. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  27783. if (barWidthAndOffset && axis) {
  27784. var result = barWidthAndOffset[getAxisKey(axis)];
  27785. if (result != null && seriesModel != null) {
  27786. result = result[getSeriesStackId(seriesModel)];
  27787. }
  27788. return result;
  27789. }
  27790. }
  27791. /**
  27792. * @param {string} seriesType
  27793. * @param {module:echarts/model/Global} ecModel
  27794. */
  27795. function layout(seriesType, ecModel) {
  27796. var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
  27797. var barWidthAndOffset = makeColumnLayout(seriesModels);
  27798. var lastStackCoords = {};
  27799. each$1(seriesModels, function (seriesModel) {
  27800. var data = seriesModel.getData();
  27801. var cartesian = seriesModel.coordinateSystem;
  27802. var baseAxis = cartesian.getBaseAxis();
  27803. var stackId = getSeriesStackId(seriesModel);
  27804. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  27805. var columnOffset = columnLayoutInfo.offset;
  27806. var columnWidth = columnLayoutInfo.width;
  27807. var valueAxis = cartesian.getOtherAxis(baseAxis);
  27808. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  27809. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  27810. data.setLayout({
  27811. bandWidth: columnLayoutInfo.bandWidth,
  27812. offset: columnOffset,
  27813. size: columnWidth
  27814. });
  27815. var valueDim = data.mapDimension(valueAxis.dim);
  27816. var baseDim = data.mapDimension(baseAxis.dim);
  27817. var stacked = isDimensionStacked(data, valueDim
  27818. /*, baseDim*/
  27819. );
  27820. var isValueAxisH = valueAxis.isHorizontal();
  27821. var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked);
  27822. for (var idx = 0, len = data.count(); idx < len; idx++) {
  27823. var value = data.get(valueDim, idx);
  27824. var baseValue = data.get(baseDim, idx);
  27825. var sign = value >= 0 ? 'p' : 'n';
  27826. var baseCoord = valueAxisStart; // Because of the barMinHeight, we can not use the value in
  27827. // stackResultDimension directly.
  27828. if (stacked) {
  27829. // Only ordinal axis can be stacked.
  27830. if (!lastStackCoords[stackId][baseValue]) {
  27831. lastStackCoords[stackId][baseValue] = {
  27832. p: valueAxisStart,
  27833. // Positive stack
  27834. n: valueAxisStart // Negative stack
  27835. };
  27836. } // Should also consider #4243
  27837. baseCoord = lastStackCoords[stackId][baseValue][sign];
  27838. }
  27839. var x;
  27840. var y;
  27841. var width;
  27842. var height;
  27843. if (isValueAxisH) {
  27844. var coord = cartesian.dataToPoint([value, baseValue]);
  27845. x = baseCoord;
  27846. y = coord[1] + columnOffset;
  27847. width = coord[0] - valueAxisStart;
  27848. height = columnWidth;
  27849. if (Math.abs(width) < barMinHeight) {
  27850. width = (width < 0 ? -1 : 1) * barMinHeight;
  27851. } // Ignore stack from NaN value
  27852. if (!isNaN(width)) {
  27853. stacked && (lastStackCoords[stackId][baseValue][sign] += width);
  27854. }
  27855. } else {
  27856. var coord = cartesian.dataToPoint([baseValue, value]);
  27857. x = coord[0] + columnOffset;
  27858. y = baseCoord;
  27859. width = columnWidth;
  27860. height = coord[1] - valueAxisStart;
  27861. if (Math.abs(height) < barMinHeight) {
  27862. // Include zero to has a positive bar
  27863. height = (height <= 0 ? -1 : 1) * barMinHeight;
  27864. } // Ignore stack from NaN value
  27865. if (!isNaN(height)) {
  27866. stacked && (lastStackCoords[stackId][baseValue][sign] += height);
  27867. }
  27868. }
  27869. data.setItemLayout(idx, {
  27870. x: x,
  27871. y: y,
  27872. width: width,
  27873. height: height
  27874. });
  27875. }
  27876. }, this);
  27877. } // TODO: Do not support stack in large mode yet.
  27878. var largeLayout = {
  27879. seriesType: 'bar',
  27880. plan: createRenderPlanner(),
  27881. reset: function (seriesModel) {
  27882. if (!isOnCartesian(seriesModel) || !isInLargeMode(seriesModel)) {
  27883. return;
  27884. }
  27885. var data = seriesModel.getData();
  27886. var cartesian = seriesModel.coordinateSystem;
  27887. var coordLayout = cartesian.grid.getRect();
  27888. var baseAxis = cartesian.getBaseAxis();
  27889. var valueAxis = cartesian.getOtherAxis(baseAxis);
  27890. var valueDim = data.mapDimension(valueAxis.dim);
  27891. var baseDim = data.mapDimension(baseAxis.dim);
  27892. var valueAxisHorizontal = valueAxis.isHorizontal();
  27893. var valueDimIdx = valueAxisHorizontal ? 0 : 1;
  27894. var barWidth = retrieveColumnLayout(makeColumnLayout([seriesModel]), baseAxis, seriesModel).width;
  27895. if (!(barWidth > LARGE_BAR_MIN_WIDTH)) {
  27896. // jshint ignore:line
  27897. barWidth = LARGE_BAR_MIN_WIDTH;
  27898. }
  27899. return {
  27900. progress: progress
  27901. };
  27902. function progress(params, data) {
  27903. var count = params.count;
  27904. var largePoints = new LargeArr(count * 2);
  27905. var largeBackgroundPoints = new LargeArr(count * 2);
  27906. var largeDataIndices = new LargeArr(count);
  27907. var dataIndex;
  27908. var coord = [];
  27909. var valuePair = [];
  27910. var pointsOffset = 0;
  27911. var idxOffset = 0;
  27912. while ((dataIndex = params.next()) != null) {
  27913. valuePair[valueDimIdx] = data.get(valueDim, dataIndex);
  27914. valuePair[1 - valueDimIdx] = data.get(baseDim, dataIndex);
  27915. coord = cartesian.dataToPoint(valuePair, null, coord); // Data index might not be in order, depends on `progressiveChunkMode`.
  27916. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal ? coordLayout.x + coordLayout.width : coord[0];
  27917. largePoints[pointsOffset++] = coord[0];
  27918. largeBackgroundPoints[pointsOffset] = valueAxisHorizontal ? coord[1] : coordLayout.y + coordLayout.height;
  27919. largePoints[pointsOffset++] = coord[1];
  27920. largeDataIndices[idxOffset++] = dataIndex;
  27921. }
  27922. data.setLayout({
  27923. largePoints: largePoints,
  27924. largeDataIndices: largeDataIndices,
  27925. largeBackgroundPoints: largeBackgroundPoints,
  27926. barWidth: barWidth,
  27927. valueAxisStart: getValueAxisStart(baseAxis, valueAxis, false),
  27928. backgroundStart: valueAxisHorizontal ? coordLayout.x : coordLayout.y,
  27929. valueAxisHorizontal: valueAxisHorizontal
  27930. });
  27931. }
  27932. }
  27933. };
  27934. function isOnCartesian(seriesModel) {
  27935. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  27936. }
  27937. function isInLargeMode(seriesModel) {
  27938. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  27939. } // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  27940. function getValueAxisStart(baseAxis, valueAxis, stacked) {
  27941. return valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.type === 'log' ? 1 : 0));
  27942. }
  27943. /*
  27944. * Licensed to the Apache Software Foundation (ASF) under one
  27945. * or more contributor license agreements. See the NOTICE file
  27946. * distributed with this work for additional information
  27947. * regarding copyright ownership. The ASF licenses this file
  27948. * to you under the Apache License, Version 2.0 (the
  27949. * "License"); you may not use this file except in compliance
  27950. * with the License. You may obtain a copy of the License at
  27951. *
  27952. * http://www.apache.org/licenses/LICENSE-2.0
  27953. *
  27954. * Unless required by applicable law or agreed to in writing,
  27955. * software distributed under the License is distributed on an
  27956. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27957. * KIND, either express or implied. See the License for the
  27958. * specific language governing permissions and limitations
  27959. * under the License.
  27960. */
  27961. /*
  27962. * A third-party license is embeded for some of the code in this file:
  27963. * The "scaleLevels" was originally copied from "d3.js" with some
  27964. * modifications made for this project.
  27965. * (See more details in the comment on the definition of "scaleLevels" below.)
  27966. * The use of the source code of this file is also subject to the terms
  27967. * and consitions of the license of "d3.js" (BSD-3Clause, see
  27968. * </licenses/LICENSE-d3>).
  27969. */
  27970. // [About UTC and local time zone]:
  27971. // In most cases, `number.parseDate` will treat input data string as local time
  27972. // (except time zone is specified in time string). And `format.formateTime` returns
  27973. // local time by default. option.useUTC is false by default. This design have
  27974. // concidered these common case:
  27975. // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
  27976. // in local time by default.
  27977. // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
  27978. // as its original time, without any time difference.
  27979. var intervalScaleProto = IntervalScale.prototype;
  27980. var mathCeil = Math.ceil;
  27981. var mathFloor = Math.floor;
  27982. var ONE_SECOND = 1000;
  27983. var ONE_MINUTE = ONE_SECOND * 60;
  27984. var ONE_HOUR = ONE_MINUTE * 60;
  27985. var ONE_DAY = ONE_HOUR * 24; // FIXME 公用?
  27986. var bisect = function (a, x, lo, hi) {
  27987. while (lo < hi) {
  27988. var mid = lo + hi >>> 1;
  27989. if (a[mid][1] < x) {
  27990. lo = mid + 1;
  27991. } else {
  27992. hi = mid;
  27993. }
  27994. }
  27995. return lo;
  27996. };
  27997. /**
  27998. * @alias module:echarts/coord/scale/Time
  27999. * @constructor
  28000. */
  28001. var TimeScale = IntervalScale.extend({
  28002. type: 'time',
  28003. /**
  28004. * @override
  28005. */
  28006. getLabel: function (val) {
  28007. var stepLvl = this._stepLvl;
  28008. var date = new Date(val);
  28009. return formatTime(stepLvl[0], date, this.getSetting('useUTC'));
  28010. },
  28011. /**
  28012. * @override
  28013. */
  28014. niceExtent: function (opt) {
  28015. var extent = this._extent; // If extent start and end are same, expand them
  28016. if (extent[0] === extent[1]) {
  28017. // Expand extent
  28018. extent[0] -= ONE_DAY;
  28019. extent[1] += ONE_DAY;
  28020. } // If there are no data and extent are [Infinity, -Infinity]
  28021. if (extent[1] === -Infinity && extent[0] === Infinity) {
  28022. var d = new Date();
  28023. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  28024. extent[0] = extent[1] - ONE_DAY;
  28025. }
  28026. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval); // var extent = this._extent;
  28027. var interval = this._interval;
  28028. if (!opt.fixMin) {
  28029. extent[0] = round$1(mathFloor(extent[0] / interval) * interval);
  28030. }
  28031. if (!opt.fixMax) {
  28032. extent[1] = round$1(mathCeil(extent[1] / interval) * interval);
  28033. }
  28034. },
  28035. /**
  28036. * @override
  28037. */
  28038. niceTicks: function (approxTickNum, minInterval, maxInterval) {
  28039. approxTickNum = approxTickNum || 10;
  28040. var extent = this._extent;
  28041. var span = extent[1] - extent[0];
  28042. var approxInterval = span / approxTickNum;
  28043. if (minInterval != null && approxInterval < minInterval) {
  28044. approxInterval = minInterval;
  28045. }
  28046. if (maxInterval != null && approxInterval > maxInterval) {
  28047. approxInterval = maxInterval;
  28048. }
  28049. var scaleLevelsLen = scaleLevels.length;
  28050. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  28051. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  28052. var interval = level[1]; // Same with interval scale if span is much larger than 1 year
  28053. if (level[0] === 'year') {
  28054. var yearSpan = span / interval; // From "Nice Numbers for Graph Labels" of Graphic Gems
  28055. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  28056. var yearStep = nice(yearSpan / approxTickNum, true);
  28057. interval *= yearStep;
  28058. }
  28059. var timezoneOffset = this.getSetting('useUTC') ? 0 : new Date(+extent[0] || +extent[1]).getTimezoneOffset() * 60 * 1000;
  28060. var niceExtent = [Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset), Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)];
  28061. fixExtent(niceExtent, extent);
  28062. this._stepLvl = level; // Interval will be used in getTicks
  28063. this._interval = interval;
  28064. this._niceExtent = niceExtent;
  28065. },
  28066. parse: function (val) {
  28067. // val might be float.
  28068. return +parseDate(val);
  28069. }
  28070. });
  28071. each$1(['contain', 'normalize'], function (methodName) {
  28072. TimeScale.prototype[methodName] = function (val) {
  28073. return intervalScaleProto[methodName].call(this, this.parse(val));
  28074. };
  28075. });
  28076. /**
  28077. * This implementation was originally copied from "d3.js"
  28078. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  28079. * with some modifications made for this program.
  28080. * See the license statement at the head of this file.
  28081. */
  28082. var scaleLevels = [// Format interval
  28083. ['hh:mm:ss', ONE_SECOND], // 1s
  28084. ['hh:mm:ss', ONE_SECOND * 5], // 5s
  28085. ['hh:mm:ss', ONE_SECOND * 10], // 10s
  28086. ['hh:mm:ss', ONE_SECOND * 15], // 15s
  28087. ['hh:mm:ss', ONE_SECOND * 30], // 30s
  28088. ['hh:mm\nMM-dd', ONE_MINUTE], // 1m
  28089. ['hh:mm\nMM-dd', ONE_MINUTE * 5], // 5m
  28090. ['hh:mm\nMM-dd', ONE_MINUTE * 10], // 10m
  28091. ['hh:mm\nMM-dd', ONE_MINUTE * 15], // 15m
  28092. ['hh:mm\nMM-dd', ONE_MINUTE * 30], // 30m
  28093. ['hh:mm\nMM-dd', ONE_HOUR], // 1h
  28094. ['hh:mm\nMM-dd', ONE_HOUR * 2], // 2h
  28095. ['hh:mm\nMM-dd', ONE_HOUR * 6], // 6h
  28096. ['hh:mm\nMM-dd', ONE_HOUR * 12], // 12h
  28097. ['MM-dd\nyyyy', ONE_DAY], // 1d
  28098. ['MM-dd\nyyyy', ONE_DAY * 2], // 2d
  28099. ['MM-dd\nyyyy', ONE_DAY * 3], // 3d
  28100. ['MM-dd\nyyyy', ONE_DAY * 4], // 4d
  28101. ['MM-dd\nyyyy', ONE_DAY * 5], // 5d
  28102. ['MM-dd\nyyyy', ONE_DAY * 6], // 6d
  28103. ['week', ONE_DAY * 7], // 7d
  28104. ['MM-dd\nyyyy', ONE_DAY * 10], // 10d
  28105. ['week', ONE_DAY * 14], // 2w
  28106. ['week', ONE_DAY * 21], // 3w
  28107. ['month', ONE_DAY * 31], // 1M
  28108. ['week', ONE_DAY * 42], // 6w
  28109. ['month', ONE_DAY * 62], // 2M
  28110. ['week', ONE_DAY * 70], // 10w
  28111. ['quarter', ONE_DAY * 95], // 3M
  28112. ['month', ONE_DAY * 31 * 4], // 4M
  28113. ['month', ONE_DAY * 31 * 5], // 5M
  28114. ['half-year', ONE_DAY * 380 / 2], // 6M
  28115. ['month', ONE_DAY * 31 * 8], // 8M
  28116. ['month', ONE_DAY * 31 * 10], // 10M
  28117. ['year', ONE_DAY * 380] // 1Y
  28118. ];
  28119. /**
  28120. * @param {module:echarts/model/Model}
  28121. * @return {module:echarts/scale/Time}
  28122. */
  28123. TimeScale.create = function (model) {
  28124. return new TimeScale({
  28125. useUTC: model.ecModel.get('useUTC')
  28126. });
  28127. };
  28128. /*
  28129. * Licensed to the Apache Software Foundation (ASF) under one
  28130. * or more contributor license agreements. See the NOTICE file
  28131. * distributed with this work for additional information
  28132. * regarding copyright ownership. The ASF licenses this file
  28133. * to you under the Apache License, Version 2.0 (the
  28134. * "License"); you may not use this file except in compliance
  28135. * with the License. You may obtain a copy of the License at
  28136. *
  28137. * http://www.apache.org/licenses/LICENSE-2.0
  28138. *
  28139. * Unless required by applicable law or agreed to in writing,
  28140. * software distributed under the License is distributed on an
  28141. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28142. * KIND, either express or implied. See the License for the
  28143. * specific language governing permissions and limitations
  28144. * under the License.
  28145. */
  28146. /**
  28147. * Log scale
  28148. * @module echarts/scale/Log
  28149. */
  28150. var scaleProto$1 = Scale.prototype;
  28151. var intervalScaleProto$1 = IntervalScale.prototype;
  28152. var getPrecisionSafe$1 = getPrecisionSafe;
  28153. var roundingErrorFix = round$1;
  28154. var mathFloor$1 = Math.floor;
  28155. var mathCeil$1 = Math.ceil;
  28156. var mathPow$1 = Math.pow;
  28157. var mathLog = Math.log;
  28158. var LogScale = Scale.extend({
  28159. type: 'log',
  28160. base: 10,
  28161. $constructor: function () {
  28162. Scale.apply(this, arguments);
  28163. this._originalScale = new IntervalScale();
  28164. },
  28165. /**
  28166. * @param {boolean} [expandToNicedExtent=false] If expand the ticks to niced extent.
  28167. * @return {Array.<number>}
  28168. */
  28169. getTicks: function (expandToNicedExtent) {
  28170. var originalScale = this._originalScale;
  28171. var extent = this._extent;
  28172. var originalExtent = originalScale.getExtent();
  28173. return map(intervalScaleProto$1.getTicks.call(this, expandToNicedExtent), function (val) {
  28174. var powVal = round$1(mathPow$1(this.base, val)); // Fix #4158
  28175. powVal = val === extent[0] && originalScale.__fixMin ? fixRoundingError(powVal, originalExtent[0]) : powVal;
  28176. powVal = val === extent[1] && originalScale.__fixMax ? fixRoundingError(powVal, originalExtent[1]) : powVal;
  28177. return powVal;
  28178. }, this);
  28179. },
  28180. /**
  28181. * @param {number} splitNumber
  28182. * @return {Array.<Array.<number>>}
  28183. */
  28184. getMinorTicks: intervalScaleProto$1.getMinorTicks,
  28185. /**
  28186. * @param {number} val
  28187. * @return {string}
  28188. */
  28189. getLabel: intervalScaleProto$1.getLabel,
  28190. /**
  28191. * @param {number} val
  28192. * @return {number}
  28193. */
  28194. scale: function (val) {
  28195. val = scaleProto$1.scale.call(this, val);
  28196. return mathPow$1(this.base, val);
  28197. },
  28198. /**
  28199. * @param {number} start
  28200. * @param {number} end
  28201. */
  28202. setExtent: function (start, end) {
  28203. var base = this.base;
  28204. start = mathLog(start) / mathLog(base);
  28205. end = mathLog(end) / mathLog(base);
  28206. intervalScaleProto$1.setExtent.call(this, start, end);
  28207. },
  28208. /**
  28209. * @return {number} end
  28210. */
  28211. getExtent: function () {
  28212. var base = this.base;
  28213. var extent = scaleProto$1.getExtent.call(this);
  28214. extent[0] = mathPow$1(base, extent[0]);
  28215. extent[1] = mathPow$1(base, extent[1]); // Fix #4158
  28216. var originalScale = this._originalScale;
  28217. var originalExtent = originalScale.getExtent();
  28218. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  28219. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  28220. return extent;
  28221. },
  28222. /**
  28223. * @param {Array.<number>} extent
  28224. */
  28225. unionExtent: function (extent) {
  28226. this._originalScale.unionExtent(extent);
  28227. var base = this.base;
  28228. extent[0] = mathLog(extent[0]) / mathLog(base);
  28229. extent[1] = mathLog(extent[1]) / mathLog(base);
  28230. scaleProto$1.unionExtent.call(this, extent);
  28231. },
  28232. /**
  28233. * @override
  28234. */
  28235. unionExtentFromData: function (data, dim) {
  28236. // TODO
  28237. // filter value that <= 0
  28238. this.unionExtent(data.getApproximateExtent(dim));
  28239. },
  28240. /**
  28241. * Update interval and extent of intervals for nice ticks
  28242. * @param {number} [approxTickNum = 10] Given approx tick number
  28243. */
  28244. niceTicks: function (approxTickNum) {
  28245. approxTickNum = approxTickNum || 10;
  28246. var extent = this._extent;
  28247. var span = extent[1] - extent[0];
  28248. if (span === Infinity || span <= 0) {
  28249. return;
  28250. }
  28251. var interval = quantity(span);
  28252. var err = approxTickNum / span * interval; // Filter ticks to get closer to the desired count.
  28253. if (err <= 0.5) {
  28254. interval *= 10;
  28255. } // Interval should be integer
  28256. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  28257. interval *= 10;
  28258. }
  28259. var niceExtent = [round$1(mathCeil$1(extent[0] / interval) * interval), round$1(mathFloor$1(extent[1] / interval) * interval)];
  28260. this._interval = interval;
  28261. this._niceExtent = niceExtent;
  28262. },
  28263. /**
  28264. * Nice extent.
  28265. * @override
  28266. */
  28267. niceExtent: function (opt) {
  28268. intervalScaleProto$1.niceExtent.call(this, opt);
  28269. var originalScale = this._originalScale;
  28270. originalScale.__fixMin = opt.fixMin;
  28271. originalScale.__fixMax = opt.fixMax;
  28272. }
  28273. });
  28274. each$1(['contain', 'normalize'], function (methodName) {
  28275. LogScale.prototype[methodName] = function (val) {
  28276. val = mathLog(val) / mathLog(this.base);
  28277. return scaleProto$1[methodName].call(this, val);
  28278. };
  28279. });
  28280. LogScale.create = function () {
  28281. return new LogScale();
  28282. };
  28283. function fixRoundingError(val, originalVal) {
  28284. return roundingErrorFix(val, getPrecisionSafe$1(originalVal));
  28285. }
  28286. /*
  28287. * Licensed to the Apache Software Foundation (ASF) under one
  28288. * or more contributor license agreements. See the NOTICE file
  28289. * distributed with this work for additional information
  28290. * regarding copyright ownership. The ASF licenses this file
  28291. * to you under the Apache License, Version 2.0 (the
  28292. * "License"); you may not use this file except in compliance
  28293. * with the License. You may obtain a copy of the License at
  28294. *
  28295. * http://www.apache.org/licenses/LICENSE-2.0
  28296. *
  28297. * Unless required by applicable law or agreed to in writing,
  28298. * software distributed under the License is distributed on an
  28299. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28300. * KIND, either express or implied. See the License for the
  28301. * specific language governing permissions and limitations
  28302. * under the License.
  28303. */
  28304. /**
  28305. * Get axis scale extent before niced.
  28306. * Item of returned array can only be number (including Infinity and NaN).
  28307. */
  28308. function getScaleExtent(scale, model) {
  28309. var scaleType = scale.type;
  28310. var min = model.getMin();
  28311. var max = model.getMax();
  28312. var originalExtent = scale.getExtent();
  28313. var axisDataLen;
  28314. var boundaryGap;
  28315. var span;
  28316. if (scaleType === 'ordinal') {
  28317. axisDataLen = model.getCategories().length;
  28318. } else {
  28319. boundaryGap = model.get('boundaryGap');
  28320. if (!isArray(boundaryGap)) {
  28321. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  28322. }
  28323. if (typeof boundaryGap[0] === 'boolean') {
  28324. boundaryGap = [0, 0];
  28325. }
  28326. boundaryGap[0] = parsePercent$1(boundaryGap[0], 1);
  28327. boundaryGap[1] = parsePercent$1(boundaryGap[1], 1);
  28328. span = originalExtent[1] - originalExtent[0] || Math.abs(originalExtent[0]);
  28329. } // Notice: When min/max is not set (that is, when there are null/undefined,
  28330. // which is the most common case), these cases should be ensured:
  28331. // (1) For 'ordinal', show all axis.data.
  28332. // (2) For others:
  28333. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  28334. // disabled).
  28335. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  28336. // be the result that originalExtent enlarged by boundaryGap.
  28337. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  28338. // FIXME
  28339. // (1) When min/max is 'dataMin' or 'dataMax', should boundaryGap be able to used?
  28340. // (2) When `needCrossZero` and all data is positive/negative, should it be ensured
  28341. // that the results processed by boundaryGap are positive/negative?
  28342. if (min === 'dataMin') {
  28343. min = originalExtent[0];
  28344. } else if (typeof min === 'function') {
  28345. min = min({
  28346. min: originalExtent[0],
  28347. max: originalExtent[1]
  28348. });
  28349. }
  28350. if (max === 'dataMax') {
  28351. max = originalExtent[1];
  28352. } else if (typeof max === 'function') {
  28353. max = max({
  28354. min: originalExtent[0],
  28355. max: originalExtent[1]
  28356. });
  28357. }
  28358. var fixMin = min != null;
  28359. var fixMax = max != null;
  28360. if (min == null) {
  28361. min = scaleType === 'ordinal' ? axisDataLen ? 0 : NaN : originalExtent[0] - boundaryGap[0] * span;
  28362. }
  28363. if (max == null) {
  28364. max = scaleType === 'ordinal' ? axisDataLen ? axisDataLen - 1 : NaN : originalExtent[1] + boundaryGap[1] * span;
  28365. }
  28366. (min == null || !isFinite(min)) && (min = NaN);
  28367. (max == null || !isFinite(max)) && (max = NaN);
  28368. scale.setBlank(eqNaN(min) || eqNaN(max) || scaleType === 'ordinal' && !scale.getOrdinalMeta().categories.length); // Evaluate if axis needs cross zero
  28369. if (model.getNeedCrossZero()) {
  28370. // Axis is over zero and min is not set
  28371. if (min > 0 && max > 0 && !fixMin) {
  28372. min = 0;
  28373. } // Axis is under zero and max is not set
  28374. if (min < 0 && max < 0 && !fixMax) {
  28375. max = 0;
  28376. }
  28377. } // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  28378. // is base axis
  28379. // FIXME
  28380. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  28381. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  28382. // Should not depend on series type `bar`?
  28383. // (3) Fix that might overlap when using dataZoom.
  28384. // (4) Consider other chart types using `barGrid`?
  28385. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  28386. var ecModel = model.ecModel;
  28387. if (ecModel && scaleType === 'time'
  28388. /*|| scaleType === 'interval' */
  28389. ) {
  28390. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  28391. var isBaseAxisAndHasBarSeries;
  28392. each$1(barSeriesModels, function (seriesModel) {
  28393. isBaseAxisAndHasBarSeries |= seriesModel.getBaseAxis() === model.axis;
  28394. });
  28395. if (isBaseAxisAndHasBarSeries) {
  28396. // Calculate placement of bars on axis
  28397. var barWidthAndOffset = makeColumnLayout(barSeriesModels); // Adjust axis min and max to account for overflow
  28398. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  28399. min = adjustedScale.min;
  28400. max = adjustedScale.max;
  28401. }
  28402. }
  28403. return {
  28404. extent: [min, max],
  28405. // "fix" means "fixed", the value should not be
  28406. // changed in the subsequent steps.
  28407. fixMin: fixMin,
  28408. fixMax: fixMax
  28409. };
  28410. }
  28411. function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
  28412. // Get Axis Length
  28413. var axisExtent = model.axis.getExtent();
  28414. var axisLength = axisExtent[1] - axisExtent[0]; // Get bars on current base axis and calculate min and max overflow
  28415. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  28416. if (barsOnCurrentAxis === undefined) {
  28417. return {
  28418. min: min,
  28419. max: max
  28420. };
  28421. }
  28422. var minOverflow = Infinity;
  28423. each$1(barsOnCurrentAxis, function (item) {
  28424. minOverflow = Math.min(item.offset, minOverflow);
  28425. });
  28426. var maxOverflow = -Infinity;
  28427. each$1(barsOnCurrentAxis, function (item) {
  28428. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  28429. });
  28430. minOverflow = Math.abs(minOverflow);
  28431. maxOverflow = Math.abs(maxOverflow);
  28432. var totalOverFlow = minOverflow + maxOverflow; // Calulate required buffer based on old range and overflow
  28433. var oldRange = max - min;
  28434. var oldRangePercentOfNew = 1 - (minOverflow + maxOverflow) / axisLength;
  28435. var overflowBuffer = oldRange / oldRangePercentOfNew - oldRange;
  28436. max += overflowBuffer * (maxOverflow / totalOverFlow);
  28437. min -= overflowBuffer * (minOverflow / totalOverFlow);
  28438. return {
  28439. min: min,
  28440. max: max
  28441. };
  28442. }
  28443. function niceScaleExtent(scale, model) {
  28444. var extentInfo = getScaleExtent(scale, model);
  28445. var extent = extentInfo.extent;
  28446. var splitNumber = model.get('splitNumber');
  28447. if (scale.type === 'log') {
  28448. scale.base = model.get('logBase');
  28449. }
  28450. var scaleType = scale.type;
  28451. scale.setExtent(extent[0], extent[1]);
  28452. scale.niceExtent({
  28453. splitNumber: splitNumber,
  28454. fixMin: extentInfo.fixMin,
  28455. fixMax: extentInfo.fixMax,
  28456. minInterval: scaleType === 'interval' || scaleType === 'time' ? model.get('minInterval') : null,
  28457. maxInterval: scaleType === 'interval' || scaleType === 'time' ? model.get('maxInterval') : null
  28458. }); // If some one specified the min, max. And the default calculated interval
  28459. // is not good enough. He can specify the interval. It is often appeared
  28460. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  28461. // to be 60.
  28462. // FIXME
  28463. var interval = model.get('interval');
  28464. if (interval != null) {
  28465. scale.setInterval && scale.setInterval(interval);
  28466. }
  28467. }
  28468. /**
  28469. * @param {module:echarts/model/Model} model
  28470. * @param {string} [axisType] Default retrieve from model.type
  28471. * @return {module:echarts/scale/*}
  28472. */
  28473. function createScaleByModel(model, axisType) {
  28474. axisType = axisType || model.get('type');
  28475. if (axisType) {
  28476. switch (axisType) {
  28477. // Buildin scale
  28478. case 'category':
  28479. return new OrdinalScale(model.getOrdinalMeta ? model.getOrdinalMeta() : model.getCategories(), [Infinity, -Infinity]);
  28480. case 'value':
  28481. return new IntervalScale();
  28482. // Extended scale, like time and log
  28483. default:
  28484. return (Scale.getClass(axisType) || IntervalScale).create(model);
  28485. }
  28486. }
  28487. }
  28488. /**
  28489. * Check if the axis corss 0
  28490. */
  28491. function ifAxisCrossZero(axis) {
  28492. var dataExtent = axis.scale.getExtent();
  28493. var min = dataExtent[0];
  28494. var max = dataExtent[1];
  28495. return !(min > 0 && max > 0 || min < 0 && max < 0);
  28496. }
  28497. /**
  28498. * @param {module:echarts/coord/Axis} axis
  28499. * @return {Function} Label formatter function.
  28500. * param: {number} tickValue,
  28501. * param: {number} idx, the index in all ticks.
  28502. * If category axis, this param is not requied.
  28503. * return: {string} label string.
  28504. */
  28505. function makeLabelFormatter(axis) {
  28506. var labelFormatter = axis.getLabelModel().get('formatter');
  28507. var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
  28508. if (typeof labelFormatter === 'string') {
  28509. labelFormatter = function (tpl) {
  28510. return function (val) {
  28511. // For category axis, get raw value; for numeric axis,
  28512. // get foramtted label like '1,333,444'.
  28513. val = axis.scale.getLabel(val);
  28514. return tpl.replace('{value}', val != null ? val : '');
  28515. };
  28516. }(labelFormatter); // Consider empty array
  28517. return labelFormatter;
  28518. } else if (typeof labelFormatter === 'function') {
  28519. return function (tickValue, idx) {
  28520. // The original intention of `idx` is "the index of the tick in all ticks".
  28521. // But the previous implementation of category axis do not consider the
  28522. // `axisLabel.interval`, which cause that, for example, the `interval` is
  28523. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  28524. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  28525. // the definition here for back compatibility.
  28526. if (categoryTickStart != null) {
  28527. idx = tickValue - categoryTickStart;
  28528. }
  28529. return labelFormatter(getAxisRawValue(axis, tickValue), idx);
  28530. };
  28531. } else {
  28532. return function (tick) {
  28533. return axis.scale.getLabel(tick);
  28534. };
  28535. }
  28536. }
  28537. function getAxisRawValue(axis, value) {
  28538. // In category axis with data zoom, tick is not the original
  28539. // index of axis.data. So tick should not be exposed to user
  28540. // in category axis.
  28541. return axis.type === 'category' ? axis.scale.getLabel(value) : value;
  28542. }
  28543. /**
  28544. * @param {module:echarts/coord/Axis} axis
  28545. * @return {module:zrender/core/BoundingRect} Be null/undefined if no labels.
  28546. */
  28547. function estimateLabelUnionRect(axis) {
  28548. var axisModel = axis.model;
  28549. var scale = axis.scale;
  28550. if (!axisModel.get('axisLabel.show') || scale.isBlank()) {
  28551. return;
  28552. }
  28553. var isCategory = axis.type === 'category';
  28554. var realNumberScaleTicks;
  28555. var tickCount;
  28556. var categoryScaleExtent = scale.getExtent(); // Optimize for large category data, avoid call `getTicks()`.
  28557. if (isCategory) {
  28558. tickCount = scale.count();
  28559. } else {
  28560. realNumberScaleTicks = scale.getTicks();
  28561. tickCount = realNumberScaleTicks.length;
  28562. }
  28563. var axisLabelModel = axis.getLabelModel();
  28564. var labelFormatter = makeLabelFormatter(axis);
  28565. var rect;
  28566. var step = 1; // Simple optimization for large amount of labels
  28567. if (tickCount > 40) {
  28568. step = Math.ceil(tickCount / 40);
  28569. }
  28570. for (var i = 0; i < tickCount; i += step) {
  28571. var tickValue = realNumberScaleTicks ? realNumberScaleTicks[i] : categoryScaleExtent[0] + i;
  28572. var label = labelFormatter(tickValue);
  28573. var unrotatedSingleRect = axisLabelModel.getTextRect(label);
  28574. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  28575. rect ? rect.union(singleRect) : rect = singleRect;
  28576. }
  28577. return rect;
  28578. }
  28579. function rotateTextRect(textRect, rotate) {
  28580. var rotateRadians = rotate * Math.PI / 180;
  28581. var boundingBox = textRect.plain();
  28582. var beforeWidth = boundingBox.width;
  28583. var beforeHeight = boundingBox.height;
  28584. var afterWidth = beforeWidth * Math.cos(rotateRadians) + beforeHeight * Math.sin(rotateRadians);
  28585. var afterHeight = beforeWidth * Math.sin(rotateRadians) + beforeHeight * Math.cos(rotateRadians);
  28586. var rotatedRect = new BoundingRect(boundingBox.x, boundingBox.y, afterWidth, afterHeight);
  28587. return rotatedRect;
  28588. }
  28589. /**
  28590. * @param {module:echarts/src/model/Model} model axisLabelModel or axisTickModel
  28591. * @return {number|String} Can be null|'auto'|number|function
  28592. */
  28593. function getOptionCategoryInterval(model) {
  28594. var interval = model.get('interval');
  28595. return interval == null ? 'auto' : interval;
  28596. }
  28597. /**
  28598. * Set `categoryInterval` as 0 implicitly indicates that
  28599. * show all labels reguardless of overlap.
  28600. * @param {Object} axis axisModel.axis
  28601. * @return {boolean}
  28602. */
  28603. function shouldShowAllLabels(axis) {
  28604. return axis.type === 'category' && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  28605. }
  28606. /*
  28607. * Licensed to the Apache Software Foundation (ASF) under one
  28608. * or more contributor license agreements. See the NOTICE file
  28609. * distributed with this work for additional information
  28610. * regarding copyright ownership. The ASF licenses this file
  28611. * to you under the Apache License, Version 2.0 (the
  28612. * "License"); you may not use this file except in compliance
  28613. * with the License. You may obtain a copy of the License at
  28614. *
  28615. * http://www.apache.org/licenses/LICENSE-2.0
  28616. *
  28617. * Unless required by applicable law or agreed to in writing,
  28618. * software distributed under the License is distributed on an
  28619. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28620. * KIND, either express or implied. See the License for the
  28621. * specific language governing permissions and limitations
  28622. * under the License.
  28623. */
  28624. var axisModelCommonMixin = {
  28625. /**
  28626. * @param {boolean} origin
  28627. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  28628. */
  28629. getMin: function (origin) {
  28630. var option = this.option;
  28631. var min = !origin && option.rangeStart != null ? option.rangeStart : option.min;
  28632. if (this.axis && min != null && min !== 'dataMin' && typeof min !== 'function' && !eqNaN(min)) {
  28633. min = this.axis.scale.parse(min);
  28634. }
  28635. return min;
  28636. },
  28637. /**
  28638. * @param {boolean} origin
  28639. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  28640. */
  28641. getMax: function (origin) {
  28642. var option = this.option;
  28643. var max = !origin && option.rangeEnd != null ? option.rangeEnd : option.max;
  28644. if (this.axis && max != null && max !== 'dataMax' && typeof max !== 'function' && !eqNaN(max)) {
  28645. max = this.axis.scale.parse(max);
  28646. }
  28647. return max;
  28648. },
  28649. /**
  28650. * @return {boolean}
  28651. */
  28652. getNeedCrossZero: function () {
  28653. var option = this.option;
  28654. return option.rangeStart != null || option.rangeEnd != null ? false : !option.scale;
  28655. },
  28656. /**
  28657. * Should be implemented by each axis model if necessary.
  28658. * @return {module:echarts/model/Component} coordinate system model
  28659. */
  28660. getCoordSysModel: noop,
  28661. /**
  28662. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  28663. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  28664. */
  28665. setRange: function (rangeStart, rangeEnd) {
  28666. this.option.rangeStart = rangeStart;
  28667. this.option.rangeEnd = rangeEnd;
  28668. },
  28669. /**
  28670. * Reset range
  28671. */
  28672. resetRange: function () {
  28673. // rangeStart and rangeEnd is readonly.
  28674. this.option.rangeStart = this.option.rangeEnd = null;
  28675. }
  28676. };
  28677. /*
  28678. * Licensed to the Apache Software Foundation (ASF) under one
  28679. * or more contributor license agreements. See the NOTICE file
  28680. * distributed with this work for additional information
  28681. * regarding copyright ownership. The ASF licenses this file
  28682. * to you under the Apache License, Version 2.0 (the
  28683. * "License"); you may not use this file except in compliance
  28684. * with the License. You may obtain a copy of the License at
  28685. *
  28686. * http://www.apache.org/licenses/LICENSE-2.0
  28687. *
  28688. * Unless required by applicable law or agreed to in writing,
  28689. * software distributed under the License is distributed on an
  28690. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28691. * KIND, either express or implied. See the License for the
  28692. * specific language governing permissions and limitations
  28693. * under the License.
  28694. */
  28695. // Symbol factory
  28696. /**
  28697. * Triangle shape
  28698. * @inner
  28699. */
  28700. var Triangle = extendShape({
  28701. type: 'triangle',
  28702. shape: {
  28703. cx: 0,
  28704. cy: 0,
  28705. width: 0,
  28706. height: 0
  28707. },
  28708. buildPath: function (path, shape) {
  28709. var cx = shape.cx;
  28710. var cy = shape.cy;
  28711. var width = shape.width / 2;
  28712. var height = shape.height / 2;
  28713. path.moveTo(cx, cy - height);
  28714. path.lineTo(cx + width, cy + height);
  28715. path.lineTo(cx - width, cy + height);
  28716. path.closePath();
  28717. }
  28718. });
  28719. /**
  28720. * Diamond shape
  28721. * @inner
  28722. */
  28723. var Diamond = extendShape({
  28724. type: 'diamond',
  28725. shape: {
  28726. cx: 0,
  28727. cy: 0,
  28728. width: 0,
  28729. height: 0
  28730. },
  28731. buildPath: function (path, shape) {
  28732. var cx = shape.cx;
  28733. var cy = shape.cy;
  28734. var width = shape.width / 2;
  28735. var height = shape.height / 2;
  28736. path.moveTo(cx, cy - height);
  28737. path.lineTo(cx + width, cy);
  28738. path.lineTo(cx, cy + height);
  28739. path.lineTo(cx - width, cy);
  28740. path.closePath();
  28741. }
  28742. });
  28743. /**
  28744. * Pin shape
  28745. * @inner
  28746. */
  28747. var Pin = extendShape({
  28748. type: 'pin',
  28749. shape: {
  28750. // x, y on the cusp
  28751. x: 0,
  28752. y: 0,
  28753. width: 0,
  28754. height: 0
  28755. },
  28756. buildPath: function (path, shape) {
  28757. var x = shape.x;
  28758. var y = shape.y;
  28759. var w = shape.width / 5 * 3; // Height must be larger than width
  28760. var h = Math.max(w, shape.height);
  28761. var r = w / 2; // Dist on y with tangent point and circle center
  28762. var dy = r * r / (h - r);
  28763. var cy = y - h + r + dy;
  28764. var angle = Math.asin(dy / r); // Dist on x with tangent point and circle center
  28765. var dx = Math.cos(angle) * r;
  28766. var tanX = Math.sin(angle);
  28767. var tanY = Math.cos(angle);
  28768. var cpLen = r * 0.6;
  28769. var cpLen2 = r * 0.7;
  28770. path.moveTo(x - dx, cy + dy);
  28771. path.arc(x, cy, r, Math.PI - angle, Math.PI * 2 + angle);
  28772. path.bezierCurveTo(x + dx - tanX * cpLen, cy + dy + tanY * cpLen, x, y - cpLen2, x, y);
  28773. path.bezierCurveTo(x, y - cpLen2, x - dx + tanX * cpLen, cy + dy + tanY * cpLen, x - dx, cy + dy);
  28774. path.closePath();
  28775. }
  28776. });
  28777. /**
  28778. * Arrow shape
  28779. * @inner
  28780. */
  28781. var Arrow = extendShape({
  28782. type: 'arrow',
  28783. shape: {
  28784. x: 0,
  28785. y: 0,
  28786. width: 0,
  28787. height: 0
  28788. },
  28789. buildPath: function (ctx, shape) {
  28790. var height = shape.height;
  28791. var width = shape.width;
  28792. var x = shape.x;
  28793. var y = shape.y;
  28794. var dx = width / 3 * 2;
  28795. ctx.moveTo(x, y);
  28796. ctx.lineTo(x + dx, y + height);
  28797. ctx.lineTo(x, y + height / 4 * 3);
  28798. ctx.lineTo(x - dx, y + height);
  28799. ctx.lineTo(x, y);
  28800. ctx.closePath();
  28801. }
  28802. });
  28803. /**
  28804. * Map of path contructors
  28805. * @type {Object.<string, module:zrender/graphic/Path>}
  28806. */
  28807. var symbolCtors = {
  28808. line: Line,
  28809. rect: Rect,
  28810. roundRect: Rect,
  28811. square: Rect,
  28812. circle: Circle,
  28813. diamond: Diamond,
  28814. pin: Pin,
  28815. arrow: Arrow,
  28816. triangle: Triangle
  28817. };
  28818. var symbolShapeMakers = {
  28819. line: function (x, y, w, h, shape) {
  28820. // FIXME
  28821. shape.x1 = x;
  28822. shape.y1 = y + h / 2;
  28823. shape.x2 = x + w;
  28824. shape.y2 = y + h / 2;
  28825. },
  28826. rect: function (x, y, w, h, shape) {
  28827. shape.x = x;
  28828. shape.y = y;
  28829. shape.width = w;
  28830. shape.height = h;
  28831. },
  28832. roundRect: function (x, y, w, h, shape) {
  28833. shape.x = x;
  28834. shape.y = y;
  28835. shape.width = w;
  28836. shape.height = h;
  28837. shape.r = Math.min(w, h) / 4;
  28838. },
  28839. square: function (x, y, w, h, shape) {
  28840. var size = Math.min(w, h);
  28841. shape.x = x;
  28842. shape.y = y;
  28843. shape.width = size;
  28844. shape.height = size;
  28845. },
  28846. circle: function (x, y, w, h, shape) {
  28847. // Put circle in the center of square
  28848. shape.cx = x + w / 2;
  28849. shape.cy = y + h / 2;
  28850. shape.r = Math.min(w, h) / 2;
  28851. },
  28852. diamond: function (x, y, w, h, shape) {
  28853. shape.cx = x + w / 2;
  28854. shape.cy = y + h / 2;
  28855. shape.width = w;
  28856. shape.height = h;
  28857. },
  28858. pin: function (x, y, w, h, shape) {
  28859. shape.x = x + w / 2;
  28860. shape.y = y + h / 2;
  28861. shape.width = w;
  28862. shape.height = h;
  28863. },
  28864. arrow: function (x, y, w, h, shape) {
  28865. shape.x = x + w / 2;
  28866. shape.y = y + h / 2;
  28867. shape.width = w;
  28868. shape.height = h;
  28869. },
  28870. triangle: function (x, y, w, h, shape) {
  28871. shape.cx = x + w / 2;
  28872. shape.cy = y + h / 2;
  28873. shape.width = w;
  28874. shape.height = h;
  28875. }
  28876. };
  28877. var symbolBuildProxies = {};
  28878. each$1(symbolCtors, function (Ctor, name) {
  28879. symbolBuildProxies[name] = new Ctor();
  28880. });
  28881. var SymbolClz = extendShape({
  28882. type: 'symbol',
  28883. shape: {
  28884. symbolType: '',
  28885. x: 0,
  28886. y: 0,
  28887. width: 0,
  28888. height: 0
  28889. },
  28890. calculateTextPosition: function (out, style, rect) {
  28891. var res = calculateTextPosition(out, style, rect);
  28892. var shape = this.shape;
  28893. if (shape && shape.symbolType === 'pin' && style.textPosition === 'inside') {
  28894. res.y = rect.y + rect.height * 0.4;
  28895. }
  28896. return res;
  28897. },
  28898. buildPath: function (ctx, shape, inBundle) {
  28899. var symbolType = shape.symbolType;
  28900. if (symbolType !== 'none') {
  28901. var proxySymbol = symbolBuildProxies[symbolType];
  28902. if (!proxySymbol) {
  28903. // Default rect
  28904. symbolType = 'rect';
  28905. proxySymbol = symbolBuildProxies[symbolType];
  28906. }
  28907. symbolShapeMakers[symbolType](shape.x, shape.y, shape.width, shape.height, proxySymbol.shape);
  28908. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  28909. }
  28910. }
  28911. }); // Provide setColor helper method to avoid determine if set the fill or stroke outside
  28912. function symbolPathSetColor(color, innerColor) {
  28913. if (this.type !== 'image') {
  28914. var symbolStyle = this.style;
  28915. var symbolShape = this.shape;
  28916. if (symbolShape && symbolShape.symbolType === 'line') {
  28917. symbolStyle.stroke = color;
  28918. } else if (this.__isEmptyBrush) {
  28919. symbolStyle.stroke = color;
  28920. symbolStyle.fill = innerColor || '#fff';
  28921. } else {
  28922. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  28923. symbolStyle.fill && (symbolStyle.fill = color);
  28924. symbolStyle.stroke && (symbolStyle.stroke = color);
  28925. }
  28926. this.dirty(false);
  28927. }
  28928. }
  28929. /**
  28930. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  28931. * @param {string} symbolType
  28932. * @param {number} x
  28933. * @param {number} y
  28934. * @param {number} w
  28935. * @param {number} h
  28936. * @param {string} color
  28937. * @param {boolean} [keepAspect=false] whether to keep the ratio of w/h,
  28938. * for path and image only.
  28939. */
  28940. function createSymbol(symbolType, x, y, w, h, color, keepAspect) {
  28941. // TODO Support image object, DynamicImage.
  28942. var isEmpty = symbolType.indexOf('empty') === 0;
  28943. if (isEmpty) {
  28944. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  28945. }
  28946. var symbolPath;
  28947. if (symbolType.indexOf('image://') === 0) {
  28948. symbolPath = makeImage(symbolType.slice(8), new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  28949. } else if (symbolType.indexOf('path://') === 0) {
  28950. symbolPath = makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h), keepAspect ? 'center' : 'cover');
  28951. } else {
  28952. symbolPath = new SymbolClz({
  28953. shape: {
  28954. symbolType: symbolType,
  28955. x: x,
  28956. y: y,
  28957. width: w,
  28958. height: h
  28959. }
  28960. });
  28961. }
  28962. symbolPath.__isEmptyBrush = isEmpty;
  28963. symbolPath.setColor = symbolPathSetColor;
  28964. symbolPath.setColor(color);
  28965. return symbolPath;
  28966. }
  28967. /*
  28968. * Licensed to the Apache Software Foundation (ASF) under one
  28969. * or more contributor license agreements. See the NOTICE file
  28970. * distributed with this work for additional information
  28971. * regarding copyright ownership. The ASF licenses this file
  28972. * to you under the Apache License, Version 2.0 (the
  28973. * "License"); you may not use this file except in compliance
  28974. * with the License. You may obtain a copy of the License at
  28975. *
  28976. * http://www.apache.org/licenses/LICENSE-2.0
  28977. *
  28978. * Unless required by applicable law or agreed to in writing,
  28979. * software distributed under the License is distributed on an
  28980. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28981. * KIND, either express or implied. See the License for the
  28982. * specific language governing permissions and limitations
  28983. * under the License.
  28984. */
  28985. /**
  28986. * Create a muti dimension List structure from seriesModel.
  28987. * @param {module:echarts/model/Model} seriesModel
  28988. * @return {module:echarts/data/List} list
  28989. */
  28990. function createList(seriesModel) {
  28991. return createListFromArray(seriesModel.getSource(), seriesModel);
  28992. } // export function createGraph(seriesModel) {
  28993. var dataStack$1 = {
  28994. isDimensionStacked: isDimensionStacked,
  28995. enableDataStack: enableDataStack,
  28996. getStackedDimension: getStackedDimension
  28997. };
  28998. /**
  28999. * Create scale
  29000. * @param {Array.<number>} dataExtent
  29001. * @param {Object|module:echarts/Model} option
  29002. */
  29003. function createScale(dataExtent, option) {
  29004. var axisModel = option;
  29005. if (!Model.isInstance(option)) {
  29006. axisModel = new Model(option);
  29007. mixin(axisModel, axisModelCommonMixin);
  29008. }
  29009. var scale = createScaleByModel(axisModel);
  29010. scale.setExtent(dataExtent[0], dataExtent[1]);
  29011. niceScaleExtent(scale, axisModel);
  29012. return scale;
  29013. }
  29014. /**
  29015. * Mixin common methods to axis model,
  29016. *
  29017. * Inlcude methods
  29018. * `getFormattedLabels() => Array.<string>`
  29019. * `getCategories() => Array.<string>`
  29020. * `getMin(origin: boolean) => number`
  29021. * `getMax(origin: boolean) => number`
  29022. * `getNeedCrossZero() => boolean`
  29023. * `setRange(start: number, end: number)`
  29024. * `resetRange()`
  29025. */
  29026. function mixinAxisModelCommonMethods(Model$$1) {
  29027. mixin(Model$$1, axisModelCommonMixin);
  29028. }
  29029. var helper = (Object.freeze || Object)({
  29030. createList: createList,
  29031. getLayoutRect: getLayoutRect,
  29032. dataStack: dataStack$1,
  29033. createScale: createScale,
  29034. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  29035. completeDimensions: completeDimensions,
  29036. createDimensions: createDimensions,
  29037. createSymbol: createSymbol
  29038. });
  29039. var EPSILON$3 = 1e-8;
  29040. function isAroundEqual$1(a, b) {
  29041. return Math.abs(a - b) < EPSILON$3;
  29042. }
  29043. function contain$1(points, x, y) {
  29044. var w = 0;
  29045. var p = points[0];
  29046. if (!p) {
  29047. return false;
  29048. }
  29049. for (var i = 1; i < points.length; i++) {
  29050. var p2 = points[i];
  29051. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  29052. p = p2;
  29053. } // Close polygon
  29054. var p0 = points[0];
  29055. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  29056. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  29057. }
  29058. return w !== 0;
  29059. }
  29060. /*
  29061. * Licensed to the Apache Software Foundation (ASF) under one
  29062. * or more contributor license agreements. See the NOTICE file
  29063. * distributed with this work for additional information
  29064. * regarding copyright ownership. The ASF licenses this file
  29065. * to you under the Apache License, Version 2.0 (the
  29066. * "License"); you may not use this file except in compliance
  29067. * with the License. You may obtain a copy of the License at
  29068. *
  29069. * http://www.apache.org/licenses/LICENSE-2.0
  29070. *
  29071. * Unless required by applicable law or agreed to in writing,
  29072. * software distributed under the License is distributed on an
  29073. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29074. * KIND, either express or implied. See the License for the
  29075. * specific language governing permissions and limitations
  29076. * under the License.
  29077. */
  29078. /**
  29079. * @module echarts/coord/geo/Region
  29080. */
  29081. /**
  29082. * @param {string|Region} name
  29083. * @param {Array} geometries
  29084. * @param {Array.<number>} cp
  29085. */
  29086. function Region(name, geometries, cp) {
  29087. /**
  29088. * @type {string}
  29089. * @readOnly
  29090. */
  29091. this.name = name;
  29092. /**
  29093. * @type {Array.<Array>}
  29094. * @readOnly
  29095. */
  29096. this.geometries = geometries;
  29097. if (!cp) {
  29098. var rect = this.getBoundingRect();
  29099. cp = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  29100. } else {
  29101. cp = [cp[0], cp[1]];
  29102. }
  29103. /**
  29104. * @type {Array.<number>}
  29105. */
  29106. this.center = cp;
  29107. }
  29108. Region.prototype = {
  29109. constructor: Region,
  29110. properties: null,
  29111. /**
  29112. * @return {module:zrender/core/BoundingRect}
  29113. */
  29114. getBoundingRect: function () {
  29115. var rect = this._rect;
  29116. if (rect) {
  29117. return rect;
  29118. }
  29119. var MAX_NUMBER = Number.MAX_VALUE;
  29120. var min$$1 = [MAX_NUMBER, MAX_NUMBER];
  29121. var max$$1 = [-MAX_NUMBER, -MAX_NUMBER];
  29122. var min2 = [];
  29123. var max2 = [];
  29124. var geometries = this.geometries;
  29125. for (var i = 0; i < geometries.length; i++) {
  29126. // Only support polygon
  29127. if (geometries[i].type !== 'polygon') {
  29128. continue;
  29129. } // Doesn't consider hole
  29130. var exterior = geometries[i].exterior;
  29131. fromPoints(exterior, min2, max2);
  29132. min(min$$1, min$$1, min2);
  29133. max(max$$1, max$$1, max2);
  29134. } // No data
  29135. if (i === 0) {
  29136. min$$1[0] = min$$1[1] = max$$1[0] = max$$1[1] = 0;
  29137. }
  29138. return this._rect = new BoundingRect(min$$1[0], min$$1[1], max$$1[0] - min$$1[0], max$$1[1] - min$$1[1]);
  29139. },
  29140. /**
  29141. * @param {<Array.<number>} coord
  29142. * @return {boolean}
  29143. */
  29144. contain: function (coord) {
  29145. var rect = this.getBoundingRect();
  29146. var geometries = this.geometries;
  29147. if (!rect.contain(coord[0], coord[1])) {
  29148. return false;
  29149. }
  29150. loopGeo: for (var i = 0, len$$1 = geometries.length; i < len$$1; 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. if (contain$1(exterior, coord[0], coord[1])) {
  29158. // Not in the region if point is in the hole.
  29159. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  29160. if (contain$1(interiors[k])) {
  29161. continue loopGeo;
  29162. }
  29163. }
  29164. return true;
  29165. }
  29166. }
  29167. return false;
  29168. },
  29169. transformTo: function (x, y, width, height) {
  29170. var rect = this.getBoundingRect();
  29171. var aspect = rect.width / rect.height;
  29172. if (!width) {
  29173. width = aspect * height;
  29174. } else if (!height) {
  29175. height = width / aspect;
  29176. }
  29177. var target = new BoundingRect(x, y, width, height);
  29178. var transform = rect.calculateTransform(target);
  29179. var geometries = this.geometries;
  29180. for (var i = 0; i < geometries.length; i++) {
  29181. // Only support polygon.
  29182. if (geometries[i].type !== 'polygon') {
  29183. continue;
  29184. }
  29185. var exterior = geometries[i].exterior;
  29186. var interiors = geometries[i].interiors;
  29187. for (var p = 0; p < exterior.length; p++) {
  29188. applyTransform(exterior[p], exterior[p], transform);
  29189. }
  29190. for (var h = 0; h < (interiors ? interiors.length : 0); h++) {
  29191. for (var p = 0; p < interiors[h].length; p++) {
  29192. applyTransform(interiors[h][p], interiors[h][p], transform);
  29193. }
  29194. }
  29195. }
  29196. rect = this._rect;
  29197. rect.copy(target); // Update center
  29198. this.center = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  29199. },
  29200. cloneShallow: function (name) {
  29201. name == null && (name = this.name);
  29202. var newRegion = new Region(name, this.geometries, this.center);
  29203. newRegion._rect = this._rect;
  29204. newRegion.transformTo = null; // Simply avoid to be called.
  29205. return newRegion;
  29206. }
  29207. };
  29208. /*
  29209. * Licensed to the Apache Software Foundation (ASF) under one
  29210. * or more contributor license agreements. See the NOTICE file
  29211. * distributed with this work for additional information
  29212. * regarding copyright ownership. The ASF licenses this file
  29213. * to you under the Apache License, Version 2.0 (the
  29214. * "License"); you may not use this file except in compliance
  29215. * with the License. You may obtain a copy of the License at
  29216. *
  29217. * http://www.apache.org/licenses/LICENSE-2.0
  29218. *
  29219. * Unless required by applicable law or agreed to in writing,
  29220. * software distributed under the License is distributed on an
  29221. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29222. * KIND, either express or implied. See the License for the
  29223. * specific language governing permissions and limitations
  29224. * under the License.
  29225. */
  29226. /**
  29227. * Parse and decode geo json
  29228. * @module echarts/coord/geo/parseGeoJson
  29229. */
  29230. function decode(json) {
  29231. if (!json.UTF8Encoding) {
  29232. return json;
  29233. }
  29234. var encodeScale = json.UTF8Scale;
  29235. if (encodeScale == null) {
  29236. encodeScale = 1024;
  29237. }
  29238. var features = json.features;
  29239. for (var f = 0; f < features.length; f++) {
  29240. var feature = features[f];
  29241. var geometry = feature.geometry;
  29242. var coordinates = geometry.coordinates;
  29243. var encodeOffsets = geometry.encodeOffsets;
  29244. for (var c = 0; c < coordinates.length; c++) {
  29245. var coordinate = coordinates[c];
  29246. if (geometry.type === 'Polygon') {
  29247. coordinates[c] = decodePolygon(coordinate, encodeOffsets[c], encodeScale);
  29248. } else if (geometry.type === 'MultiPolygon') {
  29249. for (var c2 = 0; c2 < coordinate.length; c2++) {
  29250. var polygon = coordinate[c2];
  29251. coordinate[c2] = decodePolygon(polygon, encodeOffsets[c][c2], encodeScale);
  29252. }
  29253. }
  29254. }
  29255. } // Has been decoded
  29256. json.UTF8Encoding = false;
  29257. return json;
  29258. }
  29259. function decodePolygon(coordinate, encodeOffsets, encodeScale) {
  29260. var result = [];
  29261. var prevX = encodeOffsets[0];
  29262. var prevY = encodeOffsets[1];
  29263. for (var i = 0; i < coordinate.length; i += 2) {
  29264. var x = coordinate.charCodeAt(i) - 64;
  29265. var y = coordinate.charCodeAt(i + 1) - 64; // ZigZag decoding
  29266. x = x >> 1 ^ -(x & 1);
  29267. y = y >> 1 ^ -(y & 1); // Delta deocding
  29268. x += prevX;
  29269. y += prevY;
  29270. prevX = x;
  29271. prevY = y; // Dequantize
  29272. result.push([x / encodeScale, y / encodeScale]);
  29273. }
  29274. return result;
  29275. }
  29276. /**
  29277. * @alias module:echarts/coord/geo/parseGeoJson
  29278. * @param {Object} geoJson
  29279. * @param {string} nameProperty
  29280. * @return {module:zrender/container/Group}
  29281. */
  29282. var parseGeoJson$1 = function (geoJson, nameProperty) {
  29283. decode(geoJson);
  29284. return map(filter(geoJson.features, function (featureObj) {
  29285. // Output of mapshaper may have geometry null
  29286. return featureObj.geometry && featureObj.properties && featureObj.geometry.coordinates.length > 0;
  29287. }), function (featureObj) {
  29288. var properties = featureObj.properties;
  29289. var geo = featureObj.geometry;
  29290. var coordinates = geo.coordinates;
  29291. var geometries = [];
  29292. if (geo.type === 'Polygon') {
  29293. geometries.push({
  29294. type: 'polygon',
  29295. // According to the GeoJSON specification.
  29296. // First must be exterior, and the rest are all interior(holes).
  29297. exterior: coordinates[0],
  29298. interiors: coordinates.slice(1)
  29299. });
  29300. }
  29301. if (geo.type === 'MultiPolygon') {
  29302. each$1(coordinates, function (item) {
  29303. if (item[0]) {
  29304. geometries.push({
  29305. type: 'polygon',
  29306. exterior: item[0],
  29307. interiors: item.slice(1)
  29308. });
  29309. }
  29310. });
  29311. }
  29312. var region = new Region(properties[nameProperty || 'name'], geometries, properties.cp);
  29313. region.properties = properties;
  29314. return region;
  29315. });
  29316. };
  29317. /*
  29318. * Licensed to the Apache Software Foundation (ASF) under one
  29319. * or more contributor license agreements. See the NOTICE file
  29320. * distributed with this work for additional information
  29321. * regarding copyright ownership. The ASF licenses this file
  29322. * to you under the Apache License, Version 2.0 (the
  29323. * "License"); you may not use this file except in compliance
  29324. * with the License. You may obtain a copy of the License at
  29325. *
  29326. * http://www.apache.org/licenses/LICENSE-2.0
  29327. *
  29328. * Unless required by applicable law or agreed to in writing,
  29329. * software distributed under the License is distributed on an
  29330. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29331. * KIND, either express or implied. See the License for the
  29332. * specific language governing permissions and limitations
  29333. * under the License.
  29334. */
  29335. var inner$6 = makeInner();
  29336. /**
  29337. * @param {module:echats/coord/Axis} axis
  29338. * @return {Object} {
  29339. * labels: [{
  29340. * formattedLabel: string,
  29341. * rawLabel: string,
  29342. * tickValue: number
  29343. * }, ...],
  29344. * labelCategoryInterval: number
  29345. * }
  29346. */
  29347. function createAxisLabels(axis) {
  29348. // Only ordinal scale support tick interval
  29349. return axis.type === 'category' ? makeCategoryLabels(axis) : makeRealNumberLabels(axis);
  29350. }
  29351. /**
  29352. * @param {module:echats/coord/Axis} axis
  29353. * @param {module:echarts/model/Model} tickModel For example, can be axisTick, splitLine, splitArea.
  29354. * @return {Object} {
  29355. * ticks: Array.<number>
  29356. * tickCategoryInterval: number
  29357. * }
  29358. */
  29359. function createAxisTicks(axis, tickModel) {
  29360. // Only ordinal scale support tick interval
  29361. return axis.type === 'category' ? makeCategoryTicks(axis, tickModel) : {
  29362. ticks: axis.scale.getTicks()
  29363. };
  29364. }
  29365. function makeCategoryLabels(axis) {
  29366. var labelModel = axis.getLabelModel();
  29367. var result = makeCategoryLabelsActually(axis, labelModel);
  29368. return !labelModel.get('show') || axis.scale.isBlank() ? {
  29369. labels: [],
  29370. labelCategoryInterval: result.labelCategoryInterval
  29371. } : result;
  29372. }
  29373. function makeCategoryLabelsActually(axis, labelModel) {
  29374. var labelsCache = getListCache(axis, 'labels');
  29375. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  29376. var result = listCacheGet(labelsCache, optionLabelInterval);
  29377. if (result) {
  29378. return result;
  29379. }
  29380. var labels;
  29381. var numericLabelInterval;
  29382. if (isFunction$1(optionLabelInterval)) {
  29383. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  29384. } else {
  29385. numericLabelInterval = optionLabelInterval === 'auto' ? makeAutoCategoryInterval(axis) : optionLabelInterval;
  29386. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  29387. } // Cache to avoid calling interval function repeatly.
  29388. return listCacheSet(labelsCache, optionLabelInterval, {
  29389. labels: labels,
  29390. labelCategoryInterval: numericLabelInterval
  29391. });
  29392. }
  29393. function makeCategoryTicks(axis, tickModel) {
  29394. var ticksCache = getListCache(axis, 'ticks');
  29395. var optionTickInterval = getOptionCategoryInterval(tickModel);
  29396. var result = listCacheGet(ticksCache, optionTickInterval);
  29397. if (result) {
  29398. return result;
  29399. }
  29400. var ticks;
  29401. var tickCategoryInterval; // Optimize for the case that large category data and no label displayed,
  29402. // we should not return all ticks.
  29403. if (!tickModel.get('show') || axis.scale.isBlank()) {
  29404. ticks = [];
  29405. }
  29406. if (isFunction$1(optionTickInterval)) {
  29407. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  29408. } // Always use label interval by default despite label show. Consider this
  29409. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  29410. // labels. `splitLine` and `axisTick` should be consistent in this case.
  29411. else if (optionTickInterval === 'auto') {
  29412. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel());
  29413. tickCategoryInterval = labelsResult.labelCategoryInterval;
  29414. ticks = map(labelsResult.labels, function (labelItem) {
  29415. return labelItem.tickValue;
  29416. });
  29417. } else {
  29418. tickCategoryInterval = optionTickInterval;
  29419. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  29420. } // Cache to avoid calling interval function repeatly.
  29421. return listCacheSet(ticksCache, optionTickInterval, {
  29422. ticks: ticks,
  29423. tickCategoryInterval: tickCategoryInterval
  29424. });
  29425. }
  29426. function makeRealNumberLabels(axis) {
  29427. var ticks = axis.scale.getTicks();
  29428. var labelFormatter = makeLabelFormatter(axis);
  29429. return {
  29430. labels: map(ticks, function (tickValue, idx) {
  29431. return {
  29432. formattedLabel: labelFormatter(tickValue, idx),
  29433. rawLabel: axis.scale.getLabel(tickValue),
  29434. tickValue: tickValue
  29435. };
  29436. })
  29437. };
  29438. } // Large category data calculation is performence sensitive, and ticks and label
  29439. // probably be fetched by multiple times. So we cache the result.
  29440. // axis is created each time during a ec process, so we do not need to clear cache.
  29441. function getListCache(axis, prop) {
  29442. // Because key can be funciton, and cache size always be small, we use array cache.
  29443. return inner$6(axis)[prop] || (inner$6(axis)[prop] = []);
  29444. }
  29445. function listCacheGet(cache, key) {
  29446. for (var i = 0; i < cache.length; i++) {
  29447. if (cache[i].key === key) {
  29448. return cache[i].value;
  29449. }
  29450. }
  29451. }
  29452. function listCacheSet(cache, key, value) {
  29453. cache.push({
  29454. key: key,
  29455. value: value
  29456. });
  29457. return value;
  29458. }
  29459. function makeAutoCategoryInterval(axis) {
  29460. var result = inner$6(axis).autoInterval;
  29461. return result != null ? result : inner$6(axis).autoInterval = axis.calculateCategoryInterval();
  29462. }
  29463. /**
  29464. * Calculate interval for category axis ticks and labels.
  29465. * To get precise result, at least one of `getRotate` and `isHorizontal`
  29466. * should be implemented in axis.
  29467. */
  29468. function calculateCategoryInterval(axis) {
  29469. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  29470. var labelFormatter = makeLabelFormatter(axis);
  29471. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  29472. var ordinalScale = axis.scale;
  29473. var ordinalExtent = ordinalScale.getExtent(); // Providing this method is for optimization:
  29474. // avoid generating a long array by `getTicks`
  29475. // in large category data case.
  29476. var tickCount = ordinalScale.count();
  29477. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  29478. return 0;
  29479. }
  29480. var step = 1; // Simple optimization. Empirical value: tick count should less than 40.
  29481. if (tickCount > 40) {
  29482. step = Math.max(1, Math.floor(tickCount / 40));
  29483. }
  29484. var tickValue = ordinalExtent[0];
  29485. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  29486. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  29487. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  29488. var maxW = 0;
  29489. var maxH = 0; // Caution: Performance sensitive for large category data.
  29490. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  29491. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  29492. var width = 0;
  29493. var height = 0; // Not precise, do not consider align and vertical align
  29494. // and each distance from axis line yet.
  29495. var rect = getBoundingRect(labelFormatter(tickValue), params.font, 'center', 'top'); // Magic number
  29496. width = rect.width * 1.3;
  29497. height = rect.height * 1.3; // Min size, void long loop.
  29498. maxW = Math.max(maxW, width, 7);
  29499. maxH = Math.max(maxH, height, 7);
  29500. }
  29501. var dw = maxW / unitW;
  29502. var dh = maxH / unitH; // 0/0 is NaN, 1/0 is Infinity.
  29503. isNaN(dw) && (dw = Infinity);
  29504. isNaN(dh) && (dh = Infinity);
  29505. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  29506. var cache = inner$6(axis.model);
  29507. var axisExtent = axis.getExtent();
  29508. var lastAutoInterval = cache.lastAutoInterval;
  29509. var lastTickCount = cache.lastTickCount; // Use cache to keep interval stable while moving zoom window,
  29510. // otherwise the calculated interval might jitter when the zoom
  29511. // window size is close to the interval-changing size.
  29512. // For example, if all of the axis labels are `a, b, c, d, e, f, g`.
  29513. // The jitter will cause that sometimes the displayed labels are
  29514. // `a, d, g` (interval: 2) sometimes `a, c, e`(interval: 1).
  29515. if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1 // Always choose the bigger one, otherwise the critical
  29516. // point is not the same when zooming in or zooming out.
  29517. && lastAutoInterval > interval // If the axis change is caused by chart resize, the cache should not
  29518. // be used. Otherwise some hiden labels might not be shown again.
  29519. && cache.axisExtend0 === axisExtent[0] && cache.axisExtend1 === axisExtent[1]) {
  29520. interval = lastAutoInterval;
  29521. } // Only update cache if cache not used, otherwise the
  29522. // changing of interval is too insensitive.
  29523. else {
  29524. cache.lastTickCount = tickCount;
  29525. cache.lastAutoInterval = interval;
  29526. cache.axisExtend0 = axisExtent[0];
  29527. cache.axisExtend1 = axisExtent[1];
  29528. }
  29529. return interval;
  29530. }
  29531. function fetchAutoCategoryIntervalCalculationParams(axis) {
  29532. var labelModel = axis.getLabelModel();
  29533. return {
  29534. axisRotate: axis.getRotate ? axis.getRotate() : axis.isHorizontal && !axis.isHorizontal() ? 90 : 0,
  29535. labelRotate: labelModel.get('rotate') || 0,
  29536. font: labelModel.getFont()
  29537. };
  29538. }
  29539. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  29540. var labelFormatter = makeLabelFormatter(axis);
  29541. var ordinalScale = axis.scale;
  29542. var ordinalExtent = ordinalScale.getExtent();
  29543. var labelModel = axis.getLabelModel();
  29544. var result = []; // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  29545. var step = Math.max((categoryInterval || 0) + 1, 1);
  29546. var startTick = ordinalExtent[0];
  29547. var tickCount = ordinalScale.count(); // Calculate start tick based on zero if possible to keep label consistent
  29548. // while zooming and moving while interval > 0. Otherwise the selection
  29549. // of displayable ticks and symbols probably keep changing.
  29550. // 3 is empirical value.
  29551. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  29552. startTick = Math.round(Math.ceil(startTick / step) * step);
  29553. } // (1) Only add min max label here but leave overlap checking
  29554. // to render stage, which also ensure the returned list
  29555. // suitable for splitLine and splitArea rendering.
  29556. // (2) Scales except category always contain min max label so
  29557. // do not need to perform this process.
  29558. var showAllLabel = shouldShowAllLabels(axis);
  29559. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  29560. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  29561. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  29562. addItem(ordinalExtent[0]);
  29563. } // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  29564. var tickValue = startTick;
  29565. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  29566. addItem(tickValue);
  29567. }
  29568. if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
  29569. addItem(ordinalExtent[1]);
  29570. }
  29571. function addItem(tVal) {
  29572. result.push(onlyTick ? tVal : {
  29573. formattedLabel: labelFormatter(tVal),
  29574. rawLabel: ordinalScale.getLabel(tVal),
  29575. tickValue: tVal
  29576. });
  29577. }
  29578. return result;
  29579. } // When interval is function, the result `false` means ignore the tick.
  29580. // It is time consuming for large category data.
  29581. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  29582. var ordinalScale = axis.scale;
  29583. var labelFormatter = makeLabelFormatter(axis);
  29584. var result = [];
  29585. each$1(ordinalScale.getTicks(), function (tickValue) {
  29586. var rawLabel = ordinalScale.getLabel(tickValue);
  29587. if (categoryInterval(tickValue, rawLabel)) {
  29588. result.push(onlyTick ? tickValue : {
  29589. formattedLabel: labelFormatter(tickValue),
  29590. rawLabel: rawLabel,
  29591. tickValue: tickValue
  29592. });
  29593. }
  29594. });
  29595. return result;
  29596. }
  29597. /*
  29598. * Licensed to the Apache Software Foundation (ASF) under one
  29599. * or more contributor license agreements. See the NOTICE file
  29600. * distributed with this work for additional information
  29601. * regarding copyright ownership. The ASF licenses this file
  29602. * to you under the Apache License, Version 2.0 (the
  29603. * "License"); you may not use this file except in compliance
  29604. * with the License. You may obtain a copy of the License at
  29605. *
  29606. * http://www.apache.org/licenses/LICENSE-2.0
  29607. *
  29608. * Unless required by applicable law or agreed to in writing,
  29609. * software distributed under the License is distributed on an
  29610. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29611. * KIND, either express or implied. See the License for the
  29612. * specific language governing permissions and limitations
  29613. * under the License.
  29614. */
  29615. var NORMALIZED_EXTENT = [0, 1];
  29616. /**
  29617. * Base class of Axis.
  29618. * @constructor
  29619. */
  29620. var Axis = function (dim, scale, extent) {
  29621. /**
  29622. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'.
  29623. * @type {string}
  29624. */
  29625. this.dim = dim;
  29626. /**
  29627. * Axis scale
  29628. * @type {module:echarts/coord/scale/*}
  29629. */
  29630. this.scale = scale;
  29631. /**
  29632. * @type {Array.<number>}
  29633. * @private
  29634. */
  29635. this._extent = extent || [0, 0];
  29636. /**
  29637. * @type {boolean}
  29638. */
  29639. this.inverse = false;
  29640. /**
  29641. * Usually true when axis has a ordinal scale
  29642. * @type {boolean}
  29643. */
  29644. this.onBand = false;
  29645. };
  29646. Axis.prototype = {
  29647. constructor: Axis,
  29648. /**
  29649. * If axis extent contain given coord
  29650. * @param {number} coord
  29651. * @return {boolean}
  29652. */
  29653. contain: function (coord) {
  29654. var extent = this._extent;
  29655. var min = Math.min(extent[0], extent[1]);
  29656. var max = Math.max(extent[0], extent[1]);
  29657. return coord >= min && coord <= max;
  29658. },
  29659. /**
  29660. * If axis extent contain given data
  29661. * @param {number} data
  29662. * @return {boolean}
  29663. */
  29664. containData: function (data) {
  29665. return this.scale.contain(data);
  29666. },
  29667. /**
  29668. * Get coord extent.
  29669. * @return {Array.<number>}
  29670. */
  29671. getExtent: function () {
  29672. return this._extent.slice();
  29673. },
  29674. /**
  29675. * Get precision used for formatting
  29676. * @param {Array.<number>} [dataExtent]
  29677. * @return {number}
  29678. */
  29679. getPixelPrecision: function (dataExtent) {
  29680. return getPixelPrecision(dataExtent || this.scale.getExtent(), this._extent);
  29681. },
  29682. /**
  29683. * Set coord extent
  29684. * @param {number} start
  29685. * @param {number} end
  29686. */
  29687. setExtent: function (start, end) {
  29688. var extent = this._extent;
  29689. extent[0] = start;
  29690. extent[1] = end;
  29691. },
  29692. /**
  29693. * Convert data to coord. Data is the rank if it has an ordinal scale
  29694. * @param {number} data
  29695. * @param {boolean} clamp
  29696. * @return {number}
  29697. */
  29698. dataToCoord: function (data, clamp) {
  29699. var extent = this._extent;
  29700. var scale = this.scale;
  29701. data = scale.normalize(data);
  29702. if (this.onBand && scale.type === 'ordinal') {
  29703. extent = extent.slice();
  29704. fixExtentWithBands(extent, scale.count());
  29705. }
  29706. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  29707. },
  29708. /**
  29709. * Convert coord to data. Data is the rank if it has an ordinal scale
  29710. * @param {number} coord
  29711. * @param {boolean} clamp
  29712. * @return {number}
  29713. */
  29714. coordToData: function (coord, clamp) {
  29715. var extent = this._extent;
  29716. var scale = this.scale;
  29717. if (this.onBand && scale.type === 'ordinal') {
  29718. extent = extent.slice();
  29719. fixExtentWithBands(extent, scale.count());
  29720. }
  29721. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  29722. return this.scale.scale(t);
  29723. },
  29724. /**
  29725. * Convert pixel point to data in axis
  29726. * @param {Array.<number>} point
  29727. * @param {boolean} clamp
  29728. * @return {number} data
  29729. */
  29730. pointToData: function (point, clamp) {// Should be implemented in derived class if necessary.
  29731. },
  29732. /**
  29733. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  29734. * `axis.getTicksCoords` considers `onBand`, which is used by
  29735. * `boundaryGap:true` of category axis and splitLine and splitArea.
  29736. * @param {Object} [opt]
  29737. * @param {Model} [opt.tickModel=axis.model.getModel('axisTick')]
  29738. * @param {boolean} [opt.clamp] If `true`, the first and the last
  29739. * tick must be at the axis end points. Otherwise, clip ticks
  29740. * that outside the axis extent.
  29741. * @return {Array.<Object>} [{
  29742. * coord: ...,
  29743. * tickValue: ...
  29744. * }, ...]
  29745. */
  29746. getTicksCoords: function (opt) {
  29747. opt = opt || {};
  29748. var tickModel = opt.tickModel || this.getTickModel();
  29749. var result = createAxisTicks(this, tickModel);
  29750. var ticks = result.ticks;
  29751. var ticksCoords = map(ticks, function (tickValue) {
  29752. return {
  29753. coord: this.dataToCoord(tickValue),
  29754. tickValue: tickValue
  29755. };
  29756. }, this);
  29757. var alignWithLabel = tickModel.get('alignWithLabel');
  29758. fixOnBandTicksCoords(this, ticksCoords, alignWithLabel, opt.clamp);
  29759. return ticksCoords;
  29760. },
  29761. /**
  29762. * @return {Array.<Array.<Object>>} [{ coord: ..., tickValue: ...}]
  29763. */
  29764. getMinorTicksCoords: function () {
  29765. if (this.scale.type === 'ordinal') {
  29766. // Category axis doesn't support minor ticks
  29767. return [];
  29768. }
  29769. var minorTickModel = this.model.getModel('minorTick');
  29770. var splitNumber = minorTickModel.get('splitNumber'); // Protection.
  29771. if (!(splitNumber > 0 && splitNumber < 100)) {
  29772. splitNumber = 5;
  29773. }
  29774. var minorTicks = this.scale.getMinorTicks(splitNumber);
  29775. var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
  29776. return map(minorTicksGroup, function (minorTick) {
  29777. return {
  29778. coord: this.dataToCoord(minorTick),
  29779. tickValue: minorTick
  29780. };
  29781. }, this);
  29782. }, this);
  29783. return minorTicksCoords;
  29784. },
  29785. /**
  29786. * @return {Array.<Object>} [{
  29787. * formattedLabel: string,
  29788. * rawLabel: axis.scale.getLabel(tickValue)
  29789. * tickValue: number
  29790. * }, ...]
  29791. */
  29792. getViewLabels: function () {
  29793. return createAxisLabels(this).labels;
  29794. },
  29795. /**
  29796. * @return {module:echarts/coord/model/Model}
  29797. */
  29798. getLabelModel: function () {
  29799. return this.model.getModel('axisLabel');
  29800. },
  29801. /**
  29802. * Notice here we only get the default tick model. For splitLine
  29803. * or splitArea, we should pass the splitLineModel or splitAreaModel
  29804. * manually when calling `getTicksCoords`.
  29805. * In GL, this method may be overrided to:
  29806. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  29807. * @return {module:echarts/coord/model/Model}
  29808. */
  29809. getTickModel: function () {
  29810. return this.model.getModel('axisTick');
  29811. },
  29812. /**
  29813. * Get width of band
  29814. * @return {number}
  29815. */
  29816. getBandWidth: function () {
  29817. var axisExtent = this._extent;
  29818. var dataExtent = this.scale.getExtent();
  29819. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0); // Fix #2728, avoid NaN when only one data.
  29820. len === 0 && (len = 1);
  29821. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  29822. return Math.abs(size) / len;
  29823. },
  29824. /**
  29825. * @abstract
  29826. * @return {boolean} Is horizontal
  29827. */
  29828. isHorizontal: null,
  29829. /**
  29830. * @abstract
  29831. * @return {number} Get axis rotate, by degree.
  29832. */
  29833. getRotate: null,
  29834. /**
  29835. * Only be called in category axis.
  29836. * Can be overrided, consider other axes like in 3D.
  29837. * @return {number} Auto interval for cateogry axis tick and label
  29838. */
  29839. calculateCategoryInterval: function () {
  29840. return calculateCategoryInterval(this);
  29841. }
  29842. };
  29843. function fixExtentWithBands(extent, nTick) {
  29844. var size = extent[1] - extent[0];
  29845. var len = nTick;
  29846. var margin = size / len / 2;
  29847. extent[0] += margin;
  29848. extent[1] -= margin;
  29849. } // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  29850. // |---1---|---2---|---3---|---4---|.
  29851. // So the displayed ticks and splitLine/splitArea should between
  29852. // each data item, otherwise cause misleading (e.g., split tow bars
  29853. // of a single data item when there are two bar series).
  29854. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  29855. // splitLine/spliteArea should layout appropriately corresponding
  29856. // to displayed labels. (So we should not use `getBandWidth` in this
  29857. // case).
  29858. function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) {
  29859. var ticksLen = ticksCoords.length;
  29860. if (!axis.onBand || alignWithLabel || !ticksLen) {
  29861. return;
  29862. }
  29863. var axisExtent = axis.getExtent();
  29864. var last;
  29865. var diffSize;
  29866. if (ticksLen === 1) {
  29867. ticksCoords[0].coord = axisExtent[0];
  29868. last = ticksCoords[1] = {
  29869. coord: axisExtent[0]
  29870. };
  29871. } else {
  29872. var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
  29873. var shift = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen;
  29874. each$1(ticksCoords, function (ticksItem) {
  29875. ticksItem.coord -= shift / 2;
  29876. });
  29877. var dataExtent = axis.scale.getExtent();
  29878. diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
  29879. last = {
  29880. coord: ticksCoords[ticksLen - 1].coord + shift * diffSize
  29881. };
  29882. ticksCoords.push(last);
  29883. }
  29884. var inverse = axisExtent[0] > axisExtent[1]; // Handling clamp.
  29885. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  29886. clamp ? ticksCoords[0].coord = axisExtent[0] : ticksCoords.shift();
  29887. }
  29888. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  29889. ticksCoords.unshift({
  29890. coord: axisExtent[0]
  29891. });
  29892. }
  29893. if (littleThan(axisExtent[1], last.coord)) {
  29894. clamp ? last.coord = axisExtent[1] : ticksCoords.pop();
  29895. }
  29896. if (clamp && littleThan(last.coord, axisExtent[1])) {
  29897. ticksCoords.push({
  29898. coord: axisExtent[1]
  29899. });
  29900. }
  29901. function littleThan(a, b) {
  29902. // Avoid rounding error cause calculated tick coord different with extent.
  29903. // It may cause an extra unecessary tick added.
  29904. a = round$1(a);
  29905. b = round$1(b);
  29906. return inverse ? a > b : a < b;
  29907. }
  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. /**
  29928. * Do not mount those modules on 'src/echarts' for better tree shaking.
  29929. */
  29930. var parseGeoJson = parseGeoJson$1;
  29931. var ecUtil = {};
  29932. each$1(['map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter', 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction', 'extend', 'defaults', 'clone', 'merge'], function (name) {
  29933. ecUtil[name] = zrUtil[name];
  29934. });
  29935. var graphic$1 = {};
  29936. 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) {
  29937. graphic$1[name] = graphic[name];
  29938. });
  29939. /*
  29940. * Licensed to the Apache Software Foundation (ASF) under one
  29941. * or more contributor license agreements. See the NOTICE file
  29942. * distributed with this work for additional information
  29943. * regarding copyright ownership. The ASF licenses this file
  29944. * to you under the Apache License, Version 2.0 (the
  29945. * "License"); you may not use this file except in compliance
  29946. * with the License. You may obtain a copy of the License at
  29947. *
  29948. * http://www.apache.org/licenses/LICENSE-2.0
  29949. *
  29950. * Unless required by applicable law or agreed to in writing,
  29951. * software distributed under the License is distributed on an
  29952. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29953. * KIND, either express or implied. See the License for the
  29954. * specific language governing permissions and limitations
  29955. * under the License.
  29956. */
  29957. /**
  29958. * Cartesian coordinate system
  29959. * @module echarts/coord/Cartesian
  29960. *
  29961. */
  29962. function dimAxisMapper(dim) {
  29963. return this._axes[dim];
  29964. }
  29965. /**
  29966. * @alias module:echarts/coord/Cartesian
  29967. * @constructor
  29968. */
  29969. var Cartesian = function (name) {
  29970. this._axes = {};
  29971. this._dimList = [];
  29972. /**
  29973. * @type {string}
  29974. */
  29975. this.name = name || '';
  29976. };
  29977. Cartesian.prototype = {
  29978. constructor: Cartesian,
  29979. type: 'cartesian',
  29980. /**
  29981. * Get axis
  29982. * @param {number|string} dim
  29983. * @return {module:echarts/coord/Cartesian~Axis}
  29984. */
  29985. getAxis: function (dim) {
  29986. return this._axes[dim];
  29987. },
  29988. /**
  29989. * Get axes list
  29990. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  29991. */
  29992. getAxes: function () {
  29993. return map(this._dimList, dimAxisMapper, this);
  29994. },
  29995. /**
  29996. * Get axes list by given scale type
  29997. */
  29998. getAxesByScale: function (scaleType) {
  29999. scaleType = scaleType.toLowerCase();
  30000. return filter(this.getAxes(), function (axis) {
  30001. return axis.scale.type === scaleType;
  30002. });
  30003. },
  30004. /**
  30005. * Add axis
  30006. * @param {module:echarts/coord/Cartesian.Axis}
  30007. */
  30008. addAxis: function (axis) {
  30009. var dim = axis.dim;
  30010. this._axes[dim] = axis;
  30011. this._dimList.push(dim);
  30012. },
  30013. /**
  30014. * Convert data to coord in nd space
  30015. * @param {Array.<number>|Object.<string, number>} val
  30016. * @return {Array.<number>|Object.<string, number>}
  30017. */
  30018. dataToCoord: function (val) {
  30019. return this._dataCoordConvert(val, 'dataToCoord');
  30020. },
  30021. /**
  30022. * Convert coord in nd space to data
  30023. * @param {Array.<number>|Object.<string, number>} val
  30024. * @return {Array.<number>|Object.<string, number>}
  30025. */
  30026. coordToData: function (val) {
  30027. return this._dataCoordConvert(val, 'coordToData');
  30028. },
  30029. _dataCoordConvert: function (input, method) {
  30030. var dimList = this._dimList;
  30031. var output = input instanceof Array ? [] : {};
  30032. for (var i = 0; i < dimList.length; i++) {
  30033. var dim = dimList[i];
  30034. var axis = this._axes[dim];
  30035. output[dim] = axis[method](input[dim]);
  30036. }
  30037. return output;
  30038. }
  30039. };
  30040. /*
  30041. * Licensed to the Apache Software Foundation (ASF) under one
  30042. * or more contributor license agreements. See the NOTICE file
  30043. * distributed with this work for additional information
  30044. * regarding copyright ownership. The ASF licenses this file
  30045. * to you under the Apache License, Version 2.0 (the
  30046. * "License"); you may not use this file except in compliance
  30047. * with the License. You may obtain a copy of the License at
  30048. *
  30049. * http://www.apache.org/licenses/LICENSE-2.0
  30050. *
  30051. * Unless required by applicable law or agreed to in writing,
  30052. * software distributed under the License is distributed on an
  30053. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30054. * KIND, either express or implied. See the License for the
  30055. * specific language governing permissions and limitations
  30056. * under the License.
  30057. */
  30058. function Cartesian2D(name) {
  30059. Cartesian.call(this, name);
  30060. }
  30061. Cartesian2D.prototype = {
  30062. constructor: Cartesian2D,
  30063. type: 'cartesian2d',
  30064. /**
  30065. * @type {Array.<string>}
  30066. * @readOnly
  30067. */
  30068. dimensions: ['x', 'y'],
  30069. /**
  30070. * Base axis will be used on stacking.
  30071. *
  30072. * @return {module:echarts/coord/cartesian/Axis2D}
  30073. */
  30074. getBaseAxis: function () {
  30075. return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x');
  30076. },
  30077. /**
  30078. * If contain point
  30079. * @param {Array.<number>} point
  30080. * @return {boolean}
  30081. */
  30082. containPoint: function (point) {
  30083. var axisX = this.getAxis('x');
  30084. var axisY = this.getAxis('y');
  30085. return axisX.contain(axisX.toLocalCoord(point[0])) && axisY.contain(axisY.toLocalCoord(point[1]));
  30086. },
  30087. /**
  30088. * If contain data
  30089. * @param {Array.<number>} data
  30090. * @return {boolean}
  30091. */
  30092. containData: function (data) {
  30093. return this.getAxis('x').containData(data[0]) && this.getAxis('y').containData(data[1]);
  30094. },
  30095. /**
  30096. * @param {Array.<number>} data
  30097. * @param {Array.<number>} out
  30098. * @return {Array.<number>}
  30099. */
  30100. dataToPoint: function (data, reserved, out) {
  30101. var xAxis = this.getAxis('x');
  30102. var yAxis = this.getAxis('y');
  30103. out = out || [];
  30104. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(data[0]));
  30105. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(data[1]));
  30106. return out;
  30107. },
  30108. /**
  30109. * @param {Array.<number>} data
  30110. * @param {Array.<number>} out
  30111. * @return {Array.<number>}
  30112. */
  30113. clampData: function (data, out) {
  30114. var xScale = this.getAxis('x').scale;
  30115. var yScale = this.getAxis('y').scale;
  30116. var xAxisExtent = xScale.getExtent();
  30117. var yAxisExtent = yScale.getExtent();
  30118. var x = xScale.parse(data[0]);
  30119. var y = yScale.parse(data[1]);
  30120. out = out || [];
  30121. out[0] = Math.min(Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x), Math.max(xAxisExtent[0], xAxisExtent[1]));
  30122. out[1] = Math.min(Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y), Math.max(yAxisExtent[0], yAxisExtent[1]));
  30123. return out;
  30124. },
  30125. /**
  30126. * @param {Array.<number>} point
  30127. * @param {Array.<number>} out
  30128. * @return {Array.<number>}
  30129. */
  30130. pointToData: function (point, out) {
  30131. var xAxis = this.getAxis('x');
  30132. var yAxis = this.getAxis('y');
  30133. out = out || [];
  30134. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]));
  30135. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]));
  30136. return out;
  30137. },
  30138. /**
  30139. * Get other axis
  30140. * @param {module:echarts/coord/cartesian/Axis2D} axis
  30141. */
  30142. getOtherAxis: function (axis) {
  30143. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  30144. },
  30145. /**
  30146. * Get rect area of cartesian.
  30147. * Area will have a contain function to determine if a point is in the coordinate system.
  30148. * @return {BoundingRect}
  30149. */
  30150. getArea: function () {
  30151. var xExtent = this.getAxis('x').getGlobalExtent();
  30152. var yExtent = this.getAxis('y').getGlobalExtent();
  30153. var x = Math.min(xExtent[0], xExtent[1]);
  30154. var y = Math.min(yExtent[0], yExtent[1]);
  30155. var width = Math.max(xExtent[0], xExtent[1]) - x;
  30156. var height = Math.max(yExtent[0], yExtent[1]) - y;
  30157. var rect = new BoundingRect(x, y, width, height);
  30158. return rect;
  30159. }
  30160. };
  30161. inherits(Cartesian2D, Cartesian);
  30162. /*
  30163. * Licensed to the Apache Software Foundation (ASF) under one
  30164. * or more contributor license agreements. See the NOTICE file
  30165. * distributed with this work for additional information
  30166. * regarding copyright ownership. The ASF licenses this file
  30167. * to you under the Apache License, Version 2.0 (the
  30168. * "License"); you may not use this file except in compliance
  30169. * with the License. You may obtain a copy of the License at
  30170. *
  30171. * http://www.apache.org/licenses/LICENSE-2.0
  30172. *
  30173. * Unless required by applicable law or agreed to in writing,
  30174. * software distributed under the License is distributed on an
  30175. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30176. * KIND, either express or implied. See the License for the
  30177. * specific language governing permissions and limitations
  30178. * under the License.
  30179. */
  30180. /**
  30181. * Extend axis 2d
  30182. * @constructor module:echarts/coord/cartesian/Axis2D
  30183. * @extends {module:echarts/coord/cartesian/Axis}
  30184. * @param {string} dim
  30185. * @param {*} scale
  30186. * @param {Array.<number>} coordExtent
  30187. * @param {string} axisType
  30188. * @param {string} position
  30189. */
  30190. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  30191. Axis.call(this, dim, scale, coordExtent);
  30192. /**
  30193. * Axis type
  30194. * - 'category'
  30195. * - 'value'
  30196. * - 'time'
  30197. * - 'log'
  30198. * @type {string}
  30199. */
  30200. this.type = axisType || 'value';
  30201. /**
  30202. * Axis position
  30203. * - 'top'
  30204. * - 'bottom'
  30205. * - 'left'
  30206. * - 'right'
  30207. */
  30208. this.position = position || 'bottom';
  30209. };
  30210. Axis2D.prototype = {
  30211. constructor: Axis2D,
  30212. /**
  30213. * Index of axis, can be used as key
  30214. */
  30215. index: 0,
  30216. /**
  30217. * Implemented in <module:echarts/coord/cartesian/Grid>.
  30218. * @return {Array.<module:echarts/coord/cartesian/Axis2D>}
  30219. * If not on zero of other axis, return null/undefined.
  30220. * If no axes, return an empty array.
  30221. */
  30222. getAxesOnZeroOf: null,
  30223. /**
  30224. * Axis model
  30225. * @param {module:echarts/coord/cartesian/AxisModel}
  30226. */
  30227. model: null,
  30228. isHorizontal: function () {
  30229. var position = this.position;
  30230. return position === 'top' || position === 'bottom';
  30231. },
  30232. /**
  30233. * Each item cooresponds to this.getExtent(), which
  30234. * means globalExtent[0] may greater than globalExtent[1],
  30235. * unless `asc` is input.
  30236. *
  30237. * @param {boolean} [asc]
  30238. * @return {Array.<number>}
  30239. */
  30240. getGlobalExtent: function (asc) {
  30241. var ret = this.getExtent();
  30242. ret[0] = this.toGlobalCoord(ret[0]);
  30243. ret[1] = this.toGlobalCoord(ret[1]);
  30244. asc && ret[0] > ret[1] && ret.reverse();
  30245. return ret;
  30246. },
  30247. getOtherAxis: function () {
  30248. this.grid.getOtherAxis();
  30249. },
  30250. /**
  30251. * @override
  30252. */
  30253. pointToData: function (point, clamp) {
  30254. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  30255. },
  30256. /**
  30257. * Transform global coord to local coord,
  30258. * i.e. var localCoord = axis.toLocalCoord(80);
  30259. * designate by module:echarts/coord/cartesian/Grid.
  30260. * @type {Function}
  30261. */
  30262. toLocalCoord: null,
  30263. /**
  30264. * Transform global coord to local coord,
  30265. * i.e. var globalCoord = axis.toLocalCoord(40);
  30266. * designate by module:echarts/coord/cartesian/Grid.
  30267. * @type {Function}
  30268. */
  30269. toGlobalCoord: null
  30270. };
  30271. inherits(Axis2D, Axis);
  30272. /*
  30273. * Licensed to the Apache Software Foundation (ASF) under one
  30274. * or more contributor license agreements. See the NOTICE file
  30275. * distributed with this work for additional information
  30276. * regarding copyright ownership. The ASF licenses this file
  30277. * to you under the Apache License, Version 2.0 (the
  30278. * "License"); you may not use this file except in compliance
  30279. * with the License. You may obtain a copy of the License at
  30280. *
  30281. * http://www.apache.org/licenses/LICENSE-2.0
  30282. *
  30283. * Unless required by applicable law or agreed to in writing,
  30284. * software distributed under the License is distributed on an
  30285. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30286. * KIND, either express or implied. See the License for the
  30287. * specific language governing permissions and limitations
  30288. * under the License.
  30289. */
  30290. var defaultOption = {
  30291. show: true,
  30292. zlevel: 0,
  30293. z: 0,
  30294. // Inverse the axis.
  30295. inverse: false,
  30296. // Axis name displayed.
  30297. name: '',
  30298. // 'start' | 'middle' | 'end'
  30299. nameLocation: 'end',
  30300. // By degree. By defualt auto rotate by nameLocation.
  30301. nameRotate: null,
  30302. nameTruncate: {
  30303. maxWidth: null,
  30304. ellipsis: '...',
  30305. placeholder: '.'
  30306. },
  30307. // Use global text style by default.
  30308. nameTextStyle: {},
  30309. // The gap between axisName and axisLine.
  30310. nameGap: 15,
  30311. // Default `false` to support tooltip.
  30312. silent: false,
  30313. // Default `false` to avoid legacy user event listener fail.
  30314. triggerEvent: false,
  30315. tooltip: {
  30316. show: false
  30317. },
  30318. axisPointer: {},
  30319. axisLine: {
  30320. show: true,
  30321. onZero: true,
  30322. onZeroAxisIndex: null,
  30323. lineStyle: {
  30324. color: '#333',
  30325. width: 1,
  30326. type: 'solid'
  30327. },
  30328. // The arrow at both ends the the axis.
  30329. symbol: ['none', 'none'],
  30330. symbolSize: [10, 15]
  30331. },
  30332. axisTick: {
  30333. show: true,
  30334. // Whether axisTick is inside the grid or outside the grid.
  30335. inside: false,
  30336. // The length of axisTick.
  30337. length: 5,
  30338. lineStyle: {
  30339. width: 1
  30340. }
  30341. },
  30342. axisLabel: {
  30343. show: true,
  30344. // Whether axisLabel is inside the grid or outside the grid.
  30345. inside: false,
  30346. rotate: 0,
  30347. // true | false | null/undefined (auto)
  30348. showMinLabel: null,
  30349. // true | false | null/undefined (auto)
  30350. showMaxLabel: null,
  30351. margin: 8,
  30352. // formatter: null,
  30353. fontSize: 12
  30354. },
  30355. splitLine: {
  30356. show: true,
  30357. lineStyle: {
  30358. color: ['#ccc'],
  30359. width: 1,
  30360. type: 'solid'
  30361. }
  30362. },
  30363. splitArea: {
  30364. show: false,
  30365. areaStyle: {
  30366. color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
  30367. }
  30368. }
  30369. };
  30370. var axisDefault = {};
  30371. axisDefault.categoryAxis = merge({
  30372. // The gap at both ends of the axis. For categoryAxis, boolean.
  30373. boundaryGap: true,
  30374. // Set false to faster category collection.
  30375. // Only usefull in the case like: category is
  30376. // ['2012-01-01', '2012-01-02', ...], where the input
  30377. // data has been ensured not duplicate and is large data.
  30378. // null means "auto":
  30379. // if axis.data provided, do not deduplication,
  30380. // else do deduplication.
  30381. deduplication: null,
  30382. // splitArea: {
  30383. // show: false
  30384. // },
  30385. splitLine: {
  30386. show: false
  30387. },
  30388. axisTick: {
  30389. // If tick is align with label when boundaryGap is true
  30390. alignWithLabel: false,
  30391. interval: 'auto'
  30392. },
  30393. axisLabel: {
  30394. interval: 'auto'
  30395. }
  30396. }, defaultOption);
  30397. axisDefault.valueAxis = merge({
  30398. // The gap at both ends of the axis. For value axis, [GAP, GAP], where
  30399. // `GAP` can be an absolute pixel number (like `35`), or percent (like `'30%'`)
  30400. boundaryGap: [0, 0],
  30401. // TODO
  30402. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  30403. // Min value of the axis. can be:
  30404. // + a number
  30405. // + 'dataMin': use the min value in data.
  30406. // + null/undefined: auto decide min value (consider pretty look and boundaryGap).
  30407. // min: null,
  30408. // Max value of the axis. can be:
  30409. // + a number
  30410. // + 'dataMax': use the max value in data.
  30411. // + null/undefined: auto decide max value (consider pretty look and boundaryGap).
  30412. // max: null,
  30413. // Readonly prop, specifies start value of the range when using data zoom.
  30414. // rangeStart: null
  30415. // Readonly prop, specifies end value of the range when using data zoom.
  30416. // rangeEnd: null
  30417. // Optional value can be:
  30418. // + `false`: always include value 0.
  30419. // + `true`: the extent do not consider value 0.
  30420. // scale: false,
  30421. // AxisTick and axisLabel and splitLine are caculated based on splitNumber.
  30422. splitNumber: 5,
  30423. // Interval specifies the span of the ticks is mandatorily.
  30424. // interval: null
  30425. // Specify min interval when auto calculate tick interval.
  30426. // minInterval: null
  30427. // Specify max interval when auto calculate tick interval.
  30428. // maxInterval: null
  30429. minorTick: {
  30430. // Minor tick, not available for cateogry axis.
  30431. show: false,
  30432. // Split number of minor ticks. The value should be in range of (0, 100)
  30433. splitNumber: 5,
  30434. // Lenght of minor tick
  30435. length: 3,
  30436. // Same inside with axisTick
  30437. // Line style
  30438. lineStyle: {// Default to be same with axisTick
  30439. }
  30440. },
  30441. minorSplitLine: {
  30442. show: false,
  30443. lineStyle: {
  30444. color: '#eee',
  30445. width: 1
  30446. }
  30447. }
  30448. }, defaultOption);
  30449. axisDefault.timeAxis = defaults({
  30450. scale: true,
  30451. min: 'dataMin',
  30452. max: 'dataMax'
  30453. }, axisDefault.valueAxis);
  30454. axisDefault.logAxis = defaults({
  30455. scale: true,
  30456. logBase: 10
  30457. }, axisDefault.valueAxis);
  30458. /*
  30459. * Licensed to the Apache Software Foundation (ASF) under one
  30460. * or more contributor license agreements. See the NOTICE file
  30461. * distributed with this work for additional information
  30462. * regarding copyright ownership. The ASF licenses this file
  30463. * to you under the Apache License, Version 2.0 (the
  30464. * "License"); you may not use this file except in compliance
  30465. * with the License. You may obtain a copy of the License at
  30466. *
  30467. * http://www.apache.org/licenses/LICENSE-2.0
  30468. *
  30469. * Unless required by applicable law or agreed to in writing,
  30470. * software distributed under the License is distributed on an
  30471. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30472. * KIND, either express or implied. See the License for the
  30473. * specific language governing permissions and limitations
  30474. * under the License.
  30475. */
  30476. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  30477. /**
  30478. * Generate sub axis model class
  30479. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  30480. * @param {module:echarts/model/Component} BaseAxisModelClass
  30481. * @param {Function} axisTypeDefaulter
  30482. * @param {Object} [extraDefaultOption]
  30483. */
  30484. var axisModelCreator = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  30485. each$1(AXIS_TYPES, function (axisType) {
  30486. BaseAxisModelClass.extend({
  30487. /**
  30488. * @readOnly
  30489. */
  30490. type: axisName + 'Axis.' + axisType,
  30491. mergeDefaultAndTheme: function (option, ecModel) {
  30492. var layoutMode = this.layoutMode;
  30493. var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
  30494. var themeModel = ecModel.getTheme();
  30495. merge(option, themeModel.get(axisType + 'Axis'));
  30496. merge(option, this.getDefaultOption());
  30497. option.type = axisTypeDefaulter(axisName, option);
  30498. if (layoutMode) {
  30499. mergeLayoutParam(option, inputPositionParams, layoutMode);
  30500. }
  30501. },
  30502. /**
  30503. * @override
  30504. */
  30505. optionUpdated: function () {
  30506. var thisOption = this.option;
  30507. if (thisOption.type === 'category') {
  30508. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  30509. }
  30510. },
  30511. /**
  30512. * Should not be called before all of 'getInitailData' finished.
  30513. * Because categories are collected during initializing data.
  30514. */
  30515. getCategories: function (rawData) {
  30516. var option = this.option; // FIXME
  30517. // warning if called before all of 'getInitailData' finished.
  30518. if (option.type === 'category') {
  30519. if (rawData) {
  30520. return option.data;
  30521. }
  30522. return this.__ordinalMeta.categories;
  30523. }
  30524. },
  30525. getOrdinalMeta: function () {
  30526. return this.__ordinalMeta;
  30527. },
  30528. defaultOption: mergeAll([{}, axisDefault[axisType + 'Axis'], extraDefaultOption], true)
  30529. });
  30530. });
  30531. ComponentModel.registerSubTypeDefaulter(axisName + 'Axis', curry(axisTypeDefaulter, axisName));
  30532. };
  30533. /*
  30534. * Licensed to the Apache Software Foundation (ASF) under one
  30535. * or more contributor license agreements. See the NOTICE file
  30536. * distributed with this work for additional information
  30537. * regarding copyright ownership. The ASF licenses this file
  30538. * to you under the Apache License, Version 2.0 (the
  30539. * "License"); you may not use this file except in compliance
  30540. * with the License. You may obtain a copy of the License at
  30541. *
  30542. * http://www.apache.org/licenses/LICENSE-2.0
  30543. *
  30544. * Unless required by applicable law or agreed to in writing,
  30545. * software distributed under the License is distributed on an
  30546. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30547. * KIND, either express or implied. See the License for the
  30548. * specific language governing permissions and limitations
  30549. * under the License.
  30550. */
  30551. var AxisModel = ComponentModel.extend({
  30552. type: 'cartesian2dAxis',
  30553. /**
  30554. * @type {module:echarts/coord/cartesian/Axis2D}
  30555. */
  30556. axis: null,
  30557. /**
  30558. * @override
  30559. */
  30560. init: function () {
  30561. AxisModel.superApply(this, 'init', arguments);
  30562. this.resetRange();
  30563. },
  30564. /**
  30565. * @override
  30566. */
  30567. mergeOption: function () {
  30568. AxisModel.superApply(this, 'mergeOption', arguments);
  30569. this.resetRange();
  30570. },
  30571. /**
  30572. * @override
  30573. */
  30574. restoreData: function () {
  30575. AxisModel.superApply(this, 'restoreData', arguments);
  30576. this.resetRange();
  30577. },
  30578. /**
  30579. * @override
  30580. * @return {module:echarts/model/Component}
  30581. */
  30582. getCoordSysModel: function () {
  30583. return this.ecModel.queryComponents({
  30584. mainType: 'grid',
  30585. index: this.option.gridIndex,
  30586. id: this.option.gridId
  30587. })[0];
  30588. }
  30589. });
  30590. function getAxisType(axisDim, option) {
  30591. // Default axis with data is category axis
  30592. return option.type || (option.data ? 'category' : 'value');
  30593. }
  30594. merge(AxisModel.prototype, axisModelCommonMixin);
  30595. var extraOption = {
  30596. // gridIndex: 0,
  30597. // gridId: '',
  30598. // Offset is for multiple axis on the same position
  30599. offset: 0
  30600. };
  30601. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  30602. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  30603. /*
  30604. * Licensed to the Apache Software Foundation (ASF) under one
  30605. * or more contributor license agreements. See the NOTICE file
  30606. * distributed with this work for additional information
  30607. * regarding copyright ownership. The ASF licenses this file
  30608. * to you under the Apache License, Version 2.0 (the
  30609. * "License"); you may not use this file except in compliance
  30610. * with the License. You may obtain a copy of the License at
  30611. *
  30612. * http://www.apache.org/licenses/LICENSE-2.0
  30613. *
  30614. * Unless required by applicable law or agreed to in writing,
  30615. * software distributed under the License is distributed on an
  30616. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30617. * KIND, either express or implied. See the License for the
  30618. * specific language governing permissions and limitations
  30619. * under the License.
  30620. */
  30621. // Grid 是在有直角坐标系的时候必须要存在的
  30622. // 所以这里也要被 Cartesian2D 依赖
  30623. ComponentModel.extend({
  30624. type: 'grid',
  30625. dependencies: ['xAxis', 'yAxis'],
  30626. layoutMode: 'box',
  30627. /**
  30628. * @type {module:echarts/coord/cartesian/Grid}
  30629. */
  30630. coordinateSystem: null,
  30631. defaultOption: {
  30632. show: false,
  30633. zlevel: 0,
  30634. z: 0,
  30635. left: '10%',
  30636. top: 60,
  30637. right: '10%',
  30638. bottom: 60,
  30639. // If grid size contain label
  30640. containLabel: false,
  30641. // width: {totalWidth} - left - right,
  30642. // height: {totalHeight} - top - bottom,
  30643. backgroundColor: 'rgba(0,0,0,0)',
  30644. borderWidth: 1,
  30645. borderColor: '#ccc'
  30646. }
  30647. });
  30648. /*
  30649. * Licensed to the Apache Software Foundation (ASF) under one
  30650. * or more contributor license agreements. See the NOTICE file
  30651. * distributed with this work for additional information
  30652. * regarding copyright ownership. The ASF licenses this file
  30653. * to you under the Apache License, Version 2.0 (the
  30654. * "License"); you may not use this file except in compliance
  30655. * with the License. You may obtain a copy of the License at
  30656. *
  30657. * http://www.apache.org/licenses/LICENSE-2.0
  30658. *
  30659. * Unless required by applicable law or agreed to in writing,
  30660. * software distributed under the License is distributed on an
  30661. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30662. * KIND, either express or implied. See the License for the
  30663. * specific language governing permissions and limitations
  30664. * under the License.
  30665. */
  30666. /**
  30667. * Grid is a region which contains at most 4 cartesian systems
  30668. *
  30669. * TODO Default cartesian
  30670. */
  30671. /**
  30672. * Check if the axis is used in the specified grid
  30673. * @inner
  30674. */
  30675. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  30676. return axisModel.getCoordSysModel() === gridModel;
  30677. }
  30678. function Grid(gridModel, ecModel, api) {
  30679. /**
  30680. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  30681. * @private
  30682. */
  30683. this._coordsMap = {};
  30684. /**
  30685. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  30686. * @private
  30687. */
  30688. this._coordsList = [];
  30689. /**
  30690. * @type {Object.<string, Array.<module:echarts/coord/cartesian/Axis2D>>}
  30691. * @private
  30692. */
  30693. this._axesMap = {};
  30694. /**
  30695. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  30696. * @private
  30697. */
  30698. this._axesList = [];
  30699. this._initCartesian(gridModel, ecModel, api);
  30700. this.model = gridModel;
  30701. }
  30702. var gridProto = Grid.prototype;
  30703. gridProto.type = 'grid';
  30704. gridProto.axisPointerEnabled = true;
  30705. gridProto.getRect = function () {
  30706. return this._rect;
  30707. };
  30708. gridProto.update = function (ecModel, api) {
  30709. var axesMap = this._axesMap;
  30710. this._updateScale(ecModel, this.model);
  30711. each$1(axesMap.x, function (xAxis) {
  30712. niceScaleExtent(xAxis.scale, xAxis.model);
  30713. });
  30714. each$1(axesMap.y, function (yAxis) {
  30715. niceScaleExtent(yAxis.scale, yAxis.model);
  30716. }); // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  30717. var onZeroRecords = {};
  30718. each$1(axesMap.x, function (xAxis) {
  30719. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  30720. });
  30721. each$1(axesMap.y, function (yAxis) {
  30722. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  30723. }); // Resize again if containLabel is enabled
  30724. // FIXME It may cause getting wrong grid size in data processing stage
  30725. this.resize(this.model, api);
  30726. };
  30727. function fixAxisOnZero(axesMap, otherAxisDim, axis, onZeroRecords) {
  30728. axis.getAxesOnZeroOf = function () {
  30729. // TODO: onZero of multiple axes.
  30730. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  30731. }; // onZero can not be enabled in these two situations:
  30732. // 1. When any other axis is a category axis.
  30733. // 2. When no axis is cross 0 point.
  30734. var otherAxes = axesMap[otherAxisDim];
  30735. var otherAxisOnZeroOf;
  30736. var axisModel = axis.model;
  30737. var onZero = axisModel.get('axisLine.onZero');
  30738. var onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex');
  30739. if (!onZero) {
  30740. return;
  30741. } // If target axis is specified.
  30742. if (onZeroAxisIndex != null) {
  30743. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  30744. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  30745. }
  30746. } else {
  30747. // Find the first available other axis.
  30748. for (var idx in otherAxes) {
  30749. if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx]) // Consider that two Y axes on one value axis,
  30750. // if both onZero, the two Y axes overlap.
  30751. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]) {
  30752. otherAxisOnZeroOf = otherAxes[idx];
  30753. break;
  30754. }
  30755. }
  30756. }
  30757. if (otherAxisOnZeroOf) {
  30758. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  30759. }
  30760. function getOnZeroRecordKey(axis) {
  30761. return axis.dim + '_' + axis.index;
  30762. }
  30763. }
  30764. function canOnZeroToAxis(axis) {
  30765. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  30766. }
  30767. /**
  30768. * Resize the grid
  30769. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  30770. * @param {module:echarts/ExtensionAPI} api
  30771. */
  30772. gridProto.resize = function (gridModel, api, ignoreContainLabel) {
  30773. var gridRect = getLayoutRect(gridModel.getBoxLayoutParams(), {
  30774. width: api.getWidth(),
  30775. height: api.getHeight()
  30776. });
  30777. this._rect = gridRect;
  30778. var axesList = this._axesList;
  30779. adjustAxes(); // Minus label size
  30780. if (!ignoreContainLabel && gridModel.get('containLabel')) {
  30781. each$1(axesList, function (axis) {
  30782. if (!axis.model.get('axisLabel.inside')) {
  30783. var labelUnionRect = estimateLabelUnionRect(axis);
  30784. if (labelUnionRect) {
  30785. var dim = axis.isHorizontal() ? 'height' : 'width';
  30786. var margin = axis.model.get('axisLabel.margin');
  30787. gridRect[dim] -= labelUnionRect[dim] + margin;
  30788. if (axis.position === 'top') {
  30789. gridRect.y += labelUnionRect.height + margin;
  30790. } else if (axis.position === 'left') {
  30791. gridRect.x += labelUnionRect.width + margin;
  30792. }
  30793. }
  30794. }
  30795. });
  30796. adjustAxes();
  30797. }
  30798. function adjustAxes() {
  30799. each$1(axesList, function (axis) {
  30800. var isHorizontal = axis.isHorizontal();
  30801. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  30802. var idx = axis.inverse ? 1 : 0;
  30803. axis.setExtent(extent[idx], extent[1 - idx]);
  30804. updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
  30805. });
  30806. }
  30807. };
  30808. /**
  30809. * @param {string} axisType
  30810. * @param {number} [axisIndex]
  30811. */
  30812. gridProto.getAxis = function (axisType, axisIndex) {
  30813. var axesMapOnDim = this._axesMap[axisType];
  30814. if (axesMapOnDim != null) {
  30815. if (axisIndex == null) {
  30816. // Find first axis
  30817. for (var name in axesMapOnDim) {
  30818. if (axesMapOnDim.hasOwnProperty(name)) {
  30819. return axesMapOnDim[name];
  30820. }
  30821. }
  30822. }
  30823. return axesMapOnDim[axisIndex];
  30824. }
  30825. };
  30826. /**
  30827. * @return {Array.<module:echarts/coord/Axis>}
  30828. */
  30829. gridProto.getAxes = function () {
  30830. return this._axesList.slice();
  30831. };
  30832. /**
  30833. * Usage:
  30834. * grid.getCartesian(xAxisIndex, yAxisIndex);
  30835. * grid.getCartesian(xAxisIndex);
  30836. * grid.getCartesian(null, yAxisIndex);
  30837. * grid.getCartesian({xAxisIndex: ..., yAxisIndex: ...});
  30838. *
  30839. * @param {number|Object} [xAxisIndex]
  30840. * @param {number} [yAxisIndex]
  30841. */
  30842. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  30843. if (xAxisIndex != null && yAxisIndex != null) {
  30844. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  30845. return this._coordsMap[key];
  30846. }
  30847. if (isObject$1(xAxisIndex)) {
  30848. yAxisIndex = xAxisIndex.yAxisIndex;
  30849. xAxisIndex = xAxisIndex.xAxisIndex;
  30850. } // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  30851. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  30852. if (coordList[i].getAxis('x').index === xAxisIndex || coordList[i].getAxis('y').index === yAxisIndex) {
  30853. return coordList[i];
  30854. }
  30855. }
  30856. };
  30857. gridProto.getCartesians = function () {
  30858. return this._coordsList.slice();
  30859. };
  30860. /**
  30861. * @implements
  30862. * see {module:echarts/CoodinateSystem}
  30863. */
  30864. gridProto.convertToPixel = function (ecModel, finder, value) {
  30865. var target = this._findConvertTarget(ecModel, finder);
  30866. return target.cartesian ? target.cartesian.dataToPoint(value) : target.axis ? target.axis.toGlobalCoord(target.axis.dataToCoord(value)) : null;
  30867. };
  30868. /**
  30869. * @implements
  30870. * see {module:echarts/CoodinateSystem}
  30871. */
  30872. gridProto.convertFromPixel = function (ecModel, finder, value) {
  30873. var target = this._findConvertTarget(ecModel, finder);
  30874. return target.cartesian ? target.cartesian.pointToData(value) : target.axis ? target.axis.coordToData(target.axis.toLocalCoord(value)) : null;
  30875. };
  30876. /**
  30877. * @inner
  30878. */
  30879. gridProto._findConvertTarget = function (ecModel, finder) {
  30880. var seriesModel = finder.seriesModel;
  30881. var xAxisModel = finder.xAxisModel || seriesModel && seriesModel.getReferringComponents('xAxis')[0];
  30882. var yAxisModel = finder.yAxisModel || seriesModel && seriesModel.getReferringComponents('yAxis')[0];
  30883. var gridModel = finder.gridModel;
  30884. var coordsList = this._coordsList;
  30885. var cartesian;
  30886. var axis;
  30887. if (seriesModel) {
  30888. cartesian = seriesModel.coordinateSystem;
  30889. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  30890. } else if (xAxisModel && yAxisModel) {
  30891. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  30892. } else if (xAxisModel) {
  30893. axis = this.getAxis('x', xAxisModel.componentIndex);
  30894. } else if (yAxisModel) {
  30895. axis = this.getAxis('y', yAxisModel.componentIndex);
  30896. } // Lowest priority.
  30897. else if (gridModel) {
  30898. var grid = gridModel.coordinateSystem;
  30899. if (grid === this) {
  30900. cartesian = this._coordsList[0];
  30901. }
  30902. }
  30903. return {
  30904. cartesian: cartesian,
  30905. axis: axis
  30906. };
  30907. };
  30908. /**
  30909. * @implements
  30910. * see {module:echarts/CoodinateSystem}
  30911. */
  30912. gridProto.containPoint = function (point) {
  30913. var coord = this._coordsList[0];
  30914. if (coord) {
  30915. return coord.containPoint(point);
  30916. }
  30917. };
  30918. /**
  30919. * Initialize cartesian coordinate systems
  30920. * @private
  30921. */
  30922. gridProto._initCartesian = function (gridModel, ecModel, api) {
  30923. var axisPositionUsed = {
  30924. left: false,
  30925. right: false,
  30926. top: false,
  30927. bottom: false
  30928. };
  30929. var axesMap = {
  30930. x: {},
  30931. y: {}
  30932. };
  30933. var axesCount = {
  30934. x: 0,
  30935. y: 0
  30936. }; /// Create axis
  30937. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  30938. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  30939. if (!axesCount.x || !axesCount.y) {
  30940. // Roll back when there no either x or y axis
  30941. this._axesMap = {};
  30942. this._axesList = [];
  30943. return;
  30944. }
  30945. this._axesMap = axesMap; /// Create cartesian2d
  30946. each$1(axesMap.x, function (xAxis, xAxisIndex) {
  30947. each$1(axesMap.y, function (yAxis, yAxisIndex) {
  30948. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  30949. var cartesian = new Cartesian2D(key);
  30950. cartesian.grid = this;
  30951. cartesian.model = gridModel;
  30952. this._coordsMap[key] = cartesian;
  30953. this._coordsList.push(cartesian);
  30954. cartesian.addAxis(xAxis);
  30955. cartesian.addAxis(yAxis);
  30956. }, this);
  30957. }, this);
  30958. function createAxisCreator(axisType) {
  30959. return function (axisModel, idx) {
  30960. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  30961. return;
  30962. }
  30963. var axisPosition = axisModel.get('position');
  30964. if (axisType === 'x') {
  30965. // Fix position
  30966. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  30967. // Default bottom of X
  30968. axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
  30969. }
  30970. } else {
  30971. // Fix position
  30972. if (axisPosition !== 'left' && axisPosition !== 'right') {
  30973. // Default left of Y
  30974. axisPosition = axisPositionUsed.left ? 'right' : 'left';
  30975. }
  30976. }
  30977. axisPositionUsed[axisPosition] = true;
  30978. var axis = new Axis2D(axisType, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisPosition);
  30979. var isCategory = axis.type === 'category';
  30980. axis.onBand = isCategory && axisModel.get('boundaryGap');
  30981. axis.inverse = axisModel.get('inverse'); // Inject axis into axisModel
  30982. axisModel.axis = axis; // Inject axisModel into axis
  30983. axis.model = axisModel; // Inject grid info axis
  30984. axis.grid = this; // Index of axis, can be used as key
  30985. axis.index = idx;
  30986. this._axesList.push(axis);
  30987. axesMap[axisType][idx] = axis;
  30988. axesCount[axisType]++;
  30989. };
  30990. }
  30991. };
  30992. /**
  30993. * Update cartesian properties from series
  30994. * @param {module:echarts/model/Option} option
  30995. * @private
  30996. */
  30997. gridProto._updateScale = function (ecModel, gridModel) {
  30998. // Reset scale
  30999. each$1(this._axesList, function (axis) {
  31000. axis.scale.setExtent(Infinity, -Infinity);
  31001. });
  31002. ecModel.eachSeries(function (seriesModel) {
  31003. if (isCartesian2D(seriesModel)) {
  31004. var axesModels = findAxesModels(seriesModel, ecModel);
  31005. var xAxisModel = axesModels[0];
  31006. var yAxisModel = axesModels[1];
  31007. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel) || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)) {
  31008. return;
  31009. }
  31010. var cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  31011. var data = seriesModel.getData();
  31012. var xAxis = cartesian.getAxis('x');
  31013. var yAxis = cartesian.getAxis('y');
  31014. if (data.type === 'list') {
  31015. unionExtent(data, xAxis, seriesModel);
  31016. unionExtent(data, yAxis, seriesModel);
  31017. }
  31018. }
  31019. }, this);
  31020. function unionExtent(data, axis, seriesModel) {
  31021. each$1(data.mapDimension(axis.dim, true), function (dim) {
  31022. axis.scale.unionExtentFromData( // For example, the extent of the orginal dimension
  31023. // is [0.1, 0.5], the extent of the `stackResultDimension`
  31024. // is [7, 9], the final extent should not include [0.1, 0.5].
  31025. data, getStackedDimension(data, dim));
  31026. });
  31027. }
  31028. };
  31029. /**
  31030. * @param {string} [dim] 'x' or 'y' or 'auto' or null/undefined
  31031. * @return {Object} {baseAxes: [], otherAxes: []}
  31032. */
  31033. gridProto.getTooltipAxes = function (dim) {
  31034. var baseAxes = [];
  31035. var otherAxes = [];
  31036. each$1(this.getCartesians(), function (cartesian) {
  31037. var baseAxis = dim != null && dim !== 'auto' ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  31038. var otherAxis = cartesian.getOtherAxis(baseAxis);
  31039. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  31040. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  31041. });
  31042. return {
  31043. baseAxes: baseAxes,
  31044. otherAxes: otherAxes
  31045. };
  31046. };
  31047. /**
  31048. * @inner
  31049. */
  31050. function updateAxisTransform(axis, coordBase) {
  31051. var axisExtent = axis.getExtent();
  31052. var axisExtentSum = axisExtent[0] + axisExtent[1]; // Fast transform
  31053. axis.toGlobalCoord = axis.dim === 'x' ? function (coord) {
  31054. return coord + coordBase;
  31055. } : function (coord) {
  31056. return axisExtentSum - coord + coordBase;
  31057. };
  31058. axis.toLocalCoord = axis.dim === 'x' ? function (coord) {
  31059. return coord - coordBase;
  31060. } : function (coord) {
  31061. return axisExtentSum - coord + coordBase;
  31062. };
  31063. }
  31064. var axesTypes = ['xAxis', 'yAxis'];
  31065. /**
  31066. * @inner
  31067. */
  31068. function findAxesModels(seriesModel, ecModel) {
  31069. return map(axesTypes, function (axisType) {
  31070. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  31071. return axisModel;
  31072. });
  31073. }
  31074. /**
  31075. * @inner
  31076. */
  31077. function isCartesian2D(seriesModel) {
  31078. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  31079. }
  31080. Grid.create = function (ecModel, api) {
  31081. var grids = [];
  31082. ecModel.eachComponent('grid', function (gridModel, idx) {
  31083. var grid = new Grid(gridModel, ecModel, api);
  31084. grid.name = 'grid_' + idx; // dataSampling requires axis extent, so resize
  31085. // should be performed in create stage.
  31086. grid.resize(gridModel, api, true);
  31087. gridModel.coordinateSystem = grid;
  31088. grids.push(grid);
  31089. }); // Inject the coordinateSystems into seriesModel
  31090. ecModel.eachSeries(function (seriesModel) {
  31091. if (!isCartesian2D(seriesModel)) {
  31092. return;
  31093. }
  31094. var axesModels = findAxesModels(seriesModel, ecModel);
  31095. var xAxisModel = axesModels[0];
  31096. var yAxisModel = axesModels[1];
  31097. var gridModel = xAxisModel.getCoordSysModel();
  31098. var grid = gridModel.coordinateSystem;
  31099. seriesModel.coordinateSystem = grid.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  31100. });
  31101. return grids;
  31102. }; // For deciding which dimensions to use when creating list data
  31103. Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
  31104. CoordinateSystemManager.register('cartesian2d', Grid);
  31105. /*
  31106. * Licensed to the Apache Software Foundation (ASF) under one
  31107. * or more contributor license agreements. See the NOTICE file
  31108. * distributed with this work for additional information
  31109. * regarding copyright ownership. The ASF licenses this file
  31110. * to you under the Apache License, Version 2.0 (the
  31111. * "License"); you may not use this file except in compliance
  31112. * with the License. You may obtain a copy of the License at
  31113. *
  31114. * http://www.apache.org/licenses/LICENSE-2.0
  31115. *
  31116. * Unless required by applicable law or agreed to in writing,
  31117. * software distributed under the License is distributed on an
  31118. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31119. * KIND, either express or implied. See the License for the
  31120. * specific language governing permissions and limitations
  31121. * under the License.
  31122. */
  31123. var BaseBarSeries = SeriesModel.extend({
  31124. type: 'series.__base_bar__',
  31125. getInitialData: function (option, ecModel) {
  31126. return createListFromArray(this.getSource(), this, {
  31127. useEncodeDefaulter: true
  31128. });
  31129. },
  31130. getMarkerPosition: function (value) {
  31131. var coordSys = this.coordinateSystem;
  31132. if (coordSys) {
  31133. // PENDING if clamp ?
  31134. var pt = coordSys.dataToPoint(coordSys.clampData(value));
  31135. var data = this.getData();
  31136. var offset = data.getLayout('offset');
  31137. var size = data.getLayout('size');
  31138. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  31139. pt[offsetIndex] += offset + size / 2;
  31140. return pt;
  31141. }
  31142. return [NaN, NaN];
  31143. },
  31144. defaultOption: {
  31145. zlevel: 0,
  31146. // 一级层叠
  31147. z: 2,
  31148. // 二级层叠
  31149. coordinateSystem: 'cartesian2d',
  31150. legendHoverLink: true,
  31151. // stack: null
  31152. // Cartesian coordinate system
  31153. // xAxisIndex: 0,
  31154. // yAxisIndex: 0,
  31155. // 最小高度改为0
  31156. barMinHeight: 0,
  31157. // 最小角度为0,仅对极坐标系下的柱状图有效
  31158. barMinAngle: 0,
  31159. // cursor: null,
  31160. large: false,
  31161. largeThreshold: 400,
  31162. progressive: 3e3,
  31163. progressiveChunkMode: 'mod',
  31164. // barMaxWidth: null,
  31165. // In cartesian, the default value is 1. Otherwise null.
  31166. // barMinWidth: null,
  31167. // 默认自适应
  31168. // barWidth: null,
  31169. // 柱间距离,默认为柱形宽度的30%,可设固定值
  31170. // barGap: '30%',
  31171. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  31172. // barCategoryGap: '20%',
  31173. // label: {
  31174. // show: false
  31175. // },
  31176. itemStyle: {},
  31177. emphasis: {}
  31178. }
  31179. });
  31180. /*
  31181. * Licensed to the Apache Software Foundation (ASF) under one
  31182. * or more contributor license agreements. See the NOTICE file
  31183. * distributed with this work for additional information
  31184. * regarding copyright ownership. The ASF licenses this file
  31185. * to you under the Apache License, Version 2.0 (the
  31186. * "License"); you may not use this file except in compliance
  31187. * with the License. You may obtain a copy of the License at
  31188. *
  31189. * http://www.apache.org/licenses/LICENSE-2.0
  31190. *
  31191. * Unless required by applicable law or agreed to in writing,
  31192. * software distributed under the License is distributed on an
  31193. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31194. * KIND, either express or implied. See the License for the
  31195. * specific language governing permissions and limitations
  31196. * under the License.
  31197. */
  31198. BaseBarSeries.extend({
  31199. type: 'series.bar',
  31200. dependencies: ['grid', 'polar'],
  31201. brushSelector: 'rect',
  31202. /**
  31203. * @override
  31204. */
  31205. getProgressive: function () {
  31206. // Do not support progressive in normal mode.
  31207. return this.get('large') ? this.get('progressive') : false;
  31208. },
  31209. /**
  31210. * @override
  31211. */
  31212. getProgressiveThreshold: function () {
  31213. // Do not support progressive in normal mode.
  31214. var progressiveThreshold = this.get('progressiveThreshold');
  31215. var largeThreshold = this.get('largeThreshold');
  31216. if (largeThreshold > progressiveThreshold) {
  31217. progressiveThreshold = largeThreshold;
  31218. }
  31219. return progressiveThreshold;
  31220. },
  31221. defaultOption: {
  31222. // If clipped
  31223. // Only available on cartesian2d
  31224. clip: true,
  31225. // If use caps on two sides of bars
  31226. // Only available on tangential polar bar
  31227. roundCap: false,
  31228. showBackground: false,
  31229. backgroundStyle: {
  31230. color: 'rgba(180, 180, 180, 0.2)',
  31231. borderColor: null,
  31232. borderWidth: 0,
  31233. borderType: 'solid',
  31234. borderRadius: 0,
  31235. shadowBlur: 0,
  31236. shadowColor: null,
  31237. shadowOffsetX: 0,
  31238. shadowOffsetY: 0,
  31239. opacity: 1
  31240. }
  31241. }
  31242. });
  31243. /*
  31244. * Licensed to the Apache Software Foundation (ASF) under one
  31245. * or more contributor license agreements. See the NOTICE file
  31246. * distributed with this work for additional information
  31247. * regarding copyright ownership. The ASF licenses this file
  31248. * to you under the Apache License, Version 2.0 (the
  31249. * "License"); you may not use this file except in compliance
  31250. * with the License. You may obtain a copy of the License at
  31251. *
  31252. * http://www.apache.org/licenses/LICENSE-2.0
  31253. *
  31254. * Unless required by applicable law or agreed to in writing,
  31255. * software distributed under the License is distributed on an
  31256. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31257. * KIND, either express or implied. See the License for the
  31258. * specific language governing permissions and limitations
  31259. * under the License.
  31260. */
  31261. /**
  31262. * @param {module:echarts/data/List} data
  31263. * @param {number} dataIndex
  31264. * @return {string} label string. Not null/undefined
  31265. */
  31266. function getDefaultLabel(data, dataIndex) {
  31267. var labelDims = data.mapDimension('defaultedLabel', true);
  31268. var len = labelDims.length; // Simple optimization (in lots of cases, label dims length is 1)
  31269. if (len === 1) {
  31270. return retrieveRawValue(data, dataIndex, labelDims[0]);
  31271. } else if (len) {
  31272. var vals = [];
  31273. for (var i = 0; i < labelDims.length; i++) {
  31274. var val = retrieveRawValue(data, dataIndex, labelDims[i]);
  31275. vals.push(val);
  31276. }
  31277. return vals.join(' ');
  31278. }
  31279. }
  31280. /*
  31281. * Licensed to the Apache Software Foundation (ASF) under one
  31282. * or more contributor license agreements. See the NOTICE file
  31283. * distributed with this work for additional information
  31284. * regarding copyright ownership. The ASF licenses this file
  31285. * to you under the Apache License, Version 2.0 (the
  31286. * "License"); you may not use this file except in compliance
  31287. * with the License. You may obtain a copy of the License at
  31288. *
  31289. * http://www.apache.org/licenses/LICENSE-2.0
  31290. *
  31291. * Unless required by applicable law or agreed to in writing,
  31292. * software distributed under the License is distributed on an
  31293. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31294. * KIND, either express or implied. See the License for the
  31295. * specific language governing permissions and limitations
  31296. * under the License.
  31297. */
  31298. function setLabel(normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside) {
  31299. var labelModel = itemModel.getModel('label');
  31300. var hoverLabelModel = itemModel.getModel('emphasis.label');
  31301. setLabelStyle(normalStyle, hoverStyle, labelModel, hoverLabelModel, {
  31302. labelFetcher: seriesModel,
  31303. labelDataIndex: dataIndex,
  31304. defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
  31305. isRectText: true,
  31306. autoColor: color
  31307. });
  31308. fixPosition(normalStyle);
  31309. fixPosition(hoverStyle);
  31310. }
  31311. function fixPosition(style, labelPositionOutside) {
  31312. if (style.textPosition === 'outside') {
  31313. style.textPosition = labelPositionOutside;
  31314. }
  31315. }
  31316. /*
  31317. * Licensed to the Apache Software Foundation (ASF) under one
  31318. * or more contributor license agreements. See the NOTICE file
  31319. * distributed with this work for additional information
  31320. * regarding copyright ownership. The ASF licenses this file
  31321. * to you under the Apache License, Version 2.0 (the
  31322. * "License"); you may not use this file except in compliance
  31323. * with the License. You may obtain a copy of the License at
  31324. *
  31325. * http://www.apache.org/licenses/LICENSE-2.0
  31326. *
  31327. * Unless required by applicable law or agreed to in writing,
  31328. * software distributed under the License is distributed on an
  31329. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31330. * KIND, either express or implied. See the License for the
  31331. * specific language governing permissions and limitations
  31332. * under the License.
  31333. */
  31334. var getBarItemStyle = makeStyleMapper([['fill', 'color'], ['stroke', 'borderColor'], ['lineWidth', 'borderWidth'], // Compatitable with 2
  31335. ['stroke', 'barBorderColor'], ['lineWidth', 'barBorderWidth'], ['opacity'], ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], ['shadowColor']]);
  31336. var barItemStyle = {
  31337. getBarItemStyle: function (excludes) {
  31338. var style = getBarItemStyle(this, excludes);
  31339. if (this.getBorderLineDash) {
  31340. var lineDash = this.getBorderLineDash();
  31341. lineDash && (style.lineDash = lineDash);
  31342. }
  31343. return style;
  31344. }
  31345. };
  31346. /*
  31347. * Licensed to the Apache Software Foundation (ASF) under one
  31348. * or more contributor license agreements. See the NOTICE file
  31349. * distributed with this work for additional information
  31350. * regarding copyright ownership. The ASF licenses this file
  31351. * to you under the Apache License, Version 2.0 (the
  31352. * "License"); you may not use this file except in compliance
  31353. * with the License. You may obtain a copy of the License at
  31354. *
  31355. * http://www.apache.org/licenses/LICENSE-2.0
  31356. *
  31357. * Unless required by applicable law or agreed to in writing,
  31358. * software distributed under the License is distributed on an
  31359. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31360. * KIND, either express or implied. See the License for the
  31361. * specific language governing permissions and limitations
  31362. * under the License.
  31363. */
  31364. function createGridClipPath(cartesian, hasAnimation, seriesModel) {
  31365. var rect = cartesian.getArea();
  31366. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  31367. var x = rect.x;
  31368. var y = rect.y;
  31369. var width = rect.width;
  31370. var height = rect.height;
  31371. var lineWidth = seriesModel.get('lineStyle.width') || 2; // Expand the clip path a bit to avoid the border is clipped and looks thinner
  31372. x -= lineWidth / 2;
  31373. y -= lineWidth / 2;
  31374. width += lineWidth;
  31375. height += lineWidth; // fix: https://github.com/apache/incubator-echarts/issues/11369
  31376. x = Math.floor(x);
  31377. width = Math.round(width);
  31378. var clipPath = new Rect({
  31379. shape: {
  31380. x: x,
  31381. y: y,
  31382. width: width,
  31383. height: height
  31384. }
  31385. });
  31386. if (hasAnimation) {
  31387. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  31388. initProps(clipPath, {
  31389. shape: {
  31390. width: width,
  31391. height: height
  31392. }
  31393. }, seriesModel);
  31394. }
  31395. return clipPath;
  31396. }
  31397. function createPolarClipPath(polar, hasAnimation, seriesModel) {
  31398. var sectorArea = polar.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
  31399. var clipPath = new Sector({
  31400. shape: {
  31401. cx: round$1(polar.cx, 1),
  31402. cy: round$1(polar.cy, 1),
  31403. r0: round$1(sectorArea.r0, 1),
  31404. r: round$1(sectorArea.r, 1),
  31405. startAngle: sectorArea.startAngle,
  31406. endAngle: sectorArea.endAngle,
  31407. clockwise: sectorArea.clockwise
  31408. }
  31409. });
  31410. if (hasAnimation) {
  31411. clipPath.shape.endAngle = sectorArea.startAngle;
  31412. initProps(clipPath, {
  31413. shape: {
  31414. endAngle: sectorArea.endAngle
  31415. }
  31416. }, seriesModel);
  31417. }
  31418. return clipPath;
  31419. }
  31420. function createClipPath(coordSys, hasAnimation, seriesModel) {
  31421. if (!coordSys) {
  31422. return null;
  31423. } else if (coordSys.type === 'polar') {
  31424. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  31425. } else if (coordSys.type === 'cartesian2d') {
  31426. return createGridClipPath(coordSys, hasAnimation, seriesModel);
  31427. }
  31428. return null;
  31429. }
  31430. /*
  31431. * Licensed to the Apache Software Foundation (ASF) under one
  31432. * or more contributor license agreements. See the NOTICE file
  31433. * distributed with this work for additional information
  31434. * regarding copyright ownership. The ASF licenses this file
  31435. * to you under the Apache License, Version 2.0 (the
  31436. * "License"); you may not use this file except in compliance
  31437. * with the License. You may obtain a copy of the License at
  31438. *
  31439. * http://www.apache.org/licenses/LICENSE-2.0
  31440. *
  31441. * Unless required by applicable law or agreed to in writing,
  31442. * software distributed under the License is distributed on an
  31443. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31444. * KIND, either express or implied. See the License for the
  31445. * specific language governing permissions and limitations
  31446. * under the License.
  31447. */
  31448. /**
  31449. * Sausage: similar to sector, but have half circle on both sides
  31450. * @public
  31451. */
  31452. var Sausage = extendShape({
  31453. type: 'sausage',
  31454. shape: {
  31455. cx: 0,
  31456. cy: 0,
  31457. r0: 0,
  31458. r: 0,
  31459. startAngle: 0,
  31460. endAngle: Math.PI * 2,
  31461. clockwise: true
  31462. },
  31463. buildPath: function (ctx, shape) {
  31464. var x = shape.cx;
  31465. var y = shape.cy;
  31466. var r0 = Math.max(shape.r0 || 0, 0);
  31467. var r = Math.max(shape.r, 0);
  31468. var dr = (r - r0) * 0.5;
  31469. var rCenter = r0 + dr;
  31470. var startAngle = shape.startAngle;
  31471. var endAngle = shape.endAngle;
  31472. var clockwise = shape.clockwise;
  31473. var unitStartX = Math.cos(startAngle);
  31474. var unitStartY = Math.sin(startAngle);
  31475. var unitEndX = Math.cos(endAngle);
  31476. var unitEndY = Math.sin(endAngle);
  31477. var lessThanCircle = clockwise ? endAngle - startAngle < Math.PI * 2 : startAngle - endAngle < Math.PI * 2;
  31478. if (lessThanCircle) {
  31479. ctx.moveTo(unitStartX * r0 + x, unitStartY * r0 + y);
  31480. ctx.arc(unitStartX * rCenter + x, unitStartY * rCenter + y, dr, -Math.PI + startAngle, startAngle, !clockwise);
  31481. }
  31482. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  31483. ctx.moveTo(unitEndX * r + x, unitEndY * r + y);
  31484. ctx.arc(unitEndX * rCenter + x, unitEndY * rCenter + y, dr, endAngle - Math.PI * 2, endAngle - Math.PI, !clockwise);
  31485. if (r0 !== 0) {
  31486. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  31487. ctx.moveTo(unitStartX * r0 + x, unitEndY * r0 + y);
  31488. }
  31489. ctx.closePath();
  31490. }
  31491. });
  31492. /*
  31493. * Licensed to the Apache Software Foundation (ASF) under one
  31494. * or more contributor license agreements. See the NOTICE file
  31495. * distributed with this work for additional information
  31496. * regarding copyright ownership. The ASF licenses this file
  31497. * to you under the Apache License, Version 2.0 (the
  31498. * "License"); you may not use this file except in compliance
  31499. * with the License. You may obtain a copy of the License at
  31500. *
  31501. * http://www.apache.org/licenses/LICENSE-2.0
  31502. *
  31503. * Unless required by applicable law or agreed to in writing,
  31504. * software distributed under the License is distributed on an
  31505. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31506. * KIND, either express or implied. See the License for the
  31507. * specific language governing permissions and limitations
  31508. * under the License.
  31509. */
  31510. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'barBorderWidth'];
  31511. var _eventPos = [0, 0]; // FIXME
  31512. // Just for compatible with ec2.
  31513. extend(Model.prototype, barItemStyle);
  31514. function getClipArea(coord, data) {
  31515. var coordSysClipArea = coord.getArea && coord.getArea();
  31516. if (coord.type === 'cartesian2d') {
  31517. var baseAxis = coord.getBaseAxis(); // When boundaryGap is false or using time axis. bar may exceed the grid.
  31518. // We should not clip this part.
  31519. // See test/bar2.html
  31520. if (baseAxis.type !== 'category' || !baseAxis.onBand) {
  31521. var expandWidth = data.getLayout('bandWidth');
  31522. if (baseAxis.isHorizontal()) {
  31523. coordSysClipArea.x -= expandWidth;
  31524. coordSysClipArea.width += expandWidth * 2;
  31525. } else {
  31526. coordSysClipArea.y -= expandWidth;
  31527. coordSysClipArea.height += expandWidth * 2;
  31528. }
  31529. }
  31530. }
  31531. return coordSysClipArea;
  31532. }
  31533. extendChartView({
  31534. type: 'bar',
  31535. render: function (seriesModel, ecModel, api) {
  31536. this._updateDrawMode(seriesModel);
  31537. var coordinateSystemType = seriesModel.get('coordinateSystem');
  31538. if (coordinateSystemType === 'cartesian2d' || coordinateSystemType === 'polar') {
  31539. this._isLargeDraw ? this._renderLarge(seriesModel, ecModel, api) : this._renderNormal(seriesModel, ecModel, api);
  31540. } else {}
  31541. return this.group;
  31542. },
  31543. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  31544. this._clear();
  31545. this._updateDrawMode(seriesModel);
  31546. },
  31547. incrementalRender: function (params, seriesModel, ecModel, api) {
  31548. // Do not support progressive in normal mode.
  31549. this._incrementalRenderLarge(params, seriesModel);
  31550. },
  31551. _updateDrawMode: function (seriesModel) {
  31552. var isLargeDraw = seriesModel.pipelineContext.large;
  31553. if (this._isLargeDraw == null || isLargeDraw ^ this._isLargeDraw) {
  31554. this._isLargeDraw = isLargeDraw;
  31555. this._clear();
  31556. }
  31557. },
  31558. _renderNormal: function (seriesModel, ecModel, api) {
  31559. var group = this.group;
  31560. var data = seriesModel.getData();
  31561. var oldData = this._data;
  31562. var coord = seriesModel.coordinateSystem;
  31563. var baseAxis = coord.getBaseAxis();
  31564. var isHorizontalOrRadial;
  31565. if (coord.type === 'cartesian2d') {
  31566. isHorizontalOrRadial = baseAxis.isHorizontal();
  31567. } else if (coord.type === 'polar') {
  31568. isHorizontalOrRadial = baseAxis.dim === 'angle';
  31569. }
  31570. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  31571. var needsClip = seriesModel.get('clip', true);
  31572. var coordSysClipArea = getClipArea(coord, data); // If there is clipPath created in large mode. Remove it.
  31573. group.removeClipPath(); // We don't use clipPath in normal mode because we needs a perfect animation
  31574. // And don't want the label are clipped.
  31575. var roundCap = seriesModel.get('roundCap', true);
  31576. var drawBackground = seriesModel.get('showBackground', true);
  31577. var backgroundModel = seriesModel.getModel('backgroundStyle');
  31578. var barBorderRadius = backgroundModel.get('barBorderRadius') || 0;
  31579. var bgEls = [];
  31580. var oldBgEls = this._backgroundEls || [];
  31581. data.diff(oldData).add(function (dataIndex) {
  31582. var itemModel = data.getItemModel(dataIndex);
  31583. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  31584. if (drawBackground) {
  31585. var bgLayout = getLayout[coord.type](data, dataIndex);
  31586. var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
  31587. bgEl.useStyle(backgroundModel.getBarItemStyle()); // Only cartesian2d support borderRadius.
  31588. if (coord.type === 'cartesian2d') {
  31589. bgEl.setShape('r', barBorderRadius);
  31590. }
  31591. bgEls[dataIndex] = bgEl;
  31592. } // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  31593. if (!data.hasValue(dataIndex)) {
  31594. return;
  31595. }
  31596. if (needsClip) {
  31597. // Clip will modify the layout params.
  31598. // And return a boolean to determine if the shape are fully clipped.
  31599. var isClipped = clip[coord.type](coordSysClipArea, layout);
  31600. if (isClipped) {
  31601. group.remove(el);
  31602. return;
  31603. }
  31604. }
  31605. var el = elementCreator[coord.type](dataIndex, layout, isHorizontalOrRadial, animationModel, false, roundCap);
  31606. data.setItemGraphicEl(dataIndex, el);
  31607. group.add(el);
  31608. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  31609. }).update(function (newIndex, oldIndex) {
  31610. var itemModel = data.getItemModel(newIndex);
  31611. var layout = getLayout[coord.type](data, newIndex, itemModel);
  31612. if (drawBackground) {
  31613. var bgEl = oldBgEls[oldIndex];
  31614. bgEl.useStyle(backgroundModel.getBarItemStyle()); // Only cartesian2d support borderRadius.
  31615. if (coord.type === 'cartesian2d') {
  31616. bgEl.setShape('r', barBorderRadius);
  31617. }
  31618. bgEls[newIndex] = bgEl;
  31619. var bgLayout = getLayout[coord.type](data, newIndex);
  31620. var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
  31621. updateProps(bgEl, {
  31622. shape: shape
  31623. }, animationModel, newIndex);
  31624. }
  31625. var el = oldData.getItemGraphicEl(oldIndex);
  31626. if (!data.hasValue(newIndex)) {
  31627. group.remove(el);
  31628. return;
  31629. }
  31630. if (needsClip) {
  31631. var isClipped = clip[coord.type](coordSysClipArea, layout);
  31632. if (isClipped) {
  31633. group.remove(el);
  31634. return;
  31635. }
  31636. }
  31637. if (el) {
  31638. updateProps(el, {
  31639. shape: layout
  31640. }, animationModel, newIndex);
  31641. } else {
  31642. el = elementCreator[coord.type](newIndex, layout, isHorizontalOrRadial, animationModel, true, roundCap);
  31643. }
  31644. data.setItemGraphicEl(newIndex, el); // Add back
  31645. group.add(el);
  31646. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  31647. }).remove(function (dataIndex) {
  31648. var el = oldData.getItemGraphicEl(dataIndex);
  31649. if (coord.type === 'cartesian2d') {
  31650. el && removeRect(dataIndex, animationModel, el);
  31651. } else {
  31652. el && removeSector(dataIndex, animationModel, el);
  31653. }
  31654. }).execute();
  31655. var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
  31656. bgGroup.removeAll();
  31657. for (var i = 0; i < bgEls.length; ++i) {
  31658. bgGroup.add(bgEls[i]);
  31659. }
  31660. group.add(bgGroup);
  31661. this._backgroundEls = bgEls;
  31662. this._data = data;
  31663. },
  31664. _renderLarge: function (seriesModel, ecModel, api) {
  31665. this._clear();
  31666. createLarge(seriesModel, this.group); // Use clipPath in large mode.
  31667. var clipPath = seriesModel.get('clip', true) ? createClipPath(seriesModel.coordinateSystem, false, seriesModel) : null;
  31668. if (clipPath) {
  31669. this.group.setClipPath(clipPath);
  31670. } else {
  31671. this.group.removeClipPath();
  31672. }
  31673. },
  31674. _incrementalRenderLarge: function (params, seriesModel) {
  31675. this._removeBackground();
  31676. createLarge(seriesModel, this.group, true);
  31677. },
  31678. dispose: noop,
  31679. remove: function (ecModel) {
  31680. this._clear(ecModel);
  31681. },
  31682. _clear: function (ecModel) {
  31683. var group = this.group;
  31684. var data = this._data;
  31685. if (ecModel && ecModel.get('animation') && data && !this._isLargeDraw) {
  31686. this._removeBackground();
  31687. this._backgroundEls = [];
  31688. data.eachItemGraphicEl(function (el) {
  31689. if (el.type === 'sector') {
  31690. removeSector(el.dataIndex, ecModel, el);
  31691. } else {
  31692. removeRect(el.dataIndex, ecModel, el);
  31693. }
  31694. });
  31695. } else {
  31696. group.removeAll();
  31697. }
  31698. this._data = null;
  31699. },
  31700. _removeBackground: function () {
  31701. this.group.remove(this._backgroundGroup);
  31702. this._backgroundGroup = null;
  31703. }
  31704. });
  31705. var mathMax$4 = Math.max;
  31706. var mathMin$4 = Math.min;
  31707. var clip = {
  31708. cartesian2d: function (coordSysBoundingRect, layout) {
  31709. var signWidth = layout.width < 0 ? -1 : 1;
  31710. var signHeight = layout.height < 0 ? -1 : 1; // Needs positive width and height
  31711. if (signWidth < 0) {
  31712. layout.x += layout.width;
  31713. layout.width = -layout.width;
  31714. }
  31715. if (signHeight < 0) {
  31716. layout.y += layout.height;
  31717. layout.height = -layout.height;
  31718. }
  31719. var x = mathMax$4(layout.x, coordSysBoundingRect.x);
  31720. var x2 = mathMin$4(layout.x + layout.width, coordSysBoundingRect.x + coordSysBoundingRect.width);
  31721. var y = mathMax$4(layout.y, coordSysBoundingRect.y);
  31722. var y2 = mathMin$4(layout.y + layout.height, coordSysBoundingRect.y + coordSysBoundingRect.height);
  31723. layout.x = x;
  31724. layout.y = y;
  31725. layout.width = x2 - x;
  31726. layout.height = y2 - y;
  31727. var clipped = layout.width < 0 || layout.height < 0; // Reverse back
  31728. if (signWidth < 0) {
  31729. layout.x += layout.width;
  31730. layout.width = -layout.width;
  31731. }
  31732. if (signHeight < 0) {
  31733. layout.y += layout.height;
  31734. layout.height = -layout.height;
  31735. }
  31736. return clipped;
  31737. },
  31738. polar: function (coordSysClipArea) {
  31739. return false;
  31740. }
  31741. };
  31742. var elementCreator = {
  31743. cartesian2d: function (dataIndex, layout, isHorizontal, animationModel, isUpdate) {
  31744. var rect = new Rect({
  31745. shape: extend({}, layout),
  31746. z2: 1
  31747. });
  31748. rect.name = 'item'; // Animation
  31749. if (animationModel) {
  31750. var rectShape = rect.shape;
  31751. var animateProperty = isHorizontal ? 'height' : 'width';
  31752. var animateTarget = {};
  31753. rectShape[animateProperty] = 0;
  31754. animateTarget[animateProperty] = layout[animateProperty];
  31755. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  31756. shape: animateTarget
  31757. }, animationModel, dataIndex);
  31758. }
  31759. return rect;
  31760. },
  31761. polar: function (dataIndex, layout, isRadial, animationModel, isUpdate, roundCap) {
  31762. // Keep the same logic with bar in catesion: use end value to control
  31763. // direction. Notice that if clockwise is true (by default), the sector
  31764. // will always draw clockwisely, no matter whether endAngle is greater
  31765. // or less than startAngle.
  31766. var clockwise = layout.startAngle < layout.endAngle;
  31767. var ShapeClass = !isRadial && roundCap ? Sausage : Sector;
  31768. var sector = new ShapeClass({
  31769. shape: defaults({
  31770. clockwise: clockwise
  31771. }, layout),
  31772. z2: 1
  31773. });
  31774. sector.name = 'item'; // Animation
  31775. if (animationModel) {
  31776. var sectorShape = sector.shape;
  31777. var animateProperty = isRadial ? 'r' : 'endAngle';
  31778. var animateTarget = {};
  31779. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  31780. animateTarget[animateProperty] = layout[animateProperty];
  31781. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  31782. shape: animateTarget
  31783. }, animationModel, dataIndex);
  31784. }
  31785. return sector;
  31786. }
  31787. };
  31788. function removeRect(dataIndex, animationModel, el) {
  31789. // Not show text when animating
  31790. el.style.text = null;
  31791. updateProps(el, {
  31792. shape: {
  31793. width: 0
  31794. }
  31795. }, animationModel, dataIndex, function () {
  31796. el.parent && el.parent.remove(el);
  31797. });
  31798. }
  31799. function removeSector(dataIndex, animationModel, el) {
  31800. // Not show text when animating
  31801. el.style.text = null;
  31802. updateProps(el, {
  31803. shape: {
  31804. r: el.shape.r0
  31805. }
  31806. }, animationModel, dataIndex, function () {
  31807. el.parent && el.parent.remove(el);
  31808. });
  31809. }
  31810. var getLayout = {
  31811. // itemModel is only used to get borderWidth, which is not needed
  31812. // when calculating bar background layout.
  31813. cartesian2d: function (data, dataIndex, itemModel) {
  31814. var layout = data.getItemLayout(dataIndex);
  31815. var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0; // fix layout with lineWidth
  31816. var signX = layout.width > 0 ? 1 : -1;
  31817. var signY = layout.height > 0 ? 1 : -1;
  31818. return {
  31819. x: layout.x + signX * fixedLineWidth / 2,
  31820. y: layout.y + signY * fixedLineWidth / 2,
  31821. width: layout.width - signX * fixedLineWidth,
  31822. height: layout.height - signY * fixedLineWidth
  31823. };
  31824. },
  31825. polar: function (data, dataIndex, itemModel) {
  31826. var layout = data.getItemLayout(dataIndex);
  31827. return {
  31828. cx: layout.cx,
  31829. cy: layout.cy,
  31830. r0: layout.r0,
  31831. r: layout.r,
  31832. startAngle: layout.startAngle,
  31833. endAngle: layout.endAngle
  31834. };
  31835. }
  31836. };
  31837. function isZeroOnPolar(layout) {
  31838. return layout.startAngle != null && layout.endAngle != null && layout.startAngle === layout.endAngle;
  31839. }
  31840. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar) {
  31841. var color = data.getItemVisual(dataIndex, 'color');
  31842. var opacity = data.getItemVisual(dataIndex, 'opacity');
  31843. var stroke = data.getVisual('borderColor');
  31844. var itemStyleModel = itemModel.getModel('itemStyle');
  31845. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getBarItemStyle();
  31846. if (!isPolar) {
  31847. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  31848. }
  31849. el.useStyle(defaults({
  31850. stroke: isZeroOnPolar(layout) ? 'none' : stroke,
  31851. fill: isZeroOnPolar(layout) ? 'none' : color,
  31852. opacity: opacity
  31853. }, itemStyleModel.getBarItemStyle()));
  31854. var cursorStyle = itemModel.getShallow('cursor');
  31855. cursorStyle && el.attr('cursor', cursorStyle);
  31856. var labelPositionOutside = isHorizontal ? layout.height > 0 ? 'bottom' : 'top' : layout.width > 0 ? 'left' : 'right';
  31857. if (!isPolar) {
  31858. setLabel(el.style, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside);
  31859. }
  31860. if (isZeroOnPolar(layout)) {
  31861. hoverStyle.fill = hoverStyle.stroke = 'none';
  31862. }
  31863. setHoverStyle(el, hoverStyle);
  31864. } // In case width or height are too small.
  31865. function getLineWidth(itemModel, rawLayout) {
  31866. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0; // width or height may be NaN for empty data
  31867. var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
  31868. var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
  31869. return Math.min(lineWidth, width, height);
  31870. }
  31871. var LargePath = Path.extend({
  31872. type: 'largeBar',
  31873. shape: {
  31874. points: []
  31875. },
  31876. buildPath: function (ctx, shape) {
  31877. // Drawing lines is more efficient than drawing
  31878. // a whole line or drawing rects.
  31879. var points = shape.points;
  31880. var startPoint = this.__startPoint;
  31881. var baseDimIdx = this.__baseDimIdx;
  31882. for (var i = 0; i < points.length; i += 2) {
  31883. startPoint[baseDimIdx] = points[i + baseDimIdx];
  31884. ctx.moveTo(startPoint[0], startPoint[1]);
  31885. ctx.lineTo(points[i], points[i + 1]);
  31886. }
  31887. }
  31888. });
  31889. function createLarge(seriesModel, group, incremental) {
  31890. // TODO support polar
  31891. var data = seriesModel.getData();
  31892. var startPoint = [];
  31893. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  31894. startPoint[1 - baseDimIdx] = data.getLayout('valueAxisStart');
  31895. var largeDataIndices = data.getLayout('largeDataIndices');
  31896. var barWidth = data.getLayout('barWidth');
  31897. var backgroundModel = seriesModel.getModel('backgroundStyle');
  31898. var drawBackground = seriesModel.get('showBackground', true);
  31899. if (drawBackground) {
  31900. var points = data.getLayout('largeBackgroundPoints');
  31901. var backgroundStartPoint = [];
  31902. backgroundStartPoint[1 - baseDimIdx] = data.getLayout('backgroundStart');
  31903. var bgEl = new LargePath({
  31904. shape: {
  31905. points: points
  31906. },
  31907. incremental: !!incremental,
  31908. __startPoint: backgroundStartPoint,
  31909. __baseDimIdx: baseDimIdx,
  31910. __largeDataIndices: largeDataIndices,
  31911. __barWidth: barWidth,
  31912. silent: true,
  31913. z2: 0
  31914. });
  31915. setLargeBackgroundStyle(bgEl, backgroundModel, data);
  31916. group.add(bgEl);
  31917. }
  31918. var el = new LargePath({
  31919. shape: {
  31920. points: data.getLayout('largePoints')
  31921. },
  31922. incremental: !!incremental,
  31923. __startPoint: startPoint,
  31924. __baseDimIdx: baseDimIdx,
  31925. __largeDataIndices: largeDataIndices,
  31926. __barWidth: barWidth
  31927. });
  31928. group.add(el);
  31929. setLargeStyle(el, seriesModel, data); // Enable tooltip and user mouse/touch event handlers.
  31930. el.seriesIndex = seriesModel.seriesIndex;
  31931. if (!seriesModel.get('silent')) {
  31932. el.on('mousedown', largePathUpdateDataIndex);
  31933. el.on('mousemove', largePathUpdateDataIndex);
  31934. }
  31935. } // Use throttle to avoid frequently traverse to find dataIndex.
  31936. var largePathUpdateDataIndex = throttle(function (event) {
  31937. var largePath = this;
  31938. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  31939. largePath.dataIndex = dataIndex >= 0 ? dataIndex : null;
  31940. }, 30, false);
  31941. function largePathFindDataIndex(largePath, x, y) {
  31942. var baseDimIdx = largePath.__baseDimIdx;
  31943. var valueDimIdx = 1 - baseDimIdx;
  31944. var points = largePath.shape.points;
  31945. var largeDataIndices = largePath.__largeDataIndices;
  31946. var barWidthHalf = Math.abs(largePath.__barWidth / 2);
  31947. var startValueVal = largePath.__startPoint[valueDimIdx];
  31948. _eventPos[0] = x;
  31949. _eventPos[1] = y;
  31950. var pointerBaseVal = _eventPos[baseDimIdx];
  31951. var pointerValueVal = _eventPos[1 - baseDimIdx];
  31952. var baseLowerBound = pointerBaseVal - barWidthHalf;
  31953. var baseUpperBound = pointerBaseVal + barWidthHalf;
  31954. for (var i = 0, len = points.length / 2; i < len; i++) {
  31955. var ii = i * 2;
  31956. var barBaseVal = points[ii + baseDimIdx];
  31957. var barValueVal = points[ii + valueDimIdx];
  31958. if (barBaseVal >= baseLowerBound && barBaseVal <= baseUpperBound && (startValueVal <= barValueVal ? pointerValueVal >= startValueVal && pointerValueVal <= barValueVal : pointerValueVal >= barValueVal && pointerValueVal <= startValueVal)) {
  31959. return largeDataIndices[i];
  31960. }
  31961. }
  31962. return -1;
  31963. }
  31964. function setLargeStyle(el, seriesModel, data) {
  31965. var borderColor = data.getVisual('borderColor') || data.getVisual('color');
  31966. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle(['color', 'borderColor']);
  31967. el.useStyle(itemStyle);
  31968. el.style.fill = null;
  31969. el.style.stroke = borderColor;
  31970. el.style.lineWidth = data.getLayout('barWidth');
  31971. }
  31972. function setLargeBackgroundStyle(el, backgroundModel, data) {
  31973. var borderColor = backgroundModel.get('borderColor') || backgroundModel.get('color');
  31974. var itemStyle = backgroundModel.getItemStyle(['color', 'borderColor']);
  31975. el.useStyle(itemStyle);
  31976. el.style.fill = null;
  31977. el.style.stroke = borderColor;
  31978. el.style.lineWidth = data.getLayout('barWidth');
  31979. }
  31980. function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
  31981. var coordLayout;
  31982. var isPolar = coord.type === 'polar';
  31983. if (isPolar) {
  31984. coordLayout = coord.getArea();
  31985. } else {
  31986. coordLayout = coord.grid.getRect();
  31987. }
  31988. if (isPolar) {
  31989. return {
  31990. cx: coordLayout.cx,
  31991. cy: coordLayout.cy,
  31992. r0: isHorizontalOrRadial ? coordLayout.r0 : layout.r0,
  31993. r: isHorizontalOrRadial ? coordLayout.r : layout.r,
  31994. startAngle: isHorizontalOrRadial ? layout.startAngle : 0,
  31995. endAngle: isHorizontalOrRadial ? layout.endAngle : Math.PI * 2
  31996. };
  31997. } else {
  31998. return {
  31999. x: isHorizontalOrRadial ? layout.x : coordLayout.x,
  32000. y: isHorizontalOrRadial ? coordLayout.y : layout.y,
  32001. width: isHorizontalOrRadial ? layout.width : coordLayout.width,
  32002. height: isHorizontalOrRadial ? coordLayout.height : layout.height
  32003. };
  32004. }
  32005. }
  32006. function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
  32007. var ElementClz = coord.type === 'polar' ? Sector : Rect;
  32008. return new ElementClz({
  32009. shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
  32010. silent: true,
  32011. z2: 0
  32012. });
  32013. }
  32014. /*
  32015. * Licensed to the Apache Software Foundation (ASF) under one
  32016. * or more contributor license agreements. See the NOTICE file
  32017. * distributed with this work for additional information
  32018. * regarding copyright ownership. The ASF licenses this file
  32019. * to you under the Apache License, Version 2.0 (the
  32020. * "License"); you may not use this file except in compliance
  32021. * with the License. You may obtain a copy of the License at
  32022. *
  32023. * http://www.apache.org/licenses/LICENSE-2.0
  32024. *
  32025. * Unless required by applicable law or agreed to in writing,
  32026. * software distributed under the License is distributed on an
  32027. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32028. * KIND, either express or implied. See the License for the
  32029. * specific language governing permissions and limitations
  32030. * under the License.
  32031. */
  32032. var PI$2 = Math.PI;
  32033. /**
  32034. * A final axis is translated and rotated from a "standard axis".
  32035. * So opt.position and opt.rotation is required.
  32036. *
  32037. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  32038. * for example: (0, 0) ------------> (0, 50)
  32039. *
  32040. * nameDirection or tickDirection or labelDirection is 1 means tick
  32041. * or label is below the standard axis, whereas is -1 means above
  32042. * the standard axis. labelOffset means offset between label and axis,
  32043. * which is useful when 'onZero', where axisLabel is in the grid and
  32044. * label in outside grid.
  32045. *
  32046. * Tips: like always,
  32047. * positive rotation represents anticlockwise, and negative rotation
  32048. * represents clockwise.
  32049. * The direction of position coordinate is the same as the direction
  32050. * of screen coordinate.
  32051. *
  32052. * Do not need to consider axis 'inverse', which is auto processed by
  32053. * axis extent.
  32054. *
  32055. * @param {module:zrender/container/Group} group
  32056. * @param {Object} axisModel
  32057. * @param {Object} opt Standard axis parameters.
  32058. * @param {Array.<number>} opt.position [x, y]
  32059. * @param {number} opt.rotation by radian
  32060. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle' or 'center'.
  32061. * @param {number} [opt.tickDirection=1] 1 or -1
  32062. * @param {number} [opt.labelDirection=1] 1 or -1
  32063. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  32064. * @param {string} [opt.axisLabelShow] default get from axisModel.
  32065. * @param {string} [opt.axisName] default get from axisModel.
  32066. * @param {number} [opt.axisNameAvailableWidth]
  32067. * @param {number} [opt.labelRotate] by degree, default get from axisModel.
  32068. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  32069. * @param {number} [opt.nameTruncateMaxWidth]
  32070. */
  32071. var AxisBuilder = function (axisModel, opt) {
  32072. /**
  32073. * @readOnly
  32074. */
  32075. this.opt = opt;
  32076. /**
  32077. * @readOnly
  32078. */
  32079. this.axisModel = axisModel; // Default value
  32080. defaults(opt, {
  32081. labelOffset: 0,
  32082. nameDirection: 1,
  32083. tickDirection: 1,
  32084. labelDirection: 1,
  32085. silent: true
  32086. });
  32087. /**
  32088. * @readOnly
  32089. */
  32090. this.group = new Group(); // FIXME Not use a seperate text group?
  32091. var dumbGroup = new Group({
  32092. position: opt.position.slice(),
  32093. rotation: opt.rotation
  32094. }); // this.group.add(dumbGroup);
  32095. // this._dumbGroup = dumbGroup;
  32096. dumbGroup.updateTransform();
  32097. this._transform = dumbGroup.transform;
  32098. this._dumbGroup = dumbGroup;
  32099. };
  32100. AxisBuilder.prototype = {
  32101. constructor: AxisBuilder,
  32102. hasBuilder: function (name) {
  32103. return !!builders[name];
  32104. },
  32105. add: function (name) {
  32106. builders[name].call(this);
  32107. },
  32108. getGroup: function () {
  32109. return this.group;
  32110. }
  32111. };
  32112. var builders = {
  32113. /**
  32114. * @private
  32115. */
  32116. axisLine: function () {
  32117. var opt = this.opt;
  32118. var axisModel = this.axisModel;
  32119. if (!axisModel.get('axisLine.show')) {
  32120. return;
  32121. }
  32122. var extent = this.axisModel.axis.getExtent();
  32123. var matrix = this._transform;
  32124. var pt1 = [extent[0], 0];
  32125. var pt2 = [extent[1], 0];
  32126. if (matrix) {
  32127. applyTransform(pt1, pt1, matrix);
  32128. applyTransform(pt2, pt2, matrix);
  32129. }
  32130. var lineStyle = extend({
  32131. lineCap: 'round'
  32132. }, axisModel.getModel('axisLine.lineStyle').getLineStyle());
  32133. this.group.add(new Line({
  32134. // Id for animation
  32135. anid: 'line',
  32136. subPixelOptimize: true,
  32137. shape: {
  32138. x1: pt1[0],
  32139. y1: pt1[1],
  32140. x2: pt2[0],
  32141. y2: pt2[1]
  32142. },
  32143. style: lineStyle,
  32144. strokeContainThreshold: opt.strokeContainThreshold || 5,
  32145. silent: true,
  32146. z2: 1
  32147. }));
  32148. var arrows = axisModel.get('axisLine.symbol');
  32149. var arrowSize = axisModel.get('axisLine.symbolSize');
  32150. var arrowOffset = axisModel.get('axisLine.symbolOffset') || 0;
  32151. if (typeof arrowOffset === 'number') {
  32152. arrowOffset = [arrowOffset, arrowOffset];
  32153. }
  32154. if (arrows != null) {
  32155. if (typeof arrows === 'string') {
  32156. // Use the same arrow for start and end point
  32157. arrows = [arrows, arrows];
  32158. }
  32159. if (typeof arrowSize === 'string' || typeof arrowSize === 'number') {
  32160. // Use the same size for width and height
  32161. arrowSize = [arrowSize, arrowSize];
  32162. }
  32163. var symbolWidth = arrowSize[0];
  32164. var symbolHeight = arrowSize[1];
  32165. each$1([{
  32166. rotate: opt.rotation + Math.PI / 2,
  32167. offset: arrowOffset[0],
  32168. r: 0
  32169. }, {
  32170. rotate: opt.rotation - Math.PI / 2,
  32171. offset: arrowOffset[1],
  32172. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0]) + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  32173. }], function (point, index) {
  32174. if (arrows[index] !== 'none' && arrows[index] != null) {
  32175. var symbol = createSymbol(arrows[index], -symbolWidth / 2, -symbolHeight / 2, symbolWidth, symbolHeight, lineStyle.stroke, true); // Calculate arrow position with offset
  32176. var r = point.r + point.offset;
  32177. var pos = [pt1[0] + r * Math.cos(opt.rotation), pt1[1] - r * Math.sin(opt.rotation)];
  32178. symbol.attr({
  32179. rotation: point.rotate,
  32180. position: pos,
  32181. silent: true,
  32182. z2: 11
  32183. });
  32184. this.group.add(symbol);
  32185. }
  32186. }, this);
  32187. }
  32188. },
  32189. /**
  32190. * @private
  32191. */
  32192. axisTickLabel: function () {
  32193. var axisModel = this.axisModel;
  32194. var opt = this.opt;
  32195. var ticksEls = buildAxisMajorTicks(this, axisModel, opt);
  32196. var labelEls = buildAxisLabel(this, axisModel, opt);
  32197. fixMinMaxLabelShow(axisModel, labelEls, ticksEls);
  32198. buildAxisMinorTicks(this, axisModel, opt);
  32199. },
  32200. /**
  32201. * @private
  32202. */
  32203. axisName: function () {
  32204. var opt = this.opt;
  32205. var axisModel = this.axisModel;
  32206. var name = retrieve(opt.axisName, axisModel.get('name'));
  32207. if (!name) {
  32208. return;
  32209. }
  32210. var nameLocation = axisModel.get('nameLocation');
  32211. var nameDirection = opt.nameDirection;
  32212. var textStyleModel = axisModel.getModel('nameTextStyle');
  32213. var gap = axisModel.get('nameGap') || 0;
  32214. var extent = this.axisModel.axis.getExtent();
  32215. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  32216. var pos = [nameLocation === 'start' ? extent[0] - gapSignal * gap : nameLocation === 'end' ? extent[1] + gapSignal * gap : (extent[0] + extent[1]) / 2, // 'middle'
  32217. // Reuse labelOffset.
  32218. isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0];
  32219. var labelLayout;
  32220. var nameRotation = axisModel.get('nameRotate');
  32221. if (nameRotation != null) {
  32222. nameRotation = nameRotation * PI$2 / 180; // To radian.
  32223. }
  32224. var axisNameAvailableWidth;
  32225. if (isNameLocationCenter(nameLocation)) {
  32226. labelLayout = innerTextLayout(opt.rotation, nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  32227. nameDirection);
  32228. } else {
  32229. labelLayout = endTextLayout(opt, nameLocation, nameRotation || 0, extent);
  32230. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  32231. if (axisNameAvailableWidth != null) {
  32232. axisNameAvailableWidth = Math.abs(axisNameAvailableWidth / Math.sin(labelLayout.rotation));
  32233. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  32234. }
  32235. }
  32236. var textFont = textStyleModel.getFont();
  32237. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  32238. var ellipsis = truncateOpt.ellipsis;
  32239. var maxWidth = retrieve(opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth); // FIXME
  32240. // truncate rich text? (consider performance)
  32241. var truncatedText = ellipsis != null && maxWidth != null ? truncateText$1(name, maxWidth, textFont, ellipsis, {
  32242. minChar: 2,
  32243. placeholder: truncateOpt.placeholder
  32244. }) : name;
  32245. var tooltipOpt = axisModel.get('tooltip', true);
  32246. var mainType = axisModel.mainType;
  32247. var formatterParams = {
  32248. componentType: mainType,
  32249. name: name,
  32250. $vars: ['name']
  32251. };
  32252. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  32253. var textEl = new Text({
  32254. // Id for animation
  32255. anid: 'name',
  32256. __fullText: name,
  32257. __truncatedText: truncatedText,
  32258. position: pos,
  32259. rotation: labelLayout.rotation,
  32260. silent: isLabelSilent(axisModel),
  32261. z2: 1,
  32262. tooltip: tooltipOpt && tooltipOpt.show ? extend({
  32263. content: name,
  32264. formatter: function () {
  32265. return name;
  32266. },
  32267. formatterParams: formatterParams
  32268. }, tooltipOpt) : null
  32269. });
  32270. setTextStyle(textEl.style, textStyleModel, {
  32271. text: truncatedText,
  32272. textFont: textFont,
  32273. textFill: textStyleModel.getTextColor() || axisModel.get('axisLine.lineStyle.color'),
  32274. textAlign: textStyleModel.get('align') || labelLayout.textAlign,
  32275. textVerticalAlign: textStyleModel.get('verticalAlign') || labelLayout.textVerticalAlign
  32276. });
  32277. if (axisModel.get('triggerEvent')) {
  32278. textEl.eventData = makeAxisEventDataBase(axisModel);
  32279. textEl.eventData.targetType = 'axisName';
  32280. textEl.eventData.name = name;
  32281. } // FIXME
  32282. this._dumbGroup.add(textEl);
  32283. textEl.updateTransform();
  32284. this.group.add(textEl);
  32285. textEl.decomposeTransform();
  32286. }
  32287. };
  32288. var makeAxisEventDataBase = AxisBuilder.makeAxisEventDataBase = function (axisModel) {
  32289. var eventData = {
  32290. componentType: axisModel.mainType,
  32291. componentIndex: axisModel.componentIndex
  32292. };
  32293. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  32294. return eventData;
  32295. };
  32296. /**
  32297. * @public
  32298. * @static
  32299. * @param {Object} opt
  32300. * @param {number} axisRotation in radian
  32301. * @param {number} textRotation in radian
  32302. * @param {number} direction
  32303. * @return {Object} {
  32304. * rotation, // according to axis
  32305. * textAlign,
  32306. * textVerticalAlign
  32307. * }
  32308. */
  32309. var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  32310. var rotationDiff = remRadian(textRotation - axisRotation);
  32311. var textAlign;
  32312. var textVerticalAlign;
  32313. if (isRadianAroundZero(rotationDiff)) {
  32314. // Label is parallel with axis line.
  32315. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  32316. textAlign = 'center';
  32317. } else if (isRadianAroundZero(rotationDiff - PI$2)) {
  32318. // Label is inverse parallel with axis line.
  32319. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  32320. textAlign = 'center';
  32321. } else {
  32322. textVerticalAlign = 'middle';
  32323. if (rotationDiff > 0 && rotationDiff < PI$2) {
  32324. textAlign = direction > 0 ? 'right' : 'left';
  32325. } else {
  32326. textAlign = direction > 0 ? 'left' : 'right';
  32327. }
  32328. }
  32329. return {
  32330. rotation: rotationDiff,
  32331. textAlign: textAlign,
  32332. textVerticalAlign: textVerticalAlign
  32333. };
  32334. };
  32335. function endTextLayout(opt, textPosition, textRotate, extent) {
  32336. var rotationDiff = remRadian(textRotate - opt.rotation);
  32337. var textAlign;
  32338. var textVerticalAlign;
  32339. var inverse = extent[0] > extent[1];
  32340. var onLeft = textPosition === 'start' && !inverse || textPosition !== 'start' && inverse;
  32341. if (isRadianAroundZero(rotationDiff - PI$2 / 2)) {
  32342. textVerticalAlign = onLeft ? 'bottom' : 'top';
  32343. textAlign = 'center';
  32344. } else if (isRadianAroundZero(rotationDiff - PI$2 * 1.5)) {
  32345. textVerticalAlign = onLeft ? 'top' : 'bottom';
  32346. textAlign = 'center';
  32347. } else {
  32348. textVerticalAlign = 'middle';
  32349. if (rotationDiff < PI$2 * 1.5 && rotationDiff > PI$2 / 2) {
  32350. textAlign = onLeft ? 'left' : 'right';
  32351. } else {
  32352. textAlign = onLeft ? 'right' : 'left';
  32353. }
  32354. }
  32355. return {
  32356. rotation: rotationDiff,
  32357. textAlign: textAlign,
  32358. textVerticalAlign: textVerticalAlign
  32359. };
  32360. }
  32361. var isLabelSilent = AxisBuilder.isLabelSilent = function (axisModel) {
  32362. var tooltipOpt = axisModel.get('tooltip');
  32363. return axisModel.get('silent') // Consider mouse cursor, add these restrictions.
  32364. || !(axisModel.get('triggerEvent') || tooltipOpt && tooltipOpt.show);
  32365. };
  32366. function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
  32367. if (shouldShowAllLabels(axisModel.axis)) {
  32368. return;
  32369. } // If min or max are user set, we need to check
  32370. // If the tick on min(max) are overlap on their neighbour tick
  32371. // If they are overlapped, we need to hide the min(max) tick label
  32372. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  32373. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel'); // FIXME
  32374. // Have not consider onBand yet, where tick els is more than label els.
  32375. labelEls = labelEls || [];
  32376. tickEls = tickEls || [];
  32377. var firstLabel = labelEls[0];
  32378. var nextLabel = labelEls[1];
  32379. var lastLabel = labelEls[labelEls.length - 1];
  32380. var prevLabel = labelEls[labelEls.length - 2];
  32381. var firstTick = tickEls[0];
  32382. var nextTick = tickEls[1];
  32383. var lastTick = tickEls[tickEls.length - 1];
  32384. var prevTick = tickEls[tickEls.length - 2];
  32385. if (showMinLabel === false) {
  32386. ignoreEl(firstLabel);
  32387. ignoreEl(firstTick);
  32388. } else if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  32389. if (showMinLabel) {
  32390. ignoreEl(nextLabel);
  32391. ignoreEl(nextTick);
  32392. } else {
  32393. ignoreEl(firstLabel);
  32394. ignoreEl(firstTick);
  32395. }
  32396. }
  32397. if (showMaxLabel === false) {
  32398. ignoreEl(lastLabel);
  32399. ignoreEl(lastTick);
  32400. } else if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  32401. if (showMaxLabel) {
  32402. ignoreEl(prevLabel);
  32403. ignoreEl(prevTick);
  32404. } else {
  32405. ignoreEl(lastLabel);
  32406. ignoreEl(lastTick);
  32407. }
  32408. }
  32409. }
  32410. function ignoreEl(el) {
  32411. el && (el.ignore = true);
  32412. }
  32413. function isTwoLabelOverlapped(current, next, labelLayout) {
  32414. // current and next has the same rotation.
  32415. var firstRect = current && current.getBoundingRect().clone();
  32416. var nextRect = next && next.getBoundingRect().clone();
  32417. if (!firstRect || !nextRect) {
  32418. return;
  32419. } // When checking intersect of two rotated labels, we use mRotationBack
  32420. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  32421. var mRotationBack = identity([]);
  32422. rotate(mRotationBack, mRotationBack, -current.rotation);
  32423. firstRect.applyTransform(mul$1([], mRotationBack, current.getLocalTransform()));
  32424. nextRect.applyTransform(mul$1([], mRotationBack, next.getLocalTransform()));
  32425. return firstRect.intersect(nextRect);
  32426. }
  32427. function isNameLocationCenter(nameLocation) {
  32428. return nameLocation === 'middle' || nameLocation === 'center';
  32429. }
  32430. function createTicks(ticksCoords, tickTransform, tickEndCoord, tickLineStyle, aniid) {
  32431. var tickEls = [];
  32432. var pt1 = [];
  32433. var pt2 = [];
  32434. for (var i = 0; i < ticksCoords.length; i++) {
  32435. var tickCoord = ticksCoords[i].coord;
  32436. pt1[0] = tickCoord;
  32437. pt1[1] = 0;
  32438. pt2[0] = tickCoord;
  32439. pt2[1] = tickEndCoord;
  32440. if (tickTransform) {
  32441. applyTransform(pt1, pt1, tickTransform);
  32442. applyTransform(pt2, pt2, tickTransform);
  32443. } // Tick line, Not use group transform to have better line draw
  32444. var tickEl = new Line({
  32445. // Id for animation
  32446. anid: aniid + '_' + ticksCoords[i].tickValue,
  32447. subPixelOptimize: true,
  32448. shape: {
  32449. x1: pt1[0],
  32450. y1: pt1[1],
  32451. x2: pt2[0],
  32452. y2: pt2[1]
  32453. },
  32454. style: tickLineStyle,
  32455. z2: 2,
  32456. silent: true
  32457. });
  32458. tickEls.push(tickEl);
  32459. }
  32460. return tickEls;
  32461. }
  32462. function buildAxisMajorTicks(axisBuilder, axisModel, opt) {
  32463. var axis = axisModel.axis;
  32464. var tickModel = axisModel.getModel('axisTick');
  32465. if (!tickModel.get('show') || axis.scale.isBlank()) {
  32466. return;
  32467. }
  32468. var lineStyleModel = tickModel.getModel('lineStyle');
  32469. var tickEndCoord = opt.tickDirection * tickModel.get('length');
  32470. var ticksCoords = axis.getTicksCoords();
  32471. var ticksEls = createTicks(ticksCoords, axisBuilder._transform, tickEndCoord, defaults(lineStyleModel.getLineStyle(), {
  32472. stroke: axisModel.get('axisLine.lineStyle.color')
  32473. }), 'ticks');
  32474. for (var i = 0; i < ticksEls.length; i++) {
  32475. axisBuilder.group.add(ticksEls[i]);
  32476. }
  32477. return ticksEls;
  32478. }
  32479. function buildAxisMinorTicks(axisBuilder, axisModel, opt) {
  32480. var axis = axisModel.axis;
  32481. var minorTickModel = axisModel.getModel('minorTick');
  32482. if (!minorTickModel.get('show') || axis.scale.isBlank()) {
  32483. return;
  32484. }
  32485. var minorTicksCoords = axis.getMinorTicksCoords();
  32486. if (!minorTicksCoords.length) {
  32487. return;
  32488. }
  32489. var lineStyleModel = minorTickModel.getModel('lineStyle');
  32490. var tickEndCoord = opt.tickDirection * minorTickModel.get('length');
  32491. var minorTickLineStyle = defaults(lineStyleModel.getLineStyle(), defaults(axisModel.getModel('axisTick').getLineStyle(), {
  32492. stroke: axisModel.get('axisLine.lineStyle.color')
  32493. }));
  32494. for (var i = 0; i < minorTicksCoords.length; i++) {
  32495. var minorTicksEls = createTicks(minorTicksCoords[i], axisBuilder._transform, tickEndCoord, minorTickLineStyle, 'minorticks_' + i);
  32496. for (var k = 0; k < minorTicksEls.length; k++) {
  32497. axisBuilder.group.add(minorTicksEls[k]);
  32498. }
  32499. }
  32500. }
  32501. function buildAxisLabel(axisBuilder, axisModel, opt) {
  32502. var axis = axisModel.axis;
  32503. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  32504. if (!show || axis.scale.isBlank()) {
  32505. return;
  32506. }
  32507. var labelModel = axisModel.getModel('axisLabel');
  32508. var labelMargin = labelModel.get('margin');
  32509. var labels = axis.getViewLabels(); // Special label rotate.
  32510. var labelRotation = (retrieve(opt.labelRotate, labelModel.get('rotate')) || 0) * PI$2 / 180;
  32511. var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  32512. var rawCategoryData = axisModel.getCategories && axisModel.getCategories(true);
  32513. var labelEls = [];
  32514. var silent = isLabelSilent(axisModel);
  32515. var triggerEvent = axisModel.get('triggerEvent');
  32516. each$1(labels, function (labelItem, index) {
  32517. var tickValue = labelItem.tickValue;
  32518. var formattedLabel = labelItem.formattedLabel;
  32519. var rawLabel = labelItem.rawLabel;
  32520. var itemLabelModel = labelModel;
  32521. if (rawCategoryData && rawCategoryData[tickValue] && rawCategoryData[tickValue].textStyle) {
  32522. itemLabelModel = new Model(rawCategoryData[tickValue].textStyle, labelModel, axisModel.ecModel);
  32523. }
  32524. var textColor = itemLabelModel.getTextColor() || axisModel.get('axisLine.lineStyle.color');
  32525. var tickCoord = axis.dataToCoord(tickValue);
  32526. var pos = [tickCoord, opt.labelOffset + opt.labelDirection * labelMargin];
  32527. var textEl = new Text({
  32528. // Id for animation
  32529. anid: 'label_' + tickValue,
  32530. position: pos,
  32531. rotation: labelLayout.rotation,
  32532. silent: silent,
  32533. z2: 10
  32534. });
  32535. setTextStyle(textEl.style, itemLabelModel, {
  32536. text: formattedLabel,
  32537. textAlign: itemLabelModel.getShallow('align', true) || labelLayout.textAlign,
  32538. textVerticalAlign: itemLabelModel.getShallow('verticalAlign', true) || itemLabelModel.getShallow('baseline', true) || labelLayout.textVerticalAlign,
  32539. textFill: typeof textColor === 'function' ? textColor( // (1) In category axis with data zoom, tick is not the original
  32540. // index of axis.data. So tick should not be exposed to user
  32541. // in category axis.
  32542. // (2) Compatible with previous version, which always use formatted label as
  32543. // input. But in interval scale the formatted label is like '223,445', which
  32544. // maked user repalce ','. So we modify it to return original val but remain
  32545. // it as 'string' to avoid error in replacing.
  32546. axis.type === 'category' ? rawLabel : axis.type === 'value' ? tickValue + '' : tickValue, index) : textColor
  32547. }); // Pack data for mouse event
  32548. if (triggerEvent) {
  32549. textEl.eventData = makeAxisEventDataBase(axisModel);
  32550. textEl.eventData.targetType = 'axisLabel';
  32551. textEl.eventData.value = rawLabel;
  32552. } // FIXME
  32553. axisBuilder._dumbGroup.add(textEl);
  32554. textEl.updateTransform();
  32555. labelEls.push(textEl);
  32556. axisBuilder.group.add(textEl);
  32557. textEl.decomposeTransform();
  32558. });
  32559. return labelEls;
  32560. }
  32561. /*
  32562. * Licensed to the Apache Software Foundation (ASF) under one
  32563. * or more contributor license agreements. See the NOTICE file
  32564. * distributed with this work for additional information
  32565. * regarding copyright ownership. The ASF licenses this file
  32566. * to you under the Apache License, Version 2.0 (the
  32567. * "License"); you may not use this file except in compliance
  32568. * with the License. You may obtain a copy of the License at
  32569. *
  32570. * http://www.apache.org/licenses/LICENSE-2.0
  32571. *
  32572. * Unless required by applicable law or agreed to in writing,
  32573. * software distributed under the License is distributed on an
  32574. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32575. * KIND, either express or implied. See the License for the
  32576. * specific language governing permissions and limitations
  32577. * under the License.
  32578. */
  32579. var each$6 = each$1;
  32580. var curry$1 = curry; // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  32581. // allAxesInfo should be updated when setOption performed.
  32582. function collect(ecModel, api) {
  32583. var result = {
  32584. /**
  32585. * key: makeKey(axis.model)
  32586. * value: {
  32587. * axis,
  32588. * coordSys,
  32589. * axisPointerModel,
  32590. * triggerTooltip,
  32591. * involveSeries,
  32592. * snap,
  32593. * seriesModels,
  32594. * seriesDataCount
  32595. * }
  32596. */
  32597. axesInfo: {},
  32598. seriesInvolved: false,
  32599. /**
  32600. * key: makeKey(coordSys.model)
  32601. * value: Object: key makeKey(axis.model), value: axisInfo
  32602. */
  32603. coordSysAxesInfo: {},
  32604. coordSysMap: {}
  32605. };
  32606. collectAxesInfo(result, ecModel, api); // Check seriesInvolved for performance, in case too many series in some chart.
  32607. result.seriesInvolved && collectSeriesInfo(result, ecModel);
  32608. return result;
  32609. }
  32610. function collectAxesInfo(result, ecModel, api) {
  32611. var globalTooltipModel = ecModel.getComponent('tooltip');
  32612. var globalAxisPointerModel = ecModel.getComponent('axisPointer'); // links can only be set on global.
  32613. var linksOption = globalAxisPointerModel.get('link', true) || [];
  32614. var linkGroups = []; // Collect axes info.
  32615. each$6(api.getCoordinateSystems(), function (coordSys) {
  32616. // Some coordinate system do not support axes, like geo.
  32617. if (!coordSys.axisPointerEnabled) {
  32618. return;
  32619. }
  32620. var coordSysKey = makeKey(coordSys.model);
  32621. var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
  32622. result.coordSysMap[coordSysKey] = coordSys; // Set tooltip (like 'cross') is a convienent way to show axisPointer
  32623. // for user. So we enable seting tooltip on coordSys model.
  32624. var coordSysModel = coordSys.model;
  32625. var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
  32626. each$6(coordSys.getAxes(), curry$1(saveTooltipAxisInfo, false, null)); // If axis tooltip used, choose tooltip axis for each coordSys.
  32627. // Notice this case: coordSys is `grid` but not `cartesian2D` here.
  32628. if (coordSys.getTooltipAxes && globalTooltipModel // If tooltip.showContent is set as false, tooltip will not
  32629. // show but axisPointer will show as normal.
  32630. && baseTooltipModel.get('show')) {
  32631. // Compatible with previous logic. But series.tooltip.trigger: 'axis'
  32632. // or series.data[n].tooltip.trigger: 'axis' are not support any more.
  32633. var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
  32634. var cross = baseTooltipModel.get('axisPointer.type') === 'cross';
  32635. var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get('axisPointer.axis'));
  32636. if (triggerAxis || cross) {
  32637. each$6(tooltipAxes.baseAxes, curry$1(saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis));
  32638. }
  32639. if (cross) {
  32640. each$6(tooltipAxes.otherAxes, curry$1(saveTooltipAxisInfo, 'cross', false));
  32641. }
  32642. } // fromTooltip: true | false | 'cross'
  32643. // triggerTooltip: true | false | null
  32644. function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
  32645. var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
  32646. var axisPointerShow = axisPointerModel.get('show');
  32647. if (!axisPointerShow || axisPointerShow === 'auto' && !fromTooltip && !isHandleTrigger(axisPointerModel)) {
  32648. return;
  32649. }
  32650. if (triggerTooltip == null) {
  32651. triggerTooltip = axisPointerModel.get('triggerTooltip');
  32652. }
  32653. axisPointerModel = fromTooltip ? makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) : axisPointerModel;
  32654. var snap = axisPointerModel.get('snap');
  32655. var key = makeKey(axis.model);
  32656. var involveSeries = triggerTooltip || snap || axis.type === 'category'; // If result.axesInfo[key] exist, override it (tooltip has higher priority).
  32657. var axisInfo = result.axesInfo[key] = {
  32658. key: key,
  32659. axis: axis,
  32660. coordSys: coordSys,
  32661. axisPointerModel: axisPointerModel,
  32662. triggerTooltip: triggerTooltip,
  32663. involveSeries: involveSeries,
  32664. snap: snap,
  32665. useHandle: isHandleTrigger(axisPointerModel),
  32666. seriesModels: []
  32667. };
  32668. axesInfoInCoordSys[key] = axisInfo;
  32669. result.seriesInvolved |= involveSeries;
  32670. var groupIndex = getLinkGroupIndex(linksOption, axis);
  32671. if (groupIndex != null) {
  32672. var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {
  32673. axesInfo: {}
  32674. });
  32675. linkGroup.axesInfo[key] = axisInfo;
  32676. linkGroup.mapper = linksOption[groupIndex].mapper;
  32677. axisInfo.linkGroup = linkGroup;
  32678. }
  32679. }
  32680. });
  32681. }
  32682. function makeAxisPointerModel(axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip) {
  32683. var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
  32684. var volatileOption = {};
  32685. each$6(['type', 'snap', 'lineStyle', 'shadowStyle', 'label', 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'], function (field) {
  32686. volatileOption[field] = clone(tooltipAxisPointerModel.get(field));
  32687. }); // category axis do not auto snap, otherwise some tick that do not
  32688. // has value can not be hovered. value/time/log axis default snap if
  32689. // triggered from tooltip and trigger tooltip.
  32690. volatileOption.snap = axis.type !== 'category' && !!triggerTooltip; // Compatibel with previous behavior, tooltip axis do not show label by default.
  32691. // Only these properties can be overrided from tooltip to axisPointer.
  32692. if (tooltipAxisPointerModel.get('type') === 'cross') {
  32693. volatileOption.type = 'line';
  32694. }
  32695. var labelOption = volatileOption.label || (volatileOption.label = {}); // Follow the convention, do not show label when triggered by tooltip by default.
  32696. labelOption.show == null && (labelOption.show = false);
  32697. if (fromTooltip === 'cross') {
  32698. // When 'cross', both axes show labels.
  32699. var tooltipAxisPointerLabelShow = tooltipAxisPointerModel.get('label.show');
  32700. labelOption.show = tooltipAxisPointerLabelShow != null ? tooltipAxisPointerLabelShow : true; // If triggerTooltip, this is a base axis, which should better not use cross style
  32701. // (cross style is dashed by default)
  32702. if (!triggerTooltip) {
  32703. var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
  32704. crossStyle && defaults(labelOption, crossStyle.textStyle);
  32705. }
  32706. }
  32707. return axis.model.getModel('axisPointer', new Model(volatileOption, globalAxisPointerModel, ecModel));
  32708. }
  32709. function collectSeriesInfo(result, ecModel) {
  32710. // Prepare data for axis trigger
  32711. ecModel.eachSeries(function (seriesModel) {
  32712. // Notice this case: this coordSys is `cartesian2D` but not `grid`.
  32713. var coordSys = seriesModel.coordinateSystem;
  32714. var seriesTooltipTrigger = seriesModel.get('tooltip.trigger', true);
  32715. var seriesTooltipShow = seriesModel.get('tooltip.show', true);
  32716. if (!coordSys || seriesTooltipTrigger === 'none' || seriesTooltipTrigger === false || seriesTooltipTrigger === 'item' || seriesTooltipShow === false || seriesModel.get('axisPointer.show', true) === false) {
  32717. return;
  32718. }
  32719. each$6(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
  32720. var axis = axisInfo.axis;
  32721. if (coordSys.getAxis(axis.dim) === axis) {
  32722. axisInfo.seriesModels.push(seriesModel);
  32723. axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
  32724. axisInfo.seriesDataCount += seriesModel.getData().count();
  32725. }
  32726. });
  32727. }, this);
  32728. }
  32729. /**
  32730. * For example:
  32731. * {
  32732. * axisPointer: {
  32733. * links: [{
  32734. * xAxisIndex: [2, 4],
  32735. * yAxisIndex: 'all'
  32736. * }, {
  32737. * xAxisId: ['a5', 'a7'],
  32738. * xAxisName: 'xxx'
  32739. * }]
  32740. * }
  32741. * }
  32742. */
  32743. function getLinkGroupIndex(linksOption, axis) {
  32744. var axisModel = axis.model;
  32745. var dim = axis.dim;
  32746. for (var i = 0; i < linksOption.length; i++) {
  32747. var linkOption = linksOption[i] || {};
  32748. if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id) || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex) || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)) {
  32749. return i;
  32750. }
  32751. }
  32752. }
  32753. function checkPropInLink(linkPropValue, axisPropValue) {
  32754. return linkPropValue === 'all' || isArray(linkPropValue) && indexOf(linkPropValue, axisPropValue) >= 0 || linkPropValue === axisPropValue;
  32755. }
  32756. function fixValue(axisModel) {
  32757. var axisInfo = getAxisInfo(axisModel);
  32758. if (!axisInfo) {
  32759. return;
  32760. }
  32761. var axisPointerModel = axisInfo.axisPointerModel;
  32762. var scale = axisInfo.axis.scale;
  32763. var option = axisPointerModel.option;
  32764. var status = axisPointerModel.get('status');
  32765. var value = axisPointerModel.get('value'); // Parse init value for category and time axis.
  32766. if (value != null) {
  32767. value = scale.parse(value);
  32768. }
  32769. var useHandle = isHandleTrigger(axisPointerModel); // If `handle` used, `axisPointer` will always be displayed, so value
  32770. // and status should be initialized.
  32771. if (status == null) {
  32772. option.status = useHandle ? 'show' : 'hide';
  32773. }
  32774. var extent = scale.getExtent().slice();
  32775. extent[0] > extent[1] && extent.reverse();
  32776. if ( // Pick a value on axis when initializing.
  32777. value == null // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  32778. // where we should re-pick a value to keep `handle` displaying normally.
  32779. || value > extent[1]) {
  32780. // Make handle displayed on the end of the axis when init, which looks better.
  32781. value = extent[1];
  32782. }
  32783. if (value < extent[0]) {
  32784. value = extent[0];
  32785. }
  32786. option.value = value;
  32787. if (useHandle) {
  32788. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  32789. }
  32790. }
  32791. function getAxisInfo(axisModel) {
  32792. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  32793. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  32794. }
  32795. function getAxisPointerModel(axisModel) {
  32796. var axisInfo = getAxisInfo(axisModel);
  32797. return axisInfo && axisInfo.axisPointerModel;
  32798. }
  32799. function isHandleTrigger(axisPointerModel) {
  32800. return !!axisPointerModel.get('handle.show');
  32801. }
  32802. /**
  32803. * @param {module:echarts/model/Model} model
  32804. * @return {string} unique key
  32805. */
  32806. function makeKey(model) {
  32807. return model.type + '||' + model.id;
  32808. }
  32809. /*
  32810. * Licensed to the Apache Software Foundation (ASF) under one
  32811. * or more contributor license agreements. See the NOTICE file
  32812. * distributed with this work for additional information
  32813. * regarding copyright ownership. The ASF licenses this file
  32814. * to you under the Apache License, Version 2.0 (the
  32815. * "License"); you may not use this file except in compliance
  32816. * with the License. You may obtain a copy of the License at
  32817. *
  32818. * http://www.apache.org/licenses/LICENSE-2.0
  32819. *
  32820. * Unless required by applicable law or agreed to in writing,
  32821. * software distributed under the License is distributed on an
  32822. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32823. * KIND, either express or implied. See the License for the
  32824. * specific language governing permissions and limitations
  32825. * under the License.
  32826. */
  32827. /**
  32828. * Base class of AxisView.
  32829. */
  32830. var AxisView = extendComponentView({
  32831. type: 'axis',
  32832. /**
  32833. * @private
  32834. */
  32835. _axisPointer: null,
  32836. /**
  32837. * @protected
  32838. * @type {string}
  32839. */
  32840. axisPointerClass: null,
  32841. /**
  32842. * @override
  32843. */
  32844. render: function (axisModel, ecModel, api, payload) {
  32845. // FIXME
  32846. // This process should proformed after coordinate systems updated
  32847. // (axis scale updated), and should be performed each time update.
  32848. // So put it here temporarily, although it is not appropriate to
  32849. // put a model-writing procedure in `view`.
  32850. this.axisPointerClass && fixValue(axisModel);
  32851. AxisView.superApply(this, 'render', arguments);
  32852. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  32853. },
  32854. /**
  32855. * Action handler.
  32856. * @public
  32857. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  32858. * @param {module:echarts/model/Global} ecModel
  32859. * @param {module:echarts/ExtensionAPI} api
  32860. * @param {Object} payload
  32861. */
  32862. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  32863. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  32864. },
  32865. /**
  32866. * @override
  32867. */
  32868. remove: function (ecModel, api) {
  32869. var axisPointer = this._axisPointer;
  32870. axisPointer && axisPointer.remove(api);
  32871. AxisView.superApply(this, 'remove', arguments);
  32872. },
  32873. /**
  32874. * @override
  32875. */
  32876. dispose: function (ecModel, api) {
  32877. disposeAxisPointer(this, api);
  32878. AxisView.superApply(this, 'dispose', arguments);
  32879. }
  32880. });
  32881. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  32882. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  32883. if (!Clazz) {
  32884. return;
  32885. }
  32886. var axisPointerModel = getAxisPointerModel(axisModel);
  32887. axisPointerModel ? (axisView._axisPointer || (axisView._axisPointer = new Clazz())).render(axisModel, axisPointerModel, api, forceRender) : disposeAxisPointer(axisView, api);
  32888. }
  32889. function disposeAxisPointer(axisView, ecModel, api) {
  32890. var axisPointer = axisView._axisPointer;
  32891. axisPointer && axisPointer.dispose(ecModel, api);
  32892. axisView._axisPointer = null;
  32893. }
  32894. var axisPointerClazz = [];
  32895. AxisView.registerAxisPointerClass = function (type, clazz) {
  32896. axisPointerClazz[type] = clazz;
  32897. };
  32898. AxisView.getAxisPointerClass = function (type) {
  32899. return type && axisPointerClazz[type];
  32900. };
  32901. /*
  32902. * Licensed to the Apache Software Foundation (ASF) under one
  32903. * or more contributor license agreements. See the NOTICE file
  32904. * distributed with this work for additional information
  32905. * regarding copyright ownership. The ASF licenses this file
  32906. * to you under the Apache License, Version 2.0 (the
  32907. * "License"); you may not use this file except in compliance
  32908. * with the License. You may obtain a copy of the License at
  32909. *
  32910. * http://www.apache.org/licenses/LICENSE-2.0
  32911. *
  32912. * Unless required by applicable law or agreed to in writing,
  32913. * software distributed under the License is distributed on an
  32914. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32915. * KIND, either express or implied. See the License for the
  32916. * specific language governing permissions and limitations
  32917. * under the License.
  32918. */
  32919. /**
  32920. * Can only be called after coordinate system creation stage.
  32921. * (Can be called before coordinate system update stage).
  32922. *
  32923. * @param {Object} opt {labelInside}
  32924. * @return {Object} {
  32925. * position, rotation, labelDirection, labelOffset,
  32926. * tickDirection, labelRotate, z2
  32927. * }
  32928. */
  32929. function layout$1(gridModel, axisModel, opt) {
  32930. opt = opt || {};
  32931. var grid = gridModel.coordinateSystem;
  32932. var axis = axisModel.axis;
  32933. var layout = {};
  32934. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  32935. var rawAxisPosition = axis.position;
  32936. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  32937. var axisDim = axis.dim;
  32938. var rect = grid.getRect();
  32939. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  32940. var idx = {
  32941. left: 0,
  32942. right: 1,
  32943. top: 0,
  32944. bottom: 1,
  32945. onZero: 2
  32946. };
  32947. var axisOffset = axisModel.get('offset') || 0;
  32948. var posBound = axisDim === 'x' ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset] : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  32949. if (otherAxisOnZeroOf) {
  32950. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  32951. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  32952. } // Axis position
  32953. layout.position = [axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0], axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]]; // Axis rotation
  32954. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1); // Tick and label direction, x y is axisDim
  32955. var dirMap = {
  32956. top: -1,
  32957. bottom: 1,
  32958. left: -1,
  32959. right: 1
  32960. };
  32961. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  32962. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  32963. if (axisModel.get('axisTick.inside')) {
  32964. layout.tickDirection = -layout.tickDirection;
  32965. }
  32966. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  32967. layout.labelDirection = -layout.labelDirection;
  32968. } // Special label rotation
  32969. var labelRotate = axisModel.get('axisLabel.rotate');
  32970. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate; // Over splitLine and splitArea
  32971. layout.z2 = 1;
  32972. return layout;
  32973. }
  32974. /*
  32975. * Licensed to the Apache Software Foundation (ASF) under one
  32976. * or more contributor license agreements. See the NOTICE file
  32977. * distributed with this work for additional information
  32978. * regarding copyright ownership. The ASF licenses this file
  32979. * to you under the Apache License, Version 2.0 (the
  32980. * "License"); you may not use this file except in compliance
  32981. * with the License. You may obtain a copy of the License at
  32982. *
  32983. * http://www.apache.org/licenses/LICENSE-2.0
  32984. *
  32985. * Unless required by applicable law or agreed to in writing,
  32986. * software distributed under the License is distributed on an
  32987. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32988. * KIND, either express or implied. See the License for the
  32989. * specific language governing permissions and limitations
  32990. * under the License.
  32991. */
  32992. function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
  32993. var axis = axisModel.axis;
  32994. if (axis.scale.isBlank()) {
  32995. return;
  32996. }
  32997. var splitAreaModel = axisModel.getModel('splitArea');
  32998. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  32999. var areaColors = areaStyleModel.get('color');
  33000. var gridRect = gridModel.coordinateSystem.getRect();
  33001. var ticksCoords = axis.getTicksCoords({
  33002. tickModel: splitAreaModel,
  33003. clamp: true
  33004. });
  33005. if (!ticksCoords.length) {
  33006. return;
  33007. } // For Making appropriate splitArea animation, the color and anid
  33008. // should be corresponding to previous one if possible.
  33009. var areaColorsLen = areaColors.length;
  33010. var lastSplitAreaColors = axisView.__splitAreaColors;
  33011. var newSplitAreaColors = createHashMap();
  33012. var colorIndex = 0;
  33013. if (lastSplitAreaColors) {
  33014. for (var i = 0; i < ticksCoords.length; i++) {
  33015. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  33016. if (cIndex != null) {
  33017. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  33018. break;
  33019. }
  33020. }
  33021. }
  33022. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  33023. var areaStyle = areaStyleModel.getAreaStyle();
  33024. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  33025. for (var i = 1; i < ticksCoords.length; i++) {
  33026. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  33027. var x;
  33028. var y;
  33029. var width;
  33030. var height;
  33031. if (axis.isHorizontal()) {
  33032. x = prev;
  33033. y = gridRect.y;
  33034. width = tickCoord - x;
  33035. height = gridRect.height;
  33036. prev = x + width;
  33037. } else {
  33038. x = gridRect.x;
  33039. y = prev;
  33040. width = gridRect.width;
  33041. height = tickCoord - y;
  33042. prev = y + height;
  33043. }
  33044. var tickValue = ticksCoords[i - 1].tickValue;
  33045. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  33046. axisGroup.add(new Rect({
  33047. anid: tickValue != null ? 'area_' + tickValue : null,
  33048. shape: {
  33049. x: x,
  33050. y: y,
  33051. width: width,
  33052. height: height
  33053. },
  33054. style: defaults({
  33055. fill: areaColors[colorIndex]
  33056. }, areaStyle),
  33057. silent: true
  33058. }));
  33059. colorIndex = (colorIndex + 1) % areaColorsLen;
  33060. }
  33061. axisView.__splitAreaColors = newSplitAreaColors;
  33062. }
  33063. function rectCoordAxisHandleRemove(axisView) {
  33064. axisView.__splitAreaColors = null;
  33065. }
  33066. /*
  33067. * Licensed to the Apache Software Foundation (ASF) under one
  33068. * or more contributor license agreements. See the NOTICE file
  33069. * distributed with this work for additional information
  33070. * regarding copyright ownership. The ASF licenses this file
  33071. * to you under the Apache License, Version 2.0 (the
  33072. * "License"); you may not use this file except in compliance
  33073. * with the License. You may obtain a copy of the License at
  33074. *
  33075. * http://www.apache.org/licenses/LICENSE-2.0
  33076. *
  33077. * Unless required by applicable law or agreed to in writing,
  33078. * software distributed under the License is distributed on an
  33079. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33080. * KIND, either express or implied. See the License for the
  33081. * specific language governing permissions and limitations
  33082. * under the License.
  33083. */
  33084. var axisBuilderAttrs = ['axisLine', 'axisTickLabel', 'axisName'];
  33085. var selfBuilderAttrs = ['splitArea', 'splitLine', 'minorSplitLine'];
  33086. var CartesianAxisView = AxisView.extend({
  33087. type: 'cartesianAxis',
  33088. axisPointerClass: 'CartesianAxisPointer',
  33089. /**
  33090. * @override
  33091. */
  33092. render: function (axisModel, ecModel, api, payload) {
  33093. this.group.removeAll();
  33094. var oldAxisGroup = this._axisGroup;
  33095. this._axisGroup = new Group();
  33096. this.group.add(this._axisGroup);
  33097. if (!axisModel.get('show')) {
  33098. return;
  33099. }
  33100. var gridModel = axisModel.getCoordSysModel();
  33101. var layout = layout$1(gridModel, axisModel);
  33102. var axisBuilder = new AxisBuilder(axisModel, layout);
  33103. each$1(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  33104. this._axisGroup.add(axisBuilder.getGroup());
  33105. each$1(selfBuilderAttrs, function (name) {
  33106. if (axisModel.get(name + '.show')) {
  33107. this['_' + name](axisModel, gridModel);
  33108. }
  33109. }, this);
  33110. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  33111. CartesianAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  33112. },
  33113. remove: function () {
  33114. rectCoordAxisHandleRemove(this);
  33115. },
  33116. /**
  33117. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  33118. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  33119. * @private
  33120. */
  33121. _splitLine: function (axisModel, gridModel) {
  33122. var axis = axisModel.axis;
  33123. if (axis.scale.isBlank()) {
  33124. return;
  33125. }
  33126. var splitLineModel = axisModel.getModel('splitLine');
  33127. var lineStyleModel = splitLineModel.getModel('lineStyle');
  33128. var lineColors = lineStyleModel.get('color');
  33129. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  33130. var gridRect = gridModel.coordinateSystem.getRect();
  33131. var isHorizontal = axis.isHorizontal();
  33132. var lineCount = 0;
  33133. var ticksCoords = axis.getTicksCoords({
  33134. tickModel: splitLineModel
  33135. });
  33136. var p1 = [];
  33137. var p2 = [];
  33138. var lineStyle = lineStyleModel.getLineStyle();
  33139. for (var i = 0; i < ticksCoords.length; i++) {
  33140. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  33141. if (isHorizontal) {
  33142. p1[0] = tickCoord;
  33143. p1[1] = gridRect.y;
  33144. p2[0] = tickCoord;
  33145. p2[1] = gridRect.y + gridRect.height;
  33146. } else {
  33147. p1[0] = gridRect.x;
  33148. p1[1] = tickCoord;
  33149. p2[0] = gridRect.x + gridRect.width;
  33150. p2[1] = tickCoord;
  33151. }
  33152. var colorIndex = lineCount++ % lineColors.length;
  33153. var tickValue = ticksCoords[i].tickValue;
  33154. this._axisGroup.add(new Line({
  33155. anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
  33156. subPixelOptimize: true,
  33157. shape: {
  33158. x1: p1[0],
  33159. y1: p1[1],
  33160. x2: p2[0],
  33161. y2: p2[1]
  33162. },
  33163. style: defaults({
  33164. stroke: lineColors[colorIndex]
  33165. }, lineStyle),
  33166. silent: true
  33167. }));
  33168. }
  33169. },
  33170. /**
  33171. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  33172. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  33173. * @private
  33174. */
  33175. _minorSplitLine: function (axisModel, gridModel) {
  33176. var axis = axisModel.axis;
  33177. var minorSplitLineModel = axisModel.getModel('minorSplitLine');
  33178. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  33179. var gridRect = gridModel.coordinateSystem.getRect();
  33180. var isHorizontal = axis.isHorizontal();
  33181. var minorTicksCoords = axis.getMinorTicksCoords();
  33182. if (!minorTicksCoords.length) {
  33183. return;
  33184. }
  33185. var p1 = [];
  33186. var p2 = [];
  33187. var lineStyle = lineStyleModel.getLineStyle();
  33188. for (var i = 0; i < minorTicksCoords.length; i++) {
  33189. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  33190. var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
  33191. if (isHorizontal) {
  33192. p1[0] = tickCoord;
  33193. p1[1] = gridRect.y;
  33194. p2[0] = tickCoord;
  33195. p2[1] = gridRect.y + gridRect.height;
  33196. } else {
  33197. p1[0] = gridRect.x;
  33198. p1[1] = tickCoord;
  33199. p2[0] = gridRect.x + gridRect.width;
  33200. p2[1] = tickCoord;
  33201. }
  33202. this._axisGroup.add(new Line({
  33203. anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
  33204. subPixelOptimize: true,
  33205. shape: {
  33206. x1: p1[0],
  33207. y1: p1[1],
  33208. x2: p2[0],
  33209. y2: p2[1]
  33210. },
  33211. style: lineStyle,
  33212. silent: true
  33213. }));
  33214. }
  33215. }
  33216. },
  33217. /**
  33218. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  33219. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  33220. * @private
  33221. */
  33222. _splitArea: function (axisModel, gridModel) {
  33223. rectCoordAxisBuildSplitArea(this, this._axisGroup, axisModel, gridModel);
  33224. }
  33225. });
  33226. CartesianAxisView.extend({
  33227. type: 'xAxis'
  33228. });
  33229. CartesianAxisView.extend({
  33230. type: 'yAxis'
  33231. });
  33232. /*
  33233. * Licensed to the Apache Software Foundation (ASF) under one
  33234. * or more contributor license agreements. See the NOTICE file
  33235. * distributed with this work for additional information
  33236. * regarding copyright ownership. The ASF licenses this file
  33237. * to you under the Apache License, Version 2.0 (the
  33238. * "License"); you may not use this file except in compliance
  33239. * with the License. You may obtain a copy of the License at
  33240. *
  33241. * http://www.apache.org/licenses/LICENSE-2.0
  33242. *
  33243. * Unless required by applicable law or agreed to in writing,
  33244. * software distributed under the License is distributed on an
  33245. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33246. * KIND, either express or implied. See the License for the
  33247. * specific language governing permissions and limitations
  33248. * under the License.
  33249. */
  33250. /*
  33251. * Licensed to the Apache Software Foundation (ASF) under one
  33252. * or more contributor license agreements. See the NOTICE file
  33253. * distributed with this work for additional information
  33254. * regarding copyright ownership. The ASF licenses this file
  33255. * to you under the Apache License, Version 2.0 (the
  33256. * "License"); you may not use this file except in compliance
  33257. * with the License. You may obtain a copy of the License at
  33258. *
  33259. * http://www.apache.org/licenses/LICENSE-2.0
  33260. *
  33261. * Unless required by applicable law or agreed to in writing,
  33262. * software distributed under the License is distributed on an
  33263. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33264. * KIND, either express or implied. See the License for the
  33265. * specific language governing permissions and limitations
  33266. * under the License.
  33267. */
  33268. extendComponentView({
  33269. type: 'grid',
  33270. render: function (gridModel, ecModel) {
  33271. this.group.removeAll();
  33272. if (gridModel.get('show')) {
  33273. this.group.add(new Rect({
  33274. shape: gridModel.coordinateSystem.getRect(),
  33275. style: defaults({
  33276. fill: gridModel.get('backgroundColor')
  33277. }, gridModel.getItemStyle()),
  33278. silent: true,
  33279. z2: -1
  33280. }));
  33281. }
  33282. }
  33283. });
  33284. registerPreprocessor(function (option) {
  33285. // Only create grid when need
  33286. if (option.xAxis && option.yAxis && !option.grid) {
  33287. option.grid = {};
  33288. }
  33289. });
  33290. /*
  33291. * Licensed to the Apache Software Foundation (ASF) under one
  33292. * or more contributor license agreements. See the NOTICE file
  33293. * distributed with this work for additional information
  33294. * regarding copyright ownership. The ASF licenses this file
  33295. * to you under the Apache License, Version 2.0 (the
  33296. * "License"); you may not use this file except in compliance
  33297. * with the License. You may obtain a copy of the License at
  33298. *
  33299. * http://www.apache.org/licenses/LICENSE-2.0
  33300. *
  33301. * Unless required by applicable law or agreed to in writing,
  33302. * software distributed under the License is distributed on an
  33303. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33304. * KIND, either express or implied. See the License for the
  33305. * specific language governing permissions and limitations
  33306. * under the License.
  33307. */
  33308. registerLayout(PRIORITY.VISUAL.LAYOUT, curry(layout, 'bar')); // Use higher prority to avoid to be blocked by other overall layout, which do not
  33309. // only exist in this module, but probably also exist in other modules, like `barPolar`.
  33310. registerLayout(PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, largeLayout);
  33311. registerVisual({
  33312. seriesType: 'bar',
  33313. reset: function (seriesModel) {
  33314. // Visual coding for legend
  33315. seriesModel.getData().setVisual('legendSymbol', 'roundRect');
  33316. }
  33317. });
  33318. /*
  33319. * Licensed to the Apache Software Foundation (ASF) under one
  33320. * or more contributor license agreements. See the NOTICE file
  33321. * distributed with this work for additional information
  33322. * regarding copyright ownership. The ASF licenses this file
  33323. * to you under the Apache License, Version 2.0 (the
  33324. * "License"); you may not use this file except in compliance
  33325. * with the License. You may obtain a copy of the License at
  33326. *
  33327. * http://www.apache.org/licenses/LICENSE-2.0
  33328. *
  33329. * Unless required by applicable law or agreed to in writing,
  33330. * software distributed under the License is distributed on an
  33331. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33332. * KIND, either express or implied. See the License for the
  33333. * specific language governing permissions and limitations
  33334. * under the License.
  33335. */
  33336. SeriesModel.extend({
  33337. type: 'series.line',
  33338. dependencies: ['grid', 'polar'],
  33339. getInitialData: function (option, ecModel) {
  33340. return createListFromArray(this.getSource(), this, {
  33341. useEncodeDefaulter: true
  33342. });
  33343. },
  33344. defaultOption: {
  33345. zlevel: 0,
  33346. z: 2,
  33347. coordinateSystem: 'cartesian2d',
  33348. legendHoverLink: true,
  33349. hoverAnimation: true,
  33350. // stack: null
  33351. // xAxisIndex: 0,
  33352. // yAxisIndex: 0,
  33353. // polarIndex: 0,
  33354. // If clip the overflow value
  33355. clip: true,
  33356. // cursor: null,
  33357. label: {
  33358. position: 'top'
  33359. },
  33360. // itemStyle: {
  33361. // },
  33362. lineStyle: {
  33363. width: 2,
  33364. type: 'solid'
  33365. },
  33366. // areaStyle: {
  33367. // origin of areaStyle. Valid values:
  33368. // `'auto'/null/undefined`: from axisLine to data
  33369. // `'start'`: from min to data
  33370. // `'end'`: from data to max
  33371. // origin: 'auto'
  33372. // },
  33373. // false, 'start', 'end', 'middle'
  33374. step: false,
  33375. // Disabled if step is true
  33376. smooth: false,
  33377. smoothMonotone: null,
  33378. symbol: 'emptyCircle',
  33379. symbolSize: 4,
  33380. symbolRotate: null,
  33381. showSymbol: true,
  33382. // `false`: follow the label interval strategy.
  33383. // `true`: show all symbols.
  33384. // `'auto'`: If possible, show all symbols, otherwise
  33385. // follow the label interval strategy.
  33386. showAllSymbol: 'auto',
  33387. // Whether to connect break point.
  33388. connectNulls: false,
  33389. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum'.
  33390. sampling: 'none',
  33391. animationEasing: 'linear',
  33392. // Disable progressive
  33393. progressive: 0,
  33394. hoverLayerThreshold: Infinity
  33395. }
  33396. });
  33397. /*
  33398. * Licensed to the Apache Software Foundation (ASF) under one
  33399. * or more contributor license agreements. See the NOTICE file
  33400. * distributed with this work for additional information
  33401. * regarding copyright ownership. The ASF licenses this file
  33402. * to you under the Apache License, Version 2.0 (the
  33403. * "License"); you may not use this file except in compliance
  33404. * with the License. You may obtain a copy of the License at
  33405. *
  33406. * http://www.apache.org/licenses/LICENSE-2.0
  33407. *
  33408. * Unless required by applicable law or agreed to in writing,
  33409. * software distributed under the License is distributed on an
  33410. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33411. * KIND, either express or implied. See the License for the
  33412. * specific language governing permissions and limitations
  33413. * under the License.
  33414. */
  33415. /**
  33416. * @module echarts/chart/helper/Symbol
  33417. */
  33418. /**
  33419. * @constructor
  33420. * @alias {module:echarts/chart/helper/Symbol}
  33421. * @param {module:echarts/data/List} data
  33422. * @param {number} idx
  33423. * @extends {module:zrender/graphic/Group}
  33424. */
  33425. function SymbolClz$1(data, idx, seriesScope) {
  33426. Group.call(this);
  33427. this.updateData(data, idx, seriesScope);
  33428. }
  33429. var symbolProto = SymbolClz$1.prototype;
  33430. /**
  33431. * @public
  33432. * @static
  33433. * @param {module:echarts/data/List} data
  33434. * @param {number} dataIndex
  33435. * @return {Array.<number>} [width, height]
  33436. */
  33437. var getSymbolSize = SymbolClz$1.getSymbolSize = function (data, idx) {
  33438. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  33439. return symbolSize instanceof Array ? symbolSize.slice() : [+symbolSize, +symbolSize];
  33440. };
  33441. function getScale(symbolSize) {
  33442. return [symbolSize[0] / 2, symbolSize[1] / 2];
  33443. }
  33444. function driftSymbol(dx, dy) {
  33445. this.parent.drift(dx, dy);
  33446. }
  33447. symbolProto._createSymbol = function (symbolType, data, idx, symbolSize, keepAspect) {
  33448. // Remove paths created before
  33449. this.removeAll();
  33450. var color = data.getItemVisual(idx, 'color'); // var symbolPath = createSymbol(
  33451. // symbolType, -0.5, -0.5, 1, 1, color
  33452. // );
  33453. // If width/height are set too small (e.g., set to 1) on ios10
  33454. // and macOS Sierra, a circle stroke become a rect, no matter what
  33455. // the scale is set. So we set width/height as 2. See #4150.
  33456. var symbolPath = createSymbol(symbolType, -1, -1, 2, 2, color, keepAspect);
  33457. symbolPath.attr({
  33458. z2: 100,
  33459. culling: true,
  33460. scale: getScale(symbolSize)
  33461. }); // Rewrite drift method
  33462. symbolPath.drift = driftSymbol;
  33463. this._symbolType = symbolType;
  33464. this.add(symbolPath);
  33465. };
  33466. /**
  33467. * Stop animation
  33468. * @param {boolean} toLastFrame
  33469. */
  33470. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  33471. this.childAt(0).stopAnimation(toLastFrame);
  33472. };
  33473. /**
  33474. * FIXME:
  33475. * Caution: This method breaks the encapsulation of this module,
  33476. * but it indeed brings convenience. So do not use the method
  33477. * unless you detailedly know all the implements of `Symbol`,
  33478. * especially animation.
  33479. *
  33480. * Get symbol path element.
  33481. */
  33482. symbolProto.getSymbolPath = function () {
  33483. return this.childAt(0);
  33484. };
  33485. /**
  33486. * Get scale(aka, current symbol size).
  33487. * Including the change caused by animation
  33488. */
  33489. symbolProto.getScale = function () {
  33490. return this.childAt(0).scale;
  33491. };
  33492. /**
  33493. * Highlight symbol
  33494. */
  33495. symbolProto.highlight = function () {
  33496. this.childAt(0).trigger('emphasis');
  33497. };
  33498. /**
  33499. * Downplay symbol
  33500. */
  33501. symbolProto.downplay = function () {
  33502. this.childAt(0).trigger('normal');
  33503. };
  33504. /**
  33505. * @param {number} zlevel
  33506. * @param {number} z
  33507. */
  33508. symbolProto.setZ = function (zlevel, z) {
  33509. var symbolPath = this.childAt(0);
  33510. symbolPath.zlevel = zlevel;
  33511. symbolPath.z = z;
  33512. };
  33513. symbolProto.setDraggable = function (draggable) {
  33514. var symbolPath = this.childAt(0);
  33515. symbolPath.draggable = draggable;
  33516. symbolPath.cursor = draggable ? 'move' : symbolPath.cursor;
  33517. };
  33518. /**
  33519. * Update symbol properties
  33520. * @param {module:echarts/data/List} data
  33521. * @param {number} idx
  33522. * @param {Object} [seriesScope]
  33523. * @param {Object} [seriesScope.itemStyle]
  33524. * @param {Object} [seriesScope.hoverItemStyle]
  33525. * @param {Object} [seriesScope.symbolRotate]
  33526. * @param {Object} [seriesScope.symbolOffset]
  33527. * @param {module:echarts/model/Model} [seriesScope.labelModel]
  33528. * @param {module:echarts/model/Model} [seriesScope.hoverLabelModel]
  33529. * @param {boolean} [seriesScope.hoverAnimation]
  33530. * @param {Object} [seriesScope.cursorStyle]
  33531. * @param {module:echarts/model/Model} [seriesScope.itemModel]
  33532. * @param {string} [seriesScope.symbolInnerColor]
  33533. * @param {Object} [seriesScope.fadeIn=false]
  33534. */
  33535. symbolProto.updateData = function (data, idx, seriesScope) {
  33536. this.silent = false;
  33537. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  33538. var seriesModel = data.hostModel;
  33539. var symbolSize = getSymbolSize(data, idx);
  33540. var isInit = symbolType !== this._symbolType;
  33541. if (isInit) {
  33542. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  33543. this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
  33544. } else {
  33545. var symbolPath = this.childAt(0);
  33546. symbolPath.silent = false;
  33547. updateProps(symbolPath, {
  33548. scale: getScale(symbolSize)
  33549. }, seriesModel, idx);
  33550. }
  33551. this._updateCommon(data, idx, symbolSize, seriesScope);
  33552. if (isInit) {
  33553. var symbolPath = this.childAt(0);
  33554. var fadeIn = seriesScope && seriesScope.fadeIn;
  33555. var target = {
  33556. scale: symbolPath.scale.slice()
  33557. };
  33558. fadeIn && (target.style = {
  33559. opacity: symbolPath.style.opacity
  33560. });
  33561. symbolPath.scale = [0, 0];
  33562. fadeIn && (symbolPath.style.opacity = 0);
  33563. initProps(symbolPath, target, seriesModel, idx);
  33564. }
  33565. this._seriesModel = seriesModel;
  33566. }; // Update common properties
  33567. var normalStyleAccessPath = ['itemStyle'];
  33568. var emphasisStyleAccessPath = ['emphasis', 'itemStyle'];
  33569. var normalLabelAccessPath = ['label'];
  33570. var emphasisLabelAccessPath = ['emphasis', 'label'];
  33571. /**
  33572. * @param {module:echarts/data/List} data
  33573. * @param {number} idx
  33574. * @param {Array.<number>} symbolSize
  33575. * @param {Object} [seriesScope]
  33576. */
  33577. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  33578. var symbolPath = this.childAt(0);
  33579. var seriesModel = data.hostModel;
  33580. var color = data.getItemVisual(idx, 'color'); // Reset style
  33581. if (symbolPath.type !== 'image') {
  33582. symbolPath.useStyle({
  33583. strokeNoScale: true
  33584. });
  33585. } else {
  33586. symbolPath.setStyle({
  33587. opacity: null,
  33588. shadowBlur: null,
  33589. shadowOffsetX: null,
  33590. shadowOffsetY: null,
  33591. shadowColor: null
  33592. });
  33593. }
  33594. var itemStyle = seriesScope && seriesScope.itemStyle;
  33595. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  33596. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  33597. var labelModel = seriesScope && seriesScope.labelModel;
  33598. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  33599. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  33600. var cursorStyle = seriesScope && seriesScope.cursorStyle;
  33601. if (!seriesScope || data.hasItemOption) {
  33602. var itemModel = seriesScope && seriesScope.itemModel ? seriesScope.itemModel : data.getItemModel(idx); // Color must be excluded.
  33603. // Because symbol provide setColor individually to set fill and stroke
  33604. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  33605. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  33606. symbolOffset = itemModel.getShallow('symbolOffset');
  33607. labelModel = itemModel.getModel(normalLabelAccessPath);
  33608. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  33609. hoverAnimation = itemModel.getShallow('hoverAnimation');
  33610. cursorStyle = itemModel.getShallow('cursor');
  33611. } else {
  33612. hoverItemStyle = extend({}, hoverItemStyle);
  33613. }
  33614. var elStyle = symbolPath.style;
  33615. var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
  33616. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  33617. if (symbolOffset) {
  33618. symbolPath.attr('position', [parsePercent$1(symbolOffset[0], symbolSize[0]), parsePercent$1(symbolOffset[1], symbolSize[1])]);
  33619. }
  33620. cursorStyle && symbolPath.attr('cursor', cursorStyle); // PENDING setColor before setStyle!!!
  33621. symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
  33622. symbolPath.setStyle(itemStyle);
  33623. var opacity = data.getItemVisual(idx, 'opacity');
  33624. if (opacity != null) {
  33625. elStyle.opacity = opacity;
  33626. }
  33627. var liftZ = data.getItemVisual(idx, 'liftZ');
  33628. var z2Origin = symbolPath.__z2Origin;
  33629. if (liftZ != null) {
  33630. if (z2Origin == null) {
  33631. symbolPath.__z2Origin = symbolPath.z2;
  33632. symbolPath.z2 += liftZ;
  33633. }
  33634. } else if (z2Origin != null) {
  33635. symbolPath.z2 = z2Origin;
  33636. symbolPath.__z2Origin = null;
  33637. }
  33638. var useNameLabel = seriesScope && seriesScope.useNameLabel;
  33639. setLabelStyle(elStyle, hoverItemStyle, labelModel, hoverLabelModel, {
  33640. labelFetcher: seriesModel,
  33641. labelDataIndex: idx,
  33642. defaultText: getLabelDefaultText,
  33643. isRectText: true,
  33644. autoColor: color
  33645. }); // Do not execute util needed.
  33646. function getLabelDefaultText(idx, opt) {
  33647. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  33648. }
  33649. symbolPath.__symbolOriginalScale = getScale(symbolSize);
  33650. symbolPath.hoverStyle = hoverItemStyle;
  33651. symbolPath.highDownOnUpdate = hoverAnimation && seriesModel.isAnimationEnabled() ? highDownOnUpdate : null;
  33652. setHoverStyle(symbolPath);
  33653. };
  33654. function highDownOnUpdate(fromState, toState) {
  33655. // Do not support this hover animation util some scenario required.
  33656. // Animation can only be supported in hover layer when using `el.incremetal`.
  33657. if (this.incremental || this.useHoverLayer) {
  33658. return;
  33659. }
  33660. if (toState === 'emphasis') {
  33661. var scale = this.__symbolOriginalScale;
  33662. var ratio = scale[1] / scale[0];
  33663. var emphasisOpt = {
  33664. scale: [Math.max(scale[0] * 1.1, scale[0] + 3), Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)]
  33665. }; // FIXME
  33666. // modify it after support stop specified animation.
  33667. // toState === fromState
  33668. // ? (this.stopAnimation(), this.attr(emphasisOpt))
  33669. this.animateTo(emphasisOpt, 400, 'elasticOut');
  33670. } else if (toState === 'normal') {
  33671. this.animateTo({
  33672. scale: this.__symbolOriginalScale
  33673. }, 400, 'elasticOut');
  33674. }
  33675. }
  33676. /**
  33677. * @param {Function} cb
  33678. * @param {Object} [opt]
  33679. * @param {Object} [opt.keepLabel=true]
  33680. */
  33681. symbolProto.fadeOut = function (cb, opt) {
  33682. var symbolPath = this.childAt(0); // Avoid mistaken hover when fading out
  33683. this.silent = symbolPath.silent = true; // Not show text when animating
  33684. !(opt && opt.keepLabel) && (symbolPath.style.text = null);
  33685. updateProps(symbolPath, {
  33686. style: {
  33687. opacity: 0
  33688. },
  33689. scale: [0, 0]
  33690. }, this._seriesModel, this.dataIndex, cb);
  33691. };
  33692. inherits(SymbolClz$1, Group);
  33693. /*
  33694. * Licensed to the Apache Software Foundation (ASF) under one
  33695. * or more contributor license agreements. See the NOTICE file
  33696. * distributed with this work for additional information
  33697. * regarding copyright ownership. The ASF licenses this file
  33698. * to you under the Apache License, Version 2.0 (the
  33699. * "License"); you may not use this file except in compliance
  33700. * with the License. You may obtain a copy of the License at
  33701. *
  33702. * http://www.apache.org/licenses/LICENSE-2.0
  33703. *
  33704. * Unless required by applicable law or agreed to in writing,
  33705. * software distributed under the License is distributed on an
  33706. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33707. * KIND, either express or implied. See the License for the
  33708. * specific language governing permissions and limitations
  33709. * under the License.
  33710. */
  33711. /**
  33712. * @module echarts/chart/helper/SymbolDraw
  33713. */
  33714. /**
  33715. * @constructor
  33716. * @alias module:echarts/chart/helper/SymbolDraw
  33717. * @param {module:zrender/graphic/Group} [symbolCtor]
  33718. */
  33719. function SymbolDraw(symbolCtor) {
  33720. this.group = new Group();
  33721. this._symbolCtor = symbolCtor || SymbolClz$1;
  33722. }
  33723. var symbolDrawProto = SymbolDraw.prototype;
  33724. function symbolNeedsDraw(data, point, idx, opt) {
  33725. 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
  33726. // the symbol element shape. We use the same clip shape here as
  33727. // the line clip.
  33728. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1])) && data.getItemVisual(idx, 'symbol') !== 'none';
  33729. }
  33730. /**
  33731. * Update symbols draw by new data
  33732. * @param {module:echarts/data/List} data
  33733. * @param {Object} [opt] Or isIgnore
  33734. * @param {Function} [opt.isIgnore]
  33735. * @param {Object} [opt.clipShape]
  33736. */
  33737. symbolDrawProto.updateData = function (data, opt) {
  33738. opt = normalizeUpdateOpt(opt);
  33739. var group = this.group;
  33740. var seriesModel = data.hostModel;
  33741. var oldData = this._data;
  33742. var SymbolCtor = this._symbolCtor;
  33743. var seriesScope = makeSeriesScope(data); // There is no oldLineData only when first rendering or switching from
  33744. // stream mode to normal mode, where previous elements should be removed.
  33745. if (!oldData) {
  33746. group.removeAll();
  33747. }
  33748. data.diff(oldData).add(function (newIdx) {
  33749. var point = data.getItemLayout(newIdx);
  33750. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  33751. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  33752. symbolEl.attr('position', point);
  33753. data.setItemGraphicEl(newIdx, symbolEl);
  33754. group.add(symbolEl);
  33755. }
  33756. }).update(function (newIdx, oldIdx) {
  33757. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  33758. var point = data.getItemLayout(newIdx);
  33759. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  33760. group.remove(symbolEl);
  33761. return;
  33762. }
  33763. if (!symbolEl) {
  33764. symbolEl = new SymbolCtor(data, newIdx);
  33765. symbolEl.attr('position', point);
  33766. } else {
  33767. symbolEl.updateData(data, newIdx, seriesScope);
  33768. updateProps(symbolEl, {
  33769. position: point
  33770. }, seriesModel);
  33771. } // Add back
  33772. group.add(symbolEl);
  33773. data.setItemGraphicEl(newIdx, symbolEl);
  33774. }).remove(function (oldIdx) {
  33775. var el = oldData.getItemGraphicEl(oldIdx);
  33776. el && el.fadeOut(function () {
  33777. group.remove(el);
  33778. });
  33779. }).execute();
  33780. this._data = data;
  33781. };
  33782. symbolDrawProto.isPersistent = function () {
  33783. return true;
  33784. };
  33785. symbolDrawProto.updateLayout = function () {
  33786. var data = this._data;
  33787. if (data) {
  33788. // Not use animation
  33789. data.eachItemGraphicEl(function (el, idx) {
  33790. var point = data.getItemLayout(idx);
  33791. el.attr('position', point);
  33792. });
  33793. }
  33794. };
  33795. symbolDrawProto.incrementalPrepareUpdate = function (data) {
  33796. this._seriesScope = makeSeriesScope(data);
  33797. this._data = null;
  33798. this.group.removeAll();
  33799. };
  33800. /**
  33801. * Update symbols draw by new data
  33802. * @param {module:echarts/data/List} data
  33803. * @param {Object} [opt] Or isIgnore
  33804. * @param {Function} [opt.isIgnore]
  33805. * @param {Object} [opt.clipShape]
  33806. */
  33807. symbolDrawProto.incrementalUpdate = function (taskParams, data, opt) {
  33808. opt = normalizeUpdateOpt(opt);
  33809. function updateIncrementalAndHover(el) {
  33810. if (!el.isGroup) {
  33811. el.incremental = el.useHoverLayer = true;
  33812. }
  33813. }
  33814. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  33815. var point = data.getItemLayout(idx);
  33816. if (symbolNeedsDraw(data, point, idx, opt)) {
  33817. var el = new this._symbolCtor(data, idx, this._seriesScope);
  33818. el.traverse(updateIncrementalAndHover);
  33819. el.attr('position', point);
  33820. this.group.add(el);
  33821. data.setItemGraphicEl(idx, el);
  33822. }
  33823. }
  33824. };
  33825. function normalizeUpdateOpt(opt) {
  33826. if (opt != null && !isObject$1(opt)) {
  33827. opt = {
  33828. isIgnore: opt
  33829. };
  33830. }
  33831. return opt || {};
  33832. }
  33833. symbolDrawProto.remove = function (enableAnimation) {
  33834. var group = this.group;
  33835. var data = this._data; // Incremental model do not have this._data.
  33836. if (data && enableAnimation) {
  33837. data.eachItemGraphicEl(function (el) {
  33838. el.fadeOut(function () {
  33839. group.remove(el);
  33840. });
  33841. });
  33842. } else {
  33843. group.removeAll();
  33844. }
  33845. };
  33846. function makeSeriesScope(data) {
  33847. var seriesModel = data.hostModel;
  33848. return {
  33849. itemStyle: seriesModel.getModel('itemStyle').getItemStyle(['color']),
  33850. hoverItemStyle: seriesModel.getModel('emphasis.itemStyle').getItemStyle(),
  33851. symbolRotate: seriesModel.get('symbolRotate'),
  33852. symbolOffset: seriesModel.get('symbolOffset'),
  33853. hoverAnimation: seriesModel.get('hoverAnimation'),
  33854. labelModel: seriesModel.getModel('label'),
  33855. hoverLabelModel: seriesModel.getModel('emphasis.label'),
  33856. cursorStyle: seriesModel.get('cursor')
  33857. };
  33858. }
  33859. /*
  33860. * Licensed to the Apache Software Foundation (ASF) under one
  33861. * or more contributor license agreements. See the NOTICE file
  33862. * distributed with this work for additional information
  33863. * regarding copyright ownership. The ASF licenses this file
  33864. * to you under the Apache License, Version 2.0 (the
  33865. * "License"); you may not use this file except in compliance
  33866. * with the License. You may obtain a copy of the License at
  33867. *
  33868. * http://www.apache.org/licenses/LICENSE-2.0
  33869. *
  33870. * Unless required by applicable law or agreed to in writing,
  33871. * software distributed under the License is distributed on an
  33872. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33873. * KIND, either express or implied. See the License for the
  33874. * specific language governing permissions and limitations
  33875. * under the License.
  33876. */
  33877. /**
  33878. * @param {Object} coordSys
  33879. * @param {module:echarts/data/List} data
  33880. * @param {string} valueOrigin lineSeries.option.areaStyle.origin
  33881. */
  33882. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  33883. var baseAxis = coordSys.getBaseAxis();
  33884. var valueAxis = coordSys.getOtherAxis(baseAxis);
  33885. var valueStart = getValueStart(valueAxis, valueOrigin);
  33886. var baseAxisDim = baseAxis.dim;
  33887. var valueAxisDim = valueAxis.dim;
  33888. var valueDim = data.mapDimension(valueAxisDim);
  33889. var baseDim = data.mapDimension(baseAxisDim);
  33890. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  33891. var dims = map(coordSys.dimensions, function (coordDim) {
  33892. return data.mapDimension(coordDim);
  33893. });
  33894. var stacked;
  33895. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  33896. if (stacked |= isDimensionStacked(data, dims[0]
  33897. /*, dims[1]*/
  33898. )) {
  33899. // jshint ignore:line
  33900. dims[0] = stackResultDim;
  33901. }
  33902. if (stacked |= isDimensionStacked(data, dims[1]
  33903. /*, dims[0]*/
  33904. )) {
  33905. // jshint ignore:line
  33906. dims[1] = stackResultDim;
  33907. }
  33908. return {
  33909. dataDimsForPoint: dims,
  33910. valueStart: valueStart,
  33911. valueAxisDim: valueAxisDim,
  33912. baseAxisDim: baseAxisDim,
  33913. stacked: !!stacked,
  33914. valueDim: valueDim,
  33915. baseDim: baseDim,
  33916. baseDataOffset: baseDataOffset,
  33917. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  33918. };
  33919. }
  33920. function getValueStart(valueAxis, valueOrigin) {
  33921. var valueStart = 0;
  33922. var extent = valueAxis.scale.getExtent();
  33923. if (valueOrigin === 'start') {
  33924. valueStart = extent[0];
  33925. } else if (valueOrigin === 'end') {
  33926. valueStart = extent[1];
  33927. } // auto
  33928. else {
  33929. // Both positive
  33930. if (extent[0] > 0) {
  33931. valueStart = extent[0];
  33932. } // Both negative
  33933. else if (extent[1] < 0) {
  33934. valueStart = extent[1];
  33935. } // If is one positive, and one negative, onZero shall be true
  33936. }
  33937. return valueStart;
  33938. }
  33939. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  33940. var value = NaN;
  33941. if (dataCoordInfo.stacked) {
  33942. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  33943. }
  33944. if (isNaN(value)) {
  33945. value = dataCoordInfo.valueStart;
  33946. }
  33947. var baseDataOffset = dataCoordInfo.baseDataOffset;
  33948. var stackedData = [];
  33949. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  33950. stackedData[1 - baseDataOffset] = value;
  33951. return coordSys.dataToPoint(stackedData);
  33952. }
  33953. /*
  33954. * Licensed to the Apache Software Foundation (ASF) under one
  33955. * or more contributor license agreements. See the NOTICE file
  33956. * distributed with this work for additional information
  33957. * regarding copyright ownership. The ASF licenses this file
  33958. * to you under the Apache License, Version 2.0 (the
  33959. * "License"); you may not use this file except in compliance
  33960. * with the License. You may obtain a copy of the License at
  33961. *
  33962. * http://www.apache.org/licenses/LICENSE-2.0
  33963. *
  33964. * Unless required by applicable law or agreed to in writing,
  33965. * software distributed under the License is distributed on an
  33966. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33967. * KIND, either express or implied. See the License for the
  33968. * specific language governing permissions and limitations
  33969. * under the License.
  33970. */
  33971. // 'zrender/src/core/arrayDiff' has been used before, but it did
  33972. // not do well in performance when roam with fixed dataZoom window.
  33973. // function convertToIntId(newIdList, oldIdList) {
  33974. // // Generate int id instead of string id.
  33975. // // Compare string maybe slow in score function of arrDiff
  33976. // // Assume id in idList are all unique
  33977. // var idIndicesMap = {};
  33978. // var idx = 0;
  33979. // for (var i = 0; i < newIdList.length; i++) {
  33980. // idIndicesMap[newIdList[i]] = idx;
  33981. // newIdList[i] = idx++;
  33982. // }
  33983. // for (var i = 0; i < oldIdList.length; i++) {
  33984. // var oldId = oldIdList[i];
  33985. // // Same with newIdList
  33986. // if (idIndicesMap[oldId]) {
  33987. // oldIdList[i] = idIndicesMap[oldId];
  33988. // }
  33989. // else {
  33990. // oldIdList[i] = idx++;
  33991. // }
  33992. // }
  33993. // }
  33994. function diffData(oldData, newData) {
  33995. var diffResult = [];
  33996. newData.diff(oldData).add(function (idx) {
  33997. diffResult.push({
  33998. cmd: '+',
  33999. idx: idx
  34000. });
  34001. }).update(function (newIdx, oldIdx) {
  34002. diffResult.push({
  34003. cmd: '=',
  34004. idx: oldIdx,
  34005. idx1: newIdx
  34006. });
  34007. }).remove(function (idx) {
  34008. diffResult.push({
  34009. cmd: '-',
  34010. idx: idx
  34011. });
  34012. }).execute();
  34013. return diffResult;
  34014. }
  34015. var lineAnimationDiff = function (oldData, newData, oldStackedOnPoints, newStackedOnPoints, oldCoordSys, newCoordSys, oldValueOrigin, newValueOrigin) {
  34016. var diff = diffData(oldData, newData); // var newIdList = newData.mapArray(newData.getId);
  34017. // var oldIdList = oldData.mapArray(oldData.getId);
  34018. // convertToIntId(newIdList, oldIdList);
  34019. // // FIXME One data ?
  34020. // diff = arrayDiff(oldIdList, newIdList);
  34021. var currPoints = [];
  34022. var nextPoints = []; // Points for stacking base line
  34023. var currStackedPoints = [];
  34024. var nextStackedPoints = [];
  34025. var status = [];
  34026. var sortedIndices = [];
  34027. var rawIndices = [];
  34028. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  34029. var oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  34030. for (var i = 0; i < diff.length; i++) {
  34031. var diffItem = diff[i];
  34032. var pointAdded = true; // FIXME, animation is not so perfect when dataZoom window moves fast
  34033. // Which is in case remvoing or add more than one data in the tail or head
  34034. switch (diffItem.cmd) {
  34035. case '=':
  34036. var currentPt = oldData.getItemLayout(diffItem.idx);
  34037. var nextPt = newData.getItemLayout(diffItem.idx1); // If previous data is NaN, use next point directly
  34038. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  34039. currentPt = nextPt.slice();
  34040. }
  34041. currPoints.push(currentPt);
  34042. nextPoints.push(nextPt);
  34043. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  34044. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  34045. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  34046. break;
  34047. case '+':
  34048. var idx = diffItem.idx;
  34049. currPoints.push(oldCoordSys.dataToPoint([newData.get(newDataOldCoordInfo.dataDimsForPoint[0], idx), newData.get(newDataOldCoordInfo.dataDimsForPoint[1], idx)]));
  34050. nextPoints.push(newData.getItemLayout(idx).slice());
  34051. currStackedPoints.push(getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, idx));
  34052. nextStackedPoints.push(newStackedOnPoints[idx]);
  34053. rawIndices.push(newData.getRawIndex(idx));
  34054. break;
  34055. case '-':
  34056. var idx = diffItem.idx;
  34057. var rawIndex = oldData.getRawIndex(idx); // Data is replaced. In the case of dynamic data queue
  34058. // FIXME FIXME FIXME
  34059. if (rawIndex !== idx) {
  34060. currPoints.push(oldData.getItemLayout(idx));
  34061. nextPoints.push(newCoordSys.dataToPoint([oldData.get(oldDataNewCoordInfo.dataDimsForPoint[0], idx), oldData.get(oldDataNewCoordInfo.dataDimsForPoint[1], idx)]));
  34062. currStackedPoints.push(oldStackedOnPoints[idx]);
  34063. nextStackedPoints.push(getStackedOnPoint(oldDataNewCoordInfo, newCoordSys, oldData, idx));
  34064. rawIndices.push(rawIndex);
  34065. } else {
  34066. pointAdded = false;
  34067. }
  34068. } // Original indices
  34069. if (pointAdded) {
  34070. status.push(diffItem);
  34071. sortedIndices.push(sortedIndices.length);
  34072. }
  34073. } // Diff result may be crossed if all items are changed
  34074. // Sort by data index
  34075. sortedIndices.sort(function (a, b) {
  34076. return rawIndices[a] - rawIndices[b];
  34077. });
  34078. var sortedCurrPoints = [];
  34079. var sortedNextPoints = [];
  34080. var sortedCurrStackedPoints = [];
  34081. var sortedNextStackedPoints = [];
  34082. var sortedStatus = [];
  34083. for (var i = 0; i < sortedIndices.length; i++) {
  34084. var idx = sortedIndices[i];
  34085. sortedCurrPoints[i] = currPoints[idx];
  34086. sortedNextPoints[i] = nextPoints[idx];
  34087. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  34088. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  34089. sortedStatus[i] = status[idx];
  34090. }
  34091. return {
  34092. current: sortedCurrPoints,
  34093. next: sortedNextPoints,
  34094. stackedOnCurrent: sortedCurrStackedPoints,
  34095. stackedOnNext: sortedNextStackedPoints,
  34096. status: sortedStatus
  34097. };
  34098. };
  34099. /*
  34100. * Licensed to the Apache Software Foundation (ASF) under one
  34101. * or more contributor license agreements. See the NOTICE file
  34102. * distributed with this work for additional information
  34103. * regarding copyright ownership. The ASF licenses this file
  34104. * to you under the Apache License, Version 2.0 (the
  34105. * "License"); you may not use this file except in compliance
  34106. * with the License. You may obtain a copy of the License at
  34107. *
  34108. * http://www.apache.org/licenses/LICENSE-2.0
  34109. *
  34110. * Unless required by applicable law or agreed to in writing,
  34111. * software distributed under the License is distributed on an
  34112. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34113. * KIND, either express or implied. See the License for the
  34114. * specific language governing permissions and limitations
  34115. * under the License.
  34116. */
  34117. // Poly path support NaN point
  34118. var vec2Min = min;
  34119. var vec2Max = max;
  34120. var scaleAndAdd$1 = scaleAndAdd;
  34121. var v2Copy = copy; // Temporary variable
  34122. var v = [];
  34123. var cp0 = [];
  34124. var cp1 = [];
  34125. function isPointNull(p) {
  34126. return isNaN(p[0]) || isNaN(p[1]);
  34127. }
  34128. function drawSegment(ctx, points, start, segLen, allLen, dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls) {
  34129. // if (smoothMonotone == null) {
  34130. // if (isMono(points, 'x')) {
  34131. // return drawMono(ctx, points, start, segLen, allLen,
  34132. // dir, smoothMin, smoothMax, smooth, 'x', connectNulls);
  34133. // }
  34134. // else if (isMono(points, 'y')) {
  34135. // return drawMono(ctx, points, start, segLen, allLen,
  34136. // dir, smoothMin, smoothMax, smooth, 'y', connectNulls);
  34137. // }
  34138. // else {
  34139. // return drawNonMono.apply(this, arguments);
  34140. // }
  34141. // }
  34142. // else if (smoothMonotone !== 'none' && isMono(points, smoothMonotone)) {
  34143. // return drawMono.apply(this, arguments);
  34144. // }
  34145. // else {
  34146. // return drawNonMono.apply(this, arguments);
  34147. // }
  34148. if (smoothMonotone === 'none' || !smoothMonotone) {
  34149. return drawNonMono.apply(this, arguments);
  34150. } else {
  34151. return drawMono.apply(this, arguments);
  34152. }
  34153. }
  34154. /**
  34155. * Check if points is in monotone.
  34156. *
  34157. * @param {number[][]} points Array of points which is in [x, y] form
  34158. * @param {string} smoothMonotone 'x', 'y', or 'none', stating for which
  34159. * dimension that is checking.
  34160. * If is 'none', `drawNonMono` should be
  34161. * called.
  34162. * If is undefined, either being monotone
  34163. * in 'x' or 'y' will call `drawMono`.
  34164. */
  34165. // function isMono(points, smoothMonotone) {
  34166. // if (points.length <= 1) {
  34167. // return true;
  34168. // }
  34169. // var dim = smoothMonotone === 'x' ? 0 : 1;
  34170. // var last = points[0][dim];
  34171. // var lastDiff = 0;
  34172. // for (var i = 1; i < points.length; ++i) {
  34173. // var diff = points[i][dim] - last;
  34174. // if (!isNaN(diff) && !isNaN(lastDiff)
  34175. // && diff !== 0 && lastDiff !== 0
  34176. // && ((diff >= 0) !== (lastDiff >= 0))
  34177. // ) {
  34178. // return false;
  34179. // }
  34180. // if (!isNaN(diff) && diff !== 0) {
  34181. // lastDiff = diff;
  34182. // last = points[i][dim];
  34183. // }
  34184. // }
  34185. // return true;
  34186. // }
  34187. /**
  34188. * Draw smoothed line in monotone, in which only vertical or horizontal bezier
  34189. * control points will be used. This should be used when points are monotone
  34190. * either in x or y dimension.
  34191. */
  34192. function drawMono(ctx, points, start, segLen, allLen, dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls) {
  34193. var prevIdx = 0;
  34194. var idx = start;
  34195. for (var k = 0; k < segLen; k++) {
  34196. var p = points[idx];
  34197. if (idx >= allLen || idx < 0) {
  34198. break;
  34199. }
  34200. if (isPointNull(p)) {
  34201. if (connectNulls) {
  34202. idx += dir;
  34203. continue;
  34204. }
  34205. break;
  34206. }
  34207. if (idx === start) {
  34208. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  34209. } else {
  34210. if (smooth > 0) {
  34211. var prevP = points[prevIdx];
  34212. var dim = smoothMonotone === 'y' ? 1 : 0; // Length of control point to p, either in x or y, but not both
  34213. var ctrlLen = (p[dim] - prevP[dim]) * smooth;
  34214. v2Copy(cp0, prevP);
  34215. cp0[dim] = prevP[dim] + ctrlLen;
  34216. v2Copy(cp1, p);
  34217. cp1[dim] = p[dim] - ctrlLen;
  34218. ctx.bezierCurveTo(cp0[0], cp0[1], cp1[0], cp1[1], p[0], p[1]);
  34219. } else {
  34220. ctx.lineTo(p[0], p[1]);
  34221. }
  34222. }
  34223. prevIdx = idx;
  34224. idx += dir;
  34225. }
  34226. return k;
  34227. }
  34228. /**
  34229. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  34230. * situations. This should be used when points are non-monotone neither in x or
  34231. * y dimension.
  34232. */
  34233. function drawNonMono(ctx, points, start, segLen, allLen, dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls) {
  34234. var prevIdx = 0;
  34235. var idx = start;
  34236. for (var k = 0; k < segLen; k++) {
  34237. var p = points[idx];
  34238. if (idx >= allLen || idx < 0) {
  34239. break;
  34240. }
  34241. if (isPointNull(p)) {
  34242. if (connectNulls) {
  34243. idx += dir;
  34244. continue;
  34245. }
  34246. break;
  34247. }
  34248. if (idx === start) {
  34249. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  34250. v2Copy(cp0, p);
  34251. } else {
  34252. if (smooth > 0) {
  34253. var nextIdx = idx + dir;
  34254. var nextP = points[nextIdx];
  34255. if (connectNulls) {
  34256. // Find next point not null
  34257. while (nextP && isPointNull(points[nextIdx])) {
  34258. nextIdx += dir;
  34259. nextP = points[nextIdx];
  34260. }
  34261. }
  34262. var ratioNextSeg = 0.5;
  34263. var prevP = points[prevIdx];
  34264. var nextP = points[nextIdx]; // Last point
  34265. if (!nextP || isPointNull(nextP)) {
  34266. v2Copy(cp1, p);
  34267. } else {
  34268. // If next data is null in not connect case
  34269. if (isPointNull(nextP) && !connectNulls) {
  34270. nextP = p;
  34271. }
  34272. sub(v, nextP, prevP);
  34273. var lenPrevSeg;
  34274. var lenNextSeg;
  34275. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  34276. var dim = smoothMonotone === 'x' ? 0 : 1;
  34277. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  34278. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  34279. } else {
  34280. lenPrevSeg = dist(p, prevP);
  34281. lenNextSeg = dist(p, nextP);
  34282. } // Use ratio of seg length
  34283. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  34284. scaleAndAdd$1(cp1, p, v, -smooth * (1 - ratioNextSeg));
  34285. } // Smooth constraint
  34286. vec2Min(cp0, cp0, smoothMax);
  34287. vec2Max(cp0, cp0, smoothMin);
  34288. vec2Min(cp1, cp1, smoothMax);
  34289. vec2Max(cp1, cp1, smoothMin);
  34290. ctx.bezierCurveTo(cp0[0], cp0[1], cp1[0], cp1[1], p[0], p[1]); // cp0 of next segment
  34291. scaleAndAdd$1(cp0, p, v, smooth * ratioNextSeg);
  34292. } else {
  34293. ctx.lineTo(p[0], p[1]);
  34294. }
  34295. }
  34296. prevIdx = idx;
  34297. idx += dir;
  34298. }
  34299. return k;
  34300. }
  34301. function getBoundingBox(points, smoothConstraint) {
  34302. var ptMin = [Infinity, Infinity];
  34303. var ptMax = [-Infinity, -Infinity];
  34304. if (smoothConstraint) {
  34305. for (var i = 0; i < points.length; i++) {
  34306. var pt = points[i];
  34307. if (pt[0] < ptMin[0]) {
  34308. ptMin[0] = pt[0];
  34309. }
  34310. if (pt[1] < ptMin[1]) {
  34311. ptMin[1] = pt[1];
  34312. }
  34313. if (pt[0] > ptMax[0]) {
  34314. ptMax[0] = pt[0];
  34315. }
  34316. if (pt[1] > ptMax[1]) {
  34317. ptMax[1] = pt[1];
  34318. }
  34319. }
  34320. }
  34321. return {
  34322. min: smoothConstraint ? ptMin : ptMax,
  34323. max: smoothConstraint ? ptMax : ptMin
  34324. };
  34325. }
  34326. var Polyline$1 = Path.extend({
  34327. type: 'ec-polyline',
  34328. shape: {
  34329. points: [],
  34330. smooth: 0,
  34331. smoothConstraint: true,
  34332. smoothMonotone: null,
  34333. connectNulls: false
  34334. },
  34335. style: {
  34336. fill: null,
  34337. stroke: '#000'
  34338. },
  34339. brush: fixClipWithShadow(Path.prototype.brush),
  34340. buildPath: function (ctx, shape) {
  34341. var points = shape.points;
  34342. var i = 0;
  34343. var len$$1 = points.length;
  34344. var result = getBoundingBox(points, shape.smoothConstraint);
  34345. if (shape.connectNulls) {
  34346. // Must remove first and last null values avoid draw error in polygon
  34347. for (; len$$1 > 0; len$$1--) {
  34348. if (!isPointNull(points[len$$1 - 1])) {
  34349. break;
  34350. }
  34351. }
  34352. for (; i < len$$1; i++) {
  34353. if (!isPointNull(points[i])) {
  34354. break;
  34355. }
  34356. }
  34357. }
  34358. while (i < len$$1) {
  34359. i += drawSegment(ctx, points, i, len$$1, len$$1, 1, result.min, result.max, shape.smooth, shape.smoothMonotone, shape.connectNulls) + 1;
  34360. }
  34361. }
  34362. });
  34363. var Polygon$1 = Path.extend({
  34364. type: 'ec-polygon',
  34365. shape: {
  34366. points: [],
  34367. // Offset between stacked base points and points
  34368. stackedOnPoints: [],
  34369. smooth: 0,
  34370. stackedOnSmooth: 0,
  34371. smoothConstraint: true,
  34372. smoothMonotone: null,
  34373. connectNulls: false
  34374. },
  34375. brush: fixClipWithShadow(Path.prototype.brush),
  34376. buildPath: function (ctx, shape) {
  34377. var points = shape.points;
  34378. var stackedOnPoints = shape.stackedOnPoints;
  34379. var i = 0;
  34380. var len$$1 = points.length;
  34381. var smoothMonotone = shape.smoothMonotone;
  34382. var bbox = getBoundingBox(points, shape.smoothConstraint);
  34383. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  34384. if (shape.connectNulls) {
  34385. // Must remove first and last null values avoid draw error in polygon
  34386. for (; len$$1 > 0; len$$1--) {
  34387. if (!isPointNull(points[len$$1 - 1])) {
  34388. break;
  34389. }
  34390. }
  34391. for (; i < len$$1; i++) {
  34392. if (!isPointNull(points[i])) {
  34393. break;
  34394. }
  34395. }
  34396. }
  34397. while (i < len$$1) {
  34398. var k = drawSegment(ctx, points, i, len$$1, len$$1, 1, bbox.min, bbox.max, shape.smooth, smoothMonotone, shape.connectNulls);
  34399. drawSegment(ctx, stackedOnPoints, i + k - 1, k, len$$1, -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth, smoothMonotone, shape.connectNulls);
  34400. i += k + 1;
  34401. ctx.closePath();
  34402. }
  34403. }
  34404. });
  34405. /*
  34406. * Licensed to the Apache Software Foundation (ASF) under one
  34407. * or more contributor license agreements. See the NOTICE file
  34408. * distributed with this work for additional information
  34409. * regarding copyright ownership. The ASF licenses this file
  34410. * to you under the Apache License, Version 2.0 (the
  34411. * "License"); you may not use this file except in compliance
  34412. * with the License. You may obtain a copy of the License at
  34413. *
  34414. * http://www.apache.org/licenses/LICENSE-2.0
  34415. *
  34416. * Unless required by applicable law or agreed to in writing,
  34417. * software distributed under the License is distributed on an
  34418. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34419. * KIND, either express or implied. See the License for the
  34420. * specific language governing permissions and limitations
  34421. * under the License.
  34422. */
  34423. // FIXME step not support polar
  34424. function isPointsSame(points1, points2) {
  34425. if (points1.length !== points2.length) {
  34426. return;
  34427. }
  34428. for (var i = 0; i < points1.length; i++) {
  34429. var p1 = points1[i];
  34430. var p2 = points2[i];
  34431. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  34432. return;
  34433. }
  34434. }
  34435. return true;
  34436. }
  34437. function getBoundingDiff(points1, points2) {
  34438. var min1 = [];
  34439. var max1 = [];
  34440. var min2 = [];
  34441. var max2 = [];
  34442. fromPoints(points1, min1, max1);
  34443. fromPoints(points2, min2, max2); // Get a max value from each corner of two boundings.
  34444. 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]));
  34445. }
  34446. function getSmooth(smooth) {
  34447. return typeof smooth === 'number' ? smooth : smooth ? 0.5 : 0;
  34448. }
  34449. /**
  34450. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  34451. * @param {module:echarts/data/List} data
  34452. * @param {Object} dataCoordInfo
  34453. * @param {Array.<Array.<number>>} points
  34454. */
  34455. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  34456. if (!dataCoordInfo.valueDim) {
  34457. return [];
  34458. }
  34459. var points = [];
  34460. for (var idx = 0, len = data.count(); idx < len; idx++) {
  34461. points.push(getStackedOnPoint(dataCoordInfo, coordSys, data, idx));
  34462. }
  34463. return points;
  34464. }
  34465. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  34466. var baseAxis = coordSys.getBaseAxis();
  34467. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  34468. var stepPoints = [];
  34469. for (var i = 0; i < points.length - 1; i++) {
  34470. var nextPt = points[i + 1];
  34471. var pt = points[i];
  34472. stepPoints.push(pt);
  34473. var stepPt = [];
  34474. switch (stepTurnAt) {
  34475. case 'end':
  34476. stepPt[baseIndex] = nextPt[baseIndex];
  34477. stepPt[1 - baseIndex] = pt[1 - baseIndex]; // default is start
  34478. stepPoints.push(stepPt);
  34479. break;
  34480. case 'middle':
  34481. // default is start
  34482. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  34483. var stepPt2 = [];
  34484. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  34485. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  34486. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  34487. stepPoints.push(stepPt);
  34488. stepPoints.push(stepPt2);
  34489. break;
  34490. default:
  34491. stepPt[baseIndex] = pt[baseIndex];
  34492. stepPt[1 - baseIndex] = nextPt[1 - baseIndex]; // default is start
  34493. stepPoints.push(stepPt);
  34494. }
  34495. } // Last points
  34496. points[i] && stepPoints.push(points[i]);
  34497. return stepPoints;
  34498. }
  34499. function getVisualGradient(data, coordSys) {
  34500. var visualMetaList = data.getVisual('visualMeta');
  34501. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  34502. // When data.count() is 0, gradient range can not be calculated.
  34503. return;
  34504. }
  34505. if (coordSys.type !== 'cartesian2d') {
  34506. return;
  34507. }
  34508. var coordDim;
  34509. var visualMeta;
  34510. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  34511. var dimIndex = visualMetaList[i].dimension;
  34512. var dimName = data.dimensions[dimIndex];
  34513. var dimInfo = data.getDimensionInfo(dimName);
  34514. coordDim = dimInfo && dimInfo.coordDim; // Can only be x or y
  34515. if (coordDim === 'x' || coordDim === 'y') {
  34516. visualMeta = visualMetaList[i];
  34517. break;
  34518. }
  34519. }
  34520. if (!visualMeta) {
  34521. return;
  34522. } // If the area to be rendered is bigger than area defined by LinearGradient,
  34523. // the canvas spec prescribes that the color of the first stop and the last
  34524. // stop should be used. But if two stops are added at offset 0, in effect
  34525. // browsers use the color of the second stop to render area outside
  34526. // LinearGradient. So we can only infinitesimally extend area defined in
  34527. // LinearGradient to render `outerColors`.
  34528. var axis = coordSys.getAxis(coordDim); // dataToCoor mapping may not be linear, but must be monotonic.
  34529. var colorStops = map(visualMeta.stops, function (stop) {
  34530. return {
  34531. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  34532. color: stop.color
  34533. };
  34534. });
  34535. var stopLen = colorStops.length;
  34536. var outerColors = visualMeta.outerColors.slice();
  34537. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  34538. colorStops.reverse();
  34539. outerColors.reverse();
  34540. }
  34541. var tinyExtent = 10; // Arbitrary value: 10px
  34542. var minCoord = colorStops[0].coord - tinyExtent;
  34543. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  34544. var coordSpan = maxCoord - minCoord;
  34545. if (coordSpan < 1e-3) {
  34546. return 'transparent';
  34547. }
  34548. each$1(colorStops, function (stop) {
  34549. stop.offset = (stop.coord - minCoord) / coordSpan;
  34550. });
  34551. colorStops.push({
  34552. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  34553. color: outerColors[1] || 'transparent'
  34554. });
  34555. colorStops.unshift({
  34556. // notice colorStops.length have been changed.
  34557. offset: stopLen ? colorStops[0].offset : 0.5,
  34558. color: outerColors[0] || 'transparent'
  34559. }); // zrUtil.each(colorStops, function (colorStop) {
  34560. // // Make sure each offset has rounded px to avoid not sharp edge
  34561. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  34562. // });
  34563. var gradient = new LinearGradient(0, 0, 0, 0, colorStops, true);
  34564. gradient[coordDim] = minCoord;
  34565. gradient[coordDim + '2'] = maxCoord;
  34566. return gradient;
  34567. }
  34568. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  34569. var showAllSymbol = seriesModel.get('showAllSymbol');
  34570. var isAuto = showAllSymbol === 'auto';
  34571. if (showAllSymbol && !isAuto) {
  34572. return;
  34573. }
  34574. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  34575. if (!categoryAxis) {
  34576. return;
  34577. } // Note that category label interval strategy might bring some weird effect
  34578. // in some scenario: users may wonder why some of the symbols are not
  34579. // displayed. So we show all symbols as possible as we can.
  34580. if (isAuto // Simplify the logic, do not determine label overlap here.
  34581. && canShowAllSymbolForCategory(categoryAxis, data)) {
  34582. return;
  34583. } // Otherwise follow the label interval strategy on category axis.
  34584. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  34585. var labelMap = {};
  34586. each$1(categoryAxis.getViewLabels(), function (labelItem) {
  34587. labelMap[labelItem.tickValue] = 1;
  34588. });
  34589. return function (dataIndex) {
  34590. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  34591. };
  34592. }
  34593. function canShowAllSymbolForCategory(categoryAxis, data) {
  34594. // In mose cases, line is monotonous on category axis, and the label size
  34595. // is close with each other. So we check the symbol size and some of the
  34596. // label size alone with the category axis to estimate whether all symbol
  34597. // can be shown without overlap.
  34598. var axisExtent = categoryAxis.getExtent();
  34599. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  34600. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  34601. // Sampling some points, max 5.
  34602. var dataLen = data.count();
  34603. var step = Math.max(1, Math.round(dataLen / 5));
  34604. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  34605. if (SymbolClz$1.getSymbolSize(data, dataIndex // Only for cartesian, where `isHorizontal` exists.
  34606. )[categoryAxis.isHorizontal() ? 1 : 0] // Empirical number
  34607. * 1.5 > availSize) {
  34608. return false;
  34609. }
  34610. }
  34611. return true;
  34612. }
  34613. function createLineClipPath(coordSys, hasAnimation, seriesModel) {
  34614. if (coordSys.type === 'cartesian2d') {
  34615. var isHorizontal = coordSys.getBaseAxis().isHorizontal();
  34616. var clipPath = createGridClipPath(coordSys, hasAnimation, seriesModel); // Expand clip shape to avoid clipping when line value exceeds axis
  34617. if (!seriesModel.get('clip', true)) {
  34618. var rectShape = clipPath.shape;
  34619. var expandSize = Math.max(rectShape.width, rectShape.height);
  34620. if (isHorizontal) {
  34621. rectShape.y -= expandSize;
  34622. rectShape.height += expandSize * 2;
  34623. } else {
  34624. rectShape.x -= expandSize;
  34625. rectShape.width += expandSize * 2;
  34626. }
  34627. }
  34628. return clipPath;
  34629. } else {
  34630. return createPolarClipPath(coordSys, hasAnimation, seriesModel);
  34631. }
  34632. }
  34633. Chart.extend({
  34634. type: 'line',
  34635. init: function () {
  34636. var lineGroup = new Group();
  34637. var symbolDraw = new SymbolDraw();
  34638. this.group.add(symbolDraw.group);
  34639. this._symbolDraw = symbolDraw;
  34640. this._lineGroup = lineGroup;
  34641. },
  34642. render: function (seriesModel, ecModel, api) {
  34643. var coordSys = seriesModel.coordinateSystem;
  34644. var group = this.group;
  34645. var data = seriesModel.getData();
  34646. var lineStyleModel = seriesModel.getModel('lineStyle');
  34647. var areaStyleModel = seriesModel.getModel('areaStyle');
  34648. var points = data.mapArray(data.getItemLayout);
  34649. var isCoordSysPolar = coordSys.type === 'polar';
  34650. var prevCoordSys = this._coordSys;
  34651. var symbolDraw = this._symbolDraw;
  34652. var polyline = this._polyline;
  34653. var polygon = this._polygon;
  34654. var lineGroup = this._lineGroup;
  34655. var hasAnimation = seriesModel.get('animation');
  34656. var isAreaChart = !areaStyleModel.isEmpty();
  34657. var valueOrigin = areaStyleModel.get('origin');
  34658. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  34659. var stackedOnPoints = getStackedOnPoints(coordSys, data, dataCoordInfo);
  34660. var showSymbol = seriesModel.get('showSymbol');
  34661. var isIgnoreFunc = showSymbol && !isCoordSysPolar && getIsIgnoreFunc(seriesModel, data, coordSys); // Remove temporary symbols
  34662. var oldData = this._data;
  34663. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  34664. if (el.__temp) {
  34665. group.remove(el);
  34666. oldData.setItemGraphicEl(idx, null);
  34667. }
  34668. }); // Remove previous created symbols if showSymbol changed to false
  34669. if (!showSymbol) {
  34670. symbolDraw.remove();
  34671. }
  34672. group.add(lineGroup); // FIXME step not support polar
  34673. var step = !isCoordSysPolar && seriesModel.get('step');
  34674. var clipShapeForSymbol;
  34675. if (coordSys && coordSys.getArea && seriesModel.get('clip', true)) {
  34676. clipShapeForSymbol = coordSys.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
  34677. // See #7913 and `test/dataZoom-clip.html`.
  34678. if (clipShapeForSymbol.width != null) {
  34679. clipShapeForSymbol.x -= 0.1;
  34680. clipShapeForSymbol.y -= 0.1;
  34681. clipShapeForSymbol.width += 0.2;
  34682. clipShapeForSymbol.height += 0.2;
  34683. } else if (clipShapeForSymbol.r0) {
  34684. clipShapeForSymbol.r0 -= 0.5;
  34685. clipShapeForSymbol.r1 += 0.5;
  34686. }
  34687. }
  34688. this._clipShapeForSymbol = clipShapeForSymbol; // Initialization animation or coordinate system changed
  34689. if (!(polyline && prevCoordSys.type === coordSys.type && step === this._step)) {
  34690. showSymbol && symbolDraw.updateData(data, {
  34691. isIgnore: isIgnoreFunc,
  34692. clipShape: clipShapeForSymbol
  34693. });
  34694. if (step) {
  34695. // TODO If stacked series is not step
  34696. points = turnPointsIntoStep(points, coordSys, step);
  34697. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  34698. }
  34699. polyline = this._newPolyline(points, coordSys, hasAnimation);
  34700. if (isAreaChart) {
  34701. polygon = this._newPolygon(points, stackedOnPoints, coordSys, hasAnimation);
  34702. }
  34703. lineGroup.setClipPath(createLineClipPath(coordSys, true, seriesModel));
  34704. } else {
  34705. if (isAreaChart && !polygon) {
  34706. // If areaStyle is added
  34707. polygon = this._newPolygon(points, stackedOnPoints, coordSys, hasAnimation);
  34708. } else if (polygon && !isAreaChart) {
  34709. // If areaStyle is removed
  34710. lineGroup.remove(polygon);
  34711. polygon = this._polygon = null;
  34712. } // Update clipPath
  34713. lineGroup.setClipPath(createLineClipPath(coordSys, false, seriesModel)); // Always update, or it is wrong in the case turning on legend
  34714. // because points are not changed
  34715. showSymbol && symbolDraw.updateData(data, {
  34716. isIgnore: isIgnoreFunc,
  34717. clipShape: clipShapeForSymbol
  34718. }); // Stop symbol animation and sync with line points
  34719. // FIXME performance?
  34720. data.eachItemGraphicEl(function (el) {
  34721. el.stopAnimation(true);
  34722. }); // In the case data zoom triggerred refreshing frequently
  34723. // Data may not change if line has a category axis. So it should animate nothing
  34724. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints) || !isPointsSame(this._points, points)) {
  34725. if (hasAnimation) {
  34726. this._updateAnimation(data, stackedOnPoints, coordSys, api, step, valueOrigin);
  34727. } else {
  34728. // Not do it in update with animation
  34729. if (step) {
  34730. // TODO If stacked series is not step
  34731. points = turnPointsIntoStep(points, coordSys, step);
  34732. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  34733. }
  34734. polyline.setShape({
  34735. points: points
  34736. });
  34737. polygon && polygon.setShape({
  34738. points: points,
  34739. stackedOnPoints: stackedOnPoints
  34740. });
  34741. }
  34742. }
  34743. }
  34744. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  34745. polyline.useStyle(defaults( // Use color in lineStyle first
  34746. lineStyleModel.getLineStyle(), {
  34747. fill: 'none',
  34748. stroke: visualColor,
  34749. lineJoin: 'bevel'
  34750. }));
  34751. var smooth = seriesModel.get('smooth');
  34752. smooth = getSmooth(seriesModel.get('smooth'));
  34753. polyline.setShape({
  34754. smooth: smooth,
  34755. smoothMonotone: seriesModel.get('smoothMonotone'),
  34756. connectNulls: seriesModel.get('connectNulls')
  34757. });
  34758. if (polygon) {
  34759. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  34760. var stackedOnSmooth = 0;
  34761. polygon.useStyle(defaults(areaStyleModel.getAreaStyle(), {
  34762. fill: visualColor,
  34763. opacity: 0.7,
  34764. lineJoin: 'bevel'
  34765. }));
  34766. if (stackedOnSeries) {
  34767. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  34768. }
  34769. polygon.setShape({
  34770. smooth: smooth,
  34771. stackedOnSmooth: stackedOnSmooth,
  34772. smoothMonotone: seriesModel.get('smoothMonotone'),
  34773. connectNulls: seriesModel.get('connectNulls')
  34774. });
  34775. }
  34776. this._data = data; // Save the coordinate system for transition animation when data changed
  34777. this._coordSys = coordSys;
  34778. this._stackedOnPoints = stackedOnPoints;
  34779. this._points = points;
  34780. this._step = step;
  34781. this._valueOrigin = valueOrigin;
  34782. },
  34783. dispose: function () {},
  34784. highlight: function (seriesModel, ecModel, api, payload) {
  34785. var data = seriesModel.getData();
  34786. var dataIndex = queryDataIndex(data, payload);
  34787. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  34788. var symbol = data.getItemGraphicEl(dataIndex);
  34789. if (!symbol) {
  34790. // Create a temporary symbol if it is not exists
  34791. var pt = data.getItemLayout(dataIndex);
  34792. if (!pt) {
  34793. // Null data
  34794. return;
  34795. } // fix #11360: should't draw symbol outside clipShapeForSymbol
  34796. if (this._clipShapeForSymbol && !this._clipShapeForSymbol.contain(pt[0], pt[1])) {
  34797. return;
  34798. }
  34799. symbol = new SymbolClz$1(data, dataIndex);
  34800. symbol.position = pt;
  34801. symbol.setZ(seriesModel.get('zlevel'), seriesModel.get('z'));
  34802. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  34803. symbol.__temp = true;
  34804. data.setItemGraphicEl(dataIndex, symbol); // Stop scale animation
  34805. symbol.stopSymbolAnimation(true);
  34806. this.group.add(symbol);
  34807. }
  34808. symbol.highlight();
  34809. } else {
  34810. // Highlight whole series
  34811. Chart.prototype.highlight.call(this, seriesModel, ecModel, api, payload);
  34812. }
  34813. },
  34814. downplay: function (seriesModel, ecModel, api, payload) {
  34815. var data = seriesModel.getData();
  34816. var dataIndex = queryDataIndex(data, payload);
  34817. if (dataIndex != null && dataIndex >= 0) {
  34818. var symbol = data.getItemGraphicEl(dataIndex);
  34819. if (symbol) {
  34820. if (symbol.__temp) {
  34821. data.setItemGraphicEl(dataIndex, null);
  34822. this.group.remove(symbol);
  34823. } else {
  34824. symbol.downplay();
  34825. }
  34826. }
  34827. } else {
  34828. // FIXME
  34829. // can not downplay completely.
  34830. // Downplay whole series
  34831. Chart.prototype.downplay.call(this, seriesModel, ecModel, api, payload);
  34832. }
  34833. },
  34834. /**
  34835. * @param {module:zrender/container/Group} group
  34836. * @param {Array.<Array.<number>>} points
  34837. * @private
  34838. */
  34839. _newPolyline: function (points) {
  34840. var polyline = this._polyline; // Remove previous created polyline
  34841. if (polyline) {
  34842. this._lineGroup.remove(polyline);
  34843. }
  34844. polyline = new Polyline$1({
  34845. shape: {
  34846. points: points
  34847. },
  34848. silent: true,
  34849. z2: 10
  34850. });
  34851. this._lineGroup.add(polyline);
  34852. this._polyline = polyline;
  34853. return polyline;
  34854. },
  34855. /**
  34856. * @param {module:zrender/container/Group} group
  34857. * @param {Array.<Array.<number>>} stackedOnPoints
  34858. * @param {Array.<Array.<number>>} points
  34859. * @private
  34860. */
  34861. _newPolygon: function (points, stackedOnPoints) {
  34862. var polygon = this._polygon; // Remove previous created polygon
  34863. if (polygon) {
  34864. this._lineGroup.remove(polygon);
  34865. }
  34866. polygon = new Polygon$1({
  34867. shape: {
  34868. points: points,
  34869. stackedOnPoints: stackedOnPoints
  34870. },
  34871. silent: true
  34872. });
  34873. this._lineGroup.add(polygon);
  34874. this._polygon = polygon;
  34875. return polygon;
  34876. },
  34877. /**
  34878. * @private
  34879. */
  34880. // FIXME Two value axis
  34881. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step, valueOrigin) {
  34882. var polyline = this._polyline;
  34883. var polygon = this._polygon;
  34884. var seriesModel = data.hostModel;
  34885. var diff = lineAnimationDiff(this._data, data, this._stackedOnPoints, stackedOnPoints, this._coordSys, coordSys, this._valueOrigin, valueOrigin);
  34886. var current = diff.current;
  34887. var stackedOnCurrent = diff.stackedOnCurrent;
  34888. var next = diff.next;
  34889. var stackedOnNext = diff.stackedOnNext;
  34890. if (step) {
  34891. // TODO If stacked series is not step
  34892. current = turnPointsIntoStep(diff.current, coordSys, step);
  34893. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  34894. next = turnPointsIntoStep(diff.next, coordSys, step);
  34895. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  34896. } // Don't apply animation if diff is large.
  34897. // For better result and avoid memory explosion problems like
  34898. // https://github.com/apache/incubator-echarts/issues/12229
  34899. if (getBoundingDiff(current, next) > 3000 || polygon && getBoundingDiff(stackedOnCurrent, stackedOnNext) > 3000) {
  34900. polyline.setShape({
  34901. points: next
  34902. });
  34903. if (polygon) {
  34904. polygon.setShape({
  34905. points: next,
  34906. stackedOnPoints: stackedOnNext
  34907. });
  34908. }
  34909. return;
  34910. } // `diff.current` is subset of `current` (which should be ensured by
  34911. // turnPointsIntoStep), so points in `__points` can be updated when
  34912. // points in `current` are update during animation.
  34913. polyline.shape.__points = diff.current;
  34914. polyline.shape.points = current;
  34915. updateProps(polyline, {
  34916. shape: {
  34917. points: next
  34918. }
  34919. }, seriesModel);
  34920. if (polygon) {
  34921. polygon.setShape({
  34922. points: current,
  34923. stackedOnPoints: stackedOnCurrent
  34924. });
  34925. updateProps(polygon, {
  34926. shape: {
  34927. points: next,
  34928. stackedOnPoints: stackedOnNext
  34929. }
  34930. }, seriesModel);
  34931. }
  34932. var updatedDataInfo = [];
  34933. var diffStatus = diff.status;
  34934. for (var i = 0; i < diffStatus.length; i++) {
  34935. var cmd = diffStatus[i].cmd;
  34936. if (cmd === '=') {
  34937. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  34938. if (el) {
  34939. updatedDataInfo.push({
  34940. el: el,
  34941. ptIdx: i // Index of points
  34942. });
  34943. }
  34944. }
  34945. }
  34946. if (polyline.animators && polyline.animators.length) {
  34947. polyline.animators[0].during(function () {
  34948. for (var i = 0; i < updatedDataInfo.length; i++) {
  34949. var el = updatedDataInfo[i].el;
  34950. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  34951. }
  34952. });
  34953. }
  34954. },
  34955. remove: function (ecModel) {
  34956. var group = this.group;
  34957. var oldData = this._data;
  34958. this._lineGroup.removeAll();
  34959. this._symbolDraw.remove(true); // Remove temporary created elements when highlighting
  34960. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  34961. if (el.__temp) {
  34962. group.remove(el);
  34963. oldData.setItemGraphicEl(idx, null);
  34964. }
  34965. });
  34966. this._polyline = this._polygon = this._coordSys = this._points = this._stackedOnPoints = this._data = null;
  34967. }
  34968. });
  34969. /*
  34970. * Licensed to the Apache Software Foundation (ASF) under one
  34971. * or more contributor license agreements. See the NOTICE file
  34972. * distributed with this work for additional information
  34973. * regarding copyright ownership. The ASF licenses this file
  34974. * to you under the Apache License, Version 2.0 (the
  34975. * "License"); you may not use this file except in compliance
  34976. * with the License. You may obtain a copy of the License at
  34977. *
  34978. * http://www.apache.org/licenses/LICENSE-2.0
  34979. *
  34980. * Unless required by applicable law or agreed to in writing,
  34981. * software distributed under the License is distributed on an
  34982. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34983. * KIND, either express or implied. See the License for the
  34984. * specific language governing permissions and limitations
  34985. * under the License.
  34986. */
  34987. var visualSymbol = function (seriesType, defaultSymbolType, legendSymbol) {
  34988. // Encoding visual for all series include which is filtered for legend drawing
  34989. return {
  34990. seriesType: seriesType,
  34991. // For legend.
  34992. performRawSeries: true,
  34993. reset: function (seriesModel, ecModel, api) {
  34994. var data = seriesModel.getData();
  34995. var symbolType = seriesModel.get('symbol');
  34996. var symbolSize = seriesModel.get('symbolSize');
  34997. var keepAspect = seriesModel.get('symbolKeepAspect');
  34998. var symbolRotate = seriesModel.get('symbolRotate');
  34999. var hasSymbolTypeCallback = isFunction$1(symbolType);
  35000. var hasSymbolSizeCallback = isFunction$1(symbolSize);
  35001. var hasSymbolRotateCallback = isFunction$1(symbolRotate);
  35002. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback || hasSymbolRotateCallback;
  35003. var seriesSymbol = !hasSymbolTypeCallback && symbolType ? symbolType : defaultSymbolType;
  35004. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  35005. data.setVisual({
  35006. legendSymbol: legendSymbol || seriesSymbol,
  35007. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  35008. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  35009. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  35010. // some cases but generally it is not recommanded.
  35011. symbol: seriesSymbol,
  35012. symbolSize: seriesSymbolSize,
  35013. symbolKeepAspect: keepAspect,
  35014. symbolRotate: symbolRotate
  35015. }); // Only visible series has each data be visual encoded
  35016. if (ecModel.isSeriesFiltered(seriesModel)) {
  35017. return;
  35018. }
  35019. function dataEach(data, idx) {
  35020. if (hasCallback) {
  35021. var rawValue = seriesModel.getRawValue(idx);
  35022. var params = seriesModel.getDataParams(idx);
  35023. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  35024. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  35025. hasSymbolRotateCallback && data.setItemVisual(idx, 'symbolRotate', symbolRotate(rawValue, params));
  35026. }
  35027. if (data.hasItemOption) {
  35028. var itemModel = data.getItemModel(idx);
  35029. var itemSymbolType = itemModel.getShallow('symbol', true);
  35030. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  35031. var itemSymbolRotate = itemModel.getShallow('symbolRotate', true);
  35032. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true); // If has item symbol
  35033. if (itemSymbolType != null) {
  35034. data.setItemVisual(idx, 'symbol', itemSymbolType);
  35035. }
  35036. if (itemSymbolSize != null) {
  35037. // PENDING Transform symbolSize ?
  35038. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  35039. }
  35040. if (itemSymbolRotate != null) {
  35041. data.setItemVisual(idx, 'symbolRotate', itemSymbolRotate);
  35042. }
  35043. if (itemSymbolKeepAspect != null) {
  35044. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  35045. }
  35046. }
  35047. }
  35048. return {
  35049. dataEach: data.hasItemOption || hasCallback ? dataEach : null
  35050. };
  35051. }
  35052. };
  35053. };
  35054. /*
  35055. * Licensed to the Apache Software Foundation (ASF) under one
  35056. * or more contributor license agreements. See the NOTICE file
  35057. * distributed with this work for additional information
  35058. * regarding copyright ownership. The ASF licenses this file
  35059. * to you under the Apache License, Version 2.0 (the
  35060. * "License"); you may not use this file except in compliance
  35061. * with the License. You may obtain a copy of the License at
  35062. *
  35063. * http://www.apache.org/licenses/LICENSE-2.0
  35064. *
  35065. * Unless required by applicable law or agreed to in writing,
  35066. * software distributed under the License is distributed on an
  35067. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35068. * KIND, either express or implied. See the License for the
  35069. * specific language governing permissions and limitations
  35070. * under the License.
  35071. */
  35072. /* global Float32Array */
  35073. var layoutPoints = function (seriesType) {
  35074. return {
  35075. seriesType: seriesType,
  35076. plan: createRenderPlanner(),
  35077. reset: function (seriesModel) {
  35078. var data = seriesModel.getData();
  35079. var coordSys = seriesModel.coordinateSystem;
  35080. var pipelineContext = seriesModel.pipelineContext;
  35081. var isLargeRender = pipelineContext.large;
  35082. if (!coordSys) {
  35083. return;
  35084. }
  35085. var dims = map(coordSys.dimensions, function (dim) {
  35086. return data.mapDimension(dim);
  35087. }).slice(0, 2);
  35088. var dimLen = dims.length;
  35089. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  35090. if (isDimensionStacked(data, dims[0]
  35091. /*, dims[1]*/
  35092. )) {
  35093. dims[0] = stackResultDim;
  35094. }
  35095. if (isDimensionStacked(data, dims[1]
  35096. /*, dims[0]*/
  35097. )) {
  35098. dims[1] = stackResultDim;
  35099. }
  35100. function progress(params, data) {
  35101. var segCount = params.end - params.start;
  35102. var points = isLargeRender && new Float32Array(segCount * dimLen);
  35103. for (var i = params.start, offset = 0, tmpIn = [], tmpOut = []; i < params.end; i++) {
  35104. var point;
  35105. if (dimLen === 1) {
  35106. var x = data.get(dims[0], i);
  35107. point = !isNaN(x) && coordSys.dataToPoint(x, null, tmpOut);
  35108. } else {
  35109. var x = tmpIn[0] = data.get(dims[0], i);
  35110. var y = tmpIn[1] = data.get(dims[1], i); // Also {Array.<number>}, not undefined to avoid if...else... statement
  35111. point = !isNaN(x) && !isNaN(y) && coordSys.dataToPoint(tmpIn, null, tmpOut);
  35112. }
  35113. if (isLargeRender) {
  35114. points[offset++] = point ? point[0] : NaN;
  35115. points[offset++] = point ? point[1] : NaN;
  35116. } else {
  35117. data.setItemLayout(i, point && point.slice() || [NaN, NaN]);
  35118. }
  35119. }
  35120. isLargeRender && data.setLayout('symbolPoints', points);
  35121. }
  35122. return dimLen && {
  35123. progress: progress
  35124. };
  35125. }
  35126. };
  35127. };
  35128. /*
  35129. * Licensed to the Apache Software Foundation (ASF) under one
  35130. * or more contributor license agreements. See the NOTICE file
  35131. * distributed with this work for additional information
  35132. * regarding copyright ownership. The ASF licenses this file
  35133. * to you under the Apache License, Version 2.0 (the
  35134. * "License"); you may not use this file except in compliance
  35135. * with the License. You may obtain a copy of the License at
  35136. *
  35137. * http://www.apache.org/licenses/LICENSE-2.0
  35138. *
  35139. * Unless required by applicable law or agreed to in writing,
  35140. * software distributed under the License is distributed on an
  35141. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35142. * KIND, either express or implied. See the License for the
  35143. * specific language governing permissions and limitations
  35144. * under the License.
  35145. */
  35146. var samplers = {
  35147. average: function (frame) {
  35148. var sum = 0;
  35149. var count = 0;
  35150. for (var i = 0; i < frame.length; i++) {
  35151. if (!isNaN(frame[i])) {
  35152. sum += frame[i];
  35153. count++;
  35154. }
  35155. } // Return NaN if count is 0
  35156. return count === 0 ? NaN : sum / count;
  35157. },
  35158. sum: function (frame) {
  35159. var sum = 0;
  35160. for (var i = 0; i < frame.length; i++) {
  35161. // Ignore NaN
  35162. sum += frame[i] || 0;
  35163. }
  35164. return sum;
  35165. },
  35166. max: function (frame) {
  35167. var max = -Infinity;
  35168. for (var i = 0; i < frame.length; i++) {
  35169. frame[i] > max && (max = frame[i]);
  35170. } // NaN will cause illegal axis extent.
  35171. return isFinite(max) ? max : NaN;
  35172. },
  35173. min: function (frame) {
  35174. var min = Infinity;
  35175. for (var i = 0; i < frame.length; i++) {
  35176. frame[i] < min && (min = frame[i]);
  35177. } // NaN will cause illegal axis extent.
  35178. return isFinite(min) ? min : NaN;
  35179. },
  35180. // TODO
  35181. // Median
  35182. nearest: function (frame) {
  35183. return frame[0];
  35184. }
  35185. };
  35186. var indexSampler = function (frame, value) {
  35187. return Math.round(frame.length / 2);
  35188. };
  35189. var dataSample = function (seriesType) {
  35190. return {
  35191. seriesType: seriesType,
  35192. modifyOutputEnd: true,
  35193. reset: function (seriesModel, ecModel, api) {
  35194. var data = seriesModel.getData();
  35195. var sampling = seriesModel.get('sampling');
  35196. var coordSys = seriesModel.coordinateSystem; // Only cartesian2d support down sampling
  35197. if (coordSys.type === 'cartesian2d' && sampling) {
  35198. var baseAxis = coordSys.getBaseAxis();
  35199. var valueAxis = coordSys.getOtherAxis(baseAxis);
  35200. var extent = baseAxis.getExtent(); // Coordinste system has been resized
  35201. var size = extent[1] - extent[0];
  35202. var rate = Math.round(data.count() / size);
  35203. if (rate > 1) {
  35204. var sampler;
  35205. if (typeof sampling === 'string') {
  35206. sampler = samplers[sampling];
  35207. } else if (typeof sampling === 'function') {
  35208. sampler = sampling;
  35209. }
  35210. if (sampler) {
  35211. // Only support sample the first dim mapped from value axis.
  35212. seriesModel.setData(data.downSample(data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler));
  35213. }
  35214. }
  35215. }
  35216. }
  35217. };
  35218. };
  35219. /*
  35220. * Licensed to the Apache Software Foundation (ASF) under one
  35221. * or more contributor license agreements. See the NOTICE file
  35222. * distributed with this work for additional information
  35223. * regarding copyright ownership. The ASF licenses this file
  35224. * to you under the Apache License, Version 2.0 (the
  35225. * "License"); you may not use this file except in compliance
  35226. * with the License. You may obtain a copy of the License at
  35227. *
  35228. * http://www.apache.org/licenses/LICENSE-2.0
  35229. *
  35230. * Unless required by applicable law or agreed to in writing,
  35231. * software distributed under the License is distributed on an
  35232. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35233. * KIND, either express or implied. See the License for the
  35234. * specific language governing permissions and limitations
  35235. * under the License.
  35236. */
  35237. registerVisual(visualSymbol('line', 'circle', 'line'));
  35238. registerLayout(layoutPoints('line')); // Down sample after filter
  35239. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, dataSample('line'));
  35240. /*
  35241. * Licensed to the Apache Software Foundation (ASF) under one
  35242. * or more contributor license agreements. See the NOTICE file
  35243. * distributed with this work for additional information
  35244. * regarding copyright ownership. The ASF licenses this file
  35245. * to you under the Apache License, Version 2.0 (the
  35246. * "License"); you may not use this file except in compliance
  35247. * with the License. You may obtain a copy of the License at
  35248. *
  35249. * http://www.apache.org/licenses/LICENSE-2.0
  35250. *
  35251. * Unless required by applicable law or agreed to in writing,
  35252. * software distributed under the License is distributed on an
  35253. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35254. * KIND, either express or implied. See the License for the
  35255. * specific language governing permissions and limitations
  35256. * under the License.
  35257. */
  35258. /**
  35259. * [Usage]:
  35260. * (1)
  35261. * createListSimply(seriesModel, ['value']);
  35262. * (2)
  35263. * createListSimply(seriesModel, {
  35264. * coordDimensions: ['value'],
  35265. * dimensionsCount: 5
  35266. * });
  35267. *
  35268. * @param {module:echarts/model/Series} seriesModel
  35269. * @param {Object|Array.<string|Object>} opt opt or coordDimensions
  35270. * The options in opt, see `echarts/data/helper/createDimensions`
  35271. * @param {Array.<string>} [nameList]
  35272. * @return {module:echarts/data/List}
  35273. */
  35274. var createListSimply = function (seriesModel, opt, nameList) {
  35275. opt = isArray(opt) && {
  35276. coordDimensions: opt
  35277. } || extend({}, opt);
  35278. var source = seriesModel.getSource();
  35279. var dimensionsInfo = createDimensions(source, opt);
  35280. var list = new List(dimensionsInfo, seriesModel);
  35281. list.initData(source, nameList);
  35282. return list;
  35283. };
  35284. /*
  35285. * Licensed to the Apache Software Foundation (ASF) under one
  35286. * or more contributor license agreements. See the NOTICE file
  35287. * distributed with this work for additional information
  35288. * regarding copyright ownership. The ASF licenses this file
  35289. * to you under the Apache License, Version 2.0 (the
  35290. * "License"); you may not use this file except in compliance
  35291. * with the License. You may obtain a copy of the License at
  35292. *
  35293. * http://www.apache.org/licenses/LICENSE-2.0
  35294. *
  35295. * Unless required by applicable law or agreed to in writing,
  35296. * software distributed under the License is distributed on an
  35297. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35298. * KIND, either express or implied. See the License for the
  35299. * specific language governing permissions and limitations
  35300. * under the License.
  35301. */
  35302. /**
  35303. * Data selectable mixin for chart series.
  35304. * To eanble data select, option of series must have `selectedMode`.
  35305. * And each data item will use `selected` to toggle itself selected status
  35306. */
  35307. var dataSelectableMixin = {
  35308. /**
  35309. * @param {Array.<Object>} targetList [{name, value, selected}, ...]
  35310. * If targetList is an array, it should like [{name: ..., value: ...}, ...].
  35311. * If targetList is a "List", it must have coordDim: 'value' dimension and name.
  35312. */
  35313. updateSelectedMap: function (targetList) {
  35314. this._targetList = isArray(targetList) ? targetList.slice() : [];
  35315. this._selectTargetMap = reduce(targetList || [], function (targetMap, target) {
  35316. targetMap.set(target.name, target);
  35317. return targetMap;
  35318. }, createHashMap());
  35319. },
  35320. /**
  35321. * Either name or id should be passed as input here.
  35322. * If both of them are defined, id is used.
  35323. *
  35324. * @param {string|undefined} name name of data
  35325. * @param {number|undefined} id dataIndex of data
  35326. */
  35327. // PENGING If selectedMode is null ?
  35328. select: function (name, id) {
  35329. var target = id != null ? this._targetList[id] : this._selectTargetMap.get(name);
  35330. var selectedMode = this.get('selectedMode');
  35331. if (selectedMode === 'single') {
  35332. this._selectTargetMap.each(function (target) {
  35333. target.selected = false;
  35334. });
  35335. }
  35336. target && (target.selected = true);
  35337. },
  35338. /**
  35339. * Either name or id should be passed as input here.
  35340. * If both of them are defined, id is used.
  35341. *
  35342. * @param {string|undefined} name name of data
  35343. * @param {number|undefined} id dataIndex of data
  35344. */
  35345. unSelect: function (name, id) {
  35346. var target = id != null ? this._targetList[id] : this._selectTargetMap.get(name); // var selectedMode = this.get('selectedMode');
  35347. // selectedMode !== 'single' && target && (target.selected = false);
  35348. target && (target.selected = false);
  35349. },
  35350. /**
  35351. * Either name or id should be passed as input here.
  35352. * If both of them are defined, id is used.
  35353. *
  35354. * @param {string|undefined} name name of data
  35355. * @param {number|undefined} id dataIndex of data
  35356. */
  35357. toggleSelected: function (name, id) {
  35358. var target = id != null ? this._targetList[id] : this._selectTargetMap.get(name);
  35359. if (target != null) {
  35360. this[target.selected ? 'unSelect' : 'select'](name, id);
  35361. return target.selected;
  35362. }
  35363. },
  35364. /**
  35365. * Either name or id should be passed as input here.
  35366. * If both of them are defined, id is used.
  35367. *
  35368. * @param {string|undefined} name name of data
  35369. * @param {number|undefined} id dataIndex of data
  35370. */
  35371. isSelected: function (name, id) {
  35372. var target = id != null ? this._targetList[id] : this._selectTargetMap.get(name);
  35373. return target && target.selected;
  35374. }
  35375. };
  35376. /*
  35377. * Licensed to the Apache Software Foundation (ASF) under one
  35378. * or more contributor license agreements. See the NOTICE file
  35379. * distributed with this work for additional information
  35380. * regarding copyright ownership. The ASF licenses this file
  35381. * to you under the Apache License, Version 2.0 (the
  35382. * "License"); you may not use this file except in compliance
  35383. * with the License. You may obtain a copy of the License at
  35384. *
  35385. * http://www.apache.org/licenses/LICENSE-2.0
  35386. *
  35387. * Unless required by applicable law or agreed to in writing,
  35388. * software distributed under the License is distributed on an
  35389. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35390. * KIND, either express or implied. See the License for the
  35391. * specific language governing permissions and limitations
  35392. * under the License.
  35393. */
  35394. /**
  35395. * LegendVisualProvider is an bridge that pick encoded color from data and
  35396. * provide to the legend component.
  35397. * @param {Function} getDataWithEncodedVisual Function to get data after filtered. It stores all the encoding info
  35398. * @param {Function} getRawData Function to get raw data before filtered.
  35399. */
  35400. function LegendVisualProvider(getDataWithEncodedVisual, getRawData) {
  35401. this.getAllNames = function () {
  35402. var rawData = getRawData(); // We find the name from the raw data. In case it's filtered by the legend component.
  35403. // Normally, the name can be found in rawData, but can't be found in filtered data will display as gray.
  35404. return rawData.mapArray(rawData.getName);
  35405. };
  35406. this.containName = function (name) {
  35407. var rawData = getRawData();
  35408. return rawData.indexOfName(name) >= 0;
  35409. };
  35410. this.indexOfName = function (name) {
  35411. // Only get data when necessary.
  35412. // Because LegendVisualProvider constructor may be new in the stage that data is not prepared yet.
  35413. // Invoking Series#getData immediately will throw an error.
  35414. var dataWithEncodedVisual = getDataWithEncodedVisual();
  35415. return dataWithEncodedVisual.indexOfName(name);
  35416. };
  35417. this.getItemVisual = function (dataIndex, key) {
  35418. // Get encoded visual properties from final filtered data.
  35419. var dataWithEncodedVisual = getDataWithEncodedVisual();
  35420. return dataWithEncodedVisual.getItemVisual(dataIndex, key);
  35421. };
  35422. }
  35423. /*
  35424. * Licensed to the Apache Software Foundation (ASF) under one
  35425. * or more contributor license agreements. See the NOTICE file
  35426. * distributed with this work for additional information
  35427. * regarding copyright ownership. The ASF licenses this file
  35428. * to you under the Apache License, Version 2.0 (the
  35429. * "License"); you may not use this file except in compliance
  35430. * with the License. You may obtain a copy of the License at
  35431. *
  35432. * http://www.apache.org/licenses/LICENSE-2.0
  35433. *
  35434. * Unless required by applicable law or agreed to in writing,
  35435. * software distributed under the License is distributed on an
  35436. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35437. * KIND, either express or implied. See the License for the
  35438. * specific language governing permissions and limitations
  35439. * under the License.
  35440. */
  35441. var PieSeries = extendSeriesModel({
  35442. type: 'series.pie',
  35443. // Overwrite
  35444. init: function (option) {
  35445. PieSeries.superApply(this, 'init', arguments); // Enable legend selection for each data item
  35446. // Use a function instead of direct access because data reference may changed
  35447. this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
  35448. this.updateSelectedMap(this._createSelectableList());
  35449. this._defaultLabelLine(option);
  35450. },
  35451. // Overwrite
  35452. mergeOption: function (newOption) {
  35453. PieSeries.superCall(this, 'mergeOption', newOption);
  35454. this.updateSelectedMap(this._createSelectableList());
  35455. },
  35456. getInitialData: function (option, ecModel) {
  35457. return createListSimply(this, {
  35458. coordDimensions: ['value'],
  35459. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  35460. });
  35461. },
  35462. _createSelectableList: function () {
  35463. var data = this.getRawData();
  35464. var valueDim = data.mapDimension('value');
  35465. var targetList = [];
  35466. for (var i = 0, len = data.count(); i < len; i++) {
  35467. targetList.push({
  35468. name: data.getName(i),
  35469. value: data.get(valueDim, i),
  35470. selected: retrieveRawAttr(data, i, 'selected')
  35471. });
  35472. }
  35473. return targetList;
  35474. },
  35475. // Overwrite
  35476. getDataParams: function (dataIndex) {
  35477. var data = this.getData();
  35478. var params = PieSeries.superCall(this, 'getDataParams', dataIndex); // FIXME toFixed?
  35479. var valueList = [];
  35480. data.each(data.mapDimension('value'), function (value) {
  35481. valueList.push(value);
  35482. });
  35483. params.percent = getPercentWithPrecision(valueList, dataIndex, data.hostModel.get('percentPrecision'));
  35484. params.$vars.push('percent');
  35485. return params;
  35486. },
  35487. _defaultLabelLine: function (option) {
  35488. // Extend labelLine emphasis
  35489. defaultEmphasis(option, 'labelLine', ['show']);
  35490. var labelLineNormalOpt = option.labelLine;
  35491. var labelLineEmphasisOpt = option.emphasis.labelLine; // Not show label line if `label.normal.show = false`
  35492. labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
  35493. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
  35494. },
  35495. defaultOption: {
  35496. zlevel: 0,
  35497. z: 2,
  35498. legendHoverLink: true,
  35499. hoverAnimation: true,
  35500. // 默认全局居中
  35501. center: ['50%', '50%'],
  35502. radius: [0, '75%'],
  35503. // 默认顺时针
  35504. clockwise: true,
  35505. startAngle: 90,
  35506. // 最小角度改为0
  35507. minAngle: 0,
  35508. // If the angle of a sector less than `minShowLabelAngle`,
  35509. // the label will not be displayed.
  35510. minShowLabelAngle: 0,
  35511. // 选中时扇区偏移量
  35512. selectedOffset: 10,
  35513. // 高亮扇区偏移量
  35514. hoverOffset: 10,
  35515. // If use strategy to avoid label overlapping
  35516. avoidLabelOverlap: true,
  35517. // 选择模式,默认关闭,可选single,multiple
  35518. // selectedMode: false,
  35519. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  35520. // roseType: null,
  35521. percentPrecision: 2,
  35522. // If still show when all data zero.
  35523. stillShowZeroSum: true,
  35524. // cursor: null,
  35525. left: 0,
  35526. top: 0,
  35527. right: 0,
  35528. bottom: 0,
  35529. width: null,
  35530. height: null,
  35531. label: {
  35532. // If rotate around circle
  35533. rotate: false,
  35534. show: true,
  35535. // 'outer', 'inside', 'center'
  35536. position: 'outer',
  35537. // 'none', 'labelLine', 'edge'. Works only when position is 'outer'
  35538. alignTo: 'none',
  35539. // Closest distance between label and chart edge.
  35540. // Works only position is 'outer' and alignTo is 'edge'.
  35541. margin: '25%',
  35542. // Works only position is 'outer' and alignTo is not 'edge'.
  35543. bleedMargin: 10,
  35544. // Distance between text and label line.
  35545. distanceToLabelLine: 5 // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  35546. // 默认使用全局文本样式,详见TEXTSTYLE
  35547. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  35548. },
  35549. // Enabled when label.normal.position is 'outer'
  35550. labelLine: {
  35551. show: true,
  35552. // 引导线两段中的第一段长度
  35553. length: 15,
  35554. // 引导线两段中的第二段长度
  35555. length2: 15,
  35556. smooth: false,
  35557. lineStyle: {
  35558. // color: 各异,
  35559. width: 1,
  35560. type: 'solid'
  35561. }
  35562. },
  35563. itemStyle: {
  35564. borderWidth: 1
  35565. },
  35566. // Animation type. Valid values: expansion, scale
  35567. animationType: 'expansion',
  35568. // Animation type when update. Valid values: transition, expansion
  35569. animationTypeUpdate: 'transition',
  35570. animationEasing: 'cubicOut'
  35571. }
  35572. });
  35573. mixin(PieSeries, dataSelectableMixin);
  35574. /*
  35575. * Licensed to the Apache Software Foundation (ASF) under one
  35576. * or more contributor license agreements. See the NOTICE file
  35577. * distributed with this work for additional information
  35578. * regarding copyright ownership. The ASF licenses this file
  35579. * to you under the Apache License, Version 2.0 (the
  35580. * "License"); you may not use this file except in compliance
  35581. * with the License. You may obtain a copy of the License at
  35582. *
  35583. * http://www.apache.org/licenses/LICENSE-2.0
  35584. *
  35585. * Unless required by applicable law or agreed to in writing,
  35586. * software distributed under the License is distributed on an
  35587. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35588. * KIND, either express or implied. See the License for the
  35589. * specific language governing permissions and limitations
  35590. * under the License.
  35591. */
  35592. /**
  35593. * @param {module:echarts/model/Series} seriesModel
  35594. * @param {boolean} hasAnimation
  35595. * @inner
  35596. */
  35597. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  35598. var data = seriesModel.getData();
  35599. var dataIndex = this.dataIndex;
  35600. var name = data.getName(dataIndex);
  35601. var selectedOffset = seriesModel.get('selectedOffset');
  35602. api.dispatchAction({
  35603. type: 'pieToggleSelect',
  35604. from: uid,
  35605. name: name,
  35606. seriesId: seriesModel.id
  35607. });
  35608. data.each(function (idx) {
  35609. toggleItemSelected(data.getItemGraphicEl(idx), data.getItemLayout(idx), seriesModel.isSelected(data.getName(idx)), selectedOffset, hasAnimation);
  35610. });
  35611. }
  35612. /**
  35613. * @param {module:zrender/graphic/Sector} el
  35614. * @param {Object} layout
  35615. * @param {boolean} isSelected
  35616. * @param {number} selectedOffset
  35617. * @param {boolean} hasAnimation
  35618. * @inner
  35619. */
  35620. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  35621. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  35622. var dx = Math.cos(midAngle);
  35623. var dy = Math.sin(midAngle);
  35624. var offset = isSelected ? selectedOffset : 0;
  35625. var position = [dx * offset, dy * offset];
  35626. hasAnimation // animateTo will stop revious animation like update transition
  35627. ? el.animate().when(200, {
  35628. position: position
  35629. }).start('bounceOut') : el.attr('position', position);
  35630. }
  35631. /**
  35632. * Piece of pie including Sector, Label, LabelLine
  35633. * @constructor
  35634. * @extends {module:zrender/graphic/Group}
  35635. */
  35636. function PiePiece(data, idx) {
  35637. Group.call(this);
  35638. var sector = new Sector({
  35639. z2: 2
  35640. });
  35641. var polyline = new Polyline();
  35642. var text = new Text();
  35643. this.add(sector);
  35644. this.add(polyline);
  35645. this.add(text);
  35646. this.updateData(data, idx, true);
  35647. }
  35648. var piePieceProto = PiePiece.prototype;
  35649. piePieceProto.updateData = function (data, idx, firstCreate) {
  35650. var sector = this.childAt(0);
  35651. var labelLine = this.childAt(1);
  35652. var labelText = this.childAt(2);
  35653. var seriesModel = data.hostModel;
  35654. var itemModel = data.getItemModel(idx);
  35655. var layout = data.getItemLayout(idx);
  35656. var sectorShape = extend({}, layout);
  35657. sectorShape.label = null;
  35658. var animationTypeUpdate = seriesModel.getShallow('animationTypeUpdate');
  35659. if (firstCreate) {
  35660. sector.setShape(sectorShape);
  35661. var animationType = seriesModel.getShallow('animationType');
  35662. if (animationType === 'scale') {
  35663. sector.shape.r = layout.r0;
  35664. initProps(sector, {
  35665. shape: {
  35666. r: layout.r
  35667. }
  35668. }, seriesModel, idx);
  35669. } // Expansion
  35670. else {
  35671. sector.shape.endAngle = layout.startAngle;
  35672. updateProps(sector, {
  35673. shape: {
  35674. endAngle: layout.endAngle
  35675. }
  35676. }, seriesModel, idx);
  35677. }
  35678. } else {
  35679. if (animationTypeUpdate === 'expansion') {
  35680. // Sectors are set to be target shape and an overlaying clipPath is used for animation
  35681. sector.setShape(sectorShape);
  35682. } else {
  35683. // Transition animation from the old shape
  35684. updateProps(sector, {
  35685. shape: sectorShape
  35686. }, seriesModel, idx);
  35687. }
  35688. } // Update common style
  35689. var visualColor = data.getItemVisual(idx, 'color');
  35690. sector.useStyle(defaults({
  35691. lineJoin: 'bevel',
  35692. fill: visualColor
  35693. }, itemModel.getModel('itemStyle').getItemStyle()));
  35694. sector.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  35695. var cursorStyle = itemModel.getShallow('cursor');
  35696. cursorStyle && sector.attr('cursor', cursorStyle); // Toggle selected
  35697. toggleItemSelected(this, data.getItemLayout(idx), seriesModel.isSelected(data.getName(idx)), seriesModel.get('selectedOffset'), seriesModel.get('animation')); // Label and text animation should be applied only for transition type animation when update
  35698. var withAnimation = !firstCreate && animationTypeUpdate === 'transition';
  35699. this._updateLabel(data, idx, withAnimation);
  35700. this.highDownOnUpdate = !seriesModel.get('silent') ? function (fromState, toState) {
  35701. var hasAnimation = seriesModel.isAnimationEnabled() && itemModel.get('hoverAnimation');
  35702. if (toState === 'emphasis') {
  35703. labelLine.ignore = labelLine.hoverIgnore;
  35704. labelText.ignore = labelText.hoverIgnore; // Sector may has animation of updating data. Force to move to the last frame
  35705. // Or it may stopped on the wrong shape
  35706. if (hasAnimation) {
  35707. sector.stopAnimation(true);
  35708. sector.animateTo({
  35709. shape: {
  35710. r: layout.r + seriesModel.get('hoverOffset')
  35711. }
  35712. }, 300, 'elasticOut');
  35713. }
  35714. } else {
  35715. labelLine.ignore = labelLine.normalIgnore;
  35716. labelText.ignore = labelText.normalIgnore;
  35717. if (hasAnimation) {
  35718. sector.stopAnimation(true);
  35719. sector.animateTo({
  35720. shape: {
  35721. r: layout.r
  35722. }
  35723. }, 300, 'elasticOut');
  35724. }
  35725. }
  35726. } : null;
  35727. setHoverStyle(this);
  35728. };
  35729. piePieceProto._updateLabel = function (data, idx, withAnimation) {
  35730. var labelLine = this.childAt(1);
  35731. var labelText = this.childAt(2);
  35732. var seriesModel = data.hostModel;
  35733. var itemModel = data.getItemModel(idx);
  35734. var layout = data.getItemLayout(idx);
  35735. var labelLayout = layout.label;
  35736. var visualColor = data.getItemVisual(idx, 'color');
  35737. if (!labelLayout || isNaN(labelLayout.x) || isNaN(labelLayout.y)) {
  35738. labelText.ignore = labelText.normalIgnore = labelText.hoverIgnore = labelLine.ignore = labelLine.normalIgnore = labelLine.hoverIgnore = true;
  35739. return;
  35740. }
  35741. var targetLineShape = {
  35742. points: labelLayout.linePoints || [[labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]]
  35743. };
  35744. var targetTextStyle = {
  35745. x: labelLayout.x,
  35746. y: labelLayout.y
  35747. };
  35748. if (withAnimation) {
  35749. updateProps(labelLine, {
  35750. shape: targetLineShape
  35751. }, seriesModel, idx);
  35752. updateProps(labelText, {
  35753. style: targetTextStyle
  35754. }, seriesModel, idx);
  35755. } else {
  35756. labelLine.attr({
  35757. shape: targetLineShape
  35758. });
  35759. labelText.attr({
  35760. style: targetTextStyle
  35761. });
  35762. }
  35763. labelText.attr({
  35764. rotation: labelLayout.rotation,
  35765. origin: [labelLayout.x, labelLayout.y],
  35766. z2: 10
  35767. });
  35768. var labelModel = itemModel.getModel('label');
  35769. var labelHoverModel = itemModel.getModel('emphasis.label');
  35770. var labelLineModel = itemModel.getModel('labelLine');
  35771. var labelLineHoverModel = itemModel.getModel('emphasis.labelLine');
  35772. var visualColor = data.getItemVisual(idx, 'color');
  35773. setLabelStyle(labelText.style, labelText.hoverStyle = {}, labelModel, labelHoverModel, {
  35774. labelFetcher: data.hostModel,
  35775. labelDataIndex: idx,
  35776. defaultText: labelLayout.text,
  35777. autoColor: visualColor,
  35778. useInsideStyle: !!labelLayout.inside
  35779. }, {
  35780. textAlign: labelLayout.textAlign,
  35781. textVerticalAlign: labelLayout.verticalAlign,
  35782. opacity: data.getItemVisual(idx, 'opacity')
  35783. });
  35784. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  35785. labelText.hoverIgnore = !labelHoverModel.get('show');
  35786. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  35787. labelLine.hoverIgnore = !labelLineHoverModel.get('show'); // Default use item visual color
  35788. labelLine.setStyle({
  35789. stroke: visualColor,
  35790. opacity: data.getItemVisual(idx, 'opacity')
  35791. });
  35792. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  35793. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  35794. var smooth = labelLineModel.get('smooth');
  35795. if (smooth && smooth === true) {
  35796. smooth = 0.4;
  35797. }
  35798. labelLine.setShape({
  35799. smooth: smooth
  35800. });
  35801. };
  35802. inherits(PiePiece, Group); // Pie view
  35803. var PieView = Chart.extend({
  35804. type: 'pie',
  35805. init: function () {
  35806. var sectorGroup = new Group();
  35807. this._sectorGroup = sectorGroup;
  35808. },
  35809. render: function (seriesModel, ecModel, api, payload) {
  35810. if (payload && payload.from === this.uid) {
  35811. return;
  35812. }
  35813. var data = seriesModel.getData();
  35814. var oldData = this._data;
  35815. var group = this.group;
  35816. var hasAnimation = ecModel.get('animation');
  35817. var isFirstRender = !oldData;
  35818. var animationType = seriesModel.get('animationType');
  35819. var animationTypeUpdate = seriesModel.get('animationTypeUpdate');
  35820. var onSectorClick = curry(updateDataSelected, this.uid, seriesModel, hasAnimation, api);
  35821. var selectedMode = seriesModel.get('selectedMode');
  35822. data.diff(oldData).add(function (idx) {
  35823. var piePiece = new PiePiece(data, idx); // Default expansion animation
  35824. if (isFirstRender && animationType !== 'scale') {
  35825. piePiece.eachChild(function (child) {
  35826. child.stopAnimation(true);
  35827. });
  35828. }
  35829. selectedMode && piePiece.on('click', onSectorClick);
  35830. data.setItemGraphicEl(idx, piePiece);
  35831. group.add(piePiece);
  35832. }).update(function (newIdx, oldIdx) {
  35833. var piePiece = oldData.getItemGraphicEl(oldIdx);
  35834. if (!isFirstRender && animationTypeUpdate !== 'transition') {
  35835. piePiece.eachChild(function (child) {
  35836. child.stopAnimation(true);
  35837. });
  35838. }
  35839. piePiece.updateData(data, newIdx);
  35840. piePiece.off('click');
  35841. selectedMode && piePiece.on('click', onSectorClick);
  35842. group.add(piePiece);
  35843. data.setItemGraphicEl(newIdx, piePiece);
  35844. }).remove(function (idx) {
  35845. var piePiece = oldData.getItemGraphicEl(idx);
  35846. group.remove(piePiece);
  35847. }).execute();
  35848. if (hasAnimation && data.count() > 0 && (isFirstRender ? animationType !== 'scale' : animationTypeUpdate !== 'transition')) {
  35849. var shape = data.getItemLayout(0);
  35850. for (var s = 1; isNaN(shape.startAngle) && s < data.count(); ++s) {
  35851. shape = data.getItemLayout(s);
  35852. }
  35853. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  35854. var removeClipPath = bind(group.removeClipPath, group);
  35855. group.setClipPath(this._createClipPath(shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel, isFirstRender));
  35856. } else {
  35857. // clipPath is used in first-time animation, so remove it when otherwise. See: #8994
  35858. group.removeClipPath();
  35859. }
  35860. this._data = data;
  35861. },
  35862. dispose: function () {},
  35863. _createClipPath: function (cx, cy, r, startAngle, clockwise, cb, seriesModel, isFirstRender) {
  35864. var clipPath = new Sector({
  35865. shape: {
  35866. cx: cx,
  35867. cy: cy,
  35868. r0: 0,
  35869. r: r,
  35870. startAngle: startAngle,
  35871. endAngle: startAngle,
  35872. clockwise: clockwise
  35873. }
  35874. });
  35875. var initOrUpdate = isFirstRender ? initProps : updateProps;
  35876. initOrUpdate(clipPath, {
  35877. shape: {
  35878. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  35879. }
  35880. }, seriesModel, cb);
  35881. return clipPath;
  35882. },
  35883. /**
  35884. * @implement
  35885. */
  35886. containPoint: function (point, seriesModel) {
  35887. var data = seriesModel.getData();
  35888. var itemLayout = data.getItemLayout(0);
  35889. if (itemLayout) {
  35890. var dx = point[0] - itemLayout.cx;
  35891. var dy = point[1] - itemLayout.cy;
  35892. var radius = Math.sqrt(dx * dx + dy * dy);
  35893. return radius <= itemLayout.r && radius >= itemLayout.r0;
  35894. }
  35895. }
  35896. });
  35897. /*
  35898. * Licensed to the Apache Software Foundation (ASF) under one
  35899. * or more contributor license agreements. See the NOTICE file
  35900. * distributed with this work for additional information
  35901. * regarding copyright ownership. The ASF licenses this file
  35902. * to you under the Apache License, Version 2.0 (the
  35903. * "License"); you may not use this file except in compliance
  35904. * with the License. You may obtain a copy of the License at
  35905. *
  35906. * http://www.apache.org/licenses/LICENSE-2.0
  35907. *
  35908. * Unless required by applicable law or agreed to in writing,
  35909. * software distributed under the License is distributed on an
  35910. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35911. * KIND, either express or implied. See the License for the
  35912. * specific language governing permissions and limitations
  35913. * under the License.
  35914. */
  35915. var createDataSelectAction = function (seriesType, actionInfos) {
  35916. each$1(actionInfos, function (actionInfo) {
  35917. actionInfo.update = 'updateView';
  35918. /**
  35919. * @payload
  35920. * @property {string} seriesName
  35921. * @property {string} name
  35922. */
  35923. registerAction(actionInfo, function (payload, ecModel) {
  35924. var selected = {};
  35925. ecModel.eachComponent({
  35926. mainType: 'series',
  35927. subType: seriesType,
  35928. query: payload
  35929. }, function (seriesModel) {
  35930. if (seriesModel[actionInfo.method]) {
  35931. seriesModel[actionInfo.method](payload.name, payload.dataIndex);
  35932. }
  35933. var data = seriesModel.getData(); // Create selected map
  35934. data.each(function (idx) {
  35935. var name = data.getName(idx);
  35936. selected[name] = seriesModel.isSelected(name) || false;
  35937. });
  35938. });
  35939. return {
  35940. name: payload.name,
  35941. selected: selected,
  35942. seriesId: payload.seriesId
  35943. };
  35944. });
  35945. });
  35946. };
  35947. /*
  35948. * Licensed to the Apache Software Foundation (ASF) under one
  35949. * or more contributor license agreements. See the NOTICE file
  35950. * distributed with this work for additional information
  35951. * regarding copyright ownership. The ASF licenses this file
  35952. * to you under the Apache License, Version 2.0 (the
  35953. * "License"); you may not use this file except in compliance
  35954. * with the License. You may obtain a copy of the License at
  35955. *
  35956. * http://www.apache.org/licenses/LICENSE-2.0
  35957. *
  35958. * Unless required by applicable law or agreed to in writing,
  35959. * software distributed under the License is distributed on an
  35960. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35961. * KIND, either express or implied. See the License for the
  35962. * specific language governing permissions and limitations
  35963. * under the License.
  35964. */
  35965. // Pick color from palette for each data item.
  35966. // Applicable for charts that require applying color palette
  35967. // in data level (like pie, funnel, chord).
  35968. var dataColor = function (seriesType) {
  35969. return {
  35970. getTargetSeries: function (ecModel) {
  35971. // Pie and funnel may use diferrent scope
  35972. var paletteScope = {};
  35973. var seiresModelMap = createHashMap();
  35974. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  35975. seriesModel.__paletteScope = paletteScope;
  35976. seiresModelMap.set(seriesModel.uid, seriesModel);
  35977. });
  35978. return seiresModelMap;
  35979. },
  35980. reset: function (seriesModel, ecModel) {
  35981. var dataAll = seriesModel.getRawData();
  35982. var idxMap = {};
  35983. var data = seriesModel.getData();
  35984. data.each(function (idx) {
  35985. var rawIdx = data.getRawIndex(idx);
  35986. idxMap[rawIdx] = idx;
  35987. });
  35988. dataAll.each(function (rawIdx) {
  35989. var filteredIdx = idxMap[rawIdx]; // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  35990. var singleDataColor = filteredIdx != null && data.getItemVisual(filteredIdx, 'color', true);
  35991. var singleDataBorderColor = filteredIdx != null && data.getItemVisual(filteredIdx, 'borderColor', true);
  35992. var itemModel;
  35993. if (!singleDataColor || !singleDataBorderColor) {
  35994. // FIXME Performance
  35995. itemModel = dataAll.getItemModel(rawIdx);
  35996. }
  35997. if (!singleDataColor) {
  35998. var color = itemModel.get('itemStyle.color') || seriesModel.getColorFromPalette(dataAll.getName(rawIdx) || rawIdx + '', seriesModel.__paletteScope, dataAll.count()); // Data is not filtered
  35999. if (filteredIdx != null) {
  36000. data.setItemVisual(filteredIdx, 'color', color);
  36001. }
  36002. }
  36003. if (!singleDataBorderColor) {
  36004. var borderColor = itemModel.get('itemStyle.borderColor'); // Data is not filtered
  36005. if (filteredIdx != null) {
  36006. data.setItemVisual(filteredIdx, 'borderColor', borderColor);
  36007. }
  36008. }
  36009. });
  36010. }
  36011. };
  36012. };
  36013. /*
  36014. * Licensed to the Apache Software Foundation (ASF) under one
  36015. * or more contributor license agreements. See the NOTICE file
  36016. * distributed with this work for additional information
  36017. * regarding copyright ownership. The ASF licenses this file
  36018. * to you under the Apache License, Version 2.0 (the
  36019. * "License"); you may not use this file except in compliance
  36020. * with the License. You may obtain a copy of the License at
  36021. *
  36022. * http://www.apache.org/licenses/LICENSE-2.0
  36023. *
  36024. * Unless required by applicable law or agreed to in writing,
  36025. * software distributed under the License is distributed on an
  36026. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36027. * KIND, either express or implied. See the License for the
  36028. * specific language governing permissions and limitations
  36029. * under the License.
  36030. */
  36031. // FIXME emphasis label position is not same with normal label position
  36032. var RADIAN$1 = Math.PI / 180;
  36033. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight, viewLeft, viewTop, farthestX) {
  36034. list.sort(function (a, b) {
  36035. return a.y - b.y;
  36036. });
  36037. function shiftDown(start, end, delta, dir) {
  36038. for (var j = start; j < end; j++) {
  36039. if (list[j].y + delta > viewTop + viewHeight) {
  36040. break;
  36041. }
  36042. list[j].y += delta;
  36043. if (j > start && j + 1 < end && list[j + 1].y > list[j].y + list[j].height) {
  36044. shiftUp(j, delta / 2);
  36045. return;
  36046. }
  36047. }
  36048. shiftUp(end - 1, delta / 2);
  36049. }
  36050. function shiftUp(end, delta) {
  36051. for (var j = end; j >= 0; j--) {
  36052. if (list[j].y - delta < viewTop) {
  36053. break;
  36054. }
  36055. list[j].y -= delta;
  36056. if (j > 0 && list[j].y > list[j - 1].y + list[j - 1].height) {
  36057. break;
  36058. }
  36059. }
  36060. }
  36061. function changeX(list, isDownList, cx, cy, r, dir) {
  36062. var lastDeltaX = dir > 0 ? isDownList // right-side
  36063. ? Number.MAX_VALUE // down
  36064. : 0 // up
  36065. : isDownList // left-side
  36066. ? Number.MAX_VALUE // down
  36067. : 0; // up
  36068. for (var i = 0, l = list.length; i < l; i++) {
  36069. if (list[i].labelAlignTo !== 'none') {
  36070. continue;
  36071. }
  36072. var deltaY = Math.abs(list[i].y - cy);
  36073. var length = list[i].len;
  36074. var length2 = list[i].len2;
  36075. var deltaX = deltaY < r + length ? Math.sqrt((r + length + length2) * (r + length + length2) - deltaY * deltaY) : Math.abs(list[i].x - cx);
  36076. if (isDownList && deltaX >= lastDeltaX) {
  36077. // right-down, left-down
  36078. deltaX = lastDeltaX - 10;
  36079. }
  36080. if (!isDownList && deltaX <= lastDeltaX) {
  36081. // right-up, left-up
  36082. deltaX = lastDeltaX + 10;
  36083. }
  36084. list[i].x = cx + deltaX * dir;
  36085. lastDeltaX = deltaX;
  36086. }
  36087. }
  36088. var lastY = 0;
  36089. var delta;
  36090. var len = list.length;
  36091. var upList = [];
  36092. var downList = [];
  36093. for (var i = 0; i < len; i++) {
  36094. if (list[i].position === 'outer' && list[i].labelAlignTo === 'labelLine') {
  36095. var dx = list[i].x - farthestX;
  36096. list[i].linePoints[1][0] += dx;
  36097. list[i].x = farthestX;
  36098. }
  36099. delta = list[i].y - lastY;
  36100. if (delta < 0) {
  36101. shiftDown(i, len, -delta, dir);
  36102. }
  36103. lastY = list[i].y + list[i].height;
  36104. }
  36105. if (viewHeight - lastY < 0) {
  36106. shiftUp(len - 1, lastY - viewHeight);
  36107. }
  36108. for (var i = 0; i < len; i++) {
  36109. if (list[i].y >= cy) {
  36110. downList.push(list[i]);
  36111. } else {
  36112. upList.push(list[i]);
  36113. }
  36114. }
  36115. changeX(upList, false, cx, cy, r, dir);
  36116. changeX(downList, true, cx, cy, r, dir);
  36117. }
  36118. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop) {
  36119. var leftList = [];
  36120. var rightList = [];
  36121. var leftmostX = Number.MAX_VALUE;
  36122. var rightmostX = -Number.MAX_VALUE;
  36123. for (var i = 0; i < labelLayoutList.length; i++) {
  36124. if (isPositionCenter(labelLayoutList[i])) {
  36125. continue;
  36126. }
  36127. if (labelLayoutList[i].x < cx) {
  36128. leftmostX = Math.min(leftmostX, labelLayoutList[i].x);
  36129. leftList.push(labelLayoutList[i]);
  36130. } else {
  36131. rightmostX = Math.max(rightmostX, labelLayoutList[i].x);
  36132. rightList.push(labelLayoutList[i]);
  36133. }
  36134. }
  36135. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight, viewLeft, viewTop, rightmostX);
  36136. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight, viewLeft, viewTop, leftmostX);
  36137. for (var i = 0; i < labelLayoutList.length; i++) {
  36138. var layout = labelLayoutList[i];
  36139. if (isPositionCenter(layout)) {
  36140. continue;
  36141. }
  36142. var linePoints = layout.linePoints;
  36143. if (linePoints) {
  36144. var isAlignToEdge = layout.labelAlignTo === 'edge';
  36145. var realTextWidth = layout.textRect.width;
  36146. var targetTextWidth;
  36147. if (isAlignToEdge) {
  36148. if (layout.x < cx) {
  36149. targetTextWidth = linePoints[2][0] - layout.labelDistance - viewLeft - layout.labelMargin;
  36150. } else {
  36151. targetTextWidth = viewLeft + viewWidth - layout.labelMargin - linePoints[2][0] - layout.labelDistance;
  36152. }
  36153. } else {
  36154. if (layout.x < cx) {
  36155. targetTextWidth = layout.x - viewLeft - layout.bleedMargin;
  36156. } else {
  36157. targetTextWidth = viewLeft + viewWidth - layout.x - layout.bleedMargin;
  36158. }
  36159. }
  36160. if (targetTextWidth < layout.textRect.width) {
  36161. layout.text = truncateText(layout.text, targetTextWidth, layout.font);
  36162. if (layout.labelAlignTo === 'edge') {
  36163. realTextWidth = getWidth(layout.text, layout.font);
  36164. }
  36165. }
  36166. var dist = linePoints[1][0] - linePoints[2][0];
  36167. if (isAlignToEdge) {
  36168. if (layout.x < cx) {
  36169. linePoints[2][0] = viewLeft + layout.labelMargin + realTextWidth + layout.labelDistance;
  36170. } else {
  36171. linePoints[2][0] = viewLeft + viewWidth - layout.labelMargin - realTextWidth - layout.labelDistance;
  36172. }
  36173. } else {
  36174. if (layout.x < cx) {
  36175. linePoints[2][0] = layout.x + layout.labelDistance;
  36176. } else {
  36177. linePoints[2][0] = layout.x - layout.labelDistance;
  36178. }
  36179. linePoints[1][0] = linePoints[2][0] + dist;
  36180. }
  36181. linePoints[1][1] = linePoints[2][1] = layout.y;
  36182. }
  36183. }
  36184. }
  36185. function isPositionCenter(layout) {
  36186. // Not change x for center label
  36187. return layout.position === 'center';
  36188. }
  36189. var labelLayout = function (seriesModel, r, viewWidth, viewHeight, viewLeft, viewTop) {
  36190. var data = seriesModel.getData();
  36191. var labelLayoutList = [];
  36192. var cx;
  36193. var cy;
  36194. var hasLabelRotate = false;
  36195. var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN$1;
  36196. data.each(function (idx) {
  36197. var layout = data.getItemLayout(idx);
  36198. var itemModel = data.getItemModel(idx);
  36199. var labelModel = itemModel.getModel('label'); // Use position in normal or emphasis
  36200. var labelPosition = labelModel.get('position') || itemModel.get('emphasis.label.position');
  36201. var labelDistance = labelModel.get('distanceToLabelLine');
  36202. var labelAlignTo = labelModel.get('alignTo');
  36203. var labelMargin = parsePercent$1(labelModel.get('margin'), viewWidth);
  36204. var bleedMargin = labelModel.get('bleedMargin');
  36205. var font = labelModel.getFont();
  36206. var labelLineModel = itemModel.getModel('labelLine');
  36207. var labelLineLen = labelLineModel.get('length');
  36208. labelLineLen = parsePercent$1(labelLineLen, viewWidth);
  36209. var labelLineLen2 = labelLineModel.get('length2');
  36210. labelLineLen2 = parsePercent$1(labelLineLen2, viewWidth);
  36211. if (layout.angle < minShowLabelRadian) {
  36212. return;
  36213. }
  36214. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  36215. var dx = Math.cos(midAngle);
  36216. var dy = Math.sin(midAngle);
  36217. var textX;
  36218. var textY;
  36219. var linePoints;
  36220. var textAlign;
  36221. cx = layout.cx;
  36222. cy = layout.cy;
  36223. var text = seriesModel.getFormattedLabel(idx, 'normal') || data.getName(idx);
  36224. var textRect = getBoundingRect(text, font, textAlign, 'top');
  36225. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  36226. if (labelPosition === 'center') {
  36227. textX = layout.cx;
  36228. textY = layout.cy;
  36229. textAlign = 'center';
  36230. } else {
  36231. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  36232. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  36233. textX = x1 + dx * 3;
  36234. textY = y1 + dy * 3;
  36235. if (!isLabelInside) {
  36236. // For roseType
  36237. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  36238. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  36239. var x3 = x2 + (dx < 0 ? -1 : 1) * labelLineLen2;
  36240. var y3 = y2;
  36241. if (labelAlignTo === 'edge') {
  36242. // Adjust textX because text align of edge is opposite
  36243. textX = dx < 0 ? viewLeft + labelMargin : viewLeft + viewWidth - labelMargin;
  36244. } else {
  36245. textX = x3 + (dx < 0 ? -labelDistance : labelDistance);
  36246. }
  36247. textY = y3;
  36248. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  36249. }
  36250. textAlign = isLabelInside ? 'center' : labelAlignTo === 'edge' ? dx > 0 ? 'right' : 'left' : dx > 0 ? 'left' : 'right';
  36251. }
  36252. var labelRotate;
  36253. var rotate = labelModel.get('rotate');
  36254. if (typeof rotate === 'number') {
  36255. labelRotate = rotate * (Math.PI / 180);
  36256. } else {
  36257. labelRotate = rotate ? dx < 0 ? -midAngle + Math.PI : -midAngle : 0;
  36258. }
  36259. hasLabelRotate = !!labelRotate;
  36260. layout.label = {
  36261. x: textX,
  36262. y: textY,
  36263. position: labelPosition,
  36264. height: textRect.height,
  36265. len: labelLineLen,
  36266. len2: labelLineLen2,
  36267. linePoints: linePoints,
  36268. textAlign: textAlign,
  36269. verticalAlign: 'middle',
  36270. rotation: labelRotate,
  36271. inside: isLabelInside,
  36272. labelDistance: labelDistance,
  36273. labelAlignTo: labelAlignTo,
  36274. labelMargin: labelMargin,
  36275. bleedMargin: bleedMargin,
  36276. textRect: textRect,
  36277. text: text,
  36278. font: font
  36279. }; // Not layout the inside label
  36280. if (!isLabelInside) {
  36281. labelLayoutList.push(layout.label);
  36282. }
  36283. });
  36284. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  36285. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop);
  36286. }
  36287. };
  36288. /*
  36289. * Licensed to the Apache Software Foundation (ASF) under one
  36290. * or more contributor license agreements. See the NOTICE file
  36291. * distributed with this work for additional information
  36292. * regarding copyright ownership. The ASF licenses this file
  36293. * to you under the Apache License, Version 2.0 (the
  36294. * "License"); you may not use this file except in compliance
  36295. * with the License. You may obtain a copy of the License at
  36296. *
  36297. * http://www.apache.org/licenses/LICENSE-2.0
  36298. *
  36299. * Unless required by applicable law or agreed to in writing,
  36300. * software distributed under the License is distributed on an
  36301. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36302. * KIND, either express or implied. See the License for the
  36303. * specific language governing permissions and limitations
  36304. * under the License.
  36305. */
  36306. var PI2$4 = Math.PI * 2;
  36307. var RADIAN = Math.PI / 180;
  36308. function getViewRect(seriesModel, api) {
  36309. return getLayoutRect(seriesModel.getBoxLayoutParams(), {
  36310. width: api.getWidth(),
  36311. height: api.getHeight()
  36312. });
  36313. }
  36314. var pieLayout = function (seriesType, ecModel, api, payload) {
  36315. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  36316. var data = seriesModel.getData();
  36317. var valueDim = data.mapDimension('value');
  36318. var viewRect = getViewRect(seriesModel, api);
  36319. var center = seriesModel.get('center');
  36320. var radius = seriesModel.get('radius');
  36321. if (!isArray(radius)) {
  36322. radius = [0, radius];
  36323. }
  36324. if (!isArray(center)) {
  36325. center = [center, center];
  36326. }
  36327. var width = parsePercent$1(viewRect.width, api.getWidth());
  36328. var height = parsePercent$1(viewRect.height, api.getHeight());
  36329. var size = Math.min(width, height);
  36330. var cx = parsePercent$1(center[0], width) + viewRect.x;
  36331. var cy = parsePercent$1(center[1], height) + viewRect.y;
  36332. var r0 = parsePercent$1(radius[0], size / 2);
  36333. var r = parsePercent$1(radius[1], size / 2);
  36334. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  36335. var minAngle = seriesModel.get('minAngle') * RADIAN;
  36336. var validDataCount = 0;
  36337. data.each(valueDim, function (value) {
  36338. !isNaN(value) && validDataCount++;
  36339. });
  36340. var sum = data.getSum(valueDim); // Sum may be 0
  36341. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  36342. var clockwise = seriesModel.get('clockwise');
  36343. var roseType = seriesModel.get('roseType');
  36344. var stillShowZeroSum = seriesModel.get('stillShowZeroSum'); // [0...max]
  36345. var extent = data.getDataExtent(valueDim);
  36346. extent[0] = 0; // In the case some sector angle is smaller than minAngle
  36347. var restAngle = PI2$4;
  36348. var valueSumLargerThanMinAngle = 0;
  36349. var currentAngle = startAngle;
  36350. var dir = clockwise ? 1 : -1;
  36351. data.each(valueDim, function (value, idx) {
  36352. var angle;
  36353. if (isNaN(value)) {
  36354. data.setItemLayout(idx, {
  36355. angle: NaN,
  36356. startAngle: NaN,
  36357. endAngle: NaN,
  36358. clockwise: clockwise,
  36359. cx: cx,
  36360. cy: cy,
  36361. r0: r0,
  36362. r: roseType ? NaN : r,
  36363. viewRect: viewRect
  36364. });
  36365. return;
  36366. } // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  36367. if (roseType !== 'area') {
  36368. angle = sum === 0 && stillShowZeroSum ? unitRadian : value * unitRadian;
  36369. } else {
  36370. angle = PI2$4 / validDataCount;
  36371. }
  36372. if (angle < minAngle) {
  36373. angle = minAngle;
  36374. restAngle -= minAngle;
  36375. } else {
  36376. valueSumLargerThanMinAngle += value;
  36377. }
  36378. var endAngle = currentAngle + dir * angle;
  36379. data.setItemLayout(idx, {
  36380. angle: angle,
  36381. startAngle: currentAngle,
  36382. endAngle: endAngle,
  36383. clockwise: clockwise,
  36384. cx: cx,
  36385. cy: cy,
  36386. r0: r0,
  36387. r: roseType ? linearMap(value, extent, [r0, r]) : r,
  36388. viewRect: viewRect
  36389. });
  36390. currentAngle = endAngle;
  36391. }); // Some sector is constrained by minAngle
  36392. // Rest sectors needs recalculate angle
  36393. if (restAngle < PI2$4 && validDataCount) {
  36394. // Average the angle if rest angle is not enough after all angles is
  36395. // Constrained by minAngle
  36396. if (restAngle <= 1e-3) {
  36397. var angle = PI2$4 / validDataCount;
  36398. data.each(valueDim, function (value, idx) {
  36399. if (!isNaN(value)) {
  36400. var layout = data.getItemLayout(idx);
  36401. layout.angle = angle;
  36402. layout.startAngle = startAngle + dir * idx * angle;
  36403. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  36404. }
  36405. });
  36406. } else {
  36407. unitRadian = restAngle / valueSumLargerThanMinAngle;
  36408. currentAngle = startAngle;
  36409. data.each(valueDim, function (value, idx) {
  36410. if (!isNaN(value)) {
  36411. var layout = data.getItemLayout(idx);
  36412. var angle = layout.angle === minAngle ? minAngle : value * unitRadian;
  36413. layout.startAngle = currentAngle;
  36414. layout.endAngle = currentAngle + dir * angle;
  36415. currentAngle += dir * angle;
  36416. }
  36417. });
  36418. }
  36419. }
  36420. labelLayout(seriesModel, r, viewRect.width, viewRect.height, viewRect.x, viewRect.y);
  36421. });
  36422. };
  36423. /*
  36424. * Licensed to the Apache Software Foundation (ASF) under one
  36425. * or more contributor license agreements. See the NOTICE file
  36426. * distributed with this work for additional information
  36427. * regarding copyright ownership. The ASF licenses this file
  36428. * to you under the Apache License, Version 2.0 (the
  36429. * "License"); you may not use this file except in compliance
  36430. * with the License. You may obtain a copy of the License at
  36431. *
  36432. * http://www.apache.org/licenses/LICENSE-2.0
  36433. *
  36434. * Unless required by applicable law or agreed to in writing,
  36435. * software distributed under the License is distributed on an
  36436. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36437. * KIND, either express or implied. See the License for the
  36438. * specific language governing permissions and limitations
  36439. * under the License.
  36440. */
  36441. var dataFilter = function (seriesType) {
  36442. return {
  36443. seriesType: seriesType,
  36444. reset: function (seriesModel, ecModel) {
  36445. var legendModels = ecModel.findComponents({
  36446. mainType: 'legend'
  36447. });
  36448. if (!legendModels || !legendModels.length) {
  36449. return;
  36450. }
  36451. var data = seriesModel.getData();
  36452. data.filterSelf(function (idx) {
  36453. var name = data.getName(idx); // If in any legend component the status is not selected.
  36454. for (var i = 0; i < legendModels.length; i++) {
  36455. if (!legendModels[i].isSelected(name)) {
  36456. return false;
  36457. }
  36458. }
  36459. return true;
  36460. });
  36461. }
  36462. };
  36463. };
  36464. /*
  36465. * Licensed to the Apache Software Foundation (ASF) under one
  36466. * or more contributor license agreements. See the NOTICE file
  36467. * distributed with this work for additional information
  36468. * regarding copyright ownership. The ASF licenses this file
  36469. * to you under the Apache License, Version 2.0 (the
  36470. * "License"); you may not use this file except in compliance
  36471. * with the License. You may obtain a copy of the License at
  36472. *
  36473. * http://www.apache.org/licenses/LICENSE-2.0
  36474. *
  36475. * Unless required by applicable law or agreed to in writing,
  36476. * software distributed under the License is distributed on an
  36477. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36478. * KIND, either express or implied. See the License for the
  36479. * specific language governing permissions and limitations
  36480. * under the License.
  36481. */
  36482. createDataSelectAction('pie', [{
  36483. type: 'pieToggleSelect',
  36484. event: 'pieselectchanged',
  36485. method: 'toggleSelected'
  36486. }, {
  36487. type: 'pieSelect',
  36488. event: 'pieselected',
  36489. method: 'select'
  36490. }, {
  36491. type: 'pieUnSelect',
  36492. event: 'pieunselected',
  36493. method: 'unSelect'
  36494. }]);
  36495. registerVisual(dataColor('pie'));
  36496. registerLayout(curry(pieLayout, 'pie'));
  36497. registerProcessor(dataFilter('pie'));
  36498. /*
  36499. * Licensed to the Apache Software Foundation (ASF) under one
  36500. * or more contributor license agreements. See the NOTICE file
  36501. * distributed with this work for additional information
  36502. * regarding copyright ownership. The ASF licenses this file
  36503. * to you under the Apache License, Version 2.0 (the
  36504. * "License"); you may not use this file except in compliance
  36505. * with the License. You may obtain a copy of the License at
  36506. *
  36507. * http://www.apache.org/licenses/LICENSE-2.0
  36508. *
  36509. * Unless required by applicable law or agreed to in writing,
  36510. * software distributed under the License is distributed on an
  36511. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36512. * KIND, either express or implied. See the License for the
  36513. * specific language governing permissions and limitations
  36514. * under the License.
  36515. */
  36516. /**
  36517. * Link lists and struct (graph or tree)
  36518. */
  36519. var each$7 = each$1;
  36520. var DATAS = '\0__link_datas';
  36521. var MAIN_DATA = '\0__link_mainData'; // Caution:
  36522. // In most case, either list or its shallow clones (see list.cloneShallow)
  36523. // is active in echarts process. So considering heap memory consumption,
  36524. // we do not clone tree or graph, but share them among list and its shallow clones.
  36525. // But in some rare case, we have to keep old list (like do animation in chart). So
  36526. // please take care that both the old list and the new list share the same tree/graph.
  36527. /**
  36528. * @param {Object} opt
  36529. * @param {module:echarts/data/List} opt.mainData
  36530. * @param {Object} [opt.struct] For example, instance of Graph or Tree.
  36531. * @param {string} [opt.structAttr] designation: list[structAttr] = struct;
  36532. * @param {Object} [opt.datas] {dataType: data},
  36533. * like: {node: nodeList, edge: edgeList}.
  36534. * Should contain mainData.
  36535. * @param {Object} [opt.datasAttr] {dataType: attr},
  36536. * designation: struct[datasAttr[dataType]] = list;
  36537. */
  36538. function linkList(opt) {
  36539. var mainData = opt.mainData;
  36540. var datas = opt.datas;
  36541. if (!datas) {
  36542. datas = {
  36543. main: mainData
  36544. };
  36545. opt.datasAttr = {
  36546. main: 'data'
  36547. };
  36548. }
  36549. opt.datas = opt.mainData = null;
  36550. linkAll(mainData, datas, opt); // Porxy data original methods.
  36551. each$7(datas, function (data) {
  36552. each$7(mainData.TRANSFERABLE_METHODS, function (methodName) {
  36553. data.wrapMethod(methodName, curry(transferInjection, opt));
  36554. });
  36555. }); // Beyond transfer, additional features should be added to `cloneShallow`.
  36556. mainData.wrapMethod('cloneShallow', curry(cloneShallowInjection, opt)); // Only mainData trigger change, because struct.update may trigger
  36557. // another changable methods, which may bring about dead lock.
  36558. each$7(mainData.CHANGABLE_METHODS, function (methodName) {
  36559. mainData.wrapMethod(methodName, curry(changeInjection, opt));
  36560. }); // Make sure datas contains mainData.
  36561. assert$1(datas[mainData.dataType] === mainData);
  36562. }
  36563. function transferInjection(opt, res) {
  36564. if (isMainData(this)) {
  36565. // Transfer datas to new main data.
  36566. var datas = extend({}, this[DATAS]);
  36567. datas[this.dataType] = res;
  36568. linkAll(res, datas, opt);
  36569. } else {
  36570. // Modify the reference in main data to point newData.
  36571. linkSingle(res, this.dataType, this[MAIN_DATA], opt);
  36572. }
  36573. return res;
  36574. }
  36575. function changeInjection(opt, res) {
  36576. opt.struct && opt.struct.update(this);
  36577. return res;
  36578. }
  36579. function cloneShallowInjection(opt, res) {
  36580. // cloneShallow, which brings about some fragilities, may be inappropriate
  36581. // to be exposed as an API. So for implementation simplicity we can make
  36582. // the restriction that cloneShallow of not-mainData should not be invoked
  36583. // outside, but only be invoked here.
  36584. each$7(res[DATAS], function (data, dataType) {
  36585. data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
  36586. });
  36587. return res;
  36588. }
  36589. /**
  36590. * Supplement method to List.
  36591. *
  36592. * @public
  36593. * @param {string} [dataType] If not specified, return mainData.
  36594. * @return {module:echarts/data/List}
  36595. */
  36596. function getLinkedData(dataType) {
  36597. var mainData = this[MAIN_DATA];
  36598. return dataType == null || mainData == null ? mainData : mainData[DATAS][dataType];
  36599. }
  36600. function isMainData(data) {
  36601. return data[MAIN_DATA] === data;
  36602. }
  36603. function linkAll(mainData, datas, opt) {
  36604. mainData[DATAS] = {};
  36605. each$7(datas, function (data, dataType) {
  36606. linkSingle(data, dataType, mainData, opt);
  36607. });
  36608. }
  36609. function linkSingle(data, dataType, mainData, opt) {
  36610. mainData[DATAS][dataType] = data;
  36611. data[MAIN_DATA] = mainData;
  36612. data.dataType = dataType;
  36613. if (opt.struct) {
  36614. data[opt.structAttr] = opt.struct;
  36615. opt.struct[opt.datasAttr[dataType]] = data;
  36616. } // Supplement method.
  36617. data.getLinkedData = getLinkedData;
  36618. }
  36619. /*
  36620. * Licensed to the Apache Software Foundation (ASF) under one
  36621. * or more contributor license agreements. See the NOTICE file
  36622. * distributed with this work for additional information
  36623. * regarding copyright ownership. The ASF licenses this file
  36624. * to you under the Apache License, Version 2.0 (the
  36625. * "License"); you may not use this file except in compliance
  36626. * with the License. You may obtain a copy of the License at
  36627. *
  36628. * http://www.apache.org/licenses/LICENSE-2.0
  36629. *
  36630. * Unless required by applicable law or agreed to in writing,
  36631. * software distributed under the License is distributed on an
  36632. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36633. * KIND, either express or implied. See the License for the
  36634. * specific language governing permissions and limitations
  36635. * under the License.
  36636. */
  36637. /**
  36638. * Tree data structure
  36639. *
  36640. * @module echarts/data/Tree
  36641. */
  36642. /**
  36643. * @constructor module:echarts/data/Tree~TreeNode
  36644. * @param {string} name
  36645. * @param {module:echarts/data/Tree} hostTree
  36646. */
  36647. var TreeNode = function (name, hostTree) {
  36648. /**
  36649. * @type {string}
  36650. */
  36651. this.name = name || '';
  36652. /**
  36653. * Depth of node
  36654. *
  36655. * @type {number}
  36656. * @readOnly
  36657. */
  36658. this.depth = 0;
  36659. /**
  36660. * Height of the subtree rooted at this node.
  36661. * @type {number}
  36662. * @readOnly
  36663. */
  36664. this.height = 0;
  36665. /**
  36666. * @type {module:echarts/data/Tree~TreeNode}
  36667. * @readOnly
  36668. */
  36669. this.parentNode = null;
  36670. /**
  36671. * Reference to list item.
  36672. * Do not persistent dataIndex outside,
  36673. * besause it may be changed by list.
  36674. * If dataIndex -1,
  36675. * this node is logical deleted (filtered) in list.
  36676. *
  36677. * @type {Object}
  36678. * @readOnly
  36679. */
  36680. this.dataIndex = -1;
  36681. /**
  36682. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  36683. * @readOnly
  36684. */
  36685. this.children = [];
  36686. /**
  36687. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  36688. * @pubilc
  36689. */
  36690. this.viewChildren = [];
  36691. /**
  36692. * @type {moduel:echarts/data/Tree}
  36693. * @readOnly
  36694. */
  36695. this.hostTree = hostTree;
  36696. };
  36697. TreeNode.prototype = {
  36698. constructor: TreeNode,
  36699. /**
  36700. * The node is removed.
  36701. * @return {boolean} is removed.
  36702. */
  36703. isRemoved: function () {
  36704. return this.dataIndex < 0;
  36705. },
  36706. /**
  36707. * Travel this subtree (include this node).
  36708. * Usage:
  36709. * node.eachNode(function () { ... }); // preorder
  36710. * node.eachNode('preorder', function () { ... }); // preorder
  36711. * node.eachNode('postorder', function () { ... }); // postorder
  36712. * node.eachNode(
  36713. * {order: 'postorder', attr: 'viewChildren'},
  36714. * function () { ... }
  36715. * ); // postorder
  36716. *
  36717. * @param {(Object|string)} options If string, means order.
  36718. * @param {string=} options.order 'preorder' or 'postorder'
  36719. * @param {string=} options.attr 'children' or 'viewChildren'
  36720. * @param {Function} cb If in preorder and return false,
  36721. * its subtree will not be visited.
  36722. * @param {Object} [context]
  36723. */
  36724. eachNode: function (options, cb, context) {
  36725. if (typeof options === 'function') {
  36726. context = cb;
  36727. cb = options;
  36728. options = null;
  36729. }
  36730. options = options || {};
  36731. if (isString(options)) {
  36732. options = {
  36733. order: options
  36734. };
  36735. }
  36736. var order = options.order || 'preorder';
  36737. var children = this[options.attr || 'children'];
  36738. var suppressVisitSub;
  36739. order === 'preorder' && (suppressVisitSub = cb.call(context, this));
  36740. for (var i = 0; !suppressVisitSub && i < children.length; i++) {
  36741. children[i].eachNode(options, cb, context);
  36742. }
  36743. order === 'postorder' && cb.call(context, this);
  36744. },
  36745. /**
  36746. * Update depth and height of this subtree.
  36747. *
  36748. * @param {number} depth
  36749. */
  36750. updateDepthAndHeight: function (depth) {
  36751. var height = 0;
  36752. this.depth = depth;
  36753. for (var i = 0; i < this.children.length; i++) {
  36754. var child = this.children[i];
  36755. child.updateDepthAndHeight(depth + 1);
  36756. if (child.height > height) {
  36757. height = child.height;
  36758. }
  36759. }
  36760. this.height = height + 1;
  36761. },
  36762. /**
  36763. * @param {string} id
  36764. * @return {module:echarts/data/Tree~TreeNode}
  36765. */
  36766. getNodeById: function (id) {
  36767. if (this.getId() === id) {
  36768. return this;
  36769. }
  36770. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  36771. var res = children[i].getNodeById(id);
  36772. if (res) {
  36773. return res;
  36774. }
  36775. }
  36776. },
  36777. /**
  36778. * @param {module:echarts/data/Tree~TreeNode} node
  36779. * @return {boolean}
  36780. */
  36781. contains: function (node) {
  36782. if (node === this) {
  36783. return true;
  36784. }
  36785. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  36786. var res = children[i].contains(node);
  36787. if (res) {
  36788. return res;
  36789. }
  36790. }
  36791. },
  36792. /**
  36793. * @param {boolean} includeSelf Default false.
  36794. * @return {Array.<module:echarts/data/Tree~TreeNode>} order: [root, child, grandchild, ...]
  36795. */
  36796. getAncestors: function (includeSelf) {
  36797. var ancestors = [];
  36798. var node = includeSelf ? this : this.parentNode;
  36799. while (node) {
  36800. ancestors.push(node);
  36801. node = node.parentNode;
  36802. }
  36803. ancestors.reverse();
  36804. return ancestors;
  36805. },
  36806. /**
  36807. * @param {string|Array=} [dimension='value'] Default 'value'. can be 0, 1, 2, 3
  36808. * @return {number} Value.
  36809. */
  36810. getValue: function (dimension) {
  36811. var data = this.hostTree.data;
  36812. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  36813. },
  36814. /**
  36815. * @param {Object} layout
  36816. * @param {boolean=} [merge=false]
  36817. */
  36818. setLayout: function (layout, merge$$1) {
  36819. this.dataIndex >= 0 && this.hostTree.data.setItemLayout(this.dataIndex, layout, merge$$1);
  36820. },
  36821. /**
  36822. * @return {Object} layout
  36823. */
  36824. getLayout: function () {
  36825. return this.hostTree.data.getItemLayout(this.dataIndex);
  36826. },
  36827. /**
  36828. * @param {string} [path]
  36829. * @return {module:echarts/model/Model}
  36830. */
  36831. getModel: function (path) {
  36832. if (this.dataIndex < 0) {
  36833. return;
  36834. }
  36835. var hostTree = this.hostTree;
  36836. var itemModel = hostTree.data.getItemModel(this.dataIndex);
  36837. var levelModel = this.getLevelModel(); // FIXME: refactor levelModel to "beforeLink", and remove levelModel here.
  36838. if (levelModel) {
  36839. return itemModel.getModel(path, levelModel.getModel(path));
  36840. } else {
  36841. return itemModel.getModel(path);
  36842. }
  36843. },
  36844. /**
  36845. * @return {module:echarts/model/Model}
  36846. */
  36847. getLevelModel: function () {
  36848. return (this.hostTree.levelModels || [])[this.depth];
  36849. },
  36850. /**
  36851. * @example
  36852. * setItemVisual('color', color);
  36853. * setItemVisual({
  36854. * 'color': color
  36855. * });
  36856. */
  36857. setVisual: function (key, value) {
  36858. this.dataIndex >= 0 && this.hostTree.data.setItemVisual(this.dataIndex, key, value);
  36859. },
  36860. /**
  36861. * Get item visual
  36862. */
  36863. getVisual: function (key, ignoreParent) {
  36864. return this.hostTree.data.getItemVisual(this.dataIndex, key, ignoreParent);
  36865. },
  36866. /**
  36867. * @public
  36868. * @return {number}
  36869. */
  36870. getRawIndex: function () {
  36871. return this.hostTree.data.getRawIndex(this.dataIndex);
  36872. },
  36873. /**
  36874. * @public
  36875. * @return {string}
  36876. */
  36877. getId: function () {
  36878. return this.hostTree.data.getId(this.dataIndex);
  36879. },
  36880. /**
  36881. * if this is an ancestor of another node
  36882. *
  36883. * @public
  36884. * @param {TreeNode} node another node
  36885. * @return {boolean} if is ancestor
  36886. */
  36887. isAncestorOf: function (node) {
  36888. var parent = node.parentNode;
  36889. while (parent) {
  36890. if (parent === this) {
  36891. return true;
  36892. }
  36893. parent = parent.parentNode;
  36894. }
  36895. return false;
  36896. },
  36897. /**
  36898. * if this is an descendant of another node
  36899. *
  36900. * @public
  36901. * @param {TreeNode} node another node
  36902. * @return {boolean} if is descendant
  36903. */
  36904. isDescendantOf: function (node) {
  36905. return node !== this && node.isAncestorOf(this);
  36906. }
  36907. };
  36908. /**
  36909. * @constructor
  36910. * @alias module:echarts/data/Tree
  36911. * @param {module:echarts/model/Model} hostModel
  36912. * @param {Array.<Object>} levelOptions
  36913. */
  36914. function Tree(hostModel, levelOptions) {
  36915. /**
  36916. * @type {module:echarts/data/Tree~TreeNode}
  36917. * @readOnly
  36918. */
  36919. this.root;
  36920. /**
  36921. * @type {module:echarts/data/List}
  36922. * @readOnly
  36923. */
  36924. this.data;
  36925. /**
  36926. * Index of each item is the same as the raw index of coresponding list item.
  36927. * @private
  36928. * @type {Array.<module:echarts/data/Tree~TreeNode}
  36929. */
  36930. this._nodes = [];
  36931. /**
  36932. * @private
  36933. * @readOnly
  36934. * @type {module:echarts/model/Model}
  36935. */
  36936. this.hostModel = hostModel;
  36937. /**
  36938. * @private
  36939. * @readOnly
  36940. * @type {Array.<module:echarts/model/Model}
  36941. */
  36942. this.levelModels = map(levelOptions || [], function (levelDefine) {
  36943. return new Model(levelDefine, hostModel, hostModel.ecModel);
  36944. });
  36945. }
  36946. Tree.prototype = {
  36947. constructor: Tree,
  36948. type: 'tree',
  36949. /**
  36950. * Travel this subtree (include this node).
  36951. * Usage:
  36952. * node.eachNode(function () { ... }); // preorder
  36953. * node.eachNode('preorder', function () { ... }); // preorder
  36954. * node.eachNode('postorder', function () { ... }); // postorder
  36955. * node.eachNode(
  36956. * {order: 'postorder', attr: 'viewChildren'},
  36957. * function () { ... }
  36958. * ); // postorder
  36959. *
  36960. * @param {(Object|string)} options If string, means order.
  36961. * @param {string=} options.order 'preorder' or 'postorder'
  36962. * @param {string=} options.attr 'children' or 'viewChildren'
  36963. * @param {Function} cb
  36964. * @param {Object} [context]
  36965. */
  36966. eachNode: function (options, cb, context) {
  36967. this.root.eachNode(options, cb, context);
  36968. },
  36969. /**
  36970. * @param {number} dataIndex
  36971. * @return {module:echarts/data/Tree~TreeNode}
  36972. */
  36973. getNodeByDataIndex: function (dataIndex) {
  36974. var rawIndex = this.data.getRawIndex(dataIndex);
  36975. return this._nodes[rawIndex];
  36976. },
  36977. /**
  36978. * @param {string} name
  36979. * @return {module:echarts/data/Tree~TreeNode}
  36980. */
  36981. getNodeByName: function (name) {
  36982. return this.root.getNodeByName(name);
  36983. },
  36984. /**
  36985. * Update item available by list,
  36986. * when list has been performed options like 'filterSelf' or 'map'.
  36987. */
  36988. update: function () {
  36989. var data = this.data;
  36990. var nodes = this._nodes;
  36991. for (var i = 0, len = nodes.length; i < len; i++) {
  36992. nodes[i].dataIndex = -1;
  36993. }
  36994. for (var i = 0, len = data.count(); i < len; i++) {
  36995. nodes[data.getRawIndex(i)].dataIndex = i;
  36996. }
  36997. },
  36998. /**
  36999. * Clear all layouts
  37000. */
  37001. clearLayouts: function () {
  37002. this.data.clearItemLayouts();
  37003. }
  37004. };
  37005. /**
  37006. * data node format:
  37007. * {
  37008. * name: ...
  37009. * value: ...
  37010. * children: [
  37011. * {
  37012. * name: ...
  37013. * value: ...
  37014. * children: ...
  37015. * },
  37016. * ...
  37017. * ]
  37018. * }
  37019. *
  37020. * @static
  37021. * @param {Object} dataRoot Root node.
  37022. * @param {module:echarts/model/Model} hostModel
  37023. * @param {Object} treeOptions
  37024. * @param {Array.<Object>} treeOptions.levels
  37025. * @return module:echarts/data/Tree
  37026. */
  37027. Tree.createTree = function (dataRoot, hostModel, treeOptions, beforeLink) {
  37028. var tree = new Tree(hostModel, treeOptions && treeOptions.levels);
  37029. var listData = [];
  37030. var dimMax = 1;
  37031. buildHierarchy(dataRoot);
  37032. function buildHierarchy(dataNode, parentNode) {
  37033. var value = dataNode.value;
  37034. dimMax = Math.max(dimMax, isArray(value) ? value.length : 1);
  37035. listData.push(dataNode);
  37036. var node = new TreeNode(dataNode.name, tree);
  37037. parentNode ? addChild(node, parentNode) : tree.root = node;
  37038. tree._nodes.push(node);
  37039. var children = dataNode.children;
  37040. if (children) {
  37041. for (var i = 0; i < children.length; i++) {
  37042. buildHierarchy(children[i], node);
  37043. }
  37044. }
  37045. }
  37046. tree.root.updateDepthAndHeight(0);
  37047. var dimensionsInfo = createDimensions(listData, {
  37048. coordDimensions: ['value'],
  37049. dimensionsCount: dimMax
  37050. });
  37051. var list = new List(dimensionsInfo, hostModel);
  37052. list.initData(listData);
  37053. beforeLink && beforeLink(list);
  37054. linkList({
  37055. mainData: list,
  37056. struct: tree,
  37057. structAttr: 'tree'
  37058. });
  37059. tree.update();
  37060. return tree;
  37061. };
  37062. /**
  37063. * It is needed to consider the mess of 'list', 'hostModel' when creating a TreeNote,
  37064. * so this function is not ready and not necessary to be public.
  37065. *
  37066. * @param {(module:echarts/data/Tree~TreeNode|Object)} child
  37067. */
  37068. function addChild(child, node) {
  37069. var children = node.children;
  37070. if (child.parentNode === node) {
  37071. return;
  37072. }
  37073. children.push(child);
  37074. child.parentNode = node;
  37075. }
  37076. /*
  37077. * Licensed to the Apache Software Foundation (ASF) under one
  37078. * or more contributor license agreements. See the NOTICE file
  37079. * distributed with this work for additional information
  37080. * regarding copyright ownership. The ASF licenses this file
  37081. * to you under the Apache License, Version 2.0 (the
  37082. * "License"); you may not use this file except in compliance
  37083. * with the License. You may obtain a copy of the License at
  37084. *
  37085. * http://www.apache.org/licenses/LICENSE-2.0
  37086. *
  37087. * Unless required by applicable law or agreed to in writing,
  37088. * software distributed under the License is distributed on an
  37089. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37090. * KIND, either express or implied. See the License for the
  37091. * specific language governing permissions and limitations
  37092. * under the License.
  37093. */
  37094. SeriesModel.extend({
  37095. type: 'series.tree',
  37096. layoutInfo: null,
  37097. // can support the position parameters 'left', 'top','right','bottom', 'width',
  37098. // 'height' in the setOption() with 'merge' mode normal.
  37099. layoutMode: 'box',
  37100. /**
  37101. * Init a tree data structure from data in option series
  37102. * @param {Object} option the object used to config echarts view
  37103. * @return {module:echarts/data/List} storage initial data
  37104. */
  37105. getInitialData: function (option) {
  37106. //create an virtual root
  37107. var root = {
  37108. name: option.name,
  37109. children: option.data
  37110. };
  37111. var leaves = option.leaves || {};
  37112. var leavesModel = new Model(leaves, this, this.ecModel);
  37113. var tree = Tree.createTree(root, this, {}, beforeLink);
  37114. function beforeLink(nodeData) {
  37115. nodeData.wrapMethod('getItemModel', function (model, idx) {
  37116. var node = tree.getNodeByDataIndex(idx);
  37117. if (!node.children.length || !node.isExpand) {
  37118. model.parentModel = leavesModel;
  37119. }
  37120. return model;
  37121. });
  37122. }
  37123. var treeDepth = 0;
  37124. tree.eachNode('preorder', function (node) {
  37125. if (node.depth > treeDepth) {
  37126. treeDepth = node.depth;
  37127. }
  37128. });
  37129. var expandAndCollapse = option.expandAndCollapse;
  37130. var expandTreeDepth = expandAndCollapse && option.initialTreeDepth >= 0 ? option.initialTreeDepth : treeDepth;
  37131. tree.root.eachNode('preorder', function (node) {
  37132. var item = node.hostTree.data.getRawDataItem(node.dataIndex); // Add item.collapsed != null, because users can collapse node original in the series.data.
  37133. node.isExpand = item && item.collapsed != null ? !item.collapsed : node.depth <= expandTreeDepth;
  37134. });
  37135. return tree.data;
  37136. },
  37137. /**
  37138. * Make the configuration 'orient' backward compatibly, with 'horizontal = LR', 'vertical = TB'.
  37139. * @returns {string} orient
  37140. */
  37141. getOrient: function () {
  37142. var orient = this.get('orient');
  37143. if (orient === 'horizontal') {
  37144. orient = 'LR';
  37145. } else if (orient === 'vertical') {
  37146. orient = 'TB';
  37147. }
  37148. return orient;
  37149. },
  37150. setZoom: function (zoom) {
  37151. this.option.zoom = zoom;
  37152. },
  37153. setCenter: function (center) {
  37154. this.option.center = center;
  37155. },
  37156. /**
  37157. * @override
  37158. * @param {number} dataIndex
  37159. */
  37160. formatTooltip: function (dataIndex) {
  37161. var tree = this.getData().tree;
  37162. var realRoot = tree.root.children[0];
  37163. var node = tree.getNodeByDataIndex(dataIndex);
  37164. var value = node.getValue();
  37165. var name = node.name;
  37166. while (node && node !== realRoot) {
  37167. name = node.parentNode.name + '.' + name;
  37168. node = node.parentNode;
  37169. }
  37170. return encodeHTML(name + (isNaN(value) || value == null ? '' : ' : ' + value));
  37171. },
  37172. defaultOption: {
  37173. zlevel: 0,
  37174. z: 2,
  37175. coordinateSystem: 'view',
  37176. // the position of the whole view
  37177. left: '12%',
  37178. top: '12%',
  37179. right: '12%',
  37180. bottom: '12%',
  37181. // the layout of the tree, two value can be selected, 'orthogonal' or 'radial'
  37182. layout: 'orthogonal',
  37183. // value can be 'polyline'
  37184. edgeShape: 'curve',
  37185. edgeForkPosition: '50%',
  37186. // true | false | 'move' | 'scale', see module:component/helper/RoamController.
  37187. roam: false,
  37188. // Symbol size scale ratio in roam
  37189. nodeScaleRatio: 0.4,
  37190. // Default on center of graph
  37191. center: null,
  37192. zoom: 1,
  37193. // The orient of orthoginal layout, can be setted to 'LR', 'TB', 'RL', 'BT'.
  37194. // and the backward compatibility configuration 'horizontal = LR', 'vertical = TB'.
  37195. orient: 'LR',
  37196. symbol: 'emptyCircle',
  37197. symbolSize: 7,
  37198. expandAndCollapse: true,
  37199. initialTreeDepth: 2,
  37200. lineStyle: {
  37201. color: '#ccc',
  37202. width: 1.5,
  37203. curveness: 0.5
  37204. },
  37205. itemStyle: {
  37206. color: 'lightsteelblue',
  37207. borderColor: '#c23531',
  37208. borderWidth: 1.5
  37209. },
  37210. label: {
  37211. show: true,
  37212. color: '#555'
  37213. },
  37214. leaves: {
  37215. label: {
  37216. show: true
  37217. }
  37218. },
  37219. animationEasing: 'linear',
  37220. animationDuration: 700,
  37221. animationDurationUpdate: 1000
  37222. }
  37223. });
  37224. /*
  37225. * Licensed to the Apache Software Foundation (ASF) under one
  37226. * or more contributor license agreements. See the NOTICE file
  37227. * distributed with this work for additional information
  37228. * regarding copyright ownership. The ASF licenses this file
  37229. * to you under the Apache License, Version 2.0 (the
  37230. * "License"); you may not use this file except in compliance
  37231. * with the License. You may obtain a copy of the License at
  37232. *
  37233. * http://www.apache.org/licenses/LICENSE-2.0
  37234. *
  37235. * Unless required by applicable law or agreed to in writing,
  37236. * software distributed under the License is distributed on an
  37237. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37238. * KIND, either express or implied. See the License for the
  37239. * specific language governing permissions and limitations
  37240. * under the License.
  37241. */
  37242. /*
  37243. * A third-party license is embeded for some of the code in this file:
  37244. * The tree layoutHelper implementation was originally copied from
  37245. * "d3.js"(https://github.com/d3/d3-hierarchy) with
  37246. * some modifications made for this project.
  37247. * (see more details in the comment of the specific method below.)
  37248. * The use of the source code of this file is also subject to the terms
  37249. * and consitions of the licence of "d3.js" (BSD-3Clause, see
  37250. * </licenses/LICENSE-d3>).
  37251. */
  37252. /**
  37253. * @file The layout algorithm of node-link tree diagrams. Here we using Reingold-Tilford algorithm to drawing
  37254. * the tree.
  37255. */
  37256. /**
  37257. * Initialize all computational message for following algorithm.
  37258. *
  37259. * @param {module:echarts/data/Tree~TreeNode} root The virtual root of the tree.
  37260. */
  37261. function init$2(root) {
  37262. root.hierNode = {
  37263. defaultAncestor: null,
  37264. ancestor: root,
  37265. prelim: 0,
  37266. modifier: 0,
  37267. change: 0,
  37268. shift: 0,
  37269. i: 0,
  37270. thread: null
  37271. };
  37272. var nodes = [root];
  37273. var node;
  37274. var children;
  37275. while (node = nodes.pop()) {
  37276. // jshint ignore:line
  37277. children = node.children;
  37278. if (node.isExpand && children.length) {
  37279. var n = children.length;
  37280. for (var i = n - 1; i >= 0; i--) {
  37281. var child = children[i];
  37282. child.hierNode = {
  37283. defaultAncestor: null,
  37284. ancestor: child,
  37285. prelim: 0,
  37286. modifier: 0,
  37287. change: 0,
  37288. shift: 0,
  37289. i: i,
  37290. thread: null
  37291. };
  37292. nodes.push(child);
  37293. }
  37294. }
  37295. }
  37296. }
  37297. /**
  37298. * The implementation of this function was originally copied from "d3.js"
  37299. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  37300. * with some modifications made for this program.
  37301. * See the license statement at the head of this file.
  37302. *
  37303. * Computes a preliminary x coordinate for node. Before that, this function is
  37304. * applied recursively to the children of node, as well as the function
  37305. * apportion(). After spacing out the children by calling executeShifts(), the
  37306. * node is placed to the midpoint of its outermost children.
  37307. *
  37308. * @param {module:echarts/data/Tree~TreeNode} node
  37309. * @param {Function} separation
  37310. */
  37311. function firstWalk(node, separation) {
  37312. var children = node.isExpand ? node.children : [];
  37313. var siblings = node.parentNode.children;
  37314. var subtreeW = node.hierNode.i ? siblings[node.hierNode.i - 1] : null;
  37315. if (children.length) {
  37316. executeShifts(node);
  37317. var midPoint = (children[0].hierNode.prelim + children[children.length - 1].hierNode.prelim) / 2;
  37318. if (subtreeW) {
  37319. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  37320. node.hierNode.modifier = node.hierNode.prelim - midPoint;
  37321. } else {
  37322. node.hierNode.prelim = midPoint;
  37323. }
  37324. } else if (subtreeW) {
  37325. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  37326. }
  37327. node.parentNode.hierNode.defaultAncestor = apportion(node, subtreeW, node.parentNode.hierNode.defaultAncestor || siblings[0], separation);
  37328. }
  37329. /**
  37330. * The implementation of this function was originally copied from "d3.js"
  37331. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  37332. * with some modifications made for this program.
  37333. * See the license statement at the head of this file.
  37334. *
  37335. * Computes all real x-coordinates by summing up the modifiers recursively.
  37336. *
  37337. * @param {module:echarts/data/Tree~TreeNode} node
  37338. */
  37339. function secondWalk(node) {
  37340. var nodeX = node.hierNode.prelim + node.parentNode.hierNode.modifier;
  37341. node.setLayout({
  37342. x: nodeX
  37343. }, true);
  37344. node.hierNode.modifier += node.parentNode.hierNode.modifier;
  37345. }
  37346. function separation(cb) {
  37347. return arguments.length ? cb : defaultSeparation;
  37348. }
  37349. /**
  37350. * Transform the common coordinate to radial coordinate.
  37351. *
  37352. * @param {number} x
  37353. * @param {number} y
  37354. * @return {Object}
  37355. */
  37356. function radialCoordinate(x, y) {
  37357. var radialCoor = {};
  37358. x -= Math.PI / 2;
  37359. radialCoor.x = y * Math.cos(x);
  37360. radialCoor.y = y * Math.sin(x);
  37361. return radialCoor;
  37362. }
  37363. /**
  37364. * Get the layout position of the whole view.
  37365. *
  37366. * @param {module:echarts/model/Series} seriesModel the model object of sankey series
  37367. * @param {module:echarts/ExtensionAPI} api provide the API list that the developer can call
  37368. * @return {module:zrender/core/BoundingRect} size of rect to draw the sankey view
  37369. */
  37370. function getViewRect$1(seriesModel, api) {
  37371. return getLayoutRect(seriesModel.getBoxLayoutParams(), {
  37372. width: api.getWidth(),
  37373. height: api.getHeight()
  37374. });
  37375. }
  37376. /**
  37377. * All other shifts, applied to the smaller subtrees between w- and w+, are
  37378. * performed by this function.
  37379. *
  37380. * The implementation of this function was originally copied from "d3.js"
  37381. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  37382. * with some modifications made for this program.
  37383. * See the license statement at the head of this file.
  37384. *
  37385. * @param {module:echarts/data/Tree~TreeNode} node
  37386. */
  37387. function executeShifts(node) {
  37388. var children = node.children;
  37389. var n = children.length;
  37390. var shift = 0;
  37391. var change = 0;
  37392. while (--n >= 0) {
  37393. var child = children[n];
  37394. child.hierNode.prelim += shift;
  37395. child.hierNode.modifier += shift;
  37396. change += child.hierNode.change;
  37397. shift += child.hierNode.shift + change;
  37398. }
  37399. }
  37400. /**
  37401. * The implementation of this function was originally copied from "d3.js"
  37402. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  37403. * with some modifications made for this program.
  37404. * See the license statement at the head of this file.
  37405. *
  37406. * The core of the algorithm. Here, a new subtree is combined with the
  37407. * previous subtrees. Threads are used to traverse the inside and outside
  37408. * contours of the left and right subtree up to the highest common level.
  37409. * Whenever two nodes of the inside contours conflict, we compute the left
  37410. * one of the greatest uncommon ancestors using the function nextAncestor()
  37411. * and call moveSubtree() to shift the subtree and prepare the shifts of
  37412. * smaller subtrees. Finally, we add a new thread (if necessary).
  37413. *
  37414. * @param {module:echarts/data/Tree~TreeNode} subtreeV
  37415. * @param {module:echarts/data/Tree~TreeNode} subtreeW
  37416. * @param {module:echarts/data/Tree~TreeNode} ancestor
  37417. * @param {Function} separation
  37418. * @return {module:echarts/data/Tree~TreeNode}
  37419. */
  37420. function apportion(subtreeV, subtreeW, ancestor, separation) {
  37421. if (subtreeW) {
  37422. var nodeOutRight = subtreeV;
  37423. var nodeInRight = subtreeV;
  37424. var nodeOutLeft = nodeInRight.parentNode.children[0];
  37425. var nodeInLeft = subtreeW;
  37426. var sumOutRight = nodeOutRight.hierNode.modifier;
  37427. var sumInRight = nodeInRight.hierNode.modifier;
  37428. var sumOutLeft = nodeOutLeft.hierNode.modifier;
  37429. var sumInLeft = nodeInLeft.hierNode.modifier;
  37430. while (nodeInLeft = nextRight(nodeInLeft), nodeInRight = nextLeft(nodeInRight), nodeInLeft && nodeInRight) {
  37431. nodeOutRight = nextRight(nodeOutRight);
  37432. nodeOutLeft = nextLeft(nodeOutLeft);
  37433. nodeOutRight.hierNode.ancestor = subtreeV;
  37434. var shift = nodeInLeft.hierNode.prelim + sumInLeft - nodeInRight.hierNode.prelim - sumInRight + separation(nodeInLeft, nodeInRight);
  37435. if (shift > 0) {
  37436. moveSubtree(nextAncestor(nodeInLeft, subtreeV, ancestor), subtreeV, shift);
  37437. sumInRight += shift;
  37438. sumOutRight += shift;
  37439. }
  37440. sumInLeft += nodeInLeft.hierNode.modifier;
  37441. sumInRight += nodeInRight.hierNode.modifier;
  37442. sumOutRight += nodeOutRight.hierNode.modifier;
  37443. sumOutLeft += nodeOutLeft.hierNode.modifier;
  37444. }
  37445. if (nodeInLeft && !nextRight(nodeOutRight)) {
  37446. nodeOutRight.hierNode.thread = nodeInLeft;
  37447. nodeOutRight.hierNode.modifier += sumInLeft - sumOutRight;
  37448. }
  37449. if (nodeInRight && !nextLeft(nodeOutLeft)) {
  37450. nodeOutLeft.hierNode.thread = nodeInRight;
  37451. nodeOutLeft.hierNode.modifier += sumInRight - sumOutLeft;
  37452. ancestor = subtreeV;
  37453. }
  37454. }
  37455. return ancestor;
  37456. }
  37457. /**
  37458. * This function is used to traverse the right contour of a subtree.
  37459. * It returns the rightmost child of node or the thread of node. The function
  37460. * returns null if and only if node is on the highest depth of its subtree.
  37461. *
  37462. * @param {module:echarts/data/Tree~TreeNode} node
  37463. * @return {module:echarts/data/Tree~TreeNode}
  37464. */
  37465. function nextRight(node) {
  37466. var children = node.children;
  37467. return children.length && node.isExpand ? children[children.length - 1] : node.hierNode.thread;
  37468. }
  37469. /**
  37470. * This function is used to traverse the left contour of a subtree (or a subforest).
  37471. * It returns the leftmost child of node or the thread of node. The function
  37472. * returns null if and only if node is on the highest depth of its subtree.
  37473. *
  37474. * @param {module:echarts/data/Tree~TreeNode} node
  37475. * @return {module:echarts/data/Tree~TreeNode}
  37476. */
  37477. function nextLeft(node) {
  37478. var children = node.children;
  37479. return children.length && node.isExpand ? children[0] : node.hierNode.thread;
  37480. }
  37481. /**
  37482. * If nodeInLeft’s ancestor is a sibling of node, returns nodeInLeft’s ancestor.
  37483. * Otherwise, returns the specified ancestor.
  37484. *
  37485. * @param {module:echarts/data/Tree~TreeNode} nodeInLeft
  37486. * @param {module:echarts/data/Tree~TreeNode} node
  37487. * @param {module:echarts/data/Tree~TreeNode} ancestor
  37488. * @return {module:echarts/data/Tree~TreeNode}
  37489. */
  37490. function nextAncestor(nodeInLeft, node, ancestor) {
  37491. return nodeInLeft.hierNode.ancestor.parentNode === node.parentNode ? nodeInLeft.hierNode.ancestor : ancestor;
  37492. }
  37493. /**
  37494. * The implementation of this function was originally copied from "d3.js"
  37495. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  37496. * with some modifications made for this program.
  37497. * See the license statement at the head of this file.
  37498. *
  37499. * Shifts the current subtree rooted at wr.
  37500. * This is done by increasing prelim(w+) and modifier(w+) by shift.
  37501. *
  37502. * @param {module:echarts/data/Tree~TreeNode} wl
  37503. * @param {module:echarts/data/Tree~TreeNode} wr
  37504. * @param {number} shift [description]
  37505. */
  37506. function moveSubtree(wl, wr, shift) {
  37507. var change = shift / (wr.hierNode.i - wl.hierNode.i);
  37508. wr.hierNode.change -= change;
  37509. wr.hierNode.shift += shift;
  37510. wr.hierNode.modifier += shift;
  37511. wr.hierNode.prelim += shift;
  37512. wl.hierNode.change += change;
  37513. }
  37514. /**
  37515. * The implementation of this function was originally copied from "d3.js"
  37516. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  37517. * with some modifications made for this program.
  37518. * See the license statement at the head of this file.
  37519. */
  37520. function defaultSeparation(node1, node2) {
  37521. return node1.parentNode === node2.parentNode ? 1 : 2;
  37522. }
  37523. /*
  37524. * Licensed to the Apache Software Foundation (ASF) under one
  37525. * or more contributor license agreements. See the NOTICE file
  37526. * distributed with this work for additional information
  37527. * regarding copyright ownership. The ASF licenses this file
  37528. * to you under the Apache License, Version 2.0 (the
  37529. * "License"); you may not use this file except in compliance
  37530. * with the License. You may obtain a copy of the License at
  37531. *
  37532. * http://www.apache.org/licenses/LICENSE-2.0
  37533. *
  37534. * Unless required by applicable law or agreed to in writing,
  37535. * software distributed under the License is distributed on an
  37536. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37537. * KIND, either express or implied. See the License for the
  37538. * specific language governing permissions and limitations
  37539. * under the License.
  37540. */
  37541. /**
  37542. * Simple view coordinate system
  37543. * Mapping given x, y to transformd view x, y
  37544. */
  37545. var v2ApplyTransform$1 = applyTransform; // Dummy transform node
  37546. function TransformDummy() {
  37547. Transformable.call(this);
  37548. }
  37549. mixin(TransformDummy, Transformable);
  37550. function View(name) {
  37551. /**
  37552. * @type {string}
  37553. */
  37554. this.name = name;
  37555. /**
  37556. * @type {Object}
  37557. */
  37558. this.zoomLimit;
  37559. Transformable.call(this);
  37560. this._roamTransformable = new TransformDummy();
  37561. this._rawTransformable = new TransformDummy();
  37562. this._center;
  37563. this._zoom;
  37564. }
  37565. View.prototype = {
  37566. constructor: View,
  37567. type: 'view',
  37568. /**
  37569. * @param {Array.<string>}
  37570. * @readOnly
  37571. */
  37572. dimensions: ['x', 'y'],
  37573. /**
  37574. * Set bounding rect
  37575. * @param {number} x
  37576. * @param {number} y
  37577. * @param {number} width
  37578. * @param {number} height
  37579. */
  37580. // PENDING to getRect
  37581. setBoundingRect: function (x, y, width, height) {
  37582. this._rect = new BoundingRect(x, y, width, height);
  37583. return this._rect;
  37584. },
  37585. /**
  37586. * @return {module:zrender/core/BoundingRect}
  37587. */
  37588. // PENDING to getRect
  37589. getBoundingRect: function () {
  37590. return this._rect;
  37591. },
  37592. /**
  37593. * @param {number} x
  37594. * @param {number} y
  37595. * @param {number} width
  37596. * @param {number} height
  37597. */
  37598. setViewRect: function (x, y, width, height) {
  37599. this.transformTo(x, y, width, height);
  37600. this._viewRect = new BoundingRect(x, y, width, height);
  37601. },
  37602. /**
  37603. * Transformed to particular position and size
  37604. * @param {number} x
  37605. * @param {number} y
  37606. * @param {number} width
  37607. * @param {number} height
  37608. */
  37609. transformTo: function (x, y, width, height) {
  37610. var rect = this.getBoundingRect();
  37611. var rawTransform = this._rawTransformable;
  37612. rawTransform.transform = rect.calculateTransform(new BoundingRect(x, y, width, height));
  37613. rawTransform.decomposeTransform();
  37614. this._updateTransform();
  37615. },
  37616. /**
  37617. * Set center of view
  37618. * @param {Array.<number>} [centerCoord]
  37619. */
  37620. setCenter: function (centerCoord) {
  37621. if (!centerCoord) {
  37622. return;
  37623. }
  37624. this._center = centerCoord;
  37625. this._updateCenterAndZoom();
  37626. },
  37627. /**
  37628. * @param {number} zoom
  37629. */
  37630. setZoom: function (zoom) {
  37631. zoom = zoom || 1;
  37632. var zoomLimit = this.zoomLimit;
  37633. if (zoomLimit) {
  37634. if (zoomLimit.max != null) {
  37635. zoom = Math.min(zoomLimit.max, zoom);
  37636. }
  37637. if (zoomLimit.min != null) {
  37638. zoom = Math.max(zoomLimit.min, zoom);
  37639. }
  37640. }
  37641. this._zoom = zoom;
  37642. this._updateCenterAndZoom();
  37643. },
  37644. /**
  37645. * Get default center without roam
  37646. */
  37647. getDefaultCenter: function () {
  37648. // Rect before any transform
  37649. var rawRect = this.getBoundingRect();
  37650. var cx = rawRect.x + rawRect.width / 2;
  37651. var cy = rawRect.y + rawRect.height / 2;
  37652. return [cx, cy];
  37653. },
  37654. getCenter: function () {
  37655. return this._center || this.getDefaultCenter();
  37656. },
  37657. getZoom: function () {
  37658. return this._zoom || 1;
  37659. },
  37660. /**
  37661. * @return {Array.<number}
  37662. */
  37663. getRoamTransform: function () {
  37664. return this._roamTransformable.getLocalTransform();
  37665. },
  37666. /**
  37667. * Remove roam
  37668. */
  37669. _updateCenterAndZoom: function () {
  37670. // Must update after view transform updated
  37671. var rawTransformMatrix = this._rawTransformable.getLocalTransform();
  37672. var roamTransform = this._roamTransformable;
  37673. var defaultCenter = this.getDefaultCenter();
  37674. var center = this.getCenter();
  37675. var zoom = this.getZoom();
  37676. center = applyTransform([], center, rawTransformMatrix);
  37677. defaultCenter = applyTransform([], defaultCenter, rawTransformMatrix);
  37678. roamTransform.origin = center;
  37679. roamTransform.position = [defaultCenter[0] - center[0], defaultCenter[1] - center[1]];
  37680. roamTransform.scale = [zoom, zoom];
  37681. this._updateTransform();
  37682. },
  37683. /**
  37684. * Update transform from roam and mapLocation
  37685. * @private
  37686. */
  37687. _updateTransform: function () {
  37688. var roamTransformable = this._roamTransformable;
  37689. var rawTransformable = this._rawTransformable;
  37690. rawTransformable.parent = roamTransformable;
  37691. roamTransformable.updateTransform();
  37692. rawTransformable.updateTransform();
  37693. copy$1(this.transform || (this.transform = []), rawTransformable.transform || create$1());
  37694. this._rawTransform = rawTransformable.getLocalTransform();
  37695. this.invTransform = this.invTransform || [];
  37696. invert(this.invTransform, this.transform);
  37697. this.decomposeTransform();
  37698. },
  37699. getTransformInfo: function () {
  37700. var roamTransform = this._roamTransformable.transform;
  37701. var rawTransformable = this._rawTransformable;
  37702. return {
  37703. roamTransform: roamTransform ? slice(roamTransform) : create$1(),
  37704. rawScale: slice(rawTransformable.scale),
  37705. rawPosition: slice(rawTransformable.position)
  37706. };
  37707. },
  37708. /**
  37709. * @return {module:zrender/core/BoundingRect}
  37710. */
  37711. getViewRect: function () {
  37712. return this._viewRect;
  37713. },
  37714. /**
  37715. * Get view rect after roam transform
  37716. * @return {module:zrender/core/BoundingRect}
  37717. */
  37718. getViewRectAfterRoam: function () {
  37719. var rect = this.getBoundingRect().clone();
  37720. rect.applyTransform(this.transform);
  37721. return rect;
  37722. },
  37723. /**
  37724. * Convert a single (lon, lat) data item to (x, y) point.
  37725. * @param {Array.<number>} data
  37726. * @param {boolean} noRoam
  37727. * @param {Array.<number>} [out]
  37728. * @return {Array.<number>}
  37729. */
  37730. dataToPoint: function (data, noRoam, out) {
  37731. var transform = noRoam ? this._rawTransform : this.transform;
  37732. out = out || [];
  37733. return transform ? v2ApplyTransform$1(out, data, transform) : copy(out, data);
  37734. },
  37735. /**
  37736. * Convert a (x, y) point to (lon, lat) data
  37737. * @param {Array.<number>} point
  37738. * @return {Array.<number>}
  37739. */
  37740. pointToData: function (point) {
  37741. var invTransform = this.invTransform;
  37742. return invTransform ? v2ApplyTransform$1([], point, invTransform) : [point[0], point[1]];
  37743. },
  37744. /**
  37745. * @implements
  37746. * see {module:echarts/CoodinateSystem}
  37747. */
  37748. convertToPixel: curry(doConvert, 'dataToPoint'),
  37749. /**
  37750. * @implements
  37751. * see {module:echarts/CoodinateSystem}
  37752. */
  37753. convertFromPixel: curry(doConvert, 'pointToData'),
  37754. /**
  37755. * @implements
  37756. * see {module:echarts/CoodinateSystem}
  37757. */
  37758. containPoint: function (point) {
  37759. return this.getViewRectAfterRoam().contain(point[0], point[1]);
  37760. }
  37761. /**
  37762. * @return {number}
  37763. */
  37764. // getScalarScale: function () {
  37765. // // Use determinant square root of transform to mutiply scalar
  37766. // var m = this.transform;
  37767. // var det = Math.sqrt(Math.abs(m[0] * m[3] - m[2] * m[1]));
  37768. // return det;
  37769. // }
  37770. };
  37771. mixin(View, Transformable);
  37772. function doConvert(methodName, ecModel, finder, value) {
  37773. var seriesModel = finder.seriesModel;
  37774. var coordSys = seriesModel ? seriesModel.coordinateSystem : null; // e.g., graph.
  37775. return coordSys === this ? coordSys[methodName](value) : null;
  37776. }
  37777. /*
  37778. * Licensed to the Apache Software Foundation (ASF) under one
  37779. * or more contributor license agreements. See the NOTICE file
  37780. * distributed with this work for additional information
  37781. * regarding copyright ownership. The ASF licenses this file
  37782. * to you under the Apache License, Version 2.0 (the
  37783. * "License"); you may not use this file except in compliance
  37784. * with the License. You may obtain a copy of the License at
  37785. *
  37786. * http://www.apache.org/licenses/LICENSE-2.0
  37787. *
  37788. * Unless required by applicable law or agreed to in writing,
  37789. * software distributed under the License is distributed on an
  37790. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37791. * KIND, either express or implied. See the License for the
  37792. * specific language governing permissions and limitations
  37793. * under the License.
  37794. */
  37795. /**
  37796. * For geo and graph.
  37797. *
  37798. * @param {Object} controllerHost
  37799. * @param {module:zrender/Element} controllerHost.target
  37800. */
  37801. function updateViewOnPan(controllerHost, dx, dy) {
  37802. var target = controllerHost.target;
  37803. var pos = target.position;
  37804. pos[0] += dx;
  37805. pos[1] += dy;
  37806. target.dirty();
  37807. }
  37808. /**
  37809. * For geo and graph.
  37810. *
  37811. * @param {Object} controllerHost
  37812. * @param {module:zrender/Element} controllerHost.target
  37813. * @param {number} controllerHost.zoom
  37814. * @param {number} controllerHost.zoomLimit like: {min: 1, max: 2}
  37815. */
  37816. function updateViewOnZoom(controllerHost, zoomDelta, zoomX, zoomY) {
  37817. var target = controllerHost.target;
  37818. var zoomLimit = controllerHost.zoomLimit;
  37819. var pos = target.position;
  37820. var scale = target.scale;
  37821. var newZoom = controllerHost.zoom = controllerHost.zoom || 1;
  37822. newZoom *= zoomDelta;
  37823. if (zoomLimit) {
  37824. var zoomMin = zoomLimit.min || 0;
  37825. var zoomMax = zoomLimit.max || Infinity;
  37826. newZoom = Math.max(Math.min(zoomMax, newZoom), zoomMin);
  37827. }
  37828. var zoomScale = newZoom / controllerHost.zoom;
  37829. controllerHost.zoom = newZoom; // Keep the mouse center when scaling
  37830. pos[0] -= (zoomX - pos[0]) * (zoomScale - 1);
  37831. pos[1] -= (zoomY - pos[1]) * (zoomScale - 1);
  37832. scale[0] *= zoomScale;
  37833. scale[1] *= zoomScale;
  37834. target.dirty();
  37835. }
  37836. /*
  37837. * Licensed to the Apache Software Foundation (ASF) under one
  37838. * or more contributor license agreements. See the NOTICE file
  37839. * distributed with this work for additional information
  37840. * regarding copyright ownership. The ASF licenses this file
  37841. * to you under the Apache License, Version 2.0 (the
  37842. * "License"); you may not use this file except in compliance
  37843. * with the License. You may obtain a copy of the License at
  37844. *
  37845. * http://www.apache.org/licenses/LICENSE-2.0
  37846. *
  37847. * Unless required by applicable law or agreed to in writing,
  37848. * software distributed under the License is distributed on an
  37849. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37850. * KIND, either express or implied. See the License for the
  37851. * specific language governing permissions and limitations
  37852. * under the License.
  37853. */
  37854. var ATTR = '\0_ec_interaction_mutex';
  37855. function take(zr, resourceKey, userKey) {
  37856. var store = getStore(zr);
  37857. store[resourceKey] = userKey;
  37858. }
  37859. function release(zr, resourceKey, userKey) {
  37860. var store = getStore(zr);
  37861. var uKey = store[resourceKey];
  37862. if (uKey === userKey) {
  37863. store[resourceKey] = null;
  37864. }
  37865. }
  37866. function isTaken(zr, resourceKey) {
  37867. return !!getStore(zr)[resourceKey];
  37868. }
  37869. function getStore(zr) {
  37870. return zr[ATTR] || (zr[ATTR] = {});
  37871. }
  37872. /**
  37873. * payload: {
  37874. * type: 'takeGlobalCursor',
  37875. * key: 'dataZoomSelect', or 'brush', or ...,
  37876. * If no userKey, release global cursor.
  37877. * }
  37878. */
  37879. registerAction({
  37880. type: 'takeGlobalCursor',
  37881. event: 'globalCursorTaken',
  37882. update: 'update'
  37883. }, function () {});
  37884. /*
  37885. * Licensed to the Apache Software Foundation (ASF) under one
  37886. * or more contributor license agreements. See the NOTICE file
  37887. * distributed with this work for additional information
  37888. * regarding copyright ownership. The ASF licenses this file
  37889. * to you under the Apache License, Version 2.0 (the
  37890. * "License"); you may not use this file except in compliance
  37891. * with the License. You may obtain a copy of the License at
  37892. *
  37893. * http://www.apache.org/licenses/LICENSE-2.0
  37894. *
  37895. * Unless required by applicable law or agreed to in writing,
  37896. * software distributed under the License is distributed on an
  37897. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37898. * KIND, either express or implied. See the License for the
  37899. * specific language governing permissions and limitations
  37900. * under the License.
  37901. */
  37902. /**
  37903. * @alias module:echarts/component/helper/RoamController
  37904. * @constructor
  37905. * @mixin {module:zrender/mixin/Eventful}
  37906. *
  37907. * @param {module:zrender/zrender~ZRender} zr
  37908. */
  37909. function RoamController(zr) {
  37910. /**
  37911. * @type {Function}
  37912. */
  37913. this.pointerChecker;
  37914. /**
  37915. * @type {module:zrender}
  37916. */
  37917. this._zr = zr;
  37918. /**
  37919. * @type {Object}
  37920. */
  37921. this._opt = {}; // Avoid two roamController bind the same handler
  37922. var bind$$1 = bind;
  37923. var mousedownHandler = bind$$1(mousedown, this);
  37924. var mousemoveHandler = bind$$1(mousemove, this);
  37925. var mouseupHandler = bind$$1(mouseup, this);
  37926. var mousewheelHandler = bind$$1(mousewheel, this);
  37927. var pinchHandler = bind$$1(pinch, this);
  37928. Eventful.call(this);
  37929. /**
  37930. * @param {Function} pointerChecker
  37931. * input: x, y
  37932. * output: boolean
  37933. */
  37934. this.setPointerChecker = function (pointerChecker) {
  37935. this.pointerChecker = pointerChecker;
  37936. };
  37937. /**
  37938. * Notice: only enable needed types. For example, if 'zoom'
  37939. * is not needed, 'zoom' should not be enabled, otherwise
  37940. * default mousewheel behaviour (scroll page) will be disabled.
  37941. *
  37942. * @param {boolean|string} [controlType=true] Specify the control type,
  37943. * which can be null/undefined or true/false
  37944. * or 'pan/move' or 'zoom'/'scale'
  37945. * @param {Object} [opt]
  37946. * @param {Object} [opt.zoomOnMouseWheel=true] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  37947. * @param {Object} [opt.moveOnMouseMove=true] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  37948. * @param {Object} [opt.moveOnMouseWheel=false] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  37949. * @param {Object} [opt.preventDefaultMouseMove=true] When pan.
  37950. */
  37951. this.enable = function (controlType, opt) {
  37952. // Disable previous first
  37953. this.disable();
  37954. this._opt = defaults(clone(opt) || {}, {
  37955. zoomOnMouseWheel: true,
  37956. moveOnMouseMove: true,
  37957. // By default, wheel do not trigger move.
  37958. moveOnMouseWheel: false,
  37959. preventDefaultMouseMove: true
  37960. });
  37961. if (controlType == null) {
  37962. controlType = true;
  37963. }
  37964. if (controlType === true || controlType === 'move' || controlType === 'pan') {
  37965. zr.on('mousedown', mousedownHandler);
  37966. zr.on('mousemove', mousemoveHandler);
  37967. zr.on('mouseup', mouseupHandler);
  37968. }
  37969. if (controlType === true || controlType === 'scale' || controlType === 'zoom') {
  37970. zr.on('mousewheel', mousewheelHandler);
  37971. zr.on('pinch', pinchHandler);
  37972. }
  37973. };
  37974. this.disable = function () {
  37975. zr.off('mousedown', mousedownHandler);
  37976. zr.off('mousemove', mousemoveHandler);
  37977. zr.off('mouseup', mouseupHandler);
  37978. zr.off('mousewheel', mousewheelHandler);
  37979. zr.off('pinch', pinchHandler);
  37980. };
  37981. this.dispose = this.disable;
  37982. this.isDragging = function () {
  37983. return this._dragging;
  37984. };
  37985. this.isPinching = function () {
  37986. return this._pinching;
  37987. };
  37988. }
  37989. mixin(RoamController, Eventful);
  37990. function mousedown(e) {
  37991. if (isMiddleOrRightButtonOnMouseUpDown(e) || e.target && e.target.draggable) {
  37992. return;
  37993. }
  37994. var x = e.offsetX;
  37995. var y = e.offsetY; // Only check on mosedown, but not mousemove.
  37996. // Mouse can be out of target when mouse moving.
  37997. if (this.pointerChecker && this.pointerChecker(e, x, y)) {
  37998. this._x = x;
  37999. this._y = y;
  38000. this._dragging = true;
  38001. }
  38002. }
  38003. function mousemove(e) {
  38004. if (!this._dragging || !isAvailableBehavior('moveOnMouseMove', e, this._opt) || e.gestureEvent === 'pinch' || isTaken(this._zr, 'globalPan')) {
  38005. return;
  38006. }
  38007. var x = e.offsetX;
  38008. var y = e.offsetY;
  38009. var oldX = this._x;
  38010. var oldY = this._y;
  38011. var dx = x - oldX;
  38012. var dy = y - oldY;
  38013. this._x = x;
  38014. this._y = y;
  38015. this._opt.preventDefaultMouseMove && stop(e.event);
  38016. trigger(this, 'pan', 'moveOnMouseMove', e, {
  38017. dx: dx,
  38018. dy: dy,
  38019. oldX: oldX,
  38020. oldY: oldY,
  38021. newX: x,
  38022. newY: y
  38023. });
  38024. }
  38025. function mouseup(e) {
  38026. if (!isMiddleOrRightButtonOnMouseUpDown(e)) {
  38027. this._dragging = false;
  38028. }
  38029. }
  38030. function mousewheel(e) {
  38031. var shouldZoom = isAvailableBehavior('zoomOnMouseWheel', e, this._opt);
  38032. var shouldMove = isAvailableBehavior('moveOnMouseWheel', e, this._opt);
  38033. var wheelDelta = e.wheelDelta;
  38034. var absWheelDeltaDelta = Math.abs(wheelDelta);
  38035. var originX = e.offsetX;
  38036. var originY = e.offsetY; // wheelDelta maybe -0 in chrome mac.
  38037. if (wheelDelta === 0 || !shouldZoom && !shouldMove) {
  38038. return;
  38039. } // If both `shouldZoom` and `shouldMove` is true, trigger
  38040. // their event both, and the final behavior is determined
  38041. // by event listener themselves.
  38042. if (shouldZoom) {
  38043. // Convenience:
  38044. // Mac and VM Windows on Mac: scroll up: zoom out.
  38045. // Windows: scroll up: zoom in.
  38046. // FIXME: Should do more test in different environment.
  38047. // wheelDelta is too complicated in difference nvironment
  38048. // (https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel),
  38049. // although it has been normallized by zrender.
  38050. // wheelDelta of mouse wheel is bigger than touch pad.
  38051. var factor = absWheelDeltaDelta > 3 ? 1.4 : absWheelDeltaDelta > 1 ? 1.2 : 1.1;
  38052. var scale = wheelDelta > 0 ? factor : 1 / factor;
  38053. checkPointerAndTrigger(this, 'zoom', 'zoomOnMouseWheel', e, {
  38054. scale: scale,
  38055. originX: originX,
  38056. originY: originY
  38057. });
  38058. }
  38059. if (shouldMove) {
  38060. // FIXME: Should do more test in different environment.
  38061. var absDelta = Math.abs(wheelDelta); // wheelDelta of mouse wheel is bigger than touch pad.
  38062. var scrollDelta = (wheelDelta > 0 ? 1 : -1) * (absDelta > 3 ? 0.4 : absDelta > 1 ? 0.15 : 0.05);
  38063. checkPointerAndTrigger(this, 'scrollMove', 'moveOnMouseWheel', e, {
  38064. scrollDelta: scrollDelta,
  38065. originX: originX,
  38066. originY: originY
  38067. });
  38068. }
  38069. }
  38070. function pinch(e) {
  38071. if (isTaken(this._zr, 'globalPan')) {
  38072. return;
  38073. }
  38074. var scale = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  38075. checkPointerAndTrigger(this, 'zoom', null, e, {
  38076. scale: scale,
  38077. originX: e.pinchX,
  38078. originY: e.pinchY
  38079. });
  38080. }
  38081. function checkPointerAndTrigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  38082. if (controller.pointerChecker && controller.pointerChecker(e, contollerEvent.originX, contollerEvent.originY)) {
  38083. // When mouse is out of roamController rect,
  38084. // default befavoius should not be be disabled, otherwise
  38085. // page sliding is disabled, contrary to expectation.
  38086. stop(e.event);
  38087. trigger(controller, eventName, behaviorToCheck, e, contollerEvent);
  38088. }
  38089. }
  38090. function trigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  38091. // Also provide behavior checker for event listener, for some case that
  38092. // multiple components share one listener.
  38093. contollerEvent.isAvailableBehavior = bind(isAvailableBehavior, null, behaviorToCheck, e);
  38094. controller.trigger(eventName, contollerEvent);
  38095. } // settings: {
  38096. // zoomOnMouseWheel
  38097. // moveOnMouseMove
  38098. // moveOnMouseWheel
  38099. // }
  38100. // The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  38101. function isAvailableBehavior(behaviorToCheck, e, settings) {
  38102. var setting = settings[behaviorToCheck];
  38103. return !behaviorToCheck || setting && (!isString(setting) || e.event[setting + 'Key']);
  38104. }
  38105. /*
  38106. * Licensed to the Apache Software Foundation (ASF) under one
  38107. * or more contributor license agreements. See the NOTICE file
  38108. * distributed with this work for additional information
  38109. * regarding copyright ownership. The ASF licenses this file
  38110. * to you under the Apache License, Version 2.0 (the
  38111. * "License"); you may not use this file except in compliance
  38112. * with the License. You may obtain a copy of the License at
  38113. *
  38114. * http://www.apache.org/licenses/LICENSE-2.0
  38115. *
  38116. * Unless required by applicable law or agreed to in writing,
  38117. * software distributed under the License is distributed on an
  38118. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38119. * KIND, either express or implied. See the License for the
  38120. * specific language governing permissions and limitations
  38121. * under the License.
  38122. */
  38123. var IRRELEVANT_EXCLUDES = {
  38124. 'axisPointer': 1,
  38125. 'tooltip': 1,
  38126. 'brush': 1
  38127. };
  38128. /**
  38129. * Avoid that: mouse click on a elements that is over geo or graph,
  38130. * but roam is triggered.
  38131. */
  38132. function onIrrelevantElement(e, api, targetCoordSysModel) {
  38133. var model = api.getComponentByElement(e.topTarget); // If model is axisModel, it works only if it is injected with coordinateSystem.
  38134. var coordSys = model && model.coordinateSystem;
  38135. return model && model !== targetCoordSysModel && !IRRELEVANT_EXCLUDES[model.mainType] && coordSys && coordSys.model !== targetCoordSysModel;
  38136. }
  38137. /*
  38138. * Licensed to the Apache Software Foundation (ASF) under one
  38139. * or more contributor license agreements. See the NOTICE file
  38140. * distributed with this work for additional information
  38141. * regarding copyright ownership. The ASF licenses this file
  38142. * to you under the Apache License, Version 2.0 (the
  38143. * "License"); you may not use this file except in compliance
  38144. * with the License. You may obtain a copy of the License at
  38145. *
  38146. * http://www.apache.org/licenses/LICENSE-2.0
  38147. *
  38148. * Unless required by applicable law or agreed to in writing,
  38149. * software distributed under the License is distributed on an
  38150. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38151. * KIND, either express or implied. See the License for the
  38152. * specific language governing permissions and limitations
  38153. * under the License.
  38154. */
  38155. var TreeShape = extendShape({
  38156. shape: {
  38157. parentPoint: [],
  38158. childPoints: [],
  38159. orient: '',
  38160. forkPosition: ''
  38161. },
  38162. style: {
  38163. stroke: '#000',
  38164. fill: null
  38165. },
  38166. buildPath: function (ctx, shape) {
  38167. var childPoints = shape.childPoints;
  38168. var childLen = childPoints.length;
  38169. var parentPoint = shape.parentPoint;
  38170. var firstChildPos = childPoints[0];
  38171. var lastChildPos = childPoints[childLen - 1];
  38172. if (childLen === 1) {
  38173. ctx.moveTo(parentPoint[0], parentPoint[1]);
  38174. ctx.lineTo(firstChildPos[0], firstChildPos[1]);
  38175. return;
  38176. }
  38177. var orient = shape.orient;
  38178. var forkDim = orient === 'TB' || orient === 'BT' ? 0 : 1;
  38179. var otherDim = 1 - forkDim;
  38180. var forkPosition = parsePercent$1(shape.forkPosition, 1);
  38181. var tmpPoint = [];
  38182. tmpPoint[forkDim] = parentPoint[forkDim];
  38183. tmpPoint[otherDim] = parentPoint[otherDim] + (lastChildPos[otherDim] - parentPoint[otherDim]) * forkPosition;
  38184. ctx.moveTo(parentPoint[0], parentPoint[1]);
  38185. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  38186. ctx.moveTo(firstChildPos[0], firstChildPos[1]);
  38187. tmpPoint[forkDim] = firstChildPos[forkDim];
  38188. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  38189. tmpPoint[forkDim] = lastChildPos[forkDim];
  38190. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  38191. ctx.lineTo(lastChildPos[0], lastChildPos[1]);
  38192. for (var i = 1; i < childLen - 1; i++) {
  38193. var point = childPoints[i];
  38194. ctx.moveTo(point[0], point[1]);
  38195. tmpPoint[forkDim] = point[forkDim];
  38196. ctx.lineTo(tmpPoint[0], tmpPoint[1]);
  38197. }
  38198. }
  38199. });
  38200. extendChartView({
  38201. type: 'tree',
  38202. /**
  38203. * Init the chart
  38204. * @override
  38205. * @param {module:echarts/model/Global} ecModel
  38206. * @param {module:echarts/ExtensionAPI} api
  38207. */
  38208. init: function (ecModel, api) {
  38209. /**
  38210. * @private
  38211. * @type {module:echarts/data/Tree}
  38212. */
  38213. this._oldTree;
  38214. /**
  38215. * @private
  38216. * @type {module:zrender/container/Group}
  38217. */
  38218. this._mainGroup = new Group();
  38219. /**
  38220. * @private
  38221. * @type {module:echarts/componet/helper/RoamController}
  38222. */
  38223. this._controller = new RoamController(api.getZr());
  38224. this._controllerHost = {
  38225. target: this.group
  38226. };
  38227. this.group.add(this._mainGroup);
  38228. },
  38229. render: function (seriesModel, ecModel, api, payload) {
  38230. var data = seriesModel.getData();
  38231. var layoutInfo = seriesModel.layoutInfo;
  38232. var group = this._mainGroup;
  38233. var layout = seriesModel.get('layout');
  38234. if (layout === 'radial') {
  38235. group.attr('position', [layoutInfo.x + layoutInfo.width / 2, layoutInfo.y + layoutInfo.height / 2]);
  38236. } else {
  38237. group.attr('position', [layoutInfo.x, layoutInfo.y]);
  38238. }
  38239. this._updateViewCoordSys(seriesModel, layoutInfo, layout);
  38240. this._updateController(seriesModel, ecModel, api);
  38241. var oldData = this._data;
  38242. var seriesScope = {
  38243. expandAndCollapse: seriesModel.get('expandAndCollapse'),
  38244. layout: layout,
  38245. edgeShape: seriesModel.get('edgeShape'),
  38246. edgeForkPosition: seriesModel.get('edgeForkPosition'),
  38247. orient: seriesModel.getOrient(),
  38248. curvature: seriesModel.get('lineStyle.curveness'),
  38249. symbolRotate: seriesModel.get('symbolRotate'),
  38250. symbolOffset: seriesModel.get('symbolOffset'),
  38251. hoverAnimation: seriesModel.get('hoverAnimation'),
  38252. useNameLabel: true,
  38253. fadeIn: true
  38254. };
  38255. data.diff(oldData).add(function (newIdx) {
  38256. if (symbolNeedsDraw$1(data, newIdx)) {
  38257. // Create node and edge
  38258. updateNode(data, newIdx, null, group, seriesModel, seriesScope);
  38259. }
  38260. }).update(function (newIdx, oldIdx) {
  38261. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  38262. if (!symbolNeedsDraw$1(data, newIdx)) {
  38263. symbolEl && removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
  38264. return;
  38265. } // Update node and edge
  38266. updateNode(data, newIdx, symbolEl, group, seriesModel, seriesScope);
  38267. }).remove(function (oldIdx) {
  38268. var symbolEl = oldData.getItemGraphicEl(oldIdx); // When remove a collapsed node of subtree, since the collapsed
  38269. // node haven't been initialized with a symbol element,
  38270. // you can't found it's symbol element through index.
  38271. // so if we want to remove the symbol element we should insure
  38272. // that the symbol element is not null.
  38273. if (symbolEl) {
  38274. removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
  38275. }
  38276. }).execute();
  38277. this._nodeScaleRatio = seriesModel.get('nodeScaleRatio');
  38278. this._updateNodeAndLinkScale(seriesModel);
  38279. if (seriesScope.expandAndCollapse === true) {
  38280. data.eachItemGraphicEl(function (el, dataIndex) {
  38281. el.off('click').on('click', function () {
  38282. api.dispatchAction({
  38283. type: 'treeExpandAndCollapse',
  38284. seriesId: seriesModel.id,
  38285. dataIndex: dataIndex
  38286. });
  38287. });
  38288. });
  38289. }
  38290. this._data = data;
  38291. },
  38292. _updateViewCoordSys: function (seriesModel) {
  38293. var data = seriesModel.getData();
  38294. var points = [];
  38295. data.each(function (idx) {
  38296. var layout = data.getItemLayout(idx);
  38297. if (layout && !isNaN(layout.x) && !isNaN(layout.y)) {
  38298. points.push([+layout.x, +layout.y]);
  38299. }
  38300. });
  38301. var min = [];
  38302. var max = [];
  38303. fromPoints(points, min, max); // If don't Store min max when collapse the root node after roam,
  38304. // the root node will disappear.
  38305. var oldMin = this._min;
  38306. var oldMax = this._max; // If width or height is 0
  38307. if (max[0] - min[0] === 0) {
  38308. min[0] = oldMin ? oldMin[0] : min[0] - 1;
  38309. max[0] = oldMax ? oldMax[0] : max[0] + 1;
  38310. }
  38311. if (max[1] - min[1] === 0) {
  38312. min[1] = oldMin ? oldMin[1] : min[1] - 1;
  38313. max[1] = oldMax ? oldMax[1] : max[1] + 1;
  38314. }
  38315. var viewCoordSys = seriesModel.coordinateSystem = new View();
  38316. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  38317. viewCoordSys.setBoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  38318. viewCoordSys.setCenter(seriesModel.get('center'));
  38319. viewCoordSys.setZoom(seriesModel.get('zoom')); // Here we use viewCoordSys just for computing the 'position' and 'scale' of the group
  38320. this.group.attr({
  38321. position: viewCoordSys.position,
  38322. scale: viewCoordSys.scale
  38323. });
  38324. this._viewCoordSys = viewCoordSys;
  38325. this._min = min;
  38326. this._max = max;
  38327. },
  38328. _updateController: function (seriesModel, ecModel, api) {
  38329. var controller = this._controller;
  38330. var controllerHost = this._controllerHost;
  38331. var group = this.group;
  38332. controller.setPointerChecker(function (e, x, y) {
  38333. var rect = group.getBoundingRect();
  38334. rect.applyTransform(group.transform);
  38335. return rect.contain(x, y) && !onIrrelevantElement(e, api, seriesModel);
  38336. });
  38337. controller.enable(seriesModel.get('roam'));
  38338. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  38339. controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
  38340. controller.off('pan').off('zoom').on('pan', function (e) {
  38341. updateViewOnPan(controllerHost, e.dx, e.dy);
  38342. api.dispatchAction({
  38343. seriesId: seriesModel.id,
  38344. type: 'treeRoam',
  38345. dx: e.dx,
  38346. dy: e.dy
  38347. });
  38348. }, this).on('zoom', function (e) {
  38349. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  38350. api.dispatchAction({
  38351. seriesId: seriesModel.id,
  38352. type: 'treeRoam',
  38353. zoom: e.scale,
  38354. originX: e.originX,
  38355. originY: e.originY
  38356. });
  38357. this._updateNodeAndLinkScale(seriesModel);
  38358. }, this);
  38359. },
  38360. _updateNodeAndLinkScale: function (seriesModel) {
  38361. var data = seriesModel.getData();
  38362. var nodeScale = this._getNodeGlobalScale(seriesModel);
  38363. var invScale = [nodeScale, nodeScale];
  38364. data.eachItemGraphicEl(function (el, idx) {
  38365. el.attr('scale', invScale);
  38366. });
  38367. },
  38368. _getNodeGlobalScale: function (seriesModel) {
  38369. var coordSys = seriesModel.coordinateSystem;
  38370. if (coordSys.type !== 'view') {
  38371. return 1;
  38372. }
  38373. var nodeScaleRatio = this._nodeScaleRatio;
  38374. var groupScale = coordSys.scale;
  38375. var groupZoom = groupScale && groupScale[0] || 1; // Scale node when zoom changes
  38376. var roamZoom = coordSys.getZoom();
  38377. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  38378. return nodeScale / groupZoom;
  38379. },
  38380. dispose: function () {
  38381. this._controller && this._controller.dispose();
  38382. this._controllerHost = {};
  38383. },
  38384. remove: function () {
  38385. this._mainGroup.removeAll();
  38386. this._data = null;
  38387. }
  38388. });
  38389. function symbolNeedsDraw$1(data, dataIndex) {
  38390. var layout = data.getItemLayout(dataIndex);
  38391. return layout && !isNaN(layout.x) && !isNaN(layout.y) && data.getItemVisual(dataIndex, 'symbol') !== 'none';
  38392. }
  38393. function getTreeNodeStyle(node, itemModel, seriesScope) {
  38394. seriesScope.itemModel = itemModel;
  38395. seriesScope.itemStyle = itemModel.getModel('itemStyle').getItemStyle();
  38396. seriesScope.hoverItemStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  38397. seriesScope.lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  38398. seriesScope.labelModel = itemModel.getModel('label');
  38399. seriesScope.hoverLabelModel = itemModel.getModel('emphasis.label');
  38400. if (node.isExpand === false && node.children.length !== 0) {
  38401. seriesScope.symbolInnerColor = seriesScope.itemStyle.fill;
  38402. } else {
  38403. seriesScope.symbolInnerColor = '#fff';
  38404. }
  38405. return seriesScope;
  38406. }
  38407. function updateNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
  38408. var isInit = !symbolEl;
  38409. var node = data.tree.getNodeByDataIndex(dataIndex);
  38410. var itemModel = node.getModel();
  38411. var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);
  38412. var virtualRoot = data.tree.root;
  38413. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  38414. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  38415. var sourceLayout = source.getLayout();
  38416. var sourceOldLayout = sourceSymbolEl ? {
  38417. x: sourceSymbolEl.position[0],
  38418. y: sourceSymbolEl.position[1],
  38419. rawX: sourceSymbolEl.__radialOldRawX,
  38420. rawY: sourceSymbolEl.__radialOldRawY
  38421. } : sourceLayout;
  38422. var targetLayout = node.getLayout();
  38423. if (isInit) {
  38424. symbolEl = new SymbolClz$1(data, dataIndex, seriesScope);
  38425. symbolEl.attr('position', [sourceOldLayout.x, sourceOldLayout.y]);
  38426. } else {
  38427. symbolEl.updateData(data, dataIndex, seriesScope);
  38428. }
  38429. symbolEl.__radialOldRawX = symbolEl.__radialRawX;
  38430. symbolEl.__radialOldRawY = symbolEl.__radialRawY;
  38431. symbolEl.__radialRawX = targetLayout.rawX;
  38432. symbolEl.__radialRawY = targetLayout.rawY;
  38433. group.add(symbolEl);
  38434. data.setItemGraphicEl(dataIndex, symbolEl);
  38435. updateProps(symbolEl, {
  38436. position: [targetLayout.x, targetLayout.y]
  38437. }, seriesModel);
  38438. var symbolPath = symbolEl.getSymbolPath();
  38439. if (seriesScope.layout === 'radial') {
  38440. var realRoot = virtualRoot.children[0];
  38441. var rootLayout = realRoot.getLayout();
  38442. var length = realRoot.children.length;
  38443. var rad;
  38444. var isLeft;
  38445. if (targetLayout.x === rootLayout.x && node.isExpand === true) {
  38446. var center = {};
  38447. center.x = (realRoot.children[0].getLayout().x + realRoot.children[length - 1].getLayout().x) / 2;
  38448. center.y = (realRoot.children[0].getLayout().y + realRoot.children[length - 1].getLayout().y) / 2;
  38449. rad = Math.atan2(center.y - rootLayout.y, center.x - rootLayout.x);
  38450. if (rad < 0) {
  38451. rad = Math.PI * 2 + rad;
  38452. }
  38453. isLeft = center.x < rootLayout.x;
  38454. if (isLeft) {
  38455. rad = rad - Math.PI;
  38456. }
  38457. } else {
  38458. rad = Math.atan2(targetLayout.y - rootLayout.y, targetLayout.x - rootLayout.x);
  38459. if (rad < 0) {
  38460. rad = Math.PI * 2 + rad;
  38461. }
  38462. if (node.children.length === 0 || node.children.length !== 0 && node.isExpand === false) {
  38463. isLeft = targetLayout.x < rootLayout.x;
  38464. if (isLeft) {
  38465. rad = rad - Math.PI;
  38466. }
  38467. } else {
  38468. isLeft = targetLayout.x > rootLayout.x;
  38469. if (!isLeft) {
  38470. rad = rad - Math.PI;
  38471. }
  38472. }
  38473. }
  38474. var textPosition = isLeft ? 'left' : 'right';
  38475. var rotate = seriesScope.labelModel.get('rotate');
  38476. var labelRotateRadian = rotate * (Math.PI / 180);
  38477. symbolPath.setStyle({
  38478. textPosition: seriesScope.labelModel.get('position') || textPosition,
  38479. textRotation: rotate == null ? -rad : labelRotateRadian,
  38480. textOrigin: 'center',
  38481. verticalAlign: 'middle'
  38482. });
  38483. }
  38484. drawEdge(seriesModel, node, virtualRoot, symbolEl, sourceOldLayout, sourceLayout, targetLayout, group, seriesScope);
  38485. }
  38486. function drawEdge(seriesModel, node, virtualRoot, symbolEl, sourceOldLayout, sourceLayout, targetLayout, group, seriesScope) {
  38487. var edgeShape = seriesScope.edgeShape;
  38488. var edge = symbolEl.__edge;
  38489. if (edgeShape === 'curve') {
  38490. if (node.parentNode && node.parentNode !== virtualRoot) {
  38491. if (!edge) {
  38492. edge = symbolEl.__edge = new BezierCurve({
  38493. shape: getEdgeShape(seriesScope, sourceOldLayout, sourceOldLayout),
  38494. style: defaults({
  38495. opacity: 0,
  38496. strokeNoScale: true
  38497. }, seriesScope.lineStyle)
  38498. });
  38499. }
  38500. updateProps(edge, {
  38501. shape: getEdgeShape(seriesScope, sourceLayout, targetLayout),
  38502. style: {
  38503. opacity: 1
  38504. }
  38505. }, seriesModel);
  38506. }
  38507. } else if (edgeShape === 'polyline') {
  38508. if (seriesScope.layout === 'orthogonal') {
  38509. if (node !== virtualRoot && node.children && node.children.length !== 0 && node.isExpand === true) {
  38510. var children = node.children;
  38511. var childPoints = [];
  38512. for (var i = 0; i < children.length; i++) {
  38513. var childLayout = children[i].getLayout();
  38514. childPoints.push([childLayout.x, childLayout.y]);
  38515. }
  38516. if (!edge) {
  38517. edge = symbolEl.__edge = new TreeShape({
  38518. shape: {
  38519. parentPoint: [targetLayout.x, targetLayout.y],
  38520. childPoints: [[targetLayout.x, targetLayout.y]],
  38521. orient: seriesScope.orient,
  38522. forkPosition: seriesScope.edgeForkPosition
  38523. },
  38524. style: defaults({
  38525. opacity: 0,
  38526. strokeNoScale: true
  38527. }, seriesScope.lineStyle)
  38528. });
  38529. }
  38530. updateProps(edge, {
  38531. shape: {
  38532. parentPoint: [targetLayout.x, targetLayout.y],
  38533. childPoints: childPoints
  38534. },
  38535. style: {
  38536. opacity: 1
  38537. }
  38538. }, seriesModel);
  38539. }
  38540. } else {}
  38541. }
  38542. group.add(edge);
  38543. }
  38544. function removeNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
  38545. var node = data.tree.getNodeByDataIndex(dataIndex);
  38546. var virtualRoot = data.tree.root;
  38547. var itemModel = node.getModel();
  38548. var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);
  38549. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  38550. var edgeShape = seriesScope.edgeShape;
  38551. var sourceLayout;
  38552. while (sourceLayout = source.getLayout(), sourceLayout == null) {
  38553. source = source.parentNode === virtualRoot ? source : source.parentNode || source;
  38554. }
  38555. updateProps(symbolEl, {
  38556. position: [sourceLayout.x + 1, sourceLayout.y + 1]
  38557. }, seriesModel, function () {
  38558. group.remove(symbolEl);
  38559. data.setItemGraphicEl(dataIndex, null);
  38560. });
  38561. symbolEl.fadeOut(null, {
  38562. keepLabel: true
  38563. });
  38564. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  38565. var sourceEdge = sourceSymbolEl.__edge; // 1. when expand the sub tree, delete the children node should delete the edge of
  38566. // the source at the same time. because the polyline edge shape is only owned by the source.
  38567. // 2.when the node is the only children of the source, delete the node should delete the edge of
  38568. // the source at the same time. the same reason as above.
  38569. var edge = symbolEl.__edge || (source.isExpand === false || source.children.length === 1 ? sourceEdge : undefined);
  38570. var edgeShape = seriesScope.edgeShape;
  38571. if (edge) {
  38572. if (edgeShape === 'curve') {
  38573. updateProps(edge, {
  38574. shape: getEdgeShape(seriesScope, sourceLayout, sourceLayout),
  38575. style: {
  38576. opacity: 0
  38577. }
  38578. }, seriesModel, function () {
  38579. group.remove(edge);
  38580. });
  38581. } else if (edgeShape === 'polyline' && seriesScope.layout === 'orthogonal') {
  38582. updateProps(edge, {
  38583. shape: {
  38584. parentPoint: [sourceLayout.x, sourceLayout.y],
  38585. childPoints: [[sourceLayout.x, sourceLayout.y]]
  38586. },
  38587. style: {
  38588. opacity: 0
  38589. }
  38590. }, seriesModel, function () {
  38591. group.remove(edge);
  38592. });
  38593. }
  38594. }
  38595. }
  38596. function getEdgeShape(seriesScope, sourceLayout, targetLayout) {
  38597. var cpx1;
  38598. var cpy1;
  38599. var cpx2;
  38600. var cpy2;
  38601. var orient = seriesScope.orient;
  38602. var x1;
  38603. var x2;
  38604. var y1;
  38605. var y2;
  38606. if (seriesScope.layout === 'radial') {
  38607. x1 = sourceLayout.rawX;
  38608. y1 = sourceLayout.rawY;
  38609. x2 = targetLayout.rawX;
  38610. y2 = targetLayout.rawY;
  38611. var radialCoor1 = radialCoordinate(x1, y1);
  38612. var radialCoor2 = radialCoordinate(x1, y1 + (y2 - y1) * seriesScope.curvature);
  38613. var radialCoor3 = radialCoordinate(x2, y2 + (y1 - y2) * seriesScope.curvature);
  38614. var radialCoor4 = radialCoordinate(x2, y2);
  38615. return {
  38616. x1: radialCoor1.x,
  38617. y1: radialCoor1.y,
  38618. x2: radialCoor4.x,
  38619. y2: radialCoor4.y,
  38620. cpx1: radialCoor2.x,
  38621. cpy1: radialCoor2.y,
  38622. cpx2: radialCoor3.x,
  38623. cpy2: radialCoor3.y
  38624. };
  38625. } else {
  38626. x1 = sourceLayout.x;
  38627. y1 = sourceLayout.y;
  38628. x2 = targetLayout.x;
  38629. y2 = targetLayout.y;
  38630. if (orient === 'LR' || orient === 'RL') {
  38631. cpx1 = x1 + (x2 - x1) * seriesScope.curvature;
  38632. cpy1 = y1;
  38633. cpx2 = x2 + (x1 - x2) * seriesScope.curvature;
  38634. cpy2 = y2;
  38635. }
  38636. if (orient === 'TB' || orient === 'BT') {
  38637. cpx1 = x1;
  38638. cpy1 = y1 + (y2 - y1) * seriesScope.curvature;
  38639. cpx2 = x2;
  38640. cpy2 = y2 + (y1 - y2) * seriesScope.curvature;
  38641. }
  38642. }
  38643. return {
  38644. x1: x1,
  38645. y1: y1,
  38646. x2: x2,
  38647. y2: y2,
  38648. cpx1: cpx1,
  38649. cpy1: cpy1,
  38650. cpx2: cpx2,
  38651. cpy2: cpy2
  38652. };
  38653. }
  38654. /*
  38655. * Licensed to the Apache Software Foundation (ASF) under one
  38656. * or more contributor license agreements. See the NOTICE file
  38657. * distributed with this work for additional information
  38658. * regarding copyright ownership. The ASF licenses this file
  38659. * to you under the Apache License, Version 2.0 (the
  38660. * "License"); you may not use this file except in compliance
  38661. * with the License. You may obtain a copy of the License at
  38662. *
  38663. * http://www.apache.org/licenses/LICENSE-2.0
  38664. *
  38665. * Unless required by applicable law or agreed to in writing,
  38666. * software distributed under the License is distributed on an
  38667. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38668. * KIND, either express or implied. See the License for the
  38669. * specific language governing permissions and limitations
  38670. * under the License.
  38671. */
  38672. /**
  38673. * @param {module:echarts/coord/View} view
  38674. * @param {Object} payload
  38675. * @param {Object} [zoomLimit]
  38676. */
  38677. function updateCenterAndZoom(view, payload, zoomLimit) {
  38678. var previousZoom = view.getZoom();
  38679. var center = view.getCenter();
  38680. var zoom = payload.zoom;
  38681. var point = view.dataToPoint(center);
  38682. if (payload.dx != null && payload.dy != null) {
  38683. point[0] -= payload.dx;
  38684. point[1] -= payload.dy;
  38685. var center = view.pointToData(point);
  38686. view.setCenter(center);
  38687. }
  38688. if (zoom != null) {
  38689. if (zoomLimit) {
  38690. var zoomMin = zoomLimit.min || 0;
  38691. var zoomMax = zoomLimit.max || Infinity;
  38692. zoom = Math.max(Math.min(previousZoom * zoom, zoomMax), zoomMin) / previousZoom;
  38693. } // Zoom on given point(originX, originY)
  38694. view.scale[0] *= zoom;
  38695. view.scale[1] *= zoom;
  38696. var position = view.position;
  38697. var fixX = (payload.originX - position[0]) * (zoom - 1);
  38698. var fixY = (payload.originY - position[1]) * (zoom - 1);
  38699. position[0] -= fixX;
  38700. position[1] -= fixY;
  38701. view.updateTransform(); // Get the new center
  38702. var center = view.pointToData(point);
  38703. view.setCenter(center);
  38704. view.setZoom(zoom * previousZoom);
  38705. }
  38706. return {
  38707. center: view.getCenter(),
  38708. zoom: view.getZoom()
  38709. };
  38710. }
  38711. /*
  38712. * Licensed to the Apache Software Foundation (ASF) under one
  38713. * or more contributor license agreements. See the NOTICE file
  38714. * distributed with this work for additional information
  38715. * regarding copyright ownership. The ASF licenses this file
  38716. * to you under the Apache License, Version 2.0 (the
  38717. * "License"); you may not use this file except in compliance
  38718. * with the License. You may obtain a copy of the License at
  38719. *
  38720. * http://www.apache.org/licenses/LICENSE-2.0
  38721. *
  38722. * Unless required by applicable law or agreed to in writing,
  38723. * software distributed under the License is distributed on an
  38724. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38725. * KIND, either express or implied. See the License for the
  38726. * specific language governing permissions and limitations
  38727. * under the License.
  38728. */
  38729. registerAction({
  38730. type: 'treeExpandAndCollapse',
  38731. event: 'treeExpandAndCollapse',
  38732. update: 'update'
  38733. }, function (payload, ecModel) {
  38734. ecModel.eachComponent({
  38735. mainType: 'series',
  38736. subType: 'tree',
  38737. query: payload
  38738. }, function (seriesModel) {
  38739. var dataIndex = payload.dataIndex;
  38740. var tree = seriesModel.getData().tree;
  38741. var node = tree.getNodeByDataIndex(dataIndex);
  38742. node.isExpand = !node.isExpand;
  38743. });
  38744. });
  38745. registerAction({
  38746. type: 'treeRoam',
  38747. event: 'treeRoam',
  38748. // Here we set 'none' instead of 'update', because roam action
  38749. // just need to update the transform matrix without having to recalculate
  38750. // the layout. So don't need to go through the whole update process, such
  38751. // as 'dataPrcocess', 'coordSystemUpdate', 'layout' and so on.
  38752. update: 'none'
  38753. }, function (payload, ecModel) {
  38754. ecModel.eachComponent({
  38755. mainType: 'series',
  38756. subType: 'tree',
  38757. query: payload
  38758. }, function (seriesModel) {
  38759. var coordSys = seriesModel.coordinateSystem;
  38760. var res = updateCenterAndZoom(coordSys, payload);
  38761. seriesModel.setCenter && seriesModel.setCenter(res.center);
  38762. seriesModel.setZoom && seriesModel.setZoom(res.zoom);
  38763. });
  38764. });
  38765. /*
  38766. * Licensed to the Apache Software Foundation (ASF) under one
  38767. * or more contributor license agreements. See the NOTICE file
  38768. * distributed with this work for additional information
  38769. * regarding copyright ownership. The ASF licenses this file
  38770. * to you under the Apache License, Version 2.0 (the
  38771. * "License"); you may not use this file except in compliance
  38772. * with the License. You may obtain a copy of the License at
  38773. *
  38774. * http://www.apache.org/licenses/LICENSE-2.0
  38775. *
  38776. * Unless required by applicable law or agreed to in writing,
  38777. * software distributed under the License is distributed on an
  38778. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38779. * KIND, either express or implied. See the License for the
  38780. * specific language governing permissions and limitations
  38781. * under the License.
  38782. */
  38783. /**
  38784. * Traverse the tree from bottom to top and do something
  38785. * @param {module:echarts/data/Tree~TreeNode} root The real root of the tree
  38786. * @param {Function} callback
  38787. */
  38788. function eachAfter(root, callback, separation) {
  38789. var nodes = [root];
  38790. var next = [];
  38791. var node;
  38792. while (node = nodes.pop()) {
  38793. // jshint ignore:line
  38794. next.push(node);
  38795. if (node.isExpand) {
  38796. var children = node.children;
  38797. if (children.length) {
  38798. for (var i = 0; i < children.length; i++) {
  38799. nodes.push(children[i]);
  38800. }
  38801. }
  38802. }
  38803. }
  38804. while (node = next.pop()) {
  38805. // jshint ignore:line
  38806. callback(node, separation);
  38807. }
  38808. }
  38809. /**
  38810. * Traverse the tree from top to bottom and do something
  38811. * @param {module:echarts/data/Tree~TreeNode} root The real root of the tree
  38812. * @param {Function} callback
  38813. */
  38814. function eachBefore(root, callback) {
  38815. var nodes = [root];
  38816. var node;
  38817. while (node = nodes.pop()) {
  38818. // jshint ignore:line
  38819. callback(node);
  38820. if (node.isExpand) {
  38821. var children = node.children;
  38822. if (children.length) {
  38823. for (var i = children.length - 1; i >= 0; i--) {
  38824. nodes.push(children[i]);
  38825. }
  38826. }
  38827. }
  38828. }
  38829. }
  38830. /*
  38831. * Licensed to the Apache Software Foundation (ASF) under one
  38832. * or more contributor license agreements. See the NOTICE file
  38833. * distributed with this work for additional information
  38834. * regarding copyright ownership. The ASF licenses this file
  38835. * to you under the Apache License, Version 2.0 (the
  38836. * "License"); you may not use this file except in compliance
  38837. * with the License. You may obtain a copy of the License at
  38838. *
  38839. * http://www.apache.org/licenses/LICENSE-2.0
  38840. *
  38841. * Unless required by applicable law or agreed to in writing,
  38842. * software distributed under the License is distributed on an
  38843. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38844. * KIND, either express or implied. See the License for the
  38845. * specific language governing permissions and limitations
  38846. * under the License.
  38847. */
  38848. var treeLayout = function (ecModel, api) {
  38849. ecModel.eachSeriesByType('tree', function (seriesModel) {
  38850. commonLayout(seriesModel, api);
  38851. });
  38852. };
  38853. function commonLayout(seriesModel, api) {
  38854. var layoutInfo = getViewRect$1(seriesModel, api);
  38855. seriesModel.layoutInfo = layoutInfo;
  38856. var layout = seriesModel.get('layout');
  38857. var width = 0;
  38858. var height = 0;
  38859. var separation$$1 = null;
  38860. if (layout === 'radial') {
  38861. width = 2 * Math.PI;
  38862. height = Math.min(layoutInfo.height, layoutInfo.width) / 2;
  38863. separation$$1 = separation(function (node1, node2) {
  38864. return (node1.parentNode === node2.parentNode ? 1 : 2) / node1.depth;
  38865. });
  38866. } else {
  38867. width = layoutInfo.width;
  38868. height = layoutInfo.height;
  38869. separation$$1 = separation();
  38870. }
  38871. var virtualRoot = seriesModel.getData().tree.root;
  38872. var realRoot = virtualRoot.children[0];
  38873. if (realRoot) {
  38874. init$2(virtualRoot);
  38875. eachAfter(realRoot, firstWalk, separation$$1);
  38876. virtualRoot.hierNode.modifier = -realRoot.hierNode.prelim;
  38877. eachBefore(realRoot, secondWalk);
  38878. var left = realRoot;
  38879. var right = realRoot;
  38880. var bottom = realRoot;
  38881. eachBefore(realRoot, function (node) {
  38882. var x = node.getLayout().x;
  38883. if (x < left.getLayout().x) {
  38884. left = node;
  38885. }
  38886. if (x > right.getLayout().x) {
  38887. right = node;
  38888. }
  38889. if (node.depth > bottom.depth) {
  38890. bottom = node;
  38891. }
  38892. });
  38893. var delta = left === right ? 1 : separation$$1(left, right) / 2;
  38894. var tx = delta - left.getLayout().x;
  38895. var kx = 0;
  38896. var ky = 0;
  38897. var coorX = 0;
  38898. var coorY = 0;
  38899. if (layout === 'radial') {
  38900. kx = width / (right.getLayout().x + delta + tx); // here we use (node.depth - 1), bucause the real root's depth is 1
  38901. ky = height / (bottom.depth - 1 || 1);
  38902. eachBefore(realRoot, function (node) {
  38903. coorX = (node.getLayout().x + tx) * kx;
  38904. coorY = (node.depth - 1) * ky;
  38905. var finalCoor = radialCoordinate(coorX, coorY);
  38906. node.setLayout({
  38907. x: finalCoor.x,
  38908. y: finalCoor.y,
  38909. rawX: coorX,
  38910. rawY: coorY
  38911. }, true);
  38912. });
  38913. } else {
  38914. var orient = seriesModel.getOrient();
  38915. if (orient === 'RL' || orient === 'LR') {
  38916. ky = height / (right.getLayout().x + delta + tx);
  38917. kx = width / (bottom.depth - 1 || 1);
  38918. eachBefore(realRoot, function (node) {
  38919. coorY = (node.getLayout().x + tx) * ky;
  38920. coorX = orient === 'LR' ? (node.depth - 1) * kx : width - (node.depth - 1) * kx;
  38921. node.setLayout({
  38922. x: coorX,
  38923. y: coorY
  38924. }, true);
  38925. });
  38926. } else if (orient === 'TB' || orient === 'BT') {
  38927. kx = width / (right.getLayout().x + delta + tx);
  38928. ky = height / (bottom.depth - 1 || 1);
  38929. eachBefore(realRoot, function (node) {
  38930. coorX = (node.getLayout().x + tx) * kx;
  38931. coorY = orient === 'TB' ? (node.depth - 1) * ky : height - (node.depth - 1) * ky;
  38932. node.setLayout({
  38933. x: coorX,
  38934. y: coorY
  38935. }, true);
  38936. });
  38937. }
  38938. }
  38939. }
  38940. }
  38941. /*
  38942. * Licensed to the Apache Software Foundation (ASF) under one
  38943. * or more contributor license agreements. See the NOTICE file
  38944. * distributed with this work for additional information
  38945. * regarding copyright ownership. The ASF licenses this file
  38946. * to you under the Apache License, Version 2.0 (the
  38947. * "License"); you may not use this file except in compliance
  38948. * with the License. You may obtain a copy of the License at
  38949. *
  38950. * http://www.apache.org/licenses/LICENSE-2.0
  38951. *
  38952. * Unless required by applicable law or agreed to in writing,
  38953. * software distributed under the License is distributed on an
  38954. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38955. * KIND, either express or implied. See the License for the
  38956. * specific language governing permissions and limitations
  38957. * under the License.
  38958. */
  38959. registerVisual(visualSymbol('tree', 'circle'));
  38960. registerLayout(treeLayout);
  38961. /*
  38962. * Licensed to the Apache Software Foundation (ASF) under one
  38963. * or more contributor license agreements. See the NOTICE file
  38964. * distributed with this work for additional information
  38965. * regarding copyright ownership. The ASF licenses this file
  38966. * to you under the Apache License, Version 2.0 (the
  38967. * "License"); you may not use this file except in compliance
  38968. * with the License. You may obtain a copy of the License at
  38969. *
  38970. * http://www.apache.org/licenses/LICENSE-2.0
  38971. *
  38972. * Unless required by applicable law or agreed to in writing,
  38973. * software distributed under the License is distributed on an
  38974. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38975. * KIND, either express or implied. See the License for the
  38976. * specific language governing permissions and limitations
  38977. * under the License.
  38978. */
  38979. // Fix for 南海诸岛
  38980. var geoCoord = [126, 25];
  38981. var points$1 = [[[0, 3.5], [7, 11.2], [15, 11.9], [30, 7], [42, 0.7], [52, 0.7], [56, 7.7], [59, 0.7], [64, 0.7], [64, 0], [5, 0], [0, 3.5]], [[13, 16.1], [19, 14.7], [16, 21.7], [11, 23.1], [13, 16.1]], [[12, 32.2], [14, 38.5], [15, 38.5], [13, 32.2], [12, 32.2]], [[16, 47.6], [12, 53.2], [13, 53.2], [18, 47.6], [16, 47.6]], [[6, 64.4], [8, 70], [9, 70], [8, 64.4], [6, 64.4]], [[23, 82.6], [29, 79.8], [30, 79.8], [25, 82.6], [23, 82.6]], [[37, 70.7], [43, 62.3], [44, 62.3], [39, 70.7], [37, 70.7]], [[48, 51.1], [51, 45.5], [53, 45.5], [50, 51.1], [48, 51.1]], [[51, 35], [51, 28.7], [53, 28.7], [53, 35], [51, 35]], [[52, 22.4], [55, 17.5], [56, 17.5], [53, 22.4], [52, 22.4]], [[58, 12.6], [62, 7], [63, 7], [60, 12.6], [58, 12.6]], [[0, 3.5], [0, 93.1], [64, 93.1], [64, 0], [63, 0], [63, 92.4], [1, 92.4], [1, 3.5], [0, 3.5]]];
  38982. for (var i$1 = 0; i$1 < points$1.length; i$1++) {
  38983. for (var k = 0; k < points$1[i$1].length; k++) {
  38984. points$1[i$1][k][0] /= 10.5;
  38985. points$1[i$1][k][1] /= -10.5 / 0.75;
  38986. points$1[i$1][k][0] += geoCoord[0];
  38987. points$1[i$1][k][1] += geoCoord[1];
  38988. }
  38989. }
  38990. var fixNanhai = function (mapType, regions) {
  38991. if (mapType === 'china') {
  38992. regions.push(new Region('南海诸岛', map(points$1, function (exterior) {
  38993. return {
  38994. type: 'polygon',
  38995. exterior: exterior
  38996. };
  38997. }), geoCoord));
  38998. }
  38999. };
  39000. /*
  39001. * Licensed to the Apache Software Foundation (ASF) under one
  39002. * or more contributor license agreements. See the NOTICE file
  39003. * distributed with this work for additional information
  39004. * regarding copyright ownership. The ASF licenses this file
  39005. * to you under the Apache License, Version 2.0 (the
  39006. * "License"); you may not use this file except in compliance
  39007. * with the License. You may obtain a copy of the License at
  39008. *
  39009. * http://www.apache.org/licenses/LICENSE-2.0
  39010. *
  39011. * Unless required by applicable law or agreed to in writing,
  39012. * software distributed under the License is distributed on an
  39013. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39014. * KIND, either express or implied. See the License for the
  39015. * specific language governing permissions and limitations
  39016. * under the License.
  39017. */
  39018. var coordsOffsetMap = {
  39019. '南海诸岛': [32, 80],
  39020. // 全国
  39021. '广东': [0, -10],
  39022. '香港': [10, 5],
  39023. '澳门': [-10, 10],
  39024. //'北京': [-10, 0],
  39025. '天津': [5, 5]
  39026. };
  39027. var fixTextCoord = function (mapType, region) {
  39028. if (mapType === 'china') {
  39029. var coordFix = coordsOffsetMap[region.name];
  39030. if (coordFix) {
  39031. var cp = region.center;
  39032. cp[0] += coordFix[0] / 10.5;
  39033. cp[1] += -coordFix[1] / (10.5 / 0.75);
  39034. }
  39035. }
  39036. };
  39037. /*
  39038. * Licensed to the Apache Software Foundation (ASF) under one
  39039. * or more contributor license agreements. See the NOTICE file
  39040. * distributed with this work for additional information
  39041. * regarding copyright ownership. The ASF licenses this file
  39042. * to you under the Apache License, Version 2.0 (the
  39043. * "License"); you may not use this file except in compliance
  39044. * with the License. You may obtain a copy of the License at
  39045. *
  39046. * http://www.apache.org/licenses/LICENSE-2.0
  39047. *
  39048. * Unless required by applicable law or agreed to in writing,
  39049. * software distributed under the License is distributed on an
  39050. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39051. * KIND, either express or implied. See the License for the
  39052. * specific language governing permissions and limitations
  39053. * under the License.
  39054. */
  39055. var geoCoordMap = {
  39056. 'Russia': [100, 60],
  39057. 'United States': [-99, 38],
  39058. 'United States of America': [-99, 38]
  39059. };
  39060. var fixGeoCoord = function (mapType, region) {
  39061. if (mapType === 'world') {
  39062. var geoCoord = geoCoordMap[region.name];
  39063. if (geoCoord) {
  39064. var cp = region.center;
  39065. cp[0] = geoCoord[0];
  39066. cp[1] = geoCoord[1];
  39067. }
  39068. }
  39069. };
  39070. /*
  39071. * Licensed to the Apache Software Foundation (ASF) under one
  39072. * or more contributor license agreements. See the NOTICE file
  39073. * distributed with this work for additional information
  39074. * regarding copyright ownership. The ASF licenses this file
  39075. * to you under the Apache License, Version 2.0 (the
  39076. * "License"); you may not use this file except in compliance
  39077. * with the License. You may obtain a copy of the License at
  39078. *
  39079. * http://www.apache.org/licenses/LICENSE-2.0
  39080. *
  39081. * Unless required by applicable law or agreed to in writing,
  39082. * software distributed under the License is distributed on an
  39083. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39084. * KIND, either express or implied. See the License for the
  39085. * specific language governing permissions and limitations
  39086. * under the License.
  39087. */
  39088. // Fix for 钓鱼岛
  39089. // var Region = require('../Region');
  39090. // var zrUtil = require('zrender/src/core/util');
  39091. // var geoCoord = [126, 25];
  39092. var points$2 = [[[123.45165252685547, 25.73527164402261], [123.49731445312499, 25.73527164402261], [123.49731445312499, 25.750734064600884], [123.45165252685547, 25.750734064600884], [123.45165252685547, 25.73527164402261]]];
  39093. var fixDiaoyuIsland = function (mapType, region) {
  39094. if (mapType === 'china' && region.name === '台湾') {
  39095. region.geometries.push({
  39096. type: 'polygon',
  39097. exterior: points$2[0]
  39098. });
  39099. }
  39100. };
  39101. /*
  39102. * Licensed to the Apache Software Foundation (ASF) under one
  39103. * or more contributor license agreements. See the NOTICE file
  39104. * distributed with this work for additional information
  39105. * regarding copyright ownership. The ASF licenses this file
  39106. * to you under the Apache License, Version 2.0 (the
  39107. * "License"); you may not use this file except in compliance
  39108. * with the License. You may obtain a copy of the License at
  39109. *
  39110. * http://www.apache.org/licenses/LICENSE-2.0
  39111. *
  39112. * Unless required by applicable law or agreed to in writing,
  39113. * software distributed under the License is distributed on an
  39114. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39115. * KIND, either express or implied. See the License for the
  39116. * specific language governing permissions and limitations
  39117. * under the License.
  39118. */
  39119. var inner$7 = makeInner();
  39120. var geoJSONLoader = {
  39121. /**
  39122. * @param {string} mapName
  39123. * @param {Object} mapRecord {specialAreas, geoJSON}
  39124. * @param {string} nameProperty
  39125. * @return {Object} {regions, boundingRect}
  39126. */
  39127. load: function (mapName, mapRecord, nameProperty) {
  39128. var parsed = inner$7(mapRecord).parsed;
  39129. if (parsed) {
  39130. return parsed;
  39131. }
  39132. var specialAreas = mapRecord.specialAreas || {};
  39133. var geoJSON = mapRecord.geoJSON;
  39134. var regions; // https://jsperf.com/try-catch-performance-overhead
  39135. try {
  39136. regions = geoJSON ? parseGeoJson$1(geoJSON, nameProperty) : [];
  39137. } catch (e) {
  39138. throw new Error('Invalid geoJson format\n' + e.message);
  39139. }
  39140. fixNanhai(mapName, regions);
  39141. each$1(regions, function (region) {
  39142. var regionName = region.name;
  39143. fixTextCoord(mapName, region);
  39144. fixGeoCoord(mapName, region);
  39145. fixDiaoyuIsland(mapName, region); // Some area like Alaska in USA map needs to be tansformed
  39146. // to look better
  39147. var specialArea = specialAreas[regionName];
  39148. if (specialArea) {
  39149. region.transformTo(specialArea.left, specialArea.top, specialArea.width, specialArea.height);
  39150. }
  39151. });
  39152. return inner$7(mapRecord).parsed = {
  39153. regions: regions,
  39154. boundingRect: getBoundingRect$1(regions)
  39155. };
  39156. }
  39157. };
  39158. function getBoundingRect$1(regions) {
  39159. var rect;
  39160. for (var i = 0; i < regions.length; i++) {
  39161. var regionRect = regions[i].getBoundingRect();
  39162. rect = rect || regionRect.clone();
  39163. rect.union(regionRect);
  39164. }
  39165. return rect;
  39166. }
  39167. /*
  39168. * Licensed to the Apache Software Foundation (ASF) under one
  39169. * or more contributor license agreements. See the NOTICE file
  39170. * distributed with this work for additional information
  39171. * regarding copyright ownership. The ASF licenses this file
  39172. * to you under the Apache License, Version 2.0 (the
  39173. * "License"); you may not use this file except in compliance
  39174. * with the License. You may obtain a copy of the License at
  39175. *
  39176. * http://www.apache.org/licenses/LICENSE-2.0
  39177. *
  39178. * Unless required by applicable law or agreed to in writing,
  39179. * software distributed under the License is distributed on an
  39180. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39181. * KIND, either express or implied. See the License for the
  39182. * specific language governing permissions and limitations
  39183. * under the License.
  39184. */
  39185. var inner$8 = makeInner();
  39186. var geoSVGLoader = {
  39187. /**
  39188. * @param {string} mapName
  39189. * @param {Object} mapRecord {specialAreas, geoJSON}
  39190. * @return {Object} {root, boundingRect}
  39191. */
  39192. load: function (mapName, mapRecord) {
  39193. var originRoot = inner$8(mapRecord).originRoot;
  39194. if (originRoot) {
  39195. return {
  39196. root: originRoot,
  39197. boundingRect: inner$8(mapRecord).boundingRect
  39198. };
  39199. }
  39200. var graphic = buildGraphic(mapRecord);
  39201. inner$8(mapRecord).originRoot = graphic.root;
  39202. inner$8(mapRecord).boundingRect = graphic.boundingRect;
  39203. return graphic;
  39204. },
  39205. makeGraphic: function (mapName, mapRecord, hostKey) {
  39206. // For performance consideration (in large SVG), graphic only maked
  39207. // when necessary and reuse them according to hostKey.
  39208. var field = inner$8(mapRecord);
  39209. var rootMap = field.rootMap || (field.rootMap = createHashMap());
  39210. var root = rootMap.get(hostKey);
  39211. if (root) {
  39212. return root;
  39213. }
  39214. var originRoot = field.originRoot;
  39215. var boundingRect = field.boundingRect; // For performance, if originRoot is not used by a view,
  39216. // assign it to a view, but not reproduce graphic elements.
  39217. if (!field.originRootHostKey) {
  39218. field.originRootHostKey = hostKey;
  39219. root = originRoot;
  39220. } else {
  39221. root = buildGraphic(mapRecord, boundingRect).root;
  39222. }
  39223. return rootMap.set(hostKey, root);
  39224. },
  39225. removeGraphic: function (mapName, mapRecord, hostKey) {
  39226. var field = inner$8(mapRecord);
  39227. var rootMap = field.rootMap;
  39228. rootMap && rootMap.removeKey(hostKey);
  39229. if (hostKey === field.originRootHostKey) {
  39230. field.originRootHostKey = null;
  39231. }
  39232. }
  39233. };
  39234. function buildGraphic(mapRecord, boundingRect) {
  39235. var svgXML = mapRecord.svgXML;
  39236. var result;
  39237. var root;
  39238. try {
  39239. result = svgXML && parseSVG(svgXML, {
  39240. ignoreViewBox: true,
  39241. ignoreRootClip: true
  39242. }) || {};
  39243. root = result.root;
  39244. assert$1(root != null);
  39245. } catch (e) {
  39246. throw new Error('Invalid svg format\n' + e.message);
  39247. }
  39248. var svgWidth = result.width;
  39249. var svgHeight = result.height;
  39250. var viewBoxRect = result.viewBoxRect;
  39251. if (!boundingRect) {
  39252. boundingRect = svgWidth == null || svgHeight == null ? // If svg width / height not specified, calculate
  39253. // bounding rect as the width / height
  39254. root.getBoundingRect() : new BoundingRect(0, 0, 0, 0);
  39255. if (svgWidth != null) {
  39256. boundingRect.width = svgWidth;
  39257. }
  39258. if (svgHeight != null) {
  39259. boundingRect.height = svgHeight;
  39260. }
  39261. }
  39262. if (viewBoxRect) {
  39263. var viewBoxTransform = makeViewBoxTransform(viewBoxRect, boundingRect.width, boundingRect.height);
  39264. var elRoot = root;
  39265. root = new Group();
  39266. root.add(elRoot);
  39267. elRoot.scale = viewBoxTransform.scale;
  39268. elRoot.position = viewBoxTransform.position;
  39269. }
  39270. root.setClipPath(new Rect({
  39271. shape: boundingRect.plain()
  39272. }));
  39273. return {
  39274. root: root,
  39275. boundingRect: boundingRect
  39276. };
  39277. }
  39278. /*
  39279. * Licensed to the Apache Software Foundation (ASF) under one
  39280. * or more contributor license agreements. See the NOTICE file
  39281. * distributed with this work for additional information
  39282. * regarding copyright ownership. The ASF licenses this file
  39283. * to you under the Apache License, Version 2.0 (the
  39284. * "License"); you may not use this file except in compliance
  39285. * with the License. You may obtain a copy of the License at
  39286. *
  39287. * http://www.apache.org/licenses/LICENSE-2.0
  39288. *
  39289. * Unless required by applicable law or agreed to in writing,
  39290. * software distributed under the License is distributed on an
  39291. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39292. * KIND, either express or implied. See the License for the
  39293. * specific language governing permissions and limitations
  39294. * under the License.
  39295. */
  39296. var loaders = {
  39297. geoJSON: geoJSONLoader,
  39298. svg: geoSVGLoader
  39299. };
  39300. var geoSourceManager = {
  39301. /**
  39302. * @param {string} mapName
  39303. * @param {Object} nameMap
  39304. * @param {string} nameProperty
  39305. * @return {Object} source {regions, regionsMap, nameCoordMap, boundingRect}
  39306. */
  39307. load: function (mapName, nameMap, nameProperty) {
  39308. var regions = [];
  39309. var regionsMap = createHashMap();
  39310. var nameCoordMap = createHashMap();
  39311. var boundingRect;
  39312. var mapRecords = retrieveMap(mapName);
  39313. each$1(mapRecords, function (record) {
  39314. var singleSource = loaders[record.type].load(mapName, record, nameProperty);
  39315. each$1(singleSource.regions, function (region) {
  39316. var regionName = region.name; // Try use the alias in geoNameMap
  39317. if (nameMap && nameMap.hasOwnProperty(regionName)) {
  39318. region = region.cloneShallow(regionName = nameMap[regionName]);
  39319. }
  39320. regions.push(region);
  39321. regionsMap.set(regionName, region);
  39322. nameCoordMap.set(regionName, region.center);
  39323. });
  39324. var rect = singleSource.boundingRect;
  39325. if (rect) {
  39326. boundingRect ? boundingRect.union(rect) : boundingRect = rect.clone();
  39327. }
  39328. });
  39329. return {
  39330. regions: regions,
  39331. regionsMap: regionsMap,
  39332. nameCoordMap: nameCoordMap,
  39333. // FIXME Always return new ?
  39334. boundingRect: boundingRect || new BoundingRect(0, 0, 0, 0)
  39335. };
  39336. },
  39337. /**
  39338. * @param {string} mapName
  39339. * @param {string} hostKey For cache.
  39340. * @return {Array.<module:zrender/Element>} Roots.
  39341. */
  39342. makeGraphic: makeInvoker('makeGraphic'),
  39343. /**
  39344. * @param {string} mapName
  39345. * @param {string} hostKey For cache.
  39346. */
  39347. removeGraphic: makeInvoker('removeGraphic')
  39348. };
  39349. function makeInvoker(methodName) {
  39350. return function (mapName, hostKey) {
  39351. var mapRecords = retrieveMap(mapName);
  39352. var results = [];
  39353. each$1(mapRecords, function (record) {
  39354. var method = loaders[record.type][methodName];
  39355. method && results.push(method(mapName, record, hostKey));
  39356. });
  39357. return results;
  39358. };
  39359. }
  39360. function retrieveMap(mapName) {
  39361. var mapRecords = mapDataStorage.retrieveMap(mapName) || [];
  39362. return mapRecords;
  39363. }
  39364. /*
  39365. * Licensed to the Apache Software Foundation (ASF) under one
  39366. * or more contributor license agreements. See the NOTICE file
  39367. * distributed with this work for additional information
  39368. * regarding copyright ownership. The ASF licenses this file
  39369. * to you under the Apache License, Version 2.0 (the
  39370. * "License"); you may not use this file except in compliance
  39371. * with the License. You may obtain a copy of the License at
  39372. *
  39373. * http://www.apache.org/licenses/LICENSE-2.0
  39374. *
  39375. * Unless required by applicable law or agreed to in writing,
  39376. * software distributed under the License is distributed on an
  39377. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39378. * KIND, either express or implied. See the License for the
  39379. * specific language governing permissions and limitations
  39380. * under the License.
  39381. */
  39382. var MapSeries = SeriesModel.extend({
  39383. type: 'series.map',
  39384. dependencies: ['geo'],
  39385. layoutMode: 'box',
  39386. /**
  39387. * Only first map series of same mapType will drawMap
  39388. * @type {boolean}
  39389. */
  39390. needsDrawMap: false,
  39391. /**
  39392. * Group of all map series with same mapType
  39393. * @type {boolean}
  39394. */
  39395. seriesGroup: [],
  39396. getInitialData: function (option) {
  39397. var data = createListSimply(this, {
  39398. coordDimensions: ['value'],
  39399. encodeDefaulter: curry(makeSeriesEncodeForNameBased, this)
  39400. });
  39401. var valueDim = data.mapDimension('value');
  39402. var dataNameMap = createHashMap();
  39403. var selectTargetList = [];
  39404. var toAppendNames = [];
  39405. for (var i = 0, len = data.count(); i < len; i++) {
  39406. var name = data.getName(i);
  39407. dataNameMap.set(name, true);
  39408. selectTargetList.push({
  39409. name: name,
  39410. value: data.get(valueDim, i),
  39411. selected: retrieveRawAttr(data, i, 'selected')
  39412. });
  39413. }
  39414. var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap, this.option.nameProperty);
  39415. each$1(geoSource.regions, function (region) {
  39416. var name = region.name;
  39417. if (!dataNameMap.get(name)) {
  39418. selectTargetList.push({
  39419. name: name
  39420. });
  39421. toAppendNames.push(name);
  39422. }
  39423. });
  39424. this.updateSelectedMap(selectTargetList); // Complete data with missing regions. The consequent processes (like visual
  39425. // map and render) can not be performed without a "full data". For example,
  39426. // find `dataIndex` by name.
  39427. data.appendValues([], toAppendNames);
  39428. return data;
  39429. },
  39430. /**
  39431. * If no host geo model, return null, which means using a
  39432. * inner exclusive geo model.
  39433. */
  39434. getHostGeoModel: function () {
  39435. var geoIndex = this.option.geoIndex;
  39436. return geoIndex != null ? this.dependentModels.geo[geoIndex] : null;
  39437. },
  39438. getMapType: function () {
  39439. return (this.getHostGeoModel() || this).option.map;
  39440. },
  39441. // _fillOption: function (option, mapName) {
  39442. // Shallow clone
  39443. // option = zrUtil.extend({}, option);
  39444. // option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
  39445. // return option;
  39446. // },
  39447. getRawValue: function (dataIndex) {
  39448. // Use value stored in data instead because it is calculated from multiple series
  39449. // FIXME Provide all value of multiple series ?
  39450. var data = this.getData();
  39451. return data.get(data.mapDimension('value'), dataIndex);
  39452. },
  39453. /**
  39454. * Get model of region
  39455. * @param {string} name
  39456. * @return {module:echarts/model/Model}
  39457. */
  39458. getRegionModel: function (regionName) {
  39459. var data = this.getData();
  39460. return data.getItemModel(data.indexOfName(regionName));
  39461. },
  39462. /**
  39463. * Map tooltip formatter
  39464. *
  39465. * @param {number} dataIndex
  39466. */
  39467. formatTooltip: function (dataIndex) {
  39468. // FIXME orignalData and data is a bit confusing
  39469. var data = this.getData();
  39470. var formattedValue = addCommas(this.getRawValue(dataIndex));
  39471. var name = data.getName(dataIndex);
  39472. var seriesGroup = this.seriesGroup;
  39473. var seriesNames = [];
  39474. for (var i = 0; i < seriesGroup.length; i++) {
  39475. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  39476. var valueDim = data.mapDimension('value');
  39477. if (!isNaN(seriesGroup[i].originalData.get(valueDim, otherIndex))) {
  39478. seriesNames.push(encodeHTML(seriesGroup[i].name));
  39479. }
  39480. }
  39481. return seriesNames.join(', ') + '<br />' + encodeHTML(name + ' : ' + formattedValue);
  39482. },
  39483. /**
  39484. * @implement
  39485. */
  39486. getTooltipPosition: function (dataIndex) {
  39487. if (dataIndex != null) {
  39488. var name = this.getData().getName(dataIndex);
  39489. var geo = this.coordinateSystem;
  39490. var region = geo.getRegion(name);
  39491. return region && geo.dataToPoint(region.center);
  39492. }
  39493. },
  39494. setZoom: function (zoom) {
  39495. this.option.zoom = zoom;
  39496. },
  39497. setCenter: function (center) {
  39498. this.option.center = center;
  39499. },
  39500. defaultOption: {
  39501. // 一级层叠
  39502. zlevel: 0,
  39503. // 二级层叠
  39504. z: 2,
  39505. coordinateSystem: 'geo',
  39506. // map should be explicitly specified since ec3.
  39507. map: '',
  39508. // If `geoIndex` is not specified, a exclusive geo will be
  39509. // created. Otherwise use the specified geo component, and
  39510. // `map` and `mapType` are ignored.
  39511. // geoIndex: 0,
  39512. // 'center' | 'left' | 'right' | 'x%' | {number}
  39513. left: 'center',
  39514. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  39515. top: 'center',
  39516. // right
  39517. // bottom
  39518. // width:
  39519. // height
  39520. // Aspect is width / height. Inited to be geoJson bbox aspect
  39521. // This parameter is used for scale this aspect
  39522. aspectScale: 0.75,
  39523. ///// Layout with center and size
  39524. // If you wan't to put map in a fixed size box with right aspect ratio
  39525. // This two properties may more conveninet
  39526. // layoutCenter: [50%, 50%]
  39527. // layoutSize: 100
  39528. // 数值合并方式,默认加和,可选为:
  39529. // 'sum' | 'average' | 'max' | 'min'
  39530. // mapValueCalculation: 'sum',
  39531. // 地图数值计算结果小数精度
  39532. // mapValuePrecision: 0,
  39533. // 显示图例颜色标识(系列标识的小圆点),图例开启时有效
  39534. showLegendSymbol: true,
  39535. // 选择模式,默认关闭,可选single,multiple
  39536. // selectedMode: false,
  39537. dataRangeHoverLink: true,
  39538. // 是否开启缩放及漫游模式
  39539. // roam: false,
  39540. // Define left-top, right-bottom coords to control view
  39541. // For example, [ [180, 90], [-180, -90] ],
  39542. // higher priority than center and zoom
  39543. boundingCoords: null,
  39544. // Default on center of map
  39545. center: null,
  39546. zoom: 1,
  39547. scaleLimit: null,
  39548. label: {
  39549. show: false,
  39550. color: '#000'
  39551. },
  39552. // scaleLimit: null,
  39553. itemStyle: {
  39554. borderWidth: 0.5,
  39555. borderColor: '#444',
  39556. areaColor: '#eee'
  39557. },
  39558. emphasis: {
  39559. label: {
  39560. show: true,
  39561. color: 'rgb(100,0,0)'
  39562. },
  39563. itemStyle: {
  39564. areaColor: 'rgba(255,215,0,0.8)'
  39565. }
  39566. },
  39567. nameProperty: 'name'
  39568. }
  39569. });
  39570. mixin(MapSeries, dataSelectableMixin);
  39571. /*
  39572. * Licensed to the Apache Software Foundation (ASF) under one
  39573. * or more contributor license agreements. See the NOTICE file
  39574. * distributed with this work for additional information
  39575. * regarding copyright ownership. The ASF licenses this file
  39576. * to you under the Apache License, Version 2.0 (the
  39577. * "License"); you may not use this file except in compliance
  39578. * with the License. You may obtain a copy of the License at
  39579. *
  39580. * http://www.apache.org/licenses/LICENSE-2.0
  39581. *
  39582. * Unless required by applicable law or agreed to in writing,
  39583. * software distributed under the License is distributed on an
  39584. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39585. * KIND, either express or implied. See the License for the
  39586. * specific language governing permissions and limitations
  39587. * under the License.
  39588. */
  39589. function getFixedItemStyle(model) {
  39590. var itemStyle = model.getItemStyle();
  39591. var areaColor = model.get('areaColor'); // If user want the color not to be changed when hover,
  39592. // they should both set areaColor and color to be null.
  39593. if (areaColor != null) {
  39594. itemStyle.fill = areaColor;
  39595. }
  39596. return itemStyle;
  39597. }
  39598. function updateMapSelectHandler(mapDraw, mapOrGeoModel, regionsGroup, api, fromView) {
  39599. regionsGroup.off('click');
  39600. regionsGroup.off('mousedown');
  39601. if (mapOrGeoModel.get('selectedMode')) {
  39602. regionsGroup.on('mousedown', function () {
  39603. mapDraw._mouseDownFlag = true;
  39604. });
  39605. regionsGroup.on('click', function (e) {
  39606. if (!mapDraw._mouseDownFlag) {
  39607. return;
  39608. }
  39609. mapDraw._mouseDownFlag = false;
  39610. var el = e.target;
  39611. while (!el.__regions) {
  39612. el = el.parent;
  39613. }
  39614. if (!el) {
  39615. return;
  39616. }
  39617. var action = {
  39618. type: (mapOrGeoModel.mainType === 'geo' ? 'geo' : 'map') + 'ToggleSelect',
  39619. batch: map(el.__regions, function (region) {
  39620. return {
  39621. name: region.name,
  39622. from: fromView.uid
  39623. };
  39624. })
  39625. };
  39626. action[mapOrGeoModel.mainType + 'Id'] = mapOrGeoModel.id;
  39627. api.dispatchAction(action);
  39628. updateMapSelected(mapOrGeoModel, regionsGroup);
  39629. });
  39630. }
  39631. }
  39632. function updateMapSelected(mapOrGeoModel, regionsGroup) {
  39633. // FIXME
  39634. regionsGroup.eachChild(function (otherRegionEl) {
  39635. each$1(otherRegionEl.__regions, function (region) {
  39636. otherRegionEl.trigger(mapOrGeoModel.isSelected(region.name) ? 'emphasis' : 'normal');
  39637. });
  39638. });
  39639. }
  39640. /**
  39641. * @alias module:echarts/component/helper/MapDraw
  39642. * @param {module:echarts/ExtensionAPI} api
  39643. * @param {boolean} updateGroup
  39644. */
  39645. function MapDraw(api, updateGroup) {
  39646. var group = new Group();
  39647. /**
  39648. * @type {string}
  39649. * @private
  39650. */
  39651. this.uid = getUID('ec_map_draw');
  39652. /**
  39653. * @type {module:echarts/component/helper/RoamController}
  39654. * @private
  39655. */
  39656. this._controller = new RoamController(api.getZr());
  39657. /**
  39658. * @type {Object} {target, zoom, zoomLimit}
  39659. * @private
  39660. */
  39661. this._controllerHost = {
  39662. target: updateGroup ? group : null
  39663. };
  39664. /**
  39665. * @type {module:zrender/container/Group}
  39666. * @readOnly
  39667. */
  39668. this.group = group;
  39669. /**
  39670. * @type {boolean}
  39671. * @private
  39672. */
  39673. this._updateGroup = updateGroup;
  39674. /**
  39675. * This flag is used to make sure that only one among
  39676. * `pan`, `zoom`, `click` can occurs, otherwise 'selected'
  39677. * action may be triggered when `pan`, which is unexpected.
  39678. * @type {booelan}
  39679. */
  39680. this._mouseDownFlag;
  39681. /**
  39682. * @type {string}
  39683. */
  39684. this._mapName;
  39685. /**
  39686. * @type {boolean}
  39687. */
  39688. this._initialized;
  39689. /**
  39690. * @type {module:zrender/container/Group}
  39691. */
  39692. group.add(this._regionsGroup = new Group());
  39693. /**
  39694. * @type {module:zrender/container/Group}
  39695. */
  39696. group.add(this._backgroundGroup = new Group());
  39697. }
  39698. MapDraw.prototype = {
  39699. constructor: MapDraw,
  39700. draw: function (mapOrGeoModel, ecModel, api, fromView, payload) {
  39701. var isGeo = mapOrGeoModel.mainType === 'geo'; // Map series has data. GEO model that controlled by map series
  39702. // will be assigned with map data. Other GEO model has no data.
  39703. var data = mapOrGeoModel.getData && mapOrGeoModel.getData();
  39704. isGeo && ecModel.eachComponent({
  39705. mainType: 'series',
  39706. subType: 'map'
  39707. }, function (mapSeries) {
  39708. if (!data && mapSeries.getHostGeoModel() === mapOrGeoModel) {
  39709. data = mapSeries.getData();
  39710. }
  39711. });
  39712. var geo = mapOrGeoModel.coordinateSystem;
  39713. this._updateBackground(geo);
  39714. var regionsGroup = this._regionsGroup;
  39715. var group = this.group;
  39716. var transformInfo = geo.getTransformInfo(); // No animation when first draw or in action
  39717. var isFirstDraw = !regionsGroup.childAt(0) || payload;
  39718. var targetScale;
  39719. if (isFirstDraw) {
  39720. group.transform = transformInfo.roamTransform;
  39721. group.decomposeTransform();
  39722. group.dirty();
  39723. } else {
  39724. var target = new Transformable();
  39725. target.transform = transformInfo.roamTransform;
  39726. target.decomposeTransform();
  39727. var props = {
  39728. scale: target.scale,
  39729. position: target.position
  39730. };
  39731. targetScale = target.scale;
  39732. updateProps(group, props, mapOrGeoModel);
  39733. }
  39734. var scale = transformInfo.rawScale;
  39735. var position = transformInfo.rawPosition;
  39736. regionsGroup.removeAll();
  39737. var itemStyleAccessPath = ['itemStyle'];
  39738. var hoverItemStyleAccessPath = ['emphasis', 'itemStyle'];
  39739. var labelAccessPath = ['label'];
  39740. var hoverLabelAccessPath = ['emphasis', 'label'];
  39741. var nameMap = createHashMap();
  39742. each$1(geo.regions, function (region) {
  39743. // Consider in GeoJson properties.name may be duplicated, for example,
  39744. // there is multiple region named "United Kindom" or "France" (so many
  39745. // colonies). And it is not appropriate to merge them in geo, which
  39746. // will make them share the same label and bring trouble in label
  39747. // location calculation.
  39748. var regionGroup = nameMap.get(region.name) || nameMap.set(region.name, new Group());
  39749. var compoundPath = new CompoundPath({
  39750. segmentIgnoreThreshold: 1,
  39751. shape: {
  39752. paths: []
  39753. }
  39754. });
  39755. regionGroup.add(compoundPath);
  39756. var regionModel = mapOrGeoModel.getRegionModel(region.name) || mapOrGeoModel;
  39757. var itemStyleModel = regionModel.getModel(itemStyleAccessPath);
  39758. var hoverItemStyleModel = regionModel.getModel(hoverItemStyleAccessPath);
  39759. var itemStyle = getFixedItemStyle(itemStyleModel);
  39760. var hoverItemStyle = getFixedItemStyle(hoverItemStyleModel);
  39761. var labelModel = regionModel.getModel(labelAccessPath);
  39762. var hoverLabelModel = regionModel.getModel(hoverLabelAccessPath);
  39763. var dataIdx; // Use the itemStyle in data if has data
  39764. if (data) {
  39765. dataIdx = data.indexOfName(region.name); // Only visual color of each item will be used. It can be encoded by dataRange
  39766. // But visual color of series is used in symbol drawing
  39767. //
  39768. // Visual color for each series is for the symbol draw
  39769. var visualColor = data.getItemVisual(dataIdx, 'color', true);
  39770. if (visualColor) {
  39771. itemStyle.fill = visualColor;
  39772. }
  39773. }
  39774. var transformPoint = function (point) {
  39775. return [point[0] * scale[0] + position[0], point[1] * scale[1] + position[1]];
  39776. };
  39777. each$1(region.geometries, function (geometry) {
  39778. if (geometry.type !== 'polygon') {
  39779. return;
  39780. }
  39781. var points = [];
  39782. for (var i = 0; i < geometry.exterior.length; ++i) {
  39783. points.push(transformPoint(geometry.exterior[i]));
  39784. }
  39785. compoundPath.shape.paths.push(new Polygon({
  39786. segmentIgnoreThreshold: 1,
  39787. shape: {
  39788. points: points
  39789. }
  39790. }));
  39791. for (var i = 0; i < (geometry.interiors ? geometry.interiors.length : 0); ++i) {
  39792. var interior = geometry.interiors[i];
  39793. var points = [];
  39794. for (var j = 0; j < interior.length; ++j) {
  39795. points.push(transformPoint(interior[j]));
  39796. }
  39797. compoundPath.shape.paths.push(new Polygon({
  39798. segmentIgnoreThreshold: 1,
  39799. shape: {
  39800. points: points
  39801. }
  39802. }));
  39803. }
  39804. });
  39805. compoundPath.setStyle(itemStyle);
  39806. compoundPath.style.strokeNoScale = true;
  39807. compoundPath.culling = true; // Label
  39808. var showLabel = labelModel.get('show');
  39809. var hoverShowLabel = hoverLabelModel.get('show');
  39810. var isDataNaN = data && isNaN(data.get(data.mapDimension('value'), dataIdx));
  39811. var itemLayout = data && data.getItemLayout(dataIdx); // In the following cases label will be drawn
  39812. // 1. In map series and data value is NaN
  39813. // 2. In geo component
  39814. // 4. Region has no series legendSymbol, which will be add a showLabel flag in mapSymbolLayout
  39815. if (isGeo || isDataNaN && (showLabel || hoverShowLabel) || itemLayout && itemLayout.showLabel) {
  39816. var query = !isGeo ? dataIdx : region.name;
  39817. var labelFetcher; // Consider dataIdx not found.
  39818. if (!data || dataIdx >= 0) {
  39819. labelFetcher = mapOrGeoModel;
  39820. }
  39821. var textEl = new Text({
  39822. position: transformPoint(region.center.slice()),
  39823. // FIXME
  39824. // label rotation is not support yet in geo or regions of series-map
  39825. // that has no data. The rotation will be effected by this `scale`.
  39826. // So needed to change to RectText?
  39827. scale: [1 / group.scale[0], 1 / group.scale[1]],
  39828. z2: 10,
  39829. silent: true
  39830. });
  39831. setLabelStyle(textEl.style, textEl.hoverStyle = {}, labelModel, hoverLabelModel, {
  39832. labelFetcher: labelFetcher,
  39833. labelDataIndex: query,
  39834. defaultText: region.name,
  39835. useInsideStyle: false
  39836. }, {
  39837. textAlign: 'center',
  39838. textVerticalAlign: 'middle'
  39839. });
  39840. if (!isFirstDraw) {
  39841. // Text animation
  39842. var textScale = [1 / targetScale[0], 1 / targetScale[1]];
  39843. updateProps(textEl, {
  39844. scale: textScale
  39845. }, mapOrGeoModel);
  39846. }
  39847. regionGroup.add(textEl);
  39848. } // setItemGraphicEl, setHoverStyle after all polygons and labels
  39849. // are added to the rigionGroup
  39850. if (data) {
  39851. data.setItemGraphicEl(dataIdx, regionGroup);
  39852. } else {
  39853. var regionModel = mapOrGeoModel.getRegionModel(region.name); // Package custom mouse event for geo component
  39854. compoundPath.eventData = {
  39855. componentType: 'geo',
  39856. componentIndex: mapOrGeoModel.componentIndex,
  39857. geoIndex: mapOrGeoModel.componentIndex,
  39858. name: region.name,
  39859. region: regionModel && regionModel.option || {}
  39860. };
  39861. }
  39862. var groupRegions = regionGroup.__regions || (regionGroup.__regions = []);
  39863. groupRegions.push(region);
  39864. regionGroup.highDownSilentOnTouch = !!mapOrGeoModel.get('selectedMode');
  39865. setHoverStyle(regionGroup, hoverItemStyle);
  39866. regionsGroup.add(regionGroup);
  39867. });
  39868. this._updateController(mapOrGeoModel, ecModel, api);
  39869. updateMapSelectHandler(this, mapOrGeoModel, regionsGroup, api, fromView);
  39870. updateMapSelected(mapOrGeoModel, regionsGroup);
  39871. },
  39872. remove: function () {
  39873. this._regionsGroup.removeAll();
  39874. this._backgroundGroup.removeAll();
  39875. this._controller.dispose();
  39876. this._mapName && geoSourceManager.removeGraphic(this._mapName, this.uid);
  39877. this._mapName = null;
  39878. this._controllerHost = {};
  39879. },
  39880. _updateBackground: function (geo) {
  39881. var mapName = geo.map;
  39882. if (this._mapName !== mapName) {
  39883. each$1(geoSourceManager.makeGraphic(mapName, this.uid), function (root) {
  39884. this._backgroundGroup.add(root);
  39885. }, this);
  39886. }
  39887. this._mapName = mapName;
  39888. },
  39889. _updateController: function (mapOrGeoModel, ecModel, api) {
  39890. var geo = mapOrGeoModel.coordinateSystem;
  39891. var controller = this._controller;
  39892. var controllerHost = this._controllerHost;
  39893. controllerHost.zoomLimit = mapOrGeoModel.get('scaleLimit');
  39894. controllerHost.zoom = geo.getZoom(); // roamType is will be set default true if it is null
  39895. controller.enable(mapOrGeoModel.get('roam') || false);
  39896. var mainType = mapOrGeoModel.mainType;
  39897. function makeActionBase() {
  39898. var action = {
  39899. type: 'geoRoam',
  39900. componentType: mainType
  39901. };
  39902. action[mainType + 'Id'] = mapOrGeoModel.id;
  39903. return action;
  39904. }
  39905. controller.off('pan').on('pan', function (e) {
  39906. this._mouseDownFlag = false;
  39907. updateViewOnPan(controllerHost, e.dx, e.dy);
  39908. api.dispatchAction(extend(makeActionBase(), {
  39909. dx: e.dx,
  39910. dy: e.dy
  39911. }));
  39912. }, this);
  39913. controller.off('zoom').on('zoom', function (e) {
  39914. this._mouseDownFlag = false;
  39915. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  39916. api.dispatchAction(extend(makeActionBase(), {
  39917. zoom: e.scale,
  39918. originX: e.originX,
  39919. originY: e.originY
  39920. }));
  39921. if (this._updateGroup) {
  39922. var scale = this.group.scale;
  39923. this._regionsGroup.traverse(function (el) {
  39924. if (el.type === 'text') {
  39925. el.attr('scale', [1 / scale[0], 1 / scale[1]]);
  39926. }
  39927. });
  39928. }
  39929. }, this);
  39930. controller.setPointerChecker(function (e, x, y) {
  39931. return geo.getViewRectAfterRoam().contain(x, y) && !onIrrelevantElement(e, api, mapOrGeoModel);
  39932. });
  39933. }
  39934. };
  39935. /*
  39936. * Licensed to the Apache Software Foundation (ASF) under one
  39937. * or more contributor license agreements. See the NOTICE file
  39938. * distributed with this work for additional information
  39939. * regarding copyright ownership. The ASF licenses this file
  39940. * to you under the Apache License, Version 2.0 (the
  39941. * "License"); you may not use this file except in compliance
  39942. * with the License. You may obtain a copy of the License at
  39943. *
  39944. * http://www.apache.org/licenses/LICENSE-2.0
  39945. *
  39946. * Unless required by applicable law or agreed to in writing,
  39947. * software distributed under the License is distributed on an
  39948. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39949. * KIND, either express or implied. See the License for the
  39950. * specific language governing permissions and limitations
  39951. * under the License.
  39952. */
  39953. var HIGH_DOWN_PROP = '__seriesMapHighDown';
  39954. var RECORD_VERSION_PROP = '__seriesMapCallKey';
  39955. extendChartView({
  39956. type: 'map',
  39957. render: function (mapModel, ecModel, api, payload) {
  39958. // Not render if it is an toggleSelect action from self
  39959. if (payload && payload.type === 'mapToggleSelect' && payload.from === this.uid) {
  39960. return;
  39961. }
  39962. var group = this.group;
  39963. group.removeAll();
  39964. if (mapModel.getHostGeoModel()) {
  39965. return;
  39966. } // Not update map if it is an roam action from self
  39967. if (!(payload && payload.type === 'geoRoam' && payload.componentType === 'series' && payload.seriesId === mapModel.id)) {
  39968. if (mapModel.needsDrawMap) {
  39969. var mapDraw = this._mapDraw || new MapDraw(api, true);
  39970. group.add(mapDraw.group);
  39971. mapDraw.draw(mapModel, ecModel, api, this, payload);
  39972. this._mapDraw = mapDraw;
  39973. } else {
  39974. // Remove drawed map
  39975. this._mapDraw && this._mapDraw.remove();
  39976. this._mapDraw = null;
  39977. }
  39978. } else {
  39979. var mapDraw = this._mapDraw;
  39980. mapDraw && group.add(mapDraw.group);
  39981. }
  39982. mapModel.get('showLegendSymbol') && ecModel.getComponent('legend') && this._renderSymbols(mapModel, ecModel, api);
  39983. },
  39984. remove: function () {
  39985. this._mapDraw && this._mapDraw.remove();
  39986. this._mapDraw = null;
  39987. this.group.removeAll();
  39988. },
  39989. dispose: function () {
  39990. this._mapDraw && this._mapDraw.remove();
  39991. this._mapDraw = null;
  39992. },
  39993. _renderSymbols: function (mapModel, ecModel, api) {
  39994. var originalData = mapModel.originalData;
  39995. var group = this.group;
  39996. originalData.each(originalData.mapDimension('value'), function (value, originalDataIndex) {
  39997. if (isNaN(value)) {
  39998. return;
  39999. }
  40000. var layout = originalData.getItemLayout(originalDataIndex);
  40001. if (!layout || !layout.point) {
  40002. // Not exists in map
  40003. return;
  40004. }
  40005. var point = layout.point;
  40006. var offset = layout.offset;
  40007. var circle = new Circle({
  40008. style: {
  40009. // Because the special of map draw.
  40010. // Which needs statistic of multiple series and draw on one map.
  40011. // And each series also need a symbol with legend color
  40012. //
  40013. // Layout and visual are put one the different data
  40014. fill: mapModel.getData().getVisual('color')
  40015. },
  40016. shape: {
  40017. cx: point[0] + offset * 9,
  40018. cy: point[1],
  40019. r: 3
  40020. },
  40021. silent: true,
  40022. // Do not overlap the first series, on which labels are displayed.
  40023. z2: 8 + (!offset ? Z2_EMPHASIS_LIFT + 1 : 0)
  40024. }); // Only the series that has the first value on the same region is in charge of rendering the label.
  40025. // But consider the case:
  40026. // series: [
  40027. // {id: 'X', type: 'map', map: 'm', {data: [{name: 'A', value: 11}, {name: 'B', {value: 22}]},
  40028. // {id: 'Y', type: 'map', map: 'm', {data: [{name: 'A', value: 21}, {name: 'C', {value: 33}]}
  40029. // ]
  40030. // The offset `0` of item `A` is at series `X`, but of item `C` is at series `Y`.
  40031. // For backward compatibility, we follow the rule that render label `A` by the
  40032. // settings on series `X` but render label `C` by the settings on series `Y`.
  40033. if (!offset) {
  40034. var fullData = mapModel.mainSeries.getData();
  40035. var name = originalData.getName(originalDataIndex);
  40036. var fullIndex = fullData.indexOfName(name);
  40037. var itemModel = originalData.getItemModel(originalDataIndex);
  40038. var labelModel = itemModel.getModel('label');
  40039. var hoverLabelModel = itemModel.getModel('emphasis.label');
  40040. var regionGroup = fullData.getItemGraphicEl(fullIndex); // `getFormattedLabel` needs to use `getData` inside. Here
  40041. // `mapModel.getData()` is shallow cloned from `mainSeries.getData()`.
  40042. // FIXME
  40043. // If this is not the `mainSeries`, the item model (like label formatter)
  40044. // set on original data item will never get. But it has been working
  40045. // like that from the begining, and this scenario is rarely encountered.
  40046. // So it won't be fixed until have to.
  40047. var normalText = retrieve2(mapModel.getFormattedLabel(fullIndex, 'normal'), name);
  40048. var emphasisText = retrieve2(mapModel.getFormattedLabel(fullIndex, 'emphasis'), normalText);
  40049. var highDownRecord = regionGroup[HIGH_DOWN_PROP];
  40050. var recordVersion = Math.random(); // Prevent from register listeners duplicatedly when roaming.
  40051. if (!highDownRecord) {
  40052. highDownRecord = regionGroup[HIGH_DOWN_PROP] = {};
  40053. var onEmphasis = curry(onRegionHighDown, true);
  40054. var onNormal = curry(onRegionHighDown, false);
  40055. regionGroup.on('mouseover', onEmphasis).on('mouseout', onNormal).on('emphasis', onEmphasis).on('normal', onNormal);
  40056. } // Prevent removed regions effect current grapics.
  40057. regionGroup[RECORD_VERSION_PROP] = recordVersion;
  40058. extend(highDownRecord, {
  40059. recordVersion: recordVersion,
  40060. circle: circle,
  40061. labelModel: labelModel,
  40062. hoverLabelModel: hoverLabelModel,
  40063. emphasisText: emphasisText,
  40064. normalText: normalText
  40065. }); // FIXME
  40066. // Consider set option when emphasis.
  40067. enterRegionHighDown(highDownRecord, false);
  40068. }
  40069. group.add(circle);
  40070. });
  40071. }
  40072. });
  40073. function onRegionHighDown(toHighOrDown) {
  40074. var highDownRecord = this[HIGH_DOWN_PROP];
  40075. if (highDownRecord && highDownRecord.recordVersion === this[RECORD_VERSION_PROP]) {
  40076. enterRegionHighDown(highDownRecord, toHighOrDown);
  40077. }
  40078. }
  40079. function enterRegionHighDown(highDownRecord, toHighOrDown) {
  40080. var circle = highDownRecord.circle;
  40081. var labelModel = highDownRecord.labelModel;
  40082. var hoverLabelModel = highDownRecord.hoverLabelModel;
  40083. var emphasisText = highDownRecord.emphasisText;
  40084. var normalText = highDownRecord.normalText;
  40085. if (toHighOrDown) {
  40086. circle.style.extendFrom(setTextStyle({}, hoverLabelModel, {
  40087. text: hoverLabelModel.get('show') ? emphasisText : null
  40088. }, {
  40089. isRectText: true,
  40090. useInsideStyle: false
  40091. }, true)); // Make label upper than others if overlaps.
  40092. circle.__mapOriginalZ2 = circle.z2;
  40093. circle.z2 += Z2_EMPHASIS_LIFT;
  40094. } else {
  40095. setTextStyle(circle.style, labelModel, {
  40096. text: labelModel.get('show') ? normalText : null,
  40097. textPosition: labelModel.getShallow('position') || 'bottom'
  40098. }, {
  40099. isRectText: true,
  40100. useInsideStyle: false
  40101. }); // Trigger normalize style like padding.
  40102. circle.dirty(false);
  40103. if (circle.__mapOriginalZ2 != null) {
  40104. circle.z2 = circle.__mapOriginalZ2;
  40105. circle.__mapOriginalZ2 = null;
  40106. }
  40107. }
  40108. }
  40109. /*
  40110. * Licensed to the Apache Software Foundation (ASF) under one
  40111. * or more contributor license agreements. See the NOTICE file
  40112. * distributed with this work for additional information
  40113. * regarding copyright ownership. The ASF licenses this file
  40114. * to you under the Apache License, Version 2.0 (the
  40115. * "License"); you may not use this file except in compliance
  40116. * with the License. You may obtain a copy of the License at
  40117. *
  40118. * http://www.apache.org/licenses/LICENSE-2.0
  40119. *
  40120. * Unless required by applicable law or agreed to in writing,
  40121. * software distributed under the License is distributed on an
  40122. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40123. * KIND, either express or implied. See the License for the
  40124. * specific language governing permissions and limitations
  40125. * under the License.
  40126. */
  40127. /**
  40128. * @payload
  40129. * @property {string} [componentType=series]
  40130. * @property {number} [dx]
  40131. * @property {number} [dy]
  40132. * @property {number} [zoom]
  40133. * @property {number} [originX]
  40134. * @property {number} [originY]
  40135. */
  40136. registerAction({
  40137. type: 'geoRoam',
  40138. event: 'geoRoam',
  40139. update: 'updateTransform'
  40140. }, function (payload, ecModel) {
  40141. var componentType = payload.componentType || 'series';
  40142. ecModel.eachComponent({
  40143. mainType: componentType,
  40144. query: payload
  40145. }, function (componentModel) {
  40146. var geo = componentModel.coordinateSystem;
  40147. if (geo.type !== 'geo') {
  40148. return;
  40149. }
  40150. var res = updateCenterAndZoom(geo, payload, componentModel.get('scaleLimit'));
  40151. componentModel.setCenter && componentModel.setCenter(res.center);
  40152. componentModel.setZoom && componentModel.setZoom(res.zoom); // All map series with same `map` use the same geo coordinate system
  40153. // So the center and zoom must be in sync. Include the series not selected by legend
  40154. if (componentType === 'series') {
  40155. each$1(componentModel.seriesGroup, function (seriesModel) {
  40156. seriesModel.setCenter(res.center);
  40157. seriesModel.setZoom(res.zoom);
  40158. });
  40159. }
  40160. });
  40161. });
  40162. /*
  40163. * Licensed to the Apache Software Foundation (ASF) under one
  40164. * or more contributor license agreements. See the NOTICE file
  40165. * distributed with this work for additional information
  40166. * regarding copyright ownership. The ASF licenses this file
  40167. * to you under the Apache License, Version 2.0 (the
  40168. * "License"); you may not use this file except in compliance
  40169. * with the License. You may obtain a copy of the License at
  40170. *
  40171. * http://www.apache.org/licenses/LICENSE-2.0
  40172. *
  40173. * Unless required by applicable law or agreed to in writing,
  40174. * software distributed under the License is distributed on an
  40175. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40176. * KIND, either express or implied. See the License for the
  40177. * specific language governing permissions and limitations
  40178. * under the License.
  40179. */
  40180. /**
  40181. * [Geo description]
  40182. * For backward compatibility, the orginal interface:
  40183. * `name, map, geoJson, specialAreas, nameMap` is kept.
  40184. *
  40185. * @param {string|Object} name
  40186. * @param {string} map Map type
  40187. * Specify the positioned areas by left, top, width, height
  40188. * @param {Object.<string, string>} [nameMap]
  40189. * Specify name alias
  40190. * @param {boolean} [invertLongitute=true]
  40191. */
  40192. function Geo(name, map$$1, nameMap, invertLongitute) {
  40193. View.call(this, name);
  40194. /**
  40195. * Map type
  40196. * @type {string}
  40197. */
  40198. this.map = map$$1;
  40199. var source = geoSourceManager.load(map$$1, nameMap);
  40200. this._nameCoordMap = source.nameCoordMap;
  40201. this._regionsMap = source.regionsMap;
  40202. this._invertLongitute = invertLongitute == null ? true : invertLongitute;
  40203. /**
  40204. * @readOnly
  40205. */
  40206. this.regions = source.regions;
  40207. /**
  40208. * @type {module:zrender/src/core/BoundingRect}
  40209. */
  40210. this._rect = source.boundingRect;
  40211. }
  40212. Geo.prototype = {
  40213. constructor: Geo,
  40214. type: 'geo',
  40215. /**
  40216. * @param {Array.<string>}
  40217. * @readOnly
  40218. */
  40219. dimensions: ['lng', 'lat'],
  40220. /**
  40221. * If contain given lng,lat coord
  40222. * @param {Array.<number>}
  40223. * @readOnly
  40224. */
  40225. containCoord: function (coord) {
  40226. var regions = this.regions;
  40227. for (var i = 0; i < regions.length; i++) {
  40228. if (regions[i].contain(coord)) {
  40229. return true;
  40230. }
  40231. }
  40232. return false;
  40233. },
  40234. /**
  40235. * @override
  40236. */
  40237. transformTo: function (x, y, width, height) {
  40238. var rect = this.getBoundingRect();
  40239. var invertLongitute = this._invertLongitute;
  40240. rect = rect.clone();
  40241. if (invertLongitute) {
  40242. // Longitute is inverted
  40243. rect.y = -rect.y - rect.height;
  40244. }
  40245. var rawTransformable = this._rawTransformable;
  40246. rawTransformable.transform = rect.calculateTransform(new BoundingRect(x, y, width, height));
  40247. rawTransformable.decomposeTransform();
  40248. if (invertLongitute) {
  40249. var scale = rawTransformable.scale;
  40250. scale[1] = -scale[1];
  40251. }
  40252. rawTransformable.updateTransform();
  40253. this._updateTransform();
  40254. },
  40255. /**
  40256. * @param {string} name
  40257. * @return {module:echarts/coord/geo/Region}
  40258. */
  40259. getRegion: function (name) {
  40260. return this._regionsMap.get(name);
  40261. },
  40262. getRegionByCoord: function (coord) {
  40263. var regions = this.regions;
  40264. for (var i = 0; i < regions.length; i++) {
  40265. if (regions[i].contain(coord)) {
  40266. return regions[i];
  40267. }
  40268. }
  40269. },
  40270. /**
  40271. * Add geoCoord for indexing by name
  40272. * @param {string} name
  40273. * @param {Array.<number>} geoCoord
  40274. */
  40275. addGeoCoord: function (name, geoCoord) {
  40276. this._nameCoordMap.set(name, geoCoord);
  40277. },
  40278. /**
  40279. * Get geoCoord by name
  40280. * @param {string} name
  40281. * @return {Array.<number>}
  40282. */
  40283. getGeoCoord: function (name) {
  40284. return this._nameCoordMap.get(name);
  40285. },
  40286. /**
  40287. * @override
  40288. */
  40289. getBoundingRect: function () {
  40290. return this._rect;
  40291. },
  40292. /**
  40293. * @param {string|Array.<number>} data
  40294. * @param {boolean} noRoam
  40295. * @param {Array.<number>} [out]
  40296. * @return {Array.<number>}
  40297. */
  40298. dataToPoint: function (data, noRoam, out) {
  40299. if (typeof data === 'string') {
  40300. // Map area name to geoCoord
  40301. data = this.getGeoCoord(data);
  40302. }
  40303. if (data) {
  40304. return View.prototype.dataToPoint.call(this, data, noRoam, out);
  40305. }
  40306. },
  40307. /**
  40308. * @override
  40309. */
  40310. convertToPixel: curry(doConvert$1, 'dataToPoint'),
  40311. /**
  40312. * @override
  40313. */
  40314. convertFromPixel: curry(doConvert$1, 'pointToData')
  40315. };
  40316. mixin(Geo, View);
  40317. function doConvert$1(methodName, ecModel, finder, value) {
  40318. var geoModel = finder.geoModel;
  40319. var seriesModel = finder.seriesModel;
  40320. var coordSys = geoModel ? geoModel.coordinateSystem : seriesModel ? seriesModel.coordinateSystem // For map.
  40321. || (seriesModel.getReferringComponents('geo')[0] || {}).coordinateSystem : null;
  40322. return coordSys === this ? coordSys[methodName](value) : null;
  40323. }
  40324. /*
  40325. * Licensed to the Apache Software Foundation (ASF) under one
  40326. * or more contributor license agreements. See the NOTICE file
  40327. * distributed with this work for additional information
  40328. * regarding copyright ownership. The ASF licenses this file
  40329. * to you under the Apache License, Version 2.0 (the
  40330. * "License"); you may not use this file except in compliance
  40331. * with the License. You may obtain a copy of the License at
  40332. *
  40333. * http://www.apache.org/licenses/LICENSE-2.0
  40334. *
  40335. * Unless required by applicable law or agreed to in writing,
  40336. * software distributed under the License is distributed on an
  40337. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40338. * KIND, either express or implied. See the License for the
  40339. * specific language governing permissions and limitations
  40340. * under the License.
  40341. */
  40342. /**
  40343. * Resize method bound to the geo
  40344. * @param {module:echarts/coord/geo/GeoModel|module:echarts/chart/map/MapModel} geoModel
  40345. * @param {module:echarts/ExtensionAPI} api
  40346. */
  40347. function resizeGeo(geoModel, api) {
  40348. var boundingCoords = geoModel.get('boundingCoords');
  40349. if (boundingCoords != null) {
  40350. var leftTop = boundingCoords[0];
  40351. var rightBottom = boundingCoords[1];
  40352. if (isNaN(leftTop[0]) || isNaN(leftTop[1]) || isNaN(rightBottom[0]) || isNaN(rightBottom[1])) {} else {
  40353. this.setBoundingRect(leftTop[0], leftTop[1], rightBottom[0] - leftTop[0], rightBottom[1] - leftTop[1]);
  40354. }
  40355. }
  40356. var rect = this.getBoundingRect();
  40357. var boxLayoutOption;
  40358. var center = geoModel.get('layoutCenter');
  40359. var size = geoModel.get('layoutSize');
  40360. var viewWidth = api.getWidth();
  40361. var viewHeight = api.getHeight();
  40362. var aspect = rect.width / rect.height * this.aspectScale;
  40363. var useCenterAndSize = false;
  40364. if (center && size) {
  40365. center = [parsePercent$1(center[0], viewWidth), parsePercent$1(center[1], viewHeight)];
  40366. size = parsePercent$1(size, Math.min(viewWidth, viewHeight));
  40367. if (!isNaN(center[0]) && !isNaN(center[1]) && !isNaN(size)) {
  40368. useCenterAndSize = true;
  40369. } else {}
  40370. }
  40371. var viewRect;
  40372. if (useCenterAndSize) {
  40373. var viewRect = {};
  40374. if (aspect > 1) {
  40375. // Width is same with size
  40376. viewRect.width = size;
  40377. viewRect.height = size / aspect;
  40378. } else {
  40379. viewRect.height = size;
  40380. viewRect.width = size * aspect;
  40381. }
  40382. viewRect.y = center[1] - viewRect.height / 2;
  40383. viewRect.x = center[0] - viewRect.width / 2;
  40384. } else {
  40385. // Use left/top/width/height
  40386. boxLayoutOption = geoModel.getBoxLayoutParams(); // 0.75 rate
  40387. boxLayoutOption.aspect = aspect;
  40388. viewRect = getLayoutRect(boxLayoutOption, {
  40389. width: viewWidth,
  40390. height: viewHeight
  40391. });
  40392. }
  40393. this.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
  40394. this.setCenter(geoModel.get('center'));
  40395. this.setZoom(geoModel.get('zoom'));
  40396. }
  40397. /**
  40398. * @param {module:echarts/coord/Geo} geo
  40399. * @param {module:echarts/model/Model} model
  40400. * @inner
  40401. */
  40402. function setGeoCoords(geo, model) {
  40403. each$1(model.get('geoCoord'), function (geoCoord, name) {
  40404. geo.addGeoCoord(name, geoCoord);
  40405. });
  40406. }
  40407. var geoCreator = {
  40408. // For deciding which dimensions to use when creating list data
  40409. dimensions: Geo.prototype.dimensions,
  40410. create: function (ecModel, api) {
  40411. var geoList = []; // FIXME Create each time may be slow
  40412. ecModel.eachComponent('geo', function (geoModel, idx) {
  40413. var name = geoModel.get('map');
  40414. var aspectScale = geoModel.get('aspectScale');
  40415. var invertLongitute = true;
  40416. var mapRecords = mapDataStorage.retrieveMap(name);
  40417. if (mapRecords && mapRecords[0] && mapRecords[0].type === 'svg') {
  40418. aspectScale == null && (aspectScale = 1);
  40419. invertLongitute = false;
  40420. } else {
  40421. aspectScale == null && (aspectScale = 0.75);
  40422. }
  40423. var geo = new Geo(name + idx, name, geoModel.get('nameMap'), invertLongitute);
  40424. geo.aspectScale = aspectScale;
  40425. geo.zoomLimit = geoModel.get('scaleLimit');
  40426. geoList.push(geo);
  40427. setGeoCoords(geo, geoModel);
  40428. geoModel.coordinateSystem = geo;
  40429. geo.model = geoModel; // Inject resize method
  40430. geo.resize = resizeGeo;
  40431. geo.resize(geoModel, api);
  40432. });
  40433. ecModel.eachSeries(function (seriesModel) {
  40434. var coordSys = seriesModel.get('coordinateSystem');
  40435. if (coordSys === 'geo') {
  40436. var geoIndex = seriesModel.get('geoIndex') || 0;
  40437. seriesModel.coordinateSystem = geoList[geoIndex];
  40438. }
  40439. }); // If has map series
  40440. var mapModelGroupBySeries = {};
  40441. ecModel.eachSeriesByType('map', function (seriesModel) {
  40442. if (!seriesModel.getHostGeoModel()) {
  40443. var mapType = seriesModel.getMapType();
  40444. mapModelGroupBySeries[mapType] = mapModelGroupBySeries[mapType] || [];
  40445. mapModelGroupBySeries[mapType].push(seriesModel);
  40446. }
  40447. });
  40448. each$1(mapModelGroupBySeries, function (mapSeries, mapType) {
  40449. var nameMapList = map(mapSeries, function (singleMapSeries) {
  40450. return singleMapSeries.get('nameMap');
  40451. });
  40452. var geo = new Geo(mapType, mapType, mergeAll(nameMapList));
  40453. geo.zoomLimit = retrieve.apply(null, map(mapSeries, function (singleMapSeries) {
  40454. return singleMapSeries.get('scaleLimit');
  40455. }));
  40456. geoList.push(geo); // Inject resize method
  40457. geo.resize = resizeGeo;
  40458. geo.aspectScale = mapSeries[0].get('aspectScale');
  40459. geo.resize(mapSeries[0], api);
  40460. each$1(mapSeries, function (singleMapSeries) {
  40461. singleMapSeries.coordinateSystem = geo;
  40462. setGeoCoords(geo, singleMapSeries);
  40463. });
  40464. });
  40465. return geoList;
  40466. },
  40467. /**
  40468. * Fill given regions array
  40469. * @param {Array.<Object>} originRegionArr
  40470. * @param {string} mapName
  40471. * @param {Object} [nameMap]
  40472. * @return {Array}
  40473. */
  40474. getFilledRegions: function (originRegionArr, mapName, nameMap) {
  40475. // Not use the original
  40476. var regionsArr = (originRegionArr || []).slice();
  40477. var dataNameMap = createHashMap();
  40478. for (var i = 0; i < regionsArr.length; i++) {
  40479. dataNameMap.set(regionsArr[i].name, regionsArr[i]);
  40480. }
  40481. var source = geoSourceManager.load(mapName, nameMap);
  40482. each$1(source.regions, function (region) {
  40483. var name = region.name;
  40484. !dataNameMap.get(name) && regionsArr.push({
  40485. name: name
  40486. });
  40487. });
  40488. return regionsArr;
  40489. }
  40490. };
  40491. registerCoordinateSystem('geo', geoCreator);
  40492. /*
  40493. * Licensed to the Apache Software Foundation (ASF) under one
  40494. * or more contributor license agreements. See the NOTICE file
  40495. * distributed with this work for additional information
  40496. * regarding copyright ownership. The ASF licenses this file
  40497. * to you under the Apache License, Version 2.0 (the
  40498. * "License"); you may not use this file except in compliance
  40499. * with the License. You may obtain a copy of the License at
  40500. *
  40501. * http://www.apache.org/licenses/LICENSE-2.0
  40502. *
  40503. * Unless required by applicable law or agreed to in writing,
  40504. * software distributed under the License is distributed on an
  40505. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40506. * KIND, either express or implied. See the License for the
  40507. * specific language governing permissions and limitations
  40508. * under the License.
  40509. */
  40510. var mapSymbolLayout = function (ecModel) {
  40511. var processedMapType = {};
  40512. ecModel.eachSeriesByType('map', function (mapSeries) {
  40513. var mapType = mapSeries.getMapType();
  40514. if (mapSeries.getHostGeoModel() || processedMapType[mapType]) {
  40515. return;
  40516. }
  40517. var mapSymbolOffsets = {};
  40518. each$1(mapSeries.seriesGroup, function (subMapSeries) {
  40519. var geo = subMapSeries.coordinateSystem;
  40520. var data = subMapSeries.originalData;
  40521. if (subMapSeries.get('showLegendSymbol') && ecModel.getComponent('legend')) {
  40522. data.each(data.mapDimension('value'), function (value, idx) {
  40523. var name = data.getName(idx);
  40524. var region = geo.getRegion(name); // If input series.data is [11, 22, '-'/null/undefined, 44],
  40525. // it will be filled with NaN: [11, 22, NaN, 44] and NaN will
  40526. // not be drawn. So here must validate if value is NaN.
  40527. if (!region || isNaN(value)) {
  40528. return;
  40529. }
  40530. var offset = mapSymbolOffsets[name] || 0;
  40531. var point = geo.dataToPoint(region.center);
  40532. mapSymbolOffsets[name] = offset + 1;
  40533. data.setItemLayout(idx, {
  40534. point: point,
  40535. offset: offset
  40536. });
  40537. });
  40538. }
  40539. }); // Show label of those region not has legendSymbol(which is offset 0)
  40540. var data = mapSeries.getData();
  40541. data.each(function (idx) {
  40542. var name = data.getName(idx);
  40543. var layout = data.getItemLayout(idx) || {};
  40544. layout.showLabel = !mapSymbolOffsets[name];
  40545. data.setItemLayout(idx, layout);
  40546. });
  40547. processedMapType[mapType] = true;
  40548. });
  40549. };
  40550. /*
  40551. * Licensed to the Apache Software Foundation (ASF) under one
  40552. * or more contributor license agreements. See the NOTICE file
  40553. * distributed with this work for additional information
  40554. * regarding copyright ownership. The ASF licenses this file
  40555. * to you under the Apache License, Version 2.0 (the
  40556. * "License"); you may not use this file except in compliance
  40557. * with the License. You may obtain a copy of the License at
  40558. *
  40559. * http://www.apache.org/licenses/LICENSE-2.0
  40560. *
  40561. * Unless required by applicable law or agreed to in writing,
  40562. * software distributed under the License is distributed on an
  40563. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40564. * KIND, either express or implied. See the License for the
  40565. * specific language governing permissions and limitations
  40566. * under the License.
  40567. */
  40568. var mapVisual = function (ecModel) {
  40569. ecModel.eachSeriesByType('map', function (seriesModel) {
  40570. var colorList = seriesModel.get('color');
  40571. var itemStyleModel = seriesModel.getModel('itemStyle');
  40572. var areaColor = itemStyleModel.get('areaColor');
  40573. var color = itemStyleModel.get('color') || colorList[seriesModel.seriesIndex % colorList.length];
  40574. seriesModel.getData().setVisual({
  40575. 'areaColor': areaColor,
  40576. 'color': color
  40577. });
  40578. });
  40579. };
  40580. /*
  40581. * Licensed to the Apache Software Foundation (ASF) under one
  40582. * or more contributor license agreements. See the NOTICE file
  40583. * distributed with this work for additional information
  40584. * regarding copyright ownership. The ASF licenses this file
  40585. * to you under the Apache License, Version 2.0 (the
  40586. * "License"); you may not use this file except in compliance
  40587. * with the License. You may obtain a copy of the License at
  40588. *
  40589. * http://www.apache.org/licenses/LICENSE-2.0
  40590. *
  40591. * Unless required by applicable law or agreed to in writing,
  40592. * software distributed under the License is distributed on an
  40593. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40594. * KIND, either express or implied. See the License for the
  40595. * specific language governing permissions and limitations
  40596. * under the License.
  40597. */
  40598. /**
  40599. * @param {Array.<module:echarts/data/List>} datas
  40600. * @param {string} statisticType 'average' 'sum'
  40601. * @inner
  40602. */
  40603. function dataStatistics(datas, statisticType) {
  40604. var dataNameMap = {};
  40605. each$1(datas, function (data) {
  40606. data.each(data.mapDimension('value'), function (value, idx) {
  40607. // Add prefix to avoid conflict with Object.prototype.
  40608. var mapKey = 'ec-' + data.getName(idx);
  40609. dataNameMap[mapKey] = dataNameMap[mapKey] || [];
  40610. if (!isNaN(value)) {
  40611. dataNameMap[mapKey].push(value);
  40612. }
  40613. });
  40614. });
  40615. return datas[0].map(datas[0].mapDimension('value'), function (value, idx) {
  40616. var mapKey = 'ec-' + datas[0].getName(idx);
  40617. var sum = 0;
  40618. var min = Infinity;
  40619. var max = -Infinity;
  40620. var len = dataNameMap[mapKey].length;
  40621. for (var i = 0; i < len; i++) {
  40622. min = Math.min(min, dataNameMap[mapKey][i]);
  40623. max = Math.max(max, dataNameMap[mapKey][i]);
  40624. sum += dataNameMap[mapKey][i];
  40625. }
  40626. var result;
  40627. if (statisticType === 'min') {
  40628. result = min;
  40629. } else if (statisticType === 'max') {
  40630. result = max;
  40631. } else if (statisticType === 'average') {
  40632. result = sum / len;
  40633. } else {
  40634. result = sum;
  40635. }
  40636. return len === 0 ? NaN : result;
  40637. });
  40638. }
  40639. var mapDataStatistic = function (ecModel) {
  40640. var seriesGroups = {};
  40641. ecModel.eachSeriesByType('map', function (seriesModel) {
  40642. var hostGeoModel = seriesModel.getHostGeoModel();
  40643. var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
  40644. (seriesGroups[key] = seriesGroups[key] || []).push(seriesModel);
  40645. });
  40646. each$1(seriesGroups, function (seriesList, key) {
  40647. var data = dataStatistics(map(seriesList, function (seriesModel) {
  40648. return seriesModel.getData();
  40649. }), seriesList[0].get('mapValueCalculation'));
  40650. for (var i = 0; i < seriesList.length; i++) {
  40651. seriesList[i].originalData = seriesList[i].getData();
  40652. } // FIXME Put where?
  40653. for (var i = 0; i < seriesList.length; i++) {
  40654. seriesList[i].seriesGroup = seriesList;
  40655. seriesList[i].needsDrawMap = i === 0 && !seriesList[i].getHostGeoModel();
  40656. seriesList[i].setData(data.cloneShallow());
  40657. seriesList[i].mainSeries = seriesList[0];
  40658. }
  40659. });
  40660. };
  40661. /*
  40662. * Licensed to the Apache Software Foundation (ASF) under one
  40663. * or more contributor license agreements. See the NOTICE file
  40664. * distributed with this work for additional information
  40665. * regarding copyright ownership. The ASF licenses this file
  40666. * to you under the Apache License, Version 2.0 (the
  40667. * "License"); you may not use this file except in compliance
  40668. * with the License. You may obtain a copy of the License at
  40669. *
  40670. * http://www.apache.org/licenses/LICENSE-2.0
  40671. *
  40672. * Unless required by applicable law or agreed to in writing,
  40673. * software distributed under the License is distributed on an
  40674. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40675. * KIND, either express or implied. See the License for the
  40676. * specific language governing permissions and limitations
  40677. * under the License.
  40678. */
  40679. var backwardCompat$1 = function (option) {
  40680. // Save geoCoord
  40681. var mapSeries = [];
  40682. each$1(option.series, function (seriesOpt) {
  40683. if (seriesOpt && seriesOpt.type === 'map') {
  40684. mapSeries.push(seriesOpt);
  40685. seriesOpt.map = seriesOpt.map || seriesOpt.mapType; // Put x, y, width, height, x2, y2 in the top level
  40686. defaults(seriesOpt, seriesOpt.mapLocation);
  40687. }
  40688. });
  40689. };
  40690. /*
  40691. * Licensed to the Apache Software Foundation (ASF) under one
  40692. * or more contributor license agreements. See the NOTICE file
  40693. * distributed with this work for additional information
  40694. * regarding copyright ownership. The ASF licenses this file
  40695. * to you under the Apache License, Version 2.0 (the
  40696. * "License"); you may not use this file except in compliance
  40697. * with the License. You may obtain a copy of the License at
  40698. *
  40699. * http://www.apache.org/licenses/LICENSE-2.0
  40700. *
  40701. * Unless required by applicable law or agreed to in writing,
  40702. * software distributed under the License is distributed on an
  40703. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40704. * KIND, either express or implied. See the License for the
  40705. * specific language governing permissions and limitations
  40706. * under the License.
  40707. */
  40708. registerLayout(mapSymbolLayout);
  40709. registerVisual(mapVisual);
  40710. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, mapDataStatistic);
  40711. registerPreprocessor(backwardCompat$1);
  40712. createDataSelectAction('map', [{
  40713. type: 'mapToggleSelect',
  40714. event: 'mapselectchanged',
  40715. method: 'toggleSelected'
  40716. }, {
  40717. type: 'mapSelect',
  40718. event: 'mapselected',
  40719. method: 'select'
  40720. }, {
  40721. type: 'mapUnSelect',
  40722. event: 'mapunselected',
  40723. method: 'unSelect'
  40724. }]);
  40725. /*
  40726. * Licensed to the Apache Software Foundation (ASF) under one
  40727. * or more contributor license agreements. See the NOTICE file
  40728. * distributed with this work for additional information
  40729. * regarding copyright ownership. The ASF licenses this file
  40730. * to you under the Apache License, Version 2.0 (the
  40731. * "License"); you may not use this file except in compliance
  40732. * with the License. You may obtain a copy of the License at
  40733. *
  40734. * http://www.apache.org/licenses/LICENSE-2.0
  40735. *
  40736. * Unless required by applicable law or agreed to in writing,
  40737. * software distributed under the License is distributed on an
  40738. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40739. * KIND, either express or implied. See the License for the
  40740. * specific language governing permissions and limitations
  40741. * under the License.
  40742. */
  40743. function generateNodeKey(id) {
  40744. return '_EC_' + id;
  40745. }
  40746. /**
  40747. * @alias module:echarts/data/Graph
  40748. * @constructor
  40749. * @param {boolean} directed
  40750. */
  40751. var Graph = function (directed) {
  40752. /**
  40753. * 是否是有向图
  40754. * @type {boolean}
  40755. * @private
  40756. */
  40757. this._directed = directed || false;
  40758. /**
  40759. * @type {Array.<module:echarts/data/Graph.Node>}
  40760. * @readOnly
  40761. */
  40762. this.nodes = [];
  40763. /**
  40764. * @type {Array.<module:echarts/data/Graph.Edge>}
  40765. * @readOnly
  40766. */
  40767. this.edges = [];
  40768. /**
  40769. * @type {Object.<string, module:echarts/data/Graph.Node>}
  40770. * @private
  40771. */
  40772. this._nodesMap = {};
  40773. /**
  40774. * @type {Object.<string, module:echarts/data/Graph.Edge>}
  40775. * @private
  40776. */
  40777. this._edgesMap = {};
  40778. /**
  40779. * @type {module:echarts/data/List}
  40780. * @readOnly
  40781. */
  40782. this.data;
  40783. /**
  40784. * @type {module:echarts/data/List}
  40785. * @readOnly
  40786. */
  40787. this.edgeData;
  40788. };
  40789. var graphProto = Graph.prototype;
  40790. /**
  40791. * @type {string}
  40792. */
  40793. graphProto.type = 'graph';
  40794. /**
  40795. * If is directed graph
  40796. * @return {boolean}
  40797. */
  40798. graphProto.isDirected = function () {
  40799. return this._directed;
  40800. };
  40801. /**
  40802. * Add a new node
  40803. * @param {string} id
  40804. * @param {number} [dataIndex]
  40805. */
  40806. graphProto.addNode = function (id, dataIndex) {
  40807. id = id == null ? '' + dataIndex : '' + id;
  40808. var nodesMap = this._nodesMap;
  40809. if (nodesMap[generateNodeKey(id)]) {
  40810. return;
  40811. }
  40812. var node = new Node(id, dataIndex);
  40813. node.hostGraph = this;
  40814. this.nodes.push(node);
  40815. nodesMap[generateNodeKey(id)] = node;
  40816. return node;
  40817. };
  40818. /**
  40819. * Get node by data index
  40820. * @param {number} dataIndex
  40821. * @return {module:echarts/data/Graph~Node}
  40822. */
  40823. graphProto.getNodeByIndex = function (dataIndex) {
  40824. var rawIdx = this.data.getRawIndex(dataIndex);
  40825. return this.nodes[rawIdx];
  40826. };
  40827. /**
  40828. * Get node by id
  40829. * @param {string} id
  40830. * @return {module:echarts/data/Graph.Node}
  40831. */
  40832. graphProto.getNodeById = function (id) {
  40833. return this._nodesMap[generateNodeKey(id)];
  40834. };
  40835. /**
  40836. * Add a new edge
  40837. * @param {number|string|module:echarts/data/Graph.Node} n1
  40838. * @param {number|string|module:echarts/data/Graph.Node} n2
  40839. * @param {number} [dataIndex=-1]
  40840. * @return {module:echarts/data/Graph.Edge}
  40841. */
  40842. graphProto.addEdge = function (n1, n2, dataIndex) {
  40843. var nodesMap = this._nodesMap;
  40844. var edgesMap = this._edgesMap; // PNEDING
  40845. if (typeof n1 === 'number') {
  40846. n1 = this.nodes[n1];
  40847. }
  40848. if (typeof n2 === 'number') {
  40849. n2 = this.nodes[n2];
  40850. }
  40851. if (!Node.isInstance(n1)) {
  40852. n1 = nodesMap[generateNodeKey(n1)];
  40853. }
  40854. if (!Node.isInstance(n2)) {
  40855. n2 = nodesMap[generateNodeKey(n2)];
  40856. }
  40857. if (!n1 || !n2) {
  40858. return;
  40859. }
  40860. var key = n1.id + '-' + n2.id; // PENDING
  40861. if (edgesMap[key]) {
  40862. return;
  40863. }
  40864. var edge = new Edge(n1, n2, dataIndex);
  40865. edge.hostGraph = this;
  40866. if (this._directed) {
  40867. n1.outEdges.push(edge);
  40868. n2.inEdges.push(edge);
  40869. }
  40870. n1.edges.push(edge);
  40871. if (n1 !== n2) {
  40872. n2.edges.push(edge);
  40873. }
  40874. this.edges.push(edge);
  40875. edgesMap[key] = edge;
  40876. return edge;
  40877. };
  40878. /**
  40879. * Get edge by data index
  40880. * @param {number} dataIndex
  40881. * @return {module:echarts/data/Graph~Node}
  40882. */
  40883. graphProto.getEdgeByIndex = function (dataIndex) {
  40884. var rawIdx = this.edgeData.getRawIndex(dataIndex);
  40885. return this.edges[rawIdx];
  40886. };
  40887. /**
  40888. * Get edge by two linked nodes
  40889. * @param {module:echarts/data/Graph.Node|string} n1
  40890. * @param {module:echarts/data/Graph.Node|string} n2
  40891. * @return {module:echarts/data/Graph.Edge}
  40892. */
  40893. graphProto.getEdge = function (n1, n2) {
  40894. if (Node.isInstance(n1)) {
  40895. n1 = n1.id;
  40896. }
  40897. if (Node.isInstance(n2)) {
  40898. n2 = n2.id;
  40899. }
  40900. var edgesMap = this._edgesMap;
  40901. if (this._directed) {
  40902. return edgesMap[n1 + '-' + n2];
  40903. } else {
  40904. return edgesMap[n1 + '-' + n2] || edgesMap[n2 + '-' + n1];
  40905. }
  40906. };
  40907. /**
  40908. * Iterate all nodes
  40909. * @param {Function} cb
  40910. * @param {*} [context]
  40911. */
  40912. graphProto.eachNode = function (cb, context) {
  40913. var nodes = this.nodes;
  40914. var len = nodes.length;
  40915. for (var i = 0; i < len; i++) {
  40916. if (nodes[i].dataIndex >= 0) {
  40917. cb.call(context, nodes[i], i);
  40918. }
  40919. }
  40920. };
  40921. /**
  40922. * Iterate all edges
  40923. * @param {Function} cb
  40924. * @param {*} [context]
  40925. */
  40926. graphProto.eachEdge = function (cb, context) {
  40927. var edges = this.edges;
  40928. var len = edges.length;
  40929. for (var i = 0; i < len; i++) {
  40930. if (edges[i].dataIndex >= 0 && edges[i].node1.dataIndex >= 0 && edges[i].node2.dataIndex >= 0) {
  40931. cb.call(context, edges[i], i);
  40932. }
  40933. }
  40934. };
  40935. /**
  40936. * Breadth first traverse
  40937. * @param {Function} cb
  40938. * @param {module:echarts/data/Graph.Node} startNode
  40939. * @param {string} [direction='none'] 'none'|'in'|'out'
  40940. * @param {*} [context]
  40941. */
  40942. graphProto.breadthFirstTraverse = function (cb, startNode, direction, context) {
  40943. if (!Node.isInstance(startNode)) {
  40944. startNode = this._nodesMap[generateNodeKey(startNode)];
  40945. }
  40946. if (!startNode) {
  40947. return;
  40948. }
  40949. var edgeType = direction === 'out' ? 'outEdges' : direction === 'in' ? 'inEdges' : 'edges';
  40950. for (var i = 0; i < this.nodes.length; i++) {
  40951. this.nodes[i].__visited = false;
  40952. }
  40953. if (cb.call(context, startNode, null)) {
  40954. return;
  40955. }
  40956. var queue = [startNode];
  40957. while (queue.length) {
  40958. var currentNode = queue.shift();
  40959. var edges = currentNode[edgeType];
  40960. for (var i = 0; i < edges.length; i++) {
  40961. var e = edges[i];
  40962. var otherNode = e.node1 === currentNode ? e.node2 : e.node1;
  40963. if (!otherNode.__visited) {
  40964. if (cb.call(context, otherNode, currentNode)) {
  40965. // Stop traversing
  40966. return;
  40967. }
  40968. queue.push(otherNode);
  40969. otherNode.__visited = true;
  40970. }
  40971. }
  40972. }
  40973. }; // TODO
  40974. // graphProto.depthFirstTraverse = function (
  40975. // cb, startNode, direction, context
  40976. // ) {
  40977. // };
  40978. // Filter update
  40979. graphProto.update = function () {
  40980. var data = this.data;
  40981. var edgeData = this.edgeData;
  40982. var nodes = this.nodes;
  40983. var edges = this.edges;
  40984. for (var i = 0, len = nodes.length; i < len; i++) {
  40985. nodes[i].dataIndex = -1;
  40986. }
  40987. for (var i = 0, len = data.count(); i < len; i++) {
  40988. nodes[data.getRawIndex(i)].dataIndex = i;
  40989. }
  40990. edgeData.filterSelf(function (idx) {
  40991. var edge = edges[edgeData.getRawIndex(idx)];
  40992. return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
  40993. }); // Update edge
  40994. for (var i = 0, len = edges.length; i < len; i++) {
  40995. edges[i].dataIndex = -1;
  40996. }
  40997. for (var i = 0, len = edgeData.count(); i < len; i++) {
  40998. edges[edgeData.getRawIndex(i)].dataIndex = i;
  40999. }
  41000. };
  41001. /**
  41002. * @return {module:echarts/data/Graph}
  41003. */
  41004. graphProto.clone = function () {
  41005. var graph = new Graph(this._directed);
  41006. var nodes = this.nodes;
  41007. var edges = this.edges;
  41008. for (var i = 0; i < nodes.length; i++) {
  41009. graph.addNode(nodes[i].id, nodes[i].dataIndex);
  41010. }
  41011. for (var i = 0; i < edges.length; i++) {
  41012. var e = edges[i];
  41013. graph.addEdge(e.node1.id, e.node2.id, e.dataIndex);
  41014. }
  41015. return graph;
  41016. };
  41017. /**
  41018. * @alias module:echarts/data/Graph.Node
  41019. */
  41020. function Node(id, dataIndex) {
  41021. /**
  41022. * @type {string}
  41023. */
  41024. this.id = id == null ? '' : id;
  41025. /**
  41026. * @type {Array.<module:echarts/data/Graph.Edge>}
  41027. */
  41028. this.inEdges = [];
  41029. /**
  41030. * @type {Array.<module:echarts/data/Graph.Edge>}
  41031. */
  41032. this.outEdges = [];
  41033. /**
  41034. * @type {Array.<module:echarts/data/Graph.Edge>}
  41035. */
  41036. this.edges = [];
  41037. /**
  41038. * @type {module:echarts/data/Graph}
  41039. */
  41040. this.hostGraph;
  41041. /**
  41042. * @type {number}
  41043. */
  41044. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  41045. }
  41046. Node.prototype = {
  41047. constructor: Node,
  41048. /**
  41049. * @return {number}
  41050. */
  41051. degree: function () {
  41052. return this.edges.length;
  41053. },
  41054. /**
  41055. * @return {number}
  41056. */
  41057. inDegree: function () {
  41058. return this.inEdges.length;
  41059. },
  41060. /**
  41061. * @return {number}
  41062. */
  41063. outDegree: function () {
  41064. return this.outEdges.length;
  41065. },
  41066. /**
  41067. * @param {string} [path]
  41068. * @return {module:echarts/model/Model}
  41069. */
  41070. getModel: function (path) {
  41071. if (this.dataIndex < 0) {
  41072. return;
  41073. }
  41074. var graph = this.hostGraph;
  41075. var itemModel = graph.data.getItemModel(this.dataIndex);
  41076. return itemModel.getModel(path);
  41077. }
  41078. };
  41079. /**
  41080. * 图边
  41081. * @alias module:echarts/data/Graph.Edge
  41082. * @param {module:echarts/data/Graph.Node} n1
  41083. * @param {module:echarts/data/Graph.Node} n2
  41084. * @param {number} [dataIndex=-1]
  41085. */
  41086. function Edge(n1, n2, dataIndex) {
  41087. /**
  41088. * 节点1,如果是有向图则为源节点
  41089. * @type {module:echarts/data/Graph.Node}
  41090. */
  41091. this.node1 = n1;
  41092. /**
  41093. * 节点2,如果是有向图则为目标节点
  41094. * @type {module:echarts/data/Graph.Node}
  41095. */
  41096. this.node2 = n2;
  41097. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  41098. }
  41099. /**
  41100. * @param {string} [path]
  41101. * @return {module:echarts/model/Model}
  41102. */
  41103. Edge.prototype.getModel = function (path) {
  41104. if (this.dataIndex < 0) {
  41105. return;
  41106. }
  41107. var graph = this.hostGraph;
  41108. var itemModel = graph.edgeData.getItemModel(this.dataIndex);
  41109. return itemModel.getModel(path);
  41110. };
  41111. var createGraphDataProxyMixin = function (hostName, dataName) {
  41112. return {
  41113. /**
  41114. * @param {string=} [dimension='value'] Default 'value'. can be 'a', 'b', 'c', 'd', 'e'.
  41115. * @return {number}
  41116. */
  41117. getValue: function (dimension) {
  41118. var data = this[hostName][dataName];
  41119. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  41120. },
  41121. /**
  41122. * @param {Object|string} key
  41123. * @param {*} [value]
  41124. */
  41125. setVisual: function (key, value) {
  41126. this.dataIndex >= 0 && this[hostName][dataName].setItemVisual(this.dataIndex, key, value);
  41127. },
  41128. /**
  41129. * @param {string} key
  41130. * @return {boolean}
  41131. */
  41132. getVisual: function (key, ignoreParent) {
  41133. return this[hostName][dataName].getItemVisual(this.dataIndex, key, ignoreParent);
  41134. },
  41135. /**
  41136. * @param {Object} layout
  41137. * @return {boolean} [merge=false]
  41138. */
  41139. setLayout: function (layout, merge$$1) {
  41140. this.dataIndex >= 0 && this[hostName][dataName].setItemLayout(this.dataIndex, layout, merge$$1);
  41141. },
  41142. /**
  41143. * @return {Object}
  41144. */
  41145. getLayout: function () {
  41146. return this[hostName][dataName].getItemLayout(this.dataIndex);
  41147. },
  41148. /**
  41149. * @return {module:zrender/Element}
  41150. */
  41151. getGraphicEl: function () {
  41152. return this[hostName][dataName].getItemGraphicEl(this.dataIndex);
  41153. },
  41154. /**
  41155. * @return {number}
  41156. */
  41157. getRawIndex: function () {
  41158. return this[hostName][dataName].getRawIndex(this.dataIndex);
  41159. }
  41160. };
  41161. };
  41162. mixin(Node, createGraphDataProxyMixin('hostGraph', 'data'));
  41163. mixin(Edge, createGraphDataProxyMixin('hostGraph', 'edgeData'));
  41164. Graph.Node = Node;
  41165. Graph.Edge = Edge;
  41166. enableClassCheck(Node);
  41167. enableClassCheck(Edge);
  41168. /*
  41169. * Licensed to the Apache Software Foundation (ASF) under one
  41170. * or more contributor license agreements. See the NOTICE file
  41171. * distributed with this work for additional information
  41172. * regarding copyright ownership. The ASF licenses this file
  41173. * to you under the Apache License, Version 2.0 (the
  41174. * "License"); you may not use this file except in compliance
  41175. * with the License. You may obtain a copy of the License at
  41176. *
  41177. * http://www.apache.org/licenses/LICENSE-2.0
  41178. *
  41179. * Unless required by applicable law or agreed to in writing,
  41180. * software distributed under the License is distributed on an
  41181. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41182. * KIND, either express or implied. See the License for the
  41183. * specific language governing permissions and limitations
  41184. * under the License.
  41185. */
  41186. var createGraphFromNodeEdge = function (nodes, edges, seriesModel, directed, beforeLink) {
  41187. // ??? TODO
  41188. // support dataset?
  41189. var graph = new Graph(directed);
  41190. for (var i = 0; i < nodes.length; i++) {
  41191. graph.addNode(retrieve( // Id, name, dataIndex
  41192. nodes[i].id, nodes[i].name, i), i);
  41193. }
  41194. var linkNameList = [];
  41195. var validEdges = [];
  41196. var linkCount = 0;
  41197. for (var i = 0; i < edges.length; i++) {
  41198. var link = edges[i];
  41199. var source = link.source;
  41200. var target = link.target; // addEdge may fail when source or target not exists
  41201. if (graph.addEdge(source, target, linkCount)) {
  41202. validEdges.push(link);
  41203. linkNameList.push(retrieve(link.id, source + ' > ' + target));
  41204. linkCount++;
  41205. }
  41206. }
  41207. var coordSys = seriesModel.get('coordinateSystem');
  41208. var nodeData;
  41209. if (coordSys === 'cartesian2d' || coordSys === 'polar') {
  41210. nodeData = createListFromArray(nodes, seriesModel);
  41211. } else {
  41212. var coordSysCtor = CoordinateSystemManager.get(coordSys);
  41213. var coordDimensions = coordSysCtor && coordSysCtor.type !== 'view' ? coordSysCtor.dimensions || [] : []; // FIXME: Some geo do not need `value` dimenson, whereas `calendar` needs
  41214. // `value` dimension, but graph need `value` dimension. It's better to
  41215. // uniform this behavior.
  41216. if (indexOf(coordDimensions, 'value') < 0) {
  41217. coordDimensions.concat(['value']);
  41218. }
  41219. var dimensionNames = createDimensions(nodes, {
  41220. coordDimensions: coordDimensions
  41221. });
  41222. nodeData = new List(dimensionNames, seriesModel);
  41223. nodeData.initData(nodes);
  41224. }
  41225. var edgeData = new List(['value'], seriesModel);
  41226. edgeData.initData(validEdges, linkNameList);
  41227. beforeLink && beforeLink(nodeData, edgeData);
  41228. linkList({
  41229. mainData: nodeData,
  41230. struct: graph,
  41231. structAttr: 'graph',
  41232. datas: {
  41233. node: nodeData,
  41234. edge: edgeData
  41235. },
  41236. datasAttr: {
  41237. node: 'data',
  41238. edge: 'edgeData'
  41239. }
  41240. }); // Update dataIndex of nodes and edges because invalid edge may be removed
  41241. graph.update();
  41242. return graph;
  41243. };
  41244. /*
  41245. * Licensed to the Apache Software Foundation (ASF) under one
  41246. * or more contributor license agreements. See the NOTICE file
  41247. * distributed with this work for additional information
  41248. * regarding copyright ownership. The ASF licenses this file
  41249. * to you under the Apache License, Version 2.0 (the
  41250. * "License"); you may not use this file except in compliance
  41251. * with the License. You may obtain a copy of the License at
  41252. *
  41253. * http://www.apache.org/licenses/LICENSE-2.0
  41254. *
  41255. * Unless required by applicable law or agreed to in writing,
  41256. * software distributed under the License is distributed on an
  41257. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41258. * KIND, either express or implied. See the License for the
  41259. * specific language governing permissions and limitations
  41260. * under the License.
  41261. */
  41262. var GraphSeries = extendSeriesModel({
  41263. type: 'series.graph',
  41264. init: function (option) {
  41265. GraphSeries.superApply(this, 'init', arguments);
  41266. var self = this;
  41267. function getCategoriesData() {
  41268. return self._categoriesData;
  41269. } // Provide data for legend select
  41270. this.legendVisualProvider = new LegendVisualProvider(getCategoriesData, getCategoriesData);
  41271. this.fillDataTextStyle(option.edges || option.links);
  41272. this._updateCategoriesData();
  41273. },
  41274. mergeOption: function (option) {
  41275. GraphSeries.superApply(this, 'mergeOption', arguments);
  41276. this.fillDataTextStyle(option.edges || option.links);
  41277. this._updateCategoriesData();
  41278. },
  41279. mergeDefaultAndTheme: function (option) {
  41280. GraphSeries.superApply(this, 'mergeDefaultAndTheme', arguments);
  41281. defaultEmphasis(option, ['edgeLabel'], ['show']);
  41282. },
  41283. getInitialData: function (option, ecModel) {
  41284. var edges = option.edges || option.links || [];
  41285. var nodes = option.data || option.nodes || [];
  41286. var self = this;
  41287. if (nodes && edges) {
  41288. return createGraphFromNodeEdge(nodes, edges, this, true, beforeLink).data;
  41289. }
  41290. function beforeLink(nodeData, edgeData) {
  41291. // Overwrite nodeData.getItemModel to
  41292. nodeData.wrapMethod('getItemModel', function (model) {
  41293. var categoriesModels = self._categoriesModels;
  41294. var categoryIdx = model.getShallow('category');
  41295. var categoryModel = categoriesModels[categoryIdx];
  41296. if (categoryModel) {
  41297. categoryModel.parentModel = model.parentModel;
  41298. model.parentModel = categoryModel;
  41299. }
  41300. return model;
  41301. });
  41302. var edgeLabelModel = self.getModel('edgeLabel'); // For option `edgeLabel` can be found by label.xxx.xxx on item mode.
  41303. var fakeSeriesModel = new Model({
  41304. label: edgeLabelModel.option
  41305. }, edgeLabelModel.parentModel, ecModel);
  41306. var emphasisEdgeLabelModel = self.getModel('emphasis.edgeLabel');
  41307. var emphasisFakeSeriesModel = new Model({
  41308. emphasis: {
  41309. label: emphasisEdgeLabelModel.option
  41310. }
  41311. }, emphasisEdgeLabelModel.parentModel, ecModel);
  41312. edgeData.wrapMethod('getItemModel', function (model) {
  41313. model.customizeGetParent(edgeGetParent);
  41314. return model;
  41315. });
  41316. function edgeGetParent(path) {
  41317. path = this.parsePath(path);
  41318. return path && path[0] === 'label' ? fakeSeriesModel : path && path[0] === 'emphasis' && path[1] === 'label' ? emphasisFakeSeriesModel : this.parentModel;
  41319. }
  41320. }
  41321. },
  41322. /**
  41323. * @return {module:echarts/data/Graph}
  41324. */
  41325. getGraph: function () {
  41326. return this.getData().graph;
  41327. },
  41328. /**
  41329. * @return {module:echarts/data/List}
  41330. */
  41331. getEdgeData: function () {
  41332. return this.getGraph().edgeData;
  41333. },
  41334. /**
  41335. * @return {module:echarts/data/List}
  41336. */
  41337. getCategoriesData: function () {
  41338. return this._categoriesData;
  41339. },
  41340. /**
  41341. * @override
  41342. */
  41343. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  41344. if (dataType === 'edge') {
  41345. var nodeData = this.getData();
  41346. var params = this.getDataParams(dataIndex, dataType);
  41347. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  41348. var sourceName = nodeData.getName(edge.node1.dataIndex);
  41349. var targetName = nodeData.getName(edge.node2.dataIndex);
  41350. var html = [];
  41351. sourceName != null && html.push(sourceName);
  41352. targetName != null && html.push(targetName);
  41353. html = encodeHTML(html.join(' > '));
  41354. if (params.value) {
  41355. html += ' : ' + encodeHTML(params.value);
  41356. }
  41357. return html;
  41358. } else {
  41359. // dataType === 'node' or empty
  41360. return GraphSeries.superApply(this, 'formatTooltip', arguments);
  41361. }
  41362. },
  41363. _updateCategoriesData: function () {
  41364. var categories = map(this.option.categories || [], function (category) {
  41365. // Data must has value
  41366. return category.value != null ? category : extend({
  41367. value: 0
  41368. }, category);
  41369. });
  41370. var categoriesData = new List(['value'], this);
  41371. categoriesData.initData(categories);
  41372. this._categoriesData = categoriesData;
  41373. this._categoriesModels = categoriesData.mapArray(function (idx) {
  41374. return categoriesData.getItemModel(idx, true);
  41375. });
  41376. },
  41377. setZoom: function (zoom) {
  41378. this.option.zoom = zoom;
  41379. },
  41380. setCenter: function (center) {
  41381. this.option.center = center;
  41382. },
  41383. isAnimationEnabled: function () {
  41384. return GraphSeries.superCall(this, 'isAnimationEnabled') // Not enable animation when do force layout
  41385. && !(this.get('layout') === 'force' && this.get('force.layoutAnimation'));
  41386. },
  41387. defaultOption: {
  41388. zlevel: 0,
  41389. z: 2,
  41390. coordinateSystem: 'view',
  41391. // Default option for all coordinate systems
  41392. // xAxisIndex: 0,
  41393. // yAxisIndex: 0,
  41394. // polarIndex: 0,
  41395. // geoIndex: 0,
  41396. legendHoverLink: true,
  41397. hoverAnimation: true,
  41398. layout: null,
  41399. focusNodeAdjacency: false,
  41400. // Configuration of circular layout
  41401. circular: {
  41402. rotateLabel: false
  41403. },
  41404. // Configuration of force directed layout
  41405. force: {
  41406. initLayout: null,
  41407. // Node repulsion. Can be an array to represent range.
  41408. repulsion: [0, 50],
  41409. gravity: 0.1,
  41410. // Initial friction
  41411. friction: 0.6,
  41412. // Edge length. Can be an array to represent range.
  41413. edgeLength: 30,
  41414. layoutAnimation: true
  41415. },
  41416. left: 'center',
  41417. top: 'center',
  41418. // right: null,
  41419. // bottom: null,
  41420. // width: '80%',
  41421. // height: '80%',
  41422. symbol: 'circle',
  41423. symbolSize: 10,
  41424. edgeSymbol: ['none', 'none'],
  41425. edgeSymbolSize: 10,
  41426. edgeLabel: {
  41427. position: 'middle',
  41428. distance: 5
  41429. },
  41430. draggable: false,
  41431. roam: false,
  41432. // Default on center of graph
  41433. center: null,
  41434. zoom: 1,
  41435. // Symbol size scale ratio in roam
  41436. nodeScaleRatio: 0.6,
  41437. // cursor: null,
  41438. // categories: [],
  41439. // data: []
  41440. // Or
  41441. // nodes: []
  41442. //
  41443. // links: []
  41444. // Or
  41445. // edges: []
  41446. label: {
  41447. show: false,
  41448. formatter: '{b}'
  41449. },
  41450. itemStyle: {},
  41451. lineStyle: {
  41452. color: '#aaa',
  41453. width: 1,
  41454. curveness: 0,
  41455. opacity: 0.5
  41456. },
  41457. emphasis: {
  41458. label: {
  41459. show: true
  41460. }
  41461. }
  41462. }
  41463. });
  41464. /*
  41465. * Licensed to the Apache Software Foundation (ASF) under one
  41466. * or more contributor license agreements. See the NOTICE file
  41467. * distributed with this work for additional information
  41468. * regarding copyright ownership. The ASF licenses this file
  41469. * to you under the Apache License, Version 2.0 (the
  41470. * "License"); you may not use this file except in compliance
  41471. * with the License. You may obtain a copy of the License at
  41472. *
  41473. * http://www.apache.org/licenses/LICENSE-2.0
  41474. *
  41475. * Unless required by applicable law or agreed to in writing,
  41476. * software distributed under the License is distributed on an
  41477. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41478. * KIND, either express or implied. See the License for the
  41479. * specific language governing permissions and limitations
  41480. * under the License.
  41481. */
  41482. /**
  41483. * Line path for bezier and straight line draw
  41484. */
  41485. var straightLineProto = Line.prototype;
  41486. var bezierCurveProto = BezierCurve.prototype;
  41487. function isLine(shape) {
  41488. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  41489. }
  41490. var LinePath = extendShape({
  41491. type: 'ec-line',
  41492. style: {
  41493. stroke: '#000',
  41494. fill: null
  41495. },
  41496. shape: {
  41497. x1: 0,
  41498. y1: 0,
  41499. x2: 0,
  41500. y2: 0,
  41501. percent: 1,
  41502. cpx1: null,
  41503. cpy1: null
  41504. },
  41505. buildPath: function (ctx, shape) {
  41506. this[isLine(shape) ? '_buildPathLine' : '_buildPathCurve'](ctx, shape);
  41507. },
  41508. _buildPathLine: straightLineProto.buildPath,
  41509. _buildPathCurve: bezierCurveProto.buildPath,
  41510. pointAt: function (t) {
  41511. return this[isLine(this.shape) ? '_pointAtLine' : '_pointAtCurve'](t);
  41512. },
  41513. _pointAtLine: straightLineProto.pointAt,
  41514. _pointAtCurve: bezierCurveProto.pointAt,
  41515. tangentAt: function (t) {
  41516. var shape = this.shape;
  41517. var p = isLine(shape) ? [shape.x2 - shape.x1, shape.y2 - shape.y1] : this._tangentAtCurve(t);
  41518. return normalize(p, p);
  41519. },
  41520. _tangentAtCurve: bezierCurveProto.tangentAt
  41521. });
  41522. /*
  41523. * Licensed to the Apache Software Foundation (ASF) under one
  41524. * or more contributor license agreements. See the NOTICE file
  41525. * distributed with this work for additional information
  41526. * regarding copyright ownership. The ASF licenses this file
  41527. * to you under the Apache License, Version 2.0 (the
  41528. * "License"); you may not use this file except in compliance
  41529. * with the License. You may obtain a copy of the License at
  41530. *
  41531. * http://www.apache.org/licenses/LICENSE-2.0
  41532. *
  41533. * Unless required by applicable law or agreed to in writing,
  41534. * software distributed under the License is distributed on an
  41535. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41536. * KIND, either express or implied. See the License for the
  41537. * specific language governing permissions and limitations
  41538. * under the License.
  41539. */
  41540. /**
  41541. * @module echarts/chart/helper/Line
  41542. */
  41543. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  41544. function makeSymbolTypeKey(symbolCategory) {
  41545. return '_' + symbolCategory + 'Type';
  41546. }
  41547. /**
  41548. * @inner
  41549. */
  41550. function createSymbol$1(name, lineData, idx) {
  41551. var color = lineData.getItemVisual(idx, 'color');
  41552. var symbolType = lineData.getItemVisual(idx, name);
  41553. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  41554. if (!symbolType || symbolType === 'none') {
  41555. return;
  41556. }
  41557. if (!isArray(symbolSize)) {
  41558. symbolSize = [symbolSize, symbolSize];
  41559. }
  41560. var symbolPath = createSymbol(symbolType, -symbolSize[0] / 2, -symbolSize[1] / 2, symbolSize[0], symbolSize[1], color);
  41561. symbolPath.name = name;
  41562. return symbolPath;
  41563. }
  41564. function createLine(points) {
  41565. var line = new LinePath({
  41566. name: 'line',
  41567. subPixelOptimize: true
  41568. });
  41569. setLinePoints(line.shape, points);
  41570. return line;
  41571. }
  41572. function setLinePoints(targetShape, points) {
  41573. targetShape.x1 = points[0][0];
  41574. targetShape.y1 = points[0][1];
  41575. targetShape.x2 = points[1][0];
  41576. targetShape.y2 = points[1][1];
  41577. targetShape.percent = 1;
  41578. var cp1 = points[2];
  41579. if (cp1) {
  41580. targetShape.cpx1 = cp1[0];
  41581. targetShape.cpy1 = cp1[1];
  41582. } else {
  41583. targetShape.cpx1 = NaN;
  41584. targetShape.cpy1 = NaN;
  41585. }
  41586. }
  41587. function updateSymbolAndLabelBeforeLineUpdate() {
  41588. var lineGroup = this;
  41589. var symbolFrom = lineGroup.childOfName('fromSymbol');
  41590. var symbolTo = lineGroup.childOfName('toSymbol');
  41591. var label = lineGroup.childOfName('label'); // Quick reject
  41592. if (!symbolFrom && !symbolTo && label.ignore) {
  41593. return;
  41594. }
  41595. var invScale = 1;
  41596. var parentNode = this.parent;
  41597. while (parentNode) {
  41598. if (parentNode.scale) {
  41599. invScale /= parentNode.scale[0];
  41600. }
  41601. parentNode = parentNode.parent;
  41602. }
  41603. var line = lineGroup.childOfName('line'); // If line not changed
  41604. // FIXME Parent scale changed
  41605. if (!this.__dirty && !line.__dirty) {
  41606. return;
  41607. }
  41608. var percent = line.shape.percent;
  41609. var fromPos = line.pointAt(0);
  41610. var toPos = line.pointAt(percent);
  41611. var d = sub([], toPos, fromPos);
  41612. normalize(d, d);
  41613. if (symbolFrom) {
  41614. symbolFrom.attr('position', fromPos);
  41615. var tangent = line.tangentAt(0);
  41616. symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(tangent[1], tangent[0]));
  41617. symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
  41618. }
  41619. if (symbolTo) {
  41620. symbolTo.attr('position', toPos);
  41621. var tangent = line.tangentAt(1);
  41622. symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(tangent[1], tangent[0]));
  41623. symbolTo.attr('scale', [invScale * percent, invScale * percent]);
  41624. }
  41625. if (!label.ignore) {
  41626. label.attr('position', toPos);
  41627. var textPosition;
  41628. var textAlign;
  41629. var textVerticalAlign;
  41630. var textOrigin;
  41631. var distance$$1 = label.__labelDistance;
  41632. var distanceX = distance$$1[0] * invScale;
  41633. var distanceY = distance$$1[1] * invScale;
  41634. var halfPercent = percent / 2;
  41635. var tangent = line.tangentAt(halfPercent);
  41636. var n = [tangent[1], -tangent[0]];
  41637. var cp = line.pointAt(halfPercent);
  41638. if (n[1] > 0) {
  41639. n[0] = -n[0];
  41640. n[1] = -n[1];
  41641. }
  41642. var dir = tangent[0] < 0 ? -1 : 1;
  41643. if (label.__position !== 'start' && label.__position !== 'end') {
  41644. var rotation = -Math.atan2(tangent[1], tangent[0]);
  41645. if (toPos[0] < fromPos[0]) {
  41646. rotation = Math.PI + rotation;
  41647. }
  41648. label.attr('rotation', rotation);
  41649. }
  41650. var dy;
  41651. switch (label.__position) {
  41652. case 'insideStartTop':
  41653. case 'insideMiddleTop':
  41654. case 'insideEndTop':
  41655. case 'middle':
  41656. dy = -distanceY;
  41657. textVerticalAlign = 'bottom';
  41658. break;
  41659. case 'insideStartBottom':
  41660. case 'insideMiddleBottom':
  41661. case 'insideEndBottom':
  41662. dy = distanceY;
  41663. textVerticalAlign = 'top';
  41664. break;
  41665. default:
  41666. dy = 0;
  41667. textVerticalAlign = 'middle';
  41668. }
  41669. switch (label.__position) {
  41670. case 'end':
  41671. textPosition = [d[0] * distanceX + toPos[0], d[1] * distanceY + toPos[1]];
  41672. textAlign = d[0] > 0.8 ? 'left' : d[0] < -0.8 ? 'right' : 'center';
  41673. textVerticalAlign = d[1] > 0.8 ? 'top' : d[1] < -0.8 ? 'bottom' : 'middle';
  41674. break;
  41675. case 'start':
  41676. textPosition = [-d[0] * distanceX + fromPos[0], -d[1] * distanceY + fromPos[1]];
  41677. textAlign = d[0] > 0.8 ? 'right' : d[0] < -0.8 ? 'left' : 'center';
  41678. textVerticalAlign = d[1] > 0.8 ? 'bottom' : d[1] < -0.8 ? 'top' : 'middle';
  41679. break;
  41680. case 'insideStartTop':
  41681. case 'insideStart':
  41682. case 'insideStartBottom':
  41683. textPosition = [distanceX * dir + fromPos[0], fromPos[1] + dy];
  41684. textAlign = tangent[0] < 0 ? 'right' : 'left';
  41685. textOrigin = [-distanceX * dir, -dy];
  41686. break;
  41687. case 'insideMiddleTop':
  41688. case 'insideMiddle':
  41689. case 'insideMiddleBottom':
  41690. case 'middle':
  41691. textPosition = [cp[0], cp[1] + dy];
  41692. textAlign = 'center';
  41693. textOrigin = [0, -dy];
  41694. break;
  41695. case 'insideEndTop':
  41696. case 'insideEnd':
  41697. case 'insideEndBottom':
  41698. textPosition = [-distanceX * dir + toPos[0], toPos[1] + dy];
  41699. textAlign = tangent[0] >= 0 ? 'right' : 'left';
  41700. textOrigin = [distanceX * dir, -dy];
  41701. break;
  41702. }
  41703. label.attr({
  41704. style: {
  41705. // Use the user specified text align and baseline first
  41706. textVerticalAlign: label.__verticalAlign || textVerticalAlign,
  41707. textAlign: label.__textAlign || textAlign
  41708. },
  41709. position: textPosition,
  41710. scale: [invScale, invScale],
  41711. origin: textOrigin
  41712. });
  41713. }
  41714. }
  41715. /**
  41716. * @constructor
  41717. * @extends {module:zrender/graphic/Group}
  41718. * @alias {module:echarts/chart/helper/Line}
  41719. */
  41720. function Line$1(lineData, idx, seriesScope) {
  41721. Group.call(this);
  41722. this._createLine(lineData, idx, seriesScope);
  41723. }
  41724. var lineProto = Line$1.prototype; // Update symbol position and rotation
  41725. lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
  41726. lineProto._createLine = function (lineData, idx, seriesScope) {
  41727. var seriesModel = lineData.hostModel;
  41728. var linePoints = lineData.getItemLayout(idx);
  41729. var line = createLine(linePoints);
  41730. line.shape.percent = 0;
  41731. initProps(line, {
  41732. shape: {
  41733. percent: 1
  41734. }
  41735. }, seriesModel, idx);
  41736. this.add(line);
  41737. var label = new Text({
  41738. name: 'label',
  41739. // FIXME
  41740. // Temporary solution for `focusNodeAdjacency`.
  41741. // line label do not use the opacity of lineStyle.
  41742. lineLabelOriginalOpacity: 1
  41743. });
  41744. this.add(label);
  41745. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  41746. var symbol = createSymbol$1(symbolCategory, lineData, idx); // symbols must added after line to make sure
  41747. // it will be updated after line#update.
  41748. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  41749. this.add(symbol);
  41750. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  41751. }, this);
  41752. this._updateCommonStl(lineData, idx, seriesScope);
  41753. };
  41754. lineProto.updateData = function (lineData, idx, seriesScope) {
  41755. var seriesModel = lineData.hostModel;
  41756. var line = this.childOfName('line');
  41757. var linePoints = lineData.getItemLayout(idx);
  41758. var target = {
  41759. shape: {}
  41760. };
  41761. setLinePoints(target.shape, linePoints);
  41762. updateProps(line, target, seriesModel, idx);
  41763. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  41764. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  41765. var key = makeSymbolTypeKey(symbolCategory); // Symbol changed
  41766. if (this[key] !== symbolType) {
  41767. this.remove(this.childOfName(symbolCategory));
  41768. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  41769. this.add(symbol);
  41770. }
  41771. this[key] = symbolType;
  41772. }, this);
  41773. this._updateCommonStl(lineData, idx, seriesScope);
  41774. };
  41775. lineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  41776. var seriesModel = lineData.hostModel;
  41777. var line = this.childOfName('line');
  41778. var lineStyle = seriesScope && seriesScope.lineStyle;
  41779. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  41780. var labelModel = seriesScope && seriesScope.labelModel;
  41781. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel; // Optimization for large dataset
  41782. if (!seriesScope || lineData.hasItemOption) {
  41783. var itemModel = lineData.getItemModel(idx);
  41784. lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  41785. hoverLineStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  41786. labelModel = itemModel.getModel('label');
  41787. hoverLabelModel = itemModel.getModel('emphasis.label');
  41788. }
  41789. var visualColor = lineData.getItemVisual(idx, 'color');
  41790. var visualOpacity = retrieve3(lineData.getItemVisual(idx, 'opacity'), lineStyle.opacity, 1);
  41791. line.useStyle(defaults({
  41792. strokeNoScale: true,
  41793. fill: 'none',
  41794. stroke: visualColor,
  41795. opacity: visualOpacity
  41796. }, lineStyle));
  41797. line.hoverStyle = hoverLineStyle; // Update symbol
  41798. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  41799. var symbol = this.childOfName(symbolCategory);
  41800. if (symbol) {
  41801. symbol.setColor(visualColor);
  41802. symbol.setStyle({
  41803. opacity: visualOpacity
  41804. });
  41805. }
  41806. }, this);
  41807. var showLabel = labelModel.getShallow('show');
  41808. var hoverShowLabel = hoverLabelModel.getShallow('show');
  41809. var label = this.childOfName('label');
  41810. var defaultLabelColor;
  41811. var baseText; // FIXME: the logic below probably should be merged to `graphic.setLabelStyle`.
  41812. if (showLabel || hoverShowLabel) {
  41813. defaultLabelColor = visualColor || '#000';
  41814. baseText = seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType);
  41815. if (baseText == null) {
  41816. var rawVal = seriesModel.getRawValue(idx);
  41817. baseText = rawVal == null ? lineData.getName(idx) : isFinite(rawVal) ? round$1(rawVal) : rawVal;
  41818. }
  41819. }
  41820. var normalText = showLabel ? baseText : null;
  41821. var emphasisText = hoverShowLabel ? retrieve2(seriesModel.getFormattedLabel(idx, 'emphasis', lineData.dataType), baseText) : null;
  41822. var labelStyle = label.style; // Always set `textStyle` even if `normalStyle.text` is null, because default
  41823. // values have to be set on `normalStyle`.
  41824. if (normalText != null || emphasisText != null) {
  41825. setTextStyle(label.style, labelModel, {
  41826. text: normalText
  41827. }, {
  41828. autoColor: defaultLabelColor
  41829. });
  41830. label.__textAlign = labelStyle.textAlign;
  41831. label.__verticalAlign = labelStyle.textVerticalAlign; // 'start', 'middle', 'end'
  41832. label.__position = labelModel.get('position') || 'middle';
  41833. var distance$$1 = labelModel.get('distance');
  41834. if (!isArray(distance$$1)) {
  41835. distance$$1 = [distance$$1, distance$$1];
  41836. }
  41837. label.__labelDistance = distance$$1;
  41838. }
  41839. if (emphasisText != null) {
  41840. // Only these properties supported in this emphasis style here.
  41841. label.hoverStyle = {
  41842. text: emphasisText,
  41843. textFill: hoverLabelModel.getTextColor(true),
  41844. // For merging hover style to normal style, do not use
  41845. // `hoverLabelModel.getFont()` here.
  41846. fontStyle: hoverLabelModel.getShallow('fontStyle'),
  41847. fontWeight: hoverLabelModel.getShallow('fontWeight'),
  41848. fontSize: hoverLabelModel.getShallow('fontSize'),
  41849. fontFamily: hoverLabelModel.getShallow('fontFamily')
  41850. };
  41851. } else {
  41852. label.hoverStyle = {
  41853. text: null
  41854. };
  41855. }
  41856. label.ignore = !showLabel && !hoverShowLabel;
  41857. setHoverStyle(this);
  41858. };
  41859. lineProto.highlight = function () {
  41860. this.trigger('emphasis');
  41861. };
  41862. lineProto.downplay = function () {
  41863. this.trigger('normal');
  41864. };
  41865. lineProto.updateLayout = function (lineData, idx) {
  41866. this.setLinePoints(lineData.getItemLayout(idx));
  41867. };
  41868. lineProto.setLinePoints = function (points) {
  41869. var linePath = this.childOfName('line');
  41870. setLinePoints(linePath.shape, points);
  41871. linePath.dirty();
  41872. };
  41873. inherits(Line$1, Group);
  41874. /*
  41875. * Licensed to the Apache Software Foundation (ASF) under one
  41876. * or more contributor license agreements. See the NOTICE file
  41877. * distributed with this work for additional information
  41878. * regarding copyright ownership. The ASF licenses this file
  41879. * to you under the Apache License, Version 2.0 (the
  41880. * "License"); you may not use this file except in compliance
  41881. * with the License. You may obtain a copy of the License at
  41882. *
  41883. * http://www.apache.org/licenses/LICENSE-2.0
  41884. *
  41885. * Unless required by applicable law or agreed to in writing,
  41886. * software distributed under the License is distributed on an
  41887. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41888. * KIND, either express or implied. See the License for the
  41889. * specific language governing permissions and limitations
  41890. * under the License.
  41891. */
  41892. /**
  41893. * @module echarts/chart/helper/LineDraw
  41894. */
  41895. /**
  41896. * @alias module:echarts/component/marker/LineDraw
  41897. * @constructor
  41898. */
  41899. function LineDraw(ctor) {
  41900. this._ctor = ctor || Line$1;
  41901. this.group = new Group();
  41902. }
  41903. var lineDrawProto = LineDraw.prototype;
  41904. lineDrawProto.isPersistent = function () {
  41905. return true;
  41906. };
  41907. /**
  41908. * @param {module:echarts/data/List} lineData
  41909. */
  41910. lineDrawProto.updateData = function (lineData) {
  41911. var lineDraw = this;
  41912. var group = lineDraw.group;
  41913. var oldLineData = lineDraw._lineData;
  41914. lineDraw._lineData = lineData; // There is no oldLineData only when first rendering or switching from
  41915. // stream mode to normal mode, where previous elements should be removed.
  41916. if (!oldLineData) {
  41917. group.removeAll();
  41918. }
  41919. var seriesScope = makeSeriesScope$1(lineData);
  41920. lineData.diff(oldLineData).add(function (idx) {
  41921. doAdd(lineDraw, lineData, idx, seriesScope);
  41922. }).update(function (newIdx, oldIdx) {
  41923. doUpdate(lineDraw, oldLineData, lineData, oldIdx, newIdx, seriesScope);
  41924. }).remove(function (idx) {
  41925. group.remove(oldLineData.getItemGraphicEl(idx));
  41926. }).execute();
  41927. };
  41928. function doAdd(lineDraw, lineData, idx, seriesScope) {
  41929. var itemLayout = lineData.getItemLayout(idx);
  41930. if (!lineNeedsDraw(itemLayout)) {
  41931. return;
  41932. }
  41933. var el = new lineDraw._ctor(lineData, idx, seriesScope);
  41934. lineData.setItemGraphicEl(idx, el);
  41935. lineDraw.group.add(el);
  41936. }
  41937. function doUpdate(lineDraw, oldLineData, newLineData, oldIdx, newIdx, seriesScope) {
  41938. var itemEl = oldLineData.getItemGraphicEl(oldIdx);
  41939. if (!lineNeedsDraw(newLineData.getItemLayout(newIdx))) {
  41940. lineDraw.group.remove(itemEl);
  41941. return;
  41942. }
  41943. if (!itemEl) {
  41944. itemEl = new lineDraw._ctor(newLineData, newIdx, seriesScope);
  41945. } else {
  41946. itemEl.updateData(newLineData, newIdx, seriesScope);
  41947. }
  41948. newLineData.setItemGraphicEl(newIdx, itemEl);
  41949. lineDraw.group.add(itemEl);
  41950. }
  41951. lineDrawProto.updateLayout = function () {
  41952. var lineData = this._lineData; // Do not support update layout in incremental mode.
  41953. if (!lineData) {
  41954. return;
  41955. }
  41956. lineData.eachItemGraphicEl(function (el, idx) {
  41957. el.updateLayout(lineData, idx);
  41958. }, this);
  41959. };
  41960. lineDrawProto.incrementalPrepareUpdate = function (lineData) {
  41961. this._seriesScope = makeSeriesScope$1(lineData);
  41962. this._lineData = null;
  41963. this.group.removeAll();
  41964. };
  41965. function isEffectObject(el) {
  41966. return el.animators && el.animators.length > 0;
  41967. }
  41968. lineDrawProto.incrementalUpdate = function (taskParams, lineData) {
  41969. function updateIncrementalAndHover(el) {
  41970. if (!el.isGroup && !isEffectObject(el)) {
  41971. el.incremental = el.useHoverLayer = true;
  41972. }
  41973. }
  41974. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  41975. var itemLayout = lineData.getItemLayout(idx);
  41976. if (lineNeedsDraw(itemLayout)) {
  41977. var el = new this._ctor(lineData, idx, this._seriesScope);
  41978. el.traverse(updateIncrementalAndHover);
  41979. this.group.add(el);
  41980. lineData.setItemGraphicEl(idx, el);
  41981. }
  41982. }
  41983. };
  41984. function makeSeriesScope$1(lineData) {
  41985. var hostModel = lineData.hostModel;
  41986. return {
  41987. lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
  41988. hoverLineStyle: hostModel.getModel('emphasis.lineStyle').getLineStyle(),
  41989. labelModel: hostModel.getModel('label'),
  41990. hoverLabelModel: hostModel.getModel('emphasis.label')
  41991. };
  41992. }
  41993. lineDrawProto.remove = function () {
  41994. this._clearIncremental();
  41995. this._incremental = null;
  41996. this.group.removeAll();
  41997. };
  41998. lineDrawProto._clearIncremental = function () {
  41999. var incremental = this._incremental;
  42000. if (incremental) {
  42001. incremental.clearDisplaybles();
  42002. }
  42003. };
  42004. function isPointNaN(pt) {
  42005. return isNaN(pt[0]) || isNaN(pt[1]);
  42006. }
  42007. function lineNeedsDraw(pts) {
  42008. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  42009. }
  42010. /*
  42011. * Licensed to the Apache Software Foundation (ASF) under one
  42012. * or more contributor license agreements. See the NOTICE file
  42013. * distributed with this work for additional information
  42014. * regarding copyright ownership. The ASF licenses this file
  42015. * to you under the Apache License, Version 2.0 (the
  42016. * "License"); you may not use this file except in compliance
  42017. * with the License. You may obtain a copy of the License at
  42018. *
  42019. * http://www.apache.org/licenses/LICENSE-2.0
  42020. *
  42021. * Unless required by applicable law or agreed to in writing,
  42022. * software distributed under the License is distributed on an
  42023. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42024. * KIND, either express or implied. See the License for the
  42025. * specific language governing permissions and limitations
  42026. * under the License.
  42027. */
  42028. function getNodeGlobalScale(seriesModel) {
  42029. var coordSys = seriesModel.coordinateSystem;
  42030. if (coordSys.type !== 'view') {
  42031. return 1;
  42032. }
  42033. var nodeScaleRatio = seriesModel.option.nodeScaleRatio;
  42034. var groupScale = coordSys.scale;
  42035. var groupZoom = groupScale && groupScale[0] || 1; // Scale node when zoom changes
  42036. var roamZoom = coordSys.getZoom();
  42037. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  42038. return nodeScale / groupZoom;
  42039. }
  42040. function getSymbolSize$1(node) {
  42041. var symbolSize = node.getVisual('symbolSize');
  42042. if (symbolSize instanceof Array) {
  42043. symbolSize = (symbolSize[0] + symbolSize[1]) / 2;
  42044. }
  42045. return +symbolSize;
  42046. }
  42047. /*
  42048. * Licensed to the Apache Software Foundation (ASF) under one
  42049. * or more contributor license agreements. See the NOTICE file
  42050. * distributed with this work for additional information
  42051. * regarding copyright ownership. The ASF licenses this file
  42052. * to you under the Apache License, Version 2.0 (the
  42053. * "License"); you may not use this file except in compliance
  42054. * with the License. You may obtain a copy of the License at
  42055. *
  42056. * http://www.apache.org/licenses/LICENSE-2.0
  42057. *
  42058. * Unless required by applicable law or agreed to in writing,
  42059. * software distributed under the License is distributed on an
  42060. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42061. * KIND, either express or implied. See the License for the
  42062. * specific language governing permissions and limitations
  42063. * under the License.
  42064. */
  42065. var v1 = [];
  42066. var v2 = [];
  42067. var v3 = [];
  42068. var quadraticAt$1 = quadraticAt;
  42069. var v2DistSquare = distSquare;
  42070. var mathAbs$1 = Math.abs;
  42071. function intersectCurveCircle(curvePoints, center, radius) {
  42072. var p0 = curvePoints[0];
  42073. var p1 = curvePoints[1];
  42074. var p2 = curvePoints[2];
  42075. var d = Infinity;
  42076. var t;
  42077. var radiusSquare = radius * radius;
  42078. var interval = 0.1;
  42079. for (var _t = 0.1; _t <= 0.9; _t += 0.1) {
  42080. v1[0] = quadraticAt$1(p0[0], p1[0], p2[0], _t);
  42081. v1[1] = quadraticAt$1(p0[1], p1[1], p2[1], _t);
  42082. var diff = mathAbs$1(v2DistSquare(v1, center) - radiusSquare);
  42083. if (diff < d) {
  42084. d = diff;
  42085. t = _t;
  42086. }
  42087. } // Assume the segment is monotone,Find root through Bisection method
  42088. // At most 32 iteration
  42089. for (var i = 0; i < 32; i++) {
  42090. // var prev = t - interval;
  42091. var next = t + interval; // v1[0] = quadraticAt(p0[0], p1[0], p2[0], prev);
  42092. // v1[1] = quadraticAt(p0[1], p1[1], p2[1], prev);
  42093. v2[0] = quadraticAt$1(p0[0], p1[0], p2[0], t);
  42094. v2[1] = quadraticAt$1(p0[1], p1[1], p2[1], t);
  42095. v3[0] = quadraticAt$1(p0[0], p1[0], p2[0], next);
  42096. v3[1] = quadraticAt$1(p0[1], p1[1], p2[1], next);
  42097. var diff = v2DistSquare(v2, center) - radiusSquare;
  42098. if (mathAbs$1(diff) < 1e-2) {
  42099. break;
  42100. } // var prevDiff = v2DistSquare(v1, center) - radiusSquare;
  42101. var nextDiff = v2DistSquare(v3, center) - radiusSquare;
  42102. interval /= 2;
  42103. if (diff < 0) {
  42104. if (nextDiff >= 0) {
  42105. t = t + interval;
  42106. } else {
  42107. t = t - interval;
  42108. }
  42109. } else {
  42110. if (nextDiff >= 0) {
  42111. t = t - interval;
  42112. } else {
  42113. t = t + interval;
  42114. }
  42115. }
  42116. }
  42117. return t;
  42118. } // Adjust edge to avoid
  42119. var adjustEdge = function (graph, scale$$1) {
  42120. var tmp0 = [];
  42121. var quadraticSubdivide$$1 = quadraticSubdivide;
  42122. var pts = [[], [], []];
  42123. var pts2 = [[], []];
  42124. var v = [];
  42125. scale$$1 /= 2;
  42126. graph.eachEdge(function (edge, idx) {
  42127. var linePoints = edge.getLayout();
  42128. var fromSymbol = edge.getVisual('fromSymbol');
  42129. var toSymbol = edge.getVisual('toSymbol');
  42130. if (!linePoints.__original) {
  42131. linePoints.__original = [clone$1(linePoints[0]), clone$1(linePoints[1])];
  42132. if (linePoints[2]) {
  42133. linePoints.__original.push(clone$1(linePoints[2]));
  42134. }
  42135. }
  42136. var originalPoints = linePoints.__original; // Quadratic curve
  42137. if (linePoints[2] != null) {
  42138. copy(pts[0], originalPoints[0]);
  42139. copy(pts[1], originalPoints[2]);
  42140. copy(pts[2], originalPoints[1]);
  42141. if (fromSymbol && fromSymbol !== 'none') {
  42142. var symbolSize = getSymbolSize$1(edge.node1);
  42143. var t = intersectCurveCircle(pts, originalPoints[0], symbolSize * scale$$1); // Subdivide and get the second
  42144. quadraticSubdivide$$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  42145. pts[0][0] = tmp0[3];
  42146. pts[1][0] = tmp0[4];
  42147. quadraticSubdivide$$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  42148. pts[0][1] = tmp0[3];
  42149. pts[1][1] = tmp0[4];
  42150. }
  42151. if (toSymbol && toSymbol !== 'none') {
  42152. var symbolSize = getSymbolSize$1(edge.node2);
  42153. var t = intersectCurveCircle(pts, originalPoints[1], symbolSize * scale$$1); // Subdivide and get the first
  42154. quadraticSubdivide$$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  42155. pts[1][0] = tmp0[1];
  42156. pts[2][0] = tmp0[2];
  42157. quadraticSubdivide$$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  42158. pts[1][1] = tmp0[1];
  42159. pts[2][1] = tmp0[2];
  42160. } // Copy back to layout
  42161. copy(linePoints[0], pts[0]);
  42162. copy(linePoints[1], pts[2]);
  42163. copy(linePoints[2], pts[1]);
  42164. } // Line
  42165. else {
  42166. copy(pts2[0], originalPoints[0]);
  42167. copy(pts2[1], originalPoints[1]);
  42168. sub(v, pts2[1], pts2[0]);
  42169. normalize(v, v);
  42170. if (fromSymbol && fromSymbol !== 'none') {
  42171. var symbolSize = getSymbolSize$1(edge.node1);
  42172. scaleAndAdd(pts2[0], pts2[0], v, symbolSize * scale$$1);
  42173. }
  42174. if (toSymbol && toSymbol !== 'none') {
  42175. var symbolSize = getSymbolSize$1(edge.node2);
  42176. scaleAndAdd(pts2[1], pts2[1], v, -symbolSize * scale$$1);
  42177. }
  42178. copy(linePoints[0], pts2[0]);
  42179. copy(linePoints[1], pts2[1]);
  42180. }
  42181. });
  42182. };
  42183. /*
  42184. * Licensed to the Apache Software Foundation (ASF) under one
  42185. * or more contributor license agreements. See the NOTICE file
  42186. * distributed with this work for additional information
  42187. * regarding copyright ownership. The ASF licenses this file
  42188. * to you under the Apache License, Version 2.0 (the
  42189. * "License"); you may not use this file except in compliance
  42190. * with the License. You may obtain a copy of the License at
  42191. *
  42192. * http://www.apache.org/licenses/LICENSE-2.0
  42193. *
  42194. * Unless required by applicable law or agreed to in writing,
  42195. * software distributed under the License is distributed on an
  42196. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42197. * KIND, either express or implied. See the License for the
  42198. * specific language governing permissions and limitations
  42199. * under the License.
  42200. */
  42201. var FOCUS_ADJACENCY = '__focusNodeAdjacency';
  42202. var UNFOCUS_ADJACENCY = '__unfocusNodeAdjacency';
  42203. var nodeOpacityPath = ['itemStyle', 'opacity'];
  42204. var lineOpacityPath = ['lineStyle', 'opacity'];
  42205. function getItemOpacity(item, opacityPath) {
  42206. var opacity = item.getVisual('opacity');
  42207. return opacity != null ? opacity : item.getModel().get(opacityPath);
  42208. }
  42209. function fadeOutItem(item, opacityPath, opacityRatio) {
  42210. var el = item.getGraphicEl();
  42211. var opacity = getItemOpacity(item, opacityPath);
  42212. if (opacityRatio != null) {
  42213. opacity == null && (opacity = 1);
  42214. opacity *= opacityRatio;
  42215. }
  42216. el.downplay && el.downplay();
  42217. el.traverse(function (child) {
  42218. if (!child.isGroup) {
  42219. var opct = child.lineLabelOriginalOpacity;
  42220. if (opct == null || opacityRatio != null) {
  42221. opct = opacity;
  42222. }
  42223. child.setStyle('opacity', opct);
  42224. }
  42225. });
  42226. }
  42227. function fadeInItem(item, opacityPath) {
  42228. var opacity = getItemOpacity(item, opacityPath);
  42229. var el = item.getGraphicEl(); // Should go back to normal opacity first, consider hoverLayer,
  42230. // where current state is copied to elMirror, and support
  42231. // emphasis opacity here.
  42232. el.traverse(function (child) {
  42233. !child.isGroup && child.setStyle('opacity', opacity);
  42234. });
  42235. el.highlight && el.highlight();
  42236. }
  42237. extendChartView({
  42238. type: 'graph',
  42239. init: function (ecModel, api) {
  42240. var symbolDraw = new SymbolDraw();
  42241. var lineDraw = new LineDraw();
  42242. var group = this.group;
  42243. this._controller = new RoamController(api.getZr());
  42244. this._controllerHost = {
  42245. target: group
  42246. };
  42247. group.add(symbolDraw.group);
  42248. group.add(lineDraw.group);
  42249. this._symbolDraw = symbolDraw;
  42250. this._lineDraw = lineDraw;
  42251. this._firstRender = true;
  42252. },
  42253. render: function (seriesModel, ecModel, api) {
  42254. var graphView = this;
  42255. var coordSys = seriesModel.coordinateSystem;
  42256. this._model = seriesModel;
  42257. var symbolDraw = this._symbolDraw;
  42258. var lineDraw = this._lineDraw;
  42259. var group = this.group;
  42260. if (coordSys.type === 'view') {
  42261. var groupNewProp = {
  42262. position: coordSys.position,
  42263. scale: coordSys.scale
  42264. };
  42265. if (this._firstRender) {
  42266. group.attr(groupNewProp);
  42267. } else {
  42268. updateProps(group, groupNewProp, seriesModel);
  42269. }
  42270. } // Fix edge contact point with node
  42271. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  42272. var data = seriesModel.getData();
  42273. symbolDraw.updateData(data);
  42274. var edgeData = seriesModel.getEdgeData();
  42275. lineDraw.updateData(edgeData);
  42276. this._updateNodeAndLinkScale();
  42277. this._updateController(seriesModel, ecModel, api);
  42278. clearTimeout(this._layoutTimeout);
  42279. var forceLayout = seriesModel.forceLayout;
  42280. var layoutAnimation = seriesModel.get('force.layoutAnimation');
  42281. if (forceLayout) {
  42282. this._startForceLayoutIteration(forceLayout, layoutAnimation);
  42283. }
  42284. data.eachItemGraphicEl(function (el, idx) {
  42285. var itemModel = data.getItemModel(idx); // Update draggable
  42286. el.off('drag').off('dragend');
  42287. var draggable = itemModel.get('draggable');
  42288. if (draggable) {
  42289. el.on('drag', function () {
  42290. if (forceLayout) {
  42291. forceLayout.warmUp();
  42292. !this._layouting && this._startForceLayoutIteration(forceLayout, layoutAnimation);
  42293. forceLayout.setFixed(idx); // Write position back to layout
  42294. data.setItemLayout(idx, el.position);
  42295. }
  42296. }, this).on('dragend', function () {
  42297. if (forceLayout) {
  42298. forceLayout.setUnfixed(idx);
  42299. }
  42300. }, this);
  42301. }
  42302. el.setDraggable(draggable && forceLayout);
  42303. el[FOCUS_ADJACENCY] && el.off('mouseover', el[FOCUS_ADJACENCY]);
  42304. el[UNFOCUS_ADJACENCY] && el.off('mouseout', el[UNFOCUS_ADJACENCY]);
  42305. if (itemModel.get('focusNodeAdjacency')) {
  42306. el.on('mouseover', el[FOCUS_ADJACENCY] = function () {
  42307. graphView._clearTimer();
  42308. api.dispatchAction({
  42309. type: 'focusNodeAdjacency',
  42310. seriesId: seriesModel.id,
  42311. dataIndex: el.dataIndex
  42312. });
  42313. });
  42314. el.on('mouseout', el[UNFOCUS_ADJACENCY] = function () {
  42315. graphView._dispatchUnfocus(api);
  42316. });
  42317. }
  42318. }, this);
  42319. data.graph.eachEdge(function (edge) {
  42320. var el = edge.getGraphicEl();
  42321. el[FOCUS_ADJACENCY] && el.off('mouseover', el[FOCUS_ADJACENCY]);
  42322. el[UNFOCUS_ADJACENCY] && el.off('mouseout', el[UNFOCUS_ADJACENCY]);
  42323. if (edge.getModel().get('focusNodeAdjacency')) {
  42324. el.on('mouseover', el[FOCUS_ADJACENCY] = function () {
  42325. graphView._clearTimer();
  42326. api.dispatchAction({
  42327. type: 'focusNodeAdjacency',
  42328. seriesId: seriesModel.id,
  42329. edgeDataIndex: edge.dataIndex
  42330. });
  42331. });
  42332. el.on('mouseout', el[UNFOCUS_ADJACENCY] = function () {
  42333. graphView._dispatchUnfocus(api);
  42334. });
  42335. }
  42336. });
  42337. var circularRotateLabel = seriesModel.get('layout') === 'circular' && seriesModel.get('circular.rotateLabel');
  42338. var cx = data.getLayout('cx');
  42339. var cy = data.getLayout('cy');
  42340. data.eachItemGraphicEl(function (el, idx) {
  42341. var itemModel = data.getItemModel(idx);
  42342. var labelRotate = itemModel.get('label.rotate') || 0;
  42343. var symbolPath = el.getSymbolPath();
  42344. if (circularRotateLabel) {
  42345. var pos = data.getItemLayout(idx);
  42346. var rad = Math.atan2(pos[1] - cy, pos[0] - cx);
  42347. if (rad < 0) {
  42348. rad = Math.PI * 2 + rad;
  42349. }
  42350. var isLeft = pos[0] < cx;
  42351. if (isLeft) {
  42352. rad = rad - Math.PI;
  42353. }
  42354. var textPosition = isLeft ? 'left' : 'right';
  42355. modifyLabelStyle(symbolPath, {
  42356. textRotation: -rad,
  42357. textPosition: textPosition,
  42358. textOrigin: 'center'
  42359. }, {
  42360. textPosition: textPosition
  42361. });
  42362. } else {
  42363. modifyLabelStyle(symbolPath, {
  42364. textRotation: labelRotate *= Math.PI / 180
  42365. });
  42366. }
  42367. });
  42368. this._firstRender = false;
  42369. },
  42370. dispose: function () {
  42371. this._controller && this._controller.dispose();
  42372. this._controllerHost = {};
  42373. this._clearTimer();
  42374. },
  42375. _dispatchUnfocus: function (api, opt) {
  42376. var self = this;
  42377. this._clearTimer();
  42378. this._unfocusDelayTimer = setTimeout(function () {
  42379. self._unfocusDelayTimer = null;
  42380. api.dispatchAction({
  42381. type: 'unfocusNodeAdjacency',
  42382. seriesId: self._model.id
  42383. });
  42384. }, 500);
  42385. },
  42386. _clearTimer: function () {
  42387. if (this._unfocusDelayTimer) {
  42388. clearTimeout(this._unfocusDelayTimer);
  42389. this._unfocusDelayTimer = null;
  42390. }
  42391. },
  42392. focusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  42393. var data = seriesModel.getData();
  42394. var graph = data.graph;
  42395. var dataIndex = payload.dataIndex;
  42396. var edgeDataIndex = payload.edgeDataIndex;
  42397. var node = graph.getNodeByIndex(dataIndex);
  42398. var edge = graph.getEdgeByIndex(edgeDataIndex);
  42399. if (!node && !edge) {
  42400. return;
  42401. }
  42402. graph.eachNode(function (node) {
  42403. fadeOutItem(node, nodeOpacityPath, 0.1);
  42404. });
  42405. graph.eachEdge(function (edge) {
  42406. fadeOutItem(edge, lineOpacityPath, 0.1);
  42407. });
  42408. if (node) {
  42409. fadeInItem(node, nodeOpacityPath);
  42410. each$1(node.edges, function (adjacentEdge) {
  42411. if (adjacentEdge.dataIndex < 0) {
  42412. return;
  42413. }
  42414. fadeInItem(adjacentEdge, lineOpacityPath);
  42415. fadeInItem(adjacentEdge.node1, nodeOpacityPath);
  42416. fadeInItem(adjacentEdge.node2, nodeOpacityPath);
  42417. });
  42418. }
  42419. if (edge) {
  42420. fadeInItem(edge, lineOpacityPath);
  42421. fadeInItem(edge.node1, nodeOpacityPath);
  42422. fadeInItem(edge.node2, nodeOpacityPath);
  42423. }
  42424. },
  42425. unfocusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  42426. var graph = seriesModel.getData().graph;
  42427. graph.eachNode(function (node) {
  42428. fadeOutItem(node, nodeOpacityPath);
  42429. });
  42430. graph.eachEdge(function (edge) {
  42431. fadeOutItem(edge, lineOpacityPath);
  42432. });
  42433. },
  42434. _startForceLayoutIteration: function (forceLayout, layoutAnimation) {
  42435. var self = this;
  42436. (function step() {
  42437. forceLayout.step(function (stopped) {
  42438. self.updateLayout(self._model);
  42439. (self._layouting = !stopped) && (layoutAnimation ? self._layoutTimeout = setTimeout(step, 16) : step());
  42440. });
  42441. })();
  42442. },
  42443. _updateController: function (seriesModel, ecModel, api) {
  42444. var controller = this._controller;
  42445. var controllerHost = this._controllerHost;
  42446. var group = this.group;
  42447. controller.setPointerChecker(function (e, x, y) {
  42448. var rect = group.getBoundingRect();
  42449. rect.applyTransform(group.transform);
  42450. return rect.contain(x, y) && !onIrrelevantElement(e, api, seriesModel);
  42451. });
  42452. if (seriesModel.coordinateSystem.type !== 'view') {
  42453. controller.disable();
  42454. return;
  42455. }
  42456. controller.enable(seriesModel.get('roam'));
  42457. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  42458. controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
  42459. controller.off('pan').off('zoom').on('pan', function (e) {
  42460. updateViewOnPan(controllerHost, e.dx, e.dy);
  42461. api.dispatchAction({
  42462. seriesId: seriesModel.id,
  42463. type: 'graphRoam',
  42464. dx: e.dx,
  42465. dy: e.dy
  42466. });
  42467. }).on('zoom', function (e) {
  42468. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  42469. api.dispatchAction({
  42470. seriesId: seriesModel.id,
  42471. type: 'graphRoam',
  42472. zoom: e.scale,
  42473. originX: e.originX,
  42474. originY: e.originY
  42475. });
  42476. this._updateNodeAndLinkScale();
  42477. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  42478. this._lineDraw.updateLayout();
  42479. }, this);
  42480. },
  42481. _updateNodeAndLinkScale: function () {
  42482. var seriesModel = this._model;
  42483. var data = seriesModel.getData();
  42484. var nodeScale = getNodeGlobalScale(seriesModel);
  42485. var invScale = [nodeScale, nodeScale];
  42486. data.eachItemGraphicEl(function (el, idx) {
  42487. el.attr('scale', invScale);
  42488. });
  42489. },
  42490. updateLayout: function (seriesModel) {
  42491. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  42492. this._symbolDraw.updateLayout();
  42493. this._lineDraw.updateLayout();
  42494. },
  42495. remove: function (ecModel, api) {
  42496. this._symbolDraw && this._symbolDraw.remove();
  42497. this._lineDraw && this._lineDraw.remove();
  42498. }
  42499. });
  42500. /*
  42501. * Licensed to the Apache Software Foundation (ASF) under one
  42502. * or more contributor license agreements. See the NOTICE file
  42503. * distributed with this work for additional information
  42504. * regarding copyright ownership. The ASF licenses this file
  42505. * to you under the Apache License, Version 2.0 (the
  42506. * "License"); you may not use this file except in compliance
  42507. * with the License. You may obtain a copy of the License at
  42508. *
  42509. * http://www.apache.org/licenses/LICENSE-2.0
  42510. *
  42511. * Unless required by applicable law or agreed to in writing,
  42512. * software distributed under the License is distributed on an
  42513. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42514. * KIND, either express or implied. See the License for the
  42515. * specific language governing permissions and limitations
  42516. * under the License.
  42517. */
  42518. /**
  42519. * @payload
  42520. * @property {number} [seriesIndex]
  42521. * @property {string} [seriesId]
  42522. * @property {string} [seriesName]
  42523. * @property {number} [dataIndex]
  42524. */
  42525. registerAction({
  42526. type: 'focusNodeAdjacency',
  42527. event: 'focusNodeAdjacency',
  42528. update: 'series:focusNodeAdjacency'
  42529. }, function () {});
  42530. /**
  42531. * @payload
  42532. * @property {number} [seriesIndex]
  42533. * @property {string} [seriesId]
  42534. * @property {string} [seriesName]
  42535. */
  42536. registerAction({
  42537. type: 'unfocusNodeAdjacency',
  42538. event: 'unfocusNodeAdjacency',
  42539. update: 'series:unfocusNodeAdjacency'
  42540. }, function () {});
  42541. /*
  42542. * Licensed to the Apache Software Foundation (ASF) under one
  42543. * or more contributor license agreements. See the NOTICE file
  42544. * distributed with this work for additional information
  42545. * regarding copyright ownership. The ASF licenses this file
  42546. * to you under the Apache License, Version 2.0 (the
  42547. * "License"); you may not use this file except in compliance
  42548. * with the License. You may obtain a copy of the License at
  42549. *
  42550. * http://www.apache.org/licenses/LICENSE-2.0
  42551. *
  42552. * Unless required by applicable law or agreed to in writing,
  42553. * software distributed under the License is distributed on an
  42554. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42555. * KIND, either express or implied. See the License for the
  42556. * specific language governing permissions and limitations
  42557. * under the License.
  42558. */
  42559. var actionInfo = {
  42560. type: 'graphRoam',
  42561. event: 'graphRoam',
  42562. update: 'none'
  42563. };
  42564. /**
  42565. * @payload
  42566. * @property {string} name Series name
  42567. * @property {number} [dx]
  42568. * @property {number} [dy]
  42569. * @property {number} [zoom]
  42570. * @property {number} [originX]
  42571. * @property {number} [originY]
  42572. */
  42573. registerAction(actionInfo, function (payload, ecModel) {
  42574. ecModel.eachComponent({
  42575. mainType: 'series',
  42576. query: payload
  42577. }, function (seriesModel) {
  42578. var coordSys = seriesModel.coordinateSystem;
  42579. var res = updateCenterAndZoom(coordSys, payload);
  42580. seriesModel.setCenter && seriesModel.setCenter(res.center);
  42581. seriesModel.setZoom && seriesModel.setZoom(res.zoom);
  42582. });
  42583. });
  42584. /*
  42585. * Licensed to the Apache Software Foundation (ASF) under one
  42586. * or more contributor license agreements. See the NOTICE file
  42587. * distributed with this work for additional information
  42588. * regarding copyright ownership. The ASF licenses this file
  42589. * to you under the Apache License, Version 2.0 (the
  42590. * "License"); you may not use this file except in compliance
  42591. * with the License. You may obtain a copy of the License at
  42592. *
  42593. * http://www.apache.org/licenses/LICENSE-2.0
  42594. *
  42595. * Unless required by applicable law or agreed to in writing,
  42596. * software distributed under the License is distributed on an
  42597. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42598. * KIND, either express or implied. See the License for the
  42599. * specific language governing permissions and limitations
  42600. * under the License.
  42601. */
  42602. var categoryFilter = function (ecModel) {
  42603. var legendModels = ecModel.findComponents({
  42604. mainType: 'legend'
  42605. });
  42606. if (!legendModels || !legendModels.length) {
  42607. return;
  42608. }
  42609. ecModel.eachSeriesByType('graph', function (graphSeries) {
  42610. var categoriesData = graphSeries.getCategoriesData();
  42611. var graph = graphSeries.getGraph();
  42612. var data = graph.data;
  42613. var categoryNames = categoriesData.mapArray(categoriesData.getName);
  42614. data.filterSelf(function (idx) {
  42615. var model = data.getItemModel(idx);
  42616. var category = model.getShallow('category');
  42617. if (category != null) {
  42618. if (typeof category === 'number') {
  42619. category = categoryNames[category];
  42620. } // If in any legend component the status is not selected.
  42621. for (var i = 0; i < legendModels.length; i++) {
  42622. if (!legendModels[i].isSelected(category)) {
  42623. return false;
  42624. }
  42625. }
  42626. }
  42627. return true;
  42628. });
  42629. }, this);
  42630. };
  42631. /*
  42632. * Licensed to the Apache Software Foundation (ASF) under one
  42633. * or more contributor license agreements. See the NOTICE file
  42634. * distributed with this work for additional information
  42635. * regarding copyright ownership. The ASF licenses this file
  42636. * to you under the Apache License, Version 2.0 (the
  42637. * "License"); you may not use this file except in compliance
  42638. * with the License. You may obtain a copy of the License at
  42639. *
  42640. * http://www.apache.org/licenses/LICENSE-2.0
  42641. *
  42642. * Unless required by applicable law or agreed to in writing,
  42643. * software distributed under the License is distributed on an
  42644. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42645. * KIND, either express or implied. See the License for the
  42646. * specific language governing permissions and limitations
  42647. * under the License.
  42648. */
  42649. var categoryVisual = function (ecModel) {
  42650. var paletteScope = {};
  42651. ecModel.eachSeriesByType('graph', function (seriesModel) {
  42652. var categoriesData = seriesModel.getCategoriesData();
  42653. var data = seriesModel.getData();
  42654. var categoryNameIdxMap = {};
  42655. categoriesData.each(function (idx) {
  42656. var name = categoriesData.getName(idx); // Add prefix to avoid conflict with Object.prototype.
  42657. categoryNameIdxMap['ec-' + name] = idx;
  42658. var itemModel = categoriesData.getItemModel(idx);
  42659. var color = itemModel.get('itemStyle.color') || seriesModel.getColorFromPalette(name, paletteScope);
  42660. categoriesData.setItemVisual(idx, 'color', color);
  42661. var itemStyleList = ['opacity', 'symbol', 'symbolSize', 'symbolKeepAspect'];
  42662. for (var i = 0; i < itemStyleList.length; i++) {
  42663. var itemStyle = itemModel.getShallow(itemStyleList[i], true);
  42664. if (itemStyle != null) {
  42665. categoriesData.setItemVisual(idx, itemStyleList[i], itemStyle);
  42666. }
  42667. }
  42668. }); // Assign category color to visual
  42669. if (categoriesData.count()) {
  42670. data.each(function (idx) {
  42671. var model = data.getItemModel(idx);
  42672. var category = model.getShallow('category');
  42673. if (category != null) {
  42674. if (typeof category === 'string') {
  42675. category = categoryNameIdxMap['ec-' + category];
  42676. }
  42677. var itemStyleList = ['color', 'opacity', 'symbol', 'symbolSize', 'symbolKeepAspect'];
  42678. for (var i = 0; i < itemStyleList.length; i++) {
  42679. if (data.getItemVisual(idx, itemStyleList[i], true) == null) {
  42680. data.setItemVisual(idx, itemStyleList[i], categoriesData.getItemVisual(category, itemStyleList[i]));
  42681. }
  42682. }
  42683. }
  42684. });
  42685. }
  42686. });
  42687. };
  42688. /*
  42689. * Licensed to the Apache Software Foundation (ASF) under one
  42690. * or more contributor license agreements. See the NOTICE file
  42691. * distributed with this work for additional information
  42692. * regarding copyright ownership. The ASF licenses this file
  42693. * to you under the Apache License, Version 2.0 (the
  42694. * "License"); you may not use this file except in compliance
  42695. * with the License. You may obtain a copy of the License at
  42696. *
  42697. * http://www.apache.org/licenses/LICENSE-2.0
  42698. *
  42699. * Unless required by applicable law or agreed to in writing,
  42700. * software distributed under the License is distributed on an
  42701. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42702. * KIND, either express or implied. See the License for the
  42703. * specific language governing permissions and limitations
  42704. * under the License.
  42705. */
  42706. function normalize$1(a) {
  42707. if (!(a instanceof Array)) {
  42708. a = [a, a];
  42709. }
  42710. return a;
  42711. }
  42712. var edgeVisual = function (ecModel) {
  42713. ecModel.eachSeriesByType('graph', function (seriesModel) {
  42714. var graph = seriesModel.getGraph();
  42715. var edgeData = seriesModel.getEdgeData();
  42716. var symbolType = normalize$1(seriesModel.get('edgeSymbol'));
  42717. var symbolSize = normalize$1(seriesModel.get('edgeSymbolSize'));
  42718. var colorQuery = 'lineStyle.color'.split('.');
  42719. var opacityQuery = 'lineStyle.opacity'.split('.');
  42720. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  42721. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  42722. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  42723. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  42724. edgeData.setVisual('color', seriesModel.get(colorQuery));
  42725. edgeData.setVisual('opacity', seriesModel.get(opacityQuery));
  42726. edgeData.each(function (idx) {
  42727. var itemModel = edgeData.getItemModel(idx);
  42728. var edge = graph.getEdgeByIndex(idx);
  42729. var symbolType = normalize$1(itemModel.getShallow('symbol', true));
  42730. var symbolSize = normalize$1(itemModel.getShallow('symbolSize', true)); // Edge visual must after node visual
  42731. var color = itemModel.get(colorQuery);
  42732. var opacity = itemModel.get(opacityQuery);
  42733. switch (color) {
  42734. case 'source':
  42735. color = edge.node1.getVisual('color');
  42736. break;
  42737. case 'target':
  42738. color = edge.node2.getVisual('color');
  42739. break;
  42740. }
  42741. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  42742. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  42743. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  42744. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  42745. edge.setVisual('color', color);
  42746. edge.setVisual('opacity', opacity);
  42747. });
  42748. });
  42749. };
  42750. /*
  42751. * Licensed to the Apache Software Foundation (ASF) under one
  42752. * or more contributor license agreements. See the NOTICE file
  42753. * distributed with this work for additional information
  42754. * regarding copyright ownership. The ASF licenses this file
  42755. * to you under the Apache License, Version 2.0 (the
  42756. * "License"); you may not use this file except in compliance
  42757. * with the License. You may obtain a copy of the License at
  42758. *
  42759. * http://www.apache.org/licenses/LICENSE-2.0
  42760. *
  42761. * Unless required by applicable law or agreed to in writing,
  42762. * software distributed under the License is distributed on an
  42763. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42764. * KIND, either express or implied. See the License for the
  42765. * specific language governing permissions and limitations
  42766. * under the License.
  42767. */
  42768. function simpleLayout$1(seriesModel) {
  42769. var coordSys = seriesModel.coordinateSystem;
  42770. if (coordSys && coordSys.type !== 'view') {
  42771. return;
  42772. }
  42773. var graph = seriesModel.getGraph();
  42774. graph.eachNode(function (node) {
  42775. var model = node.getModel();
  42776. node.setLayout([+model.get('x'), +model.get('y')]);
  42777. });
  42778. simpleLayoutEdge(graph);
  42779. }
  42780. function simpleLayoutEdge(graph) {
  42781. graph.eachEdge(function (edge) {
  42782. var curveness = edge.getModel().get('lineStyle.curveness') || 0;
  42783. var p1 = clone$1(edge.node1.getLayout());
  42784. var p2 = clone$1(edge.node2.getLayout());
  42785. var points = [p1, p2];
  42786. if (+curveness) {
  42787. points.push([(p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * curveness, (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * curveness]);
  42788. }
  42789. edge.setLayout(points);
  42790. });
  42791. }
  42792. /*
  42793. * Licensed to the Apache Software Foundation (ASF) under one
  42794. * or more contributor license agreements. See the NOTICE file
  42795. * distributed with this work for additional information
  42796. * regarding copyright ownership. The ASF licenses this file
  42797. * to you under the Apache License, Version 2.0 (the
  42798. * "License"); you may not use this file except in compliance
  42799. * with the License. You may obtain a copy of the License at
  42800. *
  42801. * http://www.apache.org/licenses/LICENSE-2.0
  42802. *
  42803. * Unless required by applicable law or agreed to in writing,
  42804. * software distributed under the License is distributed on an
  42805. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42806. * KIND, either express or implied. See the License for the
  42807. * specific language governing permissions and limitations
  42808. * under the License.
  42809. */
  42810. var simpleLayout = function (ecModel, api) {
  42811. ecModel.eachSeriesByType('graph', function (seriesModel) {
  42812. var layout = seriesModel.get('layout');
  42813. var coordSys = seriesModel.coordinateSystem;
  42814. if (coordSys && coordSys.type !== 'view') {
  42815. var data = seriesModel.getData();
  42816. var dimensions = [];
  42817. each$1(coordSys.dimensions, function (coordDim) {
  42818. dimensions = dimensions.concat(data.mapDimension(coordDim, true));
  42819. });
  42820. for (var dataIndex = 0; dataIndex < data.count(); dataIndex++) {
  42821. var value = [];
  42822. var hasValue = false;
  42823. for (var i = 0; i < dimensions.length; i++) {
  42824. var val = data.get(dimensions[i], dataIndex);
  42825. if (!isNaN(val)) {
  42826. hasValue = true;
  42827. }
  42828. value.push(val);
  42829. }
  42830. if (hasValue) {
  42831. data.setItemLayout(dataIndex, coordSys.dataToPoint(value));
  42832. } else {
  42833. // Also {Array.<number>}, not undefined to avoid if...else... statement
  42834. data.setItemLayout(dataIndex, [NaN, NaN]);
  42835. }
  42836. }
  42837. simpleLayoutEdge(data.graph);
  42838. } else if (!layout || layout === 'none') {
  42839. simpleLayout$1(seriesModel);
  42840. }
  42841. });
  42842. };
  42843. /*
  42844. * Licensed to the Apache Software Foundation (ASF) under one
  42845. * or more contributor license agreements. See the NOTICE file
  42846. * distributed with this work for additional information
  42847. * regarding copyright ownership. The ASF licenses this file
  42848. * to you under the Apache License, Version 2.0 (the
  42849. * "License"); you may not use this file except in compliance
  42850. * with the License. You may obtain a copy of the License at
  42851. *
  42852. * http://www.apache.org/licenses/LICENSE-2.0
  42853. *
  42854. * Unless required by applicable law or agreed to in writing,
  42855. * software distributed under the License is distributed on an
  42856. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42857. * KIND, either express or implied. See the License for the
  42858. * specific language governing permissions and limitations
  42859. * under the License.
  42860. */
  42861. var PI$3 = Math.PI;
  42862. var _symbolRadiansHalf = [];
  42863. /**
  42864. * `basedOn` can be:
  42865. * 'value':
  42866. * This layout is not accurate and have same bad case. For example,
  42867. * if the min value is very smaller than the max value, the nodes
  42868. * with the min value probably overlap even though there is enough
  42869. * space to layout them. So we only use this approach in the as the
  42870. * init layout of the force layout.
  42871. * FIXME
  42872. * Probably we do not need this method any more but use
  42873. * `basedOn: 'symbolSize'` in force layout if
  42874. * delay its init operations to GraphView.
  42875. * 'symbolSize':
  42876. * This approach work only if all of the symbol size calculated.
  42877. * That is, the progressive rendering is not applied to graph.
  42878. * FIXME
  42879. * If progressive rendering is applied to graph some day,
  42880. * probably we have to use `basedOn: 'value'`.
  42881. *
  42882. * @param {module:echarts/src/model/Series} seriesModel
  42883. * @param {string} basedOn 'value' or 'symbolSize'
  42884. */
  42885. function circularLayout$1(seriesModel, basedOn) {
  42886. var coordSys = seriesModel.coordinateSystem;
  42887. if (coordSys && coordSys.type !== 'view') {
  42888. return;
  42889. }
  42890. var rect = coordSys.getBoundingRect();
  42891. var nodeData = seriesModel.getData();
  42892. var graph = nodeData.graph;
  42893. var cx = rect.width / 2 + rect.x;
  42894. var cy = rect.height / 2 + rect.y;
  42895. var r = Math.min(rect.width, rect.height) / 2;
  42896. var count = nodeData.count();
  42897. nodeData.setLayout({
  42898. cx: cx,
  42899. cy: cy
  42900. });
  42901. if (!count) {
  42902. return;
  42903. }
  42904. _layoutNodesBasedOn[basedOn](seriesModel, coordSys, graph, nodeData, r, cx, cy, count);
  42905. graph.eachEdge(function (edge) {
  42906. var curveness = edge.getModel().get('lineStyle.curveness') || 0;
  42907. var p1 = clone$1(edge.node1.getLayout());
  42908. var p2 = clone$1(edge.node2.getLayout());
  42909. var cp1;
  42910. var x12 = (p1[0] + p2[0]) / 2;
  42911. var y12 = (p1[1] + p2[1]) / 2;
  42912. if (+curveness) {
  42913. curveness *= 3;
  42914. cp1 = [cx * curveness + x12 * (1 - curveness), cy * curveness + y12 * (1 - curveness)];
  42915. }
  42916. edge.setLayout([p1, p2, cp1]);
  42917. });
  42918. }
  42919. var _layoutNodesBasedOn = {
  42920. value: function (seriesModel, coordSys, graph, nodeData, r, cx, cy, count) {
  42921. var angle = 0;
  42922. var sum = nodeData.getSum('value');
  42923. var unitAngle = Math.PI * 2 / (sum || count);
  42924. graph.eachNode(function (node) {
  42925. var value = node.getValue('value');
  42926. var radianHalf = unitAngle * (sum ? value : 1) / 2;
  42927. angle += radianHalf;
  42928. node.setLayout([r * Math.cos(angle) + cx, r * Math.sin(angle) + cy]);
  42929. angle += radianHalf;
  42930. });
  42931. },
  42932. symbolSize: function (seriesModel, coordSys, graph, nodeData, r, cx, cy, count) {
  42933. var sumRadian = 0;
  42934. _symbolRadiansHalf.length = count;
  42935. var nodeScale = getNodeGlobalScale(seriesModel);
  42936. graph.eachNode(function (node) {
  42937. var symbolSize = getSymbolSize$1(node); // Normally this case will not happen, but we still add
  42938. // some the defensive code (2px is an arbitrary value).
  42939. isNaN(symbolSize) && (symbolSize = 2);
  42940. symbolSize < 0 && (symbolSize = 0);
  42941. symbolSize *= nodeScale;
  42942. var symbolRadianHalf = Math.asin(symbolSize / 2 / r); // when `symbolSize / 2` is bigger than `r`.
  42943. isNaN(symbolRadianHalf) && (symbolRadianHalf = PI$3 / 2);
  42944. _symbolRadiansHalf[node.dataIndex] = symbolRadianHalf;
  42945. sumRadian += symbolRadianHalf * 2;
  42946. });
  42947. var halfRemainRadian = (2 * PI$3 - sumRadian) / count / 2;
  42948. var angle = 0;
  42949. graph.eachNode(function (node) {
  42950. var radianHalf = halfRemainRadian + _symbolRadiansHalf[node.dataIndex];
  42951. angle += radianHalf;
  42952. node.setLayout([r * Math.cos(angle) + cx, r * Math.sin(angle) + cy]);
  42953. angle += radianHalf;
  42954. });
  42955. }
  42956. };
  42957. /*
  42958. * Licensed to the Apache Software Foundation (ASF) under one
  42959. * or more contributor license agreements. See the NOTICE file
  42960. * distributed with this work for additional information
  42961. * regarding copyright ownership. The ASF licenses this file
  42962. * to you under the Apache License, Version 2.0 (the
  42963. * "License"); you may not use this file except in compliance
  42964. * with the License. You may obtain a copy of the License at
  42965. *
  42966. * http://www.apache.org/licenses/LICENSE-2.0
  42967. *
  42968. * Unless required by applicable law or agreed to in writing,
  42969. * software distributed under the License is distributed on an
  42970. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42971. * KIND, either express or implied. See the License for the
  42972. * specific language governing permissions and limitations
  42973. * under the License.
  42974. */
  42975. var circularLayout = function (ecModel) {
  42976. ecModel.eachSeriesByType('graph', function (seriesModel) {
  42977. if (seriesModel.get('layout') === 'circular') {
  42978. circularLayout$1(seriesModel, 'symbolSize');
  42979. }
  42980. });
  42981. };
  42982. /*
  42983. * Licensed to the Apache Software Foundation (ASF) under one
  42984. * or more contributor license agreements. See the NOTICE file
  42985. * distributed with this work for additional information
  42986. * regarding copyright ownership. The ASF licenses this file
  42987. * to you under the Apache License, Version 2.0 (the
  42988. * "License"); you may not use this file except in compliance
  42989. * with the License. You may obtain a copy of the License at
  42990. *
  42991. * http://www.apache.org/licenses/LICENSE-2.0
  42992. *
  42993. * Unless required by applicable law or agreed to in writing,
  42994. * software distributed under the License is distributed on an
  42995. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42996. * KIND, either express or implied. See the License for the
  42997. * specific language governing permissions and limitations
  42998. * under the License.
  42999. */
  43000. /*
  43001. * A third-party license is embeded for some of the code in this file:
  43002. * Some formulas were originally copied from "d3.js" with some
  43003. * modifications made for this project.
  43004. * (See more details in the comment of the method "step" below.)
  43005. * The use of the source code of this file is also subject to the terms
  43006. * and consitions of the license of "d3.js" (BSD-3Clause, see
  43007. * </licenses/LICENSE-d3>).
  43008. */
  43009. var scaleAndAdd$2 = scaleAndAdd; // function adjacentNode(n, e) {
  43010. // return e.n1 === n ? e.n2 : e.n1;
  43011. // }
  43012. function forceLayout$1(nodes, edges, opts) {
  43013. var rect = opts.rect;
  43014. var width = rect.width;
  43015. var height = rect.height;
  43016. var center = [rect.x + width / 2, rect.y + height / 2]; // var scale = opts.scale || 1;
  43017. var gravity = opts.gravity == null ? 0.1 : opts.gravity; // for (var i = 0; i < edges.length; i++) {
  43018. // var e = edges[i];
  43019. // var n1 = e.n1;
  43020. // var n2 = e.n2;
  43021. // n1.edges = n1.edges || [];
  43022. // n2.edges = n2.edges || [];
  43023. // n1.edges.push(e);
  43024. // n2.edges.push(e);
  43025. // }
  43026. // Init position
  43027. for (var i = 0; i < nodes.length; i++) {
  43028. var n = nodes[i];
  43029. if (!n.p) {
  43030. n.p = create(width * (Math.random() - 0.5) + center[0], height * (Math.random() - 0.5) + center[1]);
  43031. }
  43032. n.pp = clone$1(n.p);
  43033. n.edges = null;
  43034. } // Formula in 'Graph Drawing by Force-directed Placement'
  43035. // var k = scale * Math.sqrt(width * height / nodes.length);
  43036. // var k2 = k * k;
  43037. var initialFriction = opts.friction == null ? 0.6 : opts.friction;
  43038. var friction = initialFriction;
  43039. return {
  43040. warmUp: function () {
  43041. friction = initialFriction * 0.8;
  43042. },
  43043. setFixed: function (idx) {
  43044. nodes[idx].fixed = true;
  43045. },
  43046. setUnfixed: function (idx) {
  43047. nodes[idx].fixed = false;
  43048. },
  43049. /**
  43050. * Some formulas were originally copied from "d3.js"
  43051. * https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/layout/force.js
  43052. * with some modifications made for this project.
  43053. * See the license statement at the head of this file.
  43054. */
  43055. step: function (cb) {
  43056. var v12 = [];
  43057. var nLen = nodes.length;
  43058. for (var i = 0; i < edges.length; i++) {
  43059. var e = edges[i];
  43060. if (e.ignoreForceLayout) {
  43061. continue;
  43062. }
  43063. var n1 = e.n1;
  43064. var n2 = e.n2;
  43065. sub(v12, n2.p, n1.p);
  43066. var d = len(v12) - e.d;
  43067. var w = n2.w / (n1.w + n2.w);
  43068. if (isNaN(w)) {
  43069. w = 0;
  43070. }
  43071. normalize(v12, v12);
  43072. !n1.fixed && scaleAndAdd$2(n1.p, n1.p, v12, w * d * friction);
  43073. !n2.fixed && scaleAndAdd$2(n2.p, n2.p, v12, -(1 - w) * d * friction);
  43074. } // Gravity
  43075. for (var i = 0; i < nLen; i++) {
  43076. var n = nodes[i];
  43077. if (!n.fixed) {
  43078. sub(v12, center, n.p); // var d = vec2.len(v12);
  43079. // vec2.scale(v12, v12, 1 / d);
  43080. // var gravityFactor = gravity;
  43081. scaleAndAdd$2(n.p, n.p, v12, gravity * friction);
  43082. }
  43083. } // Repulsive
  43084. // PENDING
  43085. for (var i = 0; i < nLen; i++) {
  43086. var n1 = nodes[i];
  43087. for (var j = i + 1; j < nLen; j++) {
  43088. var n2 = nodes[j];
  43089. sub(v12, n2.p, n1.p);
  43090. var d = len(v12);
  43091. if (d === 0) {
  43092. // Random repulse
  43093. set(v12, Math.random() - 0.5, Math.random() - 0.5);
  43094. d = 1;
  43095. }
  43096. var repFact = (n1.rep + n2.rep) / d / d;
  43097. !n1.fixed && scaleAndAdd$2(n1.pp, n1.pp, v12, repFact);
  43098. !n2.fixed && scaleAndAdd$2(n2.pp, n2.pp, v12, -repFact);
  43099. }
  43100. }
  43101. var v = [];
  43102. for (var i = 0; i < nLen; i++) {
  43103. var n = nodes[i];
  43104. if (!n.fixed) {
  43105. sub(v, n.p, n.pp);
  43106. scaleAndAdd$2(n.p, n.p, v, friction);
  43107. copy(n.pp, n.p);
  43108. }
  43109. }
  43110. friction = friction * 0.992;
  43111. cb && cb(nodes, edges, friction < 0.01);
  43112. }
  43113. };
  43114. }
  43115. /*
  43116. * Licensed to the Apache Software Foundation (ASF) under one
  43117. * or more contributor license agreements. See the NOTICE file
  43118. * distributed with this work for additional information
  43119. * regarding copyright ownership. The ASF licenses this file
  43120. * to you under the Apache License, Version 2.0 (the
  43121. * "License"); you may not use this file except in compliance
  43122. * with the License. You may obtain a copy of the License at
  43123. *
  43124. * http://www.apache.org/licenses/LICENSE-2.0
  43125. *
  43126. * Unless required by applicable law or agreed to in writing,
  43127. * software distributed under the License is distributed on an
  43128. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43129. * KIND, either express or implied. See the License for the
  43130. * specific language governing permissions and limitations
  43131. * under the License.
  43132. */
  43133. var forceLayout = function (ecModel) {
  43134. ecModel.eachSeriesByType('graph', function (graphSeries) {
  43135. var coordSys = graphSeries.coordinateSystem;
  43136. if (coordSys && coordSys.type !== 'view') {
  43137. return;
  43138. }
  43139. if (graphSeries.get('layout') === 'force') {
  43140. var preservedPoints = graphSeries.preservedPoints || {};
  43141. var graph = graphSeries.getGraph();
  43142. var nodeData = graph.data;
  43143. var edgeData = graph.edgeData;
  43144. var forceModel = graphSeries.getModel('force');
  43145. var initLayout = forceModel.get('initLayout');
  43146. if (graphSeries.preservedPoints) {
  43147. nodeData.each(function (idx) {
  43148. var id = nodeData.getId(idx);
  43149. nodeData.setItemLayout(idx, preservedPoints[id] || [NaN, NaN]);
  43150. });
  43151. } else if (!initLayout || initLayout === 'none') {
  43152. simpleLayout$1(graphSeries);
  43153. } else if (initLayout === 'circular') {
  43154. circularLayout$1(graphSeries, 'value');
  43155. }
  43156. var nodeDataExtent = nodeData.getDataExtent('value');
  43157. var edgeDataExtent = edgeData.getDataExtent('value'); // var edgeDataExtent = edgeData.getDataExtent('value');
  43158. var repulsion = forceModel.get('repulsion');
  43159. var edgeLength = forceModel.get('edgeLength');
  43160. if (!isArray(repulsion)) {
  43161. repulsion = [repulsion, repulsion];
  43162. }
  43163. if (!isArray(edgeLength)) {
  43164. edgeLength = [edgeLength, edgeLength];
  43165. } // Larger value has smaller length
  43166. edgeLength = [edgeLength[1], edgeLength[0]];
  43167. var nodes = nodeData.mapArray('value', function (value, idx) {
  43168. var point = nodeData.getItemLayout(idx);
  43169. var rep = linearMap(value, nodeDataExtent, repulsion);
  43170. if (isNaN(rep)) {
  43171. rep = (repulsion[0] + repulsion[1]) / 2;
  43172. }
  43173. return {
  43174. w: rep,
  43175. rep: rep,
  43176. fixed: nodeData.getItemModel(idx).get('fixed'),
  43177. p: !point || isNaN(point[0]) || isNaN(point[1]) ? null : point
  43178. };
  43179. });
  43180. var edges = edgeData.mapArray('value', function (value, idx) {
  43181. var edge = graph.getEdgeByIndex(idx);
  43182. var d = linearMap(value, edgeDataExtent, edgeLength);
  43183. if (isNaN(d)) {
  43184. d = (edgeLength[0] + edgeLength[1]) / 2;
  43185. }
  43186. var edgeModel = edge.getModel();
  43187. return {
  43188. n1: nodes[edge.node1.dataIndex],
  43189. n2: nodes[edge.node2.dataIndex],
  43190. d: d,
  43191. curveness: edgeModel.get('lineStyle.curveness') || 0,
  43192. ignoreForceLayout: edgeModel.get('ignoreForceLayout')
  43193. };
  43194. });
  43195. var coordSys = graphSeries.coordinateSystem;
  43196. var rect = coordSys.getBoundingRect();
  43197. var forceInstance = forceLayout$1(nodes, edges, {
  43198. rect: rect,
  43199. gravity: forceModel.get('gravity'),
  43200. friction: forceModel.get('friction')
  43201. });
  43202. var oldStep = forceInstance.step;
  43203. forceInstance.step = function (cb) {
  43204. for (var i = 0, l = nodes.length; i < l; i++) {
  43205. if (nodes[i].fixed) {
  43206. // Write back to layout instance
  43207. copy(nodes[i].p, graph.getNodeByIndex(i).getLayout());
  43208. }
  43209. }
  43210. oldStep(function (nodes, edges, stopped) {
  43211. for (var i = 0, l = nodes.length; i < l; i++) {
  43212. if (!nodes[i].fixed) {
  43213. graph.getNodeByIndex(i).setLayout(nodes[i].p);
  43214. }
  43215. preservedPoints[nodeData.getId(i)] = nodes[i].p;
  43216. }
  43217. for (var i = 0, l = edges.length; i < l; i++) {
  43218. var e = edges[i];
  43219. var edge = graph.getEdgeByIndex(i);
  43220. var p1 = e.n1.p;
  43221. var p2 = e.n2.p;
  43222. var points = edge.getLayout();
  43223. points = points ? points.slice() : [];
  43224. points[0] = points[0] || [];
  43225. points[1] = points[1] || [];
  43226. copy(points[0], p1);
  43227. copy(points[1], p2);
  43228. if (+e.curveness) {
  43229. points[2] = [(p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * e.curveness, (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * e.curveness];
  43230. }
  43231. edge.setLayout(points);
  43232. } // Update layout
  43233. cb && cb(stopped);
  43234. });
  43235. };
  43236. graphSeries.forceLayout = forceInstance;
  43237. graphSeries.preservedPoints = preservedPoints; // Step to get the layout
  43238. forceInstance.step();
  43239. } else {
  43240. // Remove prev injected forceLayout instance
  43241. graphSeries.forceLayout = null;
  43242. }
  43243. });
  43244. };
  43245. /*
  43246. * Licensed to the Apache Software Foundation (ASF) under one
  43247. * or more contributor license agreements. See the NOTICE file
  43248. * distributed with this work for additional information
  43249. * regarding copyright ownership. The ASF licenses this file
  43250. * to you under the Apache License, Version 2.0 (the
  43251. * "License"); you may not use this file except in compliance
  43252. * with the License. You may obtain a copy of the License at
  43253. *
  43254. * http://www.apache.org/licenses/LICENSE-2.0
  43255. *
  43256. * Unless required by applicable law or agreed to in writing,
  43257. * software distributed under the License is distributed on an
  43258. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43259. * KIND, either express or implied. See the License for the
  43260. * specific language governing permissions and limitations
  43261. * under the License.
  43262. */
  43263. // FIXME Where to create the simple view coordinate system
  43264. function getViewRect$2(seriesModel, api, aspect) {
  43265. var option = seriesModel.getBoxLayoutParams();
  43266. option.aspect = aspect;
  43267. return getLayoutRect(option, {
  43268. width: api.getWidth(),
  43269. height: api.getHeight()
  43270. });
  43271. }
  43272. var createView = function (ecModel, api) {
  43273. var viewList = [];
  43274. ecModel.eachSeriesByType('graph', function (seriesModel) {
  43275. var coordSysType = seriesModel.get('coordinateSystem');
  43276. if (!coordSysType || coordSysType === 'view') {
  43277. var data = seriesModel.getData();
  43278. var positions = data.mapArray(function (idx) {
  43279. var itemModel = data.getItemModel(idx);
  43280. return [+itemModel.get('x'), +itemModel.get('y')];
  43281. });
  43282. var min = [];
  43283. var max = [];
  43284. fromPoints(positions, min, max); // If width or height is 0
  43285. if (max[0] - min[0] === 0) {
  43286. max[0] += 1;
  43287. min[0] -= 1;
  43288. }
  43289. if (max[1] - min[1] === 0) {
  43290. max[1] += 1;
  43291. min[1] -= 1;
  43292. }
  43293. var aspect = (max[0] - min[0]) / (max[1] - min[1]); // FIXME If get view rect after data processed?
  43294. var viewRect = getViewRect$2(seriesModel, api, aspect); // Position may be NaN, use view rect instead
  43295. if (isNaN(aspect)) {
  43296. min = [viewRect.x, viewRect.y];
  43297. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  43298. }
  43299. var bbWidth = max[0] - min[0];
  43300. var bbHeight = max[1] - min[1];
  43301. var viewWidth = viewRect.width;
  43302. var viewHeight = viewRect.height;
  43303. var viewCoordSys = seriesModel.coordinateSystem = new View();
  43304. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  43305. viewCoordSys.setBoundingRect(min[0], min[1], bbWidth, bbHeight);
  43306. viewCoordSys.setViewRect(viewRect.x, viewRect.y, viewWidth, viewHeight); // Update roam info
  43307. viewCoordSys.setCenter(seriesModel.get('center'));
  43308. viewCoordSys.setZoom(seriesModel.get('zoom'));
  43309. viewList.push(viewCoordSys);
  43310. }
  43311. });
  43312. return viewList;
  43313. };
  43314. /*
  43315. * Licensed to the Apache Software Foundation (ASF) under one
  43316. * or more contributor license agreements. See the NOTICE file
  43317. * distributed with this work for additional information
  43318. * regarding copyright ownership. The ASF licenses this file
  43319. * to you under the Apache License, Version 2.0 (the
  43320. * "License"); you may not use this file except in compliance
  43321. * with the License. You may obtain a copy of the License at
  43322. *
  43323. * http://www.apache.org/licenses/LICENSE-2.0
  43324. *
  43325. * Unless required by applicable law or agreed to in writing,
  43326. * software distributed under the License is distributed on an
  43327. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43328. * KIND, either express or implied. See the License for the
  43329. * specific language governing permissions and limitations
  43330. * under the License.
  43331. */
  43332. registerProcessor(categoryFilter);
  43333. registerVisual(visualSymbol('graph', 'circle', null));
  43334. registerVisual(categoryVisual);
  43335. registerVisual(edgeVisual);
  43336. registerLayout(simpleLayout);
  43337. registerLayout(PRIORITY.VISUAL.POST_CHART_LAYOUT, circularLayout);
  43338. registerLayout(forceLayout); // Graph view coordinate system
  43339. registerCoordinateSystem('graphView', {
  43340. create: createView
  43341. });
  43342. /*
  43343. * Licensed to the Apache Software Foundation (ASF) under one
  43344. * or more contributor license agreements. See the NOTICE file
  43345. * distributed with this work for additional information
  43346. * regarding copyright ownership. The ASF licenses this file
  43347. * to you under the Apache License, Version 2.0 (the
  43348. * "License"); you may not use this file except in compliance
  43349. * with the License. You may obtain a copy of the License at
  43350. *
  43351. * http://www.apache.org/licenses/LICENSE-2.0
  43352. *
  43353. * Unless required by applicable law or agreed to in writing,
  43354. * software distributed under the License is distributed on an
  43355. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43356. * KIND, either express or implied. See the License for the
  43357. * specific language governing permissions and limitations
  43358. * under the License.
  43359. */
  43360. var PictorialBarSeries = BaseBarSeries.extend({
  43361. type: 'series.pictorialBar',
  43362. dependencies: ['grid'],
  43363. defaultOption: {
  43364. symbol: 'circle',
  43365. // Customized bar shape
  43366. symbolSize: null,
  43367. // Can be ['100%', '100%'], null means auto.
  43368. symbolRotate: null,
  43369. symbolPosition: null,
  43370. // 'start' or 'end' or 'center', null means auto.
  43371. symbolOffset: null,
  43372. symbolMargin: null,
  43373. // start margin and end margin. Can be a number or a percent string.
  43374. // Auto margin by defualt.
  43375. symbolRepeat: false,
  43376. // false/null/undefined, means no repeat.
  43377. // Can be true, means auto calculate repeat times and cut by data.
  43378. // Can be a number, specifies repeat times, and do not cut by data.
  43379. // Can be 'fixed', means auto calculate repeat times but do not cut by data.
  43380. symbolRepeatDirection: 'end',
  43381. // 'end' means from 'start' to 'end'.
  43382. symbolClip: false,
  43383. symbolBoundingData: null,
  43384. // Can be 60 or -40 or [-40, 60]
  43385. symbolPatternSize: 400,
  43386. // 400 * 400 px
  43387. barGap: '-100%',
  43388. // In most case, overlap is needed.
  43389. // z can be set in data item, which is z2 actually.
  43390. // Disable progressive
  43391. progressive: 0,
  43392. hoverAnimation: false // Open only when needed.
  43393. },
  43394. getInitialData: function (option) {
  43395. // Disable stack.
  43396. option.stack = null;
  43397. return PictorialBarSeries.superApply(this, 'getInitialData', arguments);
  43398. }
  43399. });
  43400. /*
  43401. * Licensed to the Apache Software Foundation (ASF) under one
  43402. * or more contributor license agreements. See the NOTICE file
  43403. * distributed with this work for additional information
  43404. * regarding copyright ownership. The ASF licenses this file
  43405. * to you under the Apache License, Version 2.0 (the
  43406. * "License"); you may not use this file except in compliance
  43407. * with the License. You may obtain a copy of the License at
  43408. *
  43409. * http://www.apache.org/licenses/LICENSE-2.0
  43410. *
  43411. * Unless required by applicable law or agreed to in writing,
  43412. * software distributed under the License is distributed on an
  43413. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43414. * KIND, either express or implied. See the License for the
  43415. * specific language governing permissions and limitations
  43416. * under the License.
  43417. */
  43418. var BAR_BORDER_WIDTH_QUERY$1 = ['itemStyle', 'borderWidth']; // index: +isHorizontal
  43419. var LAYOUT_ATTRS = [{
  43420. xy: 'x',
  43421. wh: 'width',
  43422. index: 0,
  43423. posDesc: ['left', 'right']
  43424. }, {
  43425. xy: 'y',
  43426. wh: 'height',
  43427. index: 1,
  43428. posDesc: ['top', 'bottom']
  43429. }];
  43430. var pathForLineWidth = new Circle();
  43431. var BarView$1 = extendChartView({
  43432. type: 'pictorialBar',
  43433. render: function (seriesModel, ecModel, api) {
  43434. var group = this.group;
  43435. var data = seriesModel.getData();
  43436. var oldData = this._data;
  43437. var cartesian = seriesModel.coordinateSystem;
  43438. var baseAxis = cartesian.getBaseAxis();
  43439. var isHorizontal = !!baseAxis.isHorizontal();
  43440. var coordSysRect = cartesian.grid.getRect();
  43441. var opt = {
  43442. ecSize: {
  43443. width: api.getWidth(),
  43444. height: api.getHeight()
  43445. },
  43446. seriesModel: seriesModel,
  43447. coordSys: cartesian,
  43448. coordSysExtent: [[coordSysRect.x, coordSysRect.x + coordSysRect.width], [coordSysRect.y, coordSysRect.y + coordSysRect.height]],
  43449. isHorizontal: isHorizontal,
  43450. valueDim: LAYOUT_ATTRS[+isHorizontal],
  43451. categoryDim: LAYOUT_ATTRS[1 - isHorizontal]
  43452. };
  43453. data.diff(oldData).add(function (dataIndex) {
  43454. if (!data.hasValue(dataIndex)) {
  43455. return;
  43456. }
  43457. var itemModel = getItemModel(data, dataIndex);
  43458. var symbolMeta = getSymbolMeta(data, dataIndex, itemModel, opt);
  43459. var bar = createBar(data, opt, symbolMeta);
  43460. data.setItemGraphicEl(dataIndex, bar);
  43461. group.add(bar);
  43462. updateCommon(bar, opt, symbolMeta);
  43463. }).update(function (newIndex, oldIndex) {
  43464. var bar = oldData.getItemGraphicEl(oldIndex);
  43465. if (!data.hasValue(newIndex)) {
  43466. group.remove(bar);
  43467. return;
  43468. }
  43469. var itemModel = getItemModel(data, newIndex);
  43470. var symbolMeta = getSymbolMeta(data, newIndex, itemModel, opt);
  43471. var pictorialShapeStr = getShapeStr(data, symbolMeta);
  43472. if (bar && pictorialShapeStr !== bar.__pictorialShapeStr) {
  43473. group.remove(bar);
  43474. data.setItemGraphicEl(newIndex, null);
  43475. bar = null;
  43476. }
  43477. if (bar) {
  43478. updateBar(bar, opt, symbolMeta);
  43479. } else {
  43480. bar = createBar(data, opt, symbolMeta, true);
  43481. }
  43482. data.setItemGraphicEl(newIndex, bar);
  43483. bar.__pictorialSymbolMeta = symbolMeta; // Add back
  43484. group.add(bar);
  43485. updateCommon(bar, opt, symbolMeta);
  43486. }).remove(function (dataIndex) {
  43487. var bar = oldData.getItemGraphicEl(dataIndex);
  43488. bar && removeBar(oldData, dataIndex, bar.__pictorialSymbolMeta.animationModel, bar);
  43489. }).execute();
  43490. this._data = data;
  43491. return this.group;
  43492. },
  43493. dispose: noop,
  43494. remove: function (ecModel, api) {
  43495. var group = this.group;
  43496. var data = this._data;
  43497. if (ecModel.get('animation')) {
  43498. if (data) {
  43499. data.eachItemGraphicEl(function (bar) {
  43500. removeBar(data, bar.dataIndex, ecModel, bar);
  43501. });
  43502. }
  43503. } else {
  43504. group.removeAll();
  43505. }
  43506. }
  43507. }); // Set or calculate default value about symbol, and calculate layout info.
  43508. function getSymbolMeta(data, dataIndex, itemModel, opt) {
  43509. var layout = data.getItemLayout(dataIndex);
  43510. var symbolRepeat = itemModel.get('symbolRepeat');
  43511. var symbolClip = itemModel.get('symbolClip');
  43512. var symbolPosition = itemModel.get('symbolPosition') || 'start';
  43513. var symbolRotate = itemModel.get('symbolRotate');
  43514. var rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  43515. var symbolPatternSize = itemModel.get('symbolPatternSize') || 2;
  43516. var isAnimationEnabled = itemModel.isAnimationEnabled();
  43517. var symbolMeta = {
  43518. dataIndex: dataIndex,
  43519. layout: layout,
  43520. itemModel: itemModel,
  43521. symbolType: data.getItemVisual(dataIndex, 'symbol') || 'circle',
  43522. color: data.getItemVisual(dataIndex, 'color'),
  43523. symbolClip: symbolClip,
  43524. symbolRepeat: symbolRepeat,
  43525. symbolRepeatDirection: itemModel.get('symbolRepeatDirection'),
  43526. symbolPatternSize: symbolPatternSize,
  43527. rotation: rotation,
  43528. animationModel: isAnimationEnabled ? itemModel : null,
  43529. hoverAnimation: isAnimationEnabled && itemModel.get('hoverAnimation'),
  43530. z2: itemModel.getShallow('z', true) || 0
  43531. };
  43532. prepareBarLength(itemModel, symbolRepeat, layout, opt, symbolMeta);
  43533. prepareSymbolSize(data, dataIndex, layout, symbolRepeat, symbolClip, symbolMeta.boundingLength, symbolMeta.pxSign, symbolPatternSize, opt, symbolMeta);
  43534. prepareLineWidth(itemModel, symbolMeta.symbolScale, rotation, opt, symbolMeta);
  43535. var symbolSize = symbolMeta.symbolSize;
  43536. var symbolOffset = itemModel.get('symbolOffset');
  43537. if (isArray(symbolOffset)) {
  43538. symbolOffset = [parsePercent$1(symbolOffset[0], symbolSize[0]), parsePercent$1(symbolOffset[1], symbolSize[1])];
  43539. }
  43540. prepareLayoutInfo(itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset, symbolPosition, symbolMeta.valueLineWidth, symbolMeta.boundingLength, symbolMeta.repeatCutLength, opt, symbolMeta);
  43541. return symbolMeta;
  43542. } // bar length can be negative.
  43543. function prepareBarLength(itemModel, symbolRepeat, layout, opt, output) {
  43544. var valueDim = opt.valueDim;
  43545. var symbolBoundingData = itemModel.get('symbolBoundingData');
  43546. var valueAxis = opt.coordSys.getOtherAxis(opt.coordSys.getBaseAxis());
  43547. var zeroPx = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
  43548. var pxSignIdx = 1 - +(layout[valueDim.wh] <= 0);
  43549. var boundingLength;
  43550. if (isArray(symbolBoundingData)) {
  43551. var symbolBoundingExtent = [convertToCoordOnAxis(valueAxis, symbolBoundingData[0]) - zeroPx, convertToCoordOnAxis(valueAxis, symbolBoundingData[1]) - zeroPx];
  43552. symbolBoundingExtent[1] < symbolBoundingExtent[0] && symbolBoundingExtent.reverse();
  43553. boundingLength = symbolBoundingExtent[pxSignIdx];
  43554. } else if (symbolBoundingData != null) {
  43555. boundingLength = convertToCoordOnAxis(valueAxis, symbolBoundingData) - zeroPx;
  43556. } else if (symbolRepeat) {
  43557. boundingLength = opt.coordSysExtent[valueDim.index][pxSignIdx] - zeroPx;
  43558. } else {
  43559. boundingLength = layout[valueDim.wh];
  43560. }
  43561. output.boundingLength = boundingLength;
  43562. if (symbolRepeat) {
  43563. output.repeatCutLength = layout[valueDim.wh];
  43564. }
  43565. output.pxSign = boundingLength > 0 ? 1 : boundingLength < 0 ? -1 : 0;
  43566. }
  43567. function convertToCoordOnAxis(axis, value) {
  43568. return axis.toGlobalCoord(axis.dataToCoord(axis.scale.parse(value)));
  43569. } // Support ['100%', '100%']
  43570. function prepareSymbolSize(data, dataIndex, layout, symbolRepeat, symbolClip, boundingLength, pxSign, symbolPatternSize, opt, output) {
  43571. var valueDim = opt.valueDim;
  43572. var categoryDim = opt.categoryDim;
  43573. var categorySize = Math.abs(layout[categoryDim.wh]);
  43574. var symbolSize = data.getItemVisual(dataIndex, 'symbolSize');
  43575. if (isArray(symbolSize)) {
  43576. symbolSize = symbolSize.slice();
  43577. } else {
  43578. if (symbolSize == null) {
  43579. symbolSize = '100%';
  43580. }
  43581. symbolSize = [symbolSize, symbolSize];
  43582. } // Note: percentage symbolSize (like '100%') do not consider lineWidth, because it is
  43583. // to complicated to calculate real percent value if considering scaled lineWidth.
  43584. // So the actual size will bigger than layout size if lineWidth is bigger than zero,
  43585. // which can be tolerated in pictorial chart.
  43586. symbolSize[categoryDim.index] = parsePercent$1(symbolSize[categoryDim.index], categorySize);
  43587. symbolSize[valueDim.index] = parsePercent$1(symbolSize[valueDim.index], symbolRepeat ? categorySize : Math.abs(boundingLength));
  43588. output.symbolSize = symbolSize; // If x or y is less than zero, show reversed shape.
  43589. var symbolScale = output.symbolScale = [symbolSize[0] / symbolPatternSize, symbolSize[1] / symbolPatternSize]; // Follow convention, 'right' and 'top' is the normal scale.
  43590. symbolScale[valueDim.index] *= (opt.isHorizontal ? -1 : 1) * pxSign;
  43591. }
  43592. function prepareLineWidth(itemModel, symbolScale, rotation, opt, output) {
  43593. // In symbols are drawn with scale, so do not need to care about the case that width
  43594. // or height are too small. But symbol use strokeNoScale, where acture lineWidth should
  43595. // be calculated.
  43596. var valueLineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY$1) || 0;
  43597. if (valueLineWidth) {
  43598. pathForLineWidth.attr({
  43599. scale: symbolScale.slice(),
  43600. rotation: rotation
  43601. });
  43602. pathForLineWidth.updateTransform();
  43603. valueLineWidth /= pathForLineWidth.getLineScale();
  43604. valueLineWidth *= symbolScale[opt.valueDim.index];
  43605. }
  43606. output.valueLineWidth = valueLineWidth;
  43607. }
  43608. function prepareLayoutInfo(itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset, symbolPosition, valueLineWidth, boundingLength, repeatCutLength, opt, output) {
  43609. var categoryDim = opt.categoryDim;
  43610. var valueDim = opt.valueDim;
  43611. var pxSign = output.pxSign;
  43612. var unitLength = Math.max(symbolSize[valueDim.index] + valueLineWidth, 0);
  43613. var pathLen = unitLength; // Note: rotation will not effect the layout of symbols, because user may
  43614. // want symbols to rotate on its center, which should not be translated
  43615. // when rotating.
  43616. if (symbolRepeat) {
  43617. var absBoundingLength = Math.abs(boundingLength);
  43618. var symbolMargin = retrieve(itemModel.get('symbolMargin'), '15%') + '';
  43619. var hasEndGap = false;
  43620. if (symbolMargin.lastIndexOf('!') === symbolMargin.length - 1) {
  43621. hasEndGap = true;
  43622. symbolMargin = symbolMargin.slice(0, symbolMargin.length - 1);
  43623. }
  43624. symbolMargin = parsePercent$1(symbolMargin, symbolSize[valueDim.index]);
  43625. var uLenWithMargin = Math.max(unitLength + symbolMargin * 2, 0); // When symbol margin is less than 0, margin at both ends will be subtracted
  43626. // to ensure that all of the symbols will not be overflow the given area.
  43627. var endFix = hasEndGap ? 0 : symbolMargin * 2; // Both final repeatTimes and final symbolMargin area calculated based on
  43628. // boundingLength.
  43629. var repeatSpecified = isNumeric(symbolRepeat);
  43630. var repeatTimes = repeatSpecified ? symbolRepeat : toIntTimes((absBoundingLength + endFix) / uLenWithMargin); // Adjust calculate margin, to ensure each symbol is displayed
  43631. // entirely in the given layout area.
  43632. var mDiff = absBoundingLength - repeatTimes * unitLength;
  43633. symbolMargin = mDiff / 2 / (hasEndGap ? repeatTimes : repeatTimes - 1);
  43634. uLenWithMargin = unitLength + symbolMargin * 2;
  43635. endFix = hasEndGap ? 0 : symbolMargin * 2; // Update repeatTimes when not all symbol will be shown.
  43636. if (!repeatSpecified && symbolRepeat !== 'fixed') {
  43637. repeatTimes = repeatCutLength ? toIntTimes((Math.abs(repeatCutLength) + endFix) / uLenWithMargin) : 0;
  43638. }
  43639. pathLen = repeatTimes * uLenWithMargin - endFix;
  43640. output.repeatTimes = repeatTimes;
  43641. output.symbolMargin = symbolMargin;
  43642. }
  43643. var sizeFix = pxSign * (pathLen / 2);
  43644. var pathPosition = output.pathPosition = [];
  43645. pathPosition[categoryDim.index] = layout[categoryDim.wh] / 2;
  43646. pathPosition[valueDim.index] = symbolPosition === 'start' ? sizeFix : symbolPosition === 'end' ? boundingLength - sizeFix : boundingLength / 2; // 'center'
  43647. if (symbolOffset) {
  43648. pathPosition[0] += symbolOffset[0];
  43649. pathPosition[1] += symbolOffset[1];
  43650. }
  43651. var bundlePosition = output.bundlePosition = [];
  43652. bundlePosition[categoryDim.index] = layout[categoryDim.xy];
  43653. bundlePosition[valueDim.index] = layout[valueDim.xy];
  43654. var barRectShape = output.barRectShape = extend({}, layout);
  43655. barRectShape[valueDim.wh] = pxSign * Math.max(Math.abs(layout[valueDim.wh]), Math.abs(pathPosition[valueDim.index] + sizeFix));
  43656. barRectShape[categoryDim.wh] = layout[categoryDim.wh];
  43657. var clipShape = output.clipShape = {}; // Consider that symbol may be overflow layout rect.
  43658. clipShape[categoryDim.xy] = -layout[categoryDim.xy];
  43659. clipShape[categoryDim.wh] = opt.ecSize[categoryDim.wh];
  43660. clipShape[valueDim.xy] = 0;
  43661. clipShape[valueDim.wh] = layout[valueDim.wh];
  43662. }
  43663. function createPath(symbolMeta) {
  43664. var symbolPatternSize = symbolMeta.symbolPatternSize;
  43665. var path = createSymbol( // Consider texture img, make a big size.
  43666. symbolMeta.symbolType, -symbolPatternSize / 2, -symbolPatternSize / 2, symbolPatternSize, symbolPatternSize, symbolMeta.color);
  43667. path.attr({
  43668. culling: true
  43669. });
  43670. path.type !== 'image' && path.setStyle({
  43671. strokeNoScale: true
  43672. });
  43673. return path;
  43674. }
  43675. function createOrUpdateRepeatSymbols(bar, opt, symbolMeta, isUpdate) {
  43676. var bundle = bar.__pictorialBundle;
  43677. var symbolSize = symbolMeta.symbolSize;
  43678. var valueLineWidth = symbolMeta.valueLineWidth;
  43679. var pathPosition = symbolMeta.pathPosition;
  43680. var valueDim = opt.valueDim;
  43681. var repeatTimes = symbolMeta.repeatTimes || 0;
  43682. var index = 0;
  43683. var unit = symbolSize[opt.valueDim.index] + valueLineWidth + symbolMeta.symbolMargin * 2;
  43684. eachPath(bar, function (path) {
  43685. path.__pictorialAnimationIndex = index;
  43686. path.__pictorialRepeatTimes = repeatTimes;
  43687. if (index < repeatTimes) {
  43688. updateAttr(path, null, makeTarget(index), symbolMeta, isUpdate);
  43689. } else {
  43690. updateAttr(path, null, {
  43691. scale: [0, 0]
  43692. }, symbolMeta, isUpdate, function () {
  43693. bundle.remove(path);
  43694. });
  43695. }
  43696. updateHoverAnimation(path, symbolMeta);
  43697. index++;
  43698. });
  43699. for (; index < repeatTimes; index++) {
  43700. var path = createPath(symbolMeta);
  43701. path.__pictorialAnimationIndex = index;
  43702. path.__pictorialRepeatTimes = repeatTimes;
  43703. bundle.add(path);
  43704. var target = makeTarget(index);
  43705. updateAttr(path, {
  43706. position: target.position,
  43707. scale: [0, 0]
  43708. }, {
  43709. scale: target.scale,
  43710. rotation: target.rotation
  43711. }, symbolMeta, isUpdate); // FIXME
  43712. // If all emphasis/normal through action.
  43713. path.on('mouseover', onMouseOver).on('mouseout', onMouseOut);
  43714. updateHoverAnimation(path, symbolMeta);
  43715. }
  43716. function makeTarget(index) {
  43717. var position = pathPosition.slice(); // (start && pxSign > 0) || (end && pxSign < 0): i = repeatTimes - index
  43718. // Otherwise: i = index;
  43719. var pxSign = symbolMeta.pxSign;
  43720. var i = index;
  43721. if (symbolMeta.symbolRepeatDirection === 'start' ? pxSign > 0 : pxSign < 0) {
  43722. i = repeatTimes - 1 - index;
  43723. }
  43724. position[valueDim.index] = unit * (i - repeatTimes / 2 + 0.5) + pathPosition[valueDim.index];
  43725. return {
  43726. position: position,
  43727. scale: symbolMeta.symbolScale.slice(),
  43728. rotation: symbolMeta.rotation
  43729. };
  43730. }
  43731. function onMouseOver() {
  43732. eachPath(bar, function (path) {
  43733. path.trigger('emphasis');
  43734. });
  43735. }
  43736. function onMouseOut() {
  43737. eachPath(bar, function (path) {
  43738. path.trigger('normal');
  43739. });
  43740. }
  43741. }
  43742. function createOrUpdateSingleSymbol(bar, opt, symbolMeta, isUpdate) {
  43743. var bundle = bar.__pictorialBundle;
  43744. var mainPath = bar.__pictorialMainPath;
  43745. if (!mainPath) {
  43746. mainPath = bar.__pictorialMainPath = createPath(symbolMeta);
  43747. bundle.add(mainPath);
  43748. updateAttr(mainPath, {
  43749. position: symbolMeta.pathPosition.slice(),
  43750. scale: [0, 0],
  43751. rotation: symbolMeta.rotation
  43752. }, {
  43753. scale: symbolMeta.symbolScale.slice()
  43754. }, symbolMeta, isUpdate);
  43755. mainPath.on('mouseover', onMouseOver).on('mouseout', onMouseOut);
  43756. } else {
  43757. updateAttr(mainPath, null, {
  43758. position: symbolMeta.pathPosition.slice(),
  43759. scale: symbolMeta.symbolScale.slice(),
  43760. rotation: symbolMeta.rotation
  43761. }, symbolMeta, isUpdate);
  43762. }
  43763. updateHoverAnimation(mainPath, symbolMeta);
  43764. function onMouseOver() {
  43765. this.trigger('emphasis');
  43766. }
  43767. function onMouseOut() {
  43768. this.trigger('normal');
  43769. }
  43770. } // bar rect is used for label.
  43771. function createOrUpdateBarRect(bar, symbolMeta, isUpdate) {
  43772. var rectShape = extend({}, symbolMeta.barRectShape);
  43773. var barRect = bar.__pictorialBarRect;
  43774. if (!barRect) {
  43775. barRect = bar.__pictorialBarRect = new Rect({
  43776. z2: 2,
  43777. shape: rectShape,
  43778. silent: true,
  43779. style: {
  43780. stroke: 'transparent',
  43781. fill: 'transparent',
  43782. lineWidth: 0
  43783. }
  43784. });
  43785. bar.add(barRect);
  43786. } else {
  43787. updateAttr(barRect, null, {
  43788. shape: rectShape
  43789. }, symbolMeta, isUpdate);
  43790. }
  43791. }
  43792. function createOrUpdateClip(bar, opt, symbolMeta, isUpdate) {
  43793. // If not clip, symbol will be remove and rebuilt.
  43794. if (symbolMeta.symbolClip) {
  43795. var clipPath = bar.__pictorialClipPath;
  43796. var clipShape = extend({}, symbolMeta.clipShape);
  43797. var valueDim = opt.valueDim;
  43798. var animationModel = symbolMeta.animationModel;
  43799. var dataIndex = symbolMeta.dataIndex;
  43800. if (clipPath) {
  43801. updateProps(clipPath, {
  43802. shape: clipShape
  43803. }, animationModel, dataIndex);
  43804. } else {
  43805. clipShape[valueDim.wh] = 0;
  43806. clipPath = new Rect({
  43807. shape: clipShape
  43808. });
  43809. bar.__pictorialBundle.setClipPath(clipPath);
  43810. bar.__pictorialClipPath = clipPath;
  43811. var target = {};
  43812. target[valueDim.wh] = symbolMeta.clipShape[valueDim.wh];
  43813. graphic[isUpdate ? 'updateProps' : 'initProps'](clipPath, {
  43814. shape: target
  43815. }, animationModel, dataIndex);
  43816. }
  43817. }
  43818. }
  43819. function getItemModel(data, dataIndex) {
  43820. var itemModel = data.getItemModel(dataIndex);
  43821. itemModel.getAnimationDelayParams = getAnimationDelayParams;
  43822. itemModel.isAnimationEnabled = isAnimationEnabled;
  43823. return itemModel;
  43824. }
  43825. function getAnimationDelayParams(path) {
  43826. // The order is the same as the z-order, see `symbolRepeatDiretion`.
  43827. return {
  43828. index: path.__pictorialAnimationIndex,
  43829. count: path.__pictorialRepeatTimes
  43830. };
  43831. }
  43832. function isAnimationEnabled() {
  43833. // `animation` prop can be set on itemModel in pictorial bar chart.
  43834. return this.parentModel.isAnimationEnabled() && !!this.getShallow('animation');
  43835. }
  43836. function updateHoverAnimation(path, symbolMeta) {
  43837. path.off('emphasis').off('normal');
  43838. var scale = symbolMeta.symbolScale.slice();
  43839. symbolMeta.hoverAnimation && path.on('emphasis', function () {
  43840. this.animateTo({
  43841. scale: [scale[0] * 1.1, scale[1] * 1.1]
  43842. }, 400, 'elasticOut');
  43843. }).on('normal', function () {
  43844. this.animateTo({
  43845. scale: scale.slice()
  43846. }, 400, 'elasticOut');
  43847. });
  43848. }
  43849. function createBar(data, opt, symbolMeta, isUpdate) {
  43850. // bar is the main element for each data.
  43851. var bar = new Group(); // bundle is used for location and clip.
  43852. var bundle = new Group();
  43853. bar.add(bundle);
  43854. bar.__pictorialBundle = bundle;
  43855. bundle.attr('position', symbolMeta.bundlePosition.slice());
  43856. if (symbolMeta.symbolRepeat) {
  43857. createOrUpdateRepeatSymbols(bar, opt, symbolMeta);
  43858. } else {
  43859. createOrUpdateSingleSymbol(bar, opt, symbolMeta);
  43860. }
  43861. createOrUpdateBarRect(bar, symbolMeta, isUpdate);
  43862. createOrUpdateClip(bar, opt, symbolMeta, isUpdate);
  43863. bar.__pictorialShapeStr = getShapeStr(data, symbolMeta);
  43864. bar.__pictorialSymbolMeta = symbolMeta;
  43865. return bar;
  43866. }
  43867. function updateBar(bar, opt, symbolMeta) {
  43868. var animationModel = symbolMeta.animationModel;
  43869. var dataIndex = symbolMeta.dataIndex;
  43870. var bundle = bar.__pictorialBundle;
  43871. updateProps(bundle, {
  43872. position: symbolMeta.bundlePosition.slice()
  43873. }, animationModel, dataIndex);
  43874. if (symbolMeta.symbolRepeat) {
  43875. createOrUpdateRepeatSymbols(bar, opt, symbolMeta, true);
  43876. } else {
  43877. createOrUpdateSingleSymbol(bar, opt, symbolMeta, true);
  43878. }
  43879. createOrUpdateBarRect(bar, symbolMeta, true);
  43880. createOrUpdateClip(bar, opt, symbolMeta, true);
  43881. }
  43882. function removeBar(data, dataIndex, animationModel, bar) {
  43883. // Not show text when animating
  43884. var labelRect = bar.__pictorialBarRect;
  43885. labelRect && (labelRect.style.text = null);
  43886. var pathes = [];
  43887. eachPath(bar, function (path) {
  43888. pathes.push(path);
  43889. });
  43890. bar.__pictorialMainPath && pathes.push(bar.__pictorialMainPath); // I do not find proper remove animation for clip yet.
  43891. bar.__pictorialClipPath && (animationModel = null);
  43892. each$1(pathes, function (path) {
  43893. updateProps(path, {
  43894. scale: [0, 0]
  43895. }, animationModel, dataIndex, function () {
  43896. bar.parent && bar.parent.remove(bar);
  43897. });
  43898. });
  43899. data.setItemGraphicEl(dataIndex, null);
  43900. }
  43901. function getShapeStr(data, symbolMeta) {
  43902. return [data.getItemVisual(symbolMeta.dataIndex, 'symbol') || 'none', !!symbolMeta.symbolRepeat, !!symbolMeta.symbolClip].join(':');
  43903. }
  43904. function eachPath(bar, cb, context) {
  43905. // Do not use Group#eachChild, because it do not support remove.
  43906. each$1(bar.__pictorialBundle.children(), function (el) {
  43907. el !== bar.__pictorialBarRect && cb.call(context, el);
  43908. });
  43909. }
  43910. function updateAttr(el, immediateAttrs, animationAttrs, symbolMeta, isUpdate, cb) {
  43911. immediateAttrs && el.attr(immediateAttrs); // when symbolCip used, only clip path has init animation, otherwise it would be weird effect.
  43912. if (symbolMeta.symbolClip && !isUpdate) {
  43913. animationAttrs && el.attr(animationAttrs);
  43914. } else {
  43915. animationAttrs && graphic[isUpdate ? 'updateProps' : 'initProps'](el, animationAttrs, symbolMeta.animationModel, symbolMeta.dataIndex, cb);
  43916. }
  43917. }
  43918. function updateCommon(bar, opt, symbolMeta) {
  43919. var color = symbolMeta.color;
  43920. var dataIndex = symbolMeta.dataIndex;
  43921. var itemModel = symbolMeta.itemModel; // Color must be excluded.
  43922. // Because symbol provide setColor individually to set fill and stroke
  43923. var normalStyle = itemModel.getModel('itemStyle').getItemStyle(['color']);
  43924. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  43925. var cursorStyle = itemModel.getShallow('cursor');
  43926. eachPath(bar, function (path) {
  43927. // PENDING setColor should be before setStyle!!!
  43928. path.setColor(color);
  43929. path.setStyle(defaults({
  43930. fill: color,
  43931. opacity: symbolMeta.opacity
  43932. }, normalStyle));
  43933. setHoverStyle(path, hoverStyle);
  43934. cursorStyle && (path.cursor = cursorStyle);
  43935. path.z2 = symbolMeta.z2;
  43936. });
  43937. var barRectHoverStyle = {};
  43938. var barPositionOutside = opt.valueDim.posDesc[+(symbolMeta.boundingLength > 0)];
  43939. var barRect = bar.__pictorialBarRect;
  43940. setLabel(barRect.style, barRectHoverStyle, itemModel, color, opt.seriesModel, dataIndex, barPositionOutside);
  43941. setHoverStyle(barRect, barRectHoverStyle);
  43942. }
  43943. function toIntTimes(times) {
  43944. var roundedTimes = Math.round(times); // Escapse accurate error
  43945. return Math.abs(times - roundedTimes) < 1e-4 ? roundedTimes : Math.ceil(times);
  43946. }
  43947. /*
  43948. * Licensed to the Apache Software Foundation (ASF) under one
  43949. * or more contributor license agreements. See the NOTICE file
  43950. * distributed with this work for additional information
  43951. * regarding copyright ownership. The ASF licenses this file
  43952. * to you under the Apache License, Version 2.0 (the
  43953. * "License"); you may not use this file except in compliance
  43954. * with the License. You may obtain a copy of the License at
  43955. *
  43956. * http://www.apache.org/licenses/LICENSE-2.0
  43957. *
  43958. * Unless required by applicable law or agreed to in writing,
  43959. * software distributed under the License is distributed on an
  43960. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43961. * KIND, either express or implied. See the License for the
  43962. * specific language governing permissions and limitations
  43963. * under the License.
  43964. */
  43965. registerLayout(curry(layout, 'pictorialBar'));
  43966. registerVisual(visualSymbol('pictorialBar', 'roundRect'));
  43967. /*
  43968. * Licensed to the Apache Software Foundation (ASF) under one
  43969. * or more contributor license agreements. See the NOTICE file
  43970. * distributed with this work for additional information
  43971. * regarding copyright ownership. The ASF licenses this file
  43972. * to you under the Apache License, Version 2.0 (the
  43973. * "License"); you may not use this file except in compliance
  43974. * with the License. You may obtain a copy of the License at
  43975. *
  43976. * http://www.apache.org/licenses/LICENSE-2.0
  43977. *
  43978. * Unless required by applicable law or agreed to in writing,
  43979. * software distributed under the License is distributed on an
  43980. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43981. * KIND, either express or implied. See the License for the
  43982. * specific language governing permissions and limitations
  43983. * under the License.
  43984. */
  43985. function dataToCoordSize(dataSize, dataItem) {
  43986. // dataItem is necessary in log axis.
  43987. dataItem = dataItem || [0, 0];
  43988. return map(['x', 'y'], function (dim, dimIdx) {
  43989. var axis = this.getAxis(dim);
  43990. var val = dataItem[dimIdx];
  43991. var halfSize = dataSize[dimIdx] / 2;
  43992. return axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  43993. }, this);
  43994. }
  43995. var prepareCartesian2d = function (coordSys) {
  43996. var rect = coordSys.grid.getRect();
  43997. return {
  43998. coordSys: {
  43999. // The name exposed to user is always 'cartesian2d' but not 'grid'.
  44000. type: 'cartesian2d',
  44001. x: rect.x,
  44002. y: rect.y,
  44003. width: rect.width,
  44004. height: rect.height
  44005. },
  44006. api: {
  44007. coord: function (data) {
  44008. // do not provide "out" param
  44009. return coordSys.dataToPoint(data);
  44010. },
  44011. size: bind(dataToCoordSize, coordSys)
  44012. }
  44013. };
  44014. };
  44015. /*
  44016. * Licensed to the Apache Software Foundation (ASF) under one
  44017. * or more contributor license agreements. See the NOTICE file
  44018. * distributed with this work for additional information
  44019. * regarding copyright ownership. The ASF licenses this file
  44020. * to you under the Apache License, Version 2.0 (the
  44021. * "License"); you may not use this file except in compliance
  44022. * with the License. You may obtain a copy of the License at
  44023. *
  44024. * http://www.apache.org/licenses/LICENSE-2.0
  44025. *
  44026. * Unless required by applicable law or agreed to in writing,
  44027. * software distributed under the License is distributed on an
  44028. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44029. * KIND, either express or implied. See the License for the
  44030. * specific language governing permissions and limitations
  44031. * under the License.
  44032. */
  44033. function dataToCoordSize$1(dataSize, dataItem) {
  44034. dataItem = dataItem || [0, 0];
  44035. return map([0, 1], function (dimIdx) {
  44036. var val = dataItem[dimIdx];
  44037. var halfSize = dataSize[dimIdx] / 2;
  44038. var p1 = [];
  44039. var p2 = [];
  44040. p1[dimIdx] = val - halfSize;
  44041. p2[dimIdx] = val + halfSize;
  44042. p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx];
  44043. return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx]);
  44044. }, this);
  44045. }
  44046. var prepareGeo = function (coordSys) {
  44047. var rect = coordSys.getBoundingRect();
  44048. return {
  44049. coordSys: {
  44050. type: 'geo',
  44051. x: rect.x,
  44052. y: rect.y,
  44053. width: rect.width,
  44054. height: rect.height,
  44055. zoom: coordSys.getZoom()
  44056. },
  44057. api: {
  44058. coord: function (data) {
  44059. // do not provide "out" and noRoam param,
  44060. // Compatible with this usage:
  44061. // echarts.util.map(item.points, api.coord)
  44062. return coordSys.dataToPoint(data);
  44063. },
  44064. size: bind(dataToCoordSize$1, coordSys)
  44065. }
  44066. };
  44067. };
  44068. /*
  44069. * Licensed to the Apache Software Foundation (ASF) under one
  44070. * or more contributor license agreements. See the NOTICE file
  44071. * distributed with this work for additional information
  44072. * regarding copyright ownership. The ASF licenses this file
  44073. * to you under the Apache License, Version 2.0 (the
  44074. * "License"); you may not use this file except in compliance
  44075. * with the License. You may obtain a copy of the License at
  44076. *
  44077. * http://www.apache.org/licenses/LICENSE-2.0
  44078. *
  44079. * Unless required by applicable law or agreed to in writing,
  44080. * software distributed under the License is distributed on an
  44081. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44082. * KIND, either express or implied. See the License for the
  44083. * specific language governing permissions and limitations
  44084. * under the License.
  44085. */
  44086. function dataToCoordSize$2(dataSize, dataItem) {
  44087. // dataItem is necessary in log axis.
  44088. var axis = this.getAxis();
  44089. var val = dataItem instanceof Array ? dataItem[0] : dataItem;
  44090. var halfSize = (dataSize instanceof Array ? dataSize[0] : dataSize) / 2;
  44091. return axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  44092. }
  44093. var prepareSingleAxis = function (coordSys) {
  44094. var rect = coordSys.getRect();
  44095. return {
  44096. coordSys: {
  44097. type: 'singleAxis',
  44098. x: rect.x,
  44099. y: rect.y,
  44100. width: rect.width,
  44101. height: rect.height
  44102. },
  44103. api: {
  44104. coord: function (val) {
  44105. // do not provide "out" param
  44106. return coordSys.dataToPoint(val);
  44107. },
  44108. size: bind(dataToCoordSize$2, coordSys)
  44109. }
  44110. };
  44111. };
  44112. /*
  44113. * Licensed to the Apache Software Foundation (ASF) under one
  44114. * or more contributor license agreements. See the NOTICE file
  44115. * distributed with this work for additional information
  44116. * regarding copyright ownership. The ASF licenses this file
  44117. * to you under the Apache License, Version 2.0 (the
  44118. * "License"); you may not use this file except in compliance
  44119. * with the License. You may obtain a copy of the License at
  44120. *
  44121. * http://www.apache.org/licenses/LICENSE-2.0
  44122. *
  44123. * Unless required by applicable law or agreed to in writing,
  44124. * software distributed under the License is distributed on an
  44125. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44126. * KIND, either express or implied. See the License for the
  44127. * specific language governing permissions and limitations
  44128. * under the License.
  44129. */
  44130. function dataToCoordSize$3(dataSize, dataItem) {
  44131. // dataItem is necessary in log axis.
  44132. return map(['Radius', 'Angle'], function (dim, dimIdx) {
  44133. var axis = this['get' + dim + 'Axis']();
  44134. var val = dataItem[dimIdx];
  44135. var halfSize = dataSize[dimIdx] / 2;
  44136. var method = 'dataTo' + dim;
  44137. var result = axis.type === 'category' ? axis.getBandWidth() : Math.abs(axis[method](val - halfSize) - axis[method](val + halfSize));
  44138. if (dim === 'Angle') {
  44139. result = result * Math.PI / 180;
  44140. }
  44141. return result;
  44142. }, this);
  44143. }
  44144. var preparePolar = function (coordSys) {
  44145. var radiusAxis = coordSys.getRadiusAxis();
  44146. var angleAxis = coordSys.getAngleAxis();
  44147. var radius = radiusAxis.getExtent();
  44148. radius[0] > radius[1] && radius.reverse();
  44149. return {
  44150. coordSys: {
  44151. type: 'polar',
  44152. cx: coordSys.cx,
  44153. cy: coordSys.cy,
  44154. r: radius[1],
  44155. r0: radius[0]
  44156. },
  44157. api: {
  44158. coord: bind(function (data) {
  44159. var radius = radiusAxis.dataToRadius(data[0]);
  44160. var angle = angleAxis.dataToAngle(data[1]);
  44161. var coord = coordSys.coordToPoint([radius, angle]);
  44162. coord.push(radius, angle * Math.PI / 180);
  44163. return coord;
  44164. }),
  44165. size: bind(dataToCoordSize$3, coordSys)
  44166. }
  44167. };
  44168. };
  44169. /*
  44170. * Licensed to the Apache Software Foundation (ASF) under one
  44171. * or more contributor license agreements. See the NOTICE file
  44172. * distributed with this work for additional information
  44173. * regarding copyright ownership. The ASF licenses this file
  44174. * to you under the Apache License, Version 2.0 (the
  44175. * "License"); you may not use this file except in compliance
  44176. * with the License. You may obtain a copy of the License at
  44177. *
  44178. * http://www.apache.org/licenses/LICENSE-2.0
  44179. *
  44180. * Unless required by applicable law or agreed to in writing,
  44181. * software distributed under the License is distributed on an
  44182. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44183. * KIND, either express or implied. See the License for the
  44184. * specific language governing permissions and limitations
  44185. * under the License.
  44186. */
  44187. var prepareCalendar = function (coordSys) {
  44188. var rect = coordSys.getRect();
  44189. var rangeInfo = coordSys.getRangeInfo();
  44190. return {
  44191. coordSys: {
  44192. type: 'calendar',
  44193. x: rect.x,
  44194. y: rect.y,
  44195. width: rect.width,
  44196. height: rect.height,
  44197. cellWidth: coordSys.getCellWidth(),
  44198. cellHeight: coordSys.getCellHeight(),
  44199. rangeInfo: {
  44200. start: rangeInfo.start,
  44201. end: rangeInfo.end,
  44202. weeks: rangeInfo.weeks,
  44203. dayCount: rangeInfo.allDay
  44204. }
  44205. },
  44206. api: {
  44207. coord: function (data, clamp) {
  44208. return coordSys.dataToPoint(data, clamp);
  44209. }
  44210. }
  44211. };
  44212. };
  44213. /*
  44214. * Licensed to the Apache Software Foundation (ASF) under one
  44215. * or more contributor license agreements. See the NOTICE file
  44216. * distributed with this work for additional information
  44217. * regarding copyright ownership. The ASF licenses this file
  44218. * to you under the Apache License, Version 2.0 (the
  44219. * "License"); you may not use this file except in compliance
  44220. * with the License. You may obtain a copy of the License at
  44221. *
  44222. * http://www.apache.org/licenses/LICENSE-2.0
  44223. *
  44224. * Unless required by applicable law or agreed to in writing,
  44225. * software distributed under the License is distributed on an
  44226. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44227. * KIND, either express or implied. See the License for the
  44228. * specific language governing permissions and limitations
  44229. * under the License.
  44230. */
  44231. var CACHED_LABEL_STYLE_PROPERTIES$1 = CACHED_LABEL_STYLE_PROPERTIES;
  44232. var ITEM_STYLE_NORMAL_PATH = ['itemStyle'];
  44233. var ITEM_STYLE_EMPHASIS_PATH = ['emphasis', 'itemStyle'];
  44234. var LABEL_NORMAL = ['label'];
  44235. var LABEL_EMPHASIS = ['emphasis', 'label']; // Use prefix to avoid index to be the same as el.name,
  44236. // which will cause weird udpate animation.
  44237. var GROUP_DIFF_PREFIX = 'e\0\0';
  44238. /**
  44239. * To reduce total package size of each coordinate systems, the modules `prepareCustom`
  44240. * of each coordinate systems are not required by each coordinate systems directly, but
  44241. * required by the module `custom`.
  44242. *
  44243. * prepareInfoForCustomSeries {Function}: optional
  44244. * @return {Object} {coordSys: {...}, api: {
  44245. * coord: function (data, clamp) {}, // return point in global.
  44246. * size: function (dataSize, dataItem) {} // return size of each axis in coordSys.
  44247. * }}
  44248. */
  44249. var prepareCustoms = {
  44250. cartesian2d: prepareCartesian2d,
  44251. geo: prepareGeo,
  44252. singleAxis: prepareSingleAxis,
  44253. polar: preparePolar,
  44254. calendar: prepareCalendar
  44255. }; // ------
  44256. // Model
  44257. // ------
  44258. SeriesModel.extend({
  44259. type: 'series.custom',
  44260. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  44261. defaultOption: {
  44262. coordinateSystem: 'cartesian2d',
  44263. // Can be set as 'none'
  44264. zlevel: 0,
  44265. z: 2,
  44266. legendHoverLink: true,
  44267. useTransform: true,
  44268. // Custom series will not clip by default.
  44269. // Some case will use custom series to draw label
  44270. // For example https://echarts.apache.org/examples/en/editor.html?c=custom-gantt-flight
  44271. // Only works on polar and cartesian2d coordinate system.
  44272. clip: false // Cartesian coordinate system
  44273. // xAxisIndex: 0,
  44274. // yAxisIndex: 0,
  44275. // Polar coordinate system
  44276. // polarIndex: 0,
  44277. // Geo coordinate system
  44278. // geoIndex: 0,
  44279. // label: {}
  44280. // itemStyle: {}
  44281. },
  44282. /**
  44283. * @override
  44284. */
  44285. getInitialData: function (option, ecModel) {
  44286. return createListFromArray(this.getSource(), this);
  44287. },
  44288. /**
  44289. * @override
  44290. */
  44291. getDataParams: function (dataIndex, dataType, el) {
  44292. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  44293. el && (params.info = el.info);
  44294. return params;
  44295. }
  44296. }); // -----
  44297. // View
  44298. // -----
  44299. Chart.extend({
  44300. type: 'custom',
  44301. /**
  44302. * @private
  44303. * @type {module:echarts/data/List}
  44304. */
  44305. _data: null,
  44306. /**
  44307. * @override
  44308. */
  44309. render: function (customSeries, ecModel, api, payload) {
  44310. var oldData = this._data;
  44311. var data = customSeries.getData();
  44312. var group = this.group;
  44313. var renderItem = makeRenderItem(customSeries, data, ecModel, api); // By default, merge mode is applied. In most cases, custom series is
  44314. // used in the scenario that data amount is not large but graphic elements
  44315. // is complicated, where merge mode is probably necessary for optimization.
  44316. // For example, reuse graphic elements and only update the transform when
  44317. // roam or data zoom according to `actionType`.
  44318. data.diff(oldData).add(function (newIdx) {
  44319. createOrUpdate$1(null, newIdx, renderItem(newIdx, payload), customSeries, group, data);
  44320. }).update(function (newIdx, oldIdx) {
  44321. var el = oldData.getItemGraphicEl(oldIdx);
  44322. createOrUpdate$1(el, newIdx, renderItem(newIdx, payload), customSeries, group, data);
  44323. }).remove(function (oldIdx) {
  44324. var el = oldData.getItemGraphicEl(oldIdx);
  44325. el && group.remove(el);
  44326. }).execute(); // Do clipping
  44327. var clipPath = customSeries.get('clip', true) ? createClipPath(customSeries.coordinateSystem, false, customSeries) : null;
  44328. if (clipPath) {
  44329. group.setClipPath(clipPath);
  44330. } else {
  44331. group.removeClipPath();
  44332. }
  44333. this._data = data;
  44334. },
  44335. incrementalPrepareRender: function (customSeries, ecModel, api) {
  44336. this.group.removeAll();
  44337. this._data = null;
  44338. },
  44339. incrementalRender: function (params, customSeries, ecModel, api, payload) {
  44340. var data = customSeries.getData();
  44341. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  44342. function setIncrementalAndHoverLayer(el) {
  44343. if (!el.isGroup) {
  44344. el.incremental = true;
  44345. el.useHoverLayer = true;
  44346. }
  44347. }
  44348. for (var idx = params.start; idx < params.end; idx++) {
  44349. var el = createOrUpdate$1(null, idx, renderItem(idx, payload), customSeries, this.group, data);
  44350. el.traverse(setIncrementalAndHoverLayer);
  44351. }
  44352. },
  44353. /**
  44354. * @override
  44355. */
  44356. dispose: noop,
  44357. /**
  44358. * @override
  44359. */
  44360. filterForExposedEvent: function (eventType, query, targetEl, packedEvent) {
  44361. var elementName = query.element;
  44362. if (elementName == null || targetEl.name === elementName) {
  44363. return true;
  44364. } // Enable to give a name on a group made by `renderItem`, and listen
  44365. // events that triggerd by its descendents.
  44366. while ((targetEl = targetEl.parent) && targetEl !== this.group) {
  44367. if (targetEl.name === elementName) {
  44368. return true;
  44369. }
  44370. }
  44371. return false;
  44372. }
  44373. });
  44374. function createEl(elOption) {
  44375. var graphicType = elOption.type;
  44376. var el; // Those graphic elements are not shapes. They should not be
  44377. // overwritten by users, so do them first.
  44378. if (graphicType === 'path') {
  44379. var shape = elOption.shape; // Using pathRect brings convenience to users sacle svg path.
  44380. var pathRect = shape.width != null && shape.height != null ? {
  44381. x: shape.x || 0,
  44382. y: shape.y || 0,
  44383. width: shape.width,
  44384. height: shape.height
  44385. } : null;
  44386. var pathData = getPathData(shape); // Path is also used for icon, so layout 'center' by default.
  44387. el = makePath(pathData, null, pathRect, shape.layout || 'center');
  44388. el.__customPathData = pathData;
  44389. } else if (graphicType === 'image') {
  44390. el = new ZImage({});
  44391. el.__customImagePath = elOption.style.image;
  44392. } else if (graphicType === 'text') {
  44393. el = new Text({});
  44394. el.__customText = elOption.style.text;
  44395. } else if (graphicType === 'group') {
  44396. el = new Group();
  44397. } else if (graphicType === 'compoundPath') {
  44398. throw new Error('"compoundPath" is not supported yet.');
  44399. } else {
  44400. var Clz = getShapeClass(graphicType);
  44401. el = new Clz();
  44402. }
  44403. el.__customGraphicType = graphicType;
  44404. el.name = elOption.name;
  44405. return el;
  44406. }
  44407. function updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot) {
  44408. var transitionProps = {};
  44409. var elOptionStyle = elOption.style || {};
  44410. elOption.shape && (transitionProps.shape = clone(elOption.shape));
  44411. elOption.position && (transitionProps.position = elOption.position.slice());
  44412. elOption.scale && (transitionProps.scale = elOption.scale.slice());
  44413. elOption.origin && (transitionProps.origin = elOption.origin.slice());
  44414. elOption.rotation && (transitionProps.rotation = elOption.rotation);
  44415. if (el.type === 'image' && elOption.style) {
  44416. var targetStyle = transitionProps.style = {};
  44417. each$1(['x', 'y', 'width', 'height'], function (prop) {
  44418. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  44419. });
  44420. }
  44421. if (el.type === 'text' && elOption.style) {
  44422. var targetStyle = transitionProps.style = {};
  44423. each$1(['x', 'y'], function (prop) {
  44424. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  44425. }); // Compatible with previous: both support
  44426. // textFill and fill, textStroke and stroke in 'text' element.
  44427. !elOptionStyle.hasOwnProperty('textFill') && elOptionStyle.fill && (elOptionStyle.textFill = elOptionStyle.fill);
  44428. !elOptionStyle.hasOwnProperty('textStroke') && elOptionStyle.stroke && (elOptionStyle.textStroke = elOptionStyle.stroke);
  44429. }
  44430. if (el.type !== 'group') {
  44431. el.useStyle(elOptionStyle); // Init animation.
  44432. if (isInit) {
  44433. el.style.opacity = 0;
  44434. var targetOpacity = elOptionStyle.opacity;
  44435. targetOpacity == null && (targetOpacity = 1);
  44436. initProps(el, {
  44437. style: {
  44438. opacity: targetOpacity
  44439. }
  44440. }, animatableModel, dataIndex);
  44441. }
  44442. }
  44443. if (isInit) {
  44444. el.attr(transitionProps);
  44445. } else {
  44446. updateProps(el, transitionProps, animatableModel, dataIndex);
  44447. } // Merge by default.
  44448. // z2 must not be null/undefined, otherwise sort error may occur.
  44449. elOption.hasOwnProperty('z2') && el.attr('z2', elOption.z2 || 0);
  44450. elOption.hasOwnProperty('silent') && el.attr('silent', elOption.silent);
  44451. elOption.hasOwnProperty('invisible') && el.attr('invisible', elOption.invisible);
  44452. elOption.hasOwnProperty('ignore') && el.attr('ignore', elOption.ignore); // `elOption.info` enables user to mount some info on
  44453. // elements and use them in event handlers.
  44454. // Update them only when user specified, otherwise, remain.
  44455. elOption.hasOwnProperty('info') && el.attr('info', elOption.info); // If `elOption.styleEmphasis` is `false`, remove hover style. The
  44456. // logic is ensured by `graphicUtil.setElementHoverStyle`.
  44457. var styleEmphasis = elOption.styleEmphasis; // hoverStyle should always be set here, because if the hover style
  44458. // may already be changed, where the inner cache should be reset.
  44459. setElementHoverStyle(el, styleEmphasis);
  44460. if (isRoot) {
  44461. setAsHighDownDispatcher(el, styleEmphasis !== false);
  44462. }
  44463. }
  44464. function prepareStyleTransition(prop, targetStyle, elOptionStyle, oldElStyle, isInit) {
  44465. if (elOptionStyle[prop] != null && !isInit) {
  44466. targetStyle[prop] = elOptionStyle[prop];
  44467. elOptionStyle[prop] = oldElStyle[prop];
  44468. }
  44469. }
  44470. function makeRenderItem(customSeries, data, ecModel, api) {
  44471. var renderItem = customSeries.get('renderItem');
  44472. var coordSys = customSeries.coordinateSystem;
  44473. var prepareResult = {};
  44474. if (coordSys) {
  44475. prepareResult = coordSys.prepareCustoms ? coordSys.prepareCustoms() : prepareCustoms[coordSys.type](coordSys);
  44476. }
  44477. var userAPI = defaults({
  44478. getWidth: api.getWidth,
  44479. getHeight: api.getHeight,
  44480. getZr: api.getZr,
  44481. getDevicePixelRatio: api.getDevicePixelRatio,
  44482. value: value,
  44483. style: style,
  44484. styleEmphasis: styleEmphasis,
  44485. visual: visual,
  44486. barLayout: barLayout,
  44487. currentSeriesIndices: currentSeriesIndices,
  44488. font: font
  44489. }, prepareResult.api || {});
  44490. var userParams = {
  44491. // The life cycle of context: current round of rendering.
  44492. // The global life cycle is probably not necessary, because
  44493. // user can store global status by themselves.
  44494. context: {},
  44495. seriesId: customSeries.id,
  44496. seriesName: customSeries.name,
  44497. seriesIndex: customSeries.seriesIndex,
  44498. coordSys: prepareResult.coordSys,
  44499. dataInsideLength: data.count(),
  44500. encode: wrapEncodeDef(customSeries.getData())
  44501. }; // Do not support call `api` asynchronously without dataIndexInside input.
  44502. var currDataIndexInside;
  44503. var currDirty = true;
  44504. var currItemModel;
  44505. var currLabelNormalModel;
  44506. var currLabelEmphasisModel;
  44507. var currVisualColor;
  44508. return function (dataIndexInside, payload) {
  44509. currDataIndexInside = dataIndexInside;
  44510. currDirty = true;
  44511. return renderItem && renderItem(defaults({
  44512. dataIndexInside: dataIndexInside,
  44513. dataIndex: data.getRawIndex(dataIndexInside),
  44514. // Can be used for optimization when zoom or roam.
  44515. actionType: payload ? payload.type : null
  44516. }, userParams), userAPI);
  44517. }; // Do not update cache until api called.
  44518. function updateCache(dataIndexInside) {
  44519. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  44520. if (currDirty) {
  44521. currItemModel = data.getItemModel(dataIndexInside);
  44522. currLabelNormalModel = currItemModel.getModel(LABEL_NORMAL);
  44523. currLabelEmphasisModel = currItemModel.getModel(LABEL_EMPHASIS);
  44524. currVisualColor = data.getItemVisual(dataIndexInside, 'color');
  44525. currDirty = false;
  44526. }
  44527. }
  44528. /**
  44529. * @public
  44530. * @param {number|string} dim
  44531. * @param {number} [dataIndexInside=currDataIndexInside]
  44532. * @return {number|string} value
  44533. */
  44534. function value(dim, dataIndexInside) {
  44535. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  44536. return data.get(data.getDimension(dim || 0), dataIndexInside);
  44537. }
  44538. /**
  44539. * By default, `visual` is applied to style (to support visualMap).
  44540. * `visual.color` is applied at `fill`. If user want apply visual.color on `stroke`,
  44541. * it can be implemented as:
  44542. * `api.style({stroke: api.visual('color'), fill: null})`;
  44543. * @public
  44544. * @param {Object} [extra]
  44545. * @param {number} [dataIndexInside=currDataIndexInside]
  44546. */
  44547. function style(extra, dataIndexInside) {
  44548. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  44549. updateCache(dataIndexInside);
  44550. var itemStyle = currItemModel.getModel(ITEM_STYLE_NORMAL_PATH).getItemStyle();
  44551. currVisualColor != null && (itemStyle.fill = currVisualColor);
  44552. var opacity = data.getItemVisual(dataIndexInside, 'opacity');
  44553. opacity != null && (itemStyle.opacity = opacity);
  44554. var labelModel = extra ? applyExtraBefore(extra, currLabelNormalModel) : currLabelNormalModel;
  44555. setTextStyle(itemStyle, labelModel, null, {
  44556. autoColor: currVisualColor,
  44557. isRectText: true
  44558. });
  44559. itemStyle.text = labelModel.getShallow('show') ? retrieve2(customSeries.getFormattedLabel(dataIndexInside, 'normal'), getDefaultLabel(data, dataIndexInside)) : null;
  44560. extra && applyExtraAfter(itemStyle, extra);
  44561. return itemStyle;
  44562. }
  44563. /**
  44564. * @public
  44565. * @param {Object} [extra]
  44566. * @param {number} [dataIndexInside=currDataIndexInside]
  44567. */
  44568. function styleEmphasis(extra, dataIndexInside) {
  44569. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  44570. updateCache(dataIndexInside);
  44571. var itemStyle = currItemModel.getModel(ITEM_STYLE_EMPHASIS_PATH).getItemStyle();
  44572. var labelModel = extra ? applyExtraBefore(extra, currLabelEmphasisModel) : currLabelEmphasisModel;
  44573. setTextStyle(itemStyle, labelModel, null, {
  44574. isRectText: true
  44575. }, true);
  44576. itemStyle.text = labelModel.getShallow('show') ? retrieve3(customSeries.getFormattedLabel(dataIndexInside, 'emphasis'), customSeries.getFormattedLabel(dataIndexInside, 'normal'), getDefaultLabel(data, dataIndexInside)) : null;
  44577. extra && applyExtraAfter(itemStyle, extra);
  44578. return itemStyle;
  44579. }
  44580. /**
  44581. * @public
  44582. * @param {string} visualType
  44583. * @param {number} [dataIndexInside=currDataIndexInside]
  44584. */
  44585. function visual(visualType, dataIndexInside) {
  44586. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  44587. return data.getItemVisual(dataIndexInside, visualType);
  44588. }
  44589. /**
  44590. * @public
  44591. * @param {number} opt.count Positive interger.
  44592. * @param {number} [opt.barWidth]
  44593. * @param {number} [opt.barMaxWidth]
  44594. * @param {number} [opt.barMinWidth]
  44595. * @param {number} [opt.barGap]
  44596. * @param {number} [opt.barCategoryGap]
  44597. * @return {Object} {width, offset, offsetCenter} is not support, return undefined.
  44598. */
  44599. function barLayout(opt) {
  44600. if (coordSys.getBaseAxis) {
  44601. var baseAxis = coordSys.getBaseAxis();
  44602. return getLayoutOnAxis(defaults({
  44603. axis: baseAxis
  44604. }, opt), api);
  44605. }
  44606. }
  44607. /**
  44608. * @public
  44609. * @return {Array.<number>}
  44610. */
  44611. function currentSeriesIndices() {
  44612. return ecModel.getCurrentSeriesIndices();
  44613. }
  44614. /**
  44615. * @public
  44616. * @param {Object} opt
  44617. * @param {string} [opt.fontStyle]
  44618. * @param {number} [opt.fontWeight]
  44619. * @param {number} [opt.fontSize]
  44620. * @param {string} [opt.fontFamily]
  44621. * @return {string} font string
  44622. */
  44623. function font(opt) {
  44624. return getFont(opt, ecModel);
  44625. }
  44626. }
  44627. function wrapEncodeDef(data) {
  44628. var encodeDef = {};
  44629. each$1(data.dimensions, function (dimName, dataDimIndex) {
  44630. var dimInfo = data.getDimensionInfo(dimName);
  44631. if (!dimInfo.isExtraCoord) {
  44632. var coordDim = dimInfo.coordDim;
  44633. var dataDims = encodeDef[coordDim] = encodeDef[coordDim] || [];
  44634. dataDims[dimInfo.coordDimIndex] = dataDimIndex;
  44635. }
  44636. });
  44637. return encodeDef;
  44638. }
  44639. function createOrUpdate$1(el, dataIndex, elOption, animatableModel, group, data) {
  44640. el = doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data, true);
  44641. el && data.setItemGraphicEl(dataIndex, el);
  44642. return el;
  44643. }
  44644. function doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data, isRoot) {
  44645. // [Rule]
  44646. // By default, follow merge mode.
  44647. // (It probably brings benifit for performance in some cases of large data, where
  44648. // user program can be optimized to that only updated props needed to be re-calculated,
  44649. // or according to `actionType` some calculation can be skipped.)
  44650. // If `renderItem` returns `null`/`undefined`/`false`, remove the previous el if existing.
  44651. // (It seems that violate the "merge" principle, but most of users probably intuitively
  44652. // regard "return;" as "show nothing element whatever", so make a exception to meet the
  44653. // most cases.)
  44654. var simplyRemove = !elOption; // `null`/`undefined`/`false`
  44655. elOption = elOption || {};
  44656. var elOptionType = elOption.type;
  44657. var elOptionShape = elOption.shape;
  44658. var elOptionStyle = elOption.style;
  44659. if (el && (simplyRemove // || elOption.$merge === false
  44660. // If `elOptionType` is `null`, follow the merge principle.
  44661. || elOptionType != null && elOptionType !== el.__customGraphicType || elOptionType === 'path' && hasOwnPathData(elOptionShape) && getPathData(elOptionShape) !== el.__customPathData || elOptionType === 'image' && hasOwn(elOptionStyle, 'image') && elOptionStyle.image !== el.__customImagePath // FIXME test and remove this restriction?
  44662. || elOptionType === 'text' && hasOwn(elOptionShape, 'text') && elOptionStyle.text !== el.__customText)) {
  44663. group.remove(el);
  44664. el = null;
  44665. } // `elOption.type` is undefined when `renderItem` returns nothing.
  44666. if (simplyRemove) {
  44667. return;
  44668. }
  44669. var isInit = !el;
  44670. !el && (el = createEl(elOption));
  44671. updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot);
  44672. if (elOptionType === 'group') {
  44673. mergeChildren(el, dataIndex, elOption, animatableModel, data);
  44674. } // Always add whatever already added to ensure sequence.
  44675. group.add(el);
  44676. return el;
  44677. } // Usage:
  44678. // (1) By default, `elOption.$mergeChildren` is `'byIndex'`, which indicates that
  44679. // the existing children will not be removed, and enables the feature that
  44680. // update some of the props of some of the children simply by construct
  44681. // the returned children of `renderItem` like:
  44682. // `var children = group.children = []; children[3] = {opacity: 0.5};`
  44683. // (2) If `elOption.$mergeChildren` is `'byName'`, add/update/remove children
  44684. // by child.name. But that might be lower performance.
  44685. // (3) If `elOption.$mergeChildren` is `false`, the existing children will be
  44686. // replaced totally.
  44687. // (4) If `!elOption.children`, following the "merge" principle, nothing will happen.
  44688. //
  44689. // For implementation simpleness, do not provide a direct way to remove sinlge
  44690. // child (otherwise the total indicies of the children array have to be modified).
  44691. // User can remove a single child by set its `ignore` as `true` or replace
  44692. // it by another element, where its `$merge` can be set as `true` if necessary.
  44693. function mergeChildren(el, dataIndex, elOption, animatableModel, data) {
  44694. var newChildren = elOption.children;
  44695. var newLen = newChildren ? newChildren.length : 0;
  44696. var mergeChildren = elOption.$mergeChildren; // `diffChildrenByName` has been deprecated.
  44697. var byName = mergeChildren === 'byName' || elOption.diffChildrenByName;
  44698. var notMerge = mergeChildren === false; // For better performance on roam update, only enter if necessary.
  44699. if (!newLen && !byName && !notMerge) {
  44700. return;
  44701. }
  44702. if (byName) {
  44703. diffGroupChildren({
  44704. oldChildren: el.children() || [],
  44705. newChildren: newChildren || [],
  44706. dataIndex: dataIndex,
  44707. animatableModel: animatableModel,
  44708. group: el,
  44709. data: data
  44710. });
  44711. return;
  44712. }
  44713. notMerge && el.removeAll(); // Mapping children of a group simply by index, which
  44714. // might be better performance.
  44715. var index = 0;
  44716. for (; index < newLen; index++) {
  44717. newChildren[index] && doCreateOrUpdate(el.childAt(index), dataIndex, newChildren[index], animatableModel, el, data);
  44718. }
  44719. }
  44720. function diffGroupChildren(context) {
  44721. new DataDiffer(context.oldChildren, context.newChildren, getKey, getKey, context).add(processAddUpdate).update(processAddUpdate).remove(processRemove).execute();
  44722. }
  44723. function getKey(item, idx) {
  44724. var name = item && item.name;
  44725. return name != null ? name : GROUP_DIFF_PREFIX + idx;
  44726. }
  44727. function processAddUpdate(newIndex, oldIndex) {
  44728. var context = this.context;
  44729. var childOption = newIndex != null ? context.newChildren[newIndex] : null;
  44730. var child = oldIndex != null ? context.oldChildren[oldIndex] : null;
  44731. doCreateOrUpdate(child, context.dataIndex, childOption, context.animatableModel, context.group, context.data);
  44732. } // `graphic#applyDefaultTextStyle` will cache
  44733. // textFill, textStroke, textStrokeWidth.
  44734. // We have to do this trick.
  44735. function applyExtraBefore(extra, model) {
  44736. var dummyModel = new Model({}, model);
  44737. each$1(CACHED_LABEL_STYLE_PROPERTIES$1, function (stylePropName, modelPropName) {
  44738. if (extra.hasOwnProperty(stylePropName)) {
  44739. dummyModel.option[modelPropName] = extra[stylePropName];
  44740. }
  44741. });
  44742. return dummyModel;
  44743. }
  44744. function applyExtraAfter(itemStyle, extra) {
  44745. for (var key in extra) {
  44746. if (extra.hasOwnProperty(key) || !CACHED_LABEL_STYLE_PROPERTIES$1.hasOwnProperty(key)) {
  44747. itemStyle[key] = extra[key];
  44748. }
  44749. }
  44750. }
  44751. function processRemove(oldIndex) {
  44752. var context = this.context;
  44753. var child = context.oldChildren[oldIndex];
  44754. child && context.group.remove(child);
  44755. }
  44756. function getPathData(shape) {
  44757. // "d" follows the SVG convention.
  44758. return shape && (shape.pathData || shape.d);
  44759. }
  44760. function hasOwnPathData(shape) {
  44761. return shape && (shape.hasOwnProperty('pathData') || shape.hasOwnProperty('d'));
  44762. }
  44763. function hasOwn(host, prop) {
  44764. return host && host.hasOwnProperty(prop);
  44765. }
  44766. /*
  44767. * Licensed to the Apache Software Foundation (ASF) under one
  44768. * or more contributor license agreements. See the NOTICE file
  44769. * distributed with this work for additional information
  44770. * regarding copyright ownership. The ASF licenses this file
  44771. * to you under the Apache License, Version 2.0 (the
  44772. * "License"); you may not use this file except in compliance
  44773. * with the License. You may obtain a copy of the License at
  44774. *
  44775. * http://www.apache.org/licenses/LICENSE-2.0
  44776. *
  44777. * Unless required by applicable law or agreed to in writing,
  44778. * software distributed under the License is distributed on an
  44779. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44780. * KIND, either express or implied. See the License for the
  44781. * specific language governing permissions and limitations
  44782. * under the License.
  44783. */
  44784. extendComponentModel({
  44785. type: 'title',
  44786. layoutMode: {
  44787. type: 'box',
  44788. ignoreSize: true
  44789. },
  44790. defaultOption: {
  44791. // 一级层叠
  44792. zlevel: 0,
  44793. // 二级层叠
  44794. z: 6,
  44795. show: true,
  44796. text: '',
  44797. // 超链接跳转
  44798. // link: null,
  44799. // 仅支持self | blank
  44800. target: 'blank',
  44801. subtext: '',
  44802. // 超链接跳转
  44803. // sublink: null,
  44804. // 仅支持self | blank
  44805. subtarget: 'blank',
  44806. // 'center' ¦ 'left' ¦ 'right'
  44807. // ¦ {number}(x坐标,单位px)
  44808. left: 0,
  44809. // 'top' ¦ 'bottom' ¦ 'center'
  44810. // ¦ {number}(y坐标,单位px)
  44811. top: 0,
  44812. // 水平对齐
  44813. // 'auto' | 'left' | 'right' | 'center'
  44814. // 默认根据 left 的位置判断是左对齐还是右对齐
  44815. // textAlign: null
  44816. //
  44817. // 垂直对齐
  44818. // 'auto' | 'top' | 'bottom' | 'middle'
  44819. // 默认根据 top 位置判断是上对齐还是下对齐
  44820. // textVerticalAlign: null
  44821. // textBaseline: null // The same as textVerticalAlign.
  44822. backgroundColor: 'rgba(0,0,0,0)',
  44823. // 标题边框颜色
  44824. borderColor: '#ccc',
  44825. // 标题边框线宽,单位px,默认为0(无边框)
  44826. borderWidth: 0,
  44827. // 标题内边距,单位px,默认各方向内边距为5,
  44828. // 接受数组分别设定上右下左边距,同css
  44829. padding: 5,
  44830. // 主副标题纵向间隔,单位px,默认为10,
  44831. itemGap: 10,
  44832. textStyle: {
  44833. fontSize: 18,
  44834. fontWeight: 'bolder',
  44835. color: '#333'
  44836. },
  44837. subtextStyle: {
  44838. color: '#aaa'
  44839. }
  44840. }
  44841. }); // View
  44842. extendComponentView({
  44843. type: 'title',
  44844. render: function (titleModel, ecModel, api) {
  44845. this.group.removeAll();
  44846. if (!titleModel.get('show')) {
  44847. return;
  44848. }
  44849. var group = this.group;
  44850. var textStyleModel = titleModel.getModel('textStyle');
  44851. var subtextStyleModel = titleModel.getModel('subtextStyle');
  44852. var textAlign = titleModel.get('textAlign');
  44853. var textVerticalAlign = retrieve2(titleModel.get('textBaseline'), titleModel.get('textVerticalAlign'));
  44854. var textEl = new Text({
  44855. style: setTextStyle({}, textStyleModel, {
  44856. text: titleModel.get('text'),
  44857. textFill: textStyleModel.getTextColor()
  44858. }, {
  44859. disableBox: true
  44860. }),
  44861. z2: 10
  44862. });
  44863. var textRect = textEl.getBoundingRect();
  44864. var subText = titleModel.get('subtext');
  44865. var subTextEl = new Text({
  44866. style: setTextStyle({}, subtextStyleModel, {
  44867. text: subText,
  44868. textFill: subtextStyleModel.getTextColor(),
  44869. y: textRect.height + titleModel.get('itemGap'),
  44870. textVerticalAlign: 'top'
  44871. }, {
  44872. disableBox: true
  44873. }),
  44874. z2: 10
  44875. });
  44876. var link = titleModel.get('link');
  44877. var sublink = titleModel.get('sublink');
  44878. var triggerEvent = titleModel.get('triggerEvent', true);
  44879. textEl.silent = !link && !triggerEvent;
  44880. subTextEl.silent = !sublink && !triggerEvent;
  44881. if (link) {
  44882. textEl.on('click', function () {
  44883. windowOpen(link, '_' + titleModel.get('target'));
  44884. });
  44885. }
  44886. if (sublink) {
  44887. subTextEl.on('click', function () {
  44888. windowOpen(link, '_' + titleModel.get('subtarget'));
  44889. });
  44890. }
  44891. textEl.eventData = subTextEl.eventData = triggerEvent ? {
  44892. componentType: 'title',
  44893. componentIndex: titleModel.componentIndex
  44894. } : null;
  44895. group.add(textEl);
  44896. subText && group.add(subTextEl); // If no subText, but add subTextEl, there will be an empty line.
  44897. var groupRect = group.getBoundingRect();
  44898. var layoutOption = titleModel.getBoxLayoutParams();
  44899. layoutOption.width = groupRect.width;
  44900. layoutOption.height = groupRect.height;
  44901. var layoutRect = getLayoutRect(layoutOption, {
  44902. width: api.getWidth(),
  44903. height: api.getHeight()
  44904. }, titleModel.get('padding')); // Adjust text align based on position
  44905. if (!textAlign) {
  44906. // Align left if title is on the left. center and right is same
  44907. textAlign = titleModel.get('left') || titleModel.get('right');
  44908. if (textAlign === 'middle') {
  44909. textAlign = 'center';
  44910. } // Adjust layout by text align
  44911. if (textAlign === 'right') {
  44912. layoutRect.x += layoutRect.width;
  44913. } else if (textAlign === 'center') {
  44914. layoutRect.x += layoutRect.width / 2;
  44915. }
  44916. }
  44917. if (!textVerticalAlign) {
  44918. textVerticalAlign = titleModel.get('top') || titleModel.get('bottom');
  44919. if (textVerticalAlign === 'center') {
  44920. textVerticalAlign = 'middle';
  44921. }
  44922. if (textVerticalAlign === 'bottom') {
  44923. layoutRect.y += layoutRect.height;
  44924. } else if (textVerticalAlign === 'middle') {
  44925. layoutRect.y += layoutRect.height / 2;
  44926. }
  44927. textVerticalAlign = textVerticalAlign || 'top';
  44928. }
  44929. group.attr('position', [layoutRect.x, layoutRect.y]);
  44930. var alignStyle = {
  44931. textAlign: textAlign,
  44932. textVerticalAlign: textVerticalAlign
  44933. };
  44934. textEl.setStyle(alignStyle);
  44935. subTextEl.setStyle(alignStyle); // Render background
  44936. // Get groupRect again because textAlign has been changed
  44937. groupRect = group.getBoundingRect();
  44938. var padding = layoutRect.margin;
  44939. var style = titleModel.getItemStyle(['color', 'opacity']);
  44940. style.fill = titleModel.get('backgroundColor');
  44941. var rect = new Rect({
  44942. shape: {
  44943. x: groupRect.x - padding[3],
  44944. y: groupRect.y - padding[0],
  44945. width: groupRect.width + padding[1] + padding[3],
  44946. height: groupRect.height + padding[0] + padding[2],
  44947. r: titleModel.get('borderRadius')
  44948. },
  44949. style: style,
  44950. subPixelOptimize: true,
  44951. silent: true
  44952. });
  44953. group.add(rect);
  44954. }
  44955. });
  44956. /*
  44957. * Licensed to the Apache Software Foundation (ASF) under one
  44958. * or more contributor license agreements. See the NOTICE file
  44959. * distributed with this work for additional information
  44960. * regarding copyright ownership. The ASF licenses this file
  44961. * to you under the Apache License, Version 2.0 (the
  44962. * "License"); you may not use this file except in compliance
  44963. * with the License. You may obtain a copy of the License at
  44964. *
  44965. * http://www.apache.org/licenses/LICENSE-2.0
  44966. *
  44967. * Unless required by applicable law or agreed to in writing,
  44968. * software distributed under the License is distributed on an
  44969. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44970. * KIND, either express or implied. See the License for the
  44971. * specific language governing permissions and limitations
  44972. * under the License.
  44973. */
  44974. var langSelector = lang.legend.selector;
  44975. var defaultSelectorOption = {
  44976. all: {
  44977. type: 'all',
  44978. title: clone(langSelector.all)
  44979. },
  44980. inverse: {
  44981. type: 'inverse',
  44982. title: clone(langSelector.inverse)
  44983. }
  44984. };
  44985. var LegendModel = extendComponentModel({
  44986. type: 'legend.plain',
  44987. dependencies: ['series'],
  44988. layoutMode: {
  44989. type: 'box',
  44990. // legend.width/height are maxWidth/maxHeight actually,
  44991. // whereas realy width/height is calculated by its content.
  44992. // (Setting {left: 10, right: 10} does not make sense).
  44993. // So consider the case:
  44994. // `setOption({legend: {left: 10});`
  44995. // then `setOption({legend: {right: 10});`
  44996. // The previous `left` should be cleared by setting `ignoreSize`.
  44997. ignoreSize: true
  44998. },
  44999. init: function (option, parentModel, ecModel) {
  45000. this.mergeDefaultAndTheme(option, ecModel);
  45001. option.selected = option.selected || {};
  45002. this._updateSelector(option);
  45003. },
  45004. mergeOption: function (option) {
  45005. LegendModel.superCall(this, 'mergeOption', option);
  45006. this._updateSelector(option);
  45007. },
  45008. _updateSelector: function (option) {
  45009. var selector = option.selector;
  45010. if (selector === true) {
  45011. selector = option.selector = ['all', 'inverse'];
  45012. }
  45013. if (isArray(selector)) {
  45014. each$1(selector, function (item, index) {
  45015. isString(item) && (item = {
  45016. type: item
  45017. });
  45018. selector[index] = merge(item, defaultSelectorOption[item.type]);
  45019. });
  45020. }
  45021. },
  45022. optionUpdated: function () {
  45023. this._updateData(this.ecModel);
  45024. var legendData = this._data; // If selectedMode is single, try to select one
  45025. if (legendData[0] && this.get('selectedMode') === 'single') {
  45026. var hasSelected = false; // If has any selected in option.selected
  45027. for (var i = 0; i < legendData.length; i++) {
  45028. var name = legendData[i].get('name');
  45029. if (this.isSelected(name)) {
  45030. // Force to unselect others
  45031. this.select(name);
  45032. hasSelected = true;
  45033. break;
  45034. }
  45035. } // Try select the first if selectedMode is single
  45036. !hasSelected && this.select(legendData[0].get('name'));
  45037. }
  45038. },
  45039. _updateData: function (ecModel) {
  45040. var potentialData = [];
  45041. var availableNames = [];
  45042. ecModel.eachRawSeries(function (seriesModel) {
  45043. var seriesName = seriesModel.name;
  45044. availableNames.push(seriesName);
  45045. var isPotential;
  45046. if (seriesModel.legendVisualProvider) {
  45047. var provider = seriesModel.legendVisualProvider;
  45048. var names = provider.getAllNames();
  45049. if (!ecModel.isSeriesFiltered(seriesModel)) {
  45050. availableNames = availableNames.concat(names);
  45051. }
  45052. if (names.length) {
  45053. potentialData = potentialData.concat(names);
  45054. } else {
  45055. isPotential = true;
  45056. }
  45057. } else {
  45058. isPotential = true;
  45059. }
  45060. if (isPotential && isNameSpecified(seriesModel)) {
  45061. potentialData.push(seriesModel.name);
  45062. }
  45063. });
  45064. /**
  45065. * @type {Array.<string>}
  45066. * @private
  45067. */
  45068. this._availableNames = availableNames; // If legend.data not specified in option, use availableNames as data,
  45069. // which is convinient for user preparing option.
  45070. var rawData = this.get('data') || potentialData;
  45071. var legendData = map(rawData, function (dataItem) {
  45072. // Can be string or number
  45073. if (typeof dataItem === 'string' || typeof dataItem === 'number') {
  45074. dataItem = {
  45075. name: dataItem
  45076. };
  45077. }
  45078. return new Model(dataItem, this, this.ecModel);
  45079. }, this);
  45080. /**
  45081. * @type {Array.<module:echarts/model/Model>}
  45082. * @private
  45083. */
  45084. this._data = legendData;
  45085. },
  45086. /**
  45087. * @return {Array.<module:echarts/model/Model>}
  45088. */
  45089. getData: function () {
  45090. return this._data;
  45091. },
  45092. /**
  45093. * @param {string} name
  45094. */
  45095. select: function (name) {
  45096. var selected = this.option.selected;
  45097. var selectedMode = this.get('selectedMode');
  45098. if (selectedMode === 'single') {
  45099. var data = this._data;
  45100. each$1(data, function (dataItem) {
  45101. selected[dataItem.get('name')] = false;
  45102. });
  45103. }
  45104. selected[name] = true;
  45105. },
  45106. /**
  45107. * @param {string} name
  45108. */
  45109. unSelect: function (name) {
  45110. if (this.get('selectedMode') !== 'single') {
  45111. this.option.selected[name] = false;
  45112. }
  45113. },
  45114. /**
  45115. * @param {string} name
  45116. */
  45117. toggleSelected: function (name) {
  45118. var selected = this.option.selected; // Default is true
  45119. if (!selected.hasOwnProperty(name)) {
  45120. selected[name] = true;
  45121. }
  45122. this[selected[name] ? 'unSelect' : 'select'](name);
  45123. },
  45124. allSelect: function () {
  45125. var data = this._data;
  45126. var selected = this.option.selected;
  45127. each$1(data, function (dataItem) {
  45128. selected[dataItem.get('name', true)] = true;
  45129. });
  45130. },
  45131. inverseSelect: function () {
  45132. var data = this._data;
  45133. var selected = this.option.selected;
  45134. each$1(data, function (dataItem) {
  45135. var name = dataItem.get('name', true); // Initially, default value is true
  45136. if (!selected.hasOwnProperty(name)) {
  45137. selected[name] = true;
  45138. }
  45139. selected[name] = !selected[name];
  45140. });
  45141. },
  45142. /**
  45143. * @param {string} name
  45144. */
  45145. isSelected: function (name) {
  45146. var selected = this.option.selected;
  45147. return !(selected.hasOwnProperty(name) && !selected[name]) && indexOf(this._availableNames, name) >= 0;
  45148. },
  45149. getOrient: function () {
  45150. return this.get('orient') === 'vertical' ? {
  45151. index: 1,
  45152. name: 'vertical'
  45153. } : {
  45154. index: 0,
  45155. name: 'horizontal'
  45156. };
  45157. },
  45158. defaultOption: {
  45159. // 一级层叠
  45160. zlevel: 0,
  45161. // 二级层叠
  45162. z: 4,
  45163. show: true,
  45164. // 布局方式,默认为水平布局,可选为:
  45165. // 'horizontal' | 'vertical'
  45166. orient: 'horizontal',
  45167. left: 'center',
  45168. // right: 'center',
  45169. top: 0,
  45170. // bottom: null,
  45171. // 水平对齐
  45172. // 'auto' | 'left' | 'right'
  45173. // 默认为 'auto', 根据 x 的位置判断是左对齐还是右对齐
  45174. align: 'auto',
  45175. backgroundColor: 'rgba(0,0,0,0)',
  45176. // 图例边框颜色
  45177. borderColor: '#ccc',
  45178. borderRadius: 0,
  45179. // 图例边框线宽,单位px,默认为0(无边框)
  45180. borderWidth: 0,
  45181. // 图例内边距,单位px,默认各方向内边距为5,
  45182. // 接受数组分别设定上右下左边距,同css
  45183. padding: 5,
  45184. // 各个item之间的间隔,单位px,默认为10,
  45185. // 横向布局时为水平间隔,纵向布局时为纵向间隔
  45186. itemGap: 10,
  45187. // the width of legend symbol
  45188. itemWidth: 25,
  45189. // the height of legend symbol
  45190. itemHeight: 14,
  45191. // the color of unselected legend symbol
  45192. inactiveColor: '#ccc',
  45193. // the borderColor of unselected legend symbol
  45194. inactiveBorderColor: '#ccc',
  45195. itemStyle: {
  45196. // the default borderWidth of legend symbol
  45197. borderWidth: 0
  45198. },
  45199. textStyle: {
  45200. // 图例文字颜色
  45201. color: '#333'
  45202. },
  45203. // formatter: '',
  45204. // 选择模式,默认开启图例开关
  45205. selectedMode: true,
  45206. // 配置默认选中状态,可配合LEGEND.SELECTED事件做动态数据载入
  45207. // selected: null,
  45208. // 图例内容(详见legend.data,数组中每一项代表一个item
  45209. // data: [],
  45210. // Usage:
  45211. // selector: [{type: 'all or inverse', title: xxx}]
  45212. // or
  45213. // selector: true
  45214. // or
  45215. // selector: ['all', 'inverse']
  45216. selector: false,
  45217. selectorLabel: {
  45218. show: true,
  45219. borderRadius: 10,
  45220. padding: [3, 5, 3, 5],
  45221. fontSize: 12,
  45222. fontFamily: ' sans-serif',
  45223. color: '#666',
  45224. borderWidth: 1,
  45225. borderColor: '#666'
  45226. },
  45227. emphasis: {
  45228. selectorLabel: {
  45229. show: true,
  45230. color: '#eee',
  45231. backgroundColor: '#666'
  45232. }
  45233. },
  45234. // Value can be 'start' or 'end'
  45235. selectorPosition: 'auto',
  45236. selectorItemGap: 7,
  45237. selectorButtonGap: 10,
  45238. // Tooltip 相关配置
  45239. tooltip: {
  45240. show: false
  45241. }
  45242. }
  45243. });
  45244. /*
  45245. * Licensed to the Apache Software Foundation (ASF) under one
  45246. * or more contributor license agreements. See the NOTICE file
  45247. * distributed with this work for additional information
  45248. * regarding copyright ownership. The ASF licenses this file
  45249. * to you under the Apache License, Version 2.0 (the
  45250. * "License"); you may not use this file except in compliance
  45251. * with the License. You may obtain a copy of the License at
  45252. *
  45253. * http://www.apache.org/licenses/LICENSE-2.0
  45254. *
  45255. * Unless required by applicable law or agreed to in writing,
  45256. * software distributed under the License is distributed on an
  45257. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45258. * KIND, either express or implied. See the License for the
  45259. * specific language governing permissions and limitations
  45260. * under the License.
  45261. */
  45262. function legendSelectActionHandler(methodName, payload, ecModel) {
  45263. var selectedMap = {};
  45264. var isToggleSelect = methodName === 'toggleSelected';
  45265. var isSelected; // Update all legend components
  45266. ecModel.eachComponent('legend', function (legendModel) {
  45267. if (isToggleSelect && isSelected != null) {
  45268. // Force other legend has same selected status
  45269. // Or the first is toggled to true and other are toggled to false
  45270. // In the case one legend has some item unSelected in option. And if other legend
  45271. // doesn't has the item, they will assume it is selected.
  45272. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  45273. } else if (methodName === 'allSelect' || methodName === 'inverseSelect') {
  45274. legendModel[methodName]();
  45275. } else {
  45276. legendModel[methodName](payload.name);
  45277. isSelected = legendModel.isSelected(payload.name);
  45278. }
  45279. var legendData = legendModel.getData();
  45280. each$1(legendData, function (model) {
  45281. var name = model.get('name'); // Wrap element
  45282. if (name === '\n' || name === '') {
  45283. return;
  45284. }
  45285. var isItemSelected = legendModel.isSelected(name);
  45286. if (selectedMap.hasOwnProperty(name)) {
  45287. // Unselected if any legend is unselected
  45288. selectedMap[name] = selectedMap[name] && isItemSelected;
  45289. } else {
  45290. selectedMap[name] = isItemSelected;
  45291. }
  45292. });
  45293. }); // Return the event explicitly
  45294. return methodName === 'allSelect' || methodName === 'inverseSelect' ? {
  45295. selected: selectedMap
  45296. } : {
  45297. name: payload.name,
  45298. selected: selectedMap
  45299. };
  45300. }
  45301. /**
  45302. * @event legendToggleSelect
  45303. * @type {Object}
  45304. * @property {string} type 'legendToggleSelect'
  45305. * @property {string} [from]
  45306. * @property {string} name Series name or data item name
  45307. */
  45308. registerAction('legendToggleSelect', 'legendselectchanged', curry(legendSelectActionHandler, 'toggleSelected'));
  45309. registerAction('legendAllSelect', 'legendselectall', curry(legendSelectActionHandler, 'allSelect'));
  45310. registerAction('legendInverseSelect', 'legendinverseselect', curry(legendSelectActionHandler, 'inverseSelect'));
  45311. /**
  45312. * @event legendSelect
  45313. * @type {Object}
  45314. * @property {string} type 'legendSelect'
  45315. * @property {string} name Series name or data item name
  45316. */
  45317. registerAction('legendSelect', 'legendselected', curry(legendSelectActionHandler, 'select'));
  45318. /**
  45319. * @event legendUnSelect
  45320. * @type {Object}
  45321. * @property {string} type 'legendUnSelect'
  45322. * @property {string} name Series name or data item name
  45323. */
  45324. registerAction('legendUnSelect', 'legendunselected', curry(legendSelectActionHandler, 'unSelect'));
  45325. /*
  45326. * Licensed to the Apache Software Foundation (ASF) under one
  45327. * or more contributor license agreements. See the NOTICE file
  45328. * distributed with this work for additional information
  45329. * regarding copyright ownership. The ASF licenses this file
  45330. * to you under the Apache License, Version 2.0 (the
  45331. * "License"); you may not use this file except in compliance
  45332. * with the License. You may obtain a copy of the License at
  45333. *
  45334. * http://www.apache.org/licenses/LICENSE-2.0
  45335. *
  45336. * Unless required by applicable law or agreed to in writing,
  45337. * software distributed under the License is distributed on an
  45338. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45339. * KIND, either express or implied. See the License for the
  45340. * specific language governing permissions and limitations
  45341. * under the License.
  45342. */
  45343. /**
  45344. * Layout list like component.
  45345. * It will box layout each items in group of component and then position the whole group in the viewport
  45346. * @param {module:zrender/group/Group} group
  45347. * @param {module:echarts/model/Component} componentModel
  45348. * @param {module:echarts/ExtensionAPI}
  45349. */
  45350. function layout$2(group, componentModel, api) {
  45351. var boxLayoutParams = componentModel.getBoxLayoutParams();
  45352. var padding = componentModel.get('padding');
  45353. var viewportSize = {
  45354. width: api.getWidth(),
  45355. height: api.getHeight()
  45356. };
  45357. var rect = getLayoutRect(boxLayoutParams, viewportSize, padding);
  45358. box(componentModel.get('orient'), group, componentModel.get('itemGap'), rect.width, rect.height);
  45359. positionElement(group, boxLayoutParams, viewportSize, padding);
  45360. }
  45361. function makeBackground(rect, componentModel) {
  45362. var padding = normalizeCssArray$1(componentModel.get('padding'));
  45363. var style = componentModel.getItemStyle(['color', 'opacity']);
  45364. style.fill = componentModel.get('backgroundColor');
  45365. var rect = new Rect({
  45366. shape: {
  45367. x: rect.x - padding[3],
  45368. y: rect.y - padding[0],
  45369. width: rect.width + padding[1] + padding[3],
  45370. height: rect.height + padding[0] + padding[2],
  45371. r: componentModel.get('borderRadius')
  45372. },
  45373. style: style,
  45374. silent: true,
  45375. z2: -1
  45376. }); // FIXME
  45377. // `subPixelOptimizeRect` may bring some gap between edge of viewpart
  45378. // and background rect when setting like `left: 0`, `top: 0`.
  45379. // graphic.subPixelOptimizeRect(rect);
  45380. return rect;
  45381. }
  45382. /*
  45383. * Licensed to the Apache Software Foundation (ASF) under one
  45384. * or more contributor license agreements. See the NOTICE file
  45385. * distributed with this work for additional information
  45386. * regarding copyright ownership. The ASF licenses this file
  45387. * to you under the Apache License, Version 2.0 (the
  45388. * "License"); you may not use this file except in compliance
  45389. * with the License. You may obtain a copy of the License at
  45390. *
  45391. * http://www.apache.org/licenses/LICENSE-2.0
  45392. *
  45393. * Unless required by applicable law or agreed to in writing,
  45394. * software distributed under the License is distributed on an
  45395. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45396. * KIND, either express or implied. See the License for the
  45397. * specific language governing permissions and limitations
  45398. * under the License.
  45399. */
  45400. var curry$2 = curry;
  45401. var each$8 = each$1;
  45402. var Group$2 = Group;
  45403. var LegendView = extendComponentView({
  45404. type: 'legend.plain',
  45405. newlineDisabled: false,
  45406. /**
  45407. * @override
  45408. */
  45409. init: function () {
  45410. /**
  45411. * @private
  45412. * @type {module:zrender/container/Group}
  45413. */
  45414. this.group.add(this._contentGroup = new Group$2());
  45415. /**
  45416. * @private
  45417. * @type {module:zrender/Element}
  45418. */
  45419. this._backgroundEl;
  45420. /**
  45421. * @private
  45422. * @type {module:zrender/container/Group}
  45423. */
  45424. this.group.add(this._selectorGroup = new Group$2());
  45425. /**
  45426. * If first rendering, `contentGroup.position` is [0, 0], which
  45427. * does not make sense and may cause unexepcted animation if adopted.
  45428. * @private
  45429. * @type {boolean}
  45430. */
  45431. this._isFirstRender = true;
  45432. },
  45433. /**
  45434. * @protected
  45435. */
  45436. getContentGroup: function () {
  45437. return this._contentGroup;
  45438. },
  45439. /**
  45440. * @protected
  45441. */
  45442. getSelectorGroup: function () {
  45443. return this._selectorGroup;
  45444. },
  45445. /**
  45446. * @override
  45447. */
  45448. render: function (legendModel, ecModel, api) {
  45449. var isFirstRender = this._isFirstRender;
  45450. this._isFirstRender = false;
  45451. this.resetInner();
  45452. if (!legendModel.get('show', true)) {
  45453. return;
  45454. }
  45455. var itemAlign = legendModel.get('align');
  45456. var orient = legendModel.get('orient');
  45457. if (!itemAlign || itemAlign === 'auto') {
  45458. itemAlign = legendModel.get('left') === 'right' && orient === 'vertical' ? 'right' : 'left';
  45459. }
  45460. var selector = legendModel.get('selector', true);
  45461. var selectorPosition = legendModel.get('selectorPosition', true);
  45462. if (selector && (!selectorPosition || selectorPosition === 'auto')) {
  45463. selectorPosition = orient === 'horizontal' ? 'end' : 'start';
  45464. }
  45465. this.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition); // Perform layout.
  45466. var positionInfo = legendModel.getBoxLayoutParams();
  45467. var viewportSize = {
  45468. width: api.getWidth(),
  45469. height: api.getHeight()
  45470. };
  45471. var padding = legendModel.get('padding');
  45472. var maxSize = getLayoutRect(positionInfo, viewportSize, padding);
  45473. var mainRect = this.layoutInner(legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition); // Place mainGroup, based on the calculated `mainRect`.
  45474. var layoutRect = getLayoutRect(defaults({
  45475. width: mainRect.width,
  45476. height: mainRect.height
  45477. }, positionInfo), viewportSize, padding);
  45478. this.group.attr('position', [layoutRect.x - mainRect.x, layoutRect.y - mainRect.y]); // Render background after group is layout.
  45479. this.group.add(this._backgroundEl = makeBackground(mainRect, legendModel));
  45480. },
  45481. /**
  45482. * @protected
  45483. */
  45484. resetInner: function () {
  45485. this.getContentGroup().removeAll();
  45486. this._backgroundEl && this.group.remove(this._backgroundEl);
  45487. this.getSelectorGroup().removeAll();
  45488. },
  45489. /**
  45490. * @protected
  45491. */
  45492. renderInner: function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
  45493. var contentGroup = this.getContentGroup();
  45494. var legendDrawnMap = createHashMap();
  45495. var selectMode = legendModel.get('selectedMode');
  45496. var excludeSeriesId = [];
  45497. ecModel.eachRawSeries(function (seriesModel) {
  45498. !seriesModel.get('legendHoverLink') && excludeSeriesId.push(seriesModel.id);
  45499. });
  45500. each$8(legendModel.getData(), function (itemModel, dataIndex) {
  45501. var name = itemModel.get('name'); // Use empty string or \n as a newline string
  45502. if (!this.newlineDisabled && (name === '' || name === '\n')) {
  45503. contentGroup.add(new Group$2({
  45504. newline: true
  45505. }));
  45506. return;
  45507. } // Representitive series.
  45508. var seriesModel = ecModel.getSeriesByName(name)[0];
  45509. if (legendDrawnMap.get(name)) {
  45510. // Have been drawed
  45511. return;
  45512. } // Legend to control series.
  45513. if (seriesModel) {
  45514. var data = seriesModel.getData();
  45515. var color = data.getVisual('color');
  45516. var borderColor = data.getVisual('borderColor'); // If color is a callback function
  45517. if (typeof color === 'function') {
  45518. // Use the first data
  45519. color = color(seriesModel.getDataParams(0));
  45520. } // If borderColor is a callback function
  45521. if (typeof borderColor === 'function') {
  45522. // Use the first data
  45523. borderColor = borderColor(seriesModel.getDataParams(0));
  45524. } // Using rect symbol defaultly
  45525. var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
  45526. var symbolType = data.getVisual('symbol');
  45527. var itemGroup = this._createItem(name, dataIndex, itemModel, legendModel, legendSymbolType, symbolType, itemAlign, color, borderColor, selectMode);
  45528. itemGroup.on('click', curry$2(dispatchSelectAction, name, null, api, excludeSeriesId)).on('mouseover', curry$2(dispatchHighlightAction, seriesModel.name, null, api, excludeSeriesId)).on('mouseout', curry$2(dispatchDownplayAction, seriesModel.name, null, api, excludeSeriesId));
  45529. legendDrawnMap.set(name, true);
  45530. } else {
  45531. // Legend to control data. In pie and funnel.
  45532. ecModel.eachRawSeries(function (seriesModel) {
  45533. // In case multiple series has same data name
  45534. if (legendDrawnMap.get(name)) {
  45535. return;
  45536. }
  45537. if (seriesModel.legendVisualProvider) {
  45538. var provider = seriesModel.legendVisualProvider;
  45539. if (!provider.containName(name)) {
  45540. return;
  45541. }
  45542. var idx = provider.indexOfName(name);
  45543. var color = provider.getItemVisual(idx, 'color');
  45544. var borderColor = provider.getItemVisual(idx, 'borderColor');
  45545. var legendSymbolType = 'roundRect';
  45546. var itemGroup = this._createItem(name, dataIndex, itemModel, legendModel, legendSymbolType, null, itemAlign, color, borderColor, selectMode); // FIXME: consider different series has items with the same name.
  45547. itemGroup.on('click', curry$2(dispatchSelectAction, null, name, api, excludeSeriesId)) // Should not specify the series name, consider legend controls
  45548. // more than one pie series.
  45549. .on('mouseover', curry$2(dispatchHighlightAction, null, name, api, excludeSeriesId)).on('mouseout', curry$2(dispatchDownplayAction, null, name, api, excludeSeriesId));
  45550. legendDrawnMap.set(name, true);
  45551. }
  45552. }, this);
  45553. }
  45554. }, this);
  45555. if (selector) {
  45556. this._createSelector(selector, legendModel, api, orient, selectorPosition);
  45557. }
  45558. },
  45559. _createSelector: function (selector, legendModel, api, orient, selectorPosition) {
  45560. var selectorGroup = this.getSelectorGroup();
  45561. each$8(selector, function (selectorItem) {
  45562. createSelectorButton(selectorItem);
  45563. });
  45564. function createSelectorButton(selectorItem) {
  45565. var type = selectorItem.type;
  45566. var labelText = new Text({
  45567. style: {
  45568. x: 0,
  45569. y: 0,
  45570. align: 'center',
  45571. verticalAlign: 'middle'
  45572. },
  45573. onclick: function () {
  45574. api.dispatchAction({
  45575. type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect'
  45576. });
  45577. }
  45578. });
  45579. selectorGroup.add(labelText);
  45580. var labelModel = legendModel.getModel('selectorLabel');
  45581. var emphasisLabelModel = legendModel.getModel('emphasis.selectorLabel');
  45582. setLabelStyle(labelText.style, labelText.hoverStyle = {}, labelModel, emphasisLabelModel, {
  45583. defaultText: selectorItem.title,
  45584. isRectText: false
  45585. });
  45586. setHoverStyle(labelText);
  45587. }
  45588. },
  45589. _createItem: function (name, dataIndex, itemModel, legendModel, legendSymbolType, symbolType, itemAlign, color, borderColor, selectMode) {
  45590. var itemWidth = legendModel.get('itemWidth');
  45591. var itemHeight = legendModel.get('itemHeight');
  45592. var inactiveColor = legendModel.get('inactiveColor');
  45593. var inactiveBorderColor = legendModel.get('inactiveBorderColor');
  45594. var symbolKeepAspect = legendModel.get('symbolKeepAspect');
  45595. var legendModelItemStyle = legendModel.getModel('itemStyle');
  45596. var isSelected = legendModel.isSelected(name);
  45597. var itemGroup = new Group$2();
  45598. var textStyleModel = itemModel.getModel('textStyle');
  45599. var itemIcon = itemModel.get('icon');
  45600. var tooltipModel = itemModel.getModel('tooltip');
  45601. var legendGlobalTooltipModel = tooltipModel.parentModel; // Use user given icon first
  45602. legendSymbolType = itemIcon || legendSymbolType;
  45603. var legendSymbol = createSymbol(legendSymbolType, 0, 0, itemWidth, itemHeight, isSelected ? color : inactiveColor, // symbolKeepAspect default true for legend
  45604. symbolKeepAspect == null ? true : symbolKeepAspect);
  45605. itemGroup.add(setSymbolStyle(legendSymbol, legendSymbolType, legendModelItemStyle, borderColor, inactiveBorderColor, isSelected)); // Compose symbols
  45606. // PENDING
  45607. if (!itemIcon && symbolType // At least show one symbol, can't be all none
  45608. && (symbolType !== legendSymbolType || symbolType === 'none')) {
  45609. var size = itemHeight * 0.8;
  45610. if (symbolType === 'none') {
  45611. symbolType = 'circle';
  45612. }
  45613. var legendSymbolCenter = createSymbol(symbolType, (itemWidth - size) / 2, (itemHeight - size) / 2, size, size, isSelected ? color : inactiveColor, // symbolKeepAspect default true for legend
  45614. symbolKeepAspect == null ? true : symbolKeepAspect); // Put symbol in the center
  45615. itemGroup.add(setSymbolStyle(legendSymbolCenter, symbolType, legendModelItemStyle, borderColor, inactiveBorderColor, isSelected));
  45616. }
  45617. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  45618. var textAlign = itemAlign;
  45619. var formatter = legendModel.get('formatter');
  45620. var content = name;
  45621. if (typeof formatter === 'string' && formatter) {
  45622. content = formatter.replace('{name}', name != null ? name : '');
  45623. } else if (typeof formatter === 'function') {
  45624. content = formatter(name);
  45625. }
  45626. itemGroup.add(new Text({
  45627. style: setTextStyle({}, textStyleModel, {
  45628. text: content,
  45629. x: textX,
  45630. y: itemHeight / 2,
  45631. textFill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
  45632. textAlign: textAlign,
  45633. textVerticalAlign: 'middle'
  45634. })
  45635. })); // Add a invisible rect to increase the area of mouse hover
  45636. var hitRect = new Rect({
  45637. shape: itemGroup.getBoundingRect(),
  45638. invisible: true,
  45639. tooltip: tooltipModel.get('show') ? extend({
  45640. content: name,
  45641. // Defaul formatter
  45642. formatter: legendGlobalTooltipModel.get('formatter', true) || function () {
  45643. return name;
  45644. },
  45645. formatterParams: {
  45646. componentType: 'legend',
  45647. legendIndex: legendModel.componentIndex,
  45648. name: name,
  45649. $vars: ['name']
  45650. }
  45651. }, tooltipModel.option) : null
  45652. });
  45653. itemGroup.add(hitRect);
  45654. itemGroup.eachChild(function (child) {
  45655. child.silent = true;
  45656. });
  45657. hitRect.silent = !selectMode;
  45658. this.getContentGroup().add(itemGroup);
  45659. setHoverStyle(itemGroup);
  45660. itemGroup.__legendDataIndex = dataIndex;
  45661. return itemGroup;
  45662. },
  45663. /**
  45664. * @protected
  45665. */
  45666. layoutInner: function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
  45667. var contentGroup = this.getContentGroup();
  45668. var selectorGroup = this.getSelectorGroup(); // Place items in contentGroup.
  45669. box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), maxSize.width, maxSize.height);
  45670. var contentRect = contentGroup.getBoundingRect();
  45671. var contentPos = [-contentRect.x, -contentRect.y];
  45672. if (selector) {
  45673. // Place buttons in selectorGroup
  45674. box( // Buttons in selectorGroup always layout horizontally
  45675. 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
  45676. var selectorRect = selectorGroup.getBoundingRect();
  45677. var selectorPos = [-selectorRect.x, -selectorRect.y];
  45678. var selectorButtonGap = legendModel.get('selectorButtonGap', true);
  45679. var orientIdx = legendModel.getOrient().index;
  45680. var wh = orientIdx === 0 ? 'width' : 'height';
  45681. var hw = orientIdx === 0 ? 'height' : 'width';
  45682. var yx = orientIdx === 0 ? 'y' : 'x';
  45683. if (selectorPosition === 'end') {
  45684. selectorPos[orientIdx] += contentRect[wh] + selectorButtonGap;
  45685. } else {
  45686. contentPos[orientIdx] += selectorRect[wh] + selectorButtonGap;
  45687. } //Always align selector to content as 'middle'
  45688. selectorPos[1 - orientIdx] += contentRect[hw] / 2 - selectorRect[hw] / 2;
  45689. selectorGroup.attr('position', selectorPos);
  45690. contentGroup.attr('position', contentPos);
  45691. var mainRect = {
  45692. x: 0,
  45693. y: 0
  45694. };
  45695. mainRect[wh] = contentRect[wh] + selectorButtonGap + selectorRect[wh];
  45696. mainRect[hw] = Math.max(contentRect[hw], selectorRect[hw]);
  45697. mainRect[yx] = Math.min(0, selectorRect[yx] + selectorPos[1 - orientIdx]);
  45698. return mainRect;
  45699. } else {
  45700. contentGroup.attr('position', contentPos);
  45701. return this.group.getBoundingRect();
  45702. }
  45703. },
  45704. /**
  45705. * @protected
  45706. */
  45707. remove: function () {
  45708. this.getContentGroup().removeAll();
  45709. this._isFirstRender = true;
  45710. }
  45711. });
  45712. function setSymbolStyle(symbol, symbolType, legendModelItemStyle, borderColor, inactiveBorderColor, isSelected) {
  45713. var itemStyle;
  45714. if (symbolType !== 'line' && symbolType.indexOf('empty') < 0) {
  45715. itemStyle = legendModelItemStyle.getItemStyle();
  45716. symbol.style.stroke = borderColor;
  45717. if (!isSelected) {
  45718. itemStyle.stroke = inactiveBorderColor;
  45719. }
  45720. } else {
  45721. itemStyle = legendModelItemStyle.getItemStyle(['borderWidth', 'borderColor']);
  45722. }
  45723. return symbol.setStyle(itemStyle);
  45724. }
  45725. function dispatchSelectAction(seriesName, dataName, api, excludeSeriesId) {
  45726. // downplay before unselect
  45727. dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId);
  45728. api.dispatchAction({
  45729. type: 'legendToggleSelect',
  45730. name: seriesName != null ? seriesName : dataName
  45731. }); // highlight after select
  45732. dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId);
  45733. }
  45734. function dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId) {
  45735. // If element hover will move to a hoverLayer.
  45736. var el = api.getZr().storage.getDisplayList()[0];
  45737. if (!(el && el.useHoverLayer)) {
  45738. api.dispatchAction({
  45739. type: 'highlight',
  45740. seriesName: seriesName,
  45741. name: dataName,
  45742. excludeSeriesId: excludeSeriesId
  45743. });
  45744. }
  45745. }
  45746. function dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId) {
  45747. // If element hover will move to a hoverLayer.
  45748. var el = api.getZr().storage.getDisplayList()[0];
  45749. if (!(el && el.useHoverLayer)) {
  45750. api.dispatchAction({
  45751. type: 'downplay',
  45752. seriesName: seriesName,
  45753. name: dataName,
  45754. excludeSeriesId: excludeSeriesId
  45755. });
  45756. }
  45757. }
  45758. /*
  45759. * Licensed to the Apache Software Foundation (ASF) under one
  45760. * or more contributor license agreements. See the NOTICE file
  45761. * distributed with this work for additional information
  45762. * regarding copyright ownership. The ASF licenses this file
  45763. * to you under the Apache License, Version 2.0 (the
  45764. * "License"); you may not use this file except in compliance
  45765. * with the License. You may obtain a copy of the License at
  45766. *
  45767. * http://www.apache.org/licenses/LICENSE-2.0
  45768. *
  45769. * Unless required by applicable law or agreed to in writing,
  45770. * software distributed under the License is distributed on an
  45771. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45772. * KIND, either express or implied. See the License for the
  45773. * specific language governing permissions and limitations
  45774. * under the License.
  45775. */
  45776. var legendFilter = function (ecModel) {
  45777. var legendModels = ecModel.findComponents({
  45778. mainType: 'legend'
  45779. });
  45780. if (legendModels && legendModels.length) {
  45781. ecModel.filterSeries(function (series) {
  45782. // If in any legend component the status is not selected.
  45783. // Because in legend series is assumed selected when it is not in the legend data.
  45784. for (var i = 0; i < legendModels.length; i++) {
  45785. if (!legendModels[i].isSelected(series.name)) {
  45786. return false;
  45787. }
  45788. }
  45789. return true;
  45790. });
  45791. }
  45792. };
  45793. /*
  45794. * Licensed to the Apache Software Foundation (ASF) under one
  45795. * or more contributor license agreements. See the NOTICE file
  45796. * distributed with this work for additional information
  45797. * regarding copyright ownership. The ASF licenses this file
  45798. * to you under the Apache License, Version 2.0 (the
  45799. * "License"); you may not use this file except in compliance
  45800. * with the License. You may obtain a copy of the License at
  45801. *
  45802. * http://www.apache.org/licenses/LICENSE-2.0
  45803. *
  45804. * Unless required by applicable law or agreed to in writing,
  45805. * software distributed under the License is distributed on an
  45806. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45807. * KIND, either express or implied. See the License for the
  45808. * specific language governing permissions and limitations
  45809. * under the License.
  45810. */
  45811. // Do not contain scrollable legend, for sake of file size.
  45812. registerProcessor(PRIORITY.PROCESSOR.SERIES_FILTER, legendFilter);
  45813. ComponentModel.registerSubTypeDefaulter('legend', function () {
  45814. // Default 'plain' when no type specified.
  45815. return 'plain';
  45816. });
  45817. /*
  45818. * Licensed to the Apache Software Foundation (ASF) under one
  45819. * or more contributor license agreements. See the NOTICE file
  45820. * distributed with this work for additional information
  45821. * regarding copyright ownership. The ASF licenses this file
  45822. * to you under the Apache License, Version 2.0 (the
  45823. * "License"); you may not use this file except in compliance
  45824. * with the License. You may obtain a copy of the License at
  45825. *
  45826. * http://www.apache.org/licenses/LICENSE-2.0
  45827. *
  45828. * Unless required by applicable law or agreed to in writing,
  45829. * software distributed under the License is distributed on an
  45830. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45831. * KIND, either express or implied. See the License for the
  45832. * specific language governing permissions and limitations
  45833. * under the License.
  45834. */
  45835. var ScrollableLegendModel = LegendModel.extend({
  45836. type: 'legend.scroll',
  45837. /**
  45838. * @param {number} scrollDataIndex
  45839. */
  45840. setScrollDataIndex: function (scrollDataIndex) {
  45841. this.option.scrollDataIndex = scrollDataIndex;
  45842. },
  45843. defaultOption: {
  45844. scrollDataIndex: 0,
  45845. pageButtonItemGap: 5,
  45846. pageButtonGap: null,
  45847. pageButtonPosition: 'end',
  45848. // 'start' or 'end'
  45849. pageFormatter: '{current}/{total}',
  45850. // If null/undefined, do not show page.
  45851. pageIcons: {
  45852. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  45853. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  45854. },
  45855. pageIconColor: '#2f4554',
  45856. pageIconInactiveColor: '#aaa',
  45857. pageIconSize: 15,
  45858. // Can be [10, 3], which represents [width, height]
  45859. pageTextStyle: {
  45860. color: '#333'
  45861. },
  45862. animationDurationUpdate: 800
  45863. },
  45864. /**
  45865. * @override
  45866. */
  45867. init: function (option, parentModel, ecModel, extraOpt) {
  45868. var inputPositionParams = getLayoutParams(option);
  45869. ScrollableLegendModel.superCall(this, 'init', option, parentModel, ecModel, extraOpt);
  45870. mergeAndNormalizeLayoutParams(this, option, inputPositionParams);
  45871. },
  45872. /**
  45873. * @override
  45874. */
  45875. mergeOption: function (option, extraOpt) {
  45876. ScrollableLegendModel.superCall(this, 'mergeOption', option, extraOpt);
  45877. mergeAndNormalizeLayoutParams(this, this.option, option);
  45878. }
  45879. }); // Do not `ignoreSize` to enable setting {left: 10, right: 10}.
  45880. function mergeAndNormalizeLayoutParams(legendModel, target, raw) {
  45881. var orient = legendModel.getOrient();
  45882. var ignoreSize = [1, 1];
  45883. ignoreSize[orient.index] = 0;
  45884. mergeLayoutParam(target, raw, {
  45885. type: 'box',
  45886. ignoreSize: ignoreSize
  45887. });
  45888. }
  45889. /*
  45890. * Licensed to the Apache Software Foundation (ASF) under one
  45891. * or more contributor license agreements. See the NOTICE file
  45892. * distributed with this work for additional information
  45893. * regarding copyright ownership. The ASF licenses this file
  45894. * to you under the Apache License, Version 2.0 (the
  45895. * "License"); you may not use this file except in compliance
  45896. * with the License. You may obtain a copy of the License at
  45897. *
  45898. * http://www.apache.org/licenses/LICENSE-2.0
  45899. *
  45900. * Unless required by applicable law or agreed to in writing,
  45901. * software distributed under the License is distributed on an
  45902. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45903. * KIND, either express or implied. See the License for the
  45904. * specific language governing permissions and limitations
  45905. * under the License.
  45906. */
  45907. /**
  45908. * Separate legend and scrollable legend to reduce package size.
  45909. */
  45910. var Group$3 = Group;
  45911. var WH = ['width', 'height'];
  45912. var XY = ['x', 'y'];
  45913. var ScrollableLegendView = LegendView.extend({
  45914. type: 'legend.scroll',
  45915. newlineDisabled: true,
  45916. init: function () {
  45917. ScrollableLegendView.superCall(this, 'init');
  45918. /**
  45919. * @private
  45920. * @type {number} For `scroll`.
  45921. */
  45922. this._currentIndex = 0;
  45923. /**
  45924. * @private
  45925. * @type {module:zrender/container/Group}
  45926. */
  45927. this.group.add(this._containerGroup = new Group$3());
  45928. this._containerGroup.add(this.getContentGroup());
  45929. /**
  45930. * @private
  45931. * @type {module:zrender/container/Group}
  45932. */
  45933. this.group.add(this._controllerGroup = new Group$3());
  45934. /**
  45935. *
  45936. * @private
  45937. */
  45938. this._showController;
  45939. },
  45940. /**
  45941. * @override
  45942. */
  45943. resetInner: function () {
  45944. ScrollableLegendView.superCall(this, 'resetInner');
  45945. this._controllerGroup.removeAll();
  45946. this._containerGroup.removeClipPath();
  45947. this._containerGroup.__rectSize = null;
  45948. },
  45949. /**
  45950. * @override
  45951. */
  45952. renderInner: function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
  45953. var me = this; // Render content items.
  45954. ScrollableLegendView.superCall(this, 'renderInner', itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition);
  45955. var controllerGroup = this._controllerGroup; // FIXME: support be 'auto' adapt to size number text length,
  45956. // e.g., '3/12345' should not overlap with the control arrow button.
  45957. var pageIconSize = legendModel.get('pageIconSize', true);
  45958. if (!isArray(pageIconSize)) {
  45959. pageIconSize = [pageIconSize, pageIconSize];
  45960. }
  45961. createPageButton('pagePrev', 0);
  45962. var pageTextStyleModel = legendModel.getModel('pageTextStyle');
  45963. controllerGroup.add(new Text({
  45964. name: 'pageText',
  45965. style: {
  45966. textFill: pageTextStyleModel.getTextColor(),
  45967. font: pageTextStyleModel.getFont(),
  45968. textVerticalAlign: 'middle',
  45969. textAlign: 'center'
  45970. },
  45971. silent: true
  45972. }));
  45973. createPageButton('pageNext', 1);
  45974. function createPageButton(name, iconIdx) {
  45975. var pageDataIndexName = name + 'DataIndex';
  45976. var icon = createIcon(legendModel.get('pageIcons', true)[legendModel.getOrient().name][iconIdx], {
  45977. // Buttons will be created in each render, so we do not need
  45978. // to worry about avoiding using legendModel kept in scope.
  45979. onclick: bind(me._pageGo, me, pageDataIndexName, legendModel, api)
  45980. }, {
  45981. x: -pageIconSize[0] / 2,
  45982. y: -pageIconSize[1] / 2,
  45983. width: pageIconSize[0],
  45984. height: pageIconSize[1]
  45985. });
  45986. icon.name = name;
  45987. controllerGroup.add(icon);
  45988. }
  45989. },
  45990. /**
  45991. * @override
  45992. */
  45993. layoutInner: function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
  45994. var selectorGroup = this.getSelectorGroup();
  45995. var orientIdx = legendModel.getOrient().index;
  45996. var wh = WH[orientIdx];
  45997. var xy = XY[orientIdx];
  45998. var hw = WH[1 - orientIdx];
  45999. var yx = XY[1 - orientIdx];
  46000. selector && box( // Buttons in selectorGroup always layout horizontally
  46001. 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
  46002. var selectorButtonGap = legendModel.get('selectorButtonGap', true);
  46003. var selectorRect = selectorGroup.getBoundingRect();
  46004. var selectorPos = [-selectorRect.x, -selectorRect.y];
  46005. var processMaxSize = clone(maxSize);
  46006. selector && (processMaxSize[wh] = maxSize[wh] - selectorRect[wh] - selectorButtonGap);
  46007. var mainRect = this._layoutContentAndController(legendModel, isFirstRender, processMaxSize, orientIdx, wh, hw, yx);
  46008. if (selector) {
  46009. if (selectorPosition === 'end') {
  46010. selectorPos[orientIdx] += mainRect[wh] + selectorButtonGap;
  46011. } else {
  46012. var offset = selectorRect[wh] + selectorButtonGap;
  46013. selectorPos[orientIdx] -= offset;
  46014. mainRect[xy] -= offset;
  46015. }
  46016. mainRect[wh] += selectorRect[wh] + selectorButtonGap;
  46017. selectorPos[1 - orientIdx] += mainRect[yx] + mainRect[hw] / 2 - selectorRect[hw] / 2;
  46018. mainRect[hw] = Math.max(mainRect[hw], selectorRect[hw]);
  46019. mainRect[yx] = Math.min(mainRect[yx], selectorRect[yx] + selectorPos[1 - orientIdx]);
  46020. selectorGroup.attr('position', selectorPos);
  46021. }
  46022. return mainRect;
  46023. },
  46024. _layoutContentAndController: function (legendModel, isFirstRender, maxSize, orientIdx, wh, hw, yx) {
  46025. var contentGroup = this.getContentGroup();
  46026. var containerGroup = this._containerGroup;
  46027. var controllerGroup = this._controllerGroup; // Place items in contentGroup.
  46028. box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), !orientIdx ? null : maxSize.width, orientIdx ? null : maxSize.height);
  46029. box( // Buttons in controller are layout always horizontally.
  46030. 'horizontal', controllerGroup, legendModel.get('pageButtonItemGap', true));
  46031. var contentRect = contentGroup.getBoundingRect();
  46032. var controllerRect = controllerGroup.getBoundingRect();
  46033. var showController = this._showController = contentRect[wh] > maxSize[wh];
  46034. var contentPos = [-contentRect.x, -contentRect.y]; // Remain contentPos when scroll animation perfroming.
  46035. // If first rendering, `contentGroup.position` is [0, 0], which
  46036. // does not make sense and may cause unexepcted animation if adopted.
  46037. if (!isFirstRender) {
  46038. contentPos[orientIdx] = contentGroup.position[orientIdx];
  46039. } // Layout container group based on 0.
  46040. var containerPos = [0, 0];
  46041. var controllerPos = [-controllerRect.x, -controllerRect.y];
  46042. var pageButtonGap = retrieve2(legendModel.get('pageButtonGap', true), legendModel.get('itemGap', true)); // Place containerGroup and controllerGroup and contentGroup.
  46043. if (showController) {
  46044. var pageButtonPosition = legendModel.get('pageButtonPosition', true); // controller is on the right / bottom.
  46045. if (pageButtonPosition === 'end') {
  46046. controllerPos[orientIdx] += maxSize[wh] - controllerRect[wh];
  46047. } // controller is on the left / top.
  46048. else {
  46049. containerPos[orientIdx] += controllerRect[wh] + pageButtonGap;
  46050. }
  46051. } // Always align controller to content as 'middle'.
  46052. controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
  46053. contentGroup.attr('position', contentPos);
  46054. containerGroup.attr('position', containerPos);
  46055. controllerGroup.attr('position', controllerPos); // Calculate `mainRect` and set `clipPath`.
  46056. // mainRect should not be calculated by `this.group.getBoundingRect()`
  46057. // for sake of the overflow.
  46058. var mainRect = {
  46059. x: 0,
  46060. y: 0
  46061. }; // Consider content may be overflow (should be clipped).
  46062. mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
  46063. mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]); // `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
  46064. mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);
  46065. containerGroup.__rectSize = maxSize[wh];
  46066. if (showController) {
  46067. var clipShape = {
  46068. x: 0,
  46069. y: 0
  46070. };
  46071. clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
  46072. clipShape[hw] = mainRect[hw];
  46073. containerGroup.setClipPath(new Rect({
  46074. shape: clipShape
  46075. })); // Consider content may be larger than container, container rect
  46076. // can not be obtained from `containerGroup.getBoundingRect()`.
  46077. containerGroup.__rectSize = clipShape[wh];
  46078. } else {
  46079. // Do not remove or ignore controller. Keep them set as placeholders.
  46080. controllerGroup.eachChild(function (child) {
  46081. child.attr({
  46082. invisible: true,
  46083. silent: true
  46084. });
  46085. });
  46086. } // Content translate animation.
  46087. var pageInfo = this._getPageInfo(legendModel);
  46088. pageInfo.pageIndex != null && updateProps(contentGroup, {
  46089. position: pageInfo.contentPosition
  46090. }, // When switch from "show controller" to "not show controller", view should be
  46091. // updated immediately without animation, otherwise causes weird effect.
  46092. showController ? legendModel : false);
  46093. this._updatePageInfoView(legendModel, pageInfo);
  46094. return mainRect;
  46095. },
  46096. _pageGo: function (to, legendModel, api) {
  46097. var scrollDataIndex = this._getPageInfo(legendModel)[to];
  46098. scrollDataIndex != null && api.dispatchAction({
  46099. type: 'legendScroll',
  46100. scrollDataIndex: scrollDataIndex,
  46101. legendId: legendModel.id
  46102. });
  46103. },
  46104. _updatePageInfoView: function (legendModel, pageInfo) {
  46105. var controllerGroup = this._controllerGroup;
  46106. each$1(['pagePrev', 'pageNext'], function (name) {
  46107. var canJump = pageInfo[name + 'DataIndex'] != null;
  46108. var icon = controllerGroup.childOfName(name);
  46109. if (icon) {
  46110. icon.setStyle('fill', canJump ? legendModel.get('pageIconColor', true) : legendModel.get('pageIconInactiveColor', true));
  46111. icon.cursor = canJump ? 'pointer' : 'default';
  46112. }
  46113. });
  46114. var pageText = controllerGroup.childOfName('pageText');
  46115. var pageFormatter = legendModel.get('pageFormatter');
  46116. var pageIndex = pageInfo.pageIndex;
  46117. var current = pageIndex != null ? pageIndex + 1 : 0;
  46118. var total = pageInfo.pageCount;
  46119. pageText && pageFormatter && pageText.setStyle('text', isString(pageFormatter) ? pageFormatter.replace('{current}', current).replace('{total}', total) : pageFormatter({
  46120. current: current,
  46121. total: total
  46122. }));
  46123. },
  46124. /**
  46125. * @param {module:echarts/model/Model} legendModel
  46126. * @return {Object} {
  46127. * contentPosition: Array.<number>, null when data item not found.
  46128. * pageIndex: number, null when data item not found.
  46129. * pageCount: number, always be a number, can be 0.
  46130. * pagePrevDataIndex: number, null when no previous page.
  46131. * pageNextDataIndex: number, null when no next page.
  46132. * }
  46133. */
  46134. _getPageInfo: function (legendModel) {
  46135. var scrollDataIndex = legendModel.get('scrollDataIndex', true);
  46136. var contentGroup = this.getContentGroup();
  46137. var containerRectSize = this._containerGroup.__rectSize;
  46138. var orientIdx = legendModel.getOrient().index;
  46139. var wh = WH[orientIdx];
  46140. var xy = XY[orientIdx];
  46141. var targetItemIndex = this._findTargetItemIndex(scrollDataIndex);
  46142. var children = contentGroup.children();
  46143. var targetItem = children[targetItemIndex];
  46144. var itemCount = children.length;
  46145. var pCount = !itemCount ? 0 : 1;
  46146. var result = {
  46147. contentPosition: contentGroup.position.slice(),
  46148. pageCount: pCount,
  46149. pageIndex: pCount - 1,
  46150. pagePrevDataIndex: null,
  46151. pageNextDataIndex: null
  46152. };
  46153. if (!targetItem) {
  46154. return result;
  46155. }
  46156. var targetItemInfo = getItemInfo(targetItem);
  46157. result.contentPosition[orientIdx] = -targetItemInfo.s; // Strategy:
  46158. // (1) Always align based on the left/top most item.
  46159. // (2) It is user-friendly that the last item shown in the
  46160. // current window is shown at the begining of next window.
  46161. // Otherwise if half of the last item is cut by the window,
  46162. // it will have no chance to display entirely.
  46163. // (3) Consider that item size probably be different, we
  46164. // have calculate pageIndex by size rather than item index,
  46165. // and we can not get page index directly by division.
  46166. // (4) The window is to narrow to contain more than
  46167. // one item, we should make sure that the page can be fliped.
  46168. for (var i = targetItemIndex + 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i <= itemCount; ++i) {
  46169. currItemInfo = getItemInfo(children[i]);
  46170. if ( // Half of the last item is out of the window.
  46171. !currItemInfo && winEndItemInfo.e > winStartItemInfo.s + containerRectSize || // If the current item does not intersect with the window, the new page
  46172. // can be started at the current item or the last item.
  46173. currItemInfo && !intersect(currItemInfo, winStartItemInfo.s)) {
  46174. if (winEndItemInfo.i > winStartItemInfo.i) {
  46175. winStartItemInfo = winEndItemInfo;
  46176. } else {
  46177. // e.g., when page size is smaller than item size.
  46178. winStartItemInfo = currItemInfo;
  46179. }
  46180. if (winStartItemInfo) {
  46181. if (result.pageNextDataIndex == null) {
  46182. result.pageNextDataIndex = winStartItemInfo.i;
  46183. }
  46184. ++result.pageCount;
  46185. }
  46186. }
  46187. winEndItemInfo = currItemInfo;
  46188. }
  46189. for (var i = targetItemIndex - 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i >= -1; --i) {
  46190. currItemInfo = getItemInfo(children[i]);
  46191. if ( // If the the end item does not intersect with the window started
  46192. // from the current item, a page can be settled.
  46193. (!currItemInfo || !intersect(winEndItemInfo, currItemInfo.s)) && // e.g., when page size is smaller than item size.
  46194. winStartItemInfo.i < winEndItemInfo.i) {
  46195. winEndItemInfo = winStartItemInfo;
  46196. if (result.pagePrevDataIndex == null) {
  46197. result.pagePrevDataIndex = winStartItemInfo.i;
  46198. }
  46199. ++result.pageCount;
  46200. ++result.pageIndex;
  46201. }
  46202. winStartItemInfo = currItemInfo;
  46203. }
  46204. return result;
  46205. function getItemInfo(el) {
  46206. if (el) {
  46207. var itemRect = el.getBoundingRect();
  46208. var start = itemRect[xy] + el.position[orientIdx];
  46209. return {
  46210. s: start,
  46211. e: start + itemRect[wh],
  46212. i: el.__legendDataIndex
  46213. };
  46214. }
  46215. }
  46216. function intersect(itemInfo, winStart) {
  46217. return itemInfo.e >= winStart && itemInfo.s <= winStart + containerRectSize;
  46218. }
  46219. },
  46220. _findTargetItemIndex: function (targetDataIndex) {
  46221. if (!this._showController) {
  46222. return 0;
  46223. }
  46224. var index;
  46225. var contentGroup = this.getContentGroup();
  46226. var defaultIndex;
  46227. contentGroup.eachChild(function (child, idx) {
  46228. var legendDataIdx = child.__legendDataIndex; // FIXME
  46229. // If the given targetDataIndex (from model) is illegal,
  46230. // we use defualtIndex. But the index on the legend model and
  46231. // action payload is still illegal. That case will not be
  46232. // changed until some scenario requires.
  46233. if (defaultIndex == null && legendDataIdx != null) {
  46234. defaultIndex = idx;
  46235. }
  46236. if (legendDataIdx === targetDataIndex) {
  46237. index = idx;
  46238. }
  46239. });
  46240. return index != null ? index : defaultIndex;
  46241. }
  46242. });
  46243. /*
  46244. * Licensed to the Apache Software Foundation (ASF) under one
  46245. * or more contributor license agreements. See the NOTICE file
  46246. * distributed with this work for additional information
  46247. * regarding copyright ownership. The ASF licenses this file
  46248. * to you under the Apache License, Version 2.0 (the
  46249. * "License"); you may not use this file except in compliance
  46250. * with the License. You may obtain a copy of the License at
  46251. *
  46252. * http://www.apache.org/licenses/LICENSE-2.0
  46253. *
  46254. * Unless required by applicable law or agreed to in writing,
  46255. * software distributed under the License is distributed on an
  46256. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46257. * KIND, either express or implied. See the License for the
  46258. * specific language governing permissions and limitations
  46259. * under the License.
  46260. */
  46261. /**
  46262. * @event legendScroll
  46263. * @type {Object}
  46264. * @property {string} type 'legendScroll'
  46265. * @property {string} scrollDataIndex
  46266. */
  46267. registerAction('legendScroll', 'legendscroll', function (payload, ecModel) {
  46268. var scrollDataIndex = payload.scrollDataIndex;
  46269. scrollDataIndex != null && ecModel.eachComponent({
  46270. mainType: 'legend',
  46271. subType: 'scroll',
  46272. query: payload
  46273. }, function (legendModel) {
  46274. legendModel.setScrollDataIndex(scrollDataIndex);
  46275. });
  46276. });
  46277. /*
  46278. * Licensed to the Apache Software Foundation (ASF) under one
  46279. * or more contributor license agreements. See the NOTICE file
  46280. * distributed with this work for additional information
  46281. * regarding copyright ownership. The ASF licenses this file
  46282. * to you under the Apache License, Version 2.0 (the
  46283. * "License"); you may not use this file except in compliance
  46284. * with the License. You may obtain a copy of the License at
  46285. *
  46286. * http://www.apache.org/licenses/LICENSE-2.0
  46287. *
  46288. * Unless required by applicable law or agreed to in writing,
  46289. * software distributed under the License is distributed on an
  46290. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46291. * KIND, either express or implied. See the License for the
  46292. * specific language governing permissions and limitations
  46293. * under the License.
  46294. */
  46295. /**
  46296. * Legend component entry file8
  46297. */
  46298. /*
  46299. * Licensed to the Apache Software Foundation (ASF) under one
  46300. * or more contributor license agreements. See the NOTICE file
  46301. * distributed with this work for additional information
  46302. * regarding copyright ownership. The ASF licenses this file
  46303. * to you under the Apache License, Version 2.0 (the
  46304. * "License"); you may not use this file except in compliance
  46305. * with the License. You may obtain a copy of the License at
  46306. *
  46307. * http://www.apache.org/licenses/LICENSE-2.0
  46308. *
  46309. * Unless required by applicable law or agreed to in writing,
  46310. * software distributed under the License is distributed on an
  46311. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46312. * KIND, either express or implied. See the License for the
  46313. * specific language governing permissions and limitations
  46314. * under the License.
  46315. */
  46316. /**
  46317. * @param {Object} finder contains {seriesIndex, dataIndex, dataIndexInside}
  46318. * @param {module:echarts/model/Global} ecModel
  46319. * @return {Object} {point: [x, y], el: ...} point Will not be null.
  46320. */
  46321. var findPointFromSeries = function (finder, ecModel) {
  46322. var point = [];
  46323. var seriesIndex = finder.seriesIndex;
  46324. var seriesModel;
  46325. if (seriesIndex == null || !(seriesModel = ecModel.getSeriesByIndex(seriesIndex))) {
  46326. return {
  46327. point: []
  46328. };
  46329. }
  46330. var data = seriesModel.getData();
  46331. var dataIndex = queryDataIndex(data, finder);
  46332. if (dataIndex == null || dataIndex < 0 || isArray(dataIndex)) {
  46333. return {
  46334. point: []
  46335. };
  46336. }
  46337. var el = data.getItemGraphicEl(dataIndex);
  46338. var coordSys = seriesModel.coordinateSystem;
  46339. if (seriesModel.getTooltipPosition) {
  46340. point = seriesModel.getTooltipPosition(dataIndex) || [];
  46341. } else if (coordSys && coordSys.dataToPoint) {
  46342. point = coordSys.dataToPoint(data.getValues(map(coordSys.dimensions, function (dim) {
  46343. return data.mapDimension(dim);
  46344. }), dataIndex, true)) || [];
  46345. } else if (el) {
  46346. // Use graphic bounding rect
  46347. var rect = el.getBoundingRect().clone();
  46348. rect.applyTransform(el.transform);
  46349. point = [rect.x + rect.width / 2, rect.y + rect.height / 2];
  46350. }
  46351. return {
  46352. point: point,
  46353. el: el
  46354. };
  46355. };
  46356. /*
  46357. * Licensed to the Apache Software Foundation (ASF) under one
  46358. * or more contributor license agreements. See the NOTICE file
  46359. * distributed with this work for additional information
  46360. * regarding copyright ownership. The ASF licenses this file
  46361. * to you under the Apache License, Version 2.0 (the
  46362. * "License"); you may not use this file except in compliance
  46363. * with the License. You may obtain a copy of the License at
  46364. *
  46365. * http://www.apache.org/licenses/LICENSE-2.0
  46366. *
  46367. * Unless required by applicable law or agreed to in writing,
  46368. * software distributed under the License is distributed on an
  46369. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46370. * KIND, either express or implied. See the License for the
  46371. * specific language governing permissions and limitations
  46372. * under the License.
  46373. */
  46374. var each$9 = each$1;
  46375. var curry$3 = curry;
  46376. var inner$9 = makeInner();
  46377. /**
  46378. * Basic logic: check all axis, if they do not demand show/highlight,
  46379. * then hide/downplay them.
  46380. *
  46381. * @param {Object} coordSysAxesInfo
  46382. * @param {Object} payload
  46383. * @param {string} [payload.currTrigger] 'click' | 'mousemove' | 'leave'
  46384. * @param {Array.<number>} [payload.x] x and y, which are mandatory, specify a point to
  46385. * trigger axisPointer and tooltip.
  46386. * @param {Array.<number>} [payload.y] x and y, which are mandatory, specify a point to
  46387. * trigger axisPointer and tooltip.
  46388. * @param {Object} [payload.seriesIndex] finder, optional, restrict target axes.
  46389. * @param {Object} [payload.dataIndex] finder, restrict target axes.
  46390. * @param {Object} [payload.axesInfo] finder, restrict target axes.
  46391. * [{
  46392. * axisDim: 'x'|'y'|'angle'|...,
  46393. * axisIndex: ...,
  46394. * value: ...
  46395. * }, ...]
  46396. * @param {Function} [payload.dispatchAction]
  46397. * @param {Object} [payload.tooltipOption]
  46398. * @param {Object|Array.<number>|Function} [payload.position] Tooltip position,
  46399. * which can be specified in dispatchAction
  46400. * @param {module:echarts/model/Global} ecModel
  46401. * @param {module:echarts/ExtensionAPI} api
  46402. * @return {Object} content of event obj for echarts.connect.
  46403. */
  46404. var axisTrigger = function (payload, ecModel, api) {
  46405. var currTrigger = payload.currTrigger;
  46406. var point = [payload.x, payload.y];
  46407. var finder = payload;
  46408. var dispatchAction = payload.dispatchAction || bind(api.dispatchAction, api);
  46409. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo; // Pending
  46410. // See #6121. But we are not able to reproduce it yet.
  46411. if (!coordSysAxesInfo) {
  46412. return;
  46413. }
  46414. if (illegalPoint(point)) {
  46415. // Used in the default behavior of `connection`: use the sample seriesIndex
  46416. // and dataIndex. And also used in the tooltipView trigger.
  46417. point = findPointFromSeries({
  46418. seriesIndex: finder.seriesIndex,
  46419. // Do not use dataIndexInside from other ec instance.
  46420. // FIXME: auto detect it?
  46421. dataIndex: finder.dataIndex
  46422. }, ecModel).point;
  46423. }
  46424. var isIllegalPoint = illegalPoint(point); // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
  46425. // Notice: In this case, it is difficult to get the `point` (which is necessary to show
  46426. // tooltip, so if point is not given, we just use the point found by sample seriesIndex
  46427. // and dataIndex.
  46428. var inputAxesInfo = finder.axesInfo;
  46429. var axesInfo = coordSysAxesInfo.axesInfo;
  46430. var shouldHide = currTrigger === 'leave' || illegalPoint(point);
  46431. var outputFinder = {};
  46432. var showValueMap = {};
  46433. var dataByCoordSys = {
  46434. list: [],
  46435. map: {}
  46436. };
  46437. var updaters = {
  46438. showPointer: curry$3(showPointer, showValueMap),
  46439. showTooltip: curry$3(showTooltip, dataByCoordSys)
  46440. }; // Process for triggered axes.
  46441. each$9(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
  46442. // If a point given, it must be contained by the coordinate system.
  46443. var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
  46444. each$9(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
  46445. var axis = axisInfo.axis;
  46446. var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo); // If no inputAxesInfo, no axis is restricted.
  46447. if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
  46448. var val = inputAxisInfo && inputAxisInfo.value;
  46449. if (val == null && !isIllegalPoint) {
  46450. val = axis.pointToData(point);
  46451. }
  46452. val != null && processOnAxis(axisInfo, val, updaters, false, outputFinder);
  46453. }
  46454. });
  46455. }); // Process for linked axes.
  46456. var linkTriggers = {};
  46457. each$9(axesInfo, function (tarAxisInfo, tarKey) {
  46458. var linkGroup = tarAxisInfo.linkGroup; // If axis has been triggered in the previous stage, it should not be triggered by link.
  46459. if (linkGroup && !showValueMap[tarKey]) {
  46460. each$9(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
  46461. var srcValItem = showValueMap[srcKey]; // If srcValItem exist, source axis is triggered, so link to target axis.
  46462. if (srcAxisInfo !== tarAxisInfo && srcValItem) {
  46463. var val = srcValItem.value;
  46464. linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo))));
  46465. linkTriggers[tarAxisInfo.key] = val;
  46466. }
  46467. });
  46468. }
  46469. });
  46470. each$9(linkTriggers, function (val, tarKey) {
  46471. processOnAxis(axesInfo[tarKey], val, updaters, true, outputFinder);
  46472. });
  46473. updateModelActually(showValueMap, axesInfo, outputFinder);
  46474. dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
  46475. dispatchHighDownActually(axesInfo, dispatchAction, api);
  46476. return outputFinder;
  46477. };
  46478. function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
  46479. var axis = axisInfo.axis;
  46480. if (axis.scale.isBlank() || !axis.containData(newValue)) {
  46481. return;
  46482. }
  46483. if (!axisInfo.involveSeries) {
  46484. updaters.showPointer(axisInfo, newValue);
  46485. return;
  46486. } // Heavy calculation. So put it after axis.containData checking.
  46487. var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
  46488. var payloadBatch = payloadInfo.payloadBatch;
  46489. var snapToValue = payloadInfo.snapToValue; // Fill content of event obj for echarts.connect.
  46490. // By defualt use the first involved series data as a sample to connect.
  46491. if (payloadBatch[0] && outputFinder.seriesIndex == null) {
  46492. extend(outputFinder, payloadBatch[0]);
  46493. } // If no linkSource input, this process is for collecting link
  46494. // target, where snap should not be accepted.
  46495. if (!dontSnap && axisInfo.snap) {
  46496. if (axis.containData(snapToValue) && snapToValue != null) {
  46497. newValue = snapToValue;
  46498. }
  46499. }
  46500. updaters.showPointer(axisInfo, newValue, payloadBatch, outputFinder); // Tooltip should always be snapToValue, otherwise there will be
  46501. // incorrect "axis value ~ series value" mapping displayed in tooltip.
  46502. updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
  46503. }
  46504. function buildPayloadsBySeries(value, axisInfo) {
  46505. var axis = axisInfo.axis;
  46506. var dim = axis.dim;
  46507. var snapToValue = value;
  46508. var payloadBatch = [];
  46509. var minDist = Number.MAX_VALUE;
  46510. var minDiff = -1;
  46511. each$9(axisInfo.seriesModels, function (series, idx) {
  46512. var dataDim = series.getData().mapDimension(dim, true);
  46513. var seriesNestestValue;
  46514. var dataIndices;
  46515. if (series.getAxisTooltipData) {
  46516. var result = series.getAxisTooltipData(dataDim, value, axis);
  46517. dataIndices = result.dataIndices;
  46518. seriesNestestValue = result.nestestValue;
  46519. } else {
  46520. dataIndices = series.getData().indicesOfNearest(dataDim[0], value, // Add a threshold to avoid find the wrong dataIndex
  46521. // when data length is not same.
  46522. // false,
  46523. axis.type === 'category' ? 0.5 : null);
  46524. if (!dataIndices.length) {
  46525. return;
  46526. }
  46527. seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
  46528. }
  46529. if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
  46530. return;
  46531. }
  46532. var diff = value - seriesNestestValue;
  46533. var dist = Math.abs(diff); // Consider category case
  46534. if (dist <= minDist) {
  46535. if (dist < minDist || diff >= 0 && minDiff < 0) {
  46536. minDist = dist;
  46537. minDiff = diff;
  46538. snapToValue = seriesNestestValue;
  46539. payloadBatch.length = 0;
  46540. }
  46541. each$9(dataIndices, function (dataIndex) {
  46542. payloadBatch.push({
  46543. seriesIndex: series.seriesIndex,
  46544. dataIndexInside: dataIndex,
  46545. dataIndex: series.getData().getRawIndex(dataIndex)
  46546. });
  46547. });
  46548. }
  46549. });
  46550. return {
  46551. payloadBatch: payloadBatch,
  46552. snapToValue: snapToValue
  46553. };
  46554. }
  46555. function showPointer(showValueMap, axisInfo, value, payloadBatch) {
  46556. showValueMap[axisInfo.key] = {
  46557. value: value,
  46558. payloadBatch: payloadBatch
  46559. };
  46560. }
  46561. function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
  46562. var payloadBatch = payloadInfo.payloadBatch;
  46563. var axis = axisInfo.axis;
  46564. var axisModel = axis.model;
  46565. var axisPointerModel = axisInfo.axisPointerModel; // If no data, do not create anything in dataByCoordSys,
  46566. // whose length will be used to judge whether dispatch action.
  46567. if (!axisInfo.triggerTooltip || !payloadBatch.length) {
  46568. return;
  46569. }
  46570. var coordSysModel = axisInfo.coordSys.model;
  46571. var coordSysKey = makeKey(coordSysModel);
  46572. var coordSysItem = dataByCoordSys.map[coordSysKey];
  46573. if (!coordSysItem) {
  46574. coordSysItem = dataByCoordSys.map[coordSysKey] = {
  46575. coordSysId: coordSysModel.id,
  46576. coordSysIndex: coordSysModel.componentIndex,
  46577. coordSysType: coordSysModel.type,
  46578. coordSysMainType: coordSysModel.mainType,
  46579. dataByAxis: []
  46580. };
  46581. dataByCoordSys.list.push(coordSysItem);
  46582. }
  46583. coordSysItem.dataByAxis.push({
  46584. axisDim: axis.dim,
  46585. axisIndex: axisModel.componentIndex,
  46586. axisType: axisModel.type,
  46587. axisId: axisModel.id,
  46588. value: value,
  46589. // Caustion: viewHelper.getValueLabel is actually on "view stage", which
  46590. // depends that all models have been updated. So it should not be performed
  46591. // here. Considering axisPointerModel used here is volatile, which is hard
  46592. // to be retrieve in TooltipView, we prepare parameters here.
  46593. valueLabelOpt: {
  46594. precision: axisPointerModel.get('label.precision'),
  46595. formatter: axisPointerModel.get('label.formatter')
  46596. },
  46597. seriesDataIndices: payloadBatch.slice()
  46598. });
  46599. }
  46600. function updateModelActually(showValueMap, axesInfo, outputFinder) {
  46601. var outputAxesInfo = outputFinder.axesInfo = []; // Basic logic: If no 'show' required, 'hide' this axisPointer.
  46602. each$9(axesInfo, function (axisInfo, key) {
  46603. var option = axisInfo.axisPointerModel.option;
  46604. var valItem = showValueMap[key];
  46605. if (valItem) {
  46606. !axisInfo.useHandle && (option.status = 'show');
  46607. option.value = valItem.value; // For label formatter param and highlight.
  46608. option.seriesDataIndices = (valItem.payloadBatch || []).slice();
  46609. } // When always show (e.g., handle used), remain
  46610. // original value and status.
  46611. else {
  46612. // If hide, value still need to be set, consider
  46613. // click legend to toggle axis blank.
  46614. !axisInfo.useHandle && (option.status = 'hide');
  46615. } // If status is 'hide', should be no info in payload.
  46616. option.status === 'show' && outputAxesInfo.push({
  46617. axisDim: axisInfo.axis.dim,
  46618. axisIndex: axisInfo.axis.model.componentIndex,
  46619. value: option.value
  46620. });
  46621. });
  46622. }
  46623. function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
  46624. // Basic logic: If no showTip required, hideTip will be dispatched.
  46625. if (illegalPoint(point) || !dataByCoordSys.list.length) {
  46626. dispatchAction({
  46627. type: 'hideTip'
  46628. });
  46629. return;
  46630. } // In most case only one axis (or event one series is used). It is
  46631. // convinient to fetch payload.seriesIndex and payload.dataIndex
  46632. // dirtectly. So put the first seriesIndex and dataIndex of the first
  46633. // axis on the payload.
  46634. var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
  46635. dispatchAction({
  46636. type: 'showTip',
  46637. escapeConnect: true,
  46638. x: point[0],
  46639. y: point[1],
  46640. tooltipOption: payload.tooltipOption,
  46641. position: payload.position,
  46642. dataIndexInside: sampleItem.dataIndexInside,
  46643. dataIndex: sampleItem.dataIndex,
  46644. seriesIndex: sampleItem.seriesIndex,
  46645. dataByCoordSys: dataByCoordSys.list
  46646. });
  46647. }
  46648. function dispatchHighDownActually(axesInfo, dispatchAction, api) {
  46649. // FIXME
  46650. // highlight status modification shoule be a stage of main process?
  46651. // (Consider confilct (e.g., legend and axisPointer) and setOption)
  46652. var zr = api.getZr();
  46653. var highDownKey = 'axisPointerLastHighlights';
  46654. var lastHighlights = inner$9(zr)[highDownKey] || {};
  46655. var newHighlights = inner$9(zr)[highDownKey] = {}; // Update highlight/downplay status according to axisPointer model.
  46656. // Build hash map and remove duplicate incidentally.
  46657. each$9(axesInfo, function (axisInfo, key) {
  46658. var option = axisInfo.axisPointerModel.option;
  46659. option.status === 'show' && each$9(option.seriesDataIndices, function (batchItem) {
  46660. var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
  46661. newHighlights[key] = batchItem;
  46662. });
  46663. }); // Diff.
  46664. var toHighlight = [];
  46665. var toDownplay = [];
  46666. each$1(lastHighlights, function (batchItem, key) {
  46667. !newHighlights[key] && toDownplay.push(batchItem);
  46668. });
  46669. each$1(newHighlights, function (batchItem, key) {
  46670. !lastHighlights[key] && toHighlight.push(batchItem);
  46671. });
  46672. toDownplay.length && api.dispatchAction({
  46673. type: 'downplay',
  46674. escapeConnect: true,
  46675. batch: toDownplay
  46676. });
  46677. toHighlight.length && api.dispatchAction({
  46678. type: 'highlight',
  46679. escapeConnect: true,
  46680. batch: toHighlight
  46681. });
  46682. }
  46683. function findInputAxisInfo(inputAxesInfo, axisInfo) {
  46684. for (var i = 0; i < (inputAxesInfo || []).length; i++) {
  46685. var inputAxisInfo = inputAxesInfo[i];
  46686. if (axisInfo.axis.dim === inputAxisInfo.axisDim && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex) {
  46687. return inputAxisInfo;
  46688. }
  46689. }
  46690. }
  46691. function makeMapperParam(axisInfo) {
  46692. var axisModel = axisInfo.axis.model;
  46693. var item = {};
  46694. var dim = item.axisDim = axisInfo.axis.dim;
  46695. item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
  46696. item.axisName = item[dim + 'AxisName'] = axisModel.name;
  46697. item.axisId = item[dim + 'AxisId'] = axisModel.id;
  46698. return item;
  46699. }
  46700. function illegalPoint(point) {
  46701. return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
  46702. }
  46703. /*
  46704. * Licensed to the Apache Software Foundation (ASF) under one
  46705. * or more contributor license agreements. See the NOTICE file
  46706. * distributed with this work for additional information
  46707. * regarding copyright ownership. The ASF licenses this file
  46708. * to you under the Apache License, Version 2.0 (the
  46709. * "License"); you may not use this file except in compliance
  46710. * with the License. You may obtain a copy of the License at
  46711. *
  46712. * http://www.apache.org/licenses/LICENSE-2.0
  46713. *
  46714. * Unless required by applicable law or agreed to in writing,
  46715. * software distributed under the License is distributed on an
  46716. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46717. * KIND, either express or implied. See the License for the
  46718. * specific language governing permissions and limitations
  46719. * under the License.
  46720. */
  46721. var AxisPointerModel = extendComponentModel({
  46722. type: 'axisPointer',
  46723. coordSysAxesInfo: null,
  46724. defaultOption: {
  46725. // 'auto' means that show when triggered by tooltip or handle.
  46726. show: 'auto',
  46727. // 'click' | 'mousemove' | 'none'
  46728. triggerOn: null,
  46729. // set default in AxisPonterView.js
  46730. zlevel: 0,
  46731. z: 50,
  46732. type: 'line',
  46733. // 'line' 'shadow' 'cross' 'none'.
  46734. // axispointer triggered by tootip determine snap automatically,
  46735. // see `modelHelper`.
  46736. snap: false,
  46737. triggerTooltip: true,
  46738. value: null,
  46739. status: null,
  46740. // Init value depends on whether handle is used.
  46741. // [group0, group1, ...]
  46742. // Each group can be: {
  46743. // mapper: function () {},
  46744. // singleTooltip: 'multiple', // 'multiple' or 'single'
  46745. // xAxisId: ...,
  46746. // yAxisName: ...,
  46747. // angleAxisIndex: ...
  46748. // }
  46749. // mapper: can be ignored.
  46750. // input: {axisInfo, value}
  46751. // output: {axisInfo, value}
  46752. link: [],
  46753. // Do not set 'auto' here, otherwise global animation: false
  46754. // will not effect at this axispointer.
  46755. animation: null,
  46756. animationDurationUpdate: 200,
  46757. lineStyle: {
  46758. color: '#aaa',
  46759. width: 1,
  46760. type: 'solid'
  46761. },
  46762. shadowStyle: {
  46763. color: 'rgba(150,150,150,0.3)'
  46764. },
  46765. label: {
  46766. show: true,
  46767. formatter: null,
  46768. // string | Function
  46769. precision: 'auto',
  46770. // Or a number like 0, 1, 2 ...
  46771. margin: 3,
  46772. color: '#fff',
  46773. padding: [5, 7, 5, 7],
  46774. backgroundColor: 'auto',
  46775. // default: axis line color
  46776. borderColor: null,
  46777. borderWidth: 0,
  46778. shadowBlur: 3,
  46779. shadowColor: '#aaa' // Considering applicability, common style should
  46780. // better not have shadowOffset.
  46781. // shadowOffsetX: 0,
  46782. // shadowOffsetY: 2
  46783. },
  46784. handle: {
  46785. show: false,
  46786. /* eslint-disable */
  46787. icon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z',
  46788. // jshint ignore:line
  46789. /* eslint-enable */
  46790. size: 45,
  46791. // handle margin is from symbol center to axis, which is stable when circular move.
  46792. margin: 50,
  46793. // color: '#1b8bbd'
  46794. // color: '#2f4554'
  46795. color: '#333',
  46796. shadowBlur: 3,
  46797. shadowColor: '#aaa',
  46798. shadowOffsetX: 0,
  46799. shadowOffsetY: 2,
  46800. // For mobile performance
  46801. throttle: 40
  46802. }
  46803. }
  46804. });
  46805. /*
  46806. * Licensed to the Apache Software Foundation (ASF) under one
  46807. * or more contributor license agreements. See the NOTICE file
  46808. * distributed with this work for additional information
  46809. * regarding copyright ownership. The ASF licenses this file
  46810. * to you under the Apache License, Version 2.0 (the
  46811. * "License"); you may not use this file except in compliance
  46812. * with the License. You may obtain a copy of the License at
  46813. *
  46814. * http://www.apache.org/licenses/LICENSE-2.0
  46815. *
  46816. * Unless required by applicable law or agreed to in writing,
  46817. * software distributed under the License is distributed on an
  46818. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46819. * KIND, either express or implied. See the License for the
  46820. * specific language governing permissions and limitations
  46821. * under the License.
  46822. */
  46823. var inner$10 = makeInner();
  46824. var each$10 = each$1;
  46825. /**
  46826. * @param {string} key
  46827. * @param {module:echarts/ExtensionAPI} api
  46828. * @param {Function} handler
  46829. * param: {string} currTrigger
  46830. * param: {Array.<number>} point
  46831. */
  46832. function register(key, api, handler) {
  46833. if (env$1.node) {
  46834. return;
  46835. }
  46836. var zr = api.getZr();
  46837. inner$10(zr).records || (inner$10(zr).records = {});
  46838. initGlobalListeners(zr, api);
  46839. var record = inner$10(zr).records[key] || (inner$10(zr).records[key] = {});
  46840. record.handler = handler;
  46841. }
  46842. function initGlobalListeners(zr, api) {
  46843. if (inner$10(zr).initialized) {
  46844. return;
  46845. }
  46846. inner$10(zr).initialized = true;
  46847. useHandler('click', curry(doEnter, 'click'));
  46848. useHandler('mousemove', curry(doEnter, 'mousemove')); // useHandler('mouseout', onLeave);
  46849. useHandler('globalout', onLeave);
  46850. function useHandler(eventType, cb) {
  46851. zr.on(eventType, function (e) {
  46852. var dis = makeDispatchAction(api);
  46853. each$10(inner$10(zr).records, function (record) {
  46854. record && cb(record, e, dis.dispatchAction);
  46855. });
  46856. dispatchTooltipFinally(dis.pendings, api);
  46857. });
  46858. }
  46859. }
  46860. function dispatchTooltipFinally(pendings, api) {
  46861. var showLen = pendings.showTip.length;
  46862. var hideLen = pendings.hideTip.length;
  46863. var actuallyPayload;
  46864. if (showLen) {
  46865. actuallyPayload = pendings.showTip[showLen - 1];
  46866. } else if (hideLen) {
  46867. actuallyPayload = pendings.hideTip[hideLen - 1];
  46868. }
  46869. if (actuallyPayload) {
  46870. actuallyPayload.dispatchAction = null;
  46871. api.dispatchAction(actuallyPayload);
  46872. }
  46873. }
  46874. function onLeave(record, e, dispatchAction) {
  46875. record.handler('leave', null, dispatchAction);
  46876. }
  46877. function doEnter(currTrigger, record, e, dispatchAction) {
  46878. record.handler(currTrigger, e, dispatchAction);
  46879. }
  46880. function makeDispatchAction(api) {
  46881. var pendings = {
  46882. showTip: [],
  46883. hideTip: []
  46884. }; // FIXME
  46885. // better approach?
  46886. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  46887. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  46888. // So we have to add "final stage" to merge those dispatched actions.
  46889. var dispatchAction = function (payload) {
  46890. var pendingList = pendings[payload.type];
  46891. if (pendingList) {
  46892. pendingList.push(payload);
  46893. } else {
  46894. payload.dispatchAction = dispatchAction;
  46895. api.dispatchAction(payload);
  46896. }
  46897. };
  46898. return {
  46899. dispatchAction: dispatchAction,
  46900. pendings: pendings
  46901. };
  46902. }
  46903. /**
  46904. * @param {string} key
  46905. * @param {module:echarts/ExtensionAPI} api
  46906. */
  46907. function unregister(key, api) {
  46908. if (env$1.node) {
  46909. return;
  46910. }
  46911. var zr = api.getZr();
  46912. var record = (inner$10(zr).records || {})[key];
  46913. if (record) {
  46914. inner$10(zr).records[key] = null;
  46915. }
  46916. }
  46917. /*
  46918. * Licensed to the Apache Software Foundation (ASF) under one
  46919. * or more contributor license agreements. See the NOTICE file
  46920. * distributed with this work for additional information
  46921. * regarding copyright ownership. The ASF licenses this file
  46922. * to you under the Apache License, Version 2.0 (the
  46923. * "License"); you may not use this file except in compliance
  46924. * with the License. You may obtain a copy of the License at
  46925. *
  46926. * http://www.apache.org/licenses/LICENSE-2.0
  46927. *
  46928. * Unless required by applicable law or agreed to in writing,
  46929. * software distributed under the License is distributed on an
  46930. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46931. * KIND, either express or implied. See the License for the
  46932. * specific language governing permissions and limitations
  46933. * under the License.
  46934. */
  46935. var AxisPointerView = extendComponentView({
  46936. type: 'axisPointer',
  46937. render: function (globalAxisPointerModel, ecModel, api) {
  46938. var globalTooltipModel = ecModel.getComponent('tooltip');
  46939. var triggerOn = globalAxisPointerModel.get('triggerOn') || globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click'; // Register global listener in AxisPointerView to enable
  46940. // AxisPointerView to be independent to Tooltip.
  46941. register('axisPointer', api, function (currTrigger, e, dispatchAction) {
  46942. // If 'none', it is not controlled by mouse totally.
  46943. if (triggerOn !== 'none' && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)) {
  46944. dispatchAction({
  46945. type: 'updateAxisPointer',
  46946. currTrigger: currTrigger,
  46947. x: e && e.offsetX,
  46948. y: e && e.offsetY
  46949. });
  46950. }
  46951. });
  46952. },
  46953. /**
  46954. * @override
  46955. */
  46956. remove: function (ecModel, api) {
  46957. unregister(api.getZr(), 'axisPointer');
  46958. AxisPointerView.superApply(this._model, 'remove', arguments);
  46959. },
  46960. /**
  46961. * @override
  46962. */
  46963. dispose: function (ecModel, api) {
  46964. unregister('axisPointer', api);
  46965. AxisPointerView.superApply(this._model, 'dispose', arguments);
  46966. }
  46967. });
  46968. /*
  46969. * Licensed to the Apache Software Foundation (ASF) under one
  46970. * or more contributor license agreements. See the NOTICE file
  46971. * distributed with this work for additional information
  46972. * regarding copyright ownership. The ASF licenses this file
  46973. * to you under the Apache License, Version 2.0 (the
  46974. * "License"); you may not use this file except in compliance
  46975. * with the License. You may obtain a copy of the License at
  46976. *
  46977. * http://www.apache.org/licenses/LICENSE-2.0
  46978. *
  46979. * Unless required by applicable law or agreed to in writing,
  46980. * software distributed under the License is distributed on an
  46981. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46982. * KIND, either express or implied. See the License for the
  46983. * specific language governing permissions and limitations
  46984. * under the License.
  46985. */
  46986. var inner$11 = makeInner();
  46987. var clone$4 = clone;
  46988. var bind$1 = bind;
  46989. /**
  46990. * Base axis pointer class in 2D.
  46991. * Implemenents {module:echarts/component/axis/IAxisPointer}.
  46992. */
  46993. function BaseAxisPointer() {}
  46994. BaseAxisPointer.prototype = {
  46995. /**
  46996. * @private
  46997. */
  46998. _group: null,
  46999. /**
  47000. * @private
  47001. */
  47002. _lastGraphicKey: null,
  47003. /**
  47004. * @private
  47005. */
  47006. _handle: null,
  47007. /**
  47008. * @private
  47009. */
  47010. _dragging: false,
  47011. /**
  47012. * @private
  47013. */
  47014. _lastValue: null,
  47015. /**
  47016. * @private
  47017. */
  47018. _lastStatus: null,
  47019. /**
  47020. * @private
  47021. */
  47022. _payloadInfo: null,
  47023. /**
  47024. * In px, arbitrary value. Do not set too small,
  47025. * no animation is ok for most cases.
  47026. * @protected
  47027. */
  47028. animationThreshold: 15,
  47029. /**
  47030. * @implement
  47031. */
  47032. render: function (axisModel, axisPointerModel, api, forceRender) {
  47033. var value = axisPointerModel.get('value');
  47034. var status = axisPointerModel.get('status'); // Bind them to `this`, not in closure, otherwise they will not
  47035. // be replaced when user calling setOption in not merge mode.
  47036. this._axisModel = axisModel;
  47037. this._axisPointerModel = axisPointerModel;
  47038. this._api = api; // Optimize: `render` will be called repeatly during mouse move.
  47039. // So it is power consuming if performing `render` each time,
  47040. // especially on mobile device.
  47041. if (!forceRender && this._lastValue === value && this._lastStatus === status) {
  47042. return;
  47043. }
  47044. this._lastValue = value;
  47045. this._lastStatus = status;
  47046. var group = this._group;
  47047. var handle = this._handle;
  47048. if (!status || status === 'hide') {
  47049. // Do not clear here, for animation better.
  47050. group && group.hide();
  47051. handle && handle.hide();
  47052. return;
  47053. }
  47054. group && group.show();
  47055. handle && handle.show(); // Otherwise status is 'show'
  47056. var elOption = {};
  47057. this.makeElOption(elOption, value, axisModel, axisPointerModel, api); // Enable change axis pointer type.
  47058. var graphicKey = elOption.graphicKey;
  47059. if (graphicKey !== this._lastGraphicKey) {
  47060. this.clear(api);
  47061. }
  47062. this._lastGraphicKey = graphicKey;
  47063. var moveAnimation = this._moveAnimation = this.determineAnimation(axisModel, axisPointerModel);
  47064. if (!group) {
  47065. group = this._group = new Group();
  47066. this.createPointerEl(group, elOption, axisModel, axisPointerModel);
  47067. this.createLabelEl(group, elOption, axisModel, axisPointerModel);
  47068. api.getZr().add(group);
  47069. } else {
  47070. var doUpdateProps = curry(updateProps$1, axisPointerModel, moveAnimation);
  47071. this.updatePointerEl(group, elOption, doUpdateProps, axisPointerModel);
  47072. this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
  47073. }
  47074. updateMandatoryProps(group, axisPointerModel, true);
  47075. this._renderHandle(value);
  47076. },
  47077. /**
  47078. * @implement
  47079. */
  47080. remove: function (api) {
  47081. this.clear(api);
  47082. },
  47083. /**
  47084. * @implement
  47085. */
  47086. dispose: function (api) {
  47087. this.clear(api);
  47088. },
  47089. /**
  47090. * @protected
  47091. */
  47092. determineAnimation: function (axisModel, axisPointerModel) {
  47093. var animation = axisPointerModel.get('animation');
  47094. var axis = axisModel.axis;
  47095. var isCategoryAxis = axis.type === 'category';
  47096. var useSnap = axisPointerModel.get('snap'); // Value axis without snap always do not snap.
  47097. if (!useSnap && !isCategoryAxis) {
  47098. return false;
  47099. }
  47100. if (animation === 'auto' || animation == null) {
  47101. var animationThreshold = this.animationThreshold;
  47102. if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
  47103. return true;
  47104. } // It is important to auto animation when snap used. Consider if there is
  47105. // a dataZoom, animation will be disabled when too many points exist, while
  47106. // it will be enabled for better visual effect when little points exist.
  47107. if (useSnap) {
  47108. var seriesDataCount = getAxisInfo(axisModel).seriesDataCount;
  47109. var axisExtent = axis.getExtent(); // Approximate band width
  47110. return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
  47111. }
  47112. return false;
  47113. }
  47114. return animation === true;
  47115. },
  47116. /**
  47117. * add {pointer, label, graphicKey} to elOption
  47118. * @protected
  47119. */
  47120. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {// Shoule be implemenented by sub-class.
  47121. },
  47122. /**
  47123. * @protected
  47124. */
  47125. createPointerEl: function (group, elOption, axisModel, axisPointerModel) {
  47126. var pointerOption = elOption.pointer;
  47127. if (pointerOption) {
  47128. var pointerEl = inner$11(group).pointerEl = new graphic[pointerOption.type](clone$4(elOption.pointer));
  47129. group.add(pointerEl);
  47130. }
  47131. },
  47132. /**
  47133. * @protected
  47134. */
  47135. createLabelEl: function (group, elOption, axisModel, axisPointerModel) {
  47136. if (elOption.label) {
  47137. var labelEl = inner$11(group).labelEl = new Rect(clone$4(elOption.label));
  47138. group.add(labelEl);
  47139. updateLabelShowHide(labelEl, axisPointerModel);
  47140. }
  47141. },
  47142. /**
  47143. * @protected
  47144. */
  47145. updatePointerEl: function (group, elOption, updateProps$$1) {
  47146. var pointerEl = inner$11(group).pointerEl;
  47147. if (pointerEl && elOption.pointer) {
  47148. pointerEl.setStyle(elOption.pointer.style);
  47149. updateProps$$1(pointerEl, {
  47150. shape: elOption.pointer.shape
  47151. });
  47152. }
  47153. },
  47154. /**
  47155. * @protected
  47156. */
  47157. updateLabelEl: function (group, elOption, updateProps$$1, axisPointerModel) {
  47158. var labelEl = inner$11(group).labelEl;
  47159. if (labelEl) {
  47160. labelEl.setStyle(elOption.label.style);
  47161. updateProps$$1(labelEl, {
  47162. // Consider text length change in vertical axis, animation should
  47163. // be used on shape, otherwise the effect will be weird.
  47164. shape: elOption.label.shape,
  47165. position: elOption.label.position
  47166. });
  47167. updateLabelShowHide(labelEl, axisPointerModel);
  47168. }
  47169. },
  47170. /**
  47171. * @private
  47172. */
  47173. _renderHandle: function (value) {
  47174. if (this._dragging || !this.updateHandleTransform) {
  47175. return;
  47176. }
  47177. var axisPointerModel = this._axisPointerModel;
  47178. var zr = this._api.getZr();
  47179. var handle = this._handle;
  47180. var handleModel = axisPointerModel.getModel('handle');
  47181. var status = axisPointerModel.get('status');
  47182. if (!handleModel.get('show') || !status || status === 'hide') {
  47183. handle && zr.remove(handle);
  47184. this._handle = null;
  47185. return;
  47186. }
  47187. var isInit;
  47188. if (!this._handle) {
  47189. isInit = true;
  47190. handle = this._handle = createIcon(handleModel.get('icon'), {
  47191. cursor: 'move',
  47192. draggable: true,
  47193. onmousemove: function (e) {
  47194. // Fot mobile devicem, prevent screen slider on the button.
  47195. stop(e.event);
  47196. },
  47197. onmousedown: bind$1(this._onHandleDragMove, this, 0, 0),
  47198. drift: bind$1(this._onHandleDragMove, this),
  47199. ondragend: bind$1(this._onHandleDragEnd, this)
  47200. });
  47201. zr.add(handle);
  47202. }
  47203. updateMandatoryProps(handle, axisPointerModel, false); // update style
  47204. var includeStyles = ['color', 'borderColor', 'borderWidth', 'opacity', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'];
  47205. handle.setStyle(handleModel.getItemStyle(null, includeStyles)); // update position
  47206. var handleSize = handleModel.get('size');
  47207. if (!isArray(handleSize)) {
  47208. handleSize = [handleSize, handleSize];
  47209. }
  47210. handle.attr('scale', [handleSize[0] / 2, handleSize[1] / 2]);
  47211. createOrUpdate(this, '_doDispatchAxisPointer', handleModel.get('throttle') || 0, 'fixRate');
  47212. this._moveHandleToValue(value, isInit);
  47213. },
  47214. /**
  47215. * @private
  47216. */
  47217. _moveHandleToValue: function (value, isInit) {
  47218. updateProps$1(this._axisPointerModel, !isInit && this._moveAnimation, this._handle, getHandleTransProps(this.getHandleTransform(value, this._axisModel, this._axisPointerModel)));
  47219. },
  47220. /**
  47221. * @private
  47222. */
  47223. _onHandleDragMove: function (dx, dy) {
  47224. var handle = this._handle;
  47225. if (!handle) {
  47226. return;
  47227. }
  47228. this._dragging = true; // Persistent for throttle.
  47229. var trans = this.updateHandleTransform(getHandleTransProps(handle), [dx, dy], this._axisModel, this._axisPointerModel);
  47230. this._payloadInfo = trans;
  47231. handle.stopAnimation();
  47232. handle.attr(getHandleTransProps(trans));
  47233. inner$11(handle).lastProp = null;
  47234. this._doDispatchAxisPointer();
  47235. },
  47236. /**
  47237. * Throttled method.
  47238. * @private
  47239. */
  47240. _doDispatchAxisPointer: function () {
  47241. var handle = this._handle;
  47242. if (!handle) {
  47243. return;
  47244. }
  47245. var payloadInfo = this._payloadInfo;
  47246. var axisModel = this._axisModel;
  47247. this._api.dispatchAction({
  47248. type: 'updateAxisPointer',
  47249. x: payloadInfo.cursorPoint[0],
  47250. y: payloadInfo.cursorPoint[1],
  47251. tooltipOption: payloadInfo.tooltipOption,
  47252. axesInfo: [{
  47253. axisDim: axisModel.axis.dim,
  47254. axisIndex: axisModel.componentIndex
  47255. }]
  47256. });
  47257. },
  47258. /**
  47259. * @private
  47260. */
  47261. _onHandleDragEnd: function (moveAnimation) {
  47262. this._dragging = false;
  47263. var handle = this._handle;
  47264. if (!handle) {
  47265. return;
  47266. }
  47267. var value = this._axisPointerModel.get('value'); // Consider snap or categroy axis, handle may be not consistent with
  47268. // axisPointer. So move handle to align the exact value position when
  47269. // drag ended.
  47270. this._moveHandleToValue(value); // For the effect: tooltip will be shown when finger holding on handle
  47271. // button, and will be hidden after finger left handle button.
  47272. this._api.dispatchAction({
  47273. type: 'hideTip'
  47274. });
  47275. },
  47276. /**
  47277. * Should be implemenented by sub-class if support `handle`.
  47278. * @protected
  47279. * @param {number} value
  47280. * @param {module:echarts/model/Model} axisModel
  47281. * @param {module:echarts/model/Model} axisPointerModel
  47282. * @return {Object} {position: [x, y], rotation: 0}
  47283. */
  47284. getHandleTransform: null,
  47285. /**
  47286. * * Should be implemenented by sub-class if support `handle`.
  47287. * @protected
  47288. * @param {Object} transform {position, rotation}
  47289. * @param {Array.<number>} delta [dx, dy]
  47290. * @param {module:echarts/model/Model} axisModel
  47291. * @param {module:echarts/model/Model} axisPointerModel
  47292. * @return {Object} {position: [x, y], rotation: 0, cursorPoint: [x, y]}
  47293. */
  47294. updateHandleTransform: null,
  47295. /**
  47296. * @private
  47297. */
  47298. clear: function (api) {
  47299. this._lastValue = null;
  47300. this._lastStatus = null;
  47301. var zr = api.getZr();
  47302. var group = this._group;
  47303. var handle = this._handle;
  47304. if (zr && group) {
  47305. this._lastGraphicKey = null;
  47306. group && zr.remove(group);
  47307. handle && zr.remove(handle);
  47308. this._group = null;
  47309. this._handle = null;
  47310. this._payloadInfo = null;
  47311. }
  47312. },
  47313. /**
  47314. * @protected
  47315. */
  47316. doClear: function () {// Implemented by sub-class if necessary.
  47317. },
  47318. /**
  47319. * @protected
  47320. * @param {Array.<number>} xy
  47321. * @param {Array.<number>} wh
  47322. * @param {number} [xDimIndex=0] or 1
  47323. */
  47324. buildLabel: function (xy, wh, xDimIndex) {
  47325. xDimIndex = xDimIndex || 0;
  47326. return {
  47327. x: xy[xDimIndex],
  47328. y: xy[1 - xDimIndex],
  47329. width: wh[xDimIndex],
  47330. height: wh[1 - xDimIndex]
  47331. };
  47332. }
  47333. };
  47334. BaseAxisPointer.prototype.constructor = BaseAxisPointer;
  47335. function updateProps$1(animationModel, moveAnimation, el, props) {
  47336. // Animation optimize.
  47337. if (!propsEqual(inner$11(el).lastProp, props)) {
  47338. inner$11(el).lastProp = props;
  47339. moveAnimation ? updateProps(el, props, animationModel) : (el.stopAnimation(), el.attr(props));
  47340. }
  47341. }
  47342. function propsEqual(lastProps, newProps) {
  47343. if (isObject$1(lastProps) && isObject$1(newProps)) {
  47344. var equals = true;
  47345. each$1(newProps, function (item, key) {
  47346. equals = equals && propsEqual(lastProps[key], item);
  47347. });
  47348. return !!equals;
  47349. } else {
  47350. return lastProps === newProps;
  47351. }
  47352. }
  47353. function updateLabelShowHide(labelEl, axisPointerModel) {
  47354. labelEl[axisPointerModel.get('label.show') ? 'show' : 'hide']();
  47355. }
  47356. function getHandleTransProps(trans) {
  47357. return {
  47358. position: trans.position.slice(),
  47359. rotation: trans.rotation || 0
  47360. };
  47361. }
  47362. function updateMandatoryProps(group, axisPointerModel, silent) {
  47363. var z = axisPointerModel.get('z');
  47364. var zlevel = axisPointerModel.get('zlevel');
  47365. group && group.traverse(function (el) {
  47366. if (el.type !== 'group') {
  47367. z != null && (el.z = z);
  47368. zlevel != null && (el.zlevel = zlevel);
  47369. el.silent = silent;
  47370. }
  47371. });
  47372. }
  47373. enableClassExtend(BaseAxisPointer);
  47374. /*
  47375. * Licensed to the Apache Software Foundation (ASF) under one
  47376. * or more contributor license agreements. See the NOTICE file
  47377. * distributed with this work for additional information
  47378. * regarding copyright ownership. The ASF licenses this file
  47379. * to you under the Apache License, Version 2.0 (the
  47380. * "License"); you may not use this file except in compliance
  47381. * with the License. You may obtain a copy of the License at
  47382. *
  47383. * http://www.apache.org/licenses/LICENSE-2.0
  47384. *
  47385. * Unless required by applicable law or agreed to in writing,
  47386. * software distributed under the License is distributed on an
  47387. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47388. * KIND, either express or implied. See the License for the
  47389. * specific language governing permissions and limitations
  47390. * under the License.
  47391. */
  47392. /**
  47393. * @param {module:echarts/model/Model} axisPointerModel
  47394. */
  47395. function buildElStyle(axisPointerModel) {
  47396. var axisPointerType = axisPointerModel.get('type');
  47397. var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
  47398. var style;
  47399. if (axisPointerType === 'line') {
  47400. style = styleModel.getLineStyle();
  47401. style.fill = null;
  47402. } else if (axisPointerType === 'shadow') {
  47403. style = styleModel.getAreaStyle();
  47404. style.stroke = null;
  47405. }
  47406. return style;
  47407. }
  47408. /**
  47409. * @param {Function} labelPos {align, verticalAlign, position}
  47410. */
  47411. function buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos) {
  47412. var value = axisPointerModel.get('value');
  47413. var text = getValueLabel(value, axisModel.axis, axisModel.ecModel, axisPointerModel.get('seriesDataIndices'), {
  47414. precision: axisPointerModel.get('label.precision'),
  47415. formatter: axisPointerModel.get('label.formatter')
  47416. });
  47417. var labelModel = axisPointerModel.getModel('label');
  47418. var paddings = normalizeCssArray$1(labelModel.get('padding') || 0);
  47419. var font = labelModel.getFont();
  47420. var textRect = getBoundingRect(text, font);
  47421. var position = labelPos.position;
  47422. var width = textRect.width + paddings[1] + paddings[3];
  47423. var height = textRect.height + paddings[0] + paddings[2]; // Adjust by align.
  47424. var align = labelPos.align;
  47425. align === 'right' && (position[0] -= width);
  47426. align === 'center' && (position[0] -= width / 2);
  47427. var verticalAlign = labelPos.verticalAlign;
  47428. verticalAlign === 'bottom' && (position[1] -= height);
  47429. verticalAlign === 'middle' && (position[1] -= height / 2); // Not overflow ec container
  47430. confineInContainer(position, width, height, api);
  47431. var bgColor = labelModel.get('backgroundColor');
  47432. if (!bgColor || bgColor === 'auto') {
  47433. bgColor = axisModel.get('axisLine.lineStyle.color');
  47434. }
  47435. elOption.label = {
  47436. shape: {
  47437. x: 0,
  47438. y: 0,
  47439. width: width,
  47440. height: height,
  47441. r: labelModel.get('borderRadius')
  47442. },
  47443. position: position.slice(),
  47444. // TODO: rich
  47445. style: {
  47446. text: text,
  47447. textFont: font,
  47448. textFill: labelModel.getTextColor(),
  47449. textPosition: 'inside',
  47450. textPadding: paddings,
  47451. fill: bgColor,
  47452. stroke: labelModel.get('borderColor') || 'transparent',
  47453. lineWidth: labelModel.get('borderWidth') || 0,
  47454. shadowBlur: labelModel.get('shadowBlur'),
  47455. shadowColor: labelModel.get('shadowColor'),
  47456. shadowOffsetX: labelModel.get('shadowOffsetX'),
  47457. shadowOffsetY: labelModel.get('shadowOffsetY')
  47458. },
  47459. // Lable should be over axisPointer.
  47460. z2: 10
  47461. };
  47462. } // Do not overflow ec container
  47463. function confineInContainer(position, width, height, api) {
  47464. var viewWidth = api.getWidth();
  47465. var viewHeight = api.getHeight();
  47466. position[0] = Math.min(position[0] + width, viewWidth) - width;
  47467. position[1] = Math.min(position[1] + height, viewHeight) - height;
  47468. position[0] = Math.max(position[0], 0);
  47469. position[1] = Math.max(position[1], 0);
  47470. }
  47471. /**
  47472. * @param {number} value
  47473. * @param {module:echarts/coord/Axis} axis
  47474. * @param {module:echarts/model/Global} ecModel
  47475. * @param {Object} opt
  47476. * @param {Array.<Object>} seriesDataIndices
  47477. * @param {number|string} opt.precision 'auto' or a number
  47478. * @param {string|Function} opt.formatter label formatter
  47479. */
  47480. function getValueLabel(value, axis, ecModel, seriesDataIndices, opt) {
  47481. value = axis.scale.parse(value);
  47482. var text = axis.scale.getLabel( // If `precision` is set, width can be fixed (like '12.00500'), which
  47483. // helps to debounce when when moving label.
  47484. value, {
  47485. precision: opt.precision
  47486. });
  47487. var formatter = opt.formatter;
  47488. if (formatter) {
  47489. var params = {
  47490. value: getAxisRawValue(axis, value),
  47491. axisDimension: axis.dim,
  47492. axisIndex: axis.index,
  47493. seriesData: []
  47494. };
  47495. each$1(seriesDataIndices, function (idxItem) {
  47496. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  47497. var dataIndex = idxItem.dataIndexInside;
  47498. var dataParams = series && series.getDataParams(dataIndex);
  47499. dataParams && params.seriesData.push(dataParams);
  47500. });
  47501. if (isString(formatter)) {
  47502. text = formatter.replace('{value}', text);
  47503. } else if (isFunction$1(formatter)) {
  47504. text = formatter(params);
  47505. }
  47506. }
  47507. return text;
  47508. }
  47509. /**
  47510. * @param {module:echarts/coord/Axis} axis
  47511. * @param {number} value
  47512. * @param {Object} layoutInfo {
  47513. * rotation, position, labelOffset, labelDirection, labelMargin
  47514. * }
  47515. */
  47516. function getTransformedPosition(axis, value, layoutInfo) {
  47517. var transform = create$1();
  47518. rotate(transform, transform, layoutInfo.rotation);
  47519. translate(transform, transform, layoutInfo.position);
  47520. return applyTransform$1([axis.dataToCoord(value), (layoutInfo.labelOffset || 0) + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)], transform);
  47521. }
  47522. function buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api) {
  47523. var textLayout = AxisBuilder.innerTextLayout(layoutInfo.rotation, 0, layoutInfo.labelDirection);
  47524. layoutInfo.labelMargin = axisPointerModel.get('label.margin');
  47525. buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
  47526. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  47527. align: textLayout.textAlign,
  47528. verticalAlign: textLayout.textVerticalAlign
  47529. });
  47530. }
  47531. /**
  47532. * @param {Array.<number>} p1
  47533. * @param {Array.<number>} p2
  47534. * @param {number} [xDimIndex=0] or 1
  47535. */
  47536. function makeLineShape(p1, p2, xDimIndex) {
  47537. xDimIndex = xDimIndex || 0;
  47538. return {
  47539. x1: p1[xDimIndex],
  47540. y1: p1[1 - xDimIndex],
  47541. x2: p2[xDimIndex],
  47542. y2: p2[1 - xDimIndex]
  47543. };
  47544. }
  47545. /**
  47546. * @param {Array.<number>} xy
  47547. * @param {Array.<number>} wh
  47548. * @param {number} [xDimIndex=0] or 1
  47549. */
  47550. function makeRectShape(xy, wh, xDimIndex) {
  47551. xDimIndex = xDimIndex || 0;
  47552. return {
  47553. x: xy[xDimIndex],
  47554. y: xy[1 - xDimIndex],
  47555. width: wh[xDimIndex],
  47556. height: wh[1 - xDimIndex]
  47557. };
  47558. }
  47559. /*
  47560. * Licensed to the Apache Software Foundation (ASF) under one
  47561. * or more contributor license agreements. See the NOTICE file
  47562. * distributed with this work for additional information
  47563. * regarding copyright ownership. The ASF licenses this file
  47564. * to you under the Apache License, Version 2.0 (the
  47565. * "License"); you may not use this file except in compliance
  47566. * with the License. You may obtain a copy of the License at
  47567. *
  47568. * http://www.apache.org/licenses/LICENSE-2.0
  47569. *
  47570. * Unless required by applicable law or agreed to in writing,
  47571. * software distributed under the License is distributed on an
  47572. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47573. * KIND, either express or implied. See the License for the
  47574. * specific language governing permissions and limitations
  47575. * under the License.
  47576. */
  47577. var CartesianAxisPointer = BaseAxisPointer.extend({
  47578. /**
  47579. * @override
  47580. */
  47581. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  47582. var axis = axisModel.axis;
  47583. var grid = axis.grid;
  47584. var axisPointerType = axisPointerModel.get('type');
  47585. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  47586. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  47587. if (axisPointerType && axisPointerType !== 'none') {
  47588. var elStyle = buildElStyle(axisPointerModel);
  47589. var pointerOption = pointerShapeBuilder[axisPointerType](axis, pixelValue, otherExtent);
  47590. pointerOption.style = elStyle;
  47591. elOption.graphicKey = pointerOption.type;
  47592. elOption.pointer = pointerOption;
  47593. }
  47594. var layoutInfo = layout$1(grid.model, axisModel);
  47595. buildCartesianSingleLabelElOption(value, elOption, layoutInfo, axisModel, axisPointerModel, api);
  47596. },
  47597. /**
  47598. * @override
  47599. */
  47600. getHandleTransform: function (value, axisModel, axisPointerModel) {
  47601. var layoutInfo = layout$1(axisModel.axis.grid.model, axisModel, {
  47602. labelInside: false
  47603. });
  47604. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  47605. return {
  47606. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  47607. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  47608. };
  47609. },
  47610. /**
  47611. * @override
  47612. */
  47613. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  47614. var axis = axisModel.axis;
  47615. var grid = axis.grid;
  47616. var axisExtent = axis.getGlobalExtent(true);
  47617. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  47618. var dimIndex = axis.dim === 'x' ? 0 : 1;
  47619. var currPosition = transform.position;
  47620. currPosition[dimIndex] += delta[dimIndex];
  47621. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  47622. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  47623. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  47624. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  47625. cursorPoint[dimIndex] = currPosition[dimIndex]; // Make tooltip do not overlap axisPointer and in the middle of the grid.
  47626. var tooltipOptions = [{
  47627. verticalAlign: 'middle'
  47628. }, {
  47629. align: 'center'
  47630. }];
  47631. return {
  47632. position: currPosition,
  47633. rotation: transform.rotation,
  47634. cursorPoint: cursorPoint,
  47635. tooltipOption: tooltipOptions[dimIndex]
  47636. };
  47637. }
  47638. });
  47639. function getCartesian(grid, axis) {
  47640. var opt = {};
  47641. opt[axis.dim + 'AxisIndex'] = axis.index;
  47642. return grid.getCartesian(opt);
  47643. }
  47644. var pointerShapeBuilder = {
  47645. line: function (axis, pixelValue, otherExtent) {
  47646. var targetShape = makeLineShape([pixelValue, otherExtent[0]], [pixelValue, otherExtent[1]], getAxisDimIndex(axis));
  47647. return {
  47648. type: 'Line',
  47649. subPixelOptimize: true,
  47650. shape: targetShape
  47651. };
  47652. },
  47653. shadow: function (axis, pixelValue, otherExtent) {
  47654. var bandWidth = Math.max(1, axis.getBandWidth());
  47655. var span = otherExtent[1] - otherExtent[0];
  47656. return {
  47657. type: 'Rect',
  47658. shape: makeRectShape([pixelValue - bandWidth / 2, otherExtent[0]], [bandWidth, span], getAxisDimIndex(axis))
  47659. };
  47660. }
  47661. };
  47662. function getAxisDimIndex(axis) {
  47663. return axis.dim === 'x' ? 0 : 1;
  47664. }
  47665. AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
  47666. /*
  47667. * Licensed to the Apache Software Foundation (ASF) under one
  47668. * or more contributor license agreements. See the NOTICE file
  47669. * distributed with this work for additional information
  47670. * regarding copyright ownership. The ASF licenses this file
  47671. * to you under the Apache License, Version 2.0 (the
  47672. * "License"); you may not use this file except in compliance
  47673. * with the License. You may obtain a copy of the License at
  47674. *
  47675. * http://www.apache.org/licenses/LICENSE-2.0
  47676. *
  47677. * Unless required by applicable law or agreed to in writing,
  47678. * software distributed under the License is distributed on an
  47679. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47680. * KIND, either express or implied. See the License for the
  47681. * specific language governing permissions and limitations
  47682. * under the License.
  47683. */
  47684. // echarts.simple.js and online build tooltip, which only require gridSimple,
  47685. // CartesianAxisPointer should be able to required somewhere.
  47686. registerPreprocessor(function (option) {
  47687. // Always has a global axisPointerModel for default setting.
  47688. if (option) {
  47689. (!option.axisPointer || option.axisPointer.length === 0) && (option.axisPointer = {});
  47690. var link = option.axisPointer.link; // Normalize to array to avoid object mergin. But if link
  47691. // is not set, remain null/undefined, otherwise it will
  47692. // override existent link setting.
  47693. if (link && !isArray(link)) {
  47694. option.axisPointer.link = [link];
  47695. }
  47696. }
  47697. }); // This process should proformed after coordinate systems created
  47698. // and series data processed. So put it on statistic processing stage.
  47699. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, function (ecModel, api) {
  47700. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  47701. // allAxesInfo should be updated when setOption performed.
  47702. ecModel.getComponent('axisPointer').coordSysAxesInfo = collect(ecModel, api);
  47703. }); // Broadcast to all views.
  47704. registerAction({
  47705. type: 'updateAxisPointer',
  47706. event: 'updateAxisPointer',
  47707. update: ':updateAxisPointer'
  47708. }, axisTrigger);
  47709. /*
  47710. * Licensed to the Apache Software Foundation (ASF) under one
  47711. * or more contributor license agreements. See the NOTICE file
  47712. * distributed with this work for additional information
  47713. * regarding copyright ownership. The ASF licenses this file
  47714. * to you under the Apache License, Version 2.0 (the
  47715. * "License"); you may not use this file except in compliance
  47716. * with the License. You may obtain a copy of the License at
  47717. *
  47718. * http://www.apache.org/licenses/LICENSE-2.0
  47719. *
  47720. * Unless required by applicable law or agreed to in writing,
  47721. * software distributed under the License is distributed on an
  47722. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47723. * KIND, either express or implied. See the License for the
  47724. * specific language governing permissions and limitations
  47725. * under the License.
  47726. */
  47727. extendComponentModel({
  47728. type: 'tooltip',
  47729. dependencies: ['axisPointer'],
  47730. defaultOption: {
  47731. zlevel: 0,
  47732. z: 60,
  47733. show: true,
  47734. // tooltip主体内容
  47735. showContent: true,
  47736. // 'trigger' only works on coordinate system.
  47737. // 'item' | 'axis' | 'none'
  47738. trigger: 'item',
  47739. // 'click' | 'mousemove' | 'none'
  47740. triggerOn: 'mousemove|click',
  47741. alwaysShowContent: false,
  47742. displayMode: 'single',
  47743. // 'single' | 'multipleByCoordSys'
  47744. renderMode: 'auto',
  47745. // 'auto' | 'html' | 'richText'
  47746. // 'auto': use html by default, and use non-html if `document` is not defined
  47747. // 'html': use html for tooltip
  47748. // 'richText': use canvas, svg, and etc. for tooltip
  47749. // 位置 {Array} | {Function}
  47750. // position: null
  47751. // Consider triggered from axisPointer handle, verticalAlign should be 'middle'
  47752. // align: null,
  47753. // verticalAlign: null,
  47754. // 是否约束 content 在 viewRect 中。默认 false 是为了兼容以前版本。
  47755. confine: false,
  47756. // 内容格式器:{string}(Template) ¦ {Function}
  47757. // formatter: null
  47758. showDelay: 0,
  47759. // 隐藏延迟,单位ms
  47760. hideDelay: 100,
  47761. // 动画变换时间,单位s
  47762. transitionDuration: 0.4,
  47763. enterable: false,
  47764. // 提示背景颜色,默认为透明度为0.7的黑色
  47765. backgroundColor: 'rgba(50,50,50,0.7)',
  47766. // 提示边框颜色
  47767. borderColor: '#333',
  47768. // 提示边框圆角,单位px,默认为4
  47769. borderRadius: 4,
  47770. // 提示边框线宽,单位px,默认为0(无边框)
  47771. borderWidth: 0,
  47772. // 提示内边距,单位px,默认各方向内边距为5,
  47773. // 接受数组分别设定上右下左边距,同css
  47774. padding: 5,
  47775. // Extra css text
  47776. extraCssText: '',
  47777. // 坐标轴指示器,坐标轴触发有效
  47778. axisPointer: {
  47779. // 默认为直线
  47780. // 可选为:'line' | 'shadow' | 'cross'
  47781. type: 'line',
  47782. // type 为 line 的时候有效,指定 tooltip line 所在的轴,可选
  47783. // 可选 'x' | 'y' | 'angle' | 'radius' | 'auto'
  47784. // 默认 'auto',会选择类型为 category 的轴,对于双数值轴,笛卡尔坐标系会默认选择 x 轴
  47785. // 极坐标系会默认选择 angle 轴
  47786. axis: 'auto',
  47787. animation: 'auto',
  47788. animationDurationUpdate: 200,
  47789. animationEasingUpdate: 'exponentialOut',
  47790. crossStyle: {
  47791. color: '#999',
  47792. width: 1,
  47793. type: 'dashed',
  47794. // TODO formatter
  47795. textStyle: {} // lineStyle and shadowStyle should not be specified here,
  47796. // otherwise it will always override those styles on option.axisPointer.
  47797. }
  47798. },
  47799. textStyle: {
  47800. color: '#fff',
  47801. fontSize: 14
  47802. }
  47803. }
  47804. });
  47805. /*
  47806. * Licensed to the Apache Software Foundation (ASF) under one
  47807. * or more contributor license agreements. See the NOTICE file
  47808. * distributed with this work for additional information
  47809. * regarding copyright ownership. The ASF licenses this file
  47810. * to you under the Apache License, Version 2.0 (the
  47811. * "License"); you may not use this file except in compliance
  47812. * with the License. You may obtain a copy of the License at
  47813. *
  47814. * http://www.apache.org/licenses/LICENSE-2.0
  47815. *
  47816. * Unless required by applicable law or agreed to in writing,
  47817. * software distributed under the License is distributed on an
  47818. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47819. * KIND, either express or implied. See the License for the
  47820. * specific language governing permissions and limitations
  47821. * under the License.
  47822. */
  47823. var each$12 = each$1;
  47824. var toCamelCase$1 = toCamelCase;
  47825. var vendors = ['', '-webkit-', '-moz-', '-o-'];
  47826. var gCssText = 'position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;';
  47827. /**
  47828. * @param {number} duration
  47829. * @return {string}
  47830. * @inner
  47831. */
  47832. function assembleTransition(duration) {
  47833. var transitionCurve = 'cubic-bezier(0.23, 1, 0.32, 1)';
  47834. var transitionText = 'left ' + duration + 's ' + transitionCurve + ',' + 'top ' + duration + 's ' + transitionCurve;
  47835. return map(vendors, function (vendorPrefix) {
  47836. return vendorPrefix + 'transition:' + transitionText;
  47837. }).join(';');
  47838. }
  47839. /**
  47840. * @param {Object} textStyle
  47841. * @return {string}
  47842. * @inner
  47843. */
  47844. function assembleFont(textStyleModel) {
  47845. var cssText = [];
  47846. var fontSize = textStyleModel.get('fontSize');
  47847. var color = textStyleModel.getTextColor();
  47848. color && cssText.push('color:' + color);
  47849. cssText.push('font:' + textStyleModel.getFont());
  47850. fontSize && cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  47851. each$12(['decoration', 'align'], function (name) {
  47852. var val = textStyleModel.get(name);
  47853. val && cssText.push('text-' + name + ':' + val);
  47854. });
  47855. return cssText.join(';');
  47856. }
  47857. /**
  47858. * @param {Object} tooltipModel
  47859. * @return {string}
  47860. * @inner
  47861. */
  47862. function assembleCssText(tooltipModel) {
  47863. var cssText = [];
  47864. var transitionDuration = tooltipModel.get('transitionDuration');
  47865. var backgroundColor = tooltipModel.get('backgroundColor');
  47866. var textStyleModel = tooltipModel.getModel('textStyle');
  47867. var padding = tooltipModel.get('padding'); // Animation transition. Do not animate when transitionDuration is 0.
  47868. transitionDuration && cssText.push(assembleTransition(transitionDuration));
  47869. if (backgroundColor) {
  47870. if (env$1.canvasSupported) {
  47871. cssText.push('background-Color:' + backgroundColor);
  47872. } else {
  47873. // for ie
  47874. cssText.push('background-Color:#' + toHex(backgroundColor));
  47875. cssText.push('filter:alpha(opacity=70)');
  47876. }
  47877. } // Border style
  47878. each$12(['width', 'color', 'radius'], function (name) {
  47879. var borderName = 'border-' + name;
  47880. var camelCase = toCamelCase$1(borderName);
  47881. var val = tooltipModel.get(camelCase);
  47882. val != null && cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  47883. }); // Text style
  47884. cssText.push(assembleFont(textStyleModel)); // Padding
  47885. if (padding != null) {
  47886. cssText.push('padding:' + normalizeCssArray$1(padding).join('px ') + 'px');
  47887. }
  47888. return cssText.join(';') + ';';
  47889. } // If not able to make, do not modify the input `out`.
  47890. function makeStyleCoord(out, zr, appendToBody, zrX, zrY) {
  47891. var zrPainter = zr && zr.painter;
  47892. if (appendToBody) {
  47893. var zrViewportRoot = zrPainter && zrPainter.getViewportRoot();
  47894. if (zrViewportRoot) {
  47895. // Some APPs might use scale on body, so we support CSS transform here.
  47896. transformLocalCoord(out, zrViewportRoot, document.body, zrX, zrY);
  47897. }
  47898. } else {
  47899. out[0] = zrX;
  47900. out[1] = zrY; // xy should be based on canvas root. But tooltipContent is
  47901. // the sibling of canvas root. So padding of ec container
  47902. // should be considered here.
  47903. var viewportRootOffset = zrPainter && zrPainter.getViewportRootOffset();
  47904. if (viewportRootOffset) {
  47905. out[0] += viewportRootOffset.offsetLeft;
  47906. out[1] += viewportRootOffset.offsetTop;
  47907. }
  47908. }
  47909. }
  47910. /**
  47911. * @alias module:echarts/component/tooltip/TooltipContent
  47912. * @param {HTMLElement} container
  47913. * @param {ExtensionAPI} api
  47914. * @param {Object} [opt]
  47915. * @param {boolean} [opt.appendToBody]
  47916. * `false`: the DOM element will be inside the container. Default value.
  47917. * `true`: the DOM element will be appended to HTML body, which avoid
  47918. * some overflow clip but intrude outside of the container.
  47919. * @constructor
  47920. */
  47921. function TooltipContent(container, api, opt) {
  47922. if (env$1.wxa) {
  47923. return null;
  47924. }
  47925. var el = document.createElement('div');
  47926. el.domBelongToZr = true;
  47927. this.el = el;
  47928. var zr = this._zr = api.getZr();
  47929. var appendToBody = this._appendToBody = opt && opt.appendToBody;
  47930. this._styleCoord = [0, 0];
  47931. makeStyleCoord(this._styleCoord, zr, appendToBody, api.getWidth() / 2, api.getHeight() / 2);
  47932. if (appendToBody) {
  47933. document.body.appendChild(el);
  47934. } else {
  47935. container.appendChild(el);
  47936. }
  47937. this._container = container;
  47938. this._show = false;
  47939. /**
  47940. * @private
  47941. */
  47942. this._hideTimeout; // FIXME
  47943. // Is it needed to trigger zr event manually if
  47944. // the browser do not support `pointer-events: none`.
  47945. var self = this;
  47946. el.onmouseenter = function () {
  47947. // clear the timeout in hideLater and keep showing tooltip
  47948. if (self._enterable) {
  47949. clearTimeout(self._hideTimeout);
  47950. self._show = true;
  47951. }
  47952. self._inContent = true;
  47953. };
  47954. el.onmousemove = function (e) {
  47955. e = e || window.event;
  47956. if (!self._enterable) {
  47957. // `pointer-events: none` is set to tooltip content div
  47958. // if `enterable` is set as `false`, and `el.onmousemove`
  47959. // can not be triggered. But in browser that do not
  47960. // support `pointer-events`, we need to do this:
  47961. // Try trigger zrender event to avoid mouse
  47962. // in and out shape too frequently
  47963. var handler = zr.handler;
  47964. var zrViewportRoot = zr.painter.getViewportRoot();
  47965. normalizeEvent(zrViewportRoot, e, true);
  47966. handler.dispatch('mousemove', e);
  47967. }
  47968. };
  47969. el.onmouseleave = function () {
  47970. if (self._enterable) {
  47971. if (self._show) {
  47972. self.hideLater(self._hideDelay);
  47973. }
  47974. }
  47975. self._inContent = false;
  47976. };
  47977. }
  47978. TooltipContent.prototype = {
  47979. constructor: TooltipContent,
  47980. /**
  47981. * @private
  47982. * @type {boolean}
  47983. */
  47984. _enterable: true,
  47985. /**
  47986. * Update when tooltip is rendered
  47987. */
  47988. update: function () {
  47989. // FIXME
  47990. // Move this logic to ec main?
  47991. var container = this._container;
  47992. var stl = container.currentStyle || document.defaultView.getComputedStyle(container);
  47993. var domStyle = container.style;
  47994. if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
  47995. domStyle.position = 'relative';
  47996. } // Hide the tooltip
  47997. // PENDING
  47998. // this.hide();
  47999. },
  48000. show: function (tooltipModel) {
  48001. clearTimeout(this._hideTimeout);
  48002. var el = this.el;
  48003. var styleCoord = this._styleCoord;
  48004. el.style.cssText = gCssText + assembleCssText(tooltipModel) // Because of the reason described in:
  48005. // http://stackoverflow.com/questions/21125587/css3-transition-not-working-in-chrome-anymore
  48006. // we should set initial value to `left` and `top`.
  48007. + ';left:' + styleCoord[0] + 'px;top:' + styleCoord[1] + 'px;' + (tooltipModel.get('extraCssText') || '');
  48008. el.style.display = el.innerHTML ? 'block' : 'none'; // If mouse occsionally move over the tooltip, a mouseout event will be
  48009. // triggered by canvas, and cuase some unexpectable result like dragging
  48010. // stop, "unfocusAdjacency". Here `pointer-events: none` is used to solve
  48011. // it. Although it is not suppored by IE8~IE10, fortunately it is a rare
  48012. // scenario.
  48013. el.style.pointerEvents = this._enterable ? 'auto' : 'none';
  48014. this._show = true;
  48015. },
  48016. setContent: function (content) {
  48017. this.el.innerHTML = content == null ? '' : content;
  48018. },
  48019. setEnterable: function (enterable) {
  48020. this._enterable = enterable;
  48021. },
  48022. getSize: function () {
  48023. var el = this.el;
  48024. return [el.clientWidth, el.clientHeight];
  48025. },
  48026. moveTo: function (zrX, zrY) {
  48027. var styleCoord = this._styleCoord;
  48028. makeStyleCoord(styleCoord, this._zr, this._appendToBody, zrX, zrY);
  48029. var style = this.el.style;
  48030. style.left = styleCoord[0] + 'px';
  48031. style.top = styleCoord[1] + 'px';
  48032. },
  48033. hide: function () {
  48034. this.el.style.display = 'none';
  48035. this._show = false;
  48036. },
  48037. hideLater: function (time) {
  48038. if (this._show && !(this._inContent && this._enterable)) {
  48039. if (time) {
  48040. this._hideDelay = time; // Set show false to avoid invoke hideLater mutiple times
  48041. this._show = false;
  48042. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  48043. } else {
  48044. this.hide();
  48045. }
  48046. }
  48047. },
  48048. isShow: function () {
  48049. return this._show;
  48050. },
  48051. dispose: function () {
  48052. this.el.parentNode.removeChild(this.el);
  48053. },
  48054. getOuterSize: function () {
  48055. var width = this.el.clientWidth;
  48056. var height = this.el.clientHeight; // Consider browser compatibility.
  48057. // IE8 does not support getComputedStyle.
  48058. if (document.defaultView && document.defaultView.getComputedStyle) {
  48059. var stl = document.defaultView.getComputedStyle(this.el);
  48060. if (stl) {
  48061. width += parseInt(stl.borderLeftWidth, 10) + parseInt(stl.borderRightWidth, 10);
  48062. height += parseInt(stl.borderTopWidth, 10) + parseInt(stl.borderBottomWidth, 10);
  48063. }
  48064. }
  48065. return {
  48066. width: width,
  48067. height: height
  48068. };
  48069. }
  48070. };
  48071. /*
  48072. * Licensed to the Apache Software Foundation (ASF) under one
  48073. * or more contributor license agreements. See the NOTICE file
  48074. * distributed with this work for additional information
  48075. * regarding copyright ownership. The ASF licenses this file
  48076. * to you under the Apache License, Version 2.0 (the
  48077. * "License"); you may not use this file except in compliance
  48078. * with the License. You may obtain a copy of the License at
  48079. *
  48080. * http://www.apache.org/licenses/LICENSE-2.0
  48081. *
  48082. * Unless required by applicable law or agreed to in writing,
  48083. * software distributed under the License is distributed on an
  48084. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48085. * KIND, either express or implied. See the License for the
  48086. * specific language governing permissions and limitations
  48087. * under the License.
  48088. */
  48089. /**
  48090. * @alias module:echarts/component/tooltip/TooltipRichContent
  48091. * @constructor
  48092. */
  48093. function TooltipRichContent(api) {
  48094. this._zr = api.getZr();
  48095. this._show = false;
  48096. /**
  48097. * @private
  48098. */
  48099. this._hideTimeout;
  48100. }
  48101. TooltipRichContent.prototype = {
  48102. constructor: TooltipRichContent,
  48103. /**
  48104. * @private
  48105. * @type {boolean}
  48106. */
  48107. _enterable: true,
  48108. /**
  48109. * Update when tooltip is rendered
  48110. */
  48111. update: function () {// noop
  48112. },
  48113. show: function (tooltipModel) {
  48114. if (this._hideTimeout) {
  48115. clearTimeout(this._hideTimeout);
  48116. }
  48117. this.el.attr('show', true);
  48118. this._show = true;
  48119. },
  48120. /**
  48121. * Set tooltip content
  48122. *
  48123. * @param {string} content rich text string of content
  48124. * @param {Object} markerRich rich text style
  48125. * @param {Object} tooltipModel tooltip model
  48126. */
  48127. setContent: function (content, markerRich, tooltipModel) {
  48128. if (this.el) {
  48129. this._zr.remove(this.el);
  48130. }
  48131. var markers = {};
  48132. var text = content;
  48133. var prefix = '{marker';
  48134. var suffix = '|}';
  48135. var startId = text.indexOf(prefix);
  48136. while (startId >= 0) {
  48137. var endId = text.indexOf(suffix);
  48138. var name = text.substr(startId + prefix.length, endId - startId - prefix.length);
  48139. if (name.indexOf('sub') > -1) {
  48140. markers['marker' + name] = {
  48141. textWidth: 4,
  48142. textHeight: 4,
  48143. textBorderRadius: 2,
  48144. textBackgroundColor: markerRich[name],
  48145. // TODO: textOffset is not implemented for rich text
  48146. textOffset: [3, 0]
  48147. };
  48148. } else {
  48149. markers['marker' + name] = {
  48150. textWidth: 10,
  48151. textHeight: 10,
  48152. textBorderRadius: 5,
  48153. textBackgroundColor: markerRich[name]
  48154. };
  48155. }
  48156. text = text.substr(endId + 1);
  48157. startId = text.indexOf('{marker');
  48158. }
  48159. this.el = new Text({
  48160. style: {
  48161. rich: markers,
  48162. text: content,
  48163. textLineHeight: 20,
  48164. textBackgroundColor: tooltipModel.get('backgroundColor'),
  48165. textBorderRadius: tooltipModel.get('borderRadius'),
  48166. textFill: tooltipModel.get('textStyle.color'),
  48167. textPadding: tooltipModel.get('padding')
  48168. },
  48169. z: tooltipModel.get('z')
  48170. });
  48171. this._zr.add(this.el);
  48172. var self = this;
  48173. this.el.on('mouseover', function () {
  48174. // clear the timeout in hideLater and keep showing tooltip
  48175. if (self._enterable) {
  48176. clearTimeout(self._hideTimeout);
  48177. self._show = true;
  48178. }
  48179. self._inContent = true;
  48180. });
  48181. this.el.on('mouseout', function () {
  48182. if (self._enterable) {
  48183. if (self._show) {
  48184. self.hideLater(self._hideDelay);
  48185. }
  48186. }
  48187. self._inContent = false;
  48188. });
  48189. },
  48190. setEnterable: function (enterable) {
  48191. this._enterable = enterable;
  48192. },
  48193. getSize: function () {
  48194. var bounding = this.el.getBoundingRect();
  48195. return [bounding.width, bounding.height];
  48196. },
  48197. moveTo: function (x, y) {
  48198. if (this.el) {
  48199. this.el.attr('position', [x, y]);
  48200. }
  48201. },
  48202. hide: function () {
  48203. if (this.el) {
  48204. this.el.hide();
  48205. }
  48206. this._show = false;
  48207. },
  48208. hideLater: function (time) {
  48209. if (this._show && !(this._inContent && this._enterable)) {
  48210. if (time) {
  48211. this._hideDelay = time; // Set show false to avoid invoke hideLater mutiple times
  48212. this._show = false;
  48213. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  48214. } else {
  48215. this.hide();
  48216. }
  48217. }
  48218. },
  48219. isShow: function () {
  48220. return this._show;
  48221. },
  48222. getOuterSize: function () {
  48223. var size = this.getSize();
  48224. return {
  48225. width: size[0],
  48226. height: size[1]
  48227. };
  48228. }
  48229. };
  48230. /*
  48231. * Licensed to the Apache Software Foundation (ASF) under one
  48232. * or more contributor license agreements. See the NOTICE file
  48233. * distributed with this work for additional information
  48234. * regarding copyright ownership. The ASF licenses this file
  48235. * to you under the Apache License, Version 2.0 (the
  48236. * "License"); you may not use this file except in compliance
  48237. * with the License. You may obtain a copy of the License at
  48238. *
  48239. * http://www.apache.org/licenses/LICENSE-2.0
  48240. *
  48241. * Unless required by applicable law or agreed to in writing,
  48242. * software distributed under the License is distributed on an
  48243. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48244. * KIND, either express or implied. See the License for the
  48245. * specific language governing permissions and limitations
  48246. * under the License.
  48247. */
  48248. var bind$2 = bind;
  48249. var each$11 = each$1;
  48250. var parsePercent$2 = parsePercent$1;
  48251. var proxyRect = new Rect({
  48252. shape: {
  48253. x: -1,
  48254. y: -1,
  48255. width: 2,
  48256. height: 2
  48257. }
  48258. });
  48259. extendComponentView({
  48260. type: 'tooltip',
  48261. init: function (ecModel, api) {
  48262. if (env$1.node) {
  48263. return;
  48264. }
  48265. var tooltipModel = ecModel.getComponent('tooltip');
  48266. var renderMode = tooltipModel.get('renderMode');
  48267. this._renderMode = getTooltipRenderMode(renderMode);
  48268. var tooltipContent;
  48269. if (this._renderMode === 'html') {
  48270. tooltipContent = new TooltipContent(api.getDom(), api, {
  48271. appendToBody: tooltipModel.get('appendToBody', true)
  48272. });
  48273. this._newLine = '<br/>';
  48274. } else {
  48275. tooltipContent = new TooltipRichContent(api);
  48276. this._newLine = '\n';
  48277. }
  48278. this._tooltipContent = tooltipContent;
  48279. },
  48280. render: function (tooltipModel, ecModel, api) {
  48281. if (env$1.node) {
  48282. return;
  48283. } // Reset
  48284. this.group.removeAll();
  48285. /**
  48286. * @private
  48287. * @type {module:echarts/component/tooltip/TooltipModel}
  48288. */
  48289. this._tooltipModel = tooltipModel;
  48290. /**
  48291. * @private
  48292. * @type {module:echarts/model/Global}
  48293. */
  48294. this._ecModel = ecModel;
  48295. /**
  48296. * @private
  48297. * @type {module:echarts/ExtensionAPI}
  48298. */
  48299. this._api = api;
  48300. /**
  48301. * Should be cleaned when render.
  48302. * @private
  48303. * @type {Array.<Array.<Object>>}
  48304. */
  48305. this._lastDataByCoordSys = null;
  48306. /**
  48307. * @private
  48308. * @type {boolean}
  48309. */
  48310. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  48311. var tooltipContent = this._tooltipContent;
  48312. tooltipContent.update();
  48313. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  48314. this._initGlobalListener();
  48315. this._keepShow();
  48316. },
  48317. _initGlobalListener: function () {
  48318. var tooltipModel = this._tooltipModel;
  48319. var triggerOn = tooltipModel.get('triggerOn');
  48320. register('itemTooltip', this._api, bind$2(function (currTrigger, e, dispatchAction) {
  48321. // If 'none', it is not controlled by mouse totally.
  48322. if (triggerOn !== 'none') {
  48323. if (triggerOn.indexOf(currTrigger) >= 0) {
  48324. this._tryShow(e, dispatchAction);
  48325. } else if (currTrigger === 'leave') {
  48326. this._hide(dispatchAction);
  48327. }
  48328. }
  48329. }, this));
  48330. },
  48331. _keepShow: function () {
  48332. var tooltipModel = this._tooltipModel;
  48333. var ecModel = this._ecModel;
  48334. var api = this._api; // Try to keep the tooltip show when refreshing
  48335. if (this._lastX != null && this._lastY != null // When user is willing to control tooltip totally using API,
  48336. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  48337. // which is not expected.
  48338. && tooltipModel.get('triggerOn') !== 'none') {
  48339. var self = this;
  48340. clearTimeout(this._refreshUpdateTimeout);
  48341. this._refreshUpdateTimeout = setTimeout(function () {
  48342. // Show tip next tick after other charts are rendered
  48343. // In case highlight action has wrong result
  48344. // FIXME
  48345. !api.isDisposed() && self.manuallyShowTip(tooltipModel, ecModel, api, {
  48346. x: self._lastX,
  48347. y: self._lastY
  48348. });
  48349. });
  48350. }
  48351. },
  48352. /**
  48353. * Show tip manually by
  48354. * dispatchAction({
  48355. * type: 'showTip',
  48356. * x: 10,
  48357. * y: 10
  48358. * });
  48359. * Or
  48360. * dispatchAction({
  48361. * type: 'showTip',
  48362. * seriesIndex: 0,
  48363. * dataIndex or dataIndexInside or name
  48364. * });
  48365. *
  48366. * TODO Batch
  48367. */
  48368. manuallyShowTip: function (tooltipModel, ecModel, api, payload) {
  48369. if (payload.from === this.uid || env$1.node) {
  48370. return;
  48371. }
  48372. var dispatchAction = makeDispatchAction$1(payload, api); // Reset ticket
  48373. this._ticket = ''; // When triggered from axisPointer.
  48374. var dataByCoordSys = payload.dataByCoordSys;
  48375. if (payload.tooltip && payload.x != null && payload.y != null) {
  48376. var el = proxyRect;
  48377. el.position = [payload.x, payload.y];
  48378. el.update();
  48379. el.tooltip = payload.tooltip; // Manually show tooltip while view is not using zrender elements.
  48380. this._tryShow({
  48381. offsetX: payload.x,
  48382. offsetY: payload.y,
  48383. target: el
  48384. }, dispatchAction);
  48385. } else if (dataByCoordSys) {
  48386. this._tryShow({
  48387. offsetX: payload.x,
  48388. offsetY: payload.y,
  48389. position: payload.position,
  48390. dataByCoordSys: payload.dataByCoordSys,
  48391. tooltipOption: payload.tooltipOption
  48392. }, dispatchAction);
  48393. } else if (payload.seriesIndex != null) {
  48394. if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
  48395. return;
  48396. }
  48397. var pointInfo = findPointFromSeries(payload, ecModel);
  48398. var cx = pointInfo.point[0];
  48399. var cy = pointInfo.point[1];
  48400. if (cx != null && cy != null) {
  48401. this._tryShow({
  48402. offsetX: cx,
  48403. offsetY: cy,
  48404. position: payload.position,
  48405. target: pointInfo.el
  48406. }, dispatchAction);
  48407. }
  48408. } else if (payload.x != null && payload.y != null) {
  48409. // FIXME
  48410. // should wrap dispatchAction like `axisPointer/globalListener` ?
  48411. api.dispatchAction({
  48412. type: 'updateAxisPointer',
  48413. x: payload.x,
  48414. y: payload.y
  48415. });
  48416. this._tryShow({
  48417. offsetX: payload.x,
  48418. offsetY: payload.y,
  48419. position: payload.position,
  48420. target: api.getZr().findHover(payload.x, payload.y).target
  48421. }, dispatchAction);
  48422. }
  48423. },
  48424. manuallyHideTip: function (tooltipModel, ecModel, api, payload) {
  48425. var tooltipContent = this._tooltipContent;
  48426. if (!this._alwaysShowContent && this._tooltipModel) {
  48427. tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  48428. }
  48429. this._lastX = this._lastY = null;
  48430. if (payload.from !== this.uid) {
  48431. this._hide(makeDispatchAction$1(payload, api));
  48432. }
  48433. },
  48434. // Be compatible with previous design, that is, when tooltip.type is 'axis' and
  48435. // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
  48436. // and tooltip.
  48437. _manuallyAxisShowTip: function (tooltipModel, ecModel, api, payload) {
  48438. var seriesIndex = payload.seriesIndex;
  48439. var dataIndex = payload.dataIndex;
  48440. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  48441. if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
  48442. return;
  48443. }
  48444. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  48445. if (!seriesModel) {
  48446. return;
  48447. }
  48448. var data = seriesModel.getData();
  48449. var tooltipModel = buildTooltipModel([data.getItemModel(dataIndex), seriesModel, (seriesModel.coordinateSystem || {}).model, tooltipModel]);
  48450. if (tooltipModel.get('trigger') !== 'axis') {
  48451. return;
  48452. }
  48453. api.dispatchAction({
  48454. type: 'updateAxisPointer',
  48455. seriesIndex: seriesIndex,
  48456. dataIndex: dataIndex,
  48457. position: payload.position
  48458. });
  48459. return true;
  48460. },
  48461. _tryShow: function (e, dispatchAction) {
  48462. var el = e.target;
  48463. var tooltipModel = this._tooltipModel;
  48464. if (!tooltipModel) {
  48465. return;
  48466. } // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  48467. this._lastX = e.offsetX;
  48468. this._lastY = e.offsetY;
  48469. var dataByCoordSys = e.dataByCoordSys;
  48470. if (dataByCoordSys && dataByCoordSys.length) {
  48471. this._showAxisTooltip(dataByCoordSys, e);
  48472. } // Always show item tooltip if mouse is on the element with dataIndex
  48473. else if (el && el.dataIndex != null) {
  48474. this._lastDataByCoordSys = null;
  48475. this._showSeriesItemTooltip(e, el, dispatchAction);
  48476. } // Tooltip provided directly. Like legend.
  48477. else if (el && el.tooltip) {
  48478. this._lastDataByCoordSys = null;
  48479. this._showComponentItemTooltip(e, el, dispatchAction);
  48480. } else {
  48481. this._lastDataByCoordSys = null;
  48482. this._hide(dispatchAction);
  48483. }
  48484. },
  48485. _showOrMove: function (tooltipModel, cb) {
  48486. // showDelay is used in this case: tooltip.enterable is set
  48487. // as true. User intent to move mouse into tooltip and click
  48488. // something. `showDelay` makes it easyer to enter the content
  48489. // but tooltip do not move immediately.
  48490. var delay = tooltipModel.get('showDelay');
  48491. cb = bind(cb, this);
  48492. clearTimeout(this._showTimout);
  48493. delay > 0 ? this._showTimout = setTimeout(cb, delay) : cb();
  48494. },
  48495. _showAxisTooltip: function (dataByCoordSys, e) {
  48496. var ecModel = this._ecModel;
  48497. var globalTooltipModel = this._tooltipModel;
  48498. var point = [e.offsetX, e.offsetY];
  48499. var singleDefaultHTML = [];
  48500. var singleParamsList = [];
  48501. var singleTooltipModel = buildTooltipModel([e.tooltipOption, globalTooltipModel]);
  48502. var renderMode = this._renderMode;
  48503. var newLine = this._newLine;
  48504. var markers = {};
  48505. each$11(dataByCoordSys, function (itemCoordSys) {
  48506. // var coordParamList = [];
  48507. // var coordDefaultHTML = [];
  48508. // var coordTooltipModel = buildTooltipModel([
  48509. // e.tooltipOption,
  48510. // itemCoordSys.tooltipOption,
  48511. // ecModel.getComponent(itemCoordSys.coordSysMainType, itemCoordSys.coordSysIndex),
  48512. // globalTooltipModel
  48513. // ]);
  48514. // var displayMode = coordTooltipModel.get('displayMode');
  48515. // var paramsList = displayMode === 'single' ? singleParamsList : [];
  48516. each$11(itemCoordSys.dataByAxis, function (item) {
  48517. var axisModel = ecModel.getComponent(item.axisDim + 'Axis', item.axisIndex);
  48518. var axisValue = item.value;
  48519. var seriesDefaultHTML = [];
  48520. if (!axisModel || axisValue == null) {
  48521. return;
  48522. }
  48523. var valueLabel = getValueLabel(axisValue, axisModel.axis, ecModel, item.seriesDataIndices, item.valueLabelOpt);
  48524. each$1(item.seriesDataIndices, function (idxItem) {
  48525. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  48526. var dataIndex = idxItem.dataIndexInside;
  48527. var dataParams = series && series.getDataParams(dataIndex);
  48528. dataParams.axisDim = item.axisDim;
  48529. dataParams.axisIndex = item.axisIndex;
  48530. dataParams.axisType = item.axisType;
  48531. dataParams.axisId = item.axisId;
  48532. dataParams.axisValue = getAxisRawValue(axisModel.axis, axisValue);
  48533. dataParams.axisValueLabel = valueLabel;
  48534. if (dataParams) {
  48535. singleParamsList.push(dataParams);
  48536. var seriesTooltip = series.formatTooltip(dataIndex, true, null, renderMode);
  48537. var html;
  48538. if (isObject$1(seriesTooltip)) {
  48539. html = seriesTooltip.html;
  48540. var newMarkers = seriesTooltip.markers;
  48541. merge(markers, newMarkers);
  48542. } else {
  48543. html = seriesTooltip;
  48544. }
  48545. seriesDefaultHTML.push(html);
  48546. }
  48547. }); // Default tooltip content
  48548. // FIXME
  48549. // (1) shold be the first data which has name?
  48550. // (2) themeRiver, firstDataIndex is array, and first line is unnecessary.
  48551. var firstLine = valueLabel;
  48552. if (renderMode !== 'html') {
  48553. singleDefaultHTML.push(seriesDefaultHTML.join(newLine));
  48554. } else {
  48555. singleDefaultHTML.push((firstLine ? encodeHTML(firstLine) + newLine : '') + seriesDefaultHTML.join(newLine));
  48556. }
  48557. });
  48558. }, this); // In most case, the second axis is shown upper than the first one.
  48559. singleDefaultHTML.reverse();
  48560. singleDefaultHTML = singleDefaultHTML.join(this._newLine + this._newLine);
  48561. var positionExpr = e.position;
  48562. this._showOrMove(singleTooltipModel, function () {
  48563. if (this._updateContentNotChangedOnAxis(dataByCoordSys)) {
  48564. this._updatePosition(singleTooltipModel, positionExpr, point[0], point[1], this._tooltipContent, singleParamsList);
  48565. } else {
  48566. this._showTooltipContent(singleTooltipModel, singleDefaultHTML, singleParamsList, Math.random(), point[0], point[1], positionExpr, undefined, markers);
  48567. }
  48568. }); // Do not trigger events here, because this branch only be entered
  48569. // from dispatchAction.
  48570. },
  48571. _showSeriesItemTooltip: function (e, el, dispatchAction) {
  48572. var ecModel = this._ecModel; // Use dataModel in element if possible
  48573. // Used when mouseover on a element like markPoint or edge
  48574. // In which case, the data is not main data in series.
  48575. var seriesIndex = el.seriesIndex;
  48576. var seriesModel = ecModel.getSeriesByIndex(seriesIndex); // For example, graph link.
  48577. var dataModel = el.dataModel || seriesModel;
  48578. var dataIndex = el.dataIndex;
  48579. var dataType = el.dataType;
  48580. var data = dataModel.getData(dataType);
  48581. var tooltipModel = buildTooltipModel([data.getItemModel(dataIndex), dataModel, seriesModel && (seriesModel.coordinateSystem || {}).model, this._tooltipModel]);
  48582. var tooltipTrigger = tooltipModel.get('trigger');
  48583. if (tooltipTrigger != null && tooltipTrigger !== 'item') {
  48584. return;
  48585. }
  48586. var params = dataModel.getDataParams(dataIndex, dataType);
  48587. var seriesTooltip = dataModel.formatTooltip(dataIndex, false, dataType, this._renderMode);
  48588. var defaultHtml;
  48589. var markers;
  48590. if (isObject$1(seriesTooltip)) {
  48591. defaultHtml = seriesTooltip.html;
  48592. markers = seriesTooltip.markers;
  48593. } else {
  48594. defaultHtml = seriesTooltip;
  48595. markers = null;
  48596. }
  48597. var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
  48598. this._showOrMove(tooltipModel, function () {
  48599. this._showTooltipContent(tooltipModel, defaultHtml, params, asyncTicket, e.offsetX, e.offsetY, e.position, e.target, markers);
  48600. }); // FIXME
  48601. // duplicated showtip if manuallyShowTip is called from dispatchAction.
  48602. dispatchAction({
  48603. type: 'showTip',
  48604. dataIndexInside: dataIndex,
  48605. dataIndex: data.getRawIndex(dataIndex),
  48606. seriesIndex: seriesIndex,
  48607. from: this.uid
  48608. });
  48609. },
  48610. _showComponentItemTooltip: function (e, el, dispatchAction) {
  48611. var tooltipOpt = el.tooltip;
  48612. if (typeof tooltipOpt === 'string') {
  48613. var content = tooltipOpt;
  48614. tooltipOpt = {
  48615. content: content,
  48616. // Fixed formatter
  48617. formatter: content
  48618. };
  48619. }
  48620. var subTooltipModel = new Model(tooltipOpt, this._tooltipModel, this._ecModel);
  48621. var defaultHtml = subTooltipModel.get('content');
  48622. var asyncTicket = Math.random(); // Do not check whether `trigger` is 'none' here, because `trigger`
  48623. // only works on cooridinate system. In fact, we have not found case
  48624. // that requires setting `trigger` nothing on component yet.
  48625. this._showOrMove(subTooltipModel, function () {
  48626. this._showTooltipContent(subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') || {}, asyncTicket, e.offsetX, e.offsetY, e.position, el);
  48627. }); // If not dispatch showTip, tip may be hide triggered by axis.
  48628. dispatchAction({
  48629. type: 'showTip',
  48630. from: this.uid
  48631. });
  48632. },
  48633. _showTooltipContent: function (tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el, markers) {
  48634. // Reset ticket
  48635. this._ticket = '';
  48636. if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
  48637. return;
  48638. }
  48639. var tooltipContent = this._tooltipContent;
  48640. var formatter = tooltipModel.get('formatter');
  48641. positionExpr = positionExpr || tooltipModel.get('position');
  48642. var html = defaultHtml;
  48643. if (formatter && typeof formatter === 'string') {
  48644. html = formatTpl(formatter, params, true);
  48645. } else if (typeof formatter === 'function') {
  48646. var callback = bind$2(function (cbTicket, html) {
  48647. if (cbTicket === this._ticket) {
  48648. tooltipContent.setContent(html, markers, tooltipModel);
  48649. this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
  48650. }
  48651. }, this);
  48652. this._ticket = asyncTicket;
  48653. html = formatter(params, asyncTicket, callback);
  48654. }
  48655. tooltipContent.setContent(html, markers, tooltipModel);
  48656. tooltipContent.show(tooltipModel);
  48657. this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
  48658. },
  48659. /**
  48660. * @param {string|Function|Array.<number>|Object} positionExpr
  48661. * @param {number} x Mouse x
  48662. * @param {number} y Mouse y
  48663. * @param {boolean} confine Whether confine tooltip content in view rect.
  48664. * @param {Object|<Array.<Object>} params
  48665. * @param {module:zrender/Element} el target element
  48666. * @param {module:echarts/ExtensionAPI} api
  48667. * @return {Array.<number>}
  48668. */
  48669. _updatePosition: function (tooltipModel, positionExpr, x, y, content, params, el) {
  48670. var viewWidth = this._api.getWidth();
  48671. var viewHeight = this._api.getHeight();
  48672. positionExpr = positionExpr || tooltipModel.get('position');
  48673. var contentSize = content.getSize();
  48674. var align = tooltipModel.get('align');
  48675. var vAlign = tooltipModel.get('verticalAlign');
  48676. var rect = el && el.getBoundingRect().clone();
  48677. el && rect.applyTransform(el.transform);
  48678. if (typeof positionExpr === 'function') {
  48679. // Callback of position can be an array or a string specify the position
  48680. positionExpr = positionExpr([x, y], params, content.el, rect, {
  48681. viewSize: [viewWidth, viewHeight],
  48682. contentSize: contentSize.slice()
  48683. });
  48684. }
  48685. if (isArray(positionExpr)) {
  48686. x = parsePercent$2(positionExpr[0], viewWidth);
  48687. y = parsePercent$2(positionExpr[1], viewHeight);
  48688. } else if (isObject$1(positionExpr)) {
  48689. positionExpr.width = contentSize[0];
  48690. positionExpr.height = contentSize[1];
  48691. var layoutRect = getLayoutRect(positionExpr, {
  48692. width: viewWidth,
  48693. height: viewHeight
  48694. });
  48695. x = layoutRect.x;
  48696. y = layoutRect.y;
  48697. align = null; // When positionExpr is left/top/right/bottom,
  48698. // align and verticalAlign will not work.
  48699. vAlign = null;
  48700. } // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  48701. else if (typeof positionExpr === 'string' && el) {
  48702. var pos = calcTooltipPosition(positionExpr, rect, contentSize);
  48703. x = pos[0];
  48704. y = pos[1];
  48705. } else {
  48706. var pos = refixTooltipPosition(x, y, content, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20);
  48707. x = pos[0];
  48708. y = pos[1];
  48709. }
  48710. align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
  48711. vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
  48712. if (tooltipModel.get('confine')) {
  48713. var pos = confineTooltipPosition(x, y, content, viewWidth, viewHeight);
  48714. x = pos[0];
  48715. y = pos[1];
  48716. }
  48717. content.moveTo(x, y);
  48718. },
  48719. // FIXME
  48720. // Should we remove this but leave this to user?
  48721. _updateContentNotChangedOnAxis: function (dataByCoordSys) {
  48722. var lastCoordSys = this._lastDataByCoordSys;
  48723. var contentNotChanged = !!lastCoordSys && lastCoordSys.length === dataByCoordSys.length;
  48724. contentNotChanged && each$11(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
  48725. var lastDataByAxis = lastItemCoordSys.dataByAxis || {};
  48726. var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
  48727. var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
  48728. contentNotChanged &= lastDataByAxis.length === thisDataByAxis.length;
  48729. contentNotChanged && each$11(lastDataByAxis, function (lastItem, indexAxis) {
  48730. var thisItem = thisDataByAxis[indexAxis] || {};
  48731. var lastIndices = lastItem.seriesDataIndices || [];
  48732. var newIndices = thisItem.seriesDataIndices || [];
  48733. contentNotChanged &= lastItem.value === thisItem.value && lastItem.axisType === thisItem.axisType && lastItem.axisId === thisItem.axisId && lastIndices.length === newIndices.length;
  48734. contentNotChanged && each$11(lastIndices, function (lastIdxItem, j) {
  48735. var newIdxItem = newIndices[j];
  48736. contentNotChanged &= lastIdxItem.seriesIndex === newIdxItem.seriesIndex && lastIdxItem.dataIndex === newIdxItem.dataIndex;
  48737. });
  48738. });
  48739. });
  48740. this._lastDataByCoordSys = dataByCoordSys;
  48741. return !!contentNotChanged;
  48742. },
  48743. _hide: function (dispatchAction) {
  48744. // Do not directly hideLater here, because this behavior may be prevented
  48745. // in dispatchAction when showTip is dispatched.
  48746. // FIXME
  48747. // duplicated hideTip if manuallyHideTip is called from dispatchAction.
  48748. this._lastDataByCoordSys = null;
  48749. dispatchAction({
  48750. type: 'hideTip',
  48751. from: this.uid
  48752. });
  48753. },
  48754. dispose: function (ecModel, api) {
  48755. if (env$1.node) {
  48756. return;
  48757. }
  48758. this._tooltipContent.dispose();
  48759. unregister('itemTooltip', api);
  48760. }
  48761. });
  48762. /**
  48763. * @param {Array.<Object|module:echarts/model/Model>} modelCascade
  48764. * From top to bottom. (the last one should be globalTooltipModel);
  48765. */
  48766. function buildTooltipModel(modelCascade) {
  48767. var resultModel = modelCascade.pop();
  48768. while (modelCascade.length) {
  48769. var tooltipOpt = modelCascade.pop();
  48770. if (tooltipOpt) {
  48771. if (Model.isInstance(tooltipOpt)) {
  48772. tooltipOpt = tooltipOpt.get('tooltip', true);
  48773. } // In each data item tooltip can be simply write:
  48774. // {
  48775. // value: 10,
  48776. // tooltip: 'Something you need to know'
  48777. // }
  48778. if (typeof tooltipOpt === 'string') {
  48779. tooltipOpt = {
  48780. formatter: tooltipOpt
  48781. };
  48782. }
  48783. resultModel = new Model(tooltipOpt, resultModel, resultModel.ecModel);
  48784. }
  48785. }
  48786. return resultModel;
  48787. }
  48788. function makeDispatchAction$1(payload, api) {
  48789. return payload.dispatchAction || bind(api.dispatchAction, api);
  48790. }
  48791. function refixTooltipPosition(x, y, content, viewWidth, viewHeight, gapH, gapV) {
  48792. var size = content.getOuterSize();
  48793. var width = size.width;
  48794. var height = size.height;
  48795. if (gapH != null) {
  48796. if (x + width + gapH > viewWidth) {
  48797. x -= width + gapH;
  48798. } else {
  48799. x += gapH;
  48800. }
  48801. }
  48802. if (gapV != null) {
  48803. if (y + height + gapV > viewHeight) {
  48804. y -= height + gapV;
  48805. } else {
  48806. y += gapV;
  48807. }
  48808. }
  48809. return [x, y];
  48810. }
  48811. function confineTooltipPosition(x, y, content, viewWidth, viewHeight) {
  48812. var size = content.getOuterSize();
  48813. var width = size.width;
  48814. var height = size.height;
  48815. x = Math.min(x + width, viewWidth) - width;
  48816. y = Math.min(y + height, viewHeight) - height;
  48817. x = Math.max(x, 0);
  48818. y = Math.max(y, 0);
  48819. return [x, y];
  48820. }
  48821. function calcTooltipPosition(position, rect, contentSize) {
  48822. var domWidth = contentSize[0];
  48823. var domHeight = contentSize[1];
  48824. var gap = 5;
  48825. var x = 0;
  48826. var y = 0;
  48827. var rectWidth = rect.width;
  48828. var rectHeight = rect.height;
  48829. switch (position) {
  48830. case 'inside':
  48831. x = rect.x + rectWidth / 2 - domWidth / 2;
  48832. y = rect.y + rectHeight / 2 - domHeight / 2;
  48833. break;
  48834. case 'top':
  48835. x = rect.x + rectWidth / 2 - domWidth / 2;
  48836. y = rect.y - domHeight - gap;
  48837. break;
  48838. case 'bottom':
  48839. x = rect.x + rectWidth / 2 - domWidth / 2;
  48840. y = rect.y + rectHeight + gap;
  48841. break;
  48842. case 'left':
  48843. x = rect.x - domWidth - gap;
  48844. y = rect.y + rectHeight / 2 - domHeight / 2;
  48845. break;
  48846. case 'right':
  48847. x = rect.x + rectWidth + gap;
  48848. y = rect.y + rectHeight / 2 - domHeight / 2;
  48849. }
  48850. return [x, y];
  48851. }
  48852. function isCenterAlign(align) {
  48853. return align === 'center' || align === 'middle';
  48854. }
  48855. /*
  48856. * Licensed to the Apache Software Foundation (ASF) under one
  48857. * or more contributor license agreements. See the NOTICE file
  48858. * distributed with this work for additional information
  48859. * regarding copyright ownership. The ASF licenses this file
  48860. * to you under the Apache License, Version 2.0 (the
  48861. * "License"); you may not use this file except in compliance
  48862. * with the License. You may obtain a copy of the License at
  48863. *
  48864. * http://www.apache.org/licenses/LICENSE-2.0
  48865. *
  48866. * Unless required by applicable law or agreed to in writing,
  48867. * software distributed under the License is distributed on an
  48868. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48869. * KIND, either express or implied. See the License for the
  48870. * specific language governing permissions and limitations
  48871. * under the License.
  48872. */
  48873. // FIXME Better way to pack data in graphic element
  48874. /**
  48875. * @action
  48876. * @property {string} type
  48877. * @property {number} seriesIndex
  48878. * @property {number} dataIndex
  48879. * @property {number} [x]
  48880. * @property {number} [y]
  48881. */
  48882. registerAction({
  48883. type: 'showTip',
  48884. event: 'showTip',
  48885. update: 'tooltip:manuallyShowTip'
  48886. }, // noop
  48887. function () {});
  48888. registerAction({
  48889. type: 'hideTip',
  48890. event: 'hideTip',
  48891. update: 'tooltip:manuallyHideTip'
  48892. }, // noop
  48893. function () {});
  48894. /*
  48895. * Licensed to the Apache Software Foundation (ASF) under one
  48896. * or more contributor license agreements. See the NOTICE file
  48897. * distributed with this work for additional information
  48898. * regarding copyright ownership. The ASF licenses this file
  48899. * to you under the Apache License, Version 2.0 (the
  48900. * "License"); you may not use this file except in compliance
  48901. * with the License. You may obtain a copy of the License at
  48902. *
  48903. * http://www.apache.org/licenses/LICENSE-2.0
  48904. *
  48905. * Unless required by applicable law or agreed to in writing,
  48906. * software distributed under the License is distributed on an
  48907. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48908. * KIND, either express or implied. See the License for the
  48909. * specific language governing permissions and limitations
  48910. * under the License.
  48911. */
  48912. var addCommas$1 = addCommas;
  48913. var encodeHTML$1 = encodeHTML;
  48914. function fillLabel(opt) {
  48915. defaultEmphasis(opt, 'label', ['show']);
  48916. }
  48917. var MarkerModel = extendComponentModel({
  48918. type: 'marker',
  48919. dependencies: ['series', 'grid', 'polar', 'geo'],
  48920. /**
  48921. * @overrite
  48922. */
  48923. init: function (option, parentModel, ecModel) {
  48924. this.mergeDefaultAndTheme(option, ecModel);
  48925. this._mergeOption(option, ecModel, false, true);
  48926. },
  48927. /**
  48928. * @return {boolean}
  48929. */
  48930. isAnimationEnabled: function () {
  48931. if (env$1.node) {
  48932. return false;
  48933. }
  48934. var hostSeries = this.__hostSeries;
  48935. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  48936. },
  48937. /**
  48938. * @overrite
  48939. */
  48940. mergeOption: function (newOpt, ecModel) {
  48941. this._mergeOption(newOpt, ecModel, false, false);
  48942. },
  48943. _mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  48944. var MarkerModel = this.constructor;
  48945. var modelPropName = this.mainType + 'Model';
  48946. if (!createdBySelf) {
  48947. ecModel.eachSeries(function (seriesModel) {
  48948. var markerOpt = seriesModel.get(this.mainType, true);
  48949. var markerModel = seriesModel[modelPropName];
  48950. if (!markerOpt || !markerOpt.data) {
  48951. seriesModel[modelPropName] = null;
  48952. return;
  48953. }
  48954. if (!markerModel) {
  48955. if (isInit) {
  48956. // Default label emphasis `position` and `show`
  48957. fillLabel(markerOpt);
  48958. }
  48959. each$1(markerOpt.data, function (item) {
  48960. // FIXME Overwrite fillLabel method ?
  48961. if (item instanceof Array) {
  48962. fillLabel(item[0]);
  48963. fillLabel(item[1]);
  48964. } else {
  48965. fillLabel(item);
  48966. }
  48967. });
  48968. markerModel = new MarkerModel(markerOpt, this, ecModel);
  48969. extend(markerModel, {
  48970. mainType: this.mainType,
  48971. // Use the same series index and name
  48972. seriesIndex: seriesModel.seriesIndex,
  48973. name: seriesModel.name,
  48974. createdBySelf: true
  48975. });
  48976. markerModel.__hostSeries = seriesModel;
  48977. } else {
  48978. markerModel._mergeOption(markerOpt, ecModel, true);
  48979. }
  48980. seriesModel[modelPropName] = markerModel;
  48981. }, this);
  48982. }
  48983. },
  48984. formatTooltip: function (dataIndex) {
  48985. var data = this.getData();
  48986. var value = this.getRawValue(dataIndex);
  48987. var formattedValue = isArray(value) ? map(value, addCommas$1).join(', ') : addCommas$1(value);
  48988. var name = data.getName(dataIndex);
  48989. var html = encodeHTML$1(this.name);
  48990. if (value != null || name) {
  48991. html += '<br />';
  48992. }
  48993. if (name) {
  48994. html += encodeHTML$1(name);
  48995. if (value != null) {
  48996. html += ' : ';
  48997. }
  48998. }
  48999. if (value != null) {
  49000. html += encodeHTML$1(formattedValue);
  49001. }
  49002. return html;
  49003. },
  49004. getData: function () {
  49005. return this._data;
  49006. },
  49007. setData: function (data) {
  49008. this._data = data;
  49009. }
  49010. });
  49011. mixin(MarkerModel, dataFormatMixin);
  49012. /*
  49013. * Licensed to the Apache Software Foundation (ASF) under one
  49014. * or more contributor license agreements. See the NOTICE file
  49015. * distributed with this work for additional information
  49016. * regarding copyright ownership. The ASF licenses this file
  49017. * to you under the Apache License, Version 2.0 (the
  49018. * "License"); you may not use this file except in compliance
  49019. * with the License. You may obtain a copy of the License at
  49020. *
  49021. * http://www.apache.org/licenses/LICENSE-2.0
  49022. *
  49023. * Unless required by applicable law or agreed to in writing,
  49024. * software distributed under the License is distributed on an
  49025. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49026. * KIND, either express or implied. See the License for the
  49027. * specific language governing permissions and limitations
  49028. * under the License.
  49029. */
  49030. MarkerModel.extend({
  49031. type: 'markPoint',
  49032. defaultOption: {
  49033. zlevel: 0,
  49034. z: 5,
  49035. symbol: 'pin',
  49036. symbolSize: 50,
  49037. //symbolRotate: 0,
  49038. //symbolOffset: [0, 0]
  49039. tooltip: {
  49040. trigger: 'item'
  49041. },
  49042. label: {
  49043. show: true,
  49044. position: 'inside'
  49045. },
  49046. itemStyle: {
  49047. borderWidth: 2
  49048. },
  49049. emphasis: {
  49050. label: {
  49051. show: true
  49052. }
  49053. }
  49054. }
  49055. });
  49056. /*
  49057. * Licensed to the Apache Software Foundation (ASF) under one
  49058. * or more contributor license agreements. See the NOTICE file
  49059. * distributed with this work for additional information
  49060. * regarding copyright ownership. The ASF licenses this file
  49061. * to you under the Apache License, Version 2.0 (the
  49062. * "License"); you may not use this file except in compliance
  49063. * with the License. You may obtain a copy of the License at
  49064. *
  49065. * http://www.apache.org/licenses/LICENSE-2.0
  49066. *
  49067. * Unless required by applicable law or agreed to in writing,
  49068. * software distributed under the License is distributed on an
  49069. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49070. * KIND, either express or implied. See the License for the
  49071. * specific language governing permissions and limitations
  49072. * under the License.
  49073. */
  49074. var indexOf$1 = indexOf;
  49075. function hasXOrY(item) {
  49076. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  49077. }
  49078. function hasXAndY(item) {
  49079. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  49080. } // Make it simple, do not visit all stacked value to count precision.
  49081. // function getPrecision(data, valueAxisDim, dataIndex) {
  49082. // var precision = -1;
  49083. // var stackedDim = data.mapDimension(valueAxisDim);
  49084. // do {
  49085. // precision = Math.max(
  49086. // numberUtil.getPrecision(data.get(stackedDim, dataIndex)),
  49087. // precision
  49088. // );
  49089. // var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  49090. // if (stackedOnSeries) {
  49091. // var byValue = data.get(data.getCalculationInfo('stackedByDimension'), dataIndex);
  49092. // data = stackedOnSeries.getData();
  49093. // dataIndex = data.indexOf(data.getCalculationInfo('stackedByDimension'), byValue);
  49094. // stackedDim = data.getCalculationInfo('stackedDimension');
  49095. // }
  49096. // else {
  49097. // data = null;
  49098. // }
  49099. // } while (data);
  49100. // return precision;
  49101. // }
  49102. function markerTypeCalculatorWithExtent(mlType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex) {
  49103. var coordArr = [];
  49104. var stacked = isDimensionStacked(data, targetDataDim
  49105. /*, otherDataDim*/
  49106. );
  49107. var calcDataDim = stacked ? data.getCalculationInfo('stackResultDimension') : targetDataDim;
  49108. var value = numCalculate(data, calcDataDim, mlType);
  49109. var dataIndex = data.indicesOfNearest(calcDataDim, value)[0];
  49110. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex);
  49111. coordArr[targetCoordIndex] = data.get(calcDataDim, dataIndex);
  49112. var coordArrValue = data.get(targetDataDim, dataIndex); // Make it simple, do not visit all stacked value to count precision.
  49113. var precision = getPrecision(data.get(targetDataDim, dataIndex));
  49114. precision = Math.min(precision, 20);
  49115. if (precision >= 0) {
  49116. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  49117. }
  49118. return [coordArr, coordArrValue];
  49119. }
  49120. var curry$4 = curry; // TODO Specified percent
  49121. var markerTypeCalculator = {
  49122. /**
  49123. * @method
  49124. * @param {module:echarts/data/List} data
  49125. * @param {string} baseAxisDim
  49126. * @param {string} valueAxisDim
  49127. */
  49128. min: curry$4(markerTypeCalculatorWithExtent, 'min'),
  49129. /**
  49130. * @method
  49131. * @param {module:echarts/data/List} data
  49132. * @param {string} baseAxisDim
  49133. * @param {string} valueAxisDim
  49134. */
  49135. max: curry$4(markerTypeCalculatorWithExtent, 'max'),
  49136. /**
  49137. * @method
  49138. * @param {module:echarts/data/List} data
  49139. * @param {string} baseAxisDim
  49140. * @param {string} valueAxisDim
  49141. */
  49142. average: curry$4(markerTypeCalculatorWithExtent, 'average')
  49143. };
  49144. /**
  49145. * Transform markPoint data item to format used in List by do the following
  49146. * 1. Calculate statistic like `max`, `min`, `average`
  49147. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  49148. * @param {module:echarts/model/Series} seriesModel
  49149. * @param {module:echarts/coord/*} [coordSys]
  49150. * @param {Object} item
  49151. * @return {Object}
  49152. */
  49153. function dataTransform(seriesModel, item) {
  49154. var data = seriesModel.getData();
  49155. var coordSys = seriesModel.coordinateSystem; // 1. If not specify the position with pixel directly
  49156. // 2. If `coord` is not a data array. Which uses `xAxis`,
  49157. // `yAxis` to specify the coord on each dimension
  49158. // parseFloat first because item.x and item.y can be percent string like '20%'
  49159. if (item && !hasXAndY(item) && !isArray(item.coord) && coordSys) {
  49160. var dims = coordSys.dimensions;
  49161. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel); // Clone the option
  49162. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  49163. item = clone(item);
  49164. if (item.type && markerTypeCalculator[item.type] && axisInfo.baseAxis && axisInfo.valueAxis) {
  49165. var otherCoordIndex = indexOf$1(dims, axisInfo.baseAxis.dim);
  49166. var targetCoordIndex = indexOf$1(dims, axisInfo.valueAxis.dim);
  49167. var coordInfo = markerTypeCalculator[item.type](data, axisInfo.baseDataDim, axisInfo.valueDataDim, otherCoordIndex, targetCoordIndex);
  49168. item.coord = coordInfo[0]; // Force to use the value of calculated value.
  49169. // let item use the value without stack.
  49170. item.value = coordInfo[1];
  49171. } else {
  49172. // FIXME Only has one of xAxis and yAxis.
  49173. var coord = [item.xAxis != null ? item.xAxis : item.radiusAxis, item.yAxis != null ? item.yAxis : item.angleAxis]; // Each coord support max, min, average
  49174. for (var i = 0; i < 2; i++) {
  49175. if (markerTypeCalculator[coord[i]]) {
  49176. coord[i] = numCalculate(data, data.mapDimension(dims[i]), coord[i]);
  49177. }
  49178. }
  49179. item.coord = coord;
  49180. }
  49181. }
  49182. return item;
  49183. }
  49184. function getAxisInfo$1(item, data, coordSys, seriesModel) {
  49185. var ret = {};
  49186. if (item.valueIndex != null || item.valueDim != null) {
  49187. ret.valueDataDim = item.valueIndex != null ? data.getDimension(item.valueIndex) : item.valueDim;
  49188. ret.valueAxis = coordSys.getAxis(dataDimToCoordDim(seriesModel, ret.valueDataDim));
  49189. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  49190. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  49191. } else {
  49192. ret.baseAxis = seriesModel.getBaseAxis();
  49193. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  49194. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  49195. ret.valueDataDim = data.mapDimension(ret.valueAxis.dim);
  49196. }
  49197. return ret;
  49198. }
  49199. function dataDimToCoordDim(seriesModel, dataDim) {
  49200. var data = seriesModel.getData();
  49201. var dimensions = data.dimensions;
  49202. dataDim = data.getDimension(dataDim);
  49203. for (var i = 0; i < dimensions.length; i++) {
  49204. var dimItem = data.getDimensionInfo(dimensions[i]);
  49205. if (dimItem.name === dataDim) {
  49206. return dimItem.coordDim;
  49207. }
  49208. }
  49209. }
  49210. /**
  49211. * Filter data which is out of coordinateSystem range
  49212. * [dataFilter description]
  49213. * @param {module:echarts/coord/*} [coordSys]
  49214. * @param {Object} item
  49215. * @return {boolean}
  49216. */
  49217. function dataFilter$1(coordSys, item) {
  49218. // Alwalys return true if there is no coordSys
  49219. return coordSys && coordSys.containData && item.coord && !hasXOrY(item) ? coordSys.containData(item.coord) : true;
  49220. }
  49221. function dimValueGetter(item, dimName, dataIndex, dimIndex) {
  49222. // x, y, radius, angle
  49223. if (dimIndex < 2) {
  49224. return item.coord && item.coord[dimIndex];
  49225. }
  49226. return item.value;
  49227. }
  49228. function numCalculate(data, valueDataDim, type) {
  49229. if (type === 'average') {
  49230. var sum = 0;
  49231. var count = 0;
  49232. data.each(valueDataDim, function (val, idx) {
  49233. if (!isNaN(val)) {
  49234. sum += val;
  49235. count++;
  49236. }
  49237. });
  49238. return sum / count;
  49239. } else if (type === 'median') {
  49240. return data.getMedian(valueDataDim);
  49241. } else {
  49242. // max & min
  49243. return data.getDataExtent(valueDataDim, true)[type === 'max' ? 1 : 0];
  49244. }
  49245. }
  49246. /*
  49247. * Licensed to the Apache Software Foundation (ASF) under one
  49248. * or more contributor license agreements. See the NOTICE file
  49249. * distributed with this work for additional information
  49250. * regarding copyright ownership. The ASF licenses this file
  49251. * to you under the Apache License, Version 2.0 (the
  49252. * "License"); you may not use this file except in compliance
  49253. * with the License. You may obtain a copy of the License at
  49254. *
  49255. * http://www.apache.org/licenses/LICENSE-2.0
  49256. *
  49257. * Unless required by applicable law or agreed to in writing,
  49258. * software distributed under the License is distributed on an
  49259. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49260. * KIND, either express or implied. See the License for the
  49261. * specific language governing permissions and limitations
  49262. * under the License.
  49263. */
  49264. var MarkerView = extendComponentView({
  49265. type: 'marker',
  49266. init: function () {
  49267. /**
  49268. * Markline grouped by series
  49269. * @private
  49270. * @type {module:zrender/core/util.HashMap}
  49271. */
  49272. this.markerGroupMap = createHashMap();
  49273. },
  49274. render: function (markerModel, ecModel, api) {
  49275. var markerGroupMap = this.markerGroupMap;
  49276. markerGroupMap.each(function (item) {
  49277. item.__keep = false;
  49278. });
  49279. var markerModelKey = this.type + 'Model';
  49280. ecModel.eachSeries(function (seriesModel) {
  49281. var markerModel = seriesModel[markerModelKey];
  49282. markerModel && this.renderSeries(seriesModel, markerModel, ecModel, api);
  49283. }, this);
  49284. markerGroupMap.each(function (item) {
  49285. !item.__keep && this.group.remove(item.group);
  49286. }, this);
  49287. },
  49288. renderSeries: function () {}
  49289. });
  49290. /*
  49291. * Licensed to the Apache Software Foundation (ASF) under one
  49292. * or more contributor license agreements. See the NOTICE file
  49293. * distributed with this work for additional information
  49294. * regarding copyright ownership. The ASF licenses this file
  49295. * to you under the Apache License, Version 2.0 (the
  49296. * "License"); you may not use this file except in compliance
  49297. * with the License. You may obtain a copy of the License at
  49298. *
  49299. * http://www.apache.org/licenses/LICENSE-2.0
  49300. *
  49301. * Unless required by applicable law or agreed to in writing,
  49302. * software distributed under the License is distributed on an
  49303. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49304. * KIND, either express or implied. See the License for the
  49305. * specific language governing permissions and limitations
  49306. * under the License.
  49307. */
  49308. function updateMarkerLayout(mpData, seriesModel, api) {
  49309. var coordSys = seriesModel.coordinateSystem;
  49310. mpData.each(function (idx) {
  49311. var itemModel = mpData.getItemModel(idx);
  49312. var point;
  49313. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  49314. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  49315. if (!isNaN(xPx) && !isNaN(yPx)) {
  49316. point = [xPx, yPx];
  49317. } // Chart like bar may have there own marker positioning logic
  49318. else if (seriesModel.getMarkerPosition) {
  49319. // Use the getMarkerPoisition
  49320. point = seriesModel.getMarkerPosition(mpData.getValues(mpData.dimensions, idx));
  49321. } else if (coordSys) {
  49322. var x = mpData.get(coordSys.dimensions[0], idx);
  49323. var y = mpData.get(coordSys.dimensions[1], idx);
  49324. point = coordSys.dataToPoint([x, y]);
  49325. } // Use x, y if has any
  49326. if (!isNaN(xPx)) {
  49327. point[0] = xPx;
  49328. }
  49329. if (!isNaN(yPx)) {
  49330. point[1] = yPx;
  49331. }
  49332. mpData.setItemLayout(idx, point);
  49333. });
  49334. }
  49335. MarkerView.extend({
  49336. type: 'markPoint',
  49337. // updateLayout: function (markPointModel, ecModel, api) {
  49338. // ecModel.eachSeries(function (seriesModel) {
  49339. // var mpModel = seriesModel.markPointModel;
  49340. // if (mpModel) {
  49341. // updateMarkerLayout(mpModel.getData(), seriesModel, api);
  49342. // this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
  49343. // }
  49344. // }, this);
  49345. // },
  49346. updateTransform: function (markPointModel, ecModel, api) {
  49347. ecModel.eachSeries(function (seriesModel) {
  49348. var mpModel = seriesModel.markPointModel;
  49349. if (mpModel) {
  49350. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  49351. this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
  49352. }
  49353. }, this);
  49354. },
  49355. renderSeries: function (seriesModel, mpModel, ecModel, api) {
  49356. var coordSys = seriesModel.coordinateSystem;
  49357. var seriesId = seriesModel.id;
  49358. var seriesData = seriesModel.getData();
  49359. var symbolDrawMap = this.markerGroupMap;
  49360. var symbolDraw = symbolDrawMap.get(seriesId) || symbolDrawMap.set(seriesId, new SymbolDraw());
  49361. var mpData = createList$1(coordSys, seriesModel, mpModel); // FIXME
  49362. mpModel.setData(mpData);
  49363. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  49364. mpData.each(function (idx) {
  49365. var itemModel = mpData.getItemModel(idx);
  49366. var symbol = itemModel.getShallow('symbol');
  49367. var symbolSize = itemModel.getShallow('symbolSize');
  49368. var isFnSymbol = isFunction$1(symbol);
  49369. var isFnSymbolSize = isFunction$1(symbolSize);
  49370. if (isFnSymbol || isFnSymbolSize) {
  49371. var rawIdx = mpModel.getRawValue(idx);
  49372. var dataParams = mpModel.getDataParams(idx);
  49373. if (isFnSymbol) {
  49374. symbol = symbol(rawIdx, dataParams);
  49375. }
  49376. if (isFnSymbolSize) {
  49377. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  49378. symbolSize = symbolSize(rawIdx, dataParams);
  49379. }
  49380. }
  49381. mpData.setItemVisual(idx, {
  49382. symbol: symbol,
  49383. symbolSize: symbolSize,
  49384. color: itemModel.get('itemStyle.color') || seriesData.getVisual('color')
  49385. });
  49386. }); // TODO Text are wrong
  49387. symbolDraw.updateData(mpData);
  49388. this.group.add(symbolDraw.group); // Set host model for tooltip
  49389. // FIXME
  49390. mpData.eachItemGraphicEl(function (el) {
  49391. el.traverse(function (child) {
  49392. child.dataModel = mpModel;
  49393. });
  49394. });
  49395. symbolDraw.__keep = true;
  49396. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  49397. }
  49398. });
  49399. /**
  49400. * @inner
  49401. * @param {module:echarts/coord/*} [coordSys]
  49402. * @param {module:echarts/model/Series} seriesModel
  49403. * @param {module:echarts/model/Model} mpModel
  49404. */
  49405. function createList$1(coordSys, seriesModel, mpModel) {
  49406. var coordDimsInfos;
  49407. if (coordSys) {
  49408. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  49409. var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  49410. return defaults({
  49411. name: coordDim
  49412. }, info);
  49413. });
  49414. } else {
  49415. coordDimsInfos = [{
  49416. name: 'value',
  49417. type: 'float'
  49418. }];
  49419. }
  49420. var mpData = new List(coordDimsInfos, mpModel);
  49421. var dataOpt = map(mpModel.get('data'), curry(dataTransform, seriesModel));
  49422. if (coordSys) {
  49423. dataOpt = filter(dataOpt, curry(dataFilter$1, coordSys));
  49424. }
  49425. mpData.initData(dataOpt, null, coordSys ? dimValueGetter : function (item) {
  49426. return item.value;
  49427. });
  49428. return mpData;
  49429. }
  49430. /*
  49431. * Licensed to the Apache Software Foundation (ASF) under one
  49432. * or more contributor license agreements. See the NOTICE file
  49433. * distributed with this work for additional information
  49434. * regarding copyright ownership. The ASF licenses this file
  49435. * to you under the Apache License, Version 2.0 (the
  49436. * "License"); you may not use this file except in compliance
  49437. * with the License. You may obtain a copy of the License at
  49438. *
  49439. * http://www.apache.org/licenses/LICENSE-2.0
  49440. *
  49441. * Unless required by applicable law or agreed to in writing,
  49442. * software distributed under the License is distributed on an
  49443. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49444. * KIND, either express or implied. See the License for the
  49445. * specific language governing permissions and limitations
  49446. * under the License.
  49447. */
  49448. // HINT Markpoint can't be used too much
  49449. registerPreprocessor(function (opt) {
  49450. // Make sure markPoint component is enabled
  49451. opt.markPoint = opt.markPoint || {};
  49452. });
  49453. /*
  49454. * Licensed to the Apache Software Foundation (ASF) under one
  49455. * or more contributor license agreements. See the NOTICE file
  49456. * distributed with this work for additional information
  49457. * regarding copyright ownership. The ASF licenses this file
  49458. * to you under the Apache License, Version 2.0 (the
  49459. * "License"); you may not use this file except in compliance
  49460. * with the License. You may obtain a copy of the License at
  49461. *
  49462. * http://www.apache.org/licenses/LICENSE-2.0
  49463. *
  49464. * Unless required by applicable law or agreed to in writing,
  49465. * software distributed under the License is distributed on an
  49466. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49467. * KIND, either express or implied. See the License for the
  49468. * specific language governing permissions and limitations
  49469. * under the License.
  49470. */
  49471. var preprocessor = function (option) {
  49472. var timelineOpt = option && option.timeline;
  49473. if (!isArray(timelineOpt)) {
  49474. timelineOpt = timelineOpt ? [timelineOpt] : [];
  49475. }
  49476. each$1(timelineOpt, function (opt) {
  49477. if (!opt) {
  49478. return;
  49479. }
  49480. compatibleEC2(opt);
  49481. });
  49482. };
  49483. function compatibleEC2(opt) {
  49484. var type = opt.type;
  49485. var ec2Types = {
  49486. 'number': 'value',
  49487. 'time': 'time'
  49488. }; // Compatible with ec2
  49489. if (ec2Types[type]) {
  49490. opt.axisType = ec2Types[type];
  49491. delete opt.type;
  49492. }
  49493. transferItem(opt);
  49494. if (has$1(opt, 'controlPosition')) {
  49495. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  49496. if (!has$1(controlStyle, 'position')) {
  49497. controlStyle.position = opt.controlPosition;
  49498. }
  49499. if (controlStyle.position === 'none' && !has$1(controlStyle, 'show')) {
  49500. controlStyle.show = false;
  49501. delete controlStyle.position;
  49502. }
  49503. delete opt.controlPosition;
  49504. }
  49505. each$1(opt.data || [], function (dataItem) {
  49506. if (isObject$1(dataItem) && !isArray(dataItem)) {
  49507. if (!has$1(dataItem, 'value') && has$1(dataItem, 'name')) {
  49508. // In ec2, using name as value.
  49509. dataItem.value = dataItem.name;
  49510. }
  49511. transferItem(dataItem);
  49512. }
  49513. });
  49514. }
  49515. function transferItem(opt) {
  49516. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  49517. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {}); // Transfer label out
  49518. var label = opt.label || opt.label || {};
  49519. var labelNormal = label.normal || (label.normal = {});
  49520. var excludeLabelAttr = {
  49521. normal: 1,
  49522. emphasis: 1
  49523. };
  49524. each$1(label, function (value, name) {
  49525. if (!excludeLabelAttr[name] && !has$1(labelNormal, name)) {
  49526. labelNormal[name] = value;
  49527. }
  49528. });
  49529. if (itemStyleEmphasis.label && !has$1(label, 'emphasis')) {
  49530. label.emphasis = itemStyleEmphasis.label;
  49531. delete itemStyleEmphasis.label;
  49532. }
  49533. }
  49534. function has$1(obj, attr) {
  49535. return obj.hasOwnProperty(attr);
  49536. }
  49537. /*
  49538. * Licensed to the Apache Software Foundation (ASF) under one
  49539. * or more contributor license agreements. See the NOTICE file
  49540. * distributed with this work for additional information
  49541. * regarding copyright ownership. The ASF licenses this file
  49542. * to you under the Apache License, Version 2.0 (the
  49543. * "License"); you may not use this file except in compliance
  49544. * with the License. You may obtain a copy of the License at
  49545. *
  49546. * http://www.apache.org/licenses/LICENSE-2.0
  49547. *
  49548. * Unless required by applicable law or agreed to in writing,
  49549. * software distributed under the License is distributed on an
  49550. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49551. * KIND, either express or implied. See the License for the
  49552. * specific language governing permissions and limitations
  49553. * under the License.
  49554. */
  49555. ComponentModel.registerSubTypeDefaulter('timeline', function () {
  49556. // Only slider now.
  49557. return 'slider';
  49558. });
  49559. /*
  49560. * Licensed to the Apache Software Foundation (ASF) under one
  49561. * or more contributor license agreements. See the NOTICE file
  49562. * distributed with this work for additional information
  49563. * regarding copyright ownership. The ASF licenses this file
  49564. * to you under the Apache License, Version 2.0 (the
  49565. * "License"); you may not use this file except in compliance
  49566. * with the License. You may obtain a copy of the License at
  49567. *
  49568. * http://www.apache.org/licenses/LICENSE-2.0
  49569. *
  49570. * Unless required by applicable law or agreed to in writing,
  49571. * software distributed under the License is distributed on an
  49572. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49573. * KIND, either express or implied. See the License for the
  49574. * specific language governing permissions and limitations
  49575. * under the License.
  49576. */
  49577. registerAction({
  49578. type: 'timelineChange',
  49579. event: 'timelineChanged',
  49580. update: 'prepareAndUpdate'
  49581. }, function (payload, ecModel) {
  49582. var timelineModel = ecModel.getComponent('timeline');
  49583. if (timelineModel && payload.currentIndex != null) {
  49584. timelineModel.setCurrentIndex(payload.currentIndex);
  49585. if (!timelineModel.get('loop', true) && timelineModel.isIndexMax()) {
  49586. timelineModel.setPlayState(false);
  49587. }
  49588. } // Set normalized currentIndex to payload.
  49589. ecModel.resetOption('timeline');
  49590. return defaults({
  49591. currentIndex: timelineModel.option.currentIndex
  49592. }, payload);
  49593. });
  49594. registerAction({
  49595. type: 'timelinePlayChange',
  49596. event: 'timelinePlayChanged',
  49597. update: 'update'
  49598. }, function (payload, ecModel) {
  49599. var timelineModel = ecModel.getComponent('timeline');
  49600. if (timelineModel && payload.playState != null) {
  49601. timelineModel.setPlayState(payload.playState);
  49602. }
  49603. });
  49604. /*
  49605. * Licensed to the Apache Software Foundation (ASF) under one
  49606. * or more contributor license agreements. See the NOTICE file
  49607. * distributed with this work for additional information
  49608. * regarding copyright ownership. The ASF licenses this file
  49609. * to you under the Apache License, Version 2.0 (the
  49610. * "License"); you may not use this file except in compliance
  49611. * with the License. You may obtain a copy of the License at
  49612. *
  49613. * http://www.apache.org/licenses/LICENSE-2.0
  49614. *
  49615. * Unless required by applicable law or agreed to in writing,
  49616. * software distributed under the License is distributed on an
  49617. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49618. * KIND, either express or implied. See the License for the
  49619. * specific language governing permissions and limitations
  49620. * under the License.
  49621. */
  49622. var TimelineModel = ComponentModel.extend({
  49623. type: 'timeline',
  49624. layoutMode: 'box',
  49625. /**
  49626. * @protected
  49627. */
  49628. defaultOption: {
  49629. zlevel: 0,
  49630. // 一级层叠
  49631. z: 4,
  49632. // 二级层叠
  49633. show: true,
  49634. axisType: 'time',
  49635. // 模式是时间类型,支持 value, category
  49636. realtime: true,
  49637. left: '20%',
  49638. top: null,
  49639. right: '20%',
  49640. bottom: 0,
  49641. width: null,
  49642. height: 40,
  49643. padding: 5,
  49644. controlPosition: 'left',
  49645. // 'left' 'right' 'top' 'bottom' 'none'
  49646. autoPlay: false,
  49647. rewind: false,
  49648. // 反向播放
  49649. loop: true,
  49650. playInterval: 2000,
  49651. // 播放时间间隔,单位ms
  49652. currentIndex: 0,
  49653. itemStyle: {},
  49654. label: {
  49655. color: '#000'
  49656. },
  49657. data: []
  49658. },
  49659. /**
  49660. * @override
  49661. */
  49662. init: function (option, parentModel, ecModel) {
  49663. /**
  49664. * @private
  49665. * @type {module:echarts/data/List}
  49666. */
  49667. this._data;
  49668. /**
  49669. * @private
  49670. * @type {Array.<string>}
  49671. */
  49672. this._names;
  49673. this.mergeDefaultAndTheme(option, ecModel);
  49674. this._initData();
  49675. },
  49676. /**
  49677. * @override
  49678. */
  49679. mergeOption: function (option) {
  49680. TimelineModel.superApply(this, 'mergeOption', arguments);
  49681. this._initData();
  49682. },
  49683. /**
  49684. * @param {number} [currentIndex]
  49685. */
  49686. setCurrentIndex: function (currentIndex) {
  49687. if (currentIndex == null) {
  49688. currentIndex = this.option.currentIndex;
  49689. }
  49690. var count = this._data.count();
  49691. if (this.option.loop) {
  49692. currentIndex = (currentIndex % count + count) % count;
  49693. } else {
  49694. currentIndex >= count && (currentIndex = count - 1);
  49695. currentIndex < 0 && (currentIndex = 0);
  49696. }
  49697. this.option.currentIndex = currentIndex;
  49698. },
  49699. /**
  49700. * @return {number} currentIndex
  49701. */
  49702. getCurrentIndex: function () {
  49703. return this.option.currentIndex;
  49704. },
  49705. /**
  49706. * @return {boolean}
  49707. */
  49708. isIndexMax: function () {
  49709. return this.getCurrentIndex() >= this._data.count() - 1;
  49710. },
  49711. /**
  49712. * @param {boolean} state true: play, false: stop
  49713. */
  49714. setPlayState: function (state) {
  49715. this.option.autoPlay = !!state;
  49716. },
  49717. /**
  49718. * @return {boolean} true: play, false: stop
  49719. */
  49720. getPlayState: function () {
  49721. return !!this.option.autoPlay;
  49722. },
  49723. /**
  49724. * @private
  49725. */
  49726. _initData: function () {
  49727. var thisOption = this.option;
  49728. var dataArr = thisOption.data || [];
  49729. var axisType = thisOption.axisType;
  49730. var names = this._names = [];
  49731. if (axisType === 'category') {
  49732. var idxArr = [];
  49733. each$1(dataArr, function (item, index) {
  49734. var value = getDataItemValue(item);
  49735. var newItem;
  49736. if (isObject$1(item)) {
  49737. newItem = clone(item);
  49738. newItem.value = index;
  49739. } else {
  49740. newItem = index;
  49741. }
  49742. idxArr.push(newItem);
  49743. if (!isString(value) && (value == null || isNaN(value))) {
  49744. value = '';
  49745. }
  49746. names.push(value + '');
  49747. });
  49748. dataArr = idxArr;
  49749. }
  49750. var dimType = {
  49751. category: 'ordinal',
  49752. time: 'time'
  49753. }[axisType] || 'number';
  49754. var data = this._data = new List([{
  49755. name: 'value',
  49756. type: dimType
  49757. }], this);
  49758. data.initData(dataArr, names);
  49759. },
  49760. getData: function () {
  49761. return this._data;
  49762. },
  49763. /**
  49764. * @public
  49765. * @return {Array.<string>} categoreis
  49766. */
  49767. getCategories: function () {
  49768. if (this.get('axisType') === 'category') {
  49769. return this._names.slice();
  49770. }
  49771. }
  49772. });
  49773. /*
  49774. * Licensed to the Apache Software Foundation (ASF) under one
  49775. * or more contributor license agreements. See the NOTICE file
  49776. * distributed with this work for additional information
  49777. * regarding copyright ownership. The ASF licenses this file
  49778. * to you under the Apache License, Version 2.0 (the
  49779. * "License"); you may not use this file except in compliance
  49780. * with the License. You may obtain a copy of the License at
  49781. *
  49782. * http://www.apache.org/licenses/LICENSE-2.0
  49783. *
  49784. * Unless required by applicable law or agreed to in writing,
  49785. * software distributed under the License is distributed on an
  49786. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49787. * KIND, either express or implied. See the License for the
  49788. * specific language governing permissions and limitations
  49789. * under the License.
  49790. */
  49791. var SliderTimelineModel = TimelineModel.extend({
  49792. type: 'timeline.slider',
  49793. /**
  49794. * @protected
  49795. */
  49796. defaultOption: {
  49797. backgroundColor: 'rgba(0,0,0,0)',
  49798. // 时间轴背景颜色
  49799. borderColor: '#ccc',
  49800. // 时间轴边框颜色
  49801. borderWidth: 0,
  49802. // 时间轴边框线宽,单位px,默认为0(无边框)
  49803. orient: 'horizontal',
  49804. // 'vertical'
  49805. inverse: false,
  49806. tooltip: {
  49807. // boolean or Object
  49808. trigger: 'item' // data item may also have tootip attr.
  49809. },
  49810. symbol: 'emptyCircle',
  49811. symbolSize: 10,
  49812. lineStyle: {
  49813. show: true,
  49814. width: 2,
  49815. color: '#304654'
  49816. },
  49817. label: {
  49818. // 文本标签
  49819. position: 'auto',
  49820. // auto left right top bottom
  49821. // When using number, label position is not
  49822. // restricted by viewRect.
  49823. // positive: right/bottom, negative: left/top
  49824. show: true,
  49825. interval: 'auto',
  49826. rotate: 0,
  49827. // formatter: null,
  49828. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  49829. color: '#304654'
  49830. },
  49831. itemStyle: {
  49832. color: '#304654',
  49833. borderWidth: 1
  49834. },
  49835. checkpointStyle: {
  49836. symbol: 'circle',
  49837. symbolSize: 13,
  49838. color: '#c23531',
  49839. borderWidth: 5,
  49840. borderColor: 'rgba(194,53,49, 0.5)',
  49841. animation: true,
  49842. animationDuration: 300,
  49843. animationEasing: 'quinticInOut'
  49844. },
  49845. controlStyle: {
  49846. show: true,
  49847. showPlayBtn: true,
  49848. showPrevBtn: true,
  49849. showNextBtn: true,
  49850. itemSize: 22,
  49851. itemGap: 12,
  49852. position: 'left',
  49853. // 'left' 'right' 'top' 'bottom'
  49854. playIcon: 'path://M31.6,53C17.5,53,6,41.5,6,27.4S17.5,1.8,31.6,1.8C45.7,1.8,57.2,13.3,57.2,27.4S45.7,53,31.6,53z M31.6,3.3 C18.4,3.3,7.5,14.1,7.5,27.4c0,13.3,10.8,24.1,24.1,24.1C44.9,51.5,55.7,40.7,55.7,27.4C55.7,14.1,44.9,3.3,31.6,3.3z M24.9,21.3 c0-2.2,1.6-3.1,3.5-2l10.5,6.1c1.899,1.1,1.899,2.9,0,4l-10.5,6.1c-1.9,1.1-3.5,0.2-3.5-2V21.3z',
  49855. // jshint ignore:line
  49856. stopIcon: 'path://M30.9,53.2C16.8,53.2,5.3,41.7,5.3,27.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,27.6S45,53.2,30.9,53.2z M30.9,3.5C17.6,3.5,6.8,14.4,6.8,27.6c0,13.3,10.8,24.1,24.101,24.1C44.2,51.7,55,40.9,55,27.6C54.9,14.4,44.1,3.5,30.9,3.5z M36.9,35.8c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H36c0.5,0,0.9,0.4,0.9,1V35.8z M27.8,35.8 c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H27c0.5,0,0.9,0.4,0.9,1L27.8,35.8L27.8,35.8z',
  49857. // jshint ignore:line
  49858. nextIcon: 'path://M18.6,50.8l22.5-22.5c0.2-0.2,0.3-0.4,0.3-0.7c0-0.3-0.1-0.5-0.3-0.7L18.7,4.4c-0.1-0.1-0.2-0.3-0.2-0.5 c0-0.4,0.3-0.8,0.8-0.8c0.2,0,0.5,0.1,0.6,0.3l23.5,23.5l0,0c0.2,0.2,0.3,0.4,0.3,0.7c0,0.3-0.1,0.5-0.3,0.7l-0.1,0.1L19.7,52 c-0.1,0.1-0.3,0.2-0.5,0.2c-0.4,0-0.8-0.3-0.8-0.8C18.4,51.2,18.5,51,18.6,50.8z',
  49859. // jshint ignore:line
  49860. prevIcon: 'path://M43,52.8L20.4,30.3c-0.2-0.2-0.3-0.4-0.3-0.7c0-0.3,0.1-0.5,0.3-0.7L42.9,6.4c0.1-0.1,0.2-0.3,0.2-0.5 c0-0.4-0.3-0.8-0.8-0.8c-0.2,0-0.5,0.1-0.6,0.3L18.3,28.8l0,0c-0.2,0.2-0.3,0.4-0.3,0.7c0,0.3,0.1,0.5,0.3,0.7l0.1,0.1L41.9,54 c0.1,0.1,0.3,0.2,0.5,0.2c0.4,0,0.8-0.3,0.8-0.8C43.2,53.2,43.1,53,43,52.8z',
  49861. // jshint ignore:line
  49862. color: '#304654',
  49863. borderColor: '#304654',
  49864. borderWidth: 1
  49865. },
  49866. emphasis: {
  49867. label: {
  49868. show: true,
  49869. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  49870. color: '#c23531'
  49871. },
  49872. itemStyle: {
  49873. color: '#c23531'
  49874. },
  49875. controlStyle: {
  49876. color: '#c23531',
  49877. borderColor: '#c23531',
  49878. borderWidth: 2
  49879. }
  49880. },
  49881. data: []
  49882. }
  49883. });
  49884. mixin(SliderTimelineModel, dataFormatMixin);
  49885. /*
  49886. * Licensed to the Apache Software Foundation (ASF) under one
  49887. * or more contributor license agreements. See the NOTICE file
  49888. * distributed with this work for additional information
  49889. * regarding copyright ownership. The ASF licenses this file
  49890. * to you under the Apache License, Version 2.0 (the
  49891. * "License"); you may not use this file except in compliance
  49892. * with the License. You may obtain a copy of the License at
  49893. *
  49894. * http://www.apache.org/licenses/LICENSE-2.0
  49895. *
  49896. * Unless required by applicable law or agreed to in writing,
  49897. * software distributed under the License is distributed on an
  49898. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49899. * KIND, either express or implied. See the License for the
  49900. * specific language governing permissions and limitations
  49901. * under the License.
  49902. */
  49903. var TimelineView = Component$1.extend({
  49904. type: 'timeline'
  49905. });
  49906. /*
  49907. * Licensed to the Apache Software Foundation (ASF) under one
  49908. * or more contributor license agreements. See the NOTICE file
  49909. * distributed with this work for additional information
  49910. * regarding copyright ownership. The ASF licenses this file
  49911. * to you under the Apache License, Version 2.0 (the
  49912. * "License"); you may not use this file except in compliance
  49913. * with the License. You may obtain a copy of the License at
  49914. *
  49915. * http://www.apache.org/licenses/LICENSE-2.0
  49916. *
  49917. * Unless required by applicable law or agreed to in writing,
  49918. * software distributed under the License is distributed on an
  49919. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49920. * KIND, either express or implied. See the License for the
  49921. * specific language governing permissions and limitations
  49922. * under the License.
  49923. */
  49924. /**
  49925. * Extend axis 2d
  49926. * @constructor module:echarts/coord/cartesian/Axis2D
  49927. * @extends {module:echarts/coord/cartesian/Axis}
  49928. * @param {string} dim
  49929. * @param {*} scale
  49930. * @param {Array.<number>} coordExtent
  49931. * @param {string} axisType
  49932. * @param {string} position
  49933. */
  49934. var TimelineAxis = function (dim, scale, coordExtent, axisType) {
  49935. Axis.call(this, dim, scale, coordExtent);
  49936. /**
  49937. * Axis type
  49938. * - 'category'
  49939. * - 'value'
  49940. * - 'time'
  49941. * - 'log'
  49942. * @type {string}
  49943. */
  49944. this.type = axisType || 'value';
  49945. /**
  49946. * Axis model
  49947. * @param {module:echarts/component/TimelineModel}
  49948. */
  49949. this.model = null;
  49950. };
  49951. TimelineAxis.prototype = {
  49952. constructor: TimelineAxis,
  49953. /**
  49954. * @override
  49955. */
  49956. getLabelModel: function () {
  49957. return this.model.getModel('label');
  49958. },
  49959. /**
  49960. * @override
  49961. */
  49962. isHorizontal: function () {
  49963. return this.model.get('orient') === 'horizontal';
  49964. }
  49965. };
  49966. inherits(TimelineAxis, Axis);
  49967. /*
  49968. * Licensed to the Apache Software Foundation (ASF) under one
  49969. * or more contributor license agreements. See the NOTICE file
  49970. * distributed with this work for additional information
  49971. * regarding copyright ownership. The ASF licenses this file
  49972. * to you under the Apache License, Version 2.0 (the
  49973. * "License"); you may not use this file except in compliance
  49974. * with the License. You may obtain a copy of the License at
  49975. *
  49976. * http://www.apache.org/licenses/LICENSE-2.0
  49977. *
  49978. * Unless required by applicable law or agreed to in writing,
  49979. * software distributed under the License is distributed on an
  49980. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49981. * KIND, either express or implied. See the License for the
  49982. * specific language governing permissions and limitations
  49983. * under the License.
  49984. */
  49985. var bind$3 = bind;
  49986. var each$13 = each$1;
  49987. var PI$4 = Math.PI;
  49988. TimelineView.extend({
  49989. type: 'timeline.slider',
  49990. init: function (ecModel, api) {
  49991. this.api = api;
  49992. /**
  49993. * @private
  49994. * @type {module:echarts/component/timeline/TimelineAxis}
  49995. */
  49996. this._axis;
  49997. /**
  49998. * @private
  49999. * @type {module:zrender/core/BoundingRect}
  50000. */
  50001. this._viewRect;
  50002. /**
  50003. * @type {number}
  50004. */
  50005. this._timer;
  50006. /**
  50007. * @type {module:zrender/Element}
  50008. */
  50009. this._currentPointer;
  50010. /**
  50011. * @type {module:zrender/container/Group}
  50012. */
  50013. this._mainGroup;
  50014. /**
  50015. * @type {module:zrender/container/Group}
  50016. */
  50017. this._labelGroup;
  50018. },
  50019. /**
  50020. * @override
  50021. */
  50022. render: function (timelineModel, ecModel, api, payload) {
  50023. this.model = timelineModel;
  50024. this.api = api;
  50025. this.ecModel = ecModel;
  50026. this.group.removeAll();
  50027. if (timelineModel.get('show', true)) {
  50028. var layoutInfo = this._layout(timelineModel, api);
  50029. var mainGroup = this._createGroup('mainGroup');
  50030. var labelGroup = this._createGroup('labelGroup');
  50031. /**
  50032. * @private
  50033. * @type {module:echarts/component/timeline/TimelineAxis}
  50034. */
  50035. var axis = this._axis = this._createAxis(layoutInfo, timelineModel);
  50036. timelineModel.formatTooltip = function (dataIndex) {
  50037. return encodeHTML(axis.scale.getLabel(dataIndex));
  50038. };
  50039. each$13(['AxisLine', 'AxisTick', 'Control', 'CurrentPointer'], function (name) {
  50040. this['_render' + name](layoutInfo, mainGroup, axis, timelineModel);
  50041. }, this);
  50042. this._renderAxisLabel(layoutInfo, labelGroup, axis, timelineModel);
  50043. this._position(layoutInfo, timelineModel);
  50044. }
  50045. this._doPlayStop();
  50046. },
  50047. /**
  50048. * @override
  50049. */
  50050. remove: function () {
  50051. this._clearTimer();
  50052. this.group.removeAll();
  50053. },
  50054. /**
  50055. * @override
  50056. */
  50057. dispose: function () {
  50058. this._clearTimer();
  50059. },
  50060. _layout: function (timelineModel, api) {
  50061. var labelPosOpt = timelineModel.get('label.position');
  50062. var orient = timelineModel.get('orient');
  50063. var viewRect = getViewRect$3(timelineModel, api); // Auto label offset.
  50064. if (labelPosOpt == null || labelPosOpt === 'auto') {
  50065. labelPosOpt = orient === 'horizontal' ? viewRect.y + viewRect.height / 2 < api.getHeight() / 2 ? '-' : '+' : viewRect.x + viewRect.width / 2 < api.getWidth() / 2 ? '+' : '-';
  50066. } else if (isNaN(labelPosOpt)) {
  50067. labelPosOpt = {
  50068. horizontal: {
  50069. top: '-',
  50070. bottom: '+'
  50071. },
  50072. vertical: {
  50073. left: '-',
  50074. right: '+'
  50075. }
  50076. }[orient][labelPosOpt];
  50077. }
  50078. var labelAlignMap = {
  50079. horizontal: 'center',
  50080. vertical: labelPosOpt >= 0 || labelPosOpt === '+' ? 'left' : 'right'
  50081. };
  50082. var labelBaselineMap = {
  50083. horizontal: labelPosOpt >= 0 || labelPosOpt === '+' ? 'top' : 'bottom',
  50084. vertical: 'middle'
  50085. };
  50086. var rotationMap = {
  50087. horizontal: 0,
  50088. vertical: PI$4 / 2
  50089. }; // Position
  50090. var mainLength = orient === 'vertical' ? viewRect.height : viewRect.width;
  50091. var controlModel = timelineModel.getModel('controlStyle');
  50092. var showControl = controlModel.get('show', true);
  50093. var controlSize = showControl ? controlModel.get('itemSize') : 0;
  50094. var controlGap = showControl ? controlModel.get('itemGap') : 0;
  50095. var sizePlusGap = controlSize + controlGap; // Special label rotate.
  50096. var labelRotation = timelineModel.get('label.rotate') || 0;
  50097. labelRotation = labelRotation * PI$4 / 180; // To radian.
  50098. var playPosition;
  50099. var prevBtnPosition;
  50100. var nextBtnPosition;
  50101. var axisExtent;
  50102. var controlPosition = controlModel.get('position', true);
  50103. var showPlayBtn = showControl && controlModel.get('showPlayBtn', true);
  50104. var showPrevBtn = showControl && controlModel.get('showPrevBtn', true);
  50105. var showNextBtn = showControl && controlModel.get('showNextBtn', true);
  50106. var xLeft = 0;
  50107. var xRight = mainLength; // position[0] means left, position[1] means middle.
  50108. if (controlPosition === 'left' || controlPosition === 'bottom') {
  50109. showPlayBtn && (playPosition = [0, 0], xLeft += sizePlusGap);
  50110. showPrevBtn && (prevBtnPosition = [xLeft, 0], xLeft += sizePlusGap);
  50111. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  50112. } else {
  50113. // 'top' 'right'
  50114. showPlayBtn && (playPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  50115. showPrevBtn && (prevBtnPosition = [0, 0], xLeft += sizePlusGap);
  50116. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  50117. }
  50118. axisExtent = [xLeft, xRight];
  50119. if (timelineModel.get('inverse')) {
  50120. axisExtent.reverse();
  50121. }
  50122. return {
  50123. viewRect: viewRect,
  50124. mainLength: mainLength,
  50125. orient: orient,
  50126. rotation: rotationMap[orient],
  50127. labelRotation: labelRotation,
  50128. labelPosOpt: labelPosOpt,
  50129. labelAlign: timelineModel.get('label.align') || labelAlignMap[orient],
  50130. labelBaseline: timelineModel.get('label.verticalAlign') || timelineModel.get('label.baseline') || labelBaselineMap[orient],
  50131. // Based on mainGroup.
  50132. playPosition: playPosition,
  50133. prevBtnPosition: prevBtnPosition,
  50134. nextBtnPosition: nextBtnPosition,
  50135. axisExtent: axisExtent,
  50136. controlSize: controlSize,
  50137. controlGap: controlGap
  50138. };
  50139. },
  50140. _position: function (layoutInfo, timelineModel) {
  50141. // Position is be called finally, because bounding rect is needed for
  50142. // adapt content to fill viewRect (auto adapt offset).
  50143. // Timeline may be not all in the viewRect when 'offset' is specified
  50144. // as a number, because it is more appropriate that label aligns at
  50145. // 'offset' but not the other edge defined by viewRect.
  50146. var mainGroup = this._mainGroup;
  50147. var labelGroup = this._labelGroup;
  50148. var viewRect = layoutInfo.viewRect;
  50149. if (layoutInfo.orient === 'vertical') {
  50150. // transform to horizontal, inverse rotate by left-top point.
  50151. var m = create$1();
  50152. var rotateOriginX = viewRect.x;
  50153. var rotateOriginY = viewRect.y + viewRect.height;
  50154. translate(m, m, [-rotateOriginX, -rotateOriginY]);
  50155. rotate(m, m, -PI$4 / 2);
  50156. translate(m, m, [rotateOriginX, rotateOriginY]);
  50157. viewRect = viewRect.clone();
  50158. viewRect.applyTransform(m);
  50159. }
  50160. var viewBound = getBound(viewRect);
  50161. var mainBound = getBound(mainGroup.getBoundingRect());
  50162. var labelBound = getBound(labelGroup.getBoundingRect());
  50163. var mainPosition = mainGroup.position;
  50164. var labelsPosition = labelGroup.position;
  50165. labelsPosition[0] = mainPosition[0] = viewBound[0][0];
  50166. var labelPosOpt = layoutInfo.labelPosOpt;
  50167. if (isNaN(labelPosOpt)) {
  50168. // '+' or '-'
  50169. var mainBoundIdx = labelPosOpt === '+' ? 0 : 1;
  50170. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  50171. toBound(labelsPosition, labelBound, viewBound, 1, 1 - mainBoundIdx);
  50172. } else {
  50173. var mainBoundIdx = labelPosOpt >= 0 ? 0 : 1;
  50174. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  50175. labelsPosition[1] = mainPosition[1] + labelPosOpt;
  50176. }
  50177. mainGroup.attr('position', mainPosition);
  50178. labelGroup.attr('position', labelsPosition);
  50179. mainGroup.rotation = labelGroup.rotation = layoutInfo.rotation;
  50180. setOrigin(mainGroup);
  50181. setOrigin(labelGroup);
  50182. function setOrigin(targetGroup) {
  50183. var pos = targetGroup.position;
  50184. targetGroup.origin = [viewBound[0][0] - pos[0], viewBound[1][0] - pos[1]];
  50185. }
  50186. function getBound(rect) {
  50187. // [[xmin, xmax], [ymin, ymax]]
  50188. return [[rect.x, rect.x + rect.width], [rect.y, rect.y + rect.height]];
  50189. }
  50190. function toBound(fromPos, from, to, dimIdx, boundIdx) {
  50191. fromPos[dimIdx] += to[dimIdx][boundIdx] - from[dimIdx][boundIdx];
  50192. }
  50193. },
  50194. _createAxis: function (layoutInfo, timelineModel) {
  50195. var data = timelineModel.getData();
  50196. var axisType = timelineModel.get('axisType');
  50197. var scale = createScaleByModel(timelineModel, axisType); // Customize scale. The `tickValue` is `dataIndex`.
  50198. scale.getTicks = function () {
  50199. return data.mapArray(['value'], function (value) {
  50200. return value;
  50201. });
  50202. };
  50203. var dataExtent = data.getDataExtent('value');
  50204. scale.setExtent(dataExtent[0], dataExtent[1]);
  50205. scale.niceTicks();
  50206. var axis = new TimelineAxis('value', scale, layoutInfo.axisExtent, axisType);
  50207. axis.model = timelineModel;
  50208. return axis;
  50209. },
  50210. _createGroup: function (name) {
  50211. var newGroup = this['_' + name] = new Group();
  50212. this.group.add(newGroup);
  50213. return newGroup;
  50214. },
  50215. _renderAxisLine: function (layoutInfo, group, axis, timelineModel) {
  50216. var axisExtent = axis.getExtent();
  50217. if (!timelineModel.get('lineStyle.show')) {
  50218. return;
  50219. }
  50220. group.add(new Line({
  50221. shape: {
  50222. x1: axisExtent[0],
  50223. y1: 0,
  50224. x2: axisExtent[1],
  50225. y2: 0
  50226. },
  50227. style: extend({
  50228. lineCap: 'round'
  50229. }, timelineModel.getModel('lineStyle').getLineStyle()),
  50230. silent: true,
  50231. z2: 1
  50232. }));
  50233. },
  50234. /**
  50235. * @private
  50236. */
  50237. _renderAxisTick: function (layoutInfo, group, axis, timelineModel) {
  50238. var data = timelineModel.getData(); // Show all ticks, despite ignoring strategy.
  50239. var ticks = axis.scale.getTicks(); // The value is dataIndex, see the costomized scale.
  50240. each$13(ticks, function (value) {
  50241. var tickCoord = axis.dataToCoord(value);
  50242. var itemModel = data.getItemModel(value);
  50243. var itemStyleModel = itemModel.getModel('itemStyle');
  50244. var hoverStyleModel = itemModel.getModel('emphasis.itemStyle');
  50245. var symbolOpt = {
  50246. position: [tickCoord, 0],
  50247. onclick: bind$3(this._changeTimeline, this, value)
  50248. };
  50249. var el = giveSymbol(itemModel, itemStyleModel, group, symbolOpt);
  50250. setHoverStyle(el, hoverStyleModel.getItemStyle());
  50251. if (itemModel.get('tooltip')) {
  50252. el.dataIndex = value;
  50253. el.dataModel = timelineModel;
  50254. } else {
  50255. el.dataIndex = el.dataModel = null;
  50256. }
  50257. }, this);
  50258. },
  50259. /**
  50260. * @private
  50261. */
  50262. _renderAxisLabel: function (layoutInfo, group, axis, timelineModel) {
  50263. var labelModel = axis.getLabelModel();
  50264. if (!labelModel.get('show')) {
  50265. return;
  50266. }
  50267. var data = timelineModel.getData();
  50268. var labels = axis.getViewLabels();
  50269. each$13(labels, function (labelItem) {
  50270. // The tickValue is dataIndex, see the costomized scale.
  50271. var dataIndex = labelItem.tickValue;
  50272. var itemModel = data.getItemModel(dataIndex);
  50273. var normalLabelModel = itemModel.getModel('label');
  50274. var hoverLabelModel = itemModel.getModel('emphasis.label');
  50275. var tickCoord = axis.dataToCoord(labelItem.tickValue);
  50276. var textEl = new Text({
  50277. position: [tickCoord, 0],
  50278. rotation: layoutInfo.labelRotation - layoutInfo.rotation,
  50279. onclick: bind$3(this._changeTimeline, this, dataIndex),
  50280. silent: false
  50281. });
  50282. setTextStyle(textEl.style, normalLabelModel, {
  50283. text: labelItem.formattedLabel,
  50284. textAlign: layoutInfo.labelAlign,
  50285. textVerticalAlign: layoutInfo.labelBaseline
  50286. });
  50287. group.add(textEl);
  50288. setHoverStyle(textEl, setTextStyle({}, hoverLabelModel));
  50289. }, this);
  50290. },
  50291. /**
  50292. * @private
  50293. */
  50294. _renderControl: function (layoutInfo, group, axis, timelineModel) {
  50295. var controlSize = layoutInfo.controlSize;
  50296. var rotation = layoutInfo.rotation;
  50297. var itemStyle = timelineModel.getModel('controlStyle').getItemStyle();
  50298. var hoverStyle = timelineModel.getModel('emphasis.controlStyle').getItemStyle();
  50299. var rect = [0, -controlSize / 2, controlSize, controlSize];
  50300. var playState = timelineModel.getPlayState();
  50301. var inverse = timelineModel.get('inverse', true);
  50302. makeBtn(layoutInfo.nextBtnPosition, 'controlStyle.nextIcon', bind$3(this._changeTimeline, this, inverse ? '-' : '+'));
  50303. makeBtn(layoutInfo.prevBtnPosition, 'controlStyle.prevIcon', bind$3(this._changeTimeline, this, inverse ? '+' : '-'));
  50304. makeBtn(layoutInfo.playPosition, 'controlStyle.' + (playState ? 'stopIcon' : 'playIcon'), bind$3(this._handlePlayClick, this, !playState), true);
  50305. function makeBtn(position, iconPath, onclick, willRotate) {
  50306. if (!position) {
  50307. return;
  50308. }
  50309. var opt = {
  50310. position: position,
  50311. origin: [controlSize / 2, 0],
  50312. rotation: willRotate ? -rotation : 0,
  50313. rectHover: true,
  50314. style: itemStyle,
  50315. onclick: onclick
  50316. };
  50317. var btn = makeIcon(timelineModel, iconPath, rect, opt);
  50318. group.add(btn);
  50319. setHoverStyle(btn, hoverStyle);
  50320. }
  50321. },
  50322. _renderCurrentPointer: function (layoutInfo, group, axis, timelineModel) {
  50323. var data = timelineModel.getData();
  50324. var currentIndex = timelineModel.getCurrentIndex();
  50325. var pointerModel = data.getItemModel(currentIndex).getModel('checkpointStyle');
  50326. var me = this;
  50327. var callback = {
  50328. onCreate: function (pointer) {
  50329. pointer.draggable = true;
  50330. pointer.drift = bind$3(me._handlePointerDrag, me);
  50331. pointer.ondragend = bind$3(me._handlePointerDragend, me);
  50332. pointerMoveTo(pointer, currentIndex, axis, timelineModel, true);
  50333. },
  50334. onUpdate: function (pointer) {
  50335. pointerMoveTo(pointer, currentIndex, axis, timelineModel);
  50336. }
  50337. }; // Reuse when exists, for animation and drag.
  50338. this._currentPointer = giveSymbol(pointerModel, pointerModel, this._mainGroup, {}, this._currentPointer, callback);
  50339. },
  50340. _handlePlayClick: function (nextState) {
  50341. this._clearTimer();
  50342. this.api.dispatchAction({
  50343. type: 'timelinePlayChange',
  50344. playState: nextState,
  50345. from: this.uid
  50346. });
  50347. },
  50348. _handlePointerDrag: function (dx, dy, e) {
  50349. this._clearTimer();
  50350. this._pointerChangeTimeline([e.offsetX, e.offsetY]);
  50351. },
  50352. _handlePointerDragend: function (e) {
  50353. this._pointerChangeTimeline([e.offsetX, e.offsetY], true);
  50354. },
  50355. _pointerChangeTimeline: function (mousePos, trigger) {
  50356. var toCoord = this._toAxisCoord(mousePos)[0];
  50357. var axis = this._axis;
  50358. var axisExtent = asc(axis.getExtent().slice());
  50359. toCoord > axisExtent[1] && (toCoord = axisExtent[1]);
  50360. toCoord < axisExtent[0] && (toCoord = axisExtent[0]);
  50361. this._currentPointer.position[0] = toCoord;
  50362. this._currentPointer.dirty();
  50363. var targetDataIndex = this._findNearestTick(toCoord);
  50364. var timelineModel = this.model;
  50365. if (trigger || targetDataIndex !== timelineModel.getCurrentIndex() && timelineModel.get('realtime')) {
  50366. this._changeTimeline(targetDataIndex);
  50367. }
  50368. },
  50369. _doPlayStop: function () {
  50370. this._clearTimer();
  50371. if (this.model.getPlayState()) {
  50372. this._timer = setTimeout(bind$3(handleFrame, this), this.model.get('playInterval'));
  50373. }
  50374. function handleFrame() {
  50375. // Do not cache
  50376. var timelineModel = this.model;
  50377. this._changeTimeline(timelineModel.getCurrentIndex() + (timelineModel.get('rewind', true) ? -1 : 1));
  50378. }
  50379. },
  50380. _toAxisCoord: function (vertex) {
  50381. var trans = this._mainGroup.getLocalTransform();
  50382. return applyTransform$1(vertex, trans, true);
  50383. },
  50384. _findNearestTick: function (axisCoord) {
  50385. var data = this.model.getData();
  50386. var dist = Infinity;
  50387. var targetDataIndex;
  50388. var axis = this._axis;
  50389. data.each(['value'], function (value, dataIndex) {
  50390. var coord = axis.dataToCoord(value);
  50391. var d = Math.abs(coord - axisCoord);
  50392. if (d < dist) {
  50393. dist = d;
  50394. targetDataIndex = dataIndex;
  50395. }
  50396. });
  50397. return targetDataIndex;
  50398. },
  50399. _clearTimer: function () {
  50400. if (this._timer) {
  50401. clearTimeout(this._timer);
  50402. this._timer = null;
  50403. }
  50404. },
  50405. _changeTimeline: function (nextIndex) {
  50406. var currentIndex = this.model.getCurrentIndex();
  50407. if (nextIndex === '+') {
  50408. nextIndex = currentIndex + 1;
  50409. } else if (nextIndex === '-') {
  50410. nextIndex = currentIndex - 1;
  50411. }
  50412. this.api.dispatchAction({
  50413. type: 'timelineChange',
  50414. currentIndex: nextIndex,
  50415. from: this.uid
  50416. });
  50417. }
  50418. });
  50419. function getViewRect$3(model, api) {
  50420. return getLayoutRect(model.getBoxLayoutParams(), {
  50421. width: api.getWidth(),
  50422. height: api.getHeight()
  50423. }, model.get('padding'));
  50424. }
  50425. function makeIcon(timelineModel, objPath, rect, opts) {
  50426. var icon = makePath(timelineModel.get(objPath).replace(/^path:\/\//, ''), clone(opts || {}), new BoundingRect(rect[0], rect[1], rect[2], rect[3]), 'center');
  50427. return icon;
  50428. }
  50429. /**
  50430. * Create symbol or update symbol
  50431. * opt: basic position and event handlers
  50432. */
  50433. function giveSymbol(hostModel, itemStyleModel, group, opt, symbol, callback) {
  50434. var color = itemStyleModel.get('color');
  50435. if (!symbol) {
  50436. var symbolType = hostModel.get('symbol');
  50437. symbol = createSymbol(symbolType, -1, -1, 2, 2, color);
  50438. symbol.setStyle('strokeNoScale', true);
  50439. group.add(symbol);
  50440. callback && callback.onCreate(symbol);
  50441. } else {
  50442. symbol.setColor(color);
  50443. group.add(symbol); // Group may be new, also need to add.
  50444. callback && callback.onUpdate(symbol);
  50445. } // Style
  50446. var itemStyle = itemStyleModel.getItemStyle(['color', 'symbol', 'symbolSize']);
  50447. symbol.setStyle(itemStyle); // Transform and events.
  50448. opt = merge({
  50449. rectHover: true,
  50450. z2: 100
  50451. }, opt, true);
  50452. var symbolSize = hostModel.get('symbolSize');
  50453. symbolSize = symbolSize instanceof Array ? symbolSize.slice() : [+symbolSize, +symbolSize];
  50454. symbolSize[0] /= 2;
  50455. symbolSize[1] /= 2;
  50456. opt.scale = symbolSize;
  50457. var symbolOffset = hostModel.get('symbolOffset');
  50458. if (symbolOffset) {
  50459. var pos = opt.position = opt.position || [0, 0];
  50460. pos[0] += parsePercent$1(symbolOffset[0], symbolSize[0]);
  50461. pos[1] += parsePercent$1(symbolOffset[1], symbolSize[1]);
  50462. }
  50463. var symbolRotate = hostModel.get('symbolRotate');
  50464. opt.rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  50465. symbol.attr(opt); // FIXME
  50466. // (1) When symbol.style.strokeNoScale is true and updateTransform is not performed,
  50467. // getBoundingRect will return wrong result.
  50468. // (This is supposed to be resolved in zrender, but it is a little difficult to
  50469. // leverage performance and auto updateTransform)
  50470. // (2) All of ancesters of symbol do not scale, so we can just updateTransform symbol.
  50471. symbol.updateTransform();
  50472. return symbol;
  50473. }
  50474. function pointerMoveTo(pointer, dataIndex, axis, timelineModel, noAnimation) {
  50475. if (pointer.dragging) {
  50476. return;
  50477. }
  50478. var pointerModel = timelineModel.getModel('checkpointStyle');
  50479. var toCoord = axis.dataToCoord(timelineModel.getData().get(['value'], dataIndex));
  50480. if (noAnimation || !pointerModel.get('animation', true)) {
  50481. pointer.attr({
  50482. position: [toCoord, 0]
  50483. });
  50484. } else {
  50485. pointer.stopAnimation(true);
  50486. pointer.animateTo({
  50487. position: [toCoord, 0]
  50488. }, pointerModel.get('animationDuration', true), pointerModel.get('animationEasing', true));
  50489. }
  50490. }
  50491. /*
  50492. * Licensed to the Apache Software Foundation (ASF) under one
  50493. * or more contributor license agreements. See the NOTICE file
  50494. * distributed with this work for additional information
  50495. * regarding copyright ownership. The ASF licenses this file
  50496. * to you under the Apache License, Version 2.0 (the
  50497. * "License"); you may not use this file except in compliance
  50498. * with the License. You may obtain a copy of the License at
  50499. *
  50500. * http://www.apache.org/licenses/LICENSE-2.0
  50501. *
  50502. * Unless required by applicable law or agreed to in writing,
  50503. * software distributed under the License is distributed on an
  50504. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50505. * KIND, either express or implied. See the License for the
  50506. * specific language governing permissions and limitations
  50507. * under the License.
  50508. */
  50509. /**
  50510. * DataZoom component entry
  50511. */
  50512. registerPreprocessor(preprocessor);
  50513. /*
  50514. * Licensed to the Apache Software Foundation (ASF) under one
  50515. * or more contributor license agreements. See the NOTICE file
  50516. * distributed with this work for additional information
  50517. * regarding copyright ownership. The ASF licenses this file
  50518. * to you under the Apache License, Version 2.0 (the
  50519. * "License"); you may not use this file except in compliance
  50520. * with the License. You may obtain a copy of the License at
  50521. *
  50522. * http://www.apache.org/licenses/LICENSE-2.0
  50523. *
  50524. * Unless required by applicable law or agreed to in writing,
  50525. * software distributed under the License is distributed on an
  50526. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50527. * KIND, either express or implied. See the License for the
  50528. * specific language governing permissions and limitations
  50529. * under the License.
  50530. */
  50531. ComponentModel.registerSubTypeDefaulter('dataZoom', function () {
  50532. // Default 'slider' when no type specified.
  50533. return 'slider';
  50534. });
  50535. /*
  50536. * Licensed to the Apache Software Foundation (ASF) under one
  50537. * or more contributor license agreements. See the NOTICE file
  50538. * distributed with this work for additional information
  50539. * regarding copyright ownership. The ASF licenses this file
  50540. * to you under the Apache License, Version 2.0 (the
  50541. * "License"); you may not use this file except in compliance
  50542. * with the License. You may obtain a copy of the License at
  50543. *
  50544. * http://www.apache.org/licenses/LICENSE-2.0
  50545. *
  50546. * Unless required by applicable law or agreed to in writing,
  50547. * software distributed under the License is distributed on an
  50548. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50549. * KIND, either express or implied. See the License for the
  50550. * specific language governing permissions and limitations
  50551. * under the License.
  50552. */
  50553. var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle', 'single']; // Supported coords.
  50554. var COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  50555. /**
  50556. * @param {string} coordType
  50557. * @return {boolean}
  50558. */
  50559. function isCoordSupported(coordType) {
  50560. return indexOf(COORDS, coordType) >= 0;
  50561. }
  50562. /**
  50563. * Create "each" method to iterate names.
  50564. *
  50565. * @pubilc
  50566. * @param {Array.<string>} names
  50567. * @param {Array.<string>=} attrs
  50568. * @return {Function}
  50569. */
  50570. function createNameEach(names, attrs) {
  50571. names = names.slice();
  50572. var capitalNames = map(names, capitalFirst);
  50573. attrs = (attrs || []).slice();
  50574. var capitalAttrs = map(attrs, capitalFirst);
  50575. return function (callback, context) {
  50576. each$1(names, function (name, index) {
  50577. var nameObj = {
  50578. name: name,
  50579. capital: capitalNames[index]
  50580. };
  50581. for (var j = 0; j < attrs.length; j++) {
  50582. nameObj[attrs[j]] = name + capitalAttrs[j];
  50583. }
  50584. callback.call(context, nameObj);
  50585. });
  50586. };
  50587. }
  50588. /**
  50589. * Iterate each dimension name.
  50590. *
  50591. * @public
  50592. * @param {Function} callback The parameter is like:
  50593. * {
  50594. * name: 'angle',
  50595. * capital: 'Angle',
  50596. * axis: 'angleAxis',
  50597. * axisIndex: 'angleAixs',
  50598. * index: 'angleIndex'
  50599. * }
  50600. * @param {Object} context
  50601. */
  50602. var eachAxisDim$1 = createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index', 'id']);
  50603. /**
  50604. * If tow dataZoomModels has the same axis controlled, we say that they are 'linked'.
  50605. * dataZoomModels and 'links' make up one or more graphics.
  50606. * This function finds the graphic where the source dataZoomModel is in.
  50607. *
  50608. * @public
  50609. * @param {Function} forEachNode Node iterator.
  50610. * @param {Function} forEachEdgeType edgeType iterator
  50611. * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id.
  50612. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}}
  50613. */
  50614. function createLinkedNodesFinder(forEachNode, forEachEdgeType, edgeIdGetter) {
  50615. return function (sourceNode) {
  50616. var result = {
  50617. nodes: [],
  50618. records: {} // key: edgeType.name, value: Object (key: edge id, value: boolean).
  50619. };
  50620. forEachEdgeType(function (edgeType) {
  50621. result.records[edgeType.name] = {};
  50622. });
  50623. if (!sourceNode) {
  50624. return result;
  50625. }
  50626. absorb(sourceNode, result);
  50627. var existsLink;
  50628. do {
  50629. existsLink = false;
  50630. forEachNode(processSingleNode);
  50631. } while (existsLink);
  50632. function processSingleNode(node) {
  50633. if (!isNodeAbsorded(node, result) && isLinked(node, result)) {
  50634. absorb(node, result);
  50635. existsLink = true;
  50636. }
  50637. }
  50638. return result;
  50639. };
  50640. function isNodeAbsorded(node, result) {
  50641. return indexOf(result.nodes, node) >= 0;
  50642. }
  50643. function isLinked(node, result) {
  50644. var hasLink = false;
  50645. forEachEdgeType(function (edgeType) {
  50646. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  50647. result.records[edgeType.name][edgeId] && (hasLink = true);
  50648. });
  50649. });
  50650. return hasLink;
  50651. }
  50652. function absorb(node, result) {
  50653. result.nodes.push(node);
  50654. forEachEdgeType(function (edgeType) {
  50655. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  50656. result.records[edgeType.name][edgeId] = true;
  50657. });
  50658. });
  50659. }
  50660. }
  50661. /*
  50662. * Licensed to the Apache Software Foundation (ASF) under one
  50663. * or more contributor license agreements. See the NOTICE file
  50664. * distributed with this work for additional information
  50665. * regarding copyright ownership. The ASF licenses this file
  50666. * to you under the Apache License, Version 2.0 (the
  50667. * "License"); you may not use this file except in compliance
  50668. * with the License. You may obtain a copy of the License at
  50669. *
  50670. * http://www.apache.org/licenses/LICENSE-2.0
  50671. *
  50672. * Unless required by applicable law or agreed to in writing,
  50673. * software distributed under the License is distributed on an
  50674. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50675. * KIND, either express or implied. See the License for the
  50676. * specific language governing permissions and limitations
  50677. * under the License.
  50678. */
  50679. /**
  50680. * Calculate slider move result.
  50681. * Usage:
  50682. * (1) If both handle0 and handle1 are needed to be moved, set minSpan the same as
  50683. * maxSpan and the same as `Math.abs(handleEnd[1] - handleEnds[0])`.
  50684. * (2) If handle0 is forbidden to cross handle1, set minSpan as `0`.
  50685. *
  50686. * @param {number} delta Move length.
  50687. * @param {Array.<number>} handleEnds handleEnds[0] can be bigger then handleEnds[1].
  50688. * handleEnds will be modified in this method.
  50689. * @param {Array.<number>} extent handleEnds is restricted by extent.
  50690. * extent[0] should less or equals than extent[1].
  50691. * @param {number|string} handleIndex Can be 'all', means that both move the two handleEnds.
  50692. * @param {number} [minSpan] The range of dataZoom can not be smaller than that.
  50693. * If not set, handle0 and cross handle1. If set as a non-negative
  50694. * number (including `0`), handles will push each other when reaching
  50695. * the minSpan.
  50696. * @param {number} [maxSpan] The range of dataZoom can not be larger than that.
  50697. * @return {Array.<number>} The input handleEnds.
  50698. */
  50699. var sliderMove = function (delta, handleEnds, extent, handleIndex, minSpan, maxSpan) {
  50700. delta = delta || 0;
  50701. var extentSpan = extent[1] - extent[0]; // Notice maxSpan and minSpan can be null/undefined.
  50702. if (minSpan != null) {
  50703. minSpan = restrict(minSpan, [0, extentSpan]);
  50704. }
  50705. if (maxSpan != null) {
  50706. maxSpan = Math.max(maxSpan, minSpan != null ? minSpan : 0);
  50707. }
  50708. if (handleIndex === 'all') {
  50709. var handleSpan = Math.abs(handleEnds[1] - handleEnds[0]);
  50710. handleSpan = restrict(handleSpan, [0, extentSpan]);
  50711. minSpan = maxSpan = restrict(handleSpan, [minSpan, maxSpan]);
  50712. handleIndex = 0;
  50713. }
  50714. handleEnds[0] = restrict(handleEnds[0], extent);
  50715. handleEnds[1] = restrict(handleEnds[1], extent);
  50716. var originalDistSign = getSpanSign(handleEnds, handleIndex);
  50717. handleEnds[handleIndex] += delta; // Restrict in extent.
  50718. var extentMinSpan = minSpan || 0;
  50719. var realExtent = extent.slice();
  50720. originalDistSign.sign < 0 ? realExtent[0] += extentMinSpan : realExtent[1] -= extentMinSpan;
  50721. handleEnds[handleIndex] = restrict(handleEnds[handleIndex], realExtent); // Expand span.
  50722. var currDistSign = getSpanSign(handleEnds, handleIndex);
  50723. if (minSpan != null && (currDistSign.sign !== originalDistSign.sign || currDistSign.span < minSpan)) {
  50724. // If minSpan exists, 'cross' is forbidden.
  50725. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + originalDistSign.sign * minSpan;
  50726. } // Shrink span.
  50727. var currDistSign = getSpanSign(handleEnds, handleIndex);
  50728. if (maxSpan != null && currDistSign.span > maxSpan) {
  50729. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + currDistSign.sign * maxSpan;
  50730. }
  50731. return handleEnds;
  50732. };
  50733. function getSpanSign(handleEnds, handleIndex) {
  50734. var dist = handleEnds[handleIndex] - handleEnds[1 - handleIndex]; // If `handleEnds[0] === handleEnds[1]`, always believe that handleEnd[0]
  50735. // is at left of handleEnds[1] for non-cross case.
  50736. return {
  50737. span: Math.abs(dist),
  50738. sign: dist > 0 ? -1 : dist < 0 ? 1 : handleIndex ? -1 : 1
  50739. };
  50740. }
  50741. function restrict(value, extend) {
  50742. return Math.min(extend[1] != null ? extend[1] : Infinity, Math.max(extend[0] != null ? extend[0] : -Infinity, value));
  50743. }
  50744. /*
  50745. * Licensed to the Apache Software Foundation (ASF) under one
  50746. * or more contributor license agreements. See the NOTICE file
  50747. * distributed with this work for additional information
  50748. * regarding copyright ownership. The ASF licenses this file
  50749. * to you under the Apache License, Version 2.0 (the
  50750. * "License"); you may not use this file except in compliance
  50751. * with the License. You may obtain a copy of the License at
  50752. *
  50753. * http://www.apache.org/licenses/LICENSE-2.0
  50754. *
  50755. * Unless required by applicable law or agreed to in writing,
  50756. * software distributed under the License is distributed on an
  50757. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50758. * KIND, either express or implied. See the License for the
  50759. * specific language governing permissions and limitations
  50760. * under the License.
  50761. */
  50762. var each$15 = each$1;
  50763. var asc$1 = asc;
  50764. /**
  50765. * Operate single axis.
  50766. * One axis can only operated by one axis operator.
  50767. * Different dataZoomModels may be defined to operate the same axis.
  50768. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  50769. * So dataZoomModels share one axisProxy in that case.
  50770. *
  50771. * @class
  50772. */
  50773. var AxisProxy = function (dimName, axisIndex, dataZoomModel, ecModel) {
  50774. /**
  50775. * @private
  50776. * @type {string}
  50777. */
  50778. this._dimName = dimName;
  50779. /**
  50780. * @private
  50781. */
  50782. this._axisIndex = axisIndex;
  50783. /**
  50784. * @private
  50785. * @type {Array.<number>}
  50786. */
  50787. this._valueWindow;
  50788. /**
  50789. * @private
  50790. * @type {Array.<number>}
  50791. */
  50792. this._percentWindow;
  50793. /**
  50794. * @private
  50795. * @type {Array.<number>}
  50796. */
  50797. this._dataExtent;
  50798. /**
  50799. * {minSpan, maxSpan, minValueSpan, maxValueSpan}
  50800. * @private
  50801. * @type {Object}
  50802. */
  50803. this._minMaxSpan;
  50804. /**
  50805. * @readOnly
  50806. * @type {module: echarts/model/Global}
  50807. */
  50808. this.ecModel = ecModel;
  50809. /**
  50810. * @private
  50811. * @type {module: echarts/component/dataZoom/DataZoomModel}
  50812. */
  50813. this._dataZoomModel = dataZoomModel; // /**
  50814. // * @readOnly
  50815. // * @private
  50816. // */
  50817. // this.hasSeriesStacked;
  50818. };
  50819. AxisProxy.prototype = {
  50820. constructor: AxisProxy,
  50821. /**
  50822. * Whether the axisProxy is hosted by dataZoomModel.
  50823. *
  50824. * @public
  50825. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  50826. * @return {boolean}
  50827. */
  50828. hostedBy: function (dataZoomModel) {
  50829. return this._dataZoomModel === dataZoomModel;
  50830. },
  50831. /**
  50832. * @return {Array.<number>} Value can only be NaN or finite value.
  50833. */
  50834. getDataValueWindow: function () {
  50835. return this._valueWindow.slice();
  50836. },
  50837. /**
  50838. * @return {Array.<number>}
  50839. */
  50840. getDataPercentWindow: function () {
  50841. return this._percentWindow.slice();
  50842. },
  50843. /**
  50844. * @public
  50845. * @param {number} axisIndex
  50846. * @return {Array} seriesModels
  50847. */
  50848. getTargetSeriesModels: function () {
  50849. var seriesModels = [];
  50850. var ecModel = this.ecModel;
  50851. ecModel.eachSeries(function (seriesModel) {
  50852. if (isCoordSupported(seriesModel.get('coordinateSystem'))) {
  50853. var dimName = this._dimName;
  50854. var axisModel = ecModel.queryComponents({
  50855. mainType: dimName + 'Axis',
  50856. index: seriesModel.get(dimName + 'AxisIndex'),
  50857. id: seriesModel.get(dimName + 'AxisId')
  50858. })[0];
  50859. if (this._axisIndex === (axisModel && axisModel.componentIndex)) {
  50860. seriesModels.push(seriesModel);
  50861. }
  50862. }
  50863. }, this);
  50864. return seriesModels;
  50865. },
  50866. getAxisModel: function () {
  50867. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  50868. },
  50869. getOtherAxisModel: function () {
  50870. var axisDim = this._dimName;
  50871. var ecModel = this.ecModel;
  50872. var axisModel = this.getAxisModel();
  50873. var isCartesian = axisDim === 'x' || axisDim === 'y';
  50874. var otherAxisDim;
  50875. var coordSysIndexName;
  50876. if (isCartesian) {
  50877. coordSysIndexName = 'gridIndex';
  50878. otherAxisDim = axisDim === 'x' ? 'y' : 'x';
  50879. } else {
  50880. coordSysIndexName = 'polarIndex';
  50881. otherAxisDim = axisDim === 'angle' ? 'radius' : 'angle';
  50882. }
  50883. var foundOtherAxisModel;
  50884. ecModel.eachComponent(otherAxisDim + 'Axis', function (otherAxisModel) {
  50885. if ((otherAxisModel.get(coordSysIndexName) || 0) === (axisModel.get(coordSysIndexName) || 0)) {
  50886. foundOtherAxisModel = otherAxisModel;
  50887. }
  50888. });
  50889. return foundOtherAxisModel;
  50890. },
  50891. getMinMaxSpan: function () {
  50892. return clone(this._minMaxSpan);
  50893. },
  50894. /**
  50895. * Only calculate by given range and this._dataExtent, do not change anything.
  50896. *
  50897. * @param {Object} opt
  50898. * @param {number} [opt.start]
  50899. * @param {number} [opt.end]
  50900. * @param {number} [opt.startValue]
  50901. * @param {number} [opt.endValue]
  50902. */
  50903. calculateDataWindow: function (opt) {
  50904. var dataExtent = this._dataExtent;
  50905. var axisModel = this.getAxisModel();
  50906. var scale = axisModel.axis.scale;
  50907. var rangePropMode = this._dataZoomModel.getRangePropMode();
  50908. var percentExtent = [0, 100];
  50909. var percentWindow = [];
  50910. var valueWindow = [];
  50911. var hasPropModeValue;
  50912. each$15(['start', 'end'], function (prop, idx) {
  50913. var boundPercent = opt[prop];
  50914. var boundValue = opt[prop + 'Value']; // Notice: dataZoom is based either on `percentProp` ('start', 'end') or
  50915. // on `valueProp` ('startValue', 'endValue'). (They are based on the data extent
  50916. // but not min/max of axis, which will be calculated by data window then).
  50917. // The former one is suitable for cases that a dataZoom component controls multiple
  50918. // axes with different unit or extent, and the latter one is suitable for accurate
  50919. // zoom by pixel (e.g., in dataZoomSelect).
  50920. // we use `getRangePropMode()` to mark which prop is used. `rangePropMode` is updated
  50921. // only when setOption or dispatchAction, otherwise it remains its original value.
  50922. // (Why not only record `percentProp` and always map to `valueProp`? Because
  50923. // the map `valueProp` -> `percentProp` -> `valueProp` probably not the original
  50924. // `valueProp`. consider two axes constrolled by one dataZoom. They have different
  50925. // data extent. All of values that are overflow the `dataExtent` will be calculated
  50926. // to percent '100%').
  50927. if (rangePropMode[idx] === 'percent') {
  50928. boundPercent == null && (boundPercent = percentExtent[idx]); // Use scale.parse to math round for category or time axis.
  50929. boundValue = scale.parse(linearMap(boundPercent, percentExtent, dataExtent));
  50930. } else {
  50931. hasPropModeValue = true;
  50932. boundValue = boundValue == null ? dataExtent[idx] : scale.parse(boundValue); // Calculating `percent` from `value` may be not accurate, because
  50933. // This calculation can not be inversed, because all of values that
  50934. // are overflow the `dataExtent` will be calculated to percent '100%'
  50935. boundPercent = linearMap(boundValue, dataExtent, percentExtent);
  50936. } // valueWindow[idx] = round(boundValue);
  50937. // percentWindow[idx] = round(boundPercent);
  50938. valueWindow[idx] = boundValue;
  50939. percentWindow[idx] = boundPercent;
  50940. });
  50941. asc$1(valueWindow);
  50942. asc$1(percentWindow); // The windows from user calling of `dispatchAction` might be out of the extent,
  50943. // or do not obey the `min/maxSpan`, `min/maxValueSpan`. But we dont restrict window
  50944. // by `zoomLock` here, because we see `zoomLock` just as a interaction constraint,
  50945. // where API is able to initialize/modify the window size even though `zoomLock`
  50946. // specified.
  50947. var spans = this._minMaxSpan;
  50948. hasPropModeValue ? restrictSet(valueWindow, percentWindow, dataExtent, percentExtent, false) : restrictSet(percentWindow, valueWindow, percentExtent, dataExtent, true);
  50949. function restrictSet(fromWindow, toWindow, fromExtent, toExtent, toValue) {
  50950. var suffix = toValue ? 'Span' : 'ValueSpan';
  50951. sliderMove(0, fromWindow, fromExtent, 'all', spans['min' + suffix], spans['max' + suffix]);
  50952. for (var i = 0; i < 2; i++) {
  50953. toWindow[i] = linearMap(fromWindow[i], fromExtent, toExtent, true);
  50954. toValue && (toWindow[i] = scale.parse(toWindow[i]));
  50955. }
  50956. }
  50957. return {
  50958. valueWindow: valueWindow,
  50959. percentWindow: percentWindow
  50960. };
  50961. },
  50962. /**
  50963. * Notice: reset should not be called before series.restoreData() called,
  50964. * so it is recommanded to be called in "process stage" but not "model init
  50965. * stage".
  50966. *
  50967. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  50968. */
  50969. reset: function (dataZoomModel) {
  50970. if (dataZoomModel !== this._dataZoomModel) {
  50971. return;
  50972. }
  50973. var targetSeries = this.getTargetSeriesModels(); // Culculate data window and data extent, and record them.
  50974. this._dataExtent = calculateDataExtent(this, this._dimName, targetSeries); // this.hasSeriesStacked = false;
  50975. // each(targetSeries, function (series) {
  50976. // var data = series.getData();
  50977. // var dataDim = data.mapDimension(this._dimName);
  50978. // var stackedDimension = data.getCalculationInfo('stackedDimension');
  50979. // if (stackedDimension && stackedDimension === dataDim) {
  50980. // this.hasSeriesStacked = true;
  50981. // }
  50982. // }, this);
  50983. // `calculateDataWindow` uses min/maxSpan.
  50984. setMinMaxSpan(this);
  50985. var dataWindow = this.calculateDataWindow(dataZoomModel.settledOption);
  50986. this._valueWindow = dataWindow.valueWindow;
  50987. this._percentWindow = dataWindow.percentWindow; // Update axis setting then.
  50988. setAxisModel(this);
  50989. },
  50990. /**
  50991. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  50992. */
  50993. restore: function (dataZoomModel) {
  50994. if (dataZoomModel !== this._dataZoomModel) {
  50995. return;
  50996. }
  50997. this._valueWindow = this._percentWindow = null;
  50998. setAxisModel(this, true);
  50999. },
  51000. /**
  51001. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  51002. */
  51003. filterData: function (dataZoomModel, api) {
  51004. if (dataZoomModel !== this._dataZoomModel) {
  51005. return;
  51006. }
  51007. var axisDim = this._dimName;
  51008. var seriesModels = this.getTargetSeriesModels();
  51009. var filterMode = dataZoomModel.get('filterMode');
  51010. var valueWindow = this._valueWindow;
  51011. if (filterMode === 'none') {
  51012. return;
  51013. } // FIXME
  51014. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  51015. // with NaN data, NaN will be filtered and stack will be wrong.
  51016. // So we need to force the mode to be set empty.
  51017. // In fect, it is not a big deal that do not support filterMode-'filter'
  51018. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  51019. // selection" some day, which might need "adapt to data extent on the
  51020. // otherAxis", which is disabled by filterMode-'empty'.
  51021. // But currently, stack has been fixed to based on value but not index,
  51022. // so this is not an issue any more.
  51023. // var otherAxisModel = this.getOtherAxisModel();
  51024. // if (dataZoomModel.get('$fromToolbox')
  51025. // && otherAxisModel
  51026. // && otherAxisModel.hasSeriesStacked
  51027. // ) {
  51028. // filterMode = 'empty';
  51029. // }
  51030. // TODO
  51031. // filterMode 'weakFilter' and 'empty' is not optimized for huge data yet.
  51032. each$15(seriesModels, function (seriesModel) {
  51033. var seriesData = seriesModel.getData();
  51034. var dataDims = seriesData.mapDimension(axisDim, true);
  51035. if (!dataDims.length) {
  51036. return;
  51037. }
  51038. if (filterMode === 'weakFilter') {
  51039. seriesData.filterSelf(function (dataIndex) {
  51040. var leftOut;
  51041. var rightOut;
  51042. var hasValue;
  51043. for (var i = 0; i < dataDims.length; i++) {
  51044. var value = seriesData.get(dataDims[i], dataIndex);
  51045. var thisHasValue = !isNaN(value);
  51046. var thisLeftOut = value < valueWindow[0];
  51047. var thisRightOut = value > valueWindow[1];
  51048. if (thisHasValue && !thisLeftOut && !thisRightOut) {
  51049. return true;
  51050. }
  51051. thisHasValue && (hasValue = true);
  51052. thisLeftOut && (leftOut = true);
  51053. thisRightOut && (rightOut = true);
  51054. } // If both left out and right out, do not filter.
  51055. return hasValue && leftOut && rightOut;
  51056. });
  51057. } else {
  51058. each$15(dataDims, function (dim) {
  51059. if (filterMode === 'empty') {
  51060. seriesModel.setData(seriesData = seriesData.map(dim, function (value) {
  51061. return !isInWindow(value) ? NaN : value;
  51062. }));
  51063. } else {
  51064. var range = {};
  51065. range[dim] = valueWindow; // console.time('select');
  51066. seriesData.selectRange(range); // console.timeEnd('select');
  51067. }
  51068. });
  51069. }
  51070. each$15(dataDims, function (dim) {
  51071. seriesData.setApproximateExtent(valueWindow, dim);
  51072. });
  51073. });
  51074. function isInWindow(value) {
  51075. return value >= valueWindow[0] && value <= valueWindow[1];
  51076. }
  51077. }
  51078. };
  51079. function calculateDataExtent(axisProxy, axisDim, seriesModels) {
  51080. var dataExtent = [Infinity, -Infinity];
  51081. each$15(seriesModels, function (seriesModel) {
  51082. var seriesData = seriesModel.getData();
  51083. if (seriesData) {
  51084. each$15(seriesData.mapDimension(axisDim, true), function (dim) {
  51085. var seriesExtent = seriesData.getApproximateExtent(dim);
  51086. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  51087. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  51088. });
  51089. }
  51090. });
  51091. if (dataExtent[1] < dataExtent[0]) {
  51092. dataExtent = [NaN, NaN];
  51093. } // It is important to get "consistent" extent when more then one axes is
  51094. // controlled by a `dataZoom`, otherwise those axes will not be synchronized
  51095. // when zooming. But it is difficult to know what is "consistent", considering
  51096. // axes have different type or even different meanings (For example, two
  51097. // time axes are used to compare data of the same date in different years).
  51098. // So basically dataZoom just obtains extent by series.data (in category axis
  51099. // extent can be obtained from axis.data).
  51100. // Nevertheless, user can set min/max/scale on axes to make extent of axes
  51101. // consistent.
  51102. fixExtentByAxis(axisProxy, dataExtent);
  51103. return dataExtent;
  51104. }
  51105. function fixExtentByAxis(axisProxy, dataExtent) {
  51106. var axisModel = axisProxy.getAxisModel();
  51107. var min = axisModel.getMin(true); // For category axis, if min/max/scale are not set, extent is determined
  51108. // by axis.data by default.
  51109. var isCategoryAxis = axisModel.get('type') === 'category';
  51110. var axisDataLen = isCategoryAxis && axisModel.getCategories().length;
  51111. if (min != null && min !== 'dataMin' && typeof min !== 'function') {
  51112. dataExtent[0] = min;
  51113. } else if (isCategoryAxis) {
  51114. dataExtent[0] = axisDataLen > 0 ? 0 : NaN;
  51115. }
  51116. var max = axisModel.getMax(true);
  51117. if (max != null && max !== 'dataMax' && typeof max !== 'function') {
  51118. dataExtent[1] = max;
  51119. } else if (isCategoryAxis) {
  51120. dataExtent[1] = axisDataLen > 0 ? axisDataLen - 1 : NaN;
  51121. }
  51122. if (!axisModel.get('scale', true)) {
  51123. dataExtent[0] > 0 && (dataExtent[0] = 0);
  51124. dataExtent[1] < 0 && (dataExtent[1] = 0);
  51125. } // For value axis, if min/max/scale are not set, we just use the extent obtained
  51126. // by series data, which may be a little different from the extent calculated by
  51127. // `axisHelper.getScaleExtent`. But the different just affects the experience a
  51128. // little when zooming. So it will not be fixed until some users require it strongly.
  51129. return dataExtent;
  51130. }
  51131. function setAxisModel(axisProxy, isRestore) {
  51132. var axisModel = axisProxy.getAxisModel();
  51133. var percentWindow = axisProxy._percentWindow;
  51134. var valueWindow = axisProxy._valueWindow;
  51135. if (!percentWindow) {
  51136. return;
  51137. } // [0, 500]: arbitrary value, guess axis extent.
  51138. var precision = getPixelPrecision(valueWindow, [0, 500]);
  51139. precision = Math.min(precision, 20); // isRestore or isFull
  51140. var useOrigin = isRestore || percentWindow[0] === 0 && percentWindow[1] === 100;
  51141. axisModel.setRange(useOrigin ? null : +valueWindow[0].toFixed(precision), useOrigin ? null : +valueWindow[1].toFixed(precision));
  51142. }
  51143. function setMinMaxSpan(axisProxy) {
  51144. var minMaxSpan = axisProxy._minMaxSpan = {};
  51145. var dataZoomModel = axisProxy._dataZoomModel;
  51146. var dataExtent = axisProxy._dataExtent;
  51147. each$15(['min', 'max'], function (minMax) {
  51148. var percentSpan = dataZoomModel.get(minMax + 'Span');
  51149. var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
  51150. valueSpan != null && (valueSpan = axisProxy.getAxisModel().axis.scale.parse(valueSpan)); // minValueSpan and maxValueSpan has higher priority than minSpan and maxSpan
  51151. if (valueSpan != null) {
  51152. percentSpan = linearMap(dataExtent[0] + valueSpan, dataExtent, [0, 100], true);
  51153. } else if (percentSpan != null) {
  51154. valueSpan = linearMap(percentSpan, [0, 100], dataExtent, true) - dataExtent[0];
  51155. }
  51156. minMaxSpan[minMax + 'Span'] = percentSpan;
  51157. minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
  51158. });
  51159. }
  51160. /*
  51161. * Licensed to the Apache Software Foundation (ASF) under one
  51162. * or more contributor license agreements. See the NOTICE file
  51163. * distributed with this work for additional information
  51164. * regarding copyright ownership. The ASF licenses this file
  51165. * to you under the Apache License, Version 2.0 (the
  51166. * "License"); you may not use this file except in compliance
  51167. * with the License. You may obtain a copy of the License at
  51168. *
  51169. * http://www.apache.org/licenses/LICENSE-2.0
  51170. *
  51171. * Unless required by applicable law or agreed to in writing,
  51172. * software distributed under the License is distributed on an
  51173. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51174. * KIND, either express or implied. See the License for the
  51175. * specific language governing permissions and limitations
  51176. * under the License.
  51177. */
  51178. var each$14 = each$1;
  51179. var eachAxisDim = eachAxisDim$1;
  51180. var DataZoomModel = extendComponentModel({
  51181. type: 'dataZoom',
  51182. dependencies: ['xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series'],
  51183. /**
  51184. * @protected
  51185. */
  51186. defaultOption: {
  51187. zlevel: 0,
  51188. z: 4,
  51189. // Higher than normal component (z: 2).
  51190. orient: null,
  51191. // Default auto by axisIndex. Possible value: 'horizontal', 'vertical'.
  51192. xAxisIndex: null,
  51193. // Default the first horizontal category axis.
  51194. yAxisIndex: null,
  51195. // Default the first vertical category axis.
  51196. filterMode: 'filter',
  51197. // Possible values: 'filter' or 'empty' or 'weakFilter'.
  51198. // 'filter': data items which are out of window will be removed. This option is
  51199. // applicable when filtering outliers. For each data item, it will be
  51200. // filtered if one of the relevant dimensions is out of the window.
  51201. // 'weakFilter': data items which are out of window will be removed. This option
  51202. // is applicable when filtering outliers. For each data item, it will be
  51203. // filtered only if all of the relevant dimensions are out of the same
  51204. // side of the window.
  51205. // 'empty': data items which are out of window will be set to empty.
  51206. // This option is applicable when user should not neglect
  51207. // that there are some data items out of window.
  51208. // 'none': Do not filter.
  51209. // Taking line chart as an example, line will be broken in
  51210. // the filtered points when filterModel is set to 'empty', but
  51211. // be connected when set to 'filter'.
  51212. throttle: null,
  51213. // Dispatch action by the fixed rate, avoid frequency.
  51214. // default 100. Do not throttle when use null/undefined.
  51215. // If animation === true and animationDurationUpdate > 0,
  51216. // default value is 100, otherwise 20.
  51217. start: 0,
  51218. // Start percent. 0 ~ 100
  51219. end: 100,
  51220. // End percent. 0 ~ 100
  51221. startValue: null,
  51222. // Start value. If startValue specified, start is ignored.
  51223. endValue: null,
  51224. // End value. If endValue specified, end is ignored.
  51225. minSpan: null,
  51226. // 0 ~ 100
  51227. maxSpan: null,
  51228. // 0 ~ 100
  51229. minValueSpan: null,
  51230. // The range of dataZoom can not be smaller than that.
  51231. maxValueSpan: null,
  51232. // The range of dataZoom can not be larger than that.
  51233. rangeMode: null // Array, can be 'value' or 'percent'.
  51234. },
  51235. /**
  51236. * @override
  51237. */
  51238. init: function (option, parentModel, ecModel) {
  51239. /**
  51240. * key like x_0, y_1
  51241. * @private
  51242. * @type {Object}
  51243. */
  51244. this._dataIntervalByAxis = {};
  51245. /**
  51246. * @private
  51247. */
  51248. this._dataInfo = {};
  51249. /**
  51250. * key like x_0, y_1
  51251. * @private
  51252. */
  51253. this._axisProxies = {};
  51254. /**
  51255. * @readOnly
  51256. */
  51257. this.textStyleModel;
  51258. /**
  51259. * @private
  51260. */
  51261. this._autoThrottle = true;
  51262. /**
  51263. * It is `[rangeModeForMin, rangeModeForMax]`.
  51264. * The optional values for `rangeMode`:
  51265. * + `'value'` mode: the axis extent will always be determined by
  51266. * `dataZoom.startValue` and `dataZoom.endValue`, despite
  51267. * how data like and how `axis.min` and `axis.max` are.
  51268. * + `'percent'` mode: `100` represents 100% of the `[dMin, dMax]`,
  51269. * where `dMin` is `axis.min` if `axis.min` specified, otherwise `data.extent[0]`,
  51270. * and `dMax` is `axis.max` if `axis.max` specified, otherwise `data.extent[1]`.
  51271. * Axis extent will be determined by the result of the percent of `[dMin, dMax]`.
  51272. *
  51273. * For example, when users are using dynamic data (update data periodically via `setOption`),
  51274. * if in `'value`' mode, the window will be kept in a fixed value range despite how
  51275. * data are appended, while if in `'percent'` mode, whe window range will be changed alone with
  51276. * the appended data (suppose `axis.min` and `axis.max` are not specified).
  51277. *
  51278. * @private
  51279. */
  51280. this._rangePropMode = ['percent', 'percent'];
  51281. var inputRawOption = retrieveRawOption(option);
  51282. /**
  51283. * Suppose a "main process" start at the point that model prepared (that is,
  51284. * model initialized or merged or method called in `action`).
  51285. * We should keep the `main process` idempotent, that is, given a set of values
  51286. * on `option`, we get the same result.
  51287. *
  51288. * But sometimes, values on `option` will be updated for providing users
  51289. * a "final calculated value" (`dataZoomProcessor` will do that). Those value
  51290. * should not be the base/input of the `main process`.
  51291. *
  51292. * So in that case we should save and keep the input of the `main process`
  51293. * separately, called `settledOption`.
  51294. *
  51295. * For example, consider the case:
  51296. * (Step_1) brush zoom the grid by `toolbox.dataZoom`,
  51297. * where the original input `option.startValue`, `option.endValue` are earsed by
  51298. * calculated value.
  51299. * (Step)2) click the legend to hide and show a series,
  51300. * where the new range is calculated by the earsed `startValue` and `endValue`,
  51301. * which brings incorrect result.
  51302. *
  51303. * @readOnly
  51304. */
  51305. this.settledOption = inputRawOption;
  51306. this.mergeDefaultAndTheme(option, ecModel);
  51307. this.doInit(inputRawOption);
  51308. },
  51309. /**
  51310. * @override
  51311. */
  51312. mergeOption: function (newOption) {
  51313. var inputRawOption = retrieveRawOption(newOption); //FIX #2591
  51314. merge(this.option, newOption, true);
  51315. merge(this.settledOption, inputRawOption, true);
  51316. this.doInit(inputRawOption);
  51317. },
  51318. /**
  51319. * @protected
  51320. */
  51321. doInit: function (inputRawOption) {
  51322. var thisOption = this.option; // Disable realtime view update if canvas is not supported.
  51323. if (!env$1.canvasSupported) {
  51324. thisOption.realtime = false;
  51325. }
  51326. this._setDefaultThrottle(inputRawOption);
  51327. updateRangeUse(this, inputRawOption);
  51328. var settledOption = this.settledOption;
  51329. each$14([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  51330. // start/end has higher priority over startValue/endValue if they
  51331. // both set, but we should make chart.setOption({endValue: 1000})
  51332. // effective, rather than chart.setOption({endValue: 1000, end: null}).
  51333. if (this._rangePropMode[index] === 'value') {
  51334. thisOption[names[0]] = settledOption[names[0]] = null;
  51335. } // Otherwise do nothing and use the merge result.
  51336. }, this);
  51337. this.textStyleModel = this.getModel('textStyle');
  51338. this._resetTarget();
  51339. this._giveAxisProxies();
  51340. },
  51341. /**
  51342. * @private
  51343. */
  51344. _giveAxisProxies: function () {
  51345. var axisProxies = this._axisProxies;
  51346. this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
  51347. var axisModel = this.dependentModels[dimNames.axis][axisIndex]; // If exists, share axisProxy with other dataZoomModels.
  51348. var axisProxy = axisModel.__dzAxisProxy || ( // Use the first dataZoomModel as the main model of axisProxy.
  51349. axisModel.__dzAxisProxy = new AxisProxy(dimNames.name, axisIndex, this, ecModel)); // FIXME
  51350. // dispose __dzAxisProxy
  51351. axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
  51352. }, this);
  51353. },
  51354. /**
  51355. * @private
  51356. */
  51357. _resetTarget: function () {
  51358. var thisOption = this.option;
  51359. var autoMode = this._judgeAutoMode();
  51360. eachAxisDim(function (dimNames) {
  51361. var axisIndexName = dimNames.axisIndex;
  51362. thisOption[axisIndexName] = normalizeToArray(thisOption[axisIndexName]);
  51363. }, this);
  51364. if (autoMode === 'axisIndex') {
  51365. this._autoSetAxisIndex();
  51366. } else if (autoMode === 'orient') {
  51367. this._autoSetOrient();
  51368. }
  51369. },
  51370. /**
  51371. * @private
  51372. */
  51373. _judgeAutoMode: function () {
  51374. // Auto set only works for setOption at the first time.
  51375. // The following is user's reponsibility. So using merged
  51376. // option is OK.
  51377. var thisOption = this.option;
  51378. var hasIndexSpecified = false;
  51379. eachAxisDim(function (dimNames) {
  51380. // When user set axisIndex as a empty array, we think that user specify axisIndex
  51381. // but do not want use auto mode. Because empty array may be encountered when
  51382. // some error occured.
  51383. if (thisOption[dimNames.axisIndex] != null) {
  51384. hasIndexSpecified = true;
  51385. }
  51386. }, this);
  51387. var orient = thisOption.orient;
  51388. if (orient == null && hasIndexSpecified) {
  51389. return 'orient';
  51390. } else if (!hasIndexSpecified) {
  51391. if (orient == null) {
  51392. thisOption.orient = 'horizontal';
  51393. }
  51394. return 'axisIndex';
  51395. }
  51396. },
  51397. /**
  51398. * @private
  51399. */
  51400. _autoSetAxisIndex: function () {
  51401. var autoAxisIndex = true;
  51402. var orient = this.get('orient', true);
  51403. var thisOption = this.option;
  51404. var dependentModels = this.dependentModels;
  51405. if (autoAxisIndex) {
  51406. // Find axis that parallel to dataZoom as default.
  51407. var dimName = orient === 'vertical' ? 'y' : 'x';
  51408. if (dependentModels[dimName + 'Axis'].length) {
  51409. thisOption[dimName + 'AxisIndex'] = [0];
  51410. autoAxisIndex = false;
  51411. } else {
  51412. each$14(dependentModels.singleAxis, function (singleAxisModel) {
  51413. if (autoAxisIndex && singleAxisModel.get('orient', true) === orient) {
  51414. thisOption.singleAxisIndex = [singleAxisModel.componentIndex];
  51415. autoAxisIndex = false;
  51416. }
  51417. });
  51418. }
  51419. }
  51420. if (autoAxisIndex) {
  51421. // Find the first category axis as default. (consider polar)
  51422. eachAxisDim(function (dimNames) {
  51423. if (!autoAxisIndex) {
  51424. return;
  51425. }
  51426. var axisIndices = [];
  51427. var axisModels = this.dependentModels[dimNames.axis];
  51428. if (axisModels.length && !axisIndices.length) {
  51429. for (var i = 0, len = axisModels.length; i < len; i++) {
  51430. if (axisModels[i].get('type') === 'category') {
  51431. axisIndices.push(i);
  51432. }
  51433. }
  51434. }
  51435. thisOption[dimNames.axisIndex] = axisIndices;
  51436. if (axisIndices.length) {
  51437. autoAxisIndex = false;
  51438. }
  51439. }, this);
  51440. }
  51441. if (autoAxisIndex) {
  51442. // FIXME
  51443. // 这里是兼容ec2的写法(没指定xAxisIndex和yAxisIndex时把scatter和双数值轴折柱纳入dataZoom控制),
  51444. // 但是实际是否需要Grid.js#getScaleByOption来判断(考虑time,log等axis type)?
  51445. // If both dataZoom.xAxisIndex and dataZoom.yAxisIndex is not specified,
  51446. // dataZoom component auto adopts series that reference to
  51447. // both xAxis and yAxis which type is 'value'.
  51448. this.ecModel.eachSeries(function (seriesModel) {
  51449. if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
  51450. eachAxisDim(function (dimNames) {
  51451. var axisIndices = thisOption[dimNames.axisIndex];
  51452. var axisIndex = seriesModel.get(dimNames.axisIndex);
  51453. var axisId = seriesModel.get(dimNames.axisId);
  51454. var axisModel = seriesModel.ecModel.queryComponents({
  51455. mainType: dimNames.axis,
  51456. index: axisIndex,
  51457. id: axisId
  51458. })[0];
  51459. axisIndex = axisModel.componentIndex;
  51460. if (indexOf(axisIndices, axisIndex) < 0) {
  51461. axisIndices.push(axisIndex);
  51462. }
  51463. });
  51464. }
  51465. }, this);
  51466. }
  51467. },
  51468. /**
  51469. * @private
  51470. */
  51471. _autoSetOrient: function () {
  51472. var dim; // Find the first axis
  51473. this.eachTargetAxis(function (dimNames) {
  51474. !dim && (dim = dimNames.name);
  51475. }, this);
  51476. this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
  51477. },
  51478. /**
  51479. * @private
  51480. */
  51481. _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
  51482. // FIXME
  51483. // 需要series的xAxisIndex和yAxisIndex都首先自动设置上。
  51484. // 例如series.type === scatter时。
  51485. var is = true;
  51486. eachAxisDim(function (dimNames) {
  51487. var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
  51488. var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
  51489. if (!axisModel || axisModel.get('type') !== axisType) {
  51490. is = false;
  51491. }
  51492. }, this);
  51493. return is;
  51494. },
  51495. /**
  51496. * @private
  51497. */
  51498. _setDefaultThrottle: function (inputRawOption) {
  51499. // When first time user set throttle, auto throttle ends.
  51500. if (inputRawOption.hasOwnProperty('throttle')) {
  51501. this._autoThrottle = false;
  51502. }
  51503. if (this._autoThrottle) {
  51504. var globalOption = this.ecModel.option;
  51505. this.option.throttle = globalOption.animation && globalOption.animationDurationUpdate > 0 ? 100 : 20;
  51506. }
  51507. },
  51508. /**
  51509. * @public
  51510. */
  51511. getFirstTargetAxisModel: function () {
  51512. var firstAxisModel;
  51513. eachAxisDim(function (dimNames) {
  51514. if (firstAxisModel == null) {
  51515. var indices = this.get(dimNames.axisIndex);
  51516. if (indices.length) {
  51517. firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
  51518. }
  51519. }
  51520. }, this);
  51521. return firstAxisModel;
  51522. },
  51523. /**
  51524. * @public
  51525. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  51526. */
  51527. eachTargetAxis: function (callback, context) {
  51528. var ecModel = this.ecModel;
  51529. eachAxisDim(function (dimNames) {
  51530. each$14(this.get(dimNames.axisIndex), function (axisIndex) {
  51531. callback.call(context, dimNames, axisIndex, this, ecModel);
  51532. }, this);
  51533. }, this);
  51534. },
  51535. /**
  51536. * @param {string} dimName
  51537. * @param {number} axisIndex
  51538. * @return {module:echarts/component/dataZoom/AxisProxy} If not found, return null/undefined.
  51539. */
  51540. getAxisProxy: function (dimName, axisIndex) {
  51541. return this._axisProxies[dimName + '_' + axisIndex];
  51542. },
  51543. /**
  51544. * @param {string} dimName
  51545. * @param {number} axisIndex
  51546. * @return {module:echarts/model/Model} If not found, return null/undefined.
  51547. */
  51548. getAxisModel: function (dimName, axisIndex) {
  51549. var axisProxy = this.getAxisProxy(dimName, axisIndex);
  51550. return axisProxy && axisProxy.getAxisModel();
  51551. },
  51552. /**
  51553. * If not specified, set to undefined.
  51554. *
  51555. * @public
  51556. * @param {Object} opt
  51557. * @param {number} [opt.start]
  51558. * @param {number} [opt.end]
  51559. * @param {number} [opt.startValue]
  51560. * @param {number} [opt.endValue]
  51561. */
  51562. setRawRange: function (opt) {
  51563. var thisOption = this.option;
  51564. var settledOption = this.settledOption;
  51565. each$14([['start', 'startValue'], ['end', 'endValue']], function (names) {
  51566. // Consider the pair <start, startValue>:
  51567. // If one has value and the other one is `null/undefined`, we both set them
  51568. // to `settledOption`. This strategy enables the feature to clear the original
  51569. // value in `settledOption` to `null/undefined`.
  51570. // But if both of them are `null/undefined`, we do not set them to `settledOption`
  51571. // and keep `settledOption` with the original value. This strategy enables users to
  51572. // only set <end or endValue> but not set <start or startValue> when calling
  51573. // `dispatchAction`.
  51574. // The pair <end, endValue> is treated in the same way.
  51575. if (opt[names[0]] != null || opt[names[1]] != null) {
  51576. thisOption[names[0]] = settledOption[names[0]] = opt[names[0]];
  51577. thisOption[names[1]] = settledOption[names[1]] = opt[names[1]];
  51578. }
  51579. }, this);
  51580. updateRangeUse(this, opt);
  51581. },
  51582. /**
  51583. * @public
  51584. * @param {Object} opt
  51585. * @param {number} [opt.start]
  51586. * @param {number} [opt.end]
  51587. * @param {number} [opt.startValue]
  51588. * @param {number} [opt.endValue]
  51589. */
  51590. setCalculatedRange: function (opt) {
  51591. var option = this.option;
  51592. each$14(['start', 'startValue', 'end', 'endValue'], function (name) {
  51593. option[name] = opt[name];
  51594. });
  51595. },
  51596. /**
  51597. * @public
  51598. * @return {Array.<number>} [startPercent, endPercent]
  51599. */
  51600. getPercentRange: function () {
  51601. var axisProxy = this.findRepresentativeAxisProxy();
  51602. if (axisProxy) {
  51603. return axisProxy.getDataPercentWindow();
  51604. }
  51605. },
  51606. /**
  51607. * @public
  51608. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  51609. *
  51610. * @param {string} [axisDimName]
  51611. * @param {number} [axisIndex]
  51612. * @return {Array.<number>} [startValue, endValue] value can only be '-' or finite number.
  51613. */
  51614. getValueRange: function (axisDimName, axisIndex) {
  51615. if (axisDimName == null && axisIndex == null) {
  51616. var axisProxy = this.findRepresentativeAxisProxy();
  51617. if (axisProxy) {
  51618. return axisProxy.getDataValueWindow();
  51619. }
  51620. } else {
  51621. return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
  51622. }
  51623. },
  51624. /**
  51625. * @public
  51626. * @param {module:echarts/model/Model} [axisModel] If axisModel given, find axisProxy
  51627. * corresponding to the axisModel
  51628. * @return {module:echarts/component/dataZoom/AxisProxy}
  51629. */
  51630. findRepresentativeAxisProxy: function (axisModel) {
  51631. if (axisModel) {
  51632. return axisModel.__dzAxisProxy;
  51633. } // Find the first hosted axisProxy
  51634. var axisProxies = this._axisProxies;
  51635. for (var key in axisProxies) {
  51636. if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
  51637. return axisProxies[key];
  51638. }
  51639. } // If no hosted axis find not hosted axisProxy.
  51640. // Consider this case: dataZoomModel1 and dataZoomModel2 control the same axis,
  51641. // and the option.start or option.end settings are different. The percentRange
  51642. // should follow axisProxy.
  51643. // (We encounter this problem in toolbox data zoom.)
  51644. for (var key in axisProxies) {
  51645. if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
  51646. return axisProxies[key];
  51647. }
  51648. }
  51649. },
  51650. /**
  51651. * @return {Array.<string>}
  51652. */
  51653. getRangePropMode: function () {
  51654. return this._rangePropMode.slice();
  51655. }
  51656. });
  51657. /**
  51658. * Retrieve the those raw params from option, which will be cached separately.
  51659. * becasue they will be overwritten by normalized/calculated values in the main
  51660. * process.
  51661. */
  51662. function retrieveRawOption(option) {
  51663. var ret = {};
  51664. each$14(['start', 'end', 'startValue', 'endValue', 'throttle'], function (name) {
  51665. option.hasOwnProperty(name) && (ret[name] = option[name]);
  51666. });
  51667. return ret;
  51668. }
  51669. function updateRangeUse(dataZoomModel, inputRawOption) {
  51670. var rangePropMode = dataZoomModel._rangePropMode;
  51671. var rangeModeInOption = dataZoomModel.get('rangeMode');
  51672. each$14([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  51673. var percentSpecified = inputRawOption[names[0]] != null;
  51674. var valueSpecified = inputRawOption[names[1]] != null;
  51675. if (percentSpecified && !valueSpecified) {
  51676. rangePropMode[index] = 'percent';
  51677. } else if (!percentSpecified && valueSpecified) {
  51678. rangePropMode[index] = 'value';
  51679. } else if (rangeModeInOption) {
  51680. rangePropMode[index] = rangeModeInOption[index];
  51681. } else if (percentSpecified) {
  51682. // percentSpecified && valueSpecified
  51683. rangePropMode[index] = 'percent';
  51684. } // else remain its original setting.
  51685. });
  51686. }
  51687. /*
  51688. * Licensed to the Apache Software Foundation (ASF) under one
  51689. * or more contributor license agreements. See the NOTICE file
  51690. * distributed with this work for additional information
  51691. * regarding copyright ownership. The ASF licenses this file
  51692. * to you under the Apache License, Version 2.0 (the
  51693. * "License"); you may not use this file except in compliance
  51694. * with the License. You may obtain a copy of the License at
  51695. *
  51696. * http://www.apache.org/licenses/LICENSE-2.0
  51697. *
  51698. * Unless required by applicable law or agreed to in writing,
  51699. * software distributed under the License is distributed on an
  51700. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51701. * KIND, either express or implied. See the License for the
  51702. * specific language governing permissions and limitations
  51703. * under the License.
  51704. */
  51705. var DataZoomView = Component$1.extend({
  51706. type: 'dataZoom',
  51707. render: function (dataZoomModel, ecModel, api, payload) {
  51708. this.dataZoomModel = dataZoomModel;
  51709. this.ecModel = ecModel;
  51710. this.api = api;
  51711. },
  51712. /**
  51713. * Find the first target coordinate system.
  51714. *
  51715. * @protected
  51716. * @return {Object} {
  51717. * grid: [
  51718. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  51719. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  51720. * ...
  51721. * ], // cartesians must not be null/undefined.
  51722. * polar: [
  51723. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  51724. * ...
  51725. * ], // polars must not be null/undefined.
  51726. * singleAxis: [
  51727. * {model: coord0, axisModels: [], coordIndex: 0}
  51728. * ]
  51729. */
  51730. getTargetCoordInfo: function () {
  51731. var dataZoomModel = this.dataZoomModel;
  51732. var ecModel = this.ecModel;
  51733. var coordSysLists = {};
  51734. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  51735. var axisModel = ecModel.getComponent(dimNames.axis, axisIndex);
  51736. if (axisModel) {
  51737. var coordModel = axisModel.getCoordSysModel();
  51738. coordModel && save(coordModel, axisModel, coordSysLists[coordModel.mainType] || (coordSysLists[coordModel.mainType] = []), coordModel.componentIndex);
  51739. }
  51740. }, this);
  51741. function save(coordModel, axisModel, store, coordIndex) {
  51742. var item;
  51743. for (var i = 0; i < store.length; i++) {
  51744. if (store[i].model === coordModel) {
  51745. item = store[i];
  51746. break;
  51747. }
  51748. }
  51749. if (!item) {
  51750. store.push(item = {
  51751. model: coordModel,
  51752. axisModels: [],
  51753. coordIndex: coordIndex
  51754. });
  51755. }
  51756. item.axisModels.push(axisModel);
  51757. }
  51758. return coordSysLists;
  51759. }
  51760. });
  51761. /*
  51762. * Licensed to the Apache Software Foundation (ASF) under one
  51763. * or more contributor license agreements. See the NOTICE file
  51764. * distributed with this work for additional information
  51765. * regarding copyright ownership. The ASF licenses this file
  51766. * to you under the Apache License, Version 2.0 (the
  51767. * "License"); you may not use this file except in compliance
  51768. * with the License. You may obtain a copy of the License at
  51769. *
  51770. * http://www.apache.org/licenses/LICENSE-2.0
  51771. *
  51772. * Unless required by applicable law or agreed to in writing,
  51773. * software distributed under the License is distributed on an
  51774. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51775. * KIND, either express or implied. See the License for the
  51776. * specific language governing permissions and limitations
  51777. * under the License.
  51778. */
  51779. var SliderZoomModel = DataZoomModel.extend({
  51780. type: 'dataZoom.slider',
  51781. layoutMode: 'box',
  51782. /**
  51783. * @protected
  51784. */
  51785. defaultOption: {
  51786. show: true,
  51787. // ph => placeholder. Using placehoder here because
  51788. // deault value can only be drived in view stage.
  51789. right: 'ph',
  51790. // Default align to grid rect.
  51791. top: 'ph',
  51792. // Default align to grid rect.
  51793. width: 'ph',
  51794. // Default align to grid rect.
  51795. height: 'ph',
  51796. // Default align to grid rect.
  51797. left: null,
  51798. // Default align to grid rect.
  51799. bottom: null,
  51800. // Default align to grid rect.
  51801. backgroundColor: 'rgba(47,69,84,0)',
  51802. // Background of slider zoom component.
  51803. // dataBackgroundColor: '#ddd', // Background coor of data shadow and border of box,
  51804. // highest priority, remain for compatibility of
  51805. // previous version, but not recommended any more.
  51806. dataBackground: {
  51807. lineStyle: {
  51808. color: '#2f4554',
  51809. width: 0.5,
  51810. opacity: 0.3
  51811. },
  51812. areaStyle: {
  51813. color: 'rgba(47,69,84,0.3)',
  51814. opacity: 0.3
  51815. }
  51816. },
  51817. borderColor: '#ddd',
  51818. // border color of the box. For compatibility,
  51819. // if dataBackgroundColor is set, borderColor
  51820. // is ignored.
  51821. fillerColor: 'rgba(167,183,204,0.4)',
  51822. // Color of selected area.
  51823. // handleColor: 'rgba(89,170,216,0.95)', // Color of handle.
  51824. // handleIcon: 'path://M4.9,17.8c0-1.4,4.5-10.5,5.5-12.4c0-0.1,0.6-1.1,0.9-1.1c0.4,0,0.9,1,0.9,1.1c1.1,2.2,5.4,11,5.4,12.4v17.8c0,1.5-0.6,2.1-1.3,2.1H6.1c-0.7,0-1.3-0.6-1.3-2.1V17.8z',
  51825. /* eslint-disable */
  51826. handleIcon: 'M8.2,13.6V3.9H6.3v9.7H3.1v14.9h3.3v9.7h1.8v-9.7h3.3V13.6H8.2z M9.7,24.4H4.8v-1.4h4.9V24.4z M9.7,19.1H4.8v-1.4h4.9V19.1z',
  51827. /* eslint-enable */
  51828. // Percent of the slider height
  51829. handleSize: '100%',
  51830. handleStyle: {
  51831. color: '#a7b7cc'
  51832. },
  51833. labelPrecision: null,
  51834. labelFormatter: null,
  51835. showDetail: true,
  51836. showDataShadow: 'auto',
  51837. // Default auto decision.
  51838. realtime: true,
  51839. zoomLock: false,
  51840. // Whether disable zoom.
  51841. textStyle: {
  51842. color: '#333'
  51843. }
  51844. }
  51845. });
  51846. /*
  51847. * Licensed to the Apache Software Foundation (ASF) under one
  51848. * or more contributor license agreements. See the NOTICE file
  51849. * distributed with this work for additional information
  51850. * regarding copyright ownership. The ASF licenses this file
  51851. * to you under the Apache License, Version 2.0 (the
  51852. * "License"); you may not use this file except in compliance
  51853. * with the License. You may obtain a copy of the License at
  51854. *
  51855. * http://www.apache.org/licenses/LICENSE-2.0
  51856. *
  51857. * Unless required by applicable law or agreed to in writing,
  51858. * software distributed under the License is distributed on an
  51859. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51860. * KIND, either express or implied. See the License for the
  51861. * specific language governing permissions and limitations
  51862. * under the License.
  51863. */
  51864. var Rect$1 = Rect;
  51865. var linearMap$1 = linearMap;
  51866. var asc$2 = asc;
  51867. var bind$4 = bind;
  51868. var each$16 = each$1; // Constants
  51869. var DEFAULT_LOCATION_EDGE_GAP = 7;
  51870. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  51871. var DEFAULT_FILLER_SIZE = 30;
  51872. var HORIZONTAL = 'horizontal';
  51873. var VERTICAL = 'vertical';
  51874. var LABEL_GAP = 5;
  51875. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  51876. var SliderZoomView = DataZoomView.extend({
  51877. type: 'dataZoom.slider',
  51878. init: function (ecModel, api) {
  51879. /**
  51880. * @private
  51881. * @type {Object}
  51882. */
  51883. this._displayables = {};
  51884. /**
  51885. * @private
  51886. * @type {string}
  51887. */
  51888. this._orient;
  51889. /**
  51890. * [0, 100]
  51891. * @private
  51892. */
  51893. this._range;
  51894. /**
  51895. * [coord of the first handle, coord of the second handle]
  51896. * @private
  51897. */
  51898. this._handleEnds;
  51899. /**
  51900. * [length, thick]
  51901. * @private
  51902. * @type {Array.<number>}
  51903. */
  51904. this._size;
  51905. /**
  51906. * @private
  51907. * @type {number}
  51908. */
  51909. this._handleWidth;
  51910. /**
  51911. * @private
  51912. * @type {number}
  51913. */
  51914. this._handleHeight;
  51915. /**
  51916. * @private
  51917. */
  51918. this._location;
  51919. /**
  51920. * @private
  51921. */
  51922. this._dragging;
  51923. /**
  51924. * @private
  51925. */
  51926. this._dataShadowInfo;
  51927. this.api = api;
  51928. },
  51929. /**
  51930. * @override
  51931. */
  51932. render: function (dataZoomModel, ecModel, api, payload) {
  51933. SliderZoomView.superApply(this, 'render', arguments);
  51934. createOrUpdate(this, '_dispatchZoomAction', this.dataZoomModel.get('throttle'), 'fixRate');
  51935. this._orient = dataZoomModel.get('orient');
  51936. if (this.dataZoomModel.get('show') === false) {
  51937. this.group.removeAll();
  51938. return;
  51939. } // Notice: this._resetInterval() should not be executed when payload.type
  51940. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  51941. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  51942. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  51943. this._buildView();
  51944. }
  51945. this._updateView();
  51946. },
  51947. /**
  51948. * @override
  51949. */
  51950. remove: function () {
  51951. SliderZoomView.superApply(this, 'remove', arguments);
  51952. clear(this, '_dispatchZoomAction');
  51953. },
  51954. /**
  51955. * @override
  51956. */
  51957. dispose: function () {
  51958. SliderZoomView.superApply(this, 'dispose', arguments);
  51959. clear(this, '_dispatchZoomAction');
  51960. },
  51961. _buildView: function () {
  51962. var thisGroup = this.group;
  51963. thisGroup.removeAll();
  51964. this._resetLocation();
  51965. this._resetInterval();
  51966. var barGroup = this._displayables.barGroup = new Group();
  51967. this._renderBackground();
  51968. this._renderHandle();
  51969. this._renderDataShadow();
  51970. thisGroup.add(barGroup);
  51971. this._positionGroup();
  51972. },
  51973. /**
  51974. * @private
  51975. */
  51976. _resetLocation: function () {
  51977. var dataZoomModel = this.dataZoomModel;
  51978. var api = this.api; // If some of x/y/width/height are not specified,
  51979. // auto-adapt according to target grid.
  51980. var coordRect = this._findCoordRect();
  51981. var ecSize = {
  51982. width: api.getWidth(),
  51983. height: api.getHeight()
  51984. }; // Default align by coordinate system rect.
  51985. var positionInfo = this._orient === HORIZONTAL ? {
  51986. // Why using 'right', because right should be used in vertical,
  51987. // and it is better to be consistent for dealing with position param merge.
  51988. right: ecSize.width - coordRect.x - coordRect.width,
  51989. top: ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP,
  51990. width: coordRect.width,
  51991. height: DEFAULT_FILLER_SIZE
  51992. } : {
  51993. // vertical
  51994. right: DEFAULT_LOCATION_EDGE_GAP,
  51995. top: coordRect.y,
  51996. width: DEFAULT_FILLER_SIZE,
  51997. height: coordRect.height
  51998. }; // Do not write back to option and replace value 'ph', because
  51999. // the 'ph' value should be recalculated when resize.
  52000. var layoutParams = getLayoutParams(dataZoomModel.option); // Replace the placeholder value.
  52001. each$1(['right', 'top', 'width', 'height'], function (name) {
  52002. if (layoutParams[name] === 'ph') {
  52003. layoutParams[name] = positionInfo[name];
  52004. }
  52005. });
  52006. var layoutRect = getLayoutRect(layoutParams, ecSize, dataZoomModel.padding);
  52007. this._location = {
  52008. x: layoutRect.x,
  52009. y: layoutRect.y
  52010. };
  52011. this._size = [layoutRect.width, layoutRect.height];
  52012. this._orient === VERTICAL && this._size.reverse();
  52013. },
  52014. /**
  52015. * @private
  52016. */
  52017. _positionGroup: function () {
  52018. var thisGroup = this.group;
  52019. var location = this._location;
  52020. var orient = this._orient; // Just use the first axis to determine mapping.
  52021. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  52022. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  52023. var barGroup = this._displayables.barGroup;
  52024. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse; // Transform barGroup.
  52025. barGroup.attr(orient === HORIZONTAL && !inverse ? {
  52026. scale: otherAxisInverse ? [1, 1] : [1, -1]
  52027. } : orient === HORIZONTAL && inverse ? {
  52028. scale: otherAxisInverse ? [-1, 1] : [-1, -1]
  52029. } : orient === VERTICAL && !inverse ? {
  52030. scale: otherAxisInverse ? [1, -1] : [1, 1],
  52031. rotation: Math.PI / 2 // Dont use Math.PI, considering shadow direction.
  52032. } : {
  52033. scale: otherAxisInverse ? [-1, -1] : [-1, 1],
  52034. rotation: Math.PI / 2
  52035. }); // Position barGroup
  52036. var rect = thisGroup.getBoundingRect([barGroup]);
  52037. thisGroup.attr('position', [location.x - rect.x, location.y - rect.y]);
  52038. },
  52039. /**
  52040. * @private
  52041. */
  52042. _getViewExtent: function () {
  52043. return [0, this._size[0]];
  52044. },
  52045. _renderBackground: function () {
  52046. var dataZoomModel = this.dataZoomModel;
  52047. var size = this._size;
  52048. var barGroup = this._displayables.barGroup;
  52049. barGroup.add(new Rect$1({
  52050. silent: true,
  52051. shape: {
  52052. x: 0,
  52053. y: 0,
  52054. width: size[0],
  52055. height: size[1]
  52056. },
  52057. style: {
  52058. fill: dataZoomModel.get('backgroundColor')
  52059. },
  52060. z2: -40
  52061. })); // Click panel, over shadow, below handles.
  52062. barGroup.add(new Rect$1({
  52063. shape: {
  52064. x: 0,
  52065. y: 0,
  52066. width: size[0],
  52067. height: size[1]
  52068. },
  52069. style: {
  52070. fill: 'transparent'
  52071. },
  52072. z2: 0,
  52073. onclick: bind(this._onClickPanelClick, this)
  52074. }));
  52075. },
  52076. _renderDataShadow: function () {
  52077. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  52078. if (!info) {
  52079. return;
  52080. }
  52081. var size = this._size;
  52082. var seriesModel = info.series;
  52083. var data = seriesModel.getRawData();
  52084. var otherDim = seriesModel.getShadowDim ? seriesModel.getShadowDim() // @see candlestick
  52085. : info.otherDim;
  52086. if (otherDim == null) {
  52087. return;
  52088. }
  52089. var otherDataExtent = data.getDataExtent(otherDim); // Nice extent.
  52090. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  52091. otherDataExtent = [otherDataExtent[0] - otherOffset, otherDataExtent[1] + otherOffset];
  52092. var otherShadowExtent = [0, size[1]];
  52093. var thisShadowExtent = [0, size[0]];
  52094. var areaPoints = [[size[0], 0], [0, 0]];
  52095. var linePoints = [];
  52096. var step = thisShadowExtent[1] / (data.count() - 1);
  52097. var thisCoord = 0; // Optimize for large data shadow
  52098. var stride = Math.round(data.count() / size[0]);
  52099. var lastIsEmpty;
  52100. data.each([otherDim], function (value, index) {
  52101. if (stride > 0 && index % stride) {
  52102. thisCoord += step;
  52103. return;
  52104. } // FIXME
  52105. // Should consider axis.min/axis.max when drawing dataShadow.
  52106. // FIXME
  52107. // 应该使用统一的空判断?还是在list里进行空判断?
  52108. var isEmpty = value == null || isNaN(value) || value === ''; // See #4235.
  52109. var otherCoord = isEmpty ? 0 : linearMap$1(value, otherDataExtent, otherShadowExtent, true); // Attempt to draw data shadow precisely when there are empty value.
  52110. if (isEmpty && !lastIsEmpty && index) {
  52111. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  52112. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  52113. } else if (!isEmpty && lastIsEmpty) {
  52114. areaPoints.push([thisCoord, 0]);
  52115. linePoints.push([thisCoord, 0]);
  52116. }
  52117. areaPoints.push([thisCoord, otherCoord]);
  52118. linePoints.push([thisCoord, otherCoord]);
  52119. thisCoord += step;
  52120. lastIsEmpty = isEmpty;
  52121. });
  52122. var dataZoomModel = this.dataZoomModel; // var dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  52123. this._displayables.barGroup.add(new Polygon({
  52124. shape: {
  52125. points: areaPoints
  52126. },
  52127. style: defaults({
  52128. fill: dataZoomModel.get('dataBackgroundColor')
  52129. }, dataZoomModel.getModel('dataBackground.areaStyle').getAreaStyle()),
  52130. silent: true,
  52131. z2: -20
  52132. }));
  52133. this._displayables.barGroup.add(new Polyline({
  52134. shape: {
  52135. points: linePoints
  52136. },
  52137. style: dataZoomModel.getModel('dataBackground.lineStyle').getLineStyle(),
  52138. silent: true,
  52139. z2: -19
  52140. }));
  52141. },
  52142. _prepareDataShadowInfo: function () {
  52143. var dataZoomModel = this.dataZoomModel;
  52144. var showDataShadow = dataZoomModel.get('showDataShadow');
  52145. if (showDataShadow === false) {
  52146. return;
  52147. } // Find a representative series.
  52148. var result;
  52149. var ecModel = this.ecModel;
  52150. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  52151. var seriesModels = dataZoomModel.getAxisProxy(dimNames.name, axisIndex).getTargetSeriesModels();
  52152. each$1(seriesModels, function (seriesModel) {
  52153. if (result) {
  52154. return;
  52155. }
  52156. if (showDataShadow !== true && indexOf(SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')) < 0) {
  52157. return;
  52158. }
  52159. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  52160. var otherDim = getOtherDim(dimNames.name);
  52161. var otherAxisInverse;
  52162. var coordSys = seriesModel.coordinateSystem;
  52163. if (otherDim != null && coordSys.getOtherAxis) {
  52164. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  52165. }
  52166. otherDim = seriesModel.getData().mapDimension(otherDim);
  52167. result = {
  52168. thisAxis: thisAxis,
  52169. series: seriesModel,
  52170. thisDim: dimNames.name,
  52171. otherDim: otherDim,
  52172. otherAxisInverse: otherAxisInverse
  52173. };
  52174. }, this);
  52175. }, this);
  52176. return result;
  52177. },
  52178. _renderHandle: function () {
  52179. var displaybles = this._displayables;
  52180. var handles = displaybles.handles = [];
  52181. var handleLabels = displaybles.handleLabels = [];
  52182. var barGroup = this._displayables.barGroup;
  52183. var size = this._size;
  52184. var dataZoomModel = this.dataZoomModel;
  52185. barGroup.add(displaybles.filler = new Rect$1({
  52186. draggable: true,
  52187. cursor: getCursor(this._orient),
  52188. drift: bind$4(this._onDragMove, this, 'all'),
  52189. ondragstart: bind$4(this._showDataInfo, this, true),
  52190. ondragend: bind$4(this._onDragEnd, this),
  52191. onmouseover: bind$4(this._showDataInfo, this, true),
  52192. onmouseout: bind$4(this._showDataInfo, this, false),
  52193. style: {
  52194. fill: dataZoomModel.get('fillerColor'),
  52195. textPosition: 'inside'
  52196. }
  52197. })); // Frame border.
  52198. barGroup.add(new Rect$1({
  52199. silent: true,
  52200. subPixelOptimize: true,
  52201. shape: {
  52202. x: 0,
  52203. y: 0,
  52204. width: size[0],
  52205. height: size[1]
  52206. },
  52207. style: {
  52208. stroke: dataZoomModel.get('dataBackgroundColor') || dataZoomModel.get('borderColor'),
  52209. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  52210. fill: 'rgba(0,0,0,0)'
  52211. }
  52212. }));
  52213. each$16([0, 1], function (handleIndex) {
  52214. var path = createIcon(dataZoomModel.get('handleIcon'), {
  52215. cursor: getCursor(this._orient),
  52216. draggable: true,
  52217. drift: bind$4(this._onDragMove, this, handleIndex),
  52218. ondragend: bind$4(this._onDragEnd, this),
  52219. onmouseover: bind$4(this._showDataInfo, this, true),
  52220. onmouseout: bind$4(this._showDataInfo, this, false)
  52221. }, {
  52222. x: -1,
  52223. y: 0,
  52224. width: 2,
  52225. height: 2
  52226. });
  52227. var bRect = path.getBoundingRect();
  52228. this._handleHeight = parsePercent$1(dataZoomModel.get('handleSize'), this._size[1]);
  52229. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  52230. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  52231. var handleColor = dataZoomModel.get('handleColor'); // Compatitable with previous version
  52232. if (handleColor != null) {
  52233. path.style.fill = handleColor;
  52234. }
  52235. barGroup.add(handles[handleIndex] = path);
  52236. var textStyleModel = dataZoomModel.textStyleModel;
  52237. this.group.add(handleLabels[handleIndex] = new Text({
  52238. silent: true,
  52239. invisible: true,
  52240. style: {
  52241. x: 0,
  52242. y: 0,
  52243. text: '',
  52244. textVerticalAlign: 'middle',
  52245. textAlign: 'center',
  52246. textFill: textStyleModel.getTextColor(),
  52247. textFont: textStyleModel.getFont()
  52248. },
  52249. z2: 10
  52250. }));
  52251. }, this);
  52252. },
  52253. /**
  52254. * @private
  52255. */
  52256. _resetInterval: function () {
  52257. var range = this._range = this.dataZoomModel.getPercentRange();
  52258. var viewExtent = this._getViewExtent();
  52259. this._handleEnds = [linearMap$1(range[0], [0, 100], viewExtent, true), linearMap$1(range[1], [0, 100], viewExtent, true)];
  52260. },
  52261. /**
  52262. * @private
  52263. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  52264. * @param {number} delta
  52265. * @return {boolean} changed
  52266. */
  52267. _updateInterval: function (handleIndex, delta) {
  52268. var dataZoomModel = this.dataZoomModel;
  52269. var handleEnds = this._handleEnds;
  52270. var viewExtend = this._getViewExtent();
  52271. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  52272. var percentExtent = [0, 100];
  52273. sliderMove(delta, handleEnds, viewExtend, dataZoomModel.get('zoomLock') ? 'all' : handleIndex, minMaxSpan.minSpan != null ? linearMap$1(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null, minMaxSpan.maxSpan != null ? linearMap$1(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null);
  52274. var lastRange = this._range;
  52275. var range = this._range = asc$2([linearMap$1(handleEnds[0], viewExtend, percentExtent, true), linearMap$1(handleEnds[1], viewExtend, percentExtent, true)]);
  52276. return !lastRange || lastRange[0] !== range[0] || lastRange[1] !== range[1];
  52277. },
  52278. /**
  52279. * @private
  52280. */
  52281. _updateView: function (nonRealtime) {
  52282. var displaybles = this._displayables;
  52283. var handleEnds = this._handleEnds;
  52284. var handleInterval = asc$2(handleEnds.slice());
  52285. var size = this._size;
  52286. each$16([0, 1], function (handleIndex) {
  52287. // Handles
  52288. var handle = displaybles.handles[handleIndex];
  52289. var handleHeight = this._handleHeight;
  52290. handle.attr({
  52291. scale: [handleHeight / 2, handleHeight / 2],
  52292. position: [handleEnds[handleIndex], size[1] / 2 - handleHeight / 2]
  52293. });
  52294. }, this); // Filler
  52295. displaybles.filler.setShape({
  52296. x: handleInterval[0],
  52297. y: 0,
  52298. width: handleInterval[1] - handleInterval[0],
  52299. height: size[1]
  52300. });
  52301. this._updateDataInfo(nonRealtime);
  52302. },
  52303. /**
  52304. * @private
  52305. */
  52306. _updateDataInfo: function (nonRealtime) {
  52307. var dataZoomModel = this.dataZoomModel;
  52308. var displaybles = this._displayables;
  52309. var handleLabels = displaybles.handleLabels;
  52310. var orient = this._orient;
  52311. var labelTexts = ['', '']; // FIXME
  52312. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  52313. if (dataZoomModel.get('showDetail')) {
  52314. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  52315. if (axisProxy) {
  52316. var axis = axisProxy.getAxisModel().axis;
  52317. var range = this._range;
  52318. var dataInterval = nonRealtime // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  52319. ? axisProxy.calculateDataWindow({
  52320. start: range[0],
  52321. end: range[1]
  52322. }).valueWindow : axisProxy.getDataValueWindow();
  52323. labelTexts = [this._formatLabel(dataInterval[0], axis), this._formatLabel(dataInterval[1], axis)];
  52324. }
  52325. }
  52326. var orderedHandleEnds = asc$2(this._handleEnds.slice());
  52327. setLabel.call(this, 0);
  52328. setLabel.call(this, 1);
  52329. function setLabel(handleIndex) {
  52330. // Label
  52331. // Text should not transform by barGroup.
  52332. // Ignore handlers transform
  52333. var barTransform = getTransform(displaybles.handles[handleIndex].parent, this.group);
  52334. var direction = transformDirection(handleIndex === 0 ? 'right' : 'left', barTransform);
  52335. var offset = this._handleWidth / 2 + LABEL_GAP;
  52336. var textPoint = applyTransform$1([orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset), this._size[1] / 2], barTransform);
  52337. handleLabels[handleIndex].setStyle({
  52338. x: textPoint[0],
  52339. y: textPoint[1],
  52340. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  52341. textAlign: orient === HORIZONTAL ? direction : 'center',
  52342. text: labelTexts[handleIndex]
  52343. });
  52344. }
  52345. },
  52346. /**
  52347. * @private
  52348. */
  52349. _formatLabel: function (value, axis) {
  52350. var dataZoomModel = this.dataZoomModel;
  52351. var labelFormatter = dataZoomModel.get('labelFormatter');
  52352. var labelPrecision = dataZoomModel.get('labelPrecision');
  52353. if (labelPrecision == null || labelPrecision === 'auto') {
  52354. labelPrecision = axis.getPixelPrecision();
  52355. }
  52356. var valueStr = value == null || isNaN(value) ? '' // FIXME Glue code
  52357. : axis.type === 'category' || axis.type === 'time' ? axis.scale.getLabel(Math.round(value)) // param of toFixed should less then 20.
  52358. : value.toFixed(Math.min(labelPrecision, 20));
  52359. return isFunction$1(labelFormatter) ? labelFormatter(value, valueStr) : isString(labelFormatter) ? labelFormatter.replace('{value}', valueStr) : valueStr;
  52360. },
  52361. /**
  52362. * @private
  52363. * @param {boolean} showOrHide true: show, false: hide
  52364. */
  52365. _showDataInfo: function (showOrHide) {
  52366. // Always show when drgging.
  52367. showOrHide = this._dragging || showOrHide;
  52368. var handleLabels = this._displayables.handleLabels;
  52369. handleLabels[0].attr('invisible', !showOrHide);
  52370. handleLabels[1].attr('invisible', !showOrHide);
  52371. },
  52372. _onDragMove: function (handleIndex, dx, dy, event) {
  52373. this._dragging = true; // For mobile device, prevent screen slider on the button.
  52374. stop(event.event); // Transform dx, dy to bar coordination.
  52375. var barTransform = this._displayables.barGroup.getLocalTransform();
  52376. var vertex = applyTransform$1([dx, dy], barTransform, true);
  52377. var changed = this._updateInterval(handleIndex, vertex[0]);
  52378. var realtime = this.dataZoomModel.get('realtime');
  52379. this._updateView(!realtime); // Avoid dispatch dataZoom repeatly but range not changed,
  52380. // which cause bad visual effect when progressive enabled.
  52381. changed && realtime && this._dispatchZoomAction();
  52382. },
  52383. _onDragEnd: function () {
  52384. this._dragging = false;
  52385. this._showDataInfo(false); // While in realtime mode and stream mode, dispatch action when
  52386. // drag end will cause the whole view rerender, which is unnecessary.
  52387. var realtime = this.dataZoomModel.get('realtime');
  52388. !realtime && this._dispatchZoomAction();
  52389. },
  52390. _onClickPanelClick: function (e) {
  52391. var size = this._size;
  52392. var localPoint = this._displayables.barGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  52393. if (localPoint[0] < 0 || localPoint[0] > size[0] || localPoint[1] < 0 || localPoint[1] > size[1]) {
  52394. return;
  52395. }
  52396. var handleEnds = this._handleEnds;
  52397. var center = (handleEnds[0] + handleEnds[1]) / 2;
  52398. var changed = this._updateInterval('all', localPoint[0] - center);
  52399. this._updateView();
  52400. changed && this._dispatchZoomAction();
  52401. },
  52402. /**
  52403. * This action will be throttled.
  52404. * @private
  52405. */
  52406. _dispatchZoomAction: function () {
  52407. var range = this._range;
  52408. this.api.dispatchAction({
  52409. type: 'dataZoom',
  52410. from: this.uid,
  52411. dataZoomId: this.dataZoomModel.id,
  52412. start: range[0],
  52413. end: range[1]
  52414. });
  52415. },
  52416. /**
  52417. * @private
  52418. */
  52419. _findCoordRect: function () {
  52420. // Find the grid coresponding to the first axis referred by dataZoom.
  52421. var rect;
  52422. each$16(this.getTargetCoordInfo(), function (coordInfoList) {
  52423. if (!rect && coordInfoList.length) {
  52424. var coordSys = coordInfoList[0].model.coordinateSystem;
  52425. rect = coordSys.getRect && coordSys.getRect();
  52426. }
  52427. });
  52428. if (!rect) {
  52429. var width = this.api.getWidth();
  52430. var height = this.api.getHeight();
  52431. rect = {
  52432. x: width * 0.2,
  52433. y: height * 0.2,
  52434. width: width * 0.6,
  52435. height: height * 0.6
  52436. };
  52437. }
  52438. return rect;
  52439. }
  52440. });
  52441. function getOtherDim(thisDim) {
  52442. // FIXME
  52443. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  52444. var map$$1 = {
  52445. x: 'y',
  52446. y: 'x',
  52447. radius: 'angle',
  52448. angle: 'radius'
  52449. };
  52450. return map$$1[thisDim];
  52451. }
  52452. function getCursor(orient) {
  52453. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  52454. }
  52455. /*
  52456. * Licensed to the Apache Software Foundation (ASF) under one
  52457. * or more contributor license agreements. See the NOTICE file
  52458. * distributed with this work for additional information
  52459. * regarding copyright ownership. The ASF licenses this file
  52460. * to you under the Apache License, Version 2.0 (the
  52461. * "License"); you may not use this file except in compliance
  52462. * with the License. You may obtain a copy of the License at
  52463. *
  52464. * http://www.apache.org/licenses/LICENSE-2.0
  52465. *
  52466. * Unless required by applicable law or agreed to in writing,
  52467. * software distributed under the License is distributed on an
  52468. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52469. * KIND, either express or implied. See the License for the
  52470. * specific language governing permissions and limitations
  52471. * under the License.
  52472. */
  52473. registerProcessor({
  52474. // `dataZoomProcessor` will only be performed in needed series. Consider if
  52475. // there is a line series and a pie series, it is better not to update the
  52476. // line series if only pie series is needed to be updated.
  52477. getTargetSeries: function (ecModel) {
  52478. var seriesModelMap = createHashMap();
  52479. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  52480. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  52481. var axisProxy = dataZoomModel.getAxisProxy(dimNames.name, axisIndex);
  52482. each$1(axisProxy.getTargetSeriesModels(), function (seriesModel) {
  52483. seriesModelMap.set(seriesModel.uid, seriesModel);
  52484. });
  52485. });
  52486. });
  52487. return seriesModelMap;
  52488. },
  52489. modifyOutputEnd: true,
  52490. // Consider appendData, where filter should be performed. Because data process is
  52491. // in block mode currently, it is not need to worry about that the overallProgress
  52492. // execute every frame.
  52493. overallReset: function (ecModel, api) {
  52494. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  52495. // We calculate window and reset axis here but not in model
  52496. // init stage and not after action dispatch handler, because
  52497. // reset should be called after seriesData.restoreData.
  52498. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  52499. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel, api);
  52500. }); // Caution: data zoom filtering is order sensitive when using
  52501. // percent range and no min/max/scale set on axis.
  52502. // For example, we have dataZoom definition:
  52503. // [
  52504. // {xAxisIndex: 0, start: 30, end: 70},
  52505. // {yAxisIndex: 0, start: 20, end: 80}
  52506. // ]
  52507. // In this case, [20, 80] of y-dataZoom should be based on data
  52508. // that have filtered by x-dataZoom using range of [30, 70],
  52509. // but should not be based on full raw data. Thus sliding
  52510. // x-dataZoom will change both ranges of xAxis and yAxis,
  52511. // while sliding y-dataZoom will only change the range of yAxis.
  52512. // So we should filter x-axis after reset x-axis immediately,
  52513. // and then reset y-axis and filter y-axis.
  52514. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  52515. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel, api);
  52516. });
  52517. });
  52518. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  52519. // Fullfill all of the range props so that user
  52520. // is able to get them from chart.getOption().
  52521. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  52522. var percentRange = axisProxy.getDataPercentWindow();
  52523. var valueRange = axisProxy.getDataValueWindow();
  52524. dataZoomModel.setCalculatedRange({
  52525. start: percentRange[0],
  52526. end: percentRange[1],
  52527. startValue: valueRange[0],
  52528. endValue: valueRange[1]
  52529. });
  52530. });
  52531. }
  52532. });
  52533. /*
  52534. * Licensed to the Apache Software Foundation (ASF) under one
  52535. * or more contributor license agreements. See the NOTICE file
  52536. * distributed with this work for additional information
  52537. * regarding copyright ownership. The ASF licenses this file
  52538. * to you under the Apache License, Version 2.0 (the
  52539. * "License"); you may not use this file except in compliance
  52540. * with the License. You may obtain a copy of the License at
  52541. *
  52542. * http://www.apache.org/licenses/LICENSE-2.0
  52543. *
  52544. * Unless required by applicable law or agreed to in writing,
  52545. * software distributed under the License is distributed on an
  52546. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52547. * KIND, either express or implied. See the License for the
  52548. * specific language governing permissions and limitations
  52549. * under the License.
  52550. */
  52551. registerAction('dataZoom', function (payload, ecModel) {
  52552. var linkedNodesFinder = createLinkedNodesFinder(bind(ecModel.eachComponent, ecModel, 'dataZoom'), eachAxisDim$1, function (model, dimNames) {
  52553. return model.get(dimNames.axisIndex);
  52554. });
  52555. var effectedModels = [];
  52556. ecModel.eachComponent({
  52557. mainType: 'dataZoom',
  52558. query: payload
  52559. }, function (model, index) {
  52560. effectedModels.push.apply(effectedModels, linkedNodesFinder(model).nodes);
  52561. });
  52562. each$1(effectedModels, function (dataZoomModel, index) {
  52563. dataZoomModel.setRawRange({
  52564. start: payload.start,
  52565. end: payload.end,
  52566. startValue: payload.startValue,
  52567. endValue: payload.endValue
  52568. });
  52569. });
  52570. });
  52571. /*
  52572. * Licensed to the Apache Software Foundation (ASF) under one
  52573. * or more contributor license agreements. See the NOTICE file
  52574. * distributed with this work for additional information
  52575. * regarding copyright ownership. The ASF licenses this file
  52576. * to you under the Apache License, Version 2.0 (the
  52577. * "License"); you may not use this file except in compliance
  52578. * with the License. You may obtain a copy of the License at
  52579. *
  52580. * http://www.apache.org/licenses/LICENSE-2.0
  52581. *
  52582. * Unless required by applicable law or agreed to in writing,
  52583. * software distributed under the License is distributed on an
  52584. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52585. * KIND, either express or implied. See the License for the
  52586. * specific language governing permissions and limitations
  52587. * under the License.
  52588. */
  52589. /*
  52590. * Licensed to the Apache Software Foundation (ASF) under one
  52591. * or more contributor license agreements. See the NOTICE file
  52592. * distributed with this work for additional information
  52593. * regarding copyright ownership. The ASF licenses this file
  52594. * to you under the Apache License, Version 2.0 (the
  52595. * "License"); you may not use this file except in compliance
  52596. * with the License. You may obtain a copy of the License at
  52597. *
  52598. * http://www.apache.org/licenses/LICENSE-2.0
  52599. *
  52600. * Unless required by applicable law or agreed to in writing,
  52601. * software distributed under the License is distributed on an
  52602. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52603. * KIND, either express or implied. See the License for the
  52604. * specific language governing permissions and limitations
  52605. * under the License.
  52606. */
  52607. DataZoomModel.extend({
  52608. type: 'dataZoom.inside',
  52609. /**
  52610. * @protected
  52611. */
  52612. defaultOption: {
  52613. disabled: false,
  52614. // Whether disable this inside zoom.
  52615. zoomLock: false,
  52616. // Whether disable zoom but only pan.
  52617. zoomOnMouseWheel: true,
  52618. // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  52619. moveOnMouseMove: true,
  52620. // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  52621. moveOnMouseWheel: false,
  52622. // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  52623. preventDefaultMouseMove: true
  52624. }
  52625. });
  52626. /*
  52627. * Licensed to the Apache Software Foundation (ASF) under one
  52628. * or more contributor license agreements. See the NOTICE file
  52629. * distributed with this work for additional information
  52630. * regarding copyright ownership. The ASF licenses this file
  52631. * to you under the Apache License, Version 2.0 (the
  52632. * "License"); you may not use this file except in compliance
  52633. * with the License. You may obtain a copy of the License at
  52634. *
  52635. * http://www.apache.org/licenses/LICENSE-2.0
  52636. *
  52637. * Unless required by applicable law or agreed to in writing,
  52638. * software distributed under the License is distributed on an
  52639. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52640. * KIND, either express or implied. See the License for the
  52641. * specific language governing permissions and limitations
  52642. * under the License.
  52643. */
  52644. // Only create one roam controller for each coordinate system.
  52645. // one roam controller might be refered by two inside data zoom
  52646. // components (for example, one for x and one for y). When user
  52647. // pan or zoom, only dispatch one action for those data zoom
  52648. // components.
  52649. var ATTR$1 = '\0_ec_dataZoom_roams';
  52650. /**
  52651. * @public
  52652. * @param {module:echarts/ExtensionAPI} api
  52653. * @param {Object} dataZoomInfo
  52654. * @param {string} dataZoomInfo.coordId
  52655. * @param {Function} dataZoomInfo.containsPoint
  52656. * @param {Array.<string>} dataZoomInfo.allCoordIds
  52657. * @param {string} dataZoomInfo.dataZoomId
  52658. * @param {Object} dataZoomInfo.getRange
  52659. * @param {Function} dataZoomInfo.getRange.pan
  52660. * @param {Function} dataZoomInfo.getRange.zoom
  52661. * @param {Function} dataZoomInfo.getRange.scrollMove
  52662. * @param {boolean} dataZoomInfo.dataZoomModel
  52663. */
  52664. function register$1(api, dataZoomInfo) {
  52665. var store = giveStore(api);
  52666. var theDataZoomId = dataZoomInfo.dataZoomId;
  52667. var theCoordId = dataZoomInfo.coordId; // Do clean when a dataZoom changes its target coordnate system.
  52668. // Avoid memory leak, dispose all not-used-registered.
  52669. each$1(store, function (record, coordId) {
  52670. var dataZoomInfos = record.dataZoomInfos;
  52671. if (dataZoomInfos[theDataZoomId] && indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0) {
  52672. delete dataZoomInfos[theDataZoomId];
  52673. record.count--;
  52674. }
  52675. });
  52676. cleanStore(store);
  52677. var record = store[theCoordId]; // Create if needed.
  52678. if (!record) {
  52679. record = store[theCoordId] = {
  52680. coordId: theCoordId,
  52681. dataZoomInfos: {},
  52682. count: 0
  52683. };
  52684. record.controller = createController(api, record);
  52685. record.dispatchAction = curry(dispatchAction, api);
  52686. } // Update reference of dataZoom.
  52687. !record.dataZoomInfos[theDataZoomId] && record.count++;
  52688. record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
  52689. var controllerParams = mergeControllerParams(record.dataZoomInfos);
  52690. record.controller.enable(controllerParams.controlType, controllerParams.opt); // Consider resize, area should be always updated.
  52691. record.controller.setPointerChecker(dataZoomInfo.containsPoint); // Update throttle.
  52692. createOrUpdate(record, 'dispatchAction', dataZoomInfo.dataZoomModel.get('throttle', true), 'fixRate');
  52693. }
  52694. /**
  52695. * @public
  52696. * @param {module:echarts/ExtensionAPI} api
  52697. * @param {string} dataZoomId
  52698. */
  52699. function unregister$1(api, dataZoomId) {
  52700. var store = giveStore(api);
  52701. each$1(store, function (record) {
  52702. record.controller.dispose();
  52703. var dataZoomInfos = record.dataZoomInfos;
  52704. if (dataZoomInfos[dataZoomId]) {
  52705. delete dataZoomInfos[dataZoomId];
  52706. record.count--;
  52707. }
  52708. });
  52709. cleanStore(store);
  52710. }
  52711. /**
  52712. * @public
  52713. */
  52714. function generateCoordId(coordModel) {
  52715. return coordModel.type + '\0_' + coordModel.id;
  52716. }
  52717. /**
  52718. * Key: coordId, value: {dataZoomInfos: [], count, controller}
  52719. * @type {Array.<Object>}
  52720. */
  52721. function giveStore(api) {
  52722. // Mount store on zrender instance, so that we do not
  52723. // need to worry about dispose.
  52724. var zr = api.getZr();
  52725. return zr[ATTR$1] || (zr[ATTR$1] = {});
  52726. }
  52727. function createController(api, newRecord) {
  52728. var controller = new RoamController(api.getZr());
  52729. each$1(['pan', 'zoom', 'scrollMove'], function (eventName) {
  52730. controller.on(eventName, function (event) {
  52731. var batch = [];
  52732. each$1(newRecord.dataZoomInfos, function (info) {
  52733. // Check whether the behaviors (zoomOnMouseWheel, moveOnMouseMove,
  52734. // moveOnMouseWheel, ...) enabled.
  52735. if (!event.isAvailableBehavior(info.dataZoomModel.option)) {
  52736. return;
  52737. }
  52738. var method = (info.getRange || {})[eventName];
  52739. var range = method && method(newRecord.controller, event);
  52740. !info.dataZoomModel.get('disabled', true) && range && batch.push({
  52741. dataZoomId: info.dataZoomId,
  52742. start: range[0],
  52743. end: range[1]
  52744. });
  52745. });
  52746. batch.length && newRecord.dispatchAction(batch);
  52747. });
  52748. });
  52749. return controller;
  52750. }
  52751. function cleanStore(store) {
  52752. each$1(store, function (record, coordId) {
  52753. if (!record.count) {
  52754. record.controller.dispose();
  52755. delete store[coordId];
  52756. }
  52757. });
  52758. }
  52759. /**
  52760. * This action will be throttled.
  52761. */
  52762. function dispatchAction(api, batch) {
  52763. api.dispatchAction({
  52764. type: 'dataZoom',
  52765. batch: batch
  52766. });
  52767. }
  52768. /**
  52769. * Merge roamController settings when multiple dataZooms share one roamController.
  52770. */
  52771. function mergeControllerParams(dataZoomInfos) {
  52772. var controlType; // DO NOT use reserved word (true, false, undefined) as key literally. Even if encapsulated
  52773. // as string, it is probably revert to reserved word by compress tool. See #7411.
  52774. var prefix = 'type_';
  52775. var typePriority = {
  52776. 'type_true': 2,
  52777. 'type_move': 1,
  52778. 'type_false': 0,
  52779. 'type_undefined': -1
  52780. };
  52781. var preventDefaultMouseMove = true;
  52782. each$1(dataZoomInfos, function (dataZoomInfo) {
  52783. var dataZoomModel = dataZoomInfo.dataZoomModel;
  52784. var oneType = dataZoomModel.get('disabled', true) ? false : dataZoomModel.get('zoomLock', true) ? 'move' : true;
  52785. if (typePriority[prefix + oneType] > typePriority[prefix + controlType]) {
  52786. controlType = oneType;
  52787. } // Prevent default move event by default. If one false, do not prevent. Otherwise
  52788. // users may be confused why it does not work when multiple insideZooms exist.
  52789. preventDefaultMouseMove &= dataZoomModel.get('preventDefaultMouseMove', true);
  52790. });
  52791. return {
  52792. controlType: controlType,
  52793. opt: {
  52794. // RoamController will enable all of these functionalities,
  52795. // and the final behavior is determined by its event listener
  52796. // provided by each inside zoom.
  52797. zoomOnMouseWheel: true,
  52798. moveOnMouseMove: true,
  52799. moveOnMouseWheel: true,
  52800. preventDefaultMouseMove: !!preventDefaultMouseMove
  52801. }
  52802. };
  52803. }
  52804. /*
  52805. * Licensed to the Apache Software Foundation (ASF) under one
  52806. * or more contributor license agreements. See the NOTICE file
  52807. * distributed with this work for additional information
  52808. * regarding copyright ownership. The ASF licenses this file
  52809. * to you under the Apache License, Version 2.0 (the
  52810. * "License"); you may not use this file except in compliance
  52811. * with the License. You may obtain a copy of the License at
  52812. *
  52813. * http://www.apache.org/licenses/LICENSE-2.0
  52814. *
  52815. * Unless required by applicable law or agreed to in writing,
  52816. * software distributed under the License is distributed on an
  52817. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52818. * KIND, either express or implied. See the License for the
  52819. * specific language governing permissions and limitations
  52820. * under the License.
  52821. */
  52822. var bind$5 = bind;
  52823. var InsideZoomView = DataZoomView.extend({
  52824. type: 'dataZoom.inside',
  52825. /**
  52826. * @override
  52827. */
  52828. init: function (ecModel, api) {
  52829. /**
  52830. * 'throttle' is used in this.dispatchAction, so we save range
  52831. * to avoid missing some 'pan' info.
  52832. * @private
  52833. * @type {Array.<number>}
  52834. */
  52835. this._range;
  52836. },
  52837. /**
  52838. * @override
  52839. */
  52840. render: function (dataZoomModel, ecModel, api, payload) {
  52841. InsideZoomView.superApply(this, 'render', arguments); // Hence the `throttle` util ensures to preserve command order,
  52842. // here simply updating range all the time will not cause missing
  52843. // any of the the roam change.
  52844. this._range = dataZoomModel.getPercentRange(); // Reset controllers.
  52845. each$1(this.getTargetCoordInfo(), function (coordInfoList, coordSysName) {
  52846. var allCoordIds = map(coordInfoList, function (coordInfo) {
  52847. return generateCoordId(coordInfo.model);
  52848. });
  52849. each$1(coordInfoList, function (coordInfo) {
  52850. var coordModel = coordInfo.model;
  52851. var getRange = {};
  52852. each$1(['pan', 'zoom', 'scrollMove'], function (eventName) {
  52853. getRange[eventName] = bind$5(roamHandlers[eventName], this, coordInfo, coordSysName);
  52854. }, this);
  52855. register$1(api, {
  52856. coordId: generateCoordId(coordModel),
  52857. allCoordIds: allCoordIds,
  52858. containsPoint: function (e, x, y) {
  52859. return coordModel.coordinateSystem.containPoint([x, y]);
  52860. },
  52861. dataZoomId: dataZoomModel.id,
  52862. dataZoomModel: dataZoomModel,
  52863. getRange: getRange
  52864. });
  52865. }, this);
  52866. }, this);
  52867. },
  52868. /**
  52869. * @override
  52870. */
  52871. dispose: function () {
  52872. unregister$1(this.api, this.dataZoomModel.id);
  52873. InsideZoomView.superApply(this, 'dispose', arguments);
  52874. this._range = null;
  52875. }
  52876. });
  52877. var roamHandlers = {
  52878. /**
  52879. * @this {module:echarts/component/dataZoom/InsideZoomView}
  52880. */
  52881. zoom: function (coordInfo, coordSysName, controller, e) {
  52882. var lastRange = this._range;
  52883. var range = lastRange.slice(); // Calculate transform by the first axis.
  52884. var axisModel = coordInfo.axisModels[0];
  52885. if (!axisModel) {
  52886. return;
  52887. }
  52888. var directionInfo = getDirectionInfo[coordSysName](null, [e.originX, e.originY], axisModel, controller, coordInfo);
  52889. var percentPoint = (directionInfo.signal > 0 ? directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel : directionInfo.pixel - directionInfo.pixelStart) / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  52890. var scale = Math.max(1 / e.scale, 0);
  52891. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  52892. range[1] = (range[1] - percentPoint) * scale + percentPoint; // Restrict range.
  52893. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  52894. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  52895. this._range = range;
  52896. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  52897. return range;
  52898. }
  52899. },
  52900. /**
  52901. * @this {module:echarts/component/dataZoom/InsideZoomView}
  52902. */
  52903. pan: makeMover(function (range, axisModel, coordInfo, coordSysName, controller, e) {
  52904. var directionInfo = getDirectionInfo[coordSysName]([e.oldX, e.oldY], [e.newX, e.newY], axisModel, controller, coordInfo);
  52905. return directionInfo.signal * (range[1] - range[0]) * directionInfo.pixel / directionInfo.pixelLength;
  52906. }),
  52907. /**
  52908. * @this {module:echarts/component/dataZoom/InsideZoomView}
  52909. */
  52910. scrollMove: makeMover(function (range, axisModel, coordInfo, coordSysName, controller, e) {
  52911. var directionInfo = getDirectionInfo[coordSysName]([0, 0], [e.scrollDelta, e.scrollDelta], axisModel, controller, coordInfo);
  52912. return directionInfo.signal * (range[1] - range[0]) * e.scrollDelta;
  52913. })
  52914. };
  52915. function makeMover(getPercentDelta) {
  52916. return function (coordInfo, coordSysName, controller, e) {
  52917. var lastRange = this._range;
  52918. var range = lastRange.slice(); // Calculate transform by the first axis.
  52919. var axisModel = coordInfo.axisModels[0];
  52920. if (!axisModel) {
  52921. return;
  52922. }
  52923. var percentDelta = getPercentDelta(range, axisModel, coordInfo, coordSysName, controller, e);
  52924. sliderMove(percentDelta, range, [0, 100], 'all');
  52925. this._range = range;
  52926. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  52927. return range;
  52928. }
  52929. };
  52930. }
  52931. var getDirectionInfo = {
  52932. grid: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  52933. var axis = axisModel.axis;
  52934. var ret = {};
  52935. var rect = coordInfo.model.coordinateSystem.getRect();
  52936. oldPoint = oldPoint || [0, 0];
  52937. if (axis.dim === 'x') {
  52938. ret.pixel = newPoint[0] - oldPoint[0];
  52939. ret.pixelLength = rect.width;
  52940. ret.pixelStart = rect.x;
  52941. ret.signal = axis.inverse ? 1 : -1;
  52942. } else {
  52943. // axis.dim === 'y'
  52944. ret.pixel = newPoint[1] - oldPoint[1];
  52945. ret.pixelLength = rect.height;
  52946. ret.pixelStart = rect.y;
  52947. ret.signal = axis.inverse ? -1 : 1;
  52948. }
  52949. return ret;
  52950. },
  52951. polar: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  52952. var axis = axisModel.axis;
  52953. var ret = {};
  52954. var polar = coordInfo.model.coordinateSystem;
  52955. var radiusExtent = polar.getRadiusAxis().getExtent();
  52956. var angleExtent = polar.getAngleAxis().getExtent();
  52957. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  52958. newPoint = polar.pointToCoord(newPoint);
  52959. if (axisModel.mainType === 'radiusAxis') {
  52960. ret.pixel = newPoint[0] - oldPoint[0]; // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  52961. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  52962. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  52963. ret.pixelStart = radiusExtent[0];
  52964. ret.signal = axis.inverse ? 1 : -1;
  52965. } else {
  52966. // 'angleAxis'
  52967. ret.pixel = newPoint[1] - oldPoint[1]; // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  52968. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  52969. ret.pixelLength = angleExtent[1] - angleExtent[0];
  52970. ret.pixelStart = angleExtent[0];
  52971. ret.signal = axis.inverse ? -1 : 1;
  52972. }
  52973. return ret;
  52974. },
  52975. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  52976. var axis = axisModel.axis;
  52977. var rect = coordInfo.model.coordinateSystem.getRect();
  52978. var ret = {};
  52979. oldPoint = oldPoint || [0, 0];
  52980. if (axis.orient === 'horizontal') {
  52981. ret.pixel = newPoint[0] - oldPoint[0];
  52982. ret.pixelLength = rect.width;
  52983. ret.pixelStart = rect.x;
  52984. ret.signal = axis.inverse ? 1 : -1;
  52985. } else {
  52986. // 'vertical'
  52987. ret.pixel = newPoint[1] - oldPoint[1];
  52988. ret.pixelLength = rect.height;
  52989. ret.pixelStart = rect.y;
  52990. ret.signal = axis.inverse ? -1 : 1;
  52991. }
  52992. return ret;
  52993. }
  52994. };
  52995. /*
  52996. * Licensed to the Apache Software Foundation (ASF) under one
  52997. * or more contributor license agreements. See the NOTICE file
  52998. * distributed with this work for additional information
  52999. * regarding copyright ownership. The ASF licenses this file
  53000. * to you under the Apache License, Version 2.0 (the
  53001. * "License"); you may not use this file except in compliance
  53002. * with the License. You may obtain a copy of the License at
  53003. *
  53004. * http://www.apache.org/licenses/LICENSE-2.0
  53005. *
  53006. * Unless required by applicable law or agreed to in writing,
  53007. * software distributed under the License is distributed on an
  53008. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53009. * KIND, either express or implied. See the License for the
  53010. * specific language governing permissions and limitations
  53011. * under the License.
  53012. */
  53013. /*
  53014. * Licensed to the Apache Software Foundation (ASF) under one
  53015. * or more contributor license agreements. See the NOTICE file
  53016. * distributed with this work for additional information
  53017. * regarding copyright ownership. The ASF licenses this file
  53018. * to you under the Apache License, Version 2.0 (the
  53019. * "License"); you may not use this file except in compliance
  53020. * with the License. You may obtain a copy of the License at
  53021. *
  53022. * http://www.apache.org/licenses/LICENSE-2.0
  53023. *
  53024. * Unless required by applicable law or agreed to in writing,
  53025. * software distributed under the License is distributed on an
  53026. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53027. * KIND, either express or implied. See the License for the
  53028. * specific language governing permissions and limitations
  53029. * under the License.
  53030. */
  53031. // Do not include './dataZoomSelect',
  53032. // since it only work for toolbox dataZoom.
  53033. /*
  53034. * Licensed to the Apache Software Foundation (ASF) under one
  53035. * or more contributor license agreements. See the NOTICE file
  53036. * distributed with this work for additional information
  53037. * regarding copyright ownership. The ASF licenses this file
  53038. * to you under the Apache License, Version 2.0 (the
  53039. * "License"); you may not use this file except in compliance
  53040. * with the License. You may obtain a copy of the License at
  53041. *
  53042. * http://www.apache.org/licenses/LICENSE-2.0
  53043. *
  53044. * Unless required by applicable law or agreed to in writing,
  53045. * software distributed under the License is distributed on an
  53046. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53047. * KIND, either express or implied. See the License for the
  53048. * specific language governing permissions and limitations
  53049. * under the License.
  53050. */
  53051. var features = {};
  53052. function register$2(name, ctor) {
  53053. features[name] = ctor;
  53054. }
  53055. function get$1(name) {
  53056. return features[name];
  53057. }
  53058. /*
  53059. * Licensed to the Apache Software Foundation (ASF) under one
  53060. * or more contributor license agreements. See the NOTICE file
  53061. * distributed with this work for additional information
  53062. * regarding copyright ownership. The ASF licenses this file
  53063. * to you under the Apache License, Version 2.0 (the
  53064. * "License"); you may not use this file except in compliance
  53065. * with the License. You may obtain a copy of the License at
  53066. *
  53067. * http://www.apache.org/licenses/LICENSE-2.0
  53068. *
  53069. * Unless required by applicable law or agreed to in writing,
  53070. * software distributed under the License is distributed on an
  53071. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53072. * KIND, either express or implied. See the License for the
  53073. * specific language governing permissions and limitations
  53074. * under the License.
  53075. */
  53076. var ToolboxModel = extendComponentModel({
  53077. type: 'toolbox',
  53078. layoutMode: {
  53079. type: 'box',
  53080. ignoreSize: true
  53081. },
  53082. optionUpdated: function () {
  53083. ToolboxModel.superApply(this, 'optionUpdated', arguments);
  53084. each$1(this.option.feature, function (featureOpt, featureName) {
  53085. var Feature = get$1(featureName);
  53086. Feature && merge(featureOpt, Feature.defaultOption);
  53087. });
  53088. },
  53089. defaultOption: {
  53090. show: true,
  53091. z: 6,
  53092. zlevel: 0,
  53093. orient: 'horizontal',
  53094. left: 'right',
  53095. top: 'top',
  53096. // right
  53097. // bottom
  53098. backgroundColor: 'transparent',
  53099. borderColor: '#ccc',
  53100. borderRadius: 0,
  53101. borderWidth: 0,
  53102. padding: 5,
  53103. itemSize: 15,
  53104. itemGap: 8,
  53105. showTitle: true,
  53106. iconStyle: {
  53107. borderColor: '#666',
  53108. color: 'none'
  53109. },
  53110. emphasis: {
  53111. iconStyle: {
  53112. borderColor: '#3E98C5'
  53113. }
  53114. },
  53115. // textStyle: {},
  53116. // feature
  53117. tooltip: {
  53118. show: false
  53119. }
  53120. }
  53121. });
  53122. /*
  53123. * Licensed to the Apache Software Foundation (ASF) under one
  53124. * or more contributor license agreements. See the NOTICE file
  53125. * distributed with this work for additional information
  53126. * regarding copyright ownership. The ASF licenses this file
  53127. * to you under the Apache License, Version 2.0 (the
  53128. * "License"); you may not use this file except in compliance
  53129. * with the License. You may obtain a copy of the License at
  53130. *
  53131. * http://www.apache.org/licenses/LICENSE-2.0
  53132. *
  53133. * Unless required by applicable law or agreed to in writing,
  53134. * software distributed under the License is distributed on an
  53135. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53136. * KIND, either express or implied. See the License for the
  53137. * specific language governing permissions and limitations
  53138. * under the License.
  53139. */
  53140. extendComponentView({
  53141. type: 'toolbox',
  53142. render: function (toolboxModel, ecModel, api, payload) {
  53143. var group = this.group;
  53144. group.removeAll();
  53145. if (!toolboxModel.get('show')) {
  53146. return;
  53147. }
  53148. var itemSize = +toolboxModel.get('itemSize');
  53149. var featureOpts = toolboxModel.get('feature') || {};
  53150. var features = this._features || (this._features = {});
  53151. var featureNames = [];
  53152. each$1(featureOpts, function (opt, name) {
  53153. featureNames.push(name);
  53154. });
  53155. new DataDiffer(this._featureNames || [], featureNames).add(processFeature).update(processFeature).remove(curry(processFeature, null)).execute(); // Keep for diff.
  53156. this._featureNames = featureNames;
  53157. function processFeature(newIndex, oldIndex) {
  53158. var featureName = featureNames[newIndex];
  53159. var oldName = featureNames[oldIndex];
  53160. var featureOpt = featureOpts[featureName];
  53161. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  53162. var feature; // FIX#11236, merge feature title from MagicType newOption. TODO: consider seriesIndex ?
  53163. if (payload && payload.newTitle != null && payload.featureName === featureName) {
  53164. featureOpt.title = payload.newTitle;
  53165. }
  53166. if (featureName && !oldName) {
  53167. // Create
  53168. if (isUserFeatureName(featureName)) {
  53169. feature = {
  53170. model: featureModel,
  53171. onclick: featureModel.option.onclick,
  53172. featureName: featureName
  53173. };
  53174. } else {
  53175. var Feature = get$1(featureName);
  53176. if (!Feature) {
  53177. return;
  53178. }
  53179. feature = new Feature(featureModel, ecModel, api);
  53180. }
  53181. features[featureName] = feature;
  53182. } else {
  53183. feature = features[oldName]; // If feature does not exsit.
  53184. if (!feature) {
  53185. return;
  53186. }
  53187. feature.model = featureModel;
  53188. feature.ecModel = ecModel;
  53189. feature.api = api;
  53190. }
  53191. if (!featureName && oldName) {
  53192. feature.dispose && feature.dispose(ecModel, api);
  53193. return;
  53194. }
  53195. if (!featureModel.get('show') || feature.unusable) {
  53196. feature.remove && feature.remove(ecModel, api);
  53197. return;
  53198. }
  53199. createIconPaths(featureModel, feature, featureName);
  53200. featureModel.setIconStatus = function (iconName, status) {
  53201. var option = this.option;
  53202. var iconPaths = this.iconPaths;
  53203. option.iconStatus = option.iconStatus || {};
  53204. option.iconStatus[iconName] = status; // FIXME
  53205. iconPaths[iconName] && iconPaths[iconName].trigger(status);
  53206. };
  53207. if (feature.render) {
  53208. feature.render(featureModel, ecModel, api, payload);
  53209. }
  53210. }
  53211. function createIconPaths(featureModel, feature, featureName) {
  53212. var iconStyleModel = featureModel.getModel('iconStyle');
  53213. var iconStyleEmphasisModel = featureModel.getModel('emphasis.iconStyle'); // If one feature has mutiple icon. they are orginaized as
  53214. // {
  53215. // icon: {
  53216. // foo: '',
  53217. // bar: ''
  53218. // },
  53219. // title: {
  53220. // foo: '',
  53221. // bar: ''
  53222. // }
  53223. // }
  53224. var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  53225. var titles = featureModel.get('title') || {};
  53226. if (typeof icons === 'string') {
  53227. var icon = icons;
  53228. var title = titles;
  53229. icons = {};
  53230. titles = {};
  53231. icons[featureName] = icon;
  53232. titles[featureName] = title;
  53233. }
  53234. var iconPaths = featureModel.iconPaths = {};
  53235. each$1(icons, function (iconStr, iconName) {
  53236. var path = createIcon(iconStr, {}, {
  53237. x: -itemSize / 2,
  53238. y: -itemSize / 2,
  53239. width: itemSize,
  53240. height: itemSize
  53241. });
  53242. path.setStyle(iconStyleModel.getItemStyle());
  53243. path.hoverStyle = iconStyleEmphasisModel.getItemStyle(); // Text position calculation
  53244. path.setStyle({
  53245. text: titles[iconName],
  53246. textAlign: iconStyleEmphasisModel.get('textAlign'),
  53247. textBorderRadius: iconStyleEmphasisModel.get('textBorderRadius'),
  53248. textPadding: iconStyleEmphasisModel.get('textPadding'),
  53249. textFill: null
  53250. });
  53251. var tooltipModel = toolboxModel.getModel('tooltip');
  53252. if (tooltipModel && tooltipModel.get('show')) {
  53253. path.attr('tooltip', extend({
  53254. content: titles[iconName],
  53255. formatter: tooltipModel.get('formatter', true) || function () {
  53256. return titles[iconName];
  53257. },
  53258. formatterParams: {
  53259. componentType: 'toolbox',
  53260. name: iconName,
  53261. title: titles[iconName],
  53262. $vars: ['name', 'title']
  53263. },
  53264. position: tooltipModel.get('position', true) || 'bottom'
  53265. }, tooltipModel.option));
  53266. }
  53267. setHoverStyle(path);
  53268. if (toolboxModel.get('showTitle')) {
  53269. path.__title = titles[iconName];
  53270. path.on('mouseover', function () {
  53271. // Should not reuse above hoverStyle, which might be modified.
  53272. var hoverStyle = iconStyleEmphasisModel.getItemStyle();
  53273. var defaultTextPosition = toolboxModel.get('orient') === 'vertical' ? toolboxModel.get('right') == null ? 'right' : 'left' : toolboxModel.get('bottom') == null ? 'bottom' : 'top';
  53274. path.setStyle({
  53275. textFill: iconStyleEmphasisModel.get('textFill') || hoverStyle.fill || hoverStyle.stroke || '#000',
  53276. textBackgroundColor: iconStyleEmphasisModel.get('textBackgroundColor'),
  53277. textPosition: iconStyleEmphasisModel.get('textPosition') || defaultTextPosition
  53278. });
  53279. }).on('mouseout', function () {
  53280. path.setStyle({
  53281. textFill: null,
  53282. textBackgroundColor: null
  53283. });
  53284. });
  53285. }
  53286. path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
  53287. group.add(path);
  53288. path.on('click', bind(feature.onclick, feature, ecModel, api, iconName));
  53289. iconPaths[iconName] = path;
  53290. });
  53291. }
  53292. layout$2(group, toolboxModel, api); // Render background after group is layout
  53293. // FIXME
  53294. group.add(makeBackground(group.getBoundingRect(), toolboxModel)); // Adjust icon title positions to avoid them out of screen
  53295. group.eachChild(function (icon) {
  53296. var titleText = icon.__title;
  53297. var hoverStyle = icon.hoverStyle; // May be background element
  53298. if (hoverStyle && titleText) {
  53299. var rect = getBoundingRect(titleText, makeFont(hoverStyle));
  53300. var offsetX = icon.position[0] + group.position[0];
  53301. var offsetY = icon.position[1] + group.position[1] + itemSize;
  53302. var needPutOnTop = false;
  53303. if (offsetY + rect.height > api.getHeight()) {
  53304. hoverStyle.textPosition = 'top';
  53305. needPutOnTop = true;
  53306. }
  53307. var topOffset = needPutOnTop ? -5 - rect.height : itemSize + 8;
  53308. if (offsetX + rect.width / 2 > api.getWidth()) {
  53309. hoverStyle.textPosition = ['100%', topOffset];
  53310. hoverStyle.textAlign = 'right';
  53311. } else if (offsetX - rect.width / 2 < 0) {
  53312. hoverStyle.textPosition = [0, topOffset];
  53313. hoverStyle.textAlign = 'left';
  53314. }
  53315. }
  53316. });
  53317. },
  53318. updateView: function (toolboxModel, ecModel, api, payload) {
  53319. each$1(this._features, function (feature) {
  53320. feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  53321. });
  53322. },
  53323. // updateLayout: function (toolboxModel, ecModel, api, payload) {
  53324. // zrUtil.each(this._features, function (feature) {
  53325. // feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  53326. // });
  53327. // },
  53328. remove: function (ecModel, api) {
  53329. each$1(this._features, function (feature) {
  53330. feature.remove && feature.remove(ecModel, api);
  53331. });
  53332. this.group.removeAll();
  53333. },
  53334. dispose: function (ecModel, api) {
  53335. each$1(this._features, function (feature) {
  53336. feature.dispose && feature.dispose(ecModel, api);
  53337. });
  53338. }
  53339. });
  53340. function isUserFeatureName(featureName) {
  53341. return featureName.indexOf('my') === 0;
  53342. }
  53343. /*
  53344. * Licensed to the Apache Software Foundation (ASF) under one
  53345. * or more contributor license agreements. See the NOTICE file
  53346. * distributed with this work for additional information
  53347. * regarding copyright ownership. The ASF licenses this file
  53348. * to you under the Apache License, Version 2.0 (the
  53349. * "License"); you may not use this file except in compliance
  53350. * with the License. You may obtain a copy of the License at
  53351. *
  53352. * http://www.apache.org/licenses/LICENSE-2.0
  53353. *
  53354. * Unless required by applicable law or agreed to in writing,
  53355. * software distributed under the License is distributed on an
  53356. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53357. * KIND, either express or implied. See the License for the
  53358. * specific language governing permissions and limitations
  53359. * under the License.
  53360. */
  53361. /* global Uint8Array */
  53362. var saveAsImageLang = lang.toolbox.saveAsImage;
  53363. function SaveAsImage(model) {
  53364. this.model = model;
  53365. }
  53366. SaveAsImage.defaultOption = {
  53367. show: true,
  53368. icon: 'M4.7,22.9L29.3,45.5L54.7,23.4M4.6,43.6L4.6,58L53.8,58L53.8,43.6M29.2,45.1L29.2,0',
  53369. title: saveAsImageLang.title,
  53370. type: 'png',
  53371. // Default use option.backgroundColor
  53372. // backgroundColor: '#fff',
  53373. connectedBackgroundColor: '#fff',
  53374. name: '',
  53375. excludeComponents: ['toolbox'],
  53376. pixelRatio: 1,
  53377. lang: saveAsImageLang.lang.slice()
  53378. };
  53379. SaveAsImage.prototype.unusable = !env$1.canvasSupported;
  53380. var proto$2 = SaveAsImage.prototype;
  53381. proto$2.onclick = function (ecModel, api) {
  53382. var model = this.model;
  53383. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  53384. var isSvg = api.getZr().painter.getType() === 'svg';
  53385. var type = isSvg ? 'svg' : model.get('type', true) || 'png';
  53386. var url = api.getConnectedDataURL({
  53387. type: type,
  53388. backgroundColor: model.get('backgroundColor', true) || ecModel.get('backgroundColor') || '#fff',
  53389. connectedBackgroundColor: model.get('connectedBackgroundColor'),
  53390. excludeComponents: model.get('excludeComponents'),
  53391. pixelRatio: model.get('pixelRatio')
  53392. }); // Chrome and Firefox
  53393. if (typeof MouseEvent === 'function' && !env$1.browser.ie && !env$1.browser.edge) {
  53394. var $a = document.createElement('a');
  53395. $a.download = title + '.' + type;
  53396. $a.target = '_blank';
  53397. $a.href = url;
  53398. var evt = new MouseEvent('click', {
  53399. view: window,
  53400. bubbles: true,
  53401. cancelable: false
  53402. });
  53403. $a.dispatchEvent(evt);
  53404. } // IE
  53405. else {
  53406. if (window.navigator.msSaveOrOpenBlob) {
  53407. var bstr = atob(url.split(',')[1]);
  53408. var n = bstr.length;
  53409. var u8arr = new Uint8Array(n);
  53410. while (n--) {
  53411. u8arr[n] = bstr.charCodeAt(n);
  53412. }
  53413. var blob = new Blob([u8arr]);
  53414. window.navigator.msSaveOrOpenBlob(blob, title + '.' + type);
  53415. } else {
  53416. var lang$$1 = model.get('lang');
  53417. var html = '' + '<body style="margin:0;">' + '<img src="' + url + '" style="max-width:100%;" title="' + (lang$$1 && lang$$1[0] || '') + '" />' + '</body>';
  53418. var tab = window.open();
  53419. tab.document.write(html);
  53420. }
  53421. }
  53422. };
  53423. register$2('saveAsImage', SaveAsImage);
  53424. /*
  53425. * Licensed to the Apache Software Foundation (ASF) under one
  53426. * or more contributor license agreements. See the NOTICE file
  53427. * distributed with this work for additional information
  53428. * regarding copyright ownership. The ASF licenses this file
  53429. * to you under the Apache License, Version 2.0 (the
  53430. * "License"); you may not use this file except in compliance
  53431. * with the License. You may obtain a copy of the License at
  53432. *
  53433. * http://www.apache.org/licenses/LICENSE-2.0
  53434. *
  53435. * Unless required by applicable law or agreed to in writing,
  53436. * software distributed under the License is distributed on an
  53437. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53438. * KIND, either express or implied. See the License for the
  53439. * specific language governing permissions and limitations
  53440. * under the License.
  53441. */
  53442. var magicTypeLang = lang.toolbox.magicType;
  53443. var INNER_STACK_KEYWORD = '__ec_magicType_stack__';
  53444. function MagicType(model) {
  53445. this.model = model;
  53446. }
  53447. MagicType.defaultOption = {
  53448. show: true,
  53449. type: [],
  53450. // Icon group
  53451. icon: {
  53452. /* eslint-disable */
  53453. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  53454. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  53455. stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z' // jshint ignore:line
  53456. /* eslint-enable */
  53457. },
  53458. // `line`, `bar`, `stack`, `tiled`
  53459. title: clone(magicTypeLang.title),
  53460. option: {},
  53461. seriesIndex: {}
  53462. };
  53463. var proto$3 = MagicType.prototype;
  53464. proto$3.getIcons = function () {
  53465. var model = this.model;
  53466. var availableIcons = model.get('icon');
  53467. var icons = {};
  53468. each$1(model.get('type'), function (type) {
  53469. if (availableIcons[type]) {
  53470. icons[type] = availableIcons[type];
  53471. }
  53472. });
  53473. return icons;
  53474. };
  53475. var seriesOptGenreator = {
  53476. 'line': function (seriesType, seriesId, seriesModel, model) {
  53477. if (seriesType === 'bar') {
  53478. return merge({
  53479. id: seriesId,
  53480. type: 'line',
  53481. // Preserve data related option
  53482. data: seriesModel.get('data'),
  53483. stack: seriesModel.get('stack'),
  53484. markPoint: seriesModel.get('markPoint'),
  53485. markLine: seriesModel.get('markLine')
  53486. }, model.get('option.line') || {}, true);
  53487. }
  53488. },
  53489. 'bar': function (seriesType, seriesId, seriesModel, model) {
  53490. if (seriesType === 'line') {
  53491. return merge({
  53492. id: seriesId,
  53493. type: 'bar',
  53494. // Preserve data related option
  53495. data: seriesModel.get('data'),
  53496. stack: seriesModel.get('stack'),
  53497. markPoint: seriesModel.get('markPoint'),
  53498. markLine: seriesModel.get('markLine')
  53499. }, model.get('option.bar') || {}, true);
  53500. }
  53501. },
  53502. 'stack': function (seriesType, seriesId, seriesModel, model) {
  53503. var isStack = seriesModel.get('stack') === INNER_STACK_KEYWORD;
  53504. if (seriesType === 'line' || seriesType === 'bar') {
  53505. model.setIconStatus('stack', isStack ? 'normal' : 'emphasis');
  53506. return merge({
  53507. id: seriesId,
  53508. stack: isStack ? '' : INNER_STACK_KEYWORD
  53509. }, model.get('option.stack') || {}, true);
  53510. }
  53511. }
  53512. };
  53513. var radioTypes = [['line', 'bar'], ['stack']];
  53514. proto$3.onclick = function (ecModel, api, type) {
  53515. var model = this.model;
  53516. var seriesIndex = model.get('seriesIndex.' + type); // Not supported magicType
  53517. if (!seriesOptGenreator[type]) {
  53518. return;
  53519. }
  53520. var newOption = {
  53521. series: []
  53522. };
  53523. var generateNewSeriesTypes = function (seriesModel) {
  53524. var seriesType = seriesModel.subType;
  53525. var seriesId = seriesModel.id;
  53526. var newSeriesOpt = seriesOptGenreator[type](seriesType, seriesId, seriesModel, model);
  53527. if (newSeriesOpt) {
  53528. // PENDING If merge original option?
  53529. defaults(newSeriesOpt, seriesModel.option);
  53530. newOption.series.push(newSeriesOpt);
  53531. } // Modify boundaryGap
  53532. var coordSys = seriesModel.coordinateSystem;
  53533. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  53534. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  53535. if (categoryAxis) {
  53536. var axisDim = categoryAxis.dim;
  53537. var axisType = axisDim + 'Axis';
  53538. var axisModel = ecModel.queryComponents({
  53539. mainType: axisType,
  53540. index: seriesModel.get(name + 'Index'),
  53541. id: seriesModel.get(name + 'Id')
  53542. })[0];
  53543. var axisIndex = axisModel.componentIndex;
  53544. newOption[axisType] = newOption[axisType] || [];
  53545. for (var i = 0; i <= axisIndex; i++) {
  53546. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  53547. }
  53548. newOption[axisType][axisIndex].boundaryGap = type === 'bar';
  53549. }
  53550. }
  53551. };
  53552. each$1(radioTypes, function (radio) {
  53553. if (indexOf(radio, type) >= 0) {
  53554. each$1(radio, function (item) {
  53555. model.setIconStatus(item, 'normal');
  53556. });
  53557. }
  53558. });
  53559. model.setIconStatus(type, 'emphasis');
  53560. ecModel.eachComponent({
  53561. mainType: 'series',
  53562. query: seriesIndex == null ? null : {
  53563. seriesIndex: seriesIndex
  53564. }
  53565. }, generateNewSeriesTypes);
  53566. var newTitle; // Change title of stack
  53567. if (type === 'stack') {
  53568. var isStack = newOption.series && newOption.series[0] && newOption.series[0].stack === INNER_STACK_KEYWORD;
  53569. newTitle = isStack ? merge({
  53570. stack: magicTypeLang.title.tiled
  53571. }, magicTypeLang.title) : clone(magicTypeLang.title);
  53572. }
  53573. api.dispatchAction({
  53574. type: 'changeMagicType',
  53575. currentType: type,
  53576. newOption: newOption,
  53577. newTitle: newTitle,
  53578. featureName: 'magicType'
  53579. });
  53580. };
  53581. registerAction({
  53582. type: 'changeMagicType',
  53583. event: 'magicTypeChanged',
  53584. update: 'prepareAndUpdate'
  53585. }, function (payload, ecModel) {
  53586. ecModel.mergeOption(payload.newOption);
  53587. });
  53588. register$2('magicType', MagicType);
  53589. /*
  53590. * Licensed to the Apache Software Foundation (ASF) under one
  53591. * or more contributor license agreements. See the NOTICE file
  53592. * distributed with this work for additional information
  53593. * regarding copyright ownership. The ASF licenses this file
  53594. * to you under the Apache License, Version 2.0 (the
  53595. * "License"); you may not use this file except in compliance
  53596. * with the License. You may obtain a copy of the License at
  53597. *
  53598. * http://www.apache.org/licenses/LICENSE-2.0
  53599. *
  53600. * Unless required by applicable law or agreed to in writing,
  53601. * software distributed under the License is distributed on an
  53602. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53603. * KIND, either express or implied. See the License for the
  53604. * specific language governing permissions and limitations
  53605. * under the License.
  53606. */
  53607. var dataViewLang = lang.toolbox.dataView;
  53608. var BLOCK_SPLITER = new Array(60).join('-');
  53609. var ITEM_SPLITER = '\t';
  53610. /**
  53611. * Group series into two types
  53612. * 1. on category axis, like line, bar
  53613. * 2. others, like scatter, pie
  53614. * @param {module:echarts/model/Global} ecModel
  53615. * @return {Object}
  53616. * @inner
  53617. */
  53618. function groupSeries(ecModel) {
  53619. var seriesGroupByCategoryAxis = {};
  53620. var otherSeries = [];
  53621. var meta = [];
  53622. ecModel.eachRawSeries(function (seriesModel) {
  53623. var coordSys = seriesModel.coordinateSystem;
  53624. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  53625. var baseAxis = coordSys.getBaseAxis();
  53626. if (baseAxis.type === 'category') {
  53627. var key = baseAxis.dim + '_' + baseAxis.index;
  53628. if (!seriesGroupByCategoryAxis[key]) {
  53629. seriesGroupByCategoryAxis[key] = {
  53630. categoryAxis: baseAxis,
  53631. valueAxis: coordSys.getOtherAxis(baseAxis),
  53632. series: []
  53633. };
  53634. meta.push({
  53635. axisDim: baseAxis.dim,
  53636. axisIndex: baseAxis.index
  53637. });
  53638. }
  53639. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  53640. } else {
  53641. otherSeries.push(seriesModel);
  53642. }
  53643. } else {
  53644. otherSeries.push(seriesModel);
  53645. }
  53646. });
  53647. return {
  53648. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  53649. other: otherSeries,
  53650. meta: meta
  53651. };
  53652. }
  53653. /**
  53654. * Assemble content of series on cateogory axis
  53655. * @param {Array.<module:echarts/model/Series>} series
  53656. * @return {string}
  53657. * @inner
  53658. */
  53659. function assembleSeriesWithCategoryAxis(series) {
  53660. var tables = [];
  53661. each$1(series, function (group, key) {
  53662. var categoryAxis = group.categoryAxis;
  53663. var valueAxis = group.valueAxis;
  53664. var valueAxisDim = valueAxis.dim;
  53665. var headers = [' '].concat(map(group.series, function (series) {
  53666. return series.name;
  53667. }));
  53668. var columns = [categoryAxis.model.getCategories()];
  53669. each$1(group.series, function (series) {
  53670. columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
  53671. return val;
  53672. }));
  53673. }); // Assemble table content
  53674. var lines = [headers.join(ITEM_SPLITER)];
  53675. for (var i = 0; i < columns[0].length; i++) {
  53676. var items = [];
  53677. for (var j = 0; j < columns.length; j++) {
  53678. items.push(columns[j][i]);
  53679. }
  53680. lines.push(items.join(ITEM_SPLITER));
  53681. }
  53682. tables.push(lines.join('\n'));
  53683. });
  53684. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  53685. }
  53686. /**
  53687. * Assemble content of other series
  53688. * @param {Array.<module:echarts/model/Series>} series
  53689. * @return {string}
  53690. * @inner
  53691. */
  53692. function assembleOtherSeries(series) {
  53693. return map(series, function (series) {
  53694. var data = series.getRawData();
  53695. var lines = [series.name];
  53696. var vals = [];
  53697. data.each(data.dimensions, function () {
  53698. var argLen = arguments.length;
  53699. var dataIndex = arguments[argLen - 1];
  53700. var name = data.getName(dataIndex);
  53701. for (var i = 0; i < argLen - 1; i++) {
  53702. vals[i] = arguments[i];
  53703. }
  53704. lines.push((name ? name + ITEM_SPLITER : '') + vals.join(ITEM_SPLITER));
  53705. });
  53706. return lines.join('\n');
  53707. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  53708. }
  53709. /**
  53710. * @param {module:echarts/model/Global}
  53711. * @return {Object}
  53712. * @inner
  53713. */
  53714. function getContentFromModel(ecModel) {
  53715. var result = groupSeries(ecModel);
  53716. return {
  53717. value: filter([assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis), assembleOtherSeries(result.other)], function (str) {
  53718. return str.replace(/[\n\t\s]/g, '');
  53719. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  53720. meta: result.meta
  53721. };
  53722. }
  53723. function trim$1(str) {
  53724. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  53725. }
  53726. /**
  53727. * If a block is tsv format
  53728. */
  53729. function isTSVFormat(block) {
  53730. // Simple method to find out if a block is tsv format
  53731. var firstLine = block.slice(0, block.indexOf('\n'));
  53732. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  53733. return true;
  53734. }
  53735. }
  53736. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  53737. /**
  53738. * @param {string} tsv
  53739. * @return {Object}
  53740. */
  53741. function parseTSVContents(tsv) {
  53742. var tsvLines = tsv.split(/\n+/g);
  53743. var headers = trim$1(tsvLines.shift()).split(itemSplitRegex);
  53744. var categories = [];
  53745. var series = map(headers, function (header) {
  53746. return {
  53747. name: header,
  53748. data: []
  53749. };
  53750. });
  53751. for (var i = 0; i < tsvLines.length; i++) {
  53752. var items = trim$1(tsvLines[i]).split(itemSplitRegex);
  53753. categories.push(items.shift());
  53754. for (var j = 0; j < items.length; j++) {
  53755. series[j] && (series[j].data[i] = items[j]);
  53756. }
  53757. }
  53758. return {
  53759. series: series,
  53760. categories: categories
  53761. };
  53762. }
  53763. /**
  53764. * @param {string} str
  53765. * @return {Array.<Object>}
  53766. * @inner
  53767. */
  53768. function parseListContents(str) {
  53769. var lines = str.split(/\n+/g);
  53770. var seriesName = trim$1(lines.shift());
  53771. var data = [];
  53772. for (var i = 0; i < lines.length; i++) {
  53773. var items = trim$1(lines[i]).split(itemSplitRegex);
  53774. var name = '';
  53775. var value;
  53776. var hasName = false;
  53777. if (isNaN(items[0])) {
  53778. // First item is name
  53779. hasName = true;
  53780. name = items[0];
  53781. items = items.slice(1);
  53782. data[i] = {
  53783. name: name,
  53784. value: []
  53785. };
  53786. value = data[i].value;
  53787. } else {
  53788. value = data[i] = [];
  53789. }
  53790. for (var j = 0; j < items.length; j++) {
  53791. value.push(+items[j]);
  53792. }
  53793. if (value.length === 1) {
  53794. hasName ? data[i].value = value[0] : data[i] = value[0];
  53795. }
  53796. }
  53797. return {
  53798. name: seriesName,
  53799. data: data
  53800. };
  53801. }
  53802. /**
  53803. * @param {string} str
  53804. * @param {Array.<Object>} blockMetaList
  53805. * @return {Object}
  53806. * @inner
  53807. */
  53808. function parseContents(str, blockMetaList) {
  53809. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  53810. var newOption = {
  53811. series: []
  53812. };
  53813. each$1(blocks, function (block, idx) {
  53814. if (isTSVFormat(block)) {
  53815. var result = parseTSVContents(block);
  53816. var blockMeta = blockMetaList[idx];
  53817. var axisKey = blockMeta.axisDim + 'Axis';
  53818. if (blockMeta) {
  53819. newOption[axisKey] = newOption[axisKey] || [];
  53820. newOption[axisKey][blockMeta.axisIndex] = {
  53821. data: result.categories
  53822. };
  53823. newOption.series = newOption.series.concat(result.series);
  53824. }
  53825. } else {
  53826. var result = parseListContents(block);
  53827. newOption.series.push(result);
  53828. }
  53829. });
  53830. return newOption;
  53831. }
  53832. /**
  53833. * @alias {module:echarts/component/toolbox/feature/DataView}
  53834. * @constructor
  53835. * @param {module:echarts/model/Model} model
  53836. */
  53837. function DataView(model) {
  53838. this._dom = null;
  53839. this.model = model;
  53840. }
  53841. DataView.defaultOption = {
  53842. show: true,
  53843. readOnly: false,
  53844. optionToContent: null,
  53845. contentToOption: null,
  53846. icon: 'M17.5,17.3H33 M17.5,17.3H33 M45.4,29.5h-28 M11.5,2v56H51V14.8L38.4,2H11.5z M38.4,2.2v12.7H51 M45.4,41.7h-28',
  53847. title: clone(dataViewLang.title),
  53848. lang: clone(dataViewLang.lang),
  53849. backgroundColor: '#fff',
  53850. textColor: '#000',
  53851. textareaColor: '#fff',
  53852. textareaBorderColor: '#333',
  53853. buttonColor: '#c23531',
  53854. buttonTextColor: '#fff'
  53855. };
  53856. DataView.prototype.onclick = function (ecModel, api) {
  53857. var container = api.getDom();
  53858. var model = this.model;
  53859. if (this._dom) {
  53860. container.removeChild(this._dom);
  53861. }
  53862. var root = document.createElement('div');
  53863. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  53864. root.style.backgroundColor = model.get('backgroundColor') || '#fff'; // Create elements
  53865. var header = document.createElement('h4');
  53866. var lang$$1 = model.get('lang') || [];
  53867. header.innerHTML = lang$$1[0] || model.get('title');
  53868. header.style.cssText = 'margin: 10px 20px;';
  53869. header.style.color = model.get('textColor');
  53870. var viewMain = document.createElement('div');
  53871. var textarea = document.createElement('textarea');
  53872. viewMain.style.cssText = 'display:block;width:100%;overflow:auto;';
  53873. var optionToContent = model.get('optionToContent');
  53874. var contentToOption = model.get('contentToOption');
  53875. var result = getContentFromModel(ecModel);
  53876. if (typeof optionToContent === 'function') {
  53877. var htmlOrDom = optionToContent(api.getOption());
  53878. if (typeof htmlOrDom === 'string') {
  53879. viewMain.innerHTML = htmlOrDom;
  53880. } else if (isDom(htmlOrDom)) {
  53881. viewMain.appendChild(htmlOrDom);
  53882. }
  53883. } else {
  53884. // Use default textarea
  53885. viewMain.appendChild(textarea);
  53886. textarea.readOnly = model.get('readOnly');
  53887. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  53888. textarea.style.color = model.get('textColor');
  53889. textarea.style.borderColor = model.get('textareaBorderColor');
  53890. textarea.style.backgroundColor = model.get('textareaColor');
  53891. textarea.value = result.value;
  53892. }
  53893. var blockMetaList = result.meta;
  53894. var buttonContainer = document.createElement('div');
  53895. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  53896. var buttonStyle = 'float:right;margin-right:20px;border:none;' + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  53897. var closeButton = document.createElement('div');
  53898. var refreshButton = document.createElement('div');
  53899. buttonStyle += ';background-color:' + model.get('buttonColor');
  53900. buttonStyle += ';color:' + model.get('buttonTextColor');
  53901. var self = this;
  53902. function close() {
  53903. container.removeChild(root);
  53904. self._dom = null;
  53905. }
  53906. addEventListener(closeButton, 'click', close);
  53907. addEventListener(refreshButton, 'click', function () {
  53908. var newOption;
  53909. try {
  53910. if (typeof contentToOption === 'function') {
  53911. newOption = contentToOption(viewMain, api.getOption());
  53912. } else {
  53913. newOption = parseContents(textarea.value, blockMetaList);
  53914. }
  53915. } catch (e) {
  53916. close();
  53917. throw new Error('Data view format error ' + e);
  53918. }
  53919. if (newOption) {
  53920. api.dispatchAction({
  53921. type: 'changeDataView',
  53922. newOption: newOption
  53923. });
  53924. }
  53925. close();
  53926. });
  53927. closeButton.innerHTML = lang$$1[1];
  53928. refreshButton.innerHTML = lang$$1[2];
  53929. refreshButton.style.cssText = buttonStyle;
  53930. closeButton.style.cssText = buttonStyle;
  53931. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  53932. buttonContainer.appendChild(closeButton);
  53933. root.appendChild(header);
  53934. root.appendChild(viewMain);
  53935. root.appendChild(buttonContainer);
  53936. viewMain.style.height = container.clientHeight - 80 + 'px';
  53937. container.appendChild(root);
  53938. this._dom = root;
  53939. };
  53940. DataView.prototype.remove = function (ecModel, api) {
  53941. this._dom && api.getDom().removeChild(this._dom);
  53942. };
  53943. DataView.prototype.dispose = function (ecModel, api) {
  53944. this.remove(ecModel, api);
  53945. };
  53946. /**
  53947. * @inner
  53948. */
  53949. function tryMergeDataOption(newData, originalData) {
  53950. return map(newData, function (newVal, idx) {
  53951. var original = originalData && originalData[idx];
  53952. if (isObject$1(original) && !isArray(original)) {
  53953. if (isObject$1(newVal) && !isArray(newVal)) {
  53954. newVal = newVal.value;
  53955. } // Original data has option
  53956. return defaults({
  53957. value: newVal
  53958. }, original);
  53959. } else {
  53960. return newVal;
  53961. }
  53962. });
  53963. }
  53964. register$2('dataView', DataView);
  53965. registerAction({
  53966. type: 'changeDataView',
  53967. event: 'dataViewChanged',
  53968. update: 'prepareAndUpdate'
  53969. }, function (payload, ecModel) {
  53970. var newSeriesOptList = [];
  53971. each$1(payload.newOption.series, function (seriesOpt) {
  53972. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  53973. if (!seriesModel) {
  53974. // New created series
  53975. // Geuss the series type
  53976. newSeriesOptList.push(extend({
  53977. // Default is scatter
  53978. type: 'scatter'
  53979. }, seriesOpt));
  53980. } else {
  53981. var originalData = seriesModel.get('data');
  53982. newSeriesOptList.push({
  53983. name: seriesOpt.name,
  53984. data: tryMergeDataOption(seriesOpt.data, originalData)
  53985. });
  53986. }
  53987. });
  53988. ecModel.mergeOption(defaults({
  53989. series: newSeriesOptList
  53990. }, payload.newOption));
  53991. });
  53992. /*
  53993. * Licensed to the Apache Software Foundation (ASF) under one
  53994. * or more contributor license agreements. See the NOTICE file
  53995. * distributed with this work for additional information
  53996. * regarding copyright ownership. The ASF licenses this file
  53997. * to you under the Apache License, Version 2.0 (the
  53998. * "License"); you may not use this file except in compliance
  53999. * with the License. You may obtain a copy of the License at
  54000. *
  54001. * http://www.apache.org/licenses/LICENSE-2.0
  54002. *
  54003. * Unless required by applicable law or agreed to in writing,
  54004. * software distributed under the License is distributed on an
  54005. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54006. * KIND, either express or implied. See the License for the
  54007. * specific language governing permissions and limitations
  54008. * under the License.
  54009. */
  54010. var curry$5 = curry;
  54011. var each$18 = each$1;
  54012. var map$2 = map;
  54013. var mathMin$5 = Math.min;
  54014. var mathMax$5 = Math.max;
  54015. var mathPow$2 = Math.pow;
  54016. var COVER_Z = 10000;
  54017. var UNSELECT_THRESHOLD = 6;
  54018. var MIN_RESIZE_LINE_WIDTH = 6;
  54019. var MUTEX_RESOURCE_KEY = 'globalPan';
  54020. var DIRECTION_MAP = {
  54021. w: [0, 0],
  54022. e: [0, 1],
  54023. n: [1, 0],
  54024. s: [1, 1]
  54025. };
  54026. var CURSOR_MAP = {
  54027. w: 'ew',
  54028. e: 'ew',
  54029. n: 'ns',
  54030. s: 'ns',
  54031. ne: 'nesw',
  54032. sw: 'nesw',
  54033. nw: 'nwse',
  54034. se: 'nwse'
  54035. };
  54036. var DEFAULT_BRUSH_OPT = {
  54037. brushStyle: {
  54038. lineWidth: 2,
  54039. stroke: 'rgba(0,0,0,0.3)',
  54040. fill: 'rgba(0,0,0,0.1)'
  54041. },
  54042. transformable: true,
  54043. brushMode: 'single',
  54044. removeOnClick: false
  54045. };
  54046. var baseUID = 0;
  54047. /**
  54048. * @alias module:echarts/component/helper/BrushController
  54049. * @constructor
  54050. * @mixin {module:zrender/mixin/Eventful}
  54051. * @event module:echarts/component/helper/BrushController#brush
  54052. * params:
  54053. * areas: Array.<Array>, coord relates to container group,
  54054. * If no container specified, to global.
  54055. * opt {
  54056. * isEnd: boolean,
  54057. * removeOnClick: boolean
  54058. * }
  54059. *
  54060. * @param {module:zrender/zrender~ZRender} zr
  54061. */
  54062. function BrushController(zr) {
  54063. Eventful.call(this);
  54064. /**
  54065. * @type {module:zrender/zrender~ZRender}
  54066. * @private
  54067. */
  54068. this._zr = zr;
  54069. /**
  54070. * @type {module:zrender/container/Group}
  54071. * @readOnly
  54072. */
  54073. this.group = new Group();
  54074. /**
  54075. * Only for drawing (after enabledBrush).
  54076. * 'line', 'rect', 'polygon' or false
  54077. * If passing false/null/undefined, disable brush.
  54078. * If passing 'auto', determined by panel.defaultBrushType
  54079. * @private
  54080. * @type {string}
  54081. */
  54082. this._brushType;
  54083. /**
  54084. * Only for drawing (after enabledBrush).
  54085. *
  54086. * @private
  54087. * @type {Object}
  54088. */
  54089. this._brushOption;
  54090. /**
  54091. * @private
  54092. * @type {Object}
  54093. */
  54094. this._panels;
  54095. /**
  54096. * @private
  54097. * @type {Array.<nubmer>}
  54098. */
  54099. this._track = [];
  54100. /**
  54101. * @private
  54102. * @type {boolean}
  54103. */
  54104. this._dragging;
  54105. /**
  54106. * @private
  54107. * @type {Array}
  54108. */
  54109. this._covers = [];
  54110. /**
  54111. * @private
  54112. * @type {moudule:zrender/container/Group}
  54113. */
  54114. this._creatingCover;
  54115. /**
  54116. * `true` means global panel
  54117. * @private
  54118. * @type {module:zrender/container/Group|boolean}
  54119. */
  54120. this._creatingPanel;
  54121. /**
  54122. * @private
  54123. * @type {boolean}
  54124. */
  54125. this._enableGlobalPan;
  54126. /**
  54127. * @private
  54128. * @type {boolean}
  54129. */
  54130. /**
  54131. * @private
  54132. * @type {string}
  54133. */
  54134. this._uid = 'brushController_' + baseUID++;
  54135. /**
  54136. * @private
  54137. * @type {Object}
  54138. */
  54139. this._handlers = {};
  54140. each$18(pointerHandlers, function (handler, eventName) {
  54141. this._handlers[eventName] = bind(handler, this);
  54142. }, this);
  54143. }
  54144. BrushController.prototype = {
  54145. constructor: BrushController,
  54146. /**
  54147. * If set to null/undefined/false, select disabled.
  54148. * @param {Object} brushOption
  54149. * @param {string|boolean} brushOption.brushType 'line', 'rect', 'polygon' or false
  54150. * If passing false/null/undefined, disable brush.
  54151. * If passing 'auto', determined by panel.defaultBrushType.
  54152. * ('auto' can not be used in global panel)
  54153. * @param {number} [brushOption.brushMode='single'] 'single' or 'multiple'
  54154. * @param {boolean} [brushOption.transformable=true]
  54155. * @param {boolean} [brushOption.removeOnClick=false]
  54156. * @param {Object} [brushOption.brushStyle]
  54157. * @param {number} [brushOption.brushStyle.width]
  54158. * @param {number} [brushOption.brushStyle.lineWidth]
  54159. * @param {string} [brushOption.brushStyle.stroke]
  54160. * @param {string} [brushOption.brushStyle.fill]
  54161. * @param {number} [brushOption.z]
  54162. */
  54163. enableBrush: function (brushOption) {
  54164. this._brushType && doDisableBrush(this);
  54165. brushOption.brushType && doEnableBrush(this, brushOption);
  54166. return this;
  54167. },
  54168. /**
  54169. * @param {Array.<Object>} panelOpts If not pass, it is global brush.
  54170. * Each items: {
  54171. * panelId, // mandatory.
  54172. * clipPath, // mandatory. function.
  54173. * isTargetByCursor, // mandatory. function.
  54174. * defaultBrushType, // optional, only used when brushType is 'auto'.
  54175. * getLinearBrushOtherExtent, // optional. function.
  54176. * }
  54177. */
  54178. setPanels: function (panelOpts) {
  54179. if (panelOpts && panelOpts.length) {
  54180. var panels = this._panels = {};
  54181. each$1(panelOpts, function (panelOpts) {
  54182. panels[panelOpts.panelId] = clone(panelOpts);
  54183. });
  54184. } else {
  54185. this._panels = null;
  54186. }
  54187. return this;
  54188. },
  54189. /**
  54190. * @param {Object} [opt]
  54191. * @return {boolean} [opt.enableGlobalPan=false]
  54192. */
  54193. mount: function (opt) {
  54194. opt = opt || {};
  54195. this._enableGlobalPan = opt.enableGlobalPan;
  54196. var thisGroup = this.group;
  54197. this._zr.add(thisGroup);
  54198. thisGroup.attr({
  54199. position: opt.position || [0, 0],
  54200. rotation: opt.rotation || 0,
  54201. scale: opt.scale || [1, 1]
  54202. });
  54203. this._transform = thisGroup.getLocalTransform();
  54204. return this;
  54205. },
  54206. eachCover: function (cb, context) {
  54207. each$18(this._covers, cb, context);
  54208. },
  54209. /**
  54210. * Update covers.
  54211. * @param {Array.<Object>} brushOptionList Like:
  54212. * [
  54213. * {id: 'xx', brushType: 'line', range: [23, 44], brushStyle, transformable},
  54214. * {id: 'yy', brushType: 'rect', range: [[23, 44], [23, 54]]},
  54215. * ...
  54216. * ]
  54217. * `brushType` is required in each cover info. (can not be 'auto')
  54218. * `id` is not mandatory.
  54219. * `brushStyle`, `transformable` is not mandatory, use DEFAULT_BRUSH_OPT by default.
  54220. * If brushOptionList is null/undefined, all covers removed.
  54221. */
  54222. updateCovers: function (brushOptionList) {
  54223. brushOptionList = map(brushOptionList, function (brushOption) {
  54224. return merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  54225. });
  54226. var tmpIdPrefix = '\0-brush-index-';
  54227. var oldCovers = this._covers;
  54228. var newCovers = this._covers = [];
  54229. var controller = this;
  54230. var creatingCover = this._creatingCover;
  54231. new DataDiffer(oldCovers, brushOptionList, oldGetKey, getKey).add(addOrUpdate).update(addOrUpdate).remove(remove).execute();
  54232. return this;
  54233. function getKey(brushOption, index) {
  54234. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index) + '-' + brushOption.brushType;
  54235. }
  54236. function oldGetKey(cover, index) {
  54237. return getKey(cover.__brushOption, index);
  54238. }
  54239. function addOrUpdate(newIndex, oldIndex) {
  54240. var newBrushOption = brushOptionList[newIndex]; // Consider setOption in event listener of brushSelect,
  54241. // where updating cover when creating should be forbiden.
  54242. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  54243. newCovers[newIndex] = oldCovers[oldIndex];
  54244. } else {
  54245. var cover = newCovers[newIndex] = oldIndex != null ? (oldCovers[oldIndex].__brushOption = newBrushOption, oldCovers[oldIndex]) : endCreating(controller, createCover(controller, newBrushOption));
  54246. updateCoverAfterCreation(controller, cover);
  54247. }
  54248. }
  54249. function remove(oldIndex) {
  54250. if (oldCovers[oldIndex] !== creatingCover) {
  54251. controller.group.remove(oldCovers[oldIndex]);
  54252. }
  54253. }
  54254. },
  54255. unmount: function () {
  54256. this.enableBrush(false); // container may 'removeAll' outside.
  54257. clearCovers(this);
  54258. this._zr.remove(this.group);
  54259. return this;
  54260. },
  54261. dispose: function () {
  54262. this.unmount();
  54263. this.off();
  54264. }
  54265. };
  54266. mixin(BrushController, Eventful);
  54267. function doEnableBrush(controller, brushOption) {
  54268. var zr = controller._zr; // Consider roam, which takes globalPan too.
  54269. if (!controller._enableGlobalPan) {
  54270. take(zr, MUTEX_RESOURCE_KEY, controller._uid);
  54271. }
  54272. mountHandlers(zr, controller._handlers);
  54273. controller._brushType = brushOption.brushType;
  54274. controller._brushOption = merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  54275. }
  54276. function doDisableBrush(controller) {
  54277. var zr = controller._zr;
  54278. release(zr, MUTEX_RESOURCE_KEY, controller._uid);
  54279. unmountHandlers(zr, controller._handlers);
  54280. controller._brushType = controller._brushOption = null;
  54281. }
  54282. function mountHandlers(zr, handlers) {
  54283. each$18(handlers, function (handler, eventName) {
  54284. zr.on(eventName, handler);
  54285. });
  54286. }
  54287. function unmountHandlers(zr, handlers) {
  54288. each$18(handlers, function (handler, eventName) {
  54289. zr.off(eventName, handler);
  54290. });
  54291. }
  54292. function createCover(controller, brushOption) {
  54293. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  54294. cover.__brushOption = brushOption;
  54295. updateZ$1(cover, brushOption);
  54296. controller.group.add(cover);
  54297. return cover;
  54298. }
  54299. function endCreating(controller, creatingCover) {
  54300. var coverRenderer = getCoverRenderer(creatingCover);
  54301. if (coverRenderer.endCreating) {
  54302. coverRenderer.endCreating(controller, creatingCover);
  54303. updateZ$1(creatingCover, creatingCover.__brushOption);
  54304. }
  54305. return creatingCover;
  54306. }
  54307. function updateCoverShape(controller, cover) {
  54308. var brushOption = cover.__brushOption;
  54309. getCoverRenderer(cover).updateCoverShape(controller, cover, brushOption.range, brushOption);
  54310. }
  54311. function updateZ$1(cover, brushOption) {
  54312. var z = brushOption.z;
  54313. z == null && (z = COVER_Z);
  54314. cover.traverse(function (el) {
  54315. el.z = z;
  54316. el.z2 = z; // Consider in given container.
  54317. });
  54318. }
  54319. function updateCoverAfterCreation(controller, cover) {
  54320. getCoverRenderer(cover).updateCommon(controller, cover);
  54321. updateCoverShape(controller, cover);
  54322. }
  54323. function getCoverRenderer(cover) {
  54324. return coverRenderers[cover.__brushOption.brushType];
  54325. } // return target panel or `true` (means global panel)
  54326. function getPanelByPoint(controller, e, localCursorPoint) {
  54327. var panels = controller._panels;
  54328. if (!panels) {
  54329. return true; // Global panel
  54330. }
  54331. var panel;
  54332. var transform = controller._transform;
  54333. each$18(panels, function (pn) {
  54334. pn.isTargetByCursor(e, localCursorPoint, transform) && (panel = pn);
  54335. });
  54336. return panel;
  54337. } // Return a panel or true
  54338. function getPanelByCover(controller, cover) {
  54339. var panels = controller._panels;
  54340. if (!panels) {
  54341. return true; // Global panel
  54342. }
  54343. var panelId = cover.__brushOption.panelId; // User may give cover without coord sys info,
  54344. // which is then treated as global panel.
  54345. return panelId != null ? panels[panelId] : true;
  54346. }
  54347. function clearCovers(controller) {
  54348. var covers = controller._covers;
  54349. var originalLength = covers.length;
  54350. each$18(covers, function (cover) {
  54351. controller.group.remove(cover);
  54352. }, controller);
  54353. covers.length = 0;
  54354. return !!originalLength;
  54355. }
  54356. function trigger$1(controller, opt) {
  54357. var areas = map$2(controller._covers, function (cover) {
  54358. var brushOption = cover.__brushOption;
  54359. var range = clone(brushOption.range);
  54360. return {
  54361. brushType: brushOption.brushType,
  54362. panelId: brushOption.panelId,
  54363. range: range
  54364. };
  54365. });
  54366. controller.trigger('brush', areas, {
  54367. isEnd: !!opt.isEnd,
  54368. removeOnClick: !!opt.removeOnClick
  54369. });
  54370. }
  54371. function shouldShowCover(controller) {
  54372. var track = controller._track;
  54373. if (!track.length) {
  54374. return false;
  54375. }
  54376. var p2 = track[track.length - 1];
  54377. var p1 = track[0];
  54378. var dx = p2[0] - p1[0];
  54379. var dy = p2[1] - p1[1];
  54380. var dist = mathPow$2(dx * dx + dy * dy, 0.5);
  54381. return dist > UNSELECT_THRESHOLD;
  54382. }
  54383. function getTrackEnds(track) {
  54384. var tail = track.length - 1;
  54385. tail < 0 && (tail = 0);
  54386. return [track[0], track[tail]];
  54387. }
  54388. function createBaseRectCover(doDrift, controller, brushOption, edgeNames) {
  54389. var cover = new Group();
  54390. cover.add(new Rect({
  54391. name: 'main',
  54392. style: makeStyle(brushOption),
  54393. silent: true,
  54394. draggable: true,
  54395. cursor: 'move',
  54396. drift: curry$5(doDrift, controller, cover, 'nswe'),
  54397. ondragend: curry$5(trigger$1, controller, {
  54398. isEnd: true
  54399. })
  54400. }));
  54401. each$18(edgeNames, function (name) {
  54402. cover.add(new Rect({
  54403. name: name,
  54404. style: {
  54405. opacity: 0
  54406. },
  54407. draggable: true,
  54408. silent: true,
  54409. invisible: true,
  54410. drift: curry$5(doDrift, controller, cover, name),
  54411. ondragend: curry$5(trigger$1, controller, {
  54412. isEnd: true
  54413. })
  54414. }));
  54415. });
  54416. return cover;
  54417. }
  54418. function updateBaseRect(controller, cover, localRange, brushOption) {
  54419. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  54420. var handleSize = mathMax$5(lineWidth, MIN_RESIZE_LINE_WIDTH);
  54421. var x = localRange[0][0];
  54422. var y = localRange[1][0];
  54423. var xa = x - lineWidth / 2;
  54424. var ya = y - lineWidth / 2;
  54425. var x2 = localRange[0][1];
  54426. var y2 = localRange[1][1];
  54427. var x2a = x2 - handleSize + lineWidth / 2;
  54428. var y2a = y2 - handleSize + lineWidth / 2;
  54429. var width = x2 - x;
  54430. var height = y2 - y;
  54431. var widtha = width + lineWidth;
  54432. var heighta = height + lineWidth;
  54433. updateRectShape(controller, cover, 'main', x, y, width, height);
  54434. if (brushOption.transformable) {
  54435. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  54436. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  54437. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  54438. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  54439. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  54440. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  54441. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  54442. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  54443. }
  54444. }
  54445. function updateCommon$1(controller, cover) {
  54446. var brushOption = cover.__brushOption;
  54447. var transformable = brushOption.transformable;
  54448. var mainEl = cover.childAt(0);
  54449. mainEl.useStyle(makeStyle(brushOption));
  54450. mainEl.attr({
  54451. silent: !transformable,
  54452. cursor: transformable ? 'move' : 'default'
  54453. });
  54454. each$18(['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw'], function (name) {
  54455. var el = cover.childOfName(name);
  54456. var globalDir = getGlobalDirection(controller, name);
  54457. el && el.attr({
  54458. silent: !transformable,
  54459. invisible: !transformable,
  54460. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  54461. });
  54462. });
  54463. }
  54464. function updateRectShape(controller, cover, name, x, y, w, h) {
  54465. var el = cover.childOfName(name);
  54466. el && el.setShape(pointsToRect(clipByPanel(controller, cover, [[x, y], [x + w, y + h]])));
  54467. }
  54468. function makeStyle(brushOption) {
  54469. return defaults({
  54470. strokeNoScale: true
  54471. }, brushOption.brushStyle);
  54472. }
  54473. function formatRectRange(x, y, x2, y2) {
  54474. var min = [mathMin$5(x, x2), mathMin$5(y, y2)];
  54475. var max = [mathMax$5(x, x2), mathMax$5(y, y2)];
  54476. return [[min[0], max[0]], // x range
  54477. [min[1], max[1]] // y range
  54478. ];
  54479. }
  54480. function getTransform$1(controller) {
  54481. return getTransform(controller.group);
  54482. }
  54483. function getGlobalDirection(controller, localDirection) {
  54484. if (localDirection.length > 1) {
  54485. localDirection = localDirection.split('');
  54486. var globalDir = [getGlobalDirection(controller, localDirection[0]), getGlobalDirection(controller, localDirection[1])];
  54487. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  54488. return globalDir.join('');
  54489. } else {
  54490. var map$$1 = {
  54491. w: 'left',
  54492. e: 'right',
  54493. n: 'top',
  54494. s: 'bottom'
  54495. };
  54496. var inverseMap = {
  54497. left: 'w',
  54498. right: 'e',
  54499. top: 'n',
  54500. bottom: 's'
  54501. };
  54502. var globalDir = transformDirection(map$$1[localDirection], getTransform$1(controller));
  54503. return inverseMap[globalDir];
  54504. }
  54505. }
  54506. function driftRect(toRectRange, fromRectRange, controller, cover, name, dx, dy, e) {
  54507. var brushOption = cover.__brushOption;
  54508. var rectRange = toRectRange(brushOption.range);
  54509. var localDelta = toLocalDelta(controller, dx, dy);
  54510. each$18(name.split(''), function (namePart) {
  54511. var ind = DIRECTION_MAP[namePart];
  54512. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  54513. });
  54514. brushOption.range = fromRectRange(formatRectRange(rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]));
  54515. updateCoverAfterCreation(controller, cover);
  54516. trigger$1(controller, {
  54517. isEnd: false
  54518. });
  54519. }
  54520. function driftPolygon(controller, cover, dx, dy, e) {
  54521. var range = cover.__brushOption.range;
  54522. var localDelta = toLocalDelta(controller, dx, dy);
  54523. each$18(range, function (point) {
  54524. point[0] += localDelta[0];
  54525. point[1] += localDelta[1];
  54526. });
  54527. updateCoverAfterCreation(controller, cover);
  54528. trigger$1(controller, {
  54529. isEnd: false
  54530. });
  54531. }
  54532. function toLocalDelta(controller, dx, dy) {
  54533. var thisGroup = controller.group;
  54534. var localD = thisGroup.transformCoordToLocal(dx, dy);
  54535. var localZero = thisGroup.transformCoordToLocal(0, 0);
  54536. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  54537. }
  54538. function clipByPanel(controller, cover, data) {
  54539. var panel = getPanelByCover(controller, cover);
  54540. return panel && panel !== true ? panel.clipPath(data, controller._transform) : clone(data);
  54541. }
  54542. function pointsToRect(points) {
  54543. var xmin = mathMin$5(points[0][0], points[1][0]);
  54544. var ymin = mathMin$5(points[0][1], points[1][1]);
  54545. var xmax = mathMax$5(points[0][0], points[1][0]);
  54546. var ymax = mathMax$5(points[0][1], points[1][1]);
  54547. return {
  54548. x: xmin,
  54549. y: ymin,
  54550. width: xmax - xmin,
  54551. height: ymax - ymin
  54552. };
  54553. }
  54554. function resetCursor(controller, e, localCursorPoint) {
  54555. if ( // Check active
  54556. !controller._brushType // resetCursor should be always called when mouse is in zr area,
  54557. // but not called when mouse is out of zr area to avoid bad influence
  54558. // if `mousemove`, `mouseup` are triggered from `document` event.
  54559. || isOutsideZrArea(controller, e)) {
  54560. return;
  54561. }
  54562. var zr = controller._zr;
  54563. var covers = controller._covers;
  54564. var currPanel = getPanelByPoint(controller, e, localCursorPoint); // Check whether in covers.
  54565. if (!controller._dragging) {
  54566. for (var i = 0; i < covers.length; i++) {
  54567. var brushOption = covers[i].__brushOption;
  54568. if (currPanel && (currPanel === true || brushOption.panelId === currPanel.panelId) && coverRenderers[brushOption.brushType].contain(covers[i], localCursorPoint[0], localCursorPoint[1])) {
  54569. // Use cursor style set on cover.
  54570. return;
  54571. }
  54572. }
  54573. }
  54574. currPanel && zr.setCursorStyle('crosshair');
  54575. }
  54576. function preventDefault(e) {
  54577. var rawE = e.event;
  54578. rawE.preventDefault && rawE.preventDefault();
  54579. }
  54580. function mainShapeContain(cover, x, y) {
  54581. return cover.childOfName('main').contain(x, y);
  54582. }
  54583. function updateCoverByMouse(controller, e, localCursorPoint, isEnd) {
  54584. var creatingCover = controller._creatingCover;
  54585. var panel = controller._creatingPanel;
  54586. var thisBrushOption = controller._brushOption;
  54587. var eventParams;
  54588. controller._track.push(localCursorPoint.slice());
  54589. if (shouldShowCover(controller) || creatingCover) {
  54590. if (panel && !creatingCover) {
  54591. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  54592. var brushOption = clone(thisBrushOption);
  54593. brushOption.brushType = determineBrushType(brushOption.brushType, panel);
  54594. brushOption.panelId = panel === true ? null : panel.panelId;
  54595. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  54596. controller._covers.push(creatingCover);
  54597. }
  54598. if (creatingCover) {
  54599. var coverRenderer = coverRenderers[determineBrushType(controller._brushType, panel)];
  54600. var coverBrushOption = creatingCover.__brushOption;
  54601. coverBrushOption.range = coverRenderer.getCreatingRange(clipByPanel(controller, creatingCover, controller._track));
  54602. if (isEnd) {
  54603. endCreating(controller, creatingCover);
  54604. coverRenderer.updateCommon(controller, creatingCover);
  54605. }
  54606. updateCoverShape(controller, creatingCover);
  54607. eventParams = {
  54608. isEnd: isEnd
  54609. };
  54610. }
  54611. } else if (isEnd && thisBrushOption.brushMode === 'single' && thisBrushOption.removeOnClick) {
  54612. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  54613. // But a single click do not clear covers, because user may have casual
  54614. // clicks (for example, click on other component and do not expect covers
  54615. // disappear).
  54616. // Only some cover removed, trigger action, but not every click trigger action.
  54617. if (getPanelByPoint(controller, e, localCursorPoint) && clearCovers(controller)) {
  54618. eventParams = {
  54619. isEnd: isEnd,
  54620. removeOnClick: true
  54621. };
  54622. }
  54623. }
  54624. return eventParams;
  54625. }
  54626. function determineBrushType(brushType, panel) {
  54627. if (brushType === 'auto') {
  54628. return panel.defaultBrushType;
  54629. }
  54630. return brushType;
  54631. }
  54632. var pointerHandlers = {
  54633. mousedown: function (e) {
  54634. if (this._dragging) {
  54635. // In case some browser do not support globalOut,
  54636. // and release mose out side the browser.
  54637. handleDragEnd(this, e);
  54638. } else if (!e.target || !e.target.draggable) {
  54639. preventDefault(e);
  54640. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  54641. this._creatingCover = null;
  54642. var panel = this._creatingPanel = getPanelByPoint(this, e, localCursorPoint);
  54643. if (panel) {
  54644. this._dragging = true;
  54645. this._track = [localCursorPoint.slice()];
  54646. }
  54647. }
  54648. },
  54649. mousemove: function (e) {
  54650. var x = e.offsetX;
  54651. var y = e.offsetY;
  54652. var localCursorPoint = this.group.transformCoordToLocal(x, y);
  54653. resetCursor(this, e, localCursorPoint);
  54654. if (this._dragging) {
  54655. preventDefault(e);
  54656. var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);
  54657. eventParams && trigger$1(this, eventParams);
  54658. }
  54659. },
  54660. mouseup: function (e) {
  54661. handleDragEnd(this, e);
  54662. }
  54663. };
  54664. function handleDragEnd(controller, e) {
  54665. if (controller._dragging) {
  54666. preventDefault(e);
  54667. var x = e.offsetX;
  54668. var y = e.offsetY;
  54669. var localCursorPoint = controller.group.transformCoordToLocal(x, y);
  54670. var eventParams = updateCoverByMouse(controller, e, localCursorPoint, true);
  54671. controller._dragging = false;
  54672. controller._track = [];
  54673. controller._creatingCover = null; // trigger event shoule be at final, after procedure will be nested.
  54674. eventParams && trigger$1(controller, eventParams);
  54675. }
  54676. }
  54677. function isOutsideZrArea(controller, x, y) {
  54678. var zr = controller._zr;
  54679. return x < 0 || x > zr.getWidth() || y < 0 || y > zr.getHeight();
  54680. }
  54681. /**
  54682. * key: brushType
  54683. * @type {Object}
  54684. */
  54685. var coverRenderers = {
  54686. lineX: getLineRenderer(0),
  54687. lineY: getLineRenderer(1),
  54688. rect: {
  54689. createCover: function (controller, brushOption) {
  54690. return createBaseRectCover(curry$5(driftRect, function (range) {
  54691. return range;
  54692. }, function (range) {
  54693. return range;
  54694. }), controller, brushOption, ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw']);
  54695. },
  54696. getCreatingRange: function (localTrack) {
  54697. var ends = getTrackEnds(localTrack);
  54698. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  54699. },
  54700. updateCoverShape: function (controller, cover, localRange, brushOption) {
  54701. updateBaseRect(controller, cover, localRange, brushOption);
  54702. },
  54703. updateCommon: updateCommon$1,
  54704. contain: mainShapeContain
  54705. },
  54706. polygon: {
  54707. createCover: function (controller, brushOption) {
  54708. var cover = new Group(); // Do not use graphic.Polygon because graphic.Polyline do not close the
  54709. // border of the shape when drawing, which is a better experience for user.
  54710. cover.add(new Polyline({
  54711. name: 'main',
  54712. style: makeStyle(brushOption),
  54713. silent: true
  54714. }));
  54715. return cover;
  54716. },
  54717. getCreatingRange: function (localTrack) {
  54718. return localTrack;
  54719. },
  54720. endCreating: function (controller, cover) {
  54721. cover.remove(cover.childAt(0)); // Use graphic.Polygon close the shape.
  54722. cover.add(new Polygon({
  54723. name: 'main',
  54724. draggable: true,
  54725. drift: curry$5(driftPolygon, controller, cover),
  54726. ondragend: curry$5(trigger$1, controller, {
  54727. isEnd: true
  54728. })
  54729. }));
  54730. },
  54731. updateCoverShape: function (controller, cover, localRange, brushOption) {
  54732. cover.childAt(0).setShape({
  54733. points: clipByPanel(controller, cover, localRange)
  54734. });
  54735. },
  54736. updateCommon: updateCommon$1,
  54737. contain: mainShapeContain
  54738. }
  54739. };
  54740. function getLineRenderer(xyIndex) {
  54741. return {
  54742. createCover: function (controller, brushOption) {
  54743. return createBaseRectCover(curry$5(driftRect, function (range) {
  54744. var rectRange = [range, [0, 100]];
  54745. xyIndex && rectRange.reverse();
  54746. return rectRange;
  54747. }, function (rectRange) {
  54748. return rectRange[xyIndex];
  54749. }), controller, brushOption, [['w', 'e'], ['n', 's']][xyIndex]);
  54750. },
  54751. getCreatingRange: function (localTrack) {
  54752. var ends = getTrackEnds(localTrack);
  54753. var min = mathMin$5(ends[0][xyIndex], ends[1][xyIndex]);
  54754. var max = mathMax$5(ends[0][xyIndex], ends[1][xyIndex]);
  54755. return [min, max];
  54756. },
  54757. updateCoverShape: function (controller, cover, localRange, brushOption) {
  54758. var otherExtent; // If brushWidth not specified, fit the panel.
  54759. var panel = getPanelByCover(controller, cover);
  54760. if (panel !== true && panel.getLinearBrushOtherExtent) {
  54761. otherExtent = panel.getLinearBrushOtherExtent(xyIndex, controller._transform);
  54762. } else {
  54763. var zr = controller._zr;
  54764. otherExtent = [0, [zr.getWidth(), zr.getHeight()][1 - xyIndex]];
  54765. }
  54766. var rectRange = [localRange, otherExtent];
  54767. xyIndex && rectRange.reverse();
  54768. updateBaseRect(controller, cover, rectRange, brushOption);
  54769. },
  54770. updateCommon: updateCommon$1,
  54771. contain: mainShapeContain
  54772. };
  54773. }
  54774. /*
  54775. * Licensed to the Apache Software Foundation (ASF) under one
  54776. * or more contributor license agreements. See the NOTICE file
  54777. * distributed with this work for additional information
  54778. * regarding copyright ownership. The ASF licenses this file
  54779. * to you under the Apache License, Version 2.0 (the
  54780. * "License"); you may not use this file except in compliance
  54781. * with the License. You may obtain a copy of the License at
  54782. *
  54783. * http://www.apache.org/licenses/LICENSE-2.0
  54784. *
  54785. * Unless required by applicable law or agreed to in writing,
  54786. * software distributed under the License is distributed on an
  54787. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54788. * KIND, either express or implied. See the License for the
  54789. * specific language governing permissions and limitations
  54790. * under the License.
  54791. */
  54792. function makeRectPanelClipPath(rect) {
  54793. rect = normalizeRect(rect);
  54794. return function (localPoints, transform) {
  54795. return clipPointsByRect(localPoints, rect);
  54796. };
  54797. }
  54798. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  54799. rect = normalizeRect(rect);
  54800. return function (xyIndex) {
  54801. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  54802. var brushWidth = idx ? rect.width : rect.height;
  54803. var base = idx ? rect.x : rect.y;
  54804. return [base, base + (brushWidth || 0)];
  54805. };
  54806. }
  54807. function makeRectIsTargetByCursor(rect, api, targetModel) {
  54808. rect = normalizeRect(rect);
  54809. return function (e, localCursorPoint, transform) {
  54810. return rect.contain(localCursorPoint[0], localCursorPoint[1]) && !onIrrelevantElement(e, api, targetModel);
  54811. };
  54812. } // Consider width/height is negative.
  54813. function normalizeRect(rect) {
  54814. return BoundingRect.create(rect);
  54815. }
  54816. /*
  54817. * Licensed to the Apache Software Foundation (ASF) under one
  54818. * or more contributor license agreements. See the NOTICE file
  54819. * distributed with this work for additional information
  54820. * regarding copyright ownership. The ASF licenses this file
  54821. * to you under the Apache License, Version 2.0 (the
  54822. * "License"); you may not use this file except in compliance
  54823. * with the License. You may obtain a copy of the License at
  54824. *
  54825. * http://www.apache.org/licenses/LICENSE-2.0
  54826. *
  54827. * Unless required by applicable law or agreed to in writing,
  54828. * software distributed under the License is distributed on an
  54829. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54830. * KIND, either express or implied. See the License for the
  54831. * specific language governing permissions and limitations
  54832. * under the License.
  54833. */
  54834. var each$19 = each$1;
  54835. var indexOf$2 = indexOf;
  54836. var curry$6 = curry;
  54837. var COORD_CONVERTS = ['dataToPoint', 'pointToData']; // FIXME
  54838. // how to genarialize to more coordinate systems.
  54839. var INCLUDE_FINDER_MAIN_TYPES = ['grid', 'xAxis', 'yAxis', 'geo', 'graph', 'polar', 'radiusAxis', 'angleAxis', 'bmap'];
  54840. /**
  54841. * [option in constructor]:
  54842. * {
  54843. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  54844. * }
  54845. *
  54846. *
  54847. * [targetInfo]:
  54848. *
  54849. * There can be multiple axes in a single targetInfo. Consider the case
  54850. * of `grid` component, a targetInfo represents a grid which contains one or more
  54851. * cartesian and one or more axes. And consider the case of parallel system,
  54852. * which has multiple axes in a coordinate system.
  54853. * Can be {
  54854. * panelId: ...,
  54855. * coordSys: <a representitive cartesian in grid (first cartesian by default)>,
  54856. * coordSyses: all cartesians.
  54857. * gridModel: <grid component>
  54858. * xAxes: correspond to coordSyses on index
  54859. * yAxes: correspond to coordSyses on index
  54860. * }
  54861. * or {
  54862. * panelId: ...,
  54863. * coordSys: <geo coord sys>
  54864. * coordSyses: [<geo coord sys>]
  54865. * geoModel: <geo component>
  54866. * }
  54867. *
  54868. *
  54869. * [panelOpt]:
  54870. *
  54871. * Make from targetInfo. Input to BrushController.
  54872. * {
  54873. * panelId: ...,
  54874. * rect: ...
  54875. * }
  54876. *
  54877. *
  54878. * [area]:
  54879. *
  54880. * Generated by BrushController or user input.
  54881. * {
  54882. * panelId: Used to locate coordInfo directly. If user inpput, no panelId.
  54883. * brushType: determine how to convert to/from coord('rect' or 'polygon' or 'lineX/Y').
  54884. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  54885. * range: pixel range.
  54886. * coordRange: representitive coord range (the first one of coordRanges).
  54887. * coordRanges: <Array> coord ranges, used in multiple cartesian in one grid.
  54888. * }
  54889. */
  54890. /**
  54891. * @param {Object} option contains Index/Id/Name of xAxis/yAxis/geo/grid
  54892. * Each can be {number|Array.<number>}. like: {xAxisIndex: [3, 4]}
  54893. * @param {module:echarts/model/Global} ecModel
  54894. * @param {Object} [opt]
  54895. * @param {Array.<string>} [opt.include] include coordinate system types.
  54896. */
  54897. function BrushTargetManager(option, ecModel, opt) {
  54898. /**
  54899. * @private
  54900. * @type {Array.<Object>}
  54901. */
  54902. var targetInfoList = this._targetInfoList = [];
  54903. var info = {};
  54904. var foundCpts = parseFinder$1(ecModel, option);
  54905. each$19(targetInfoBuilders, function (builder, type) {
  54906. if (!opt || !opt.include || indexOf$2(opt.include, type) >= 0) {
  54907. builder(foundCpts, targetInfoList, info);
  54908. }
  54909. });
  54910. }
  54911. var proto$5 = BrushTargetManager.prototype;
  54912. proto$5.setOutputRanges = function (areas, ecModel) {
  54913. this.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  54914. (area.coordRanges || (area.coordRanges = [])).push(coordRange); // area.coordRange is the first of area.coordRanges
  54915. if (!area.coordRange) {
  54916. area.coordRange = coordRange; // In 'category' axis, coord to pixel is not reversible, so we can not
  54917. // rebuild range by coordRange accrately, which may bring trouble when
  54918. // brushing only one item. So we use __rangeOffset to rebuilding range
  54919. // by coordRange. And this it only used in brush component so it is no
  54920. // need to be adapted to coordRanges.
  54921. var result = coordConvert[area.brushType](0, coordSys, coordRange);
  54922. area.__rangeOffset = {
  54923. offset: diffProcessor[area.brushType](result.values, area.range, [1, 1]),
  54924. xyMinMax: result.xyMinMax
  54925. };
  54926. }
  54927. });
  54928. };
  54929. proto$5.matchOutputRanges = function (areas, ecModel, cb) {
  54930. each$19(areas, function (area) {
  54931. var targetInfo = this.findTargetInfo(area, ecModel);
  54932. if (targetInfo && targetInfo !== true) {
  54933. each$1(targetInfo.coordSyses, function (coordSys) {
  54934. var result = coordConvert[area.brushType](1, coordSys, area.range);
  54935. cb(area, result.values, coordSys, ecModel);
  54936. });
  54937. }
  54938. }, this);
  54939. };
  54940. proto$5.setInputRanges = function (areas, ecModel) {
  54941. each$19(areas, function (area) {
  54942. var targetInfo = this.findTargetInfo(area, ecModel);
  54943. area.range = area.range || []; // convert coordRange to global range and set panelId.
  54944. if (targetInfo && targetInfo !== true) {
  54945. area.panelId = targetInfo.panelId; // (1) area.range shoule always be calculate from coordRange but does
  54946. // not keep its original value, for the sake of the dataZoom scenario,
  54947. // where area.coordRange remains unchanged but area.range may be changed.
  54948. // (2) Only support converting one coordRange to pixel range in brush
  54949. // component. So do not consider `coordRanges`.
  54950. // (3) About __rangeOffset, see comment above.
  54951. var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
  54952. var rangeOffset = area.__rangeOffset;
  54953. area.range = rangeOffset ? diffProcessor[area.brushType](result.values, rangeOffset.offset, getScales(result.xyMinMax, rangeOffset.xyMinMax)) : result.values;
  54954. }
  54955. }, this);
  54956. };
  54957. proto$5.makePanelOpts = function (api, getDefaultBrushType) {
  54958. return map(this._targetInfoList, function (targetInfo) {
  54959. var rect = targetInfo.getPanelRect();
  54960. return {
  54961. panelId: targetInfo.panelId,
  54962. defaultBrushType: getDefaultBrushType && getDefaultBrushType(targetInfo),
  54963. clipPath: makeRectPanelClipPath(rect),
  54964. isTargetByCursor: makeRectIsTargetByCursor(rect, api, targetInfo.coordSysModel),
  54965. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect)
  54966. };
  54967. });
  54968. };
  54969. proto$5.controlSeries = function (area, seriesModel, ecModel) {
  54970. // Check whether area is bound in coord, and series do not belong to that coord.
  54971. // If do not do this check, some brush (like lineX) will controll all axes.
  54972. var targetInfo = this.findTargetInfo(area, ecModel);
  54973. return targetInfo === true || targetInfo && indexOf$2(targetInfo.coordSyses, seriesModel.coordinateSystem) >= 0;
  54974. };
  54975. /**
  54976. * If return Object, a coord found.
  54977. * If reutrn true, global found.
  54978. * Otherwise nothing found.
  54979. *
  54980. * @param {Object} area
  54981. * @param {Array} targetInfoList
  54982. * @return {Object|boolean}
  54983. */
  54984. proto$5.findTargetInfo = function (area, ecModel) {
  54985. var targetInfoList = this._targetInfoList;
  54986. var foundCpts = parseFinder$1(ecModel, area);
  54987. for (var i = 0; i < targetInfoList.length; i++) {
  54988. var targetInfo = targetInfoList[i];
  54989. var areaPanelId = area.panelId;
  54990. if (areaPanelId) {
  54991. if (targetInfo.panelId === areaPanelId) {
  54992. return targetInfo;
  54993. }
  54994. } else {
  54995. for (var i = 0; i < targetInfoMatchers.length; i++) {
  54996. if (targetInfoMatchers[i](foundCpts, targetInfo)) {
  54997. return targetInfo;
  54998. }
  54999. }
  55000. }
  55001. }
  55002. return true;
  55003. };
  55004. function formatMinMax(minMax) {
  55005. minMax[0] > minMax[1] && minMax.reverse();
  55006. return minMax;
  55007. }
  55008. function parseFinder$1(ecModel, option) {
  55009. return parseFinder(ecModel, option, {
  55010. includeMainTypes: INCLUDE_FINDER_MAIN_TYPES
  55011. });
  55012. }
  55013. var targetInfoBuilders = {
  55014. grid: function (foundCpts, targetInfoList) {
  55015. var xAxisModels = foundCpts.xAxisModels;
  55016. var yAxisModels = foundCpts.yAxisModels;
  55017. var gridModels = foundCpts.gridModels; // Remove duplicated.
  55018. var gridModelMap = createHashMap();
  55019. var xAxesHas = {};
  55020. var yAxesHas = {};
  55021. if (!xAxisModels && !yAxisModels && !gridModels) {
  55022. return;
  55023. }
  55024. each$19(xAxisModels, function (axisModel) {
  55025. var gridModel = axisModel.axis.grid.model;
  55026. gridModelMap.set(gridModel.id, gridModel);
  55027. xAxesHas[gridModel.id] = true;
  55028. });
  55029. each$19(yAxisModels, function (axisModel) {
  55030. var gridModel = axisModel.axis.grid.model;
  55031. gridModelMap.set(gridModel.id, gridModel);
  55032. yAxesHas[gridModel.id] = true;
  55033. });
  55034. each$19(gridModels, function (gridModel) {
  55035. gridModelMap.set(gridModel.id, gridModel);
  55036. xAxesHas[gridModel.id] = true;
  55037. yAxesHas[gridModel.id] = true;
  55038. });
  55039. gridModelMap.each(function (gridModel) {
  55040. var grid = gridModel.coordinateSystem;
  55041. var cartesians = [];
  55042. each$19(grid.getCartesians(), function (cartesian, index) {
  55043. if (indexOf$2(xAxisModels, cartesian.getAxis('x').model) >= 0 || indexOf$2(yAxisModels, cartesian.getAxis('y').model) >= 0) {
  55044. cartesians.push(cartesian);
  55045. }
  55046. });
  55047. targetInfoList.push({
  55048. panelId: 'grid--' + gridModel.id,
  55049. gridModel: gridModel,
  55050. coordSysModel: gridModel,
  55051. // Use the first one as the representitive coordSys.
  55052. coordSys: cartesians[0],
  55053. coordSyses: cartesians,
  55054. getPanelRect: panelRectBuilder.grid,
  55055. xAxisDeclared: xAxesHas[gridModel.id],
  55056. yAxisDeclared: yAxesHas[gridModel.id]
  55057. });
  55058. });
  55059. },
  55060. geo: function (foundCpts, targetInfoList) {
  55061. each$19(foundCpts.geoModels, function (geoModel) {
  55062. var coordSys = geoModel.coordinateSystem;
  55063. targetInfoList.push({
  55064. panelId: 'geo--' + geoModel.id,
  55065. geoModel: geoModel,
  55066. coordSysModel: geoModel,
  55067. coordSys: coordSys,
  55068. coordSyses: [coordSys],
  55069. getPanelRect: panelRectBuilder.geo
  55070. });
  55071. });
  55072. }
  55073. };
  55074. var targetInfoMatchers = [// grid
  55075. function (foundCpts, targetInfo) {
  55076. var xAxisModel = foundCpts.xAxisModel;
  55077. var yAxisModel = foundCpts.yAxisModel;
  55078. var gridModel = foundCpts.gridModel;
  55079. !gridModel && xAxisModel && (gridModel = xAxisModel.axis.grid.model);
  55080. !gridModel && yAxisModel && (gridModel = yAxisModel.axis.grid.model);
  55081. return gridModel && gridModel === targetInfo.gridModel;
  55082. }, // geo
  55083. function (foundCpts, targetInfo) {
  55084. var geoModel = foundCpts.geoModel;
  55085. return geoModel && geoModel === targetInfo.geoModel;
  55086. }];
  55087. var panelRectBuilder = {
  55088. grid: function () {
  55089. // grid is not Transformable.
  55090. return this.coordSys.grid.getRect().clone();
  55091. },
  55092. geo: function () {
  55093. var coordSys = this.coordSys;
  55094. var rect = coordSys.getBoundingRect().clone(); // geo roam and zoom transform
  55095. rect.applyTransform(getTransform(coordSys));
  55096. return rect;
  55097. }
  55098. };
  55099. var coordConvert = {
  55100. lineX: curry$6(axisConvert, 0),
  55101. lineY: curry$6(axisConvert, 1),
  55102. rect: function (to, coordSys, rangeOrCoordRange) {
  55103. var xminymin = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]]);
  55104. var xmaxymax = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]]);
  55105. var values = [formatMinMax([xminymin[0], xmaxymax[0]]), formatMinMax([xminymin[1], xmaxymax[1]])];
  55106. return {
  55107. values: values,
  55108. xyMinMax: values
  55109. };
  55110. },
  55111. polygon: function (to, coordSys, rangeOrCoordRange) {
  55112. var xyMinMax = [[Infinity, -Infinity], [Infinity, -Infinity]];
  55113. var values = map(rangeOrCoordRange, function (item) {
  55114. var p = coordSys[COORD_CONVERTS[to]](item);
  55115. xyMinMax[0][0] = Math.min(xyMinMax[0][0], p[0]);
  55116. xyMinMax[1][0] = Math.min(xyMinMax[1][0], p[1]);
  55117. xyMinMax[0][1] = Math.max(xyMinMax[0][1], p[0]);
  55118. xyMinMax[1][1] = Math.max(xyMinMax[1][1], p[1]);
  55119. return p;
  55120. });
  55121. return {
  55122. values: values,
  55123. xyMinMax: xyMinMax
  55124. };
  55125. }
  55126. };
  55127. function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
  55128. var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
  55129. var values = formatMinMax(map([0, 1], function (i) {
  55130. return to ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i])) : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
  55131. }));
  55132. var xyMinMax = [];
  55133. xyMinMax[axisNameIndex] = values;
  55134. xyMinMax[1 - axisNameIndex] = [NaN, NaN];
  55135. return {
  55136. values: values,
  55137. xyMinMax: xyMinMax
  55138. };
  55139. }
  55140. var diffProcessor = {
  55141. lineX: curry$6(axisDiffProcessor, 0),
  55142. lineY: curry$6(axisDiffProcessor, 1),
  55143. rect: function (values, refer, scales) {
  55144. return [[values[0][0] - scales[0] * refer[0][0], values[0][1] - scales[0] * refer[0][1]], [values[1][0] - scales[1] * refer[1][0], values[1][1] - scales[1] * refer[1][1]]];
  55145. },
  55146. polygon: function (values, refer, scales) {
  55147. return map(values, function (item, idx) {
  55148. return [item[0] - scales[0] * refer[idx][0], item[1] - scales[1] * refer[idx][1]];
  55149. });
  55150. }
  55151. };
  55152. function axisDiffProcessor(axisNameIndex, values, refer, scales) {
  55153. return [values[0] - scales[axisNameIndex] * refer[0], values[1] - scales[axisNameIndex] * refer[1]];
  55154. } // We have to process scale caused by dataZoom manually,
  55155. // although it might be not accurate.
  55156. function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
  55157. var sizeCurr = getSize(xyMinMaxCurr);
  55158. var sizeOrigin = getSize(xyMinMaxOrigin);
  55159. var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
  55160. isNaN(scales[0]) && (scales[0] = 1);
  55161. isNaN(scales[1]) && (scales[1] = 1);
  55162. return scales;
  55163. }
  55164. function getSize(xyMinMax) {
  55165. return xyMinMax ? [xyMinMax[0][1] - xyMinMax[0][0], xyMinMax[1][1] - xyMinMax[1][0]] : [NaN, NaN];
  55166. }
  55167. /*
  55168. * Licensed to the Apache Software Foundation (ASF) under one
  55169. * or more contributor license agreements. See the NOTICE file
  55170. * distributed with this work for additional information
  55171. * regarding copyright ownership. The ASF licenses this file
  55172. * to you under the Apache License, Version 2.0 (the
  55173. * "License"); you may not use this file except in compliance
  55174. * with the License. You may obtain a copy of the License at
  55175. *
  55176. * http://www.apache.org/licenses/LICENSE-2.0
  55177. *
  55178. * Unless required by applicable law or agreed to in writing,
  55179. * software distributed under the License is distributed on an
  55180. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55181. * KIND, either express or implied. See the License for the
  55182. * specific language governing permissions and limitations
  55183. * under the License.
  55184. */
  55185. var each$20 = each$1;
  55186. var ATTR$2 = '\0_ec_hist_store';
  55187. /**
  55188. * @param {module:echarts/model/Global} ecModel
  55189. * @param {Object} newSnapshot {dataZoomId, batch: [payloadInfo, ...]}
  55190. */
  55191. function push(ecModel, newSnapshot) {
  55192. var store = giveStore$1(ecModel); // If previous dataZoom can not be found,
  55193. // complete an range with current range.
  55194. each$20(newSnapshot, function (batchItem, dataZoomId) {
  55195. var i = store.length - 1;
  55196. for (; i >= 0; i--) {
  55197. var snapshot = store[i];
  55198. if (snapshot[dataZoomId]) {
  55199. break;
  55200. }
  55201. }
  55202. if (i < 0) {
  55203. // No origin range set, create one by current range.
  55204. var dataZoomModel = ecModel.queryComponents({
  55205. mainType: 'dataZoom',
  55206. subType: 'select',
  55207. id: dataZoomId
  55208. })[0];
  55209. if (dataZoomModel) {
  55210. var percentRange = dataZoomModel.getPercentRange();
  55211. store[0][dataZoomId] = {
  55212. dataZoomId: dataZoomId,
  55213. start: percentRange[0],
  55214. end: percentRange[1]
  55215. };
  55216. }
  55217. }
  55218. });
  55219. store.push(newSnapshot);
  55220. }
  55221. /**
  55222. * @param {module:echarts/model/Global} ecModel
  55223. * @return {Object} snapshot
  55224. */
  55225. function pop(ecModel) {
  55226. var store = giveStore$1(ecModel);
  55227. var head = store[store.length - 1];
  55228. store.length > 1 && store.pop(); // Find top for all dataZoom.
  55229. var snapshot = {};
  55230. each$20(head, function (batchItem, dataZoomId) {
  55231. for (var i = store.length - 1; i >= 0; i--) {
  55232. var batchItem = store[i][dataZoomId];
  55233. if (batchItem) {
  55234. snapshot[dataZoomId] = batchItem;
  55235. break;
  55236. }
  55237. }
  55238. });
  55239. return snapshot;
  55240. }
  55241. /**
  55242. * @param {module:echarts/model/Global} ecModel
  55243. */
  55244. function clear$1(ecModel) {
  55245. ecModel[ATTR$2] = null;
  55246. }
  55247. /**
  55248. * @param {module:echarts/model/Global} ecModel
  55249. * @return {number} records. always >= 1.
  55250. */
  55251. function count(ecModel) {
  55252. return giveStore$1(ecModel).length;
  55253. }
  55254. /**
  55255. * [{key: dataZoomId, value: {dataZoomId, range}}, ...]
  55256. * History length of each dataZoom may be different.
  55257. * this._history[0] is used to store origin range.
  55258. * @type {Array.<Object>}
  55259. */
  55260. function giveStore$1(ecModel) {
  55261. var store = ecModel[ATTR$2];
  55262. if (!store) {
  55263. store = ecModel[ATTR$2] = [{}];
  55264. }
  55265. return store;
  55266. }
  55267. /*
  55268. * Licensed to the Apache Software Foundation (ASF) under one
  55269. * or more contributor license agreements. See the NOTICE file
  55270. * distributed with this work for additional information
  55271. * regarding copyright ownership. The ASF licenses this file
  55272. * to you under the Apache License, Version 2.0 (the
  55273. * "License"); you may not use this file except in compliance
  55274. * with the License. You may obtain a copy of the License at
  55275. *
  55276. * http://www.apache.org/licenses/LICENSE-2.0
  55277. *
  55278. * Unless required by applicable law or agreed to in writing,
  55279. * software distributed under the License is distributed on an
  55280. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55281. * KIND, either express or implied. See the License for the
  55282. * specific language governing permissions and limitations
  55283. * under the License.
  55284. */
  55285. DataZoomModel.extend({
  55286. type: 'dataZoom.select'
  55287. });
  55288. /*
  55289. * Licensed to the Apache Software Foundation (ASF) under one
  55290. * or more contributor license agreements. See the NOTICE file
  55291. * distributed with this work for additional information
  55292. * regarding copyright ownership. The ASF licenses this file
  55293. * to you under the Apache License, Version 2.0 (the
  55294. * "License"); you may not use this file except in compliance
  55295. * with the License. You may obtain a copy of the License at
  55296. *
  55297. * http://www.apache.org/licenses/LICENSE-2.0
  55298. *
  55299. * Unless required by applicable law or agreed to in writing,
  55300. * software distributed under the License is distributed on an
  55301. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55302. * KIND, either express or implied. See the License for the
  55303. * specific language governing permissions and limitations
  55304. * under the License.
  55305. */
  55306. DataZoomView.extend({
  55307. type: 'dataZoom.select'
  55308. });
  55309. /*
  55310. * Licensed to the Apache Software Foundation (ASF) under one
  55311. * or more contributor license agreements. See the NOTICE file
  55312. * distributed with this work for additional information
  55313. * regarding copyright ownership. The ASF licenses this file
  55314. * to you under the Apache License, Version 2.0 (the
  55315. * "License"); you may not use this file except in compliance
  55316. * with the License. You may obtain a copy of the License at
  55317. *
  55318. * http://www.apache.org/licenses/LICENSE-2.0
  55319. *
  55320. * Unless required by applicable law or agreed to in writing,
  55321. * software distributed under the License is distributed on an
  55322. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55323. * KIND, either express or implied. See the License for the
  55324. * specific language governing permissions and limitations
  55325. * under the License.
  55326. */
  55327. /**
  55328. * Only work for toolbox dataZoom. User
  55329. * MUST NOT import this module directly.
  55330. */
  55331. /*
  55332. * Licensed to the Apache Software Foundation (ASF) under one
  55333. * or more contributor license agreements. See the NOTICE file
  55334. * distributed with this work for additional information
  55335. * regarding copyright ownership. The ASF licenses this file
  55336. * to you under the Apache License, Version 2.0 (the
  55337. * "License"); you may not use this file except in compliance
  55338. * with the License. You may obtain a copy of the License at
  55339. *
  55340. * http://www.apache.org/licenses/LICENSE-2.0
  55341. *
  55342. * Unless required by applicable law or agreed to in writing,
  55343. * software distributed under the License is distributed on an
  55344. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55345. * KIND, either express or implied. See the License for the
  55346. * specific language governing permissions and limitations
  55347. * under the License.
  55348. */
  55349. var dataZoomLang = lang.toolbox.dataZoom;
  55350. var each$17 = each$1; // Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
  55351. var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
  55352. function DataZoom(model, ecModel, api) {
  55353. /**
  55354. * @private
  55355. * @type {module:echarts/component/helper/BrushController}
  55356. */
  55357. (this._brushController = new BrushController(api.getZr())).on('brush', bind(this._onBrush, this)).mount();
  55358. /**
  55359. * @private
  55360. * @type {boolean}
  55361. */
  55362. this._isZoomActive;
  55363. }
  55364. DataZoom.defaultOption = {
  55365. show: true,
  55366. filterMode: 'filter',
  55367. // Icon group
  55368. icon: {
  55369. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  55370. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  55371. },
  55372. // `zoom`, `back`
  55373. title: clone(dataZoomLang.title)
  55374. };
  55375. var proto$4 = DataZoom.prototype;
  55376. proto$4.render = function (featureModel, ecModel, api, payload) {
  55377. this.model = featureModel;
  55378. this.ecModel = ecModel;
  55379. this.api = api;
  55380. updateZoomBtnStatus(featureModel, ecModel, this, payload, api);
  55381. updateBackBtnStatus(featureModel, ecModel);
  55382. };
  55383. proto$4.onclick = function (ecModel, api, type) {
  55384. handlers[type].call(this);
  55385. };
  55386. proto$4.remove = function (ecModel, api) {
  55387. this._brushController.unmount();
  55388. };
  55389. proto$4.dispose = function (ecModel, api) {
  55390. this._brushController.dispose();
  55391. };
  55392. /**
  55393. * @private
  55394. */
  55395. var handlers = {
  55396. zoom: function () {
  55397. var nextActive = !this._isZoomActive;
  55398. this.api.dispatchAction({
  55399. type: 'takeGlobalCursor',
  55400. key: 'dataZoomSelect',
  55401. dataZoomSelectActive: nextActive
  55402. });
  55403. },
  55404. back: function () {
  55405. this._dispatchZoomAction(pop(this.ecModel));
  55406. }
  55407. };
  55408. /**
  55409. * @private
  55410. */
  55411. proto$4._onBrush = function (areas, opt) {
  55412. if (!opt.isEnd || !areas.length) {
  55413. return;
  55414. }
  55415. var snapshot = {};
  55416. var ecModel = this.ecModel;
  55417. this._brushController.updateCovers([]); // remove cover
  55418. var brushTargetManager = new BrushTargetManager(retrieveAxisSetting(this.model.option), ecModel, {
  55419. include: ['grid']
  55420. });
  55421. brushTargetManager.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  55422. if (coordSys.type !== 'cartesian2d') {
  55423. return;
  55424. }
  55425. var brushType = area.brushType;
  55426. if (brushType === 'rect') {
  55427. setBatch('x', coordSys, coordRange[0]);
  55428. setBatch('y', coordSys, coordRange[1]);
  55429. } else {
  55430. setBatch({
  55431. lineX: 'x',
  55432. lineY: 'y'
  55433. }[brushType], coordSys, coordRange);
  55434. }
  55435. });
  55436. push(ecModel, snapshot);
  55437. this._dispatchZoomAction(snapshot);
  55438. function setBatch(dimName, coordSys, minMax) {
  55439. var axis = coordSys.getAxis(dimName);
  55440. var axisModel = axis.model;
  55441. var dataZoomModel = findDataZoom(dimName, axisModel, ecModel); // Restrict range.
  55442. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy(axisModel).getMinMaxSpan();
  55443. if (minMaxSpan.minValueSpan != null || minMaxSpan.maxValueSpan != null) {
  55444. minMax = sliderMove(0, minMax.slice(), axis.scale.getExtent(), 0, minMaxSpan.minValueSpan, minMaxSpan.maxValueSpan);
  55445. }
  55446. dataZoomModel && (snapshot[dataZoomModel.id] = {
  55447. dataZoomId: dataZoomModel.id,
  55448. startValue: minMax[0],
  55449. endValue: minMax[1]
  55450. });
  55451. }
  55452. function findDataZoom(dimName, axisModel, ecModel) {
  55453. var found;
  55454. ecModel.eachComponent({
  55455. mainType: 'dataZoom',
  55456. subType: 'select'
  55457. }, function (dzModel) {
  55458. var has = dzModel.getAxisModel(dimName, axisModel.componentIndex);
  55459. has && (found = dzModel);
  55460. });
  55461. return found;
  55462. }
  55463. };
  55464. /**
  55465. * @private
  55466. */
  55467. proto$4._dispatchZoomAction = function (snapshot) {
  55468. var batch = []; // Convert from hash map to array.
  55469. each$17(snapshot, function (batchItem, dataZoomId) {
  55470. batch.push(clone(batchItem));
  55471. });
  55472. batch.length && this.api.dispatchAction({
  55473. type: 'dataZoom',
  55474. from: this.uid,
  55475. batch: batch
  55476. });
  55477. };
  55478. function retrieveAxisSetting(option) {
  55479. var setting = {}; // Compatible with previous setting: null => all axis, false => no axis.
  55480. each$1(['xAxisIndex', 'yAxisIndex'], function (name) {
  55481. setting[name] = option[name];
  55482. setting[name] == null && (setting[name] = 'all');
  55483. (setting[name] === false || setting[name] === 'none') && (setting[name] = []);
  55484. });
  55485. return setting;
  55486. }
  55487. function updateBackBtnStatus(featureModel, ecModel) {
  55488. featureModel.setIconStatus('back', count(ecModel) > 1 ? 'emphasis' : 'normal');
  55489. }
  55490. function updateZoomBtnStatus(featureModel, ecModel, view, payload, api) {
  55491. var zoomActive = view._isZoomActive;
  55492. if (payload && payload.type === 'takeGlobalCursor') {
  55493. zoomActive = payload.key === 'dataZoomSelect' ? payload.dataZoomSelectActive : false;
  55494. }
  55495. view._isZoomActive = zoomActive;
  55496. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  55497. var brushTargetManager = new BrushTargetManager(retrieveAxisSetting(featureModel.option), ecModel, {
  55498. include: ['grid']
  55499. });
  55500. view._brushController.setPanels(brushTargetManager.makePanelOpts(api, function (targetInfo) {
  55501. return targetInfo.xAxisDeclared && !targetInfo.yAxisDeclared ? 'lineX' : !targetInfo.xAxisDeclared && targetInfo.yAxisDeclared ? 'lineY' : 'rect';
  55502. })).enableBrush(zoomActive ? {
  55503. brushType: 'auto',
  55504. brushStyle: {
  55505. // FIXME user customized?
  55506. lineWidth: 0,
  55507. fill: 'rgba(0,0,0,0.2)'
  55508. }
  55509. } : false);
  55510. }
  55511. register$2('dataZoom', DataZoom); // Create special dataZoom option for select
  55512. // FIXME consider the case of merge option, where axes options are not exists.
  55513. registerPreprocessor(function (option) {
  55514. if (!option) {
  55515. return;
  55516. }
  55517. var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
  55518. if (!isArray(dataZoomOpts)) {
  55519. option.dataZoom = dataZoomOpts = [dataZoomOpts];
  55520. }
  55521. var toolboxOpt = option.toolbox;
  55522. if (toolboxOpt) {
  55523. // Assume there is only one toolbox
  55524. if (isArray(toolboxOpt)) {
  55525. toolboxOpt = toolboxOpt[0];
  55526. }
  55527. if (toolboxOpt && toolboxOpt.feature) {
  55528. var dataZoomOpt = toolboxOpt.feature.dataZoom; // FIXME: If add dataZoom when setOption in merge mode,
  55529. // no axis info to be added. See `test/dataZoom-extreme.html`
  55530. addForAxis('xAxis', dataZoomOpt);
  55531. addForAxis('yAxis', dataZoomOpt);
  55532. }
  55533. }
  55534. function addForAxis(axisName, dataZoomOpt) {
  55535. if (!dataZoomOpt) {
  55536. return;
  55537. } // Try not to modify model, because it is not merged yet.
  55538. var axisIndicesName = axisName + 'Index';
  55539. var givenAxisIndices = dataZoomOpt[axisIndicesName];
  55540. if (givenAxisIndices != null && givenAxisIndices !== 'all' && !isArray(givenAxisIndices)) {
  55541. givenAxisIndices = givenAxisIndices === false || givenAxisIndices === 'none' ? [] : [givenAxisIndices];
  55542. }
  55543. forEachComponent(axisName, function (axisOpt, axisIndex) {
  55544. if (givenAxisIndices != null && givenAxisIndices !== 'all' && indexOf(givenAxisIndices, axisIndex) === -1) {
  55545. return;
  55546. }
  55547. var newOpt = {
  55548. type: 'select',
  55549. $fromToolbox: true,
  55550. // Default to be filter
  55551. filterMode: dataZoomOpt.filterMode || 'filter',
  55552. // Id for merge mapping.
  55553. id: DATA_ZOOM_ID_BASE + axisName + axisIndex
  55554. }; // FIXME
  55555. // Only support one axis now.
  55556. newOpt[axisIndicesName] = axisIndex;
  55557. dataZoomOpts.push(newOpt);
  55558. });
  55559. }
  55560. function forEachComponent(mainType, cb) {
  55561. var opts = option[mainType];
  55562. if (!isArray(opts)) {
  55563. opts = opts ? [opts] : [];
  55564. }
  55565. each$17(opts, cb);
  55566. }
  55567. });
  55568. /*
  55569. * Licensed to the Apache Software Foundation (ASF) under one
  55570. * or more contributor license agreements. See the NOTICE file
  55571. * distributed with this work for additional information
  55572. * regarding copyright ownership. The ASF licenses this file
  55573. * to you under the Apache License, Version 2.0 (the
  55574. * "License"); you may not use this file except in compliance
  55575. * with the License. You may obtain a copy of the License at
  55576. *
  55577. * http://www.apache.org/licenses/LICENSE-2.0
  55578. *
  55579. * Unless required by applicable law or agreed to in writing,
  55580. * software distributed under the License is distributed on an
  55581. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55582. * KIND, either express or implied. See the License for the
  55583. * specific language governing permissions and limitations
  55584. * under the License.
  55585. */
  55586. var restoreLang = lang.toolbox.restore;
  55587. function Restore(model) {
  55588. this.model = model;
  55589. }
  55590. Restore.defaultOption = {
  55591. show: true,
  55592. /* eslint-disable */
  55593. icon: 'M3.8,33.4 M47,18.9h9.8V8.7 M56.3,20.1 C52.1,9,40.5,0.6,26.8,2.1C12.6,3.7,1.6,16.2,2.1,30.6 M13,41.1H3.1v10.2 M3.7,39.9c4.2,11.1,15.8,19.5,29.5,18 c14.2-1.6,25.2-14.1,24.7-28.5',
  55594. /* eslint-enable */
  55595. title: restoreLang.title
  55596. };
  55597. var proto$6 = Restore.prototype;
  55598. proto$6.onclick = function (ecModel, api, type) {
  55599. clear$1(ecModel);
  55600. api.dispatchAction({
  55601. type: 'restore',
  55602. from: this.uid
  55603. });
  55604. };
  55605. register$2('restore', Restore);
  55606. registerAction({
  55607. type: 'restore',
  55608. event: 'restore',
  55609. update: 'prepareAndUpdate'
  55610. }, function (payload, ecModel) {
  55611. ecModel.resetOption('recreate');
  55612. });
  55613. /*
  55614. * Licensed to the Apache Software Foundation (ASF) under one
  55615. * or more contributor license agreements. See the NOTICE file
  55616. * distributed with this work for additional information
  55617. * regarding copyright ownership. The ASF licenses this file
  55618. * to you under the Apache License, Version 2.0 (the
  55619. * "License"); you may not use this file except in compliance
  55620. * with the License. You may obtain a copy of the License at
  55621. *
  55622. * http://www.apache.org/licenses/LICENSE-2.0
  55623. *
  55624. * Unless required by applicable law or agreed to in writing,
  55625. * software distributed under the License is distributed on an
  55626. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55627. * KIND, either express or implied. See the License for the
  55628. * specific language governing permissions and limitations
  55629. * under the License.
  55630. */
  55631. /*
  55632. * Licensed to the Apache Software Foundation (ASF) under one
  55633. * or more contributor license agreements. See the NOTICE file
  55634. * distributed with this work for additional information
  55635. * regarding copyright ownership. The ASF licenses this file
  55636. * to you under the Apache License, Version 2.0 (the
  55637. * "License"); you may not use this file except in compliance
  55638. * with the License. You may obtain a copy of the License at
  55639. *
  55640. * http://www.apache.org/licenses/LICENSE-2.0
  55641. *
  55642. * Unless required by applicable law or agreed to in writing,
  55643. * software distributed under the License is distributed on an
  55644. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55645. * KIND, either express or implied. See the License for the
  55646. * specific language governing permissions and limitations
  55647. * under the License.
  55648. */
  55649. var _nonShapeGraphicElements = {
  55650. // Reserved but not supported in graphic component.
  55651. path: null,
  55652. compoundPath: null,
  55653. // Supported in graphic component.
  55654. group: Group,
  55655. image: ZImage,
  55656. text: Text
  55657. }; // -------------
  55658. // Preprocessor
  55659. // -------------
  55660. registerPreprocessor(function (option) {
  55661. var graphicOption = option.graphic; // Convert
  55662. // {graphic: [{left: 10, type: 'circle'}, ...]}
  55663. // or
  55664. // {graphic: {left: 10, type: 'circle'}}
  55665. // to
  55666. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  55667. if (isArray(graphicOption)) {
  55668. if (!graphicOption[0] || !graphicOption[0].elements) {
  55669. option.graphic = [{
  55670. elements: graphicOption
  55671. }];
  55672. } else {
  55673. // Only one graphic instance can be instantiated. (We dont
  55674. // want that too many views are created in echarts._viewMap)
  55675. option.graphic = [option.graphic[0]];
  55676. }
  55677. } else if (graphicOption && !graphicOption.elements) {
  55678. option.graphic = [{
  55679. elements: [graphicOption]
  55680. }];
  55681. }
  55682. }); // ------
  55683. // Model
  55684. // ------
  55685. var GraphicModel = extendComponentModel({
  55686. type: 'graphic',
  55687. defaultOption: {
  55688. // Extra properties for each elements:
  55689. //
  55690. // left/right/top/bottom: (like 12, '22%', 'center', default undefined)
  55691. // If left/rigth is set, shape.x/shape.cx/position will not be used.
  55692. // If top/bottom is set, shape.y/shape.cy/position will not be used.
  55693. // This mechanism is useful when you want to position a group/element
  55694. // against the right side or the center of this container.
  55695. //
  55696. // width/height: (can only be pixel value, default 0)
  55697. // Only be used to specify contianer(group) size, if needed. And
  55698. // can not be percentage value (like '33%'). See the reason in the
  55699. // layout algorithm below.
  55700. //
  55701. // bounding: (enum: 'all' (default) | 'raw')
  55702. // Specify how to calculate boundingRect when locating.
  55703. // 'all': Get uioned and transformed boundingRect
  55704. // from both itself and its descendants.
  55705. // This mode simplies confining a group of elements in the bounding
  55706. // of their ancester container (e.g., using 'right: 0').
  55707. // 'raw': Only use the boundingRect of itself and before transformed.
  55708. // This mode is similar to css behavior, which is useful when you
  55709. // want an element to be able to overflow its container. (Consider
  55710. // a rotated circle needs to be located in a corner.)
  55711. // info: custom info. enables user to mount some info on elements and use them
  55712. // in event handlers. Update them only when user specified, otherwise, remain.
  55713. // Note: elements is always behind its ancestors in this elements array.
  55714. elements: [],
  55715. parentId: null
  55716. },
  55717. /**
  55718. * Save el options for the sake of the performance (only update modified graphics).
  55719. * The order is the same as those in option. (ancesters -> descendants)
  55720. *
  55721. * @private
  55722. * @type {Array.<Object>}
  55723. */
  55724. _elOptionsToUpdate: null,
  55725. /**
  55726. * @override
  55727. */
  55728. mergeOption: function (option) {
  55729. // Prevent default merge to elements
  55730. var elements = this.option.elements;
  55731. this.option.elements = null;
  55732. GraphicModel.superApply(this, 'mergeOption', arguments);
  55733. this.option.elements = elements;
  55734. },
  55735. /**
  55736. * @override
  55737. */
  55738. optionUpdated: function (newOption, isInit) {
  55739. var thisOption = this.option;
  55740. var newList = (isInit ? thisOption : newOption).elements;
  55741. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  55742. var flattenedList = [];
  55743. this._flatten(newList, flattenedList);
  55744. var mappingResult = mappingToExists(existList, flattenedList);
  55745. makeIdAndName(mappingResult); // Clear elOptionsToUpdate
  55746. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  55747. each$1(mappingResult, function (resultItem, index) {
  55748. var newElOption = resultItem.option;
  55749. if (!newElOption) {
  55750. return;
  55751. }
  55752. elOptionsToUpdate.push(newElOption);
  55753. setKeyInfoToNewElOption(resultItem, newElOption);
  55754. mergeNewElOptionToExist(existList, index, newElOption);
  55755. setLayoutInfoToExist(existList[index], newElOption);
  55756. }, this); // Clean
  55757. for (var i = existList.length - 1; i >= 0; i--) {
  55758. if (existList[i] == null) {
  55759. existList.splice(i, 1);
  55760. } else {
  55761. // $action should be volatile, otherwise option gotten from
  55762. // `getOption` will contain unexpected $action.
  55763. delete existList[i].$action;
  55764. }
  55765. }
  55766. },
  55767. /**
  55768. * Convert
  55769. * [{
  55770. * type: 'group',
  55771. * id: 'xx',
  55772. * children: [{type: 'circle'}, {type: 'polygon'}]
  55773. * }]
  55774. * to
  55775. * [
  55776. * {type: 'group', id: 'xx'},
  55777. * {type: 'circle', parentId: 'xx'},
  55778. * {type: 'polygon', parentId: 'xx'}
  55779. * ]
  55780. *
  55781. * @private
  55782. * @param {Array.<Object>} optionList option list
  55783. * @param {Array.<Object>} result result of flatten
  55784. * @param {Object} parentOption parent option
  55785. */
  55786. _flatten: function (optionList, result, parentOption) {
  55787. each$1(optionList, function (option) {
  55788. if (!option) {
  55789. return;
  55790. }
  55791. if (parentOption) {
  55792. option.parentOption = parentOption;
  55793. }
  55794. result.push(option);
  55795. var children = option.children;
  55796. if (option.type === 'group' && children) {
  55797. this._flatten(children, result, option);
  55798. } // Deleting for JSON output, and for not affecting group creation.
  55799. delete option.children;
  55800. }, this);
  55801. },
  55802. // FIXME
  55803. // Pass to view using payload? setOption has a payload?
  55804. useElOptionsToUpdate: function () {
  55805. var els = this._elOptionsToUpdate; // Clear to avoid render duplicately when zooming.
  55806. this._elOptionsToUpdate = null;
  55807. return els;
  55808. }
  55809. }); // -----
  55810. // View
  55811. // -----
  55812. extendComponentView({
  55813. type: 'graphic',
  55814. /**
  55815. * @override
  55816. */
  55817. init: function (ecModel, api) {
  55818. /**
  55819. * @private
  55820. * @type {module:zrender/core/util.HashMap}
  55821. */
  55822. this._elMap = createHashMap();
  55823. /**
  55824. * @private
  55825. * @type {module:echarts/graphic/GraphicModel}
  55826. */
  55827. this._lastGraphicModel;
  55828. },
  55829. /**
  55830. * @override
  55831. */
  55832. render: function (graphicModel, ecModel, api) {
  55833. // Having leveraged between use cases and algorithm complexity, a very
  55834. // simple layout mechanism is used:
  55835. // The size(width/height) can be determined by itself or its parent (not
  55836. // implemented yet), but can not by its children. (Top-down travel)
  55837. // The location(x/y) can be determined by the bounding rect of itself
  55838. // (can including its descendants or not) and the size of its parent.
  55839. // (Bottom-up travel)
  55840. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  55841. // view will be reused.
  55842. if (graphicModel !== this._lastGraphicModel) {
  55843. this._clear();
  55844. }
  55845. this._lastGraphicModel = graphicModel;
  55846. this._updateElements(graphicModel);
  55847. this._relocate(graphicModel, api);
  55848. },
  55849. /**
  55850. * Update graphic elements.
  55851. *
  55852. * @private
  55853. * @param {Object} graphicModel graphic model
  55854. */
  55855. _updateElements: function (graphicModel) {
  55856. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  55857. if (!elOptionsToUpdate) {
  55858. return;
  55859. }
  55860. var elMap = this._elMap;
  55861. var rootGroup = this.group; // Top-down tranverse to assign graphic settings to each elements.
  55862. each$1(elOptionsToUpdate, function (elOption) {
  55863. var $action = elOption.$action;
  55864. var id = elOption.id;
  55865. var existEl = elMap.get(id);
  55866. var parentId = elOption.parentId;
  55867. var targetElParent = parentId != null ? elMap.get(parentId) : rootGroup;
  55868. var elOptionStyle = elOption.style;
  55869. if (elOption.type === 'text' && elOptionStyle) {
  55870. // In top/bottom mode, textVerticalAlign should not be used, which cause
  55871. // inaccurately locating.
  55872. if (elOption.hv && elOption.hv[1]) {
  55873. elOptionStyle.textVerticalAlign = elOptionStyle.textBaseline = null;
  55874. } // Compatible with previous setting: both support fill and textFill,
  55875. // stroke and textStroke.
  55876. !elOptionStyle.hasOwnProperty('textFill') && elOptionStyle.fill && (elOptionStyle.textFill = elOptionStyle.fill);
  55877. !elOptionStyle.hasOwnProperty('textStroke') && elOptionStyle.stroke && (elOptionStyle.textStroke = elOptionStyle.stroke);
  55878. } // Remove unnecessary props to avoid potential problems.
  55879. var elOptionCleaned = getCleanedElOption(elOption); // For simple, do not support parent change, otherwise reorder is needed.
  55880. if (!$action || $action === 'merge') {
  55881. existEl ? existEl.attr(elOptionCleaned) : createEl$1(id, targetElParent, elOptionCleaned, elMap);
  55882. } else if ($action === 'replace') {
  55883. removeEl(existEl, elMap);
  55884. createEl$1(id, targetElParent, elOptionCleaned, elMap);
  55885. } else if ($action === 'remove') {
  55886. removeEl(existEl, elMap);
  55887. }
  55888. var el = elMap.get(id);
  55889. if (el) {
  55890. el.__ecGraphicWidthOption = elOption.width;
  55891. el.__ecGraphicHeightOption = elOption.height;
  55892. setEventData(el, graphicModel, elOption);
  55893. }
  55894. });
  55895. },
  55896. /**
  55897. * Locate graphic elements.
  55898. *
  55899. * @private
  55900. * @param {Object} graphicModel graphic model
  55901. * @param {module:echarts/ExtensionAPI} api extension API
  55902. */
  55903. _relocate: function (graphicModel, api) {
  55904. var elOptions = graphicModel.option.elements;
  55905. var rootGroup = this.group;
  55906. var elMap = this._elMap;
  55907. var apiWidth = api.getWidth();
  55908. var apiHeight = api.getHeight(); // Top-down to calculate percentage width/height of group
  55909. for (var i = 0; i < elOptions.length; i++) {
  55910. var elOption = elOptions[i];
  55911. var el = elMap.get(elOption.id);
  55912. if (!el || !el.isGroup) {
  55913. continue;
  55914. }
  55915. var parentEl = el.parent;
  55916. var isParentRoot = parentEl === rootGroup; // Like 'position:absolut' in css, default 0.
  55917. el.__ecGraphicWidth = parsePercent$1(el.__ecGraphicWidthOption, isParentRoot ? apiWidth : parentEl.__ecGraphicWidth) || 0;
  55918. el.__ecGraphicHeight = parsePercent$1(el.__ecGraphicHeightOption, isParentRoot ? apiHeight : parentEl.__ecGraphicHeight) || 0;
  55919. } // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  55920. for (var i = elOptions.length - 1; i >= 0; i--) {
  55921. var elOption = elOptions[i];
  55922. var el = elMap.get(elOption.id);
  55923. if (!el) {
  55924. continue;
  55925. }
  55926. var parentEl = el.parent;
  55927. var containerInfo = parentEl === rootGroup ? {
  55928. width: apiWidth,
  55929. height: apiHeight
  55930. } : {
  55931. width: parentEl.__ecGraphicWidth,
  55932. height: parentEl.__ecGraphicHeight
  55933. }; // PENDING
  55934. // Currently, when `bounding: 'all'`, the union bounding rect of the group
  55935. // does not include the rect of [0, 0, group.width, group.height], which
  55936. // is probably weird for users. Should we make a break change for it?
  55937. positionElement(el, elOption, containerInfo, null, {
  55938. hv: elOption.hv,
  55939. boundingMode: elOption.bounding
  55940. });
  55941. }
  55942. },
  55943. /**
  55944. * Clear all elements.
  55945. *
  55946. * @private
  55947. */
  55948. _clear: function () {
  55949. var elMap = this._elMap;
  55950. elMap.each(function (el) {
  55951. removeEl(el, elMap);
  55952. });
  55953. this._elMap = createHashMap();
  55954. },
  55955. /**
  55956. * @override
  55957. */
  55958. dispose: function () {
  55959. this._clear();
  55960. }
  55961. });
  55962. function createEl$1(id, targetElParent, elOption, elMap) {
  55963. var graphicType = elOption.type;
  55964. var Clz = _nonShapeGraphicElements.hasOwnProperty(graphicType) // Those graphic elements are not shapes. They should not be
  55965. // overwritten by users, so do them first.
  55966. ? _nonShapeGraphicElements[graphicType] : getShapeClass(graphicType);
  55967. var el = new Clz(elOption);
  55968. targetElParent.add(el);
  55969. elMap.set(id, el);
  55970. el.__ecGraphicId = id;
  55971. }
  55972. function removeEl(existEl, elMap) {
  55973. var existElParent = existEl && existEl.parent;
  55974. if (existElParent) {
  55975. existEl.type === 'group' && existEl.traverse(function (el) {
  55976. removeEl(el, elMap);
  55977. });
  55978. elMap.removeKey(existEl.__ecGraphicId);
  55979. existElParent.remove(existEl);
  55980. }
  55981. } // Remove unnecessary props to avoid potential problems.
  55982. function getCleanedElOption(elOption) {
  55983. elOption = extend({}, elOption);
  55984. each$1(['id', 'parentId', '$action', 'hv', 'bounding'].concat(LOCATION_PARAMS), function (name) {
  55985. delete elOption[name];
  55986. });
  55987. return elOption;
  55988. }
  55989. function isSetLoc(obj, props) {
  55990. var isSet;
  55991. each$1(props, function (prop) {
  55992. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  55993. });
  55994. return isSet;
  55995. }
  55996. function setKeyInfoToNewElOption(resultItem, newElOption) {
  55997. var existElOption = resultItem.exist; // Set id and type after id assigned.
  55998. newElOption.id = resultItem.keyInfo.id;
  55999. !newElOption.type && existElOption && (newElOption.type = existElOption.type); // Set parent id if not specified
  56000. if (newElOption.parentId == null) {
  56001. var newElParentOption = newElOption.parentOption;
  56002. if (newElParentOption) {
  56003. newElOption.parentId = newElParentOption.id;
  56004. } else if (existElOption) {
  56005. newElOption.parentId = existElOption.parentId;
  56006. }
  56007. } // Clear
  56008. newElOption.parentOption = null;
  56009. }
  56010. function mergeNewElOptionToExist(existList, index, newElOption) {
  56011. // Update existing options, for `getOption` feature.
  56012. var newElOptCopy = extend({}, newElOption);
  56013. var existElOption = existList[index];
  56014. var $action = newElOption.$action || 'merge';
  56015. if ($action === 'merge') {
  56016. if (existElOption) {
  56017. // We can ensure that newElOptCopy and existElOption are not
  56018. // the same object, so `merge` will not change newElOptCopy.
  56019. merge(existElOption, newElOptCopy, true); // Rigid body, use ignoreSize.
  56020. mergeLayoutParam(existElOption, newElOptCopy, {
  56021. ignoreSize: true
  56022. }); // Will be used in render.
  56023. copyLayoutParams(newElOption, existElOption);
  56024. } else {
  56025. existList[index] = newElOptCopy;
  56026. }
  56027. } else if ($action === 'replace') {
  56028. existList[index] = newElOptCopy;
  56029. } else if ($action === 'remove') {
  56030. // null will be cleaned later.
  56031. existElOption && (existList[index] = null);
  56032. }
  56033. }
  56034. function setLayoutInfoToExist(existItem, newElOption) {
  56035. if (!existItem) {
  56036. return;
  56037. }
  56038. existItem.hv = newElOption.hv = [// Rigid body, dont care `width`.
  56039. isSetLoc(newElOption, ['left', 'right']), // Rigid body, dont care `height`.
  56040. isSetLoc(newElOption, ['top', 'bottom'])]; // Give default group size. Otherwise layout error may occur.
  56041. if (existItem.type === 'group') {
  56042. existItem.width == null && (existItem.width = newElOption.width = 0);
  56043. existItem.height == null && (existItem.height = newElOption.height = 0);
  56044. }
  56045. }
  56046. function setEventData(el, graphicModel, elOption) {
  56047. var eventData = el.eventData; // Simple optimize for large amount of elements that no need event.
  56048. if (!el.silent && !el.ignore && !eventData) {
  56049. eventData = el.eventData = {
  56050. componentType: 'graphic',
  56051. componentIndex: graphicModel.componentIndex,
  56052. name: el.name
  56053. };
  56054. } // `elOption.info` enables user to mount some info on
  56055. // elements and use them in event handlers.
  56056. if (eventData) {
  56057. eventData.info = el.info;
  56058. }
  56059. }
  56060. exports.version = version;
  56061. exports.dependencies = dependencies;
  56062. exports.PRIORITY = PRIORITY;
  56063. exports.init = init;
  56064. exports.connect = connect;
  56065. exports.disConnect = disConnect;
  56066. exports.disconnect = disconnect;
  56067. exports.dispose = dispose;
  56068. exports.getInstanceByDom = getInstanceByDom;
  56069. exports.getInstanceById = getInstanceById;
  56070. exports.registerTheme = registerTheme;
  56071. exports.registerPreprocessor = registerPreprocessor;
  56072. exports.registerProcessor = registerProcessor;
  56073. exports.registerPostUpdate = registerPostUpdate;
  56074. exports.registerAction = registerAction;
  56075. exports.registerCoordinateSystem = registerCoordinateSystem;
  56076. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  56077. exports.registerLayout = registerLayout;
  56078. exports.registerVisual = registerVisual;
  56079. exports.registerLoading = registerLoading;
  56080. exports.extendComponentModel = extendComponentModel;
  56081. exports.extendComponentView = extendComponentView;
  56082. exports.extendSeriesModel = extendSeriesModel;
  56083. exports.extendChartView = extendChartView;
  56084. exports.setCanvasCreator = setCanvasCreator;
  56085. exports.registerMap = registerMap;
  56086. exports.getMap = getMap;
  56087. exports.dataTool = dataTool;
  56088. exports.zrender = zrender;
  56089. exports.number = number;
  56090. exports.format = format;
  56091. exports.throttle = throttle;
  56092. exports.helper = helper;
  56093. exports.matrix = matrix;
  56094. exports.vector = vector;
  56095. exports.color = color;
  56096. exports.parseGeoJSON = parseGeoJson$1;
  56097. exports.parseGeoJson = parseGeoJson;
  56098. exports.util = ecUtil;
  56099. exports.graphic = graphic$1;
  56100. exports.List = List;
  56101. exports.Model = Model;
  56102. exports.Axis = Axis;
  56103. exports.env = env$1;
  56104. })));